Workaround for an STM32F405 bug causing a delay between an RCC peripheral clock enable and the effective peripheral enabling, as described in ST's silicon errata sheet

replace/36dda16454f463d5949c6113fef9122624551c00
Silvano Seva 2020-11-16 11:24:52 +01:00
rodzic 76086d567f
commit 01ee477b02
9 zmienionych plików z 24 dodań i 1 usunięć

Wyświetl plik

@ -25,6 +25,7 @@ void adc1_init()
{ {
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN; RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
__DSB();
/* /*
* Configure GPIOs to analog input mode: * Configure GPIOs to analog input mode:
@ -100,8 +101,9 @@ void adc1_init()
void adc1_terminate() void adc1_terminate()
{ {
DMA2_Stream0->CR &= ~DMA_SxCR_EN; DMA2_Stream0->CR &= ~DMA_SxCR_EN;
ADC1->CR2 &= ADC_CR2_ADON; ADC1->CR2 &= ~ADC_CR2_ADON;
RCC->APB2ENR &= ~RCC_APB2ENR_ADC1EN; RCC->APB2ENR &= ~RCC_APB2ENR_ADC1EN;
__DSB();
} }
float adc1_getMeasurement(uint8_t ch) float adc1_getMeasurement(uint8_t ch)

Wyświetl plik

@ -132,6 +132,8 @@ void display_init()
* framebuffer content to the screen without using CPU. * framebuffer content to the screen without using CPU.
*/ */
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN; RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
__DSB();
NVIC_ClearPendingIRQ(DMA2_Stream7_IRQn); NVIC_ClearPendingIRQ(DMA2_Stream7_IRQn);
NVIC_SetPriority(DMA2_Stream7_IRQn, 14); NVIC_SetPriority(DMA2_Stream7_IRQn, 14);
NVIC_EnableIRQ(DMA2_Stream7_IRQn); NVIC_EnableIRQ(DMA2_Stream7_IRQn);
@ -141,6 +143,7 @@ void display_init()
* lines. * lines.
*/ */
RCC->AHB3ENR |= RCC_AHB3ENR_FSMCEN; RCC->AHB3ENR |= RCC_AHB3ENR_FSMCEN;
__DSB();
/* Configure FSMC as LCD driver. /* Configure FSMC as LCD driver.
* BCR1 config: * BCR1 config:
@ -331,6 +334,8 @@ void display_terminate()
{ {
/* Shut off FSMC and deallocate framebuffer */ /* Shut off FSMC and deallocate framebuffer */
RCC->AHB3ENR &= ~RCC_AHB3ENR_FSMCEN; RCC->AHB3ENR &= ~RCC_AHB3ENR_FSMCEN;
__DSB();
if(frameBuffer != NULL) if(frameBuffer != NULL)
{ {
free(frameBuffer); free(frameBuffer);

Wyświetl plik

@ -106,6 +106,7 @@ void toneGen_init()
* - Nominal update rate is 16.384kHz -> error = +22.25Hz * - Nominal update rate is 16.384kHz -> error = +22.25Hz
*/ */
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
__DSB();
TIM3->ARR = 0xFF; TIM3->ARR = 0xFF;
TIM3->PSC = 9; TIM3->PSC = 9;
@ -125,6 +126,8 @@ void toneGen_init()
void toneGen_shutdown() void toneGen_shutdown()
{ {
RCC->APB1ENR &= ~RCC_APB1ENR_TIM3EN; RCC->APB1ENR &= ~RCC_APB1ENR_TIM3EN;
__DSB();
gpio_setMode(CTCSS_OUT, INPUT); gpio_setMode(CTCSS_OUT, INPUT);
gpio_setMode(BEEP_OUT, INPUT); gpio_setMode(BEEP_OUT, INPUT);
} }

Wyświetl plik

@ -59,6 +59,7 @@ void Reset_Handler()
| RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOCEN
| RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIODEN
| RCC_AHB1ENR_GPIOEEN; | RCC_AHB1ENR_GPIOEEN;
__DSB();
// Configure all GPIO pins to fast speed mode (50MHz) // Configure all GPIO pins to fast speed mode (50MHz)
GPIOA->OSPEEDR = 0xAAAAAAAA; GPIOA->OSPEEDR = 0xAAAAAAAA;

Wyświetl plik

@ -25,6 +25,8 @@ void rtc_init()
{ {
/* Enable write protection for RTC registers */ /* Enable write protection for RTC registers */
RCC->APB1ENR |= RCC_APB1ENR_PWREN; RCC->APB1ENR |= RCC_APB1ENR_PWREN;
__DSB();
PWR->CR |= PWR_CR_DBP; PWR->CR |= PWR_CR_DBP;
RTC->WPR = 0xCA; RTC->WPR = 0xCA;
RTC->WPR = 0x53; RTC->WPR = 0x53;

Wyświetl plik

@ -58,6 +58,7 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN; RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
__DSB();
} }
/** /**

Wyświetl plik

@ -52,6 +52,8 @@ void platform_init()
* Backlight pin is connected to TIM8 CR1. * Backlight pin is connected to TIM8 CR1.
*/ */
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; RCC->APB2ENR |= RCC_APB2ENR_TIM8EN;
__DSB();
TIM8->ARR = 255; TIM8->ARR = 255;
TIM8->PSC = 327; TIM8->PSC = 327;
TIM8->CNT = 0; TIM8->CNT = 0;
@ -78,6 +80,7 @@ void platform_terminate()
/* Shut down timer */ /* Shut down timer */
RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN; RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN;
__DSB();
/* Shut down ADC */ /* Shut down ADC */
adc1_terminate(); adc1_terminate();

Wyświetl plik

@ -52,6 +52,8 @@ void platform_init()
* Backlight pin is connected to TIM8 CR1. * Backlight pin is connected to TIM8 CR1.
*/ */
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; RCC->APB2ENR |= RCC_APB2ENR_TIM8EN;
__DSB();
TIM8->ARR = 255; TIM8->ARR = 255;
TIM8->PSC = 327; TIM8->PSC = 327;
TIM8->CNT = 0; TIM8->CNT = 0;
@ -78,6 +80,7 @@ void platform_terminate()
/* Shut down timer */ /* Shut down timer */
RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN; RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN;
__DSB();
/* Shut down ADC */ /* Shut down ADC */
adc1_terminate(); adc1_terminate();

Wyświetl plik

@ -72,6 +72,8 @@ void platform_init()
* With ARR = 256, Fpwm is 256Hz; * With ARR = 256, Fpwm is 256Hz;
*/ */
RCC->APB2ENR |= RCC_APB2ENR_TIM11EN; RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
__DSB();
TIM11->ARR = 255; TIM11->ARR = 255;
TIM11->PSC = 1282; TIM11->PSC = 1282;
TIM11->CNT = 0; TIM11->CNT = 0;
@ -100,6 +102,7 @@ void platform_terminate()
#ifdef ENABLE_BKLIGHT_DIMMING #ifdef ENABLE_BKLIGHT_DIMMING
RCC->APB2ENR &= ~RCC_APB2ENR_TIM11EN; RCC->APB2ENR &= ~RCC_APB2ENR_TIM11EN;
__DSB();
#endif #endif
/* Shut down LEDs */ /* Shut down LEDs */