Skip to content

Commit 7281d09

Browse files
c1728p9adbridge
authored andcommitted
Fix STM32 crashes on boot due to unset VTOR
Remove HAL_Init and related code from SystemInit and move it to mbed_sdk_init. The function SystemInit is called early in the boot sequence before RAM is initialized or the VTOR is setup, so it should not be used to perform the HAL initialization. This fixes crashes due the vector table being used before it has been relocated.
1 parent 162f800 commit 7281d09

File tree

65 files changed

+62
-723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+62
-723
lines changed

targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/system_stm32f0xx.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,6 @@ void SystemInit(void)
234234

235235
/* Enable SYSCFGENR in APB2EN, needed for 1st call of NVIC_SetVector, to copy vectors from flash to ram */
236236
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
237-
238-
/* Configure the Cube driver */
239-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
240-
HAL_Init();
241-
242-
/* Configure the System clock source, PLL Multiplier and Divider factors,
243-
AHB/APBx prescalers and Flash settings */
244-
SetSysClock();
245237

246238
}
247239

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/system_stm32f0xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
#include "hal_tick.h"
85+
8686
/**
8787
* @}
8888
*/
@@ -234,18 +234,7 @@ void SystemInit(void)
234234

235235
/* Enable SYSCFGENR in APB2EN, needed for 1st call of NVIC_SetVector, to copy vectors from flash to ram */
236236
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
237-
238-
/* Configure the Cube driver */
239-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
240-
HAL_Init();
241-
242-
/* Configure the System clock source, PLL Multiplier and Divider factors,
243-
AHB/APBx prescalers and Flash settings */
244-
SetSysClock();
245237

246-
/* Reset the timer to avoid issues after the RAM initialization */
247-
TIM_MST_RESET_ON;
248-
TIM_MST_RESET_OFF;
249238
}
250239

251240
/**

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/system_stm32f0xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
#include "hal_tick.h"
85+
8686
/**
8787
* @}
8888
*/
@@ -234,18 +234,7 @@ void SystemInit(void)
234234

235235
/* Enable SYSCFGENR in APB2EN, needed for 1st call of NVIC_SetVector, to copy vectors from flash to ram */
236236
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
237-
238-
/* Configure the Cube driver */
239-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
240-
HAL_Init();
241-
242-
/* Configure the System clock source, PLL Multiplier and Divider factors,
243-
AHB/APBx prescalers and Flash settings */
244-
SetSysClock();
245237

246-
/* Reset the timer to avoid issues after the RAM initialization */
247-
TIM_MST_RESET_ON;
248-
TIM_MST_RESET_OFF;
249238
}
250239

251240
/**

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/system_stm32f0xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
#include "hal_tick.h"
85+
8686
/**
8787
* @}
8888
*/
@@ -234,18 +234,7 @@ void SystemInit(void)
234234

235235
/* Enable SYSCFGENR in APB2EN, needed for 1st call of NVIC_SetVector, to copy vectors from flash to ram */
236236
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
237-
238-
/* Configure the Cube driver */
239-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
240-
HAL_Init();
241-
242-
/* Configure the System clock source, PLL Multiplier and Divider factors,
243-
AHB/APBx prescalers and Flash settings */
244-
SetSysClock();
245237

246-
/* Reset the timer to avoid issues after the RAM initialization */
247-
TIM_MST_RESET_ON;
248-
TIM_MST_RESET_OFF;
249238
}
250239

251240
/**

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/system_stm32f0xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
#include "hal_tick.h"
85+
8686
/**
8787
* @}
8888
*/
@@ -234,18 +234,7 @@ void SystemInit(void)
234234

235235
/* Enable SYSCFGENR in APB2EN, needed for 1st call of NVIC_SetVector, to copy vectors from flash to ram */
236236
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
237-
238-
/* Configure the Cube driver */
239-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
240-
HAL_Init();
241-
242-
/* Configure the System clock source, PLL Multiplier and Divider factors,
243-
AHB/APBx prescalers and Flash settings */
244-
SetSysClock();
245237

246-
/* Reset the timer to avoid issues after the RAM initialization */
247-
TIM_MST_RESET_ON;
248-
TIM_MST_RESET_OFF;
249238
}
250239

251240
/**

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/system_stm32f0xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
#include "hal_tick.h"
85+
8686
/**
8787
* @}
8888
*/
@@ -233,18 +233,7 @@ void SystemInit(void)
233233

234234
/* Enable SYSCFGENR in APB2EN, needed for 1st call of NVIC_SetVector, to copy vectors from flash to ram */
235235
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
236-
237-
/* Configure the Cube driver */
238-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
239-
HAL_Init();
240-
241-
/* Configure the System clock source, PLL Multiplier and Divider factors,
242-
AHB/APBx prescalers and Flash settings */
243-
SetSysClock();
244236

245-
/* Reset the timer to avoid issues after the RAM initialization */
246-
TIM_MST_RESET_ON;
247-
TIM_MST_RESET_OFF;
248237
}
249238

250239
/**

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/system_stm32f0xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
#include "hal_tick.h"
85+
8686
/**
8787
* @}
8888
*/
@@ -233,18 +233,7 @@ void SystemInit(void)
233233

234234
/* Enable SYSCFGENR in APB2EN, needed for 1st call of NVIC_SetVector, to copy vectors from flash to ram */
235235
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
236-
237-
/* Configure the Cube driver */
238-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
239-
HAL_Init();
240-
241-
/* Configure the System clock source, PLL Multiplier and Divider factors,
242-
AHB/APBx prescalers and Flash settings */
243-
SetSysClock();
244236

245-
/* Reset the timer to avoid issues after the RAM initialization */
246-
TIM_MST_RESET_ON;
247-
TIM_MST_RESET_OFF;
248237
}
249238

250239
/**

targets/TARGET_STM/TARGET_STM32F0/mbed_overrides.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
void mbed_sdk_init() {
3232
// Update the SystemCoreClock variable.
3333
SystemCoreClockUpdate();
34-
// Need to restart HAL driver after the RAM is initialized
3534
HAL_Init();
35+
36+
/* Configure the System clock source, PLL Multiplier and Divider factors,
37+
AHB/APBx prescalers and Flash settings */
38+
SetSysClock();
39+
SystemCoreClockUpdate();
3640
}

targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/system_stm32f1xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
*/
9393

9494
#include "stm32f1xx.h"
95-
#include "hal_tick.h"
95+
9696

9797
/**
9898
* @}
@@ -254,17 +254,6 @@ void SystemInit (void)
254254
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
255255
#endif
256256

257-
/* Configure the Cube driver */
258-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
259-
HAL_Init();
260-
261-
/* Configure the System clock source, PLL Multiplier and Divider factors,
262-
AHB/APBx prescalers and Flash settings */
263-
SetSysClock();
264-
265-
/* Reset the timer to avoid issues after the RAM initialization */
266-
TIM_MST_RESET_ON;
267-
TIM_MST_RESET_OFF;
268257
}
269258

270259
/**

targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/system_stm32f1xx.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
*/
9191

9292
#include "stm32f1xx.h"
93-
#include "hal_tick.h"
93+
9494

9595
/**
9696
* @}
@@ -252,17 +252,6 @@ void SystemInit (void)
252252
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
253253
#endif
254254

255-
/* Configure the Cube driver */
256-
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
257-
HAL_Init();
258-
259-
/* Configure the System clock source, PLL Multiplier and Divider factors,
260-
AHB/APBx prescalers and Flash settings */
261-
SetSysClock();
262-
263-
/* Reset the timer to avoid issues after the RAM initialization */
264-
TIM_MST_RESET_ON;
265-
TIM_MST_RESET_OFF;
266255
}
267256

268257
/**

0 commit comments

Comments
 (0)