writing to internal flash memory

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

writing to internal flash memory

Post 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.c
https://svn.code.sf.net/p/rusefi/code/trunk/firmware/controllers/flash_main.cpp

PS: if only ChibiOS had a flash driver... :)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: writing to internal flash memory

Post 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
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: writing to internal flash memory

Post by russian »

But 2 seconds to write just 8Kb? Is the the expected speed?
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: writing to internal flash memory

Post 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!]
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: writing to internal flash memory

Post by mobyfab »

on the F4 the sectors at the end are quite big (128k) so it can take a very long time to erase.
Jeroen3
Posts: 35
Joined: Wed Apr 02, 2014 10:14 am

Re: writing to internal flash memory

Post 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.
Post Reply