2017-08-31 07:29 AM
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.
2017-08-31 07:49 AM
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.
2017-08-31 10:11 AM
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!
2017-08-31 11:11 AM
>>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.
2017-09-01 05:27 AM
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.
2017-09-01 10:00 AM
Change 0x08000000 in these posts with your APPLICATION_ADDRESS
2017-09-01 10:09 AM
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.
2017-09-01 10:25 AM
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();
2017-09-04 01:31 AM
The jump to my application is after the vector relocation or before?
Thank you!