Application and vector offset

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

Application and vector offset

1,553 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tjoAG on Fri Nov 02 01:21:32 MST 2012
Hi

I'm making our application ready so it can be used with the bootloader.

The bootloader will be placed from flash address 0x0000 - 0x8000
The application will then start from address 0x8000.

I'm trying to get the application running from flash address 0x8000, just to see if it works. But if I do that, the debugger looses its connection. (Using KEIL and ULINK2). I have to force the CPU into internal bootloader before I can get my debugger connect again.

What I have done so far in my application to make it run from address 0x8000

In the scatter file I have offset the RO space to 0x8000:

<code>
; Load region is in internal FLASH, 512KBytes
FLASH 0x00000000 0x78000 {
  ; All code and RO data in in FLASH
  ER_RO 0x00000000 0x78000 {
    ;startup_LPC177x_8x.o (RESET, +FIRST)
startup_ea1788.o (RESET, +FIRST)
    *.o (+RO)
  }
</code>

In the SystemInit function I move the VTOR to address 0x8000:
<code>
SCB->VTOR  = 0x00000000 & 0x3FFFFF80;
</code>
In the uVision debug setup I add a ini script for the debugger to jump the SP and PC to the flash address 0x8000:
<code>
FUNC void Setup (void) {
  SP = _RDWORD(0x00008000);          // Setup Stack Pointer
  PC = _RDWORD(0x00008004);          // Setup Program Counter
// _WDWORD(0xE000ED08, 0x00000000);   // Setup Vector Table Offset Register
}

Setup();                             // Setup for Running
</code>

When I download the code and execute the debugger I get a connection lost and the ULINK cant connect to the CPU.

Am I missing something? Something todo with the Memory Mapping Control register (MEMMAP register) loading some boot code?
Or do I have to have the bootloader code in the target for the debugger to connect?

Thomas
Labels (1)
0 Kudos
5 Replies

1,164 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Mon Nov 05 13:27:48 MST 2012
Rolf,

you are right. I missed this. Thank you for pointing this out.

Wolfgang
0 Kudos

1,164 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DF9DQ on Sun Nov 04 05:00:24 MST 2012
That's not the complete truth! :-)

You are right that there is a limitation to the address that can be set in VTOR. It can only start with a certain bit pattern:
000x xxxx xxxx ....  ("code space")
001x xxxx xxxx ....  ("SRAM space")
The base addresses of these two regions are 0 and 0x2000,0000, which you have mentioned.

However, within these two regions you can set VTOR to any 256-byte boundary (bits 7...0 are unused). The minimum required alignment depends on the number of interrupts implemented in the device. The LPC1700 has a total of 51 interrupts lines (system: 16, user: 35), where a 256-byte alignment suffices. The recommendation is to always align to a 1024-byte boundary, enough for the maximum of 240 user interrupts in a Cortex-M3 implementation.

In our case, setting VTOR to 0x8000 (start of sector 8) is perfectly valid, as it is in code space and more than sufficiently aligned.

Regards,
Rolf
0 Kudos

1,164 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Fri Nov 02 14:25:40 MST 2012
Please check the valid addresses for VTOR!

Only 0 and 0x20000000 are allowed.

For anything else, you have to set VTOR to 0x20000000 and copy the vector table to 0x20000000. Your runtime library may have a mechanism for copying a memory region at startup.
0 Kudos

1,164 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DF9DQ on Fri Nov 02 09:08:18 MST 2012
Hi Thomas,

I think the scatter file for the application should start like this:
<code>
; Load region is in internal FLASH, 512KBytes
FLASH 0x00008000 0x78000 {
  ; All code and RO data in in FLASH
  ER_RO 0x00008000 0x78000 {
    startup_ea1788.o (RESET, +FIRST)
    *.o (+RO)
  }
</code>

The code you show sets VTOR to 0, not 0x8000!
Your boot code should set VTOR to 0x8000 before jumping into the application:

<code>
SCB->VTOR = 0x00008000;
</code>

For the INI file this is:

<code>
FUNC void Setup (void) {
  SP = _RDWORD(0x00008000);
  PC = _RDWORD(0x00008004);
  _WDWORD(0xE000ED08, 0x00008000);   // VTOR=0x8000
}

Setup();
</code>

That's just a hint. I haven't tested anything... :-)

Regards,
Rolf

0 Kudos

1,164 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tjoAG on Fri Nov 02 02:35:45 MST 2012
Hi

When using the above "modification" the application works when bootloaded by the bootloader.

So it still a mystery: Why cant I use the debugger to run the application?

Thomas
0 Kudos