2022-05-09 02:40 AM
Hi all,
I'm trying to use a version of the elua interpreter on a stm32f446re nucleo board.
I've encountered a problem, the program is jumping on an infinite loop after entering a couple of functions of the interpreter. The system is blocking in an WWDG_IRQHandler set to the default irq handler that is a infinite loop, here's the code where it's blocked:
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
* @param None
* @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
The debugger can't find the source of the interrupt in the stack trace.
Debugging the C code I discovered that the program blocks inside an obscure call to a function pointer, so I tried to debug directly the asm code to find out exactly where the code is blocking and I discovered that the program is blocking exactly after a blx instruction that is branching to a mov instruction:
The compilation flags that I'm using are the following:
-std=gnu11 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Os -mcpu=cortex-m4 -ffunction-sections -fdata-sections -Wall -nostdlib --param max-inline-insns-single=500
I tried to take away the -mthumb option but nothing is changing.
Do you know what could be the cause of this behavior?
Do you think that the blx instruction is the problem or that it is just a coincidence?
Do you know what I could do to find out what's the problem? I 'm kinda stuck with the debugging process because I don't know if I should focus on the compilation or maybe the code.
Solved! Go to Solution.
2022-05-09 02:55 AM
Try to set the lowest bit of the address: should be 0x800f711
2022-05-09 02:55 AM
Try to set the lowest bit of the address: should be 0x800f711
2022-05-09 11:50 AM
the solution works, I don't know why though.
The addresses are generated by the compiler of course (probably the linker) how can I make it compile correctly?
2022-05-09 07:25 PM
> the solution works, I don't know why though
STM32s have so called "thumb" instruction set which requires this trick with the lowest bit on jump/call addresses - though the real addresses are even.
> The addresses are generated by the compiler
All C/C++ compilers for Cortex M of course know this trick and generate correct code.
Does this code come out of the Lua interpreter or some library unaware of thumb mode?