cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to overwrite the external flash memory from itself?

Alex777
Associate II

Hello everyone! I have a STM32H750VBT6 controller with external W25Q128 QSPI memory.

The bootloader starts from address 0x080000000, initializes the flash in memory mapping mode and starts the main program from 0x900000000.

There was a need to update the data in the external memory. Since the update must be done via Ethernet, this amount of code will not fit in the 128k flash. Question: is it possible to put the code that directly clears the memory and writes, for example, in the address 0x080100000 and use it there.

How to properly disable execution from SPI for the duration of work from the address 0x080100000, and then return to the same place from where the jump function was called.

Or will this not work?

Ext Flash RW.png

6 REPLIES 6

The memory mapping operation (XIP) can't operate concurrently with the slower "erase, wait, write, wait" operations.

You need to QSPI Abort to break it back into command mode, and not call functions, interrupts, etc that dwell in the QSPI memory space. When done push in the memory mapped command template again.

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

How can I interrupt the operation of spi if code is being executed from it? I tried calling SPI de-initialization and then calling the function at 0x0801XXXXX. After entering the function, the following command results in a HardFault.

You'd need all the code, call-trees, interrupts to be in RAM or Internal Flash whilst you're interacting with the QSPI content.

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

Since the update must be done via Ethernet, this amount of code will not fit in the 128k flash.

128K is quite much. If the ethernet stuff is done properly & sparingly, it may very well fit in the 128K.

The code to initialize QSPI flash is already there, adding some code to move the app image can fit too.

H750 has a large internal RAM (at least 512K) that can be used for the ethernet and update code as well.

In this 16Mbytes flash chip, do you have space to store the new image?

I wanted to record data without restarting the controller.
Will it be possible to prohibit interrupts, call the write function from the internal memory of the processor, and then go back, allow interrupts and continue working?


SCB_Disable cache();
SCB_Disable cache();
Disable Interrupts();

u08 w_err = write_flash(w_data, addr, len);

SCB_EnableD Cache();
SCB_Enablecache();
Enable Interrupts();

Where write_flash() is located at 0x080XXXXX.

When entering the write_flash function, we fall into HardFault at the first step. What am I doing wrong?

The project is large, SSL, MQTT, mbetTLS are used, so the RAM is all occupied.

Pavel A.
Evangelist III

Yes, should be possible. To prevent touching the flash area while it is erased, use MPU. But RAM occupied - this is a problem. Whenever you say "HardFault" be sure to investigate and find the actual reason (google...) then we can think of a solution.