I am currently writing a bootloader for the CC2652 and I am new to this so my apologies in case I missed something very obvious.
As far as I know in order to jump to another application you have to do three things
- Change the Vector Table Offset Register
- Change the Stack Pointer
- Change the Program counter
However when trying to write to the Vector Table Offset Register (VTOR) I end up in FaultISR() from which I can see in the CFSR (Configurable Fault Status Register) that the IMPRECISERR bit is set indicating an imprecise buss error. I change the register from an SVCall handler which means I should be in Privileged mode, right? I added my code for jumping to the other application, a description of the IMPRECISERR bit and the paragraph about changing the VTOR from the Technical Manual below.
Code:
void svcallIRQ(void) { typedef void (*p_function)(void); uint32_t jump_address = *(volatile uint32_t*)(FIRM_OFFSET + 4); // FIRM_OFFSET = 0x2E000 p_function p_jump_function = (p_function) jump_address; __disable_irq(); uint32_t *vtor = (uint32_t*)CPU_SCS_O_VTOR; // CPU_SCS_O_VTOR = 0x00000D08 *vtor = ((uint32_t )FIRM_OFFSET); // change vector table offset to first bytes of firmware __NOP(); // The error occurs after this NOP __NOP(); __NOP(); __DSB(); __set_MSP(*(volatile uint32_t*) FIRM_OFFSET); p_jump_function(); }
IMPRECISERR:
Imprecise data bus error. It is a BusFault, but the Return PC is not related to the causing instruction. This is not a synchronous fault. So, if detected when the priority of the current activation is higher than the Bus Fault, it only pends. Bus fault activates when returning to a lower priority activation. If a precise fault occurs before returning to a lower priority exception, the handler detects both IMPRECISERR set and one of the precise fault status bits set at the same time. BFAR is not written.
VTOR Description:
On system reset, the vector table is fixed at address 0x00000000. Privileged software can write to the Vector Table Offset register (CPU_SCS:VTOR) to relocate the vector table start address to a different memory location, in the range 0x00000200 to 0x3FFFFE00. When configuring the CPU_SCS:VTOR register, the offset must be aligned on a 512-byte boundary.