AnsweredAssumed Answered

Jumping to custom bootloader

Question asked by waters.mark on Jan 21, 2013
Latest reply on Jan 22, 2013 by Uwe Bonnes
Chip: STM32F4
Toolchain: Atollic

I have a custom bootloader at 0x08000000, and regular code at 0x0800C000.  On boot, the bootloader checks for a valid image and then jumps to regular code:

     typedef void (*pFunction)(void);

     pFunction JumpToApplication;
     uint32_t jumpAddress;

     // Initialize the user application Stack Pointer
     __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

     // Jump to the user application
     // The stack pointer lives at APPLICATION_ADDRESS
     // The reset vector is at APPLICATION_ADDRESS + 4
     jumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
     JumpToApplication = (pFunction) jumpAddress;

This works as expected.  However, I need to jump back to the bootloader from the main application.  This is where I'm running into trouble.  I'm trying to jump to mainFromUserSpace().  Here is part of my map file:

                0x080004c4       0x30 src\main.o
                0x080004f4       0xc8 src\main.o
                0x080005bc       0x14 src\main.o

The function I'd like to jump to is mainFromUserSpace, so it looks like I want 0x080004f4 as my address, but this results in a hard fault:

     typedef void (*pFunction)(void);

     pFunction JumpToBootloader;
     uint32_t jumpAddress;

     // Initialize the bootloader Stack Pointer
     __set_MSP(*(__IO uint32_t*) 0x08000000);

     // Jump to the bootloader
     jumpAddress = *(__IO uint32_t*) (0x080004f4);
     JumpToBootloader = (pFunction) jumpAddress;

I only see one difference between the two jumps.  The bootloader jumps to the reset vector for the user code while the user code jumps to an individual function in bootloader space.  Am I setting this up properly?