cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 cortex jump to application

Giu S
Associate II
Posted on August 31, 2017 at 16:29

Hello to all, I need to write the bootloader for a cortex M0. Could someone explain to me what I have to do. What are the code that I have to write and how I have to modify the linker and the sturtup .s file? In the forum I find many different solution, but at the moment no one works. I read that in the M0 processor is not possible to relocate the vector table, but I don't understand what I have to do. Thank you very much in advanced.

8 REPLIES 8
Posted on August 31, 2017 at 16:49

Indeed, custom bootloader related questions seem to be the most popular ones here. There are several very informative posts written by

Turvey.Clive.002

‌ and others describing the technique and demonstrating the code. If you want something more official then there are example projects provided by ST too.

1. Install STM32CubeMX, install the latest F0 library

2. Find where is located your repository directory by opening the 'Help -> Updater settings...' menu item

3. You will find two projects inside your repository in 'STM32Cube_FW_F0_V1.8.0/Projects/STM32091C_EVAL/Applications/IAP'

One of those projects is the example bootloader, and the other one is the example application. Examine their source code to understand how it works.

Posted on August 31, 2017 at 17:11

Ok, thank you very much. I found it! I have a question now. I have to do a CAN bootloader so if I understand good I have to write the code of the CAN bootloader in this 'if':

if

(

BSP_PB_GetState

(

BUTTON_TAMPER

) ==

GPIO_PIN_RESET

)

{

/*

Initialise

Flash */

FLASH_If_Init();

/* Execute the IAP driver in order to reprogram the Flash */

IAP_Init();

/* Display main menu */

Main_Menu ();

}

............

and I have to write my application in the while(1) after the else. It's correct?

If this is correct I don't understand how my application code is stored after the APPLICATION_ADDRESS.

Could someone explain this to me?

Thank you very much!

Posted on August 31, 2017 at 18:11

>>I don't understand how my application code is stored after the APPLICATION_ADDRESS.

You configure your tool chain's linker to build the code at that address, either via the GUI, or scatter file, or linker script.

Your loader needs to store the downloaded image there.

The Cortex-M0 will need you to build a new vector table in RAM, typically by copying the one built by the linker to the base of RAM at 0x20000000, and then use the STM32 specific mapping register to map/shadow RAM at zero.

The CM0+ does provide the SCB->VTOR Vector Table mapping register, and this can be used instead.

Get an understanding of the CPU have chosen, read the docs so you have some grasp of how it functions with respect to your existing knowledge of micro-controllers.

Then understand the features/functions of your chosen STM32 part (not specified) by reviewing the Data Sheet and Reference Manual with respect to the knowledge gained above.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 01, 2017 at 12:27

Ok, thank you for your reply. I try to take a look in the two IAP example projects. But it doesn't work.

Then, why in one of this projects there is the vectortable relocation and in the other there is only the jump to application. 

Sorry for my question but is my first time use with this microcontroller. I try to read the documentation, but is difficult for me to write code that make what I want. It seems that doesn't work correctly.

Posted on September 01, 2017 at 17:00

Change 0x08000000 in these posts with your APPLICATION_ADDRESS

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 01, 2017 at 17:09

Ok, and the jump to my application code how is made? I have to modify the linker script too?

Thank you very much for your help.

Posted on September 01, 2017 at 17:25

Something along the lines for setting a function pointer, and calling it. User a debugger and step execution to follow the transfer

// Your Loader Code transferring control to Application Code

AppJump = (void (*)(void)) (*((uint32_t *)(APPLICATION_ADDRESS+4))); // Initial PC [+4]

__set_MSP(*((uint32_t *)APPLICATION_ADDRESS)); // Initial SP [+0]

AppJump();

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 04, 2017 at 08:31

The jump to my application is after the vector relocation or before?

Thank you!