Hello,
I am using Keil to develop code for my Cortex M0+ based MCU. I have added code to set the core to sleep state based on a certain condition.
The problem is that when I run the code on the MCU, all works fine. When I try to debug the code, the execution doesn't even get to the main().
The only possibilities I have during that debug session are to either click the reset button or the stop button on the debug interface. When I click on the stop button, call stack shows me that the execution stopped in a HardFault_Handler.
I am aware that in the low power mode that I am using the debug is not possible, but after a reset the core should run normally and then enter sleep state. Until that happens I should be able to debug!
I even tried to hack that the code tries to put the core in the run state (current state) again. Still the debug is not possible. Runs well on the MCU.
The new code with the low power modes enabled links wells and runs on the MCU. So I can't doubt the memory insufficiency. If I go back to my old code, debug is possible as normal.
Please help.
I tried stepping through the reset handler. ============= Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT SystemInit IMPORT __main
IF :LNOT::DEF:RAM_TARGET REQUIRE FlashConfig ENDIF
CPSID I ; Mask interrupts LDR R0, =0xE000ED08 LDR R1, =__Vectors STR R1, [R0] LDR R0, =SystemInit BLX R0 CPSIE i ; Unmask interrupts LDR R0, =__main BX R0 ENDP ============ Execution goes through absolutely fine until after "LDR R0, =__main". The last BX instruction does not get me to the main().
If I remove a specific line of code, then the debug works just fine. I would repeat, when not in debug mode, the code runs fine! But I need to debug :(
Please give me some more clues.
__main isn't your main() function - it's a library initialization function that sets up the runtime library before main() is called.
A C compiler normally adds one (1) _ prefix character to symbol names, just to make sure that C code symbols will not clash with any unknown assembler symbols.
Internal functions in the C runtime library are normally named with a leading _ in the C source code. So their external name seen by the linker will then have two leading _.