HardFault when I set specific location for the var

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HardFault when I set specific location for the var

425 Views
lpcware
NXP Employee
NXP Employee
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?
0 Kudos
10 Replies

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by FlySnake on Thu Dec 08 02:20:54 MST 2011
1. Yes. But it seems like linker script works OK. The variable placed where it should be. If I remove this from declaration: __attribute__ ((section(".BootSector")))  then all will be OK, same linker script, same code, the only difference is placing 1 variable. But if it is there - boom! access violation fault before accessing this variable. Or some other error afterward.
2. Yes. All types of libs. Nothing changed.
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Dec 07 19:40:57 MST 2011
Considering that you don't really know what you're doing you are gluing together a lot of code :rolleyes:

#1 Did you switch back to Managed linker script to test your project?

#2 Did you switch back your linker script library from Semihost to Nohost?
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by FlySnake on Tue Dec 06 08:54:17 MST 2011

Quote: Zero
Made a few changes an added semihosting :eek:


Wow! Thank you very much! It works. But what is the crucial difference? Where was my mistake?

-=UPDATED=-

It works in test project only, not real. When I do this in real project (exact same ld scripts) I get IACCVIOL fault.
Piece of disassembly:
87                             case PRG_LED_T: off_led_fp(PRG_LED_PORT, PRG_LED); break;
00000378: off_led+40             movw r3, #260   ; 0x104
0000037c: off_led+44             movt r3, #4096  ; 0x1000
00000380: off_led+48             ldr r3, [r3, #0]
00000382: off_led+50             mov.w r0, #0
00000386: off_led+54             mov.w r1, #16
0000038a: off_led+58             blx r3
0000038c: off_led+60             b.n 0x3d2 <off_led+130>  // fault here
88                             case TXB_LED_T: off_led_fp(TXB_LED_PORT, TXB_LED); break;

The real project attached. The fault generates in function off_led_fp() which is just a pointer to GPIO_SetValue(). But, if I remove this function at all, then I get another faults in other places and different instructions, or not working program without faults. but with some other glitches. Hope you don't lose yourself in my code
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Dec 06 06:17:47 MST 2011
Made a few changes an added semihosting :eek:
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by FlySnake on Tue Dec 06 03:43:38 MST 2011
The actual project I'm working on is too big already, thus I've created tiny test project with the same linker settings and the same problem.
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Dec 05 15:12:38 MST 2011
Could be helpful if you post your project :rolleyes:
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by FlySnake on Mon Dec 05 13:14:40 MST 2011

Quote: TheFallGuy
Try making the size of your flash 0x48000. The *end* address will be 0x47fff, but the *size* is 0x48000.


Did you mean this
  MyBootSector(rx) : ORIGIN = 0x48000, LENGTH = 0x48000

?
I tried this, nothing changed
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Dec 05 10:56:06 MST 2011
Try making the size of your flash 0x48000. The *end* address will be 0x47fff, but the *size* is 0x48000.
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by FlySnake on Mon Dec 05 10:13:01 MST 2011
Yes:
PSR  = 0x01000003 (current exception = HardFault, 24th bit always set to 1)
CFSR = 0x00000400 (IMPRECISERR)

All what I know about IMPRECISERR from Cortex-M3 book:

Quote:
For precise bus faults, the offending instruction can be located by the stacked program counter, and if the BFARVALID bit in BFSR is set, it is also possible to determine the memory location that caused the bus fault. This is done by reading another NVIC register called the Bus Fault Address Register (BFAR). However, the same information is not available for imprecise bus faults because by the time the processor receives the error, the processor could have already executed a number of other instructions.


:confused:
0 Kudos

369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Sun Dec 04 13:31:52 MST 2011
Have you checked the Fault status registers and the Program status register?
0 Kudos