-
Notifications
You must be signed in to change notification settings - Fork 2k
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
stm32l152re: hard-fault unless power-cycled after flash, or depending on optimization #11820
Comments
@cladmi @kaspar030 @kYc0o you were all highly involved in #8518, would you have more clues, suggestions, or insight in the problem I could use to try and find a explanation to this? |
Do you have any clue which exact instruction causes the hard fault? If a cold-boot mitigates the issue, it means that this is dependent on some state change that happens since the last cold boot. As this happens after flashing, I'd expect that the flash logic does something weird. Are you using openocd? Can you try st-flash? |
@kaspar030 I'm using opencod. The issue is NOT present when flashing with st-flash! (thanks for the suggestion). |
Flashing with st-flash does not fix the issue if it has already been flashed before with openocd without a Also, flashing the |
That means that openocd's flashing code puts the MCU in a state that breaks our code. Looking at what my openocd does:
Maybe some of the stmclk assumptions are not valid after openocd fiddled with the registers. |
According to the debug output it would be
|
When steping threw the code the registers BTW |
Do you have info of what is at |
In this case I think its just a corrupted addres, depending on the application I get different values. If flashing
Which is outside of the flash region. |
Ideas for bisecting, as you said it changes with optimization
Note as I just thought about it, if there is re-ordering, a memory barrier may be necessary |
@cladmi Thanks for the suggestions!
It does not, I lowered optimization just for
But it hardfaults if the |
I don't have any knowledge in ST MCU but is this issue related to this somehow ? (section 2.1.13) |
Hi @dylad thanks for the suggestion, I had looked at this some time ago but couldn't find a reason why this would be related, because we never set RUN_PD bit so it should never be in Power Down. I will look into it again though since, the fact that flashing with |
So far I've been looking only at the assembler code for pm_set. When comparing current code output in master with fixes 1 & 2 (I numbered the fixes) the code is pretty much the same, the only difference (bedsides the one introduced by the change in 1 &2) is that a When comparing the base case with 3 there is indeed some re-ordering but functionally the code seems to be the same. Master:
-O2:
|
@cladmi I'm quite puzzled at why |
For me it looks like it moved the |
And no idea about how openocd works… It is something I lack for a long time and never managed to compensate. |
I don't think that is the case, to me |
@kaspar030 @cladmi I think I found the culprit. Openocd has the following difference with
And interestingly:
Which explains why it works after POR, and why openocd triggers the hardfault. When removing Alternatively I can also add on start up I add I both cases all issues are gone. :) |
I'm looking into how to implement this in the best way so these bit are only set when debugging. There is also something to be done in the |
Indeed, I read a bit the output with more details, and the code I tried blindly adding many For my analysis, I used
Comparing building normally and with master
CFLAGS_OPT=-O2
|
I can confirm setting:
Fixes the issue in all cases, but there is no debugging in sleep modes. |
I remember that debugging with sleep mode could require some debugger special operation. For the IoT-LAB tutorials we were recommending to remove It could be configured in the And to connect to a sleeping device it may need to |
@cladmi I would propose changing the openocd config for all stm32 to add this:
That way the This still wouldn't fix this issue because there is still a problem with wakeups when |
Description
#8518 introduced a
_NOP()
after_WFI
to avoid a hard-fault because of the loss of a register content after exiting sleep (or at least that was the best possible cause at the time).When #11159 was introduced the way
pm_set_lowest()
was called changed becausepm_set()
was now implemented forSTM32L1
, this made the problem re-appear. At the time the PR was merged I did not see the bug because I was using a different version of gcc and for some reason the bug didn't appear under those conditions. I did see it when @aabadie tested #11489 and I switched compiler versions.As for what I can tell the hardfault still occurs at the same point.
There are many puzzling things about this:
NOP
solves the issue now...Summing the possible fixes I have found:
_NOP()
_NOP()
after and even afterirqs
are enabled again-Os
to-O2
state
as volatile (when callingirq_disable()
)I've tried to find a proper formal explanation for this but I haven't succeeded. I'm specially intrigued by the fact that after a power-cycle it works again I feel that could be an important insight into the problem #8518 tried to fix.
I can post the disassembly for any of these solutions, I haven't been able to find something that could explain it (but I'm not very knowledged in assembler).
Steps to reproduce the issue
Checkout upstream master and flash an application (different than hello-world), I usually do:
make -C tests/xtimer_usleep BOARD=nucleo-l152re clean -j3 flash term
Plug and un-plug the board (or remove IDD jumper on nucleo boards), in the same terminal and without flashing again run the application again:
It works as expected.
Expected results
Should work fine after flashing with or without power-cycle.
Actual results
Crashes unless complete power-cycle is performed.
Versions
No issues toolchain:
Issues toolchain:
The text was updated successfully, but these errors were encountered: