Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Cortex-M3 STM32F103 core stall during a flash page erase because the FPEC is busy and can't fetch any more instructions from flash?

On the STM32F103, the erasing of a flash page takes 20ms during which the core stalls for me. It's not clear from the ST PM00042 Flash programming manual whether the core would always stall when erasing a flash page or whether it just stalls because the instruction stream itself is in flash memory (in my project) and the FPEC (the flash memory interface) is busy and can't fetch more instructions.

Another way to ask this question is "would running my flash programming code from RAM avoid the flash page erasing stall?".

Thanks,

like image 836
Captain NedD Avatar asked Aug 10 '10 02:08

Captain NedD


1 Answers

I believe that during flash programming, any attempted access to flash will stall the CPU.

So what you want to do is ensure that the critical code (maybe interrupt handlers, watchdog kicker, etc) can be run out of RAM during a program operation. The last time I used the STM32 (probably ~2 years ago) that's exactly what I did.

So just to be clear, to answer the question at the end of your post:

Another way to ask this question is "would running my flash programming code from RAM avoid the flash page erasing stall?".

I believe the answer is "no". It doesn't matter so much where the flash programming driver is located, what matters is what your code does while the erase / program operation is in progress. If the CPU tries to access flash during an operation, even to read instructions for your program or read a table of constants, I believe it will stall.

I know for a fact that this is how the NXP flash works on their ARM uCs, but I wanted to cite chapter & verse for the STM32 as well. For some reason, the flash programming manual seems to be unavailable right now, but I found the following language in a similar document (PM0068, I believe):

An ongoing Flash memory operation will not block the CPU as long as the CPU does not access the Flash memory.

and

If a read/write operation [to flash] is initiated during programming, (BSY bit set), the CPU stalls until the ongoing main Flash memory programming is over.

like image 119
Dan Avatar answered Dec 10 '22 21:12

Dan