2009-06-23 04:10 PM
Flash Programming Problem
2011-05-17 04:15 AM
Hi Everyone,
I'm having problems with flash programming in my current project. The project is based on the STM32F103RB and uses a two stage bootloader to load the main code into flash. The first bootloader is small and is located at the beginning of flash. It is used to download the second (larger) bootloader into RAM. This second stage bootloader is used to download the main program and store it in flash after the first stage bootloader. My problem is as follows: The first stage bootloader successfully downloads the second stage bootloader into RAM. Interrupts are then disabled, NVIC de-initialized and control passed to the second stage bootloader using this code: __asm void RunProgram( u32_t StartAddress ) { LDR r13,[r0,#0] LDR r0, [r0,#4] BX r0 } The second stage bootloader performs the normal startup sequence, re-initializes the NVIC to it's own vector table, and unlocks the flash. It then runs and downloads the first block of the main program. When it tries to erase the flash page, it fails with a timeout error. If the second stage bootloader is downloaded and run via the debugger, it works fine, downloads the main code, burns it to flash and executes it OK. Similarly if this bootloader is downloaded via the first stage bootloader, then started via the debugger, it works fine. In summary, if the second stage bootloader is run from the debugger, regardless of how it is loaded into RAM, it works fine. If it is run from the first stage bootloader, it starts OK, downloads the first block but fails to erase the flash page. All the flash routines are taken from the ST library. Any suggestions will be most welcome. Thanks2011-05-17 04:15 AM
Solved!
The HSI was ON during debugging but OFF when running normally. According to the Flash Programming Manual PM0042: For write and erase operations on the Flash memory (write/erase), the internal RC oscillator (HSI) must be ON. Thanks