5 years, 5 months ago.

Error in jumping from BootLoader to Application

Hi, I am working on a bootloader which jumps to the application after some verification. I am working on a STM32L475 device and STM32Cube IDE. It is an ARM M4 Cortex. My bootloader starts at 0x8000000 and has a size of 48K whereas the Application starts at 0x800C000 and has a size of 464K. The total Flash Memory available for use on the device is 512K. I have also disabled these lines of code in SystemInit():-

  1. ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
  2. else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */#endif

which basically prevents the VTOR to overwrite the addresss to 0x00.

This is my main code:-

int boot_main(void) {

pFunction appEntry; uint32_t appStack;

/* Check if firmware update required */ if(checkFirmwareUpdate()) {

/* Perform the update */ performFirmwareUpdate();

}

int va = Verify_Application(); Verify Application

if(va==0)If Application not verified, exit from the bootloader return 0;

/* Get the application stack pointer (First entry in the application vector table) */ appStack = (uint32_t) *((IO uint32_t*)APPLICATION_ADDRESS);

/* Get the application entry point (Second entry in the application vector table) */ appEntry = (pFunction) *(IO uint32_t*) (APPLICATION_ADDRESS + 4);

/* Reconfigure vector table offset register to match the application location */ SCB->VTOR = APPLICATION_ADDRESS;

/* Set the application stack pointer */ set_MSP(appStack);

/* Start the application */ appEntry();

while(1);

}

So when I debug, I find that the appStack and appEntry() both contain a non-accessible memory address value of 0x462821A0‬ and not the desired value of 0x0800C000. Can anyone explain why is it happening or am I missing something out?

Thanks

1 Answer

5 years, 5 months ago.

Same/Similar problem here.

The point I don't understand and might be the problem: Why is the casting and dereferencing *((IO uint32_t*) necessary anyway? In fact when I debug my code with APP_ADDR 0x08010000 and execute the similar line: appStack = (uint32_t) *((IO uint32_t*)APP_ADDR ); What I get is appStack == 0x080279C5 instead of estimated 0x08010004. But there must be some necessity of doing it, because without the casting it's not working either and it's in all ST examples.

I also tried with extra cast inside the calculation, without success: appStack = *((IO uint32_t*)((uint32_t)(APP_ADDR + 4)))

When I readback the MCU code, I programmed the application starting at 0x08010000 and bootloader code starting at 0x08000000...only the jump doesn't work (yet)

Regards, Alex

Accepted Answer