💡 We made explanation earlier u can check this link (https://github.com/Rabie45/Bootloader_STM32F303RE)
- The task is to create a program start with application with multiple options one for bootloader command and the other for user application to something like that we would use Flash module organization used before create multiple section in memory each section is full program it self (vector table + system init + main) once the program start choose the program u want and the bootloader will through u to the starting address holding this program
- the figure show the addresses of each program and how to mange the space
And this is the workflow
- initialize GPIO
- initialize UART2
- Check if the button is pressed this mean go to bootloader mode to change UserApp
- not pressed go to default user app This program starts with default memory section which is 0x8000000
-
pretty simple
-
initialize GPIO
-
initialize UART2
-
toggle the LED print this word over UART "Hey from user data:Toggling" This program starts with memory address 0x8008000
Dont forget to relocate VTOR (vector table register ) to new address 0x8008000
-
After loading each program in memory the bootloader program will start with default user app printing the line
-
If the button is pressed the bootloader will go to to something then go to userapp program address
-
void UserApp_Mode() in bootloader responsible to to this
uint32_t MSP_VAL=*(volatile uint32_t * )(FLASH_PAGE2_0x08008000U) //get the memory address to load in MSP
__set_MSP(MSP_VAL); // use this fuction to set the MSP value
uint32_t resetHandler =*(volatile uint32_t *)(FLASH_PAGE2_0x08001800U +4 ); // alwayes the next instruction is the Reset handler
appHandler=(void*) resetHandler;
appHandler(); // Call the function