9 years, 4 months ago.  This question has been closed. Reason: Duplicate question

stm32f411 building, flashing, and using bootloader+application

Hi all, I've trying to get a bootloader and application setup running on a stm32f411 processor so I can remotely update the firmware on the processor. Here's what I'd like to do...

I want to build a bootloader and application separately using the offline SDK, then combine those 2 binaries into a single binary. I plan to eventually automate this process so that every time I build for this platform, I get a binary that has the bootloader and the application. The reason for this is so that I can update the device via the bootloader OR the drag-and-drop interface and have the same result in both cases (the entire microcontroller's flash gets updated, but the new binary always contains the bootloader and the application).

I have an external flash part connected to the processor, so the problem of storing and loading firmware is already solved. I've read that it is possible for the microcontroller to flash itself, so I'm not worried about that at the moment either.

Right now I'm just trying to get a simple bootloader and application built, combined, and running properly on the microcontroller. I want to use the first 32kB of the flash for the bootloader and the other 480kB for the application.

I should say I'm currently working with the GCC_ARM toolchain.

The relevant part of my bootloader is as follows:

#define APPLICATION_ADDRESS     0x08008000

typedef void (*ptr)(void);
ptr jump;
uint32_t addr;

log("set stack pointer");
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
log("set address");
addr = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
jump = (ptr) addr;
log("JUMP");
jump();

My application code is very simple. It sits in a while loop and writes to the debug port and blinks an LED.

I'm currently tweaking the linker script when I build both the bootloader and the application: I believe I need to configure the linker script to define the memory regions differently for the bootloader and the application.

For the bootloader, I've got:

/* Linker script to configure memory regions. */
MEMORY
{ 
  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
/*  CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K */
  RAM (rwx) : ORIGIN = 0x20000198, LENGTH = 128k - 0x198
}

For the application, I have:

/* Linker script to configure memory regions. */
MEMORY
{ 
  FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 480K
/*  CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K */
  RAM (rwx) : ORIGIN = 0x20000198, LENGTH = 128k - 0x198
}

The script was originally:

/* Linker script to configure memory regions. */
MEMORY
{ 
  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
/*  CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K */
  RAM (rwx) : ORIGIN = 0x20000198, LENGTH = 128k - 0x198
}

I'm combining the binaries using a python script. It copies the bootloader binary into a new file, pads the file with 0xFF up to 32kB - bootloader binary size, then copies in the application binary so the application starts at the 32kB mark.

When I flash and run this combined binary, I see the prints from the bootloader, but nothing from the application. Am I setting up my linker script correctly for both parts? Am I combining the 2 binaries correctly?

Thanks, Mike

I ended up discovering the issue! I found a ST application note on this and realized I was missing a step.

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00036049.pdf

The application needs to either make a call to NVIC_SetVectorTable(<APPLICATION_ADDRESS>) or #define VECT_TAB_OFFSET=<APPLICATION_ADDRESS>.

posted by Mike Fiore 12 Jan 2015

Hi,

Glad to see you have solve this problem. Can you please move this question in "Answered" or "Close" state ?

Thanks.

posted by bco stm 18 Mar 2015

Hi , Dear Mike , if you share us the code we can also learn a lot from your awesome experiment the nucleo boards..

Thanks

posted by Naganand V 11 May 2015

1 Answer

9 years, 2 months ago.

Hi,

Glad to see you have solve this problem. Can you please move this question in "Answered" or "Close" state ?

Thanks.

Accepted Answer