Page 1 of 1
writing to internal flash memory
Posted: Fri Jul 25, 2014 12:18 am
by russian
I am using
viewtopic.php?f=14&t=820 code to write stuff into internal flash, it works but there is a performance issue: writing 8KB of data freezes the whole application for ~2 seconds - meaning all threads are stopped.
Is there a fundamental hardware reason why the whole chip would be suspended while I am updating the flash? I think I am not locking anything on the Chibi level yet somehow all threads are frozen for a second.
https://svn.code.sf.net/p/rusefi/code/trunk/firmware/hw_layer/flash.chttps://svn.code.sf.net/p/rusefi/code/trunk/firmware/controllers/flash_main.cppPS: if only ChibiOS had a flash driver...

Re: writing to internal flash memory
Posted: Fri Jul 25, 2014 7:42 am
by Giovanni
It is an HW reason, while you are programming/erasing the flash you cannot execute from the same flash. It is not matter of having a dedicated driver for that.
Some microcontrollers have a dedicated data flash (SPC5xx

) but not the STM32F4.
Giovanni
Re: writing to internal flash memory
Posted: Fri Jul 25, 2014 10:54 am
by russian
But 2 seconds to write just 8Kb? Is the the expected speed?
Re: writing to internal flash memory
Posted: Fri Jul 25, 2014 1:45 pm
by steved
russian wrote:But 2 seconds to write just 8Kb? Is the the expected speed?
Quite possible. It will depend on a number of things, including the physical location of the block of flash, and the extent to which the flash write routines are optimised for the F4.
Flash is divided into sectors, and IIRC you have to erase a complete sector before you rewrite the data. This can take from 250ms to 2400ms dependent on sector size.
You then have to reprogram the entire sector, at 16 to 100us per 32-64 bytes.
If your block of data crosses a sector boudary, the programming time is roughly doubled.
[Based on quick read of F4 data - might easily have missed something - but writing to flash is certainly slow!]
Re: writing to internal flash memory
Posted: Fri Aug 01, 2014 2:44 pm
by mobyfab
on the F4 the sectors at the end are quite big (128k) so it can take a very long time to erase.
Re: writing to internal flash memory
Posted: Mon Aug 04, 2014 9:47 am
by Jeroen3
Have you tried the Flash modules in the STM32F4xx_StdPeriph_Driver package?
It looks complete, and introduces no noticable delay when writing a few bytes to one of the first smaller sectors.
Not sure if other threads will be affected while running, since the flash part is in syslock anyway.