1
votes

Question: - how to locate application to non 0x0000.0000 address? Processor: NXP LPC1768 Dev system: Keil ARM 4.73

Steps used: 1) scatter file below used to set load region and execution region to 0x0000.2000 2) copied vector table to 0x2000 3) udpated vtor register to 0x2000

Problem: Application does not run.

Scatter file used:
LR_IROM1 0x00002000 0x00000D000     
{   ; load region size_region
  ER_IROM1 0x00002000 0x0000D000    
  { ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }
  RW_IRAM1 0x10000000 0x00008000    {   ; RW data
   .ANY (+RW +ZI)
  }
}

This follows instructions specified in NXP app note AN10744, something else I’m missing?

1

1 Answers

1
votes

Vector Table Offset Register (VTOR) points to 0x00000000 at reset. Thus, stack pointer must be at 0x00000000, and program start address (program counter) at 0x00000004.

If you change the location of the vector table in linker settings, you need to update VTOR to point to this new location. This can only happen at runtime.

This means that you need to have a small bootloader program which does the remapping, which means that first sector must be reserved for that purpose.

Bootloader needs to:

  1. Make sure that interrupts are disabled, so you don't accidentally use VTOR.
  2. Update VTOR register to address 0x2000.
  3. Get stack pointer address from 0x2000 and update stack pointer register.
  4. Get program start address from 0x2004 and update the program counter.

You might want to check out CMSIS library, it has functions like NVIC_SetVTOR and __set_MSP which make setting these registers a little easier.

To set the program counter, you can cast the address to function pointer and then call the function:

uint32_t * vtor = (uint32_t *)0x2000;
uint32_t startAddr = vtor[1];
( (void(*)(void))startAddr )(); // Cast and call