cancel
Showing results for 
Search instead for 
Did you mean: 

Issue on optimization level -O3 STM32WLE5CCU - Exception handler occures

kyf
Associate II

Hello there.

 

I've been developing a project with STM32WLE5CCU with LoraWAN included. I've used ST's utilities like LMhandler, UTILITIES_timer, and SEQUENCER to handle tasks and different functions.

I've encountered a strange behavior though. When I change the optimization level to O3 there are times where code asserts to an error and the error handler is called to reset the device.

I've done some search regarding the state of the registers in the MCU and I've found out that BFSR.IMPRECISERR register was set.

kyf_0-1719232526253.png

 

 

 

 

....
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/MMARVALID:0x0
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/IBUSERR:0x0
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/PRECISERR:0x0
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/IMPRECISERR:0x1
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/UNSTKERR:0x0
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/STKERR:0x0
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/LSPERR:0x0
STM32WL5x_CM4/SCB/CFSR_UFSR_BFSR_MMFSR/BFARVALID:0x0
...

 

 

 

 

I've exported all registers right when the error occurred.

This is the attached file name: exported registers regarding Hardfault exception.txt

 

- I could not figure out the triggering conditions of this fault. Time that this fault occurred was not the same all the times.

- This issue does not happen in -Os (size) optimization

 

Can anyone point me out where to look at in order to fix this ?!

 

Kind regards,

kyf

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

The dump is next to useless, you want to be looking at the processor registers, and the faulting instructions in that context.

Imprecise implies a write, that was pending in the write buffer, so look a few instructions prior.

Output actionable data..  https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

Failure based on optimization levels tends to high-light latent coding errors.

Watch for stack corruption, or writing variables beyond their scope.

Enable asserts to catch parameter issues.

Find commonality in failures, ie leaving an IRQ/callback for things which are more sporadic and random.

Instrument code to understand dynamic flow, and relationship of things going on, to hard faulting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3
STTwo-32
ST Employee

Hello @kyf 

I suggest you take a look at the errata 2.2.9 and 2.2.10 of the ES0506. It may be the raison behind this hardfault.

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

The dump is next to useless, you want to be looking at the processor registers, and the faulting instructions in that context.

Imprecise implies a write, that was pending in the write buffer, so look a few instructions prior.

Output actionable data..  https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

Failure based on optimization levels tends to high-light latent coding errors.

Watch for stack corruption, or writing variables beyond their scope.

Enable asserts to catch parameter issues.

Find commonality in failures, ie leaving an IRQ/callback for things which are more sporadic and random.

Instrument code to understand dynamic flow, and relationship of things going on, to hard faulting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kyf
Associate II

Thank you @STTwo-32 and @Tesla DeLorean for your responses.

I've read the errata documentation 2.2.9 and 2.2.10. Our case seems similar to 2.2.9 "SysTick trigger in debug emulation generates HardFault" but we always disable SysTick before going to stop2 sleep mode.

@Tesla DeLoreanI believe that is the case:

Failure based on optimization levels tends to high-light latent coding errors.

The projects that I'm working at the moment need lots of refactoring regarding variable, pointer and error handling. I will use your suggestions to narrow down the issue.


Kind regards,

kyf