Hi, I've made a simple program that blink a led on my stm32 board.
The program is built with both WinARM test-release 20080331 and Sourcery G++ Lite. The problem is that every time I use one C standard library function (memset) the program stop in the hard Fault exception after the execution of the blx instruction. I've made a simple memset alike function to test if my function parameters pointed to strange memory location, but they look fine. After searching in the Cortexâ„¢-M3 Revision: r1p1 Technical Reference Manual what could be the cause, I've read the content of the HFSR register where the only bit set (FORCED) can be triggered by different sources. I don't know how to go ahead from this point, Is there something obvious that I've missed out? thanks in advance
thanks all for your reply, I'll work on the blx vs bl instruction fow now (blx is used to call all the function of libc.a instead of bl <address<).
Is there a simple way to tell gcc to avoid using the blx instruction? My compiler flags are: CFLAGS = -c -g $(INCLUDE_DIR) -fno-common -mcpu=cortex-m3 -mthumb -Wall -O0 -DSTM32 LFLAGS = -Wl,--gc-sections,-Map=$@.map,-cref,-u,Reset_Handler -T$(LINKER) [ This message was edited by: nagiox on 23-02-2009 20:35 ]
BLX Rm is allowed in the Cortex-M3. (BLX label is not allowed).
However, you need to make sure the LSB of the address value in the register is set to 1 to indicate Thumb. Otherwise a usage fault would occurred and can escape to hardfault. In you case, I guess you code try to load the address value of a function into the register, and then call it using BLX instruction. However, you didn't declare the function you call as a Thumb function so the LSB of the register is not set. A recent post on CodeSourcery email list mentioned you can define the function as Thumb code by defining the function in an assembly file: http://www.codesourcery.com/archives/arm-gnu/msg02458.html Maybe this will help you.
I am not aware of any switch to avoid BLX instruction. If you could post your question on CodeSourcery email list (http://www.codesourcery.com/archives/arm-gnu/maillist.html), I guess the folks there might be able to help.