4
votes

I am using an stm32f40x microcontroller (UC), and I have to use its internal flash to store some data. The write operation, as you know, is very slow and occupies the UC for very long time. So I thought to DMA and here is the question:

Is it possible to use DMA to transfer data from SRAM to FLASH?

Thank you for your time.

2
Some specialized microcontrollers have a RAM area which is an image of the flash. Your program writes to the RAM and then the hardware takes care of burning it to flash. Possibly in combination with ECC. For such a part you should be able to DMA the data. I'm not sure if ST has something like that though. You should probably just look for a part with data flash ("emulated eeprom") - such flash has smaller segments that don't take an eternity to erase before programming. I know that several STM32 come with data flash.Lundin

2 Answers

8
votes

In short: No. At least not in a useful way.

Longer: The slow writing to flash is not caused by the CPU being so slow, but rather caused by time-consuming page write cycles to flash memory. (So, DMA isn't any faster). You can theoretically use DMA to write to flash (even if that is a bit tricky and has quite some pitfalls), but you won't gain any speed. Reason is, the CPU will be halted when it tries to access flash memory while it is written. Thus, the CPU will not be able to execute code from there while DMA writes it - No time gained.

The manual says:

Any attempt to read the Flash memory on STM32F4xx while it is being written or erased, causes the bus to stall. Read operations are processed correctly once the program operation has completed. This means that code or data fetches cannot be performed while a write/erase operation is ongoing.

That means executing code from any flash area while DMA runs to it is not possible - The CPU will be halted for that time period. You could, however, complicate things even more and copy parts of your code to RAM to execute it there to work around this.

Some of the F4 series have 4k of battery-backable RAM. Use that, it's much faster and much simpler to handle.

5
votes

Another possibility would be to use a dual-bank device with read-while-write capability. In these devices there are two banks of flash. It is possible to execute code from one bank while writing data to the second bank.