cancel
Showing results for 
Search instead for 
Did you mean: 

How Read-while-write operations are performed on the STM32F413 chip?

AAlex.8
Associate II

Hi,

As I understand, the STM32F413 MCU doesn't have dual-bank architecture, but I'm still able to perform read-while-write (RWW) operations without causing the CPU to stall.

I have a little experience of working with the chips that don't have an internal Flash, and in order to perform RWW operations I had to put the particular parts of code into RAM.

I feel that I have a lack of knowledge on the subject, so can anyone please explain how the F413 chip handles RWW operations?

5 REPLIES 5

Are you talking about FLASH programming?

The whole problem with FLASH programming is, that during programming you cannot read from it. It means, that whatever code you want to run during FLASH programming - and that includes every interrupt handler which can be called in that time - has to run from RAM.

JW

TDK
Guru

You can read and write to flash at the same time, although the CPU may stall a few cycles under heavy use, which is typically not an issue. Erasing while also reading will block the CPU for considerably longer, perhaps that's what you mean.

If you feel a post has answered your question, please click "Accept as Solution".
ssipa.1
Associate II

Hi Alex

You can use the following code for writing data to flash with the HAL library.

void Write_Flash(uint8_t data)

{

HAL_FLASH_Unlock();

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );

FLASH_Erase_Sector(FLASH_SECTOR_6, VOLTAGE_RANGE_3);

HAL_FLASH_Program(TYPEPROGRAM_WORD, FlashAddress, data);

HAL_FLASH_Lock();

}

Erasing a whole sector to write one word, doesn't seem like the most quick and efficient method, and will cause very long stalls. The OP wants to avoid that, and understand use of RAM, etc.

As @TDK mentions the real performance killer here is the ERASE, the single write, while it can stall, is probably survivable..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

> You can read and write to flash at the same time

Well, you can't.

0693W00000JNsGoQAL.png 

> the CPU may stall a few cycles

Typical word programming time of 'F413 is 16us (max. is 100us). At 100MHz system clock, that's 1600 cycles. I personally wouldn't call that "a few".

JW