I am using RL-RTX with uVision IDE.
Just recently I ran into a weird issue. The only way I can describe it, is by the following way:
When I compile a C/C++ code I typically click on "Start/Stop Debug Session" after it is done compiling. At this time I see the uVision IDE flashing the microcontroller with the compiled software (using a status bar). After this is done the uVision IDE is ready to for me to click on "Run" to execute the firmware on the target. When I click on "Run" the target executes the firmware as expected. I can tell this by LEDs, LCD, and key inputs. At this time I want to restart and run the firware again, so I click on "Stop". Next, I click on "Reset" and follow this with a click on "Run" again. At this this point the ARM Cortex-M3 generates a 'hard fault exception". This exception is at the following line of code:
LDR r0,[r4, #0x00]
This line of code happens to be in the RTX library. I do not have access to this code, but from the Disassembly I can tell that it is part of the RTX library. See below:
_malloc_internal: PUSH {r4-r8, lr} MOV r4,r0 MOV r6,r1 MOV r7,r2 BL.W 0x080003E4 CMP r0,r4 MOV r5,r0 BLS 0x0800046A CBZ r7,0x08000412 ADD r0,r6,#0x0C NOP.W LDR r4,[r6,#0x04] MOV r1,r6 CBZ r4,0x08000454 LDR r0,[r4,#0x00]
Having typed all of this I was wondering why this is suddenly happening? Why is it only happening when I reset the target and run again? The RTX libraries are precompiled, so nothing changes there.
Has anyone ran into an issue like this?
Do you have a custom board or an evaluation board? Is RESET from the debug connector properly connected?
Also try "HW Reset" setting for Reset instead of Autodetect.
This is a custom board that I have been using for several months. I've been able to debug with it previously.
When I compare the STM32F Eval board to this design it is very similar.
Changing the setting to "HW Reset" instead of "Autodetect" does not help.
It has something to do with the heap. I moved the heap to external SRAM.
;Heap_Mem SPACE Heap_Size Heap_Mem EQU 0x68100000
If I move it back to internal memory I can see that it goes away. I don't see why this should cause a problem because the external controller is initialized before __main.
This is my startup.s file:
; Reset handler routine Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT HW_init IMPORT __main LDR R0, = HW_init ; Initialize board: FSMC, clock, etc... BLX R0 LDR R0, =__main BX R0 ENDP
Check which instruction caused the hardware fault. I’m assuming Load/Store instruction to certain address. Could be a problem with the memory controller setup.
Does the program run correctly without the debugger also after forcing a reset?