cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 and hardfault exception

nagiox
Associate II
Posted on February 28, 2009 at 11:23

stm32 and hardfault exception

8 REPLIES 8
paulsmitton9
Associate II
Posted on May 17, 2011 at 13:04

The Cortex M3 technical reference manual (search the forum for a link to this if you don't have it) says that BLX always faults.

n.b. the cortex only supports thumb2, not arm so the x part seems a bit redundant.

nagiox
Associate II
Posted on May 17, 2011 at 13:04

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

wywrotj
Associate II
Posted on May 17, 2011 at 13:04

Which attributes has your reset handler? Also do you have your vectors table filled with fault handlers like:

UsageFault

BusFault

MemManage

NMIException

Regards!!

joseph239955
Associate II
Posted on May 17, 2011 at 13:04

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.

nagiox
Associate II
Posted on May 17, 2011 at 13:04

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 ]

mdeneen
Associate II
Posted on May 17, 2011 at 13:04

Sorry if I am late. Make sure you link with the -mthumb parameter or else you will link in the non-thumb libraries. This will solve your problem.

Mark

joseph239955
Associate II
Posted on May 17, 2011 at 13:04

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.

nagiox
Associate II
Posted on May 17, 2011 at 13:04

thanks!, I've added -mthumb to my linker command line and the problem is solved.

LFLAGS = -Wl,--gc-sections,-Map=$@.map,-cref,-u,Reset_Handler -T$(LINKER) -mthumb