cancel
Showing results for 
Search instead for 
Did you mean: 

Jumping to custom bootloader

order
Associate
Posted on January 21, 2013 at 20:33

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;

JumpToApplication();

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:

 .text.NVIC_SystemReset

                0x080004c4       0x30 src\main.o

 .text.mainFromUserSpace

                0x080004f4       0xc8 src\main.o

 .text.SendUartByte

                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;

JumpToBootloader();

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?

#stm32f4-bootloader
3 REPLIES 3
Posted on January 21, 2013 at 20:47

Am I setting this up properly?

No. You're loading the address indirectly, and the address of 16-bit Thumb code is always ODD, the Cortex-M3 can't execute ARM code at EVEN addresses, and will Hard Fault. Personally to get back to the boot loader I'd probably just reset the processor, as there is less potential to get it in a screwed up state. Figure clocks, interrupts, vectors, etc.

// Jump to the bootloader
jumpAddress = (uint32_t) 0x080004f5; // 0x4f4 + 1
JumpToBootloader = (pFunction) jumpAddress;
JumpToBootloader();

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
order
Associate
Posted on January 22, 2013 at 02:28

Ah, the ''odd'' address has solved the problem.  Thanks for the help.

Uwe Bonnes
Principal II
Posted on January 22, 2013 at 11:58