2024-10-01 09:39 PM - last edited on 2024-10-04 03:00 AM by Amel NASRI
Dear STM32 Community,
I am currently working on a project using the STM32F072RBT6 microcontroller, where I have implemented a custom bootloader to load an application program into flash memory. However, after the bootloader successfully writes the application binary, the stack pointer does not correctly jump to the application’s address, and the application fails to execute.
MCU Model: STM32F072RBT6 Bootloader
Functionality: The bootloader receives the application binary and writes it to flash memory at the designated application address.
Application Flash Address: 0x08004000
Problem: After the bootloader completes, I attempt to jump to the application by setting the stack pointer and program counter accordingly, but the application does not start. It appears that the stack pointer is not correctly set to the application's address.
Jump Code in Bootloader:
static void goto_application(void){
void (* app_reset_handler)(void) = (void *)(*(volatile uint32_t *) (0x08004000 + 4));
__disable_irq();
__set_MSP((*(volatile uint32_t *)0x08004000));
__enable_irq();
app_reset_handler();
}
Solved! Go to Solution.
2024-10-08 02:43 AM - edited 2024-10-08 02:44 AM
@MM..1 I hope you're doing well. However, I encountered an issue with the UART interrupt-based reception of the application binary.
Currently, I'm receiving the application binary via UART in an interrupt routine and writing it to the flash memory. Once the flashing process is complete, I attempt to execute the application code but problem was application not run.
microcontroller : STM32f072rbt6
FLASH MEMORY = 128KB
In bootloader linker script file :- FLASH (rx) : ORIGIN = 0X08000000, LENGTH = 24K
In application linker script file :- FLASH (rx) : ORIGIN = 0X08005000, LENGTH = 42K
2024-10-08 02:55 AM
Hope you change 4000 to 5000 in your code , but you still skip normal testing operation for locate trouble.
info application not run is ok for magic crystal ball. After UART write full next step is check with STLINK read and compare if code is in place OK.
2024-10-08 03:08 AM
@MM..1 thank you for your response.
Yes, I have changed the code from 4000 to 5000. Regarding the testing, I have now conducted the normal testing operations, and everything is working fine.
After performing the UART write, I also used STLINK to read and compare the code. The flash application .bin file matches the original .bin file with no differences, so the code is in place and functioning as expected.
Let me know what should i do ? .
2024-10-09 04:30 AM
Dear STM32 Community,
I hope this message finds you well. I wanted to take a moment to express my sincere thanks to everyone who contributed their time and expertise to help me with my issue. I’m happy to report that I’ve successfully solved the problem!
The issue was related to the HAL_Delay function in my application code. I was using HAL_Delay incorrectly, which caused my application code to get stuck. After going through the suggestions and feedback from the community, I was able to identify and resolve the root cause.
Thank you once again for your invaluable support and insights. I appreciate being part of such a knowledgeable and helpful community!