简体   繁体   中英

DMA to Flash for STM32

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM