cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152RE application shifted to new address results in hardfault FORCED on startup with debugger

jeroenjvdb
Associate II

I'm trying to implement a bootloader for my application and need to shift my application to a higher address. I've updated the linker script such that the application starts at address 0x08040200 and this seems to work. However, when I start debugging the application and the startup script tries to jump to systemInit it returns a hardfault (FORCED -> [STKERR, IMPRECISERR])

I've taken the basic cubeMX project and made following changes:

linker:

/* Memories definition */
MEMORY
{
  RAM    (xrw)    : ORIGIN = 0x20001000,   LENGTH = 76K
  FLASH    (rx)    : ORIGIN = 0x8040200,   LENGTH = 192K
}
 
...
after .data
 
/* Extra ROM section (last one) to make sure the binary size is a multiple of the AES block size (16 bytes) */
  .align16 :
  {
    . = . + 1;         /* _edata=. is aligned on 8 bytes so could be aligned on 16 bytes: add 1 byte gap */
    . = ALIGN(16) - 1; /* increment the location counter until next 16 bytes aligned address (-1 byte)   */
    BYTE(0);           /* allocate 1 byte (value is 0) to be a multiple of 16 bytes                      */
  } > FLASH

in system32_stm32l1xx.c

#define VECT_TAB_OFFSET    0x40200U

but systemInit does not get called so I suppose the problem is in my linkerfile.

1 ACCEPTED SOLUTION

Accepted Solutions
jeroenjvdb
Associate II

After some debugging I found out the stack pointer was not properly in the startup script (generated by cubeMX). This was no problem when running at address 0x0800 0000 but after shifting the whole application, this line needed to be added in the script:

Reset_Handler:
  ldr  sp, =_estack /* add this to startup script */
/* Copy the data segment initializers from flash to SRAM */
...

View solution in original post

1 REPLY 1
jeroenjvdb
Associate II

After some debugging I found out the stack pointer was not properly in the startup script (generated by cubeMX). This was no problem when running at address 0x0800 0000 but after shifting the whole application, this line needed to be added in the script:

Reset_Handler:
  ldr  sp, =_estack /* add this to startup script */
/* Copy the data segment initializers from flash to SRAM */
...