This Technical Note covers ONE specific reason for the application not to function as expected at run-time. This specific case is most often seen after migrating from IAR Embedded Workbench for ARM version 4.x or older to IAR Embedded Workbench for ARM version 5.x or newer.
There are of course many reasons for not functioning, but at least this aspect can be removed for the list of topics to troubleshoot.
These kind of issues can range from just a function not working as intended to the whole application malfunctioning.
IAR Embedded Workbench for ARM version 5.x (and newer) is AEABI compliant. The AEABI standard specifies that the stack pointer must be 8-byte aligned at function entry.
If the application makes the stack pointer to be 4-byte aligned then the aplciation will not work as intended. The IAR Embedded Workbench for ARM tools do not detect if your application is not correct (8-byte aligned stack) in this respect.
The IAR C/C++ Compiler for ARM will always make a proper 8-byte alignment. So the reason for the problems can be either:
SUB sp,sp,#4 ; push of 4 bytes for align to 8 bytes
STMFD sp!,{lr} ; Save the link register - a push of 4 bytes
LDR lr, = ReturnAddress ; Read the return address.
BX r0 ; Branch to the C function.
ReturnAddress
LDMFD sp!,{lr} ; Restore the link register - a pop of 4 bytes
ADD sp,sp,#4 ; Adjust stack - a pop of 4 bytes
With the stack checked to be 8-byte aligned, then the application may start to work as intended. Otherwise other aspects needs to be examined in the application.
All product names are trademarks or registered trademarks of their respective owners.
© IAR Systems 1995-2021 - All rights reserved.
We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies