cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 Flash Write Fails

harisuvarna
Associate II

Hi ,

I am writing multiple chunk of each 48 bytes to Flash by following flash programming sequence mentioned in STM32 U5 Reference manual. However some chunks are written properly where some chunks are still remains 0xFF. Please let me know if anybody encountered similar kind problem.

Flash programming
The Flash memory programming sequence is as follows:
1.Check that no Flash main memory operation is ongoing by checking the BSY bit in the FLASH non-secure status register (FLASH_NSSR) or FLASH secure status register (FLASH_SECSR).
2. Check that the write buffer is empty by checking the WDW bit in the FLASH non-secure status register (FLASH_NSSR) or FLASH secure status register (FLASH_SECSR).
3. Check and clear all error programming flags due to a previous programming. If not, PGSERR is set.

Set the PG bit in the FLASH non-secure control register (FLASH_NSCR) or FLASH secure control register (FLASH_SECCR).
5. Perform the data write operation at the desired Flash memory address, or in the OTP area. Only a quad-word can be programmed and OTP can be only programmed in non-secure access:
– Write a first word in an address aligned on a quad-word address. The WDW bits in
the FLASH non-secure status register (FLASH_NSSR) and FLASH secure status
register (FLASH_SECSR) are set to indicate that more data can be written in the
write buffer.
– Write the second, third and fourth word in the same quad-word.
6. The BSY bit gets set. WDW is reset automatically.
7. Wait until the BSY bit is cleared in the FLASH non-secure status register (FLASH_NSSR) or FLASH secure status register (FLASH_SECSR). The software must make sure that BSY is set or WDW is cleared before waiting for BSY to get cleared.
8. If the EOP flag is set in the FLASH non-secure status register (FLASH_NSSR) or FLASH secure status register (FLASH_SECSR) (meaning that the programming operation has succeeded and the EOPIE bit is set), it must be cleared by software.
9. Clear the PG bit in the FLASH non-secure control register (FLASH_NSCR) or FLASH secure control register (FLASH_SECCR) if there is no more programming request.

 

Regards,

Hareesha

2 REPLIES 2
harisuvarna
Associate II

One more thing I observed is that ,

BSY flag never sets when WDW bit is cleared to initiate the programming process. But still sometimes data is written to flash. Please clarify.

TDK
Guru

Are you writing to flash word-aligned areas?

Show your code and show the results of it in flash. Likely some clues can be obtained by what portions are written vs which ones are still at 0xFF. Note that you can only write to a flash word once before it must be erased.

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