Skip to main content
Associate
January 29, 2026
Solved

can't write to external flash memory after erase, without reseting the board first

  • January 29, 2026
  • 1 reply
  • 267 views

I have a custom PCB with an STM32H563VGT6 microcontroller and an external Winbond W25Q16JVUXIQ NOR flash memory connected to the octoSPI's (XSPI) upper four pins. The problem is I can only write data to the flash memory after an erase, if I reset my board between the two operation. Everything the erasing, writing, indirect reading, memory mapped reading work on their own, but not after erase without reset. I read out all 3 status registers, they are the same before and after the chip erase. (Of course I set the write enable bit before trying to write into the memory) 
Any idea what could be the problem?

Best answer by RRichard

Hi @KDJEM.1 

I think I figured it out. I am checking the BUSY flag with autopolling after erase, and I am only proceeding when it becomes ready, it wasn't the problem.

I think this error was impossible for others to guess, because I didn't say I was uploading two programs after each other, because I didn't think it was important, but I will leave the solution here if someone runs into this niche error.

First I am using a program to load the pictures into the external flash for a graphical application. This code first erases the external flash and then loads the pictures into it. After this program is done, I am uploading a second program to the microcontroller, the main program that is responsible for the functionality of the device (this only reads the external flash, never writes anything into it). 

I think during second program's upload the microcontroller gets a reset and the previously uploaded program's first few lines including the external flash's chip erase is able to run again before the second program is uploaded. 

If I first use the external loader program, then I delete this program from the microcontroller with the STM32CubeProgrammer (chip erase on the internal flash) and only afterwards I upload the second program then it works fine and the pictures remain in the external flash.

So I thought the external flash write didn't work because the pictures were not in the external flash, but they just got erased again. And previously when I took the external load program apart to first only erase the external flash and then only write it, they remained in the external flash because even if the writing part rerun again during the main program's upload, it didn't matter.

Also correct me if I am wrong, but as far as I know memory-mapped NOR flash memory write is not possible with the HAL library. The reading works in memory-mapped mode, because you can randomly access any number of bytes anywhere with a single XSPI command.
But for writing you need to write the memory page by page (256 byte), send a new write enable command at every new page, and calculate the page's starting address every time. At the memory-mapped setup the HAL library only accepts a single XSPI command, so I don't think it can do the writing for NOR flash in memory-mapped mode. 


1 reply

KDJEM.1
Technical Moderator
January 29, 2026

Hello @RRichard and welcome to the community;

 

I think that the issue is due to incomplete erase operation.

Could you please check if the erase operation is completed correctly.

Do you encounter the same problem when using mapped memory writes and indirect writes?

 

Thank you.

Kaouthar

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
RRichardAuthorBest answer
Associate
January 29, 2026

Hi @KDJEM.1 

I think I figured it out. I am checking the BUSY flag with autopolling after erase, and I am only proceeding when it becomes ready, it wasn't the problem.

I think this error was impossible for others to guess, because I didn't say I was uploading two programs after each other, because I didn't think it was important, but I will leave the solution here if someone runs into this niche error.

First I am using a program to load the pictures into the external flash for a graphical application. This code first erases the external flash and then loads the pictures into it. After this program is done, I am uploading a second program to the microcontroller, the main program that is responsible for the functionality of the device (this only reads the external flash, never writes anything into it). 

I think during second program's upload the microcontroller gets a reset and the previously uploaded program's first few lines including the external flash's chip erase is able to run again before the second program is uploaded. 

If I first use the external loader program, then I delete this program from the microcontroller with the STM32CubeProgrammer (chip erase on the internal flash) and only afterwards I upload the second program then it works fine and the pictures remain in the external flash.

So I thought the external flash write didn't work because the pictures were not in the external flash, but they just got erased again. And previously when I took the external load program apart to first only erase the external flash and then only write it, they remained in the external flash because even if the writing part rerun again during the main program's upload, it didn't matter.

Also correct me if I am wrong, but as far as I know memory-mapped NOR flash memory write is not possible with the HAL library. The reading works in memory-mapped mode, because you can randomly access any number of bytes anywhere with a single XSPI command.
But for writing you need to write the memory page by page (256 byte), send a new write enable command at every new page, and calculate the page's starting address every time. At the memory-mapped setup the HAL library only accepts a single XSPI command, so I don't think it can do the writing for NOR flash in memory-mapped mode.