AnsweredAssumed Answered

STM32F303RE Nucleo custom bootloader jumping to application not working

Question asked by Steve Neves on May 31, 2018
Latest reply on Jun 1, 2018 by Clive Two.Zero

I've been going through numerous old posts that ask similar questions however I'm seeing something slightly different then everyone else.


I've written bootloaders before for Kinetis MCU's which I had hoped to essentially tweak and bring forward.  The only real difference I've noticed is the flash location is set to 0x08000000.  Very small wrinkle but easy enough to deal with.


I have two separate linker files (I'm using Atollic 9.0's GCC compiler for what it's worth) with the bootloader starting at:

RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 64K
CCMRAM (rw)      : ORIGIN = 0x10000000, LENGTH = 16K
FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 32K

and the Application's:


RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 64K
CCMRAM (rw)      : ORIGIN = 0x10000000, LENGTH = 16K
FLASH (rx)      : ORIGIN = 0x8008000, LENGTH = 480K /* Offset 32K for bootloader */


I've decided to keep the vector table in flash so there are two instances of it in flash (from system_stm32fxx.c):

#define VECT_TAB_OFFSET  0x8000 /*!< Vector Table base offset field.
                                  This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET  0x0 /*!< Vector Table base offset field.
                                  This value must be a multiple of 0x200. */


I'm sharing files so the application will obviously grab the correct define.  However do not pay much attention to this as the application for some reason never gets here.


I looked at my flash image dump and verified that at 0x08000000 (0x00000000 relative to the binary) we have 0x20010000 and at 0x08000004 we have 0x08000F29.  I looked into the memory map for this bootloader portion and verified that is where the reset handler lives:

                0x08000f28       0x50 bin/startup_stm32f303xe.o
                0x08000f28                Reset_Handler


This stage works fine.  The bootloader launches.


The jump logic is pretty cookie cutter compared to what I've seen on this forum and the IAP example:



/* Private variables ---------------------------------------------------------*/
//typedef  void (*pFunction)(void);
//pFunction JumpToApplication;
//uint32_t JumpAddress;
#define APPLICATION_ADDRESS           ((uint32_t)0x08008000)
//uint32_t AppAddress = APPLICATION_ADDRESS;


void FirmwareUpgrade_JumpToApp(void)
    SysTick->CTRL = 0;
////    Set SP and PC
            "ldr r0, =0x8008000\n\t"
            "ldr sp, [r0]\n\t"
            "ldr r0, =0x8008004\n\t"
            "ldr pc, [r0]\n\t"
//    /* Jump to user application */
//    JumpAddress = *(__IO uint32_t*) (AppAddress + 4);
//    JumpToApplication = (pFunction) JumpAddress;
//    __disable_irq();
//    /* Reconfigure vector table offset */
//    SCB->VTOR = AppAddress;
//    /* Initialize user application's Stack Pointer */
//    __set_MSP(*(__IO uint32_t*) AppAddress);
//    JumpToApplication();


Don't mind the mess, it's essentially two ways of performing the same task.  Neither seems to do the trick and both send me to the same location which is where I'd assume I want to go which is 0x0800C379.  The same bin dump as mentioned above shows at offset 0x8000 we have the same 0x20010000 for the top of the stack and 0x0800C379.  Confirming with the map file for the upgrade image we see:

                0x0800c378       0x50 bin/startup_stm32f303xe.o
                0x0800c378                Reset_Handler


At this point I'm pretty confused.   Previously in my Kinetis days I accomplished all this virtually in an identical fashion expect rather than offset the second vector table for the upgrade image, I just threw it in RAM.  That process doesn't seem to be as straight forward and RAM is more of premium in this particular project. 


Just to clarify, I do not hard fault.  The application is just out there in the weeds even though the PC register and SP register are exactly what I want them to be.


Thanks in advance for any help you guys may give me.