cancel
Showing results for 
Search instead for 
Did you mean: 

Flash Programming Problem

victor239955_st
Associate II
Posted on June 24, 2009 at 01:10

Flash Programming Problem

2 REPLIES 2
victor239955_st
Associate II
Posted on May 17, 2011 at 13:15

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.

Thanks

victor239955_st
Associate II
Posted on May 17, 2011 at 13:15

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