-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix STM32 crashes on boot due to unset VTOR #4543
Conversation
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.
/morph test |
@@ -32,6 +32,10 @@ void mbed_sdk_init() | |||
{ | |||
// Update the SystemCoreClock variable. | |||
SystemCoreClockUpdate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this SystemCoreClockUpdate() call (and associated comment) can be removed since this call is now being added at the end of this function, after setting up the clocks (same comment applies to all changed mbed_overrides.c files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @monkiineko, does HAL_Init need the clock speeds to be set before it is called? Just want to double check before I go through and remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c1728p9 I've now spent some time investigating everything being done in the STM32 HAL_Init() and clock setting functions, and while I think it's a little wasteful doing the clock detection twice, the HAL RCC clock setting functions actually make use of the HAL tick timer for checking timeouts when starting oscillators and such, so it is safer to keep the extra SystemCoreClockUpdate() call as you have it to ensure these clock setup timeouts are of the proper duration. So, from my point of view, your code is okay as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monkiineko Thanks for the review
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
cc @adustm @bcostm @LMESTM @jeromecoutant Please review. This should work for mbed 2 and mbed 5. I'll run some mbed 2/5 tests to be sure this is now corrected. |
@c1728p9 @monkiineko Thanks for the PR. There is now a nice sequence description of boot calls in mbed_boot.c here (https://github.com/ARMmbed/mbed-os/blob/master/rtos/mbed_boot.c#L43) and I have 2 questions:
|
Confirmed that this resolves the problem I raised in #4532. |
Issue created #4550
ARM: __rt_lib_init All of these are invoked from pre_main, after mbed_sdk_init
Thanks for testing |
Hi |
Interested in this one, handler or what is the failure? |
I'm trying to debug ....
it looks like I don't even reach SystemInit ... and I don't understand why (yet) :-( |
Last STM32 family quick test: |
the issue on L476RG / GCC_ARM seems to be somehow related to the changes for bootloader support that were done during 17q2 workshop and which have been rebased and merged recently after cmsis5 updates ... |
I run CI test shield on F411, all OK. mbed 2 examples on F030R8 - OK
lets deal with this separately then. I just got the board, going to check what is going on. Is it only GCC ARM ? I believe this patch is ready to go in for 5.5.1 |
can you create an issue? I tested ARM, working on that target, GCC_ARM seems to go somewhere with frames corrupted, will require investigation. |
I think I found the issue in ld file for GCC_ARM: new issue created #4553 |
Hey Guys, Configuring the MCU using CoIde and no mbed libraries seems to work until I set the RCC params and Hal_InitTick() is called within stm32f4xx_hal_rcc.c on line 847. It seems like you all have worked out a solution here, but I am not quite there. I have updated all the libraries within my build folder. Can anyone point me to a solution here? |
@waymond91 Please create a new issue for this where someone can help you provide details about versions of toolchains, mbed OS, mbed-cli, etc , any detail that can help |
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.