Malfunction using release build

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Malfunction using release build

Jump to solution
607 Views
marc_v
Contributor I

Hello again.
I have a problem and it is the following.
If I flash the Debug build, the device works correctly.
The same code compiled in Release fails and the equipment freezes.
When debugging the Release build I get to the indicated point, after which, when doing a step (at the assembly instruction level) HardFault_Handler jumps.
The Debug build at that point is similar, but works without any issues.
Any tips or ideas how to solve or what else I should try?
From already thank you very much, greetings.

Debug_vs_Release_2.png

0 Kudos
1 Solution
562 Views
ErichStyger
Senior Contributor V
0 Kudos
4 Replies
590 Views
ErichStyger
Senior Contributor V

It looks like the content of the R4 register is causing the problem. What is the value of R4, and is there valid memory where it points to it? And if the content is properly aligned?

It is very hard to tell what is going on as you have blurred things out which could be important to know about.

Keep in mind that with aggressive optimizations, if you have something not properly initialized it could cause a crash, while in debug build the variable/etc might still be set to something.

I hope this helps,

Erich

0 Kudos
565 Views
marc_v
Contributor I

Hi Erich.

Sorry for the delay in my response.
I tried minor changes in the declaration of the 'origin' pointer variable, such as changing the order of the declaration of the local variables in the function or declaring it as global volatile without success.
There were changes in the generated assembler but the same error continues, a HardFault occurs when the indicated line is executed.
I was also able to observe that, in all cases, the value stored in 'origen' is correct, it matches the memory address of the 'mem_page' buffer, which is expected.

imagen.png

 I really appreciate your help, thank you very much in advance, greetings!

0 Kudos
563 Views
ErichStyger
Senior Contributor V
0 Kudos
556 Views
marc_v
Contributor I

Ok, that gives me a clue.
I found an old community message (from 05-28-2020) that says "The GCC compiler version used by MCUXpresso has a bug with misaligned accesses when optimisation is high and if you keep the level no higher that -O1 for code that fails it may work around it.".
I changed the optimization level to None (-O0) and now it works.
In a quick test, with level (-O1), there were problems with the I2C, but I'm still looking.
This current solution is enough, I'll have time to explore more options later.

Thank you Erich for your comments, greetings.

0 Kudos