lpcware

HardFault when I set specific location for the var

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by FlySnake on Sun Dec 04 06:50:11 MST 2011
Hi all
I want store a bunch of code in specific flash location. To play with this possibility I set memory region and place 1 variable there. MCU - LPC1768
mem.ld
MEMORY
{
  /* Define each memory region */
  MFlash512 (rx) : ORIGIN = 0x0, LENGTH = 0x47FFF             /* 256k */
  RamLoc32 (rwx) : ORIGIN = 0x10000100, LENGTH = 0x7F00     /* 32k-100h */
  RamAHB32 (rwx) : ORIGIN = 0x2007c000, LENGTH = 0x8000     /* 32k */
  MyBootSector(rx) : ORIGIN = 0x48000, LENGTH = 0x8000        /* 32k NEW LOC*/
 

}
  /* Define a symbol for the top of each memory region */
  __top_MFlash512 = 0x0 + 0x47FFF;
  __top_RamLoc32 = 0x10000000 + 0x8000;
  __top_RamAHB32 = 0x2007c000 + 0x8000;
  __top_MyBootSector = 0x48000 + 0x8000;
in ld sript:
 .BootSector : ALIGN(4)
    {
         *(.BootSector)
    } > MyBootSector
and define variable
__attribute__ ((section(".BootSector")))
const char teststring[]="\n\nHello blabla\n\n";
In .map file I see this sector and the variable. This variable appears in memory where it is defined
0x00048000  65480A0A 206F6C6C 62616C62 0A0A616C 00000000 FFFFFFFF FFFFFFFF  ..Hello blabla......ÿÿÿÿÿÿÿÿ
But, if it is there - MCU falls to HardFault immediately after start.
Call stack:
Thread [1] (Suspended: Signal 'SIGINT' received. Description: Interrupt.)    
    5 HardFault_Handler() cr_startup_lpc17.c:297 0x00000164   
    4 <signal handler called>()  0xfffffff9   
    3 malloc()  0x0000cb3a   
    2 _sbrk()  0x0000f8a6   
    1 <symbol is not available> 0x10007ff0   
What am I doing wrong?

Outcomes