cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault exception problem

mcho.19
Associate II

I make boot loader for jump to 0x08020000

And, I make program that start from 0x08020000, also same vector table address(0x08020000)

It works well, but sometimes(when program modified), it doesn't work

I use debugger, and get result below

//Fault exception viewer

HardFault exception.

The processor has escalated a configurable-priority exception to HardFault.

  A precise data access error has occurred (CFSR.PRECISERR, BFAR) at data address 0x1fff8001.

Exception occured at PC = 0x80216ae, LR = 0x802b61d

See the call stack for more information.

//Debug Log

The stack pointer for stack 'CSTACK' (currently 0x200025C8) is outside the stack range (0x20009170 to 0x2000A170) 

What is the problem?

Can you help me?

0690X000006CFCoQAO.jpg

8 REPLIES 8
AvaTar
Lead

Have you tried to pinpoint the exact location (instruction) where the fault happens ?

Perhaps you tried to access peripherals not yet enabled ?

mcho.19
Associate II

Thank you AvaTar

But, I don't know what i can

I try to debug program only, it works well.

I try to set program address and vector table 0x0800 0000, it works well.

Therefore, I guess set register or interrupt error when jump from 0x08000000(boot loader) to 0x08020000(program)

I made program it works well,

And, add 2lines in any function, uint8_t buf[10] and memset ( buf, 0x00, 10)

then, program halt and same issue

It work well at 0x08000000 or 0x08020000 starting by debugger

It's so hard to solve

AvaTar
Lead

Does the application set it's own vector table properly ?

Sounds like it uses the BL table.

In a similar application I have, the application sets the VTOR as one of the very first things in the reset handler.

mcho.19
Associate II

I set icf file

define symbol __ICFEDIT_intvec_start__ = 0x08020000;

/*-Memory Regions-*/

define symbol __ICFEDIT_region_ROM_start__ = 0x08020000;

define symbol __ICFEDIT_region_ROM_end__  = 0x080FFFFF;

I set stm32f2xx.c file

​#define VECT_TAB_OFFSET 0x20000 

void SystemInit(void)

{

 RCC->CR |= (uint32_t)0x00000001;

 RCC->CFGR = 0x00000000;

 RCC->CR &= (uint32_t)0xFEF6FFFF;

 RCC->PLLCFGR = 0x24003010;

 RCC->CR &= (uint32_t)0xFFFBFFFF;

 RCC->CIR = 0x00000000;

 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */

}

#define FLASH_BASE      0x08000000U /*!< FLASH(up to 1 MB) base address in the alias region             */

AvaTar
Lead

Our BL-loaded firmware does this as the very first thing in the reset handler:

 ; relocate the VTAB to the location in the firmware (0x30000)

LDR    R0, =__vector_table          ; get pointer to vector table

LDR    R1, =0xE000ED08              ; store the table address to NVIC VTOR register

STR    R0, [R1] ; Vector Table Relocation in Internal FLASH

IAR WB, but for another (non-ST) MCU, though. And your application project needs to map the vector table there, of course.

mcho.19
Associate II

Where should I insert that code?

AvaTar
Lead

I showed this code just as example. I hope you understood that addresses do not match - it is actually for a Cypress FM4 MCU.

> Where should I insert that code?

For our application, we created a derived startup code (using the IAR-supplied "startup_***.s" as starting point), which relocates the vector table, and sets the stack pointer from that table.

Afterwards, SystemInit and __iar_program_start are called (as usual).

mcho.19
Associate II

Ok, I see, I know that is example code (vtor 0x30000)

This is my startup code

-----------------------------------------------------------------

    MODULE ?cstartup

    ;; Forward declaration of sections.

    SECTION CSTACK:DATA:NOROOT(3)

    SECTION .intvec:CODE:NOROOT(2)

    EXTERN __iar_program_start

    EXTERN SystemInit

    PUBLIC __vector_table

    DATA

__vector_table

    DCD   sfe(CSTACK)

    DCD   Reset_Handler       ; Reset Handler

    DCD   NMI_Handler        ; NMI Handler

....

-------------

SystemInit() calls here, and SystemInit() set vtor