cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WLE5 cannot write to FLASH

Foreen
Associate III

Hello,

I'm encountering an issue when trying to write data to the flash memory on the STM32WL5C8U6. I'm using the official driver implementation (V1.3.1) and the following sequence of commands:

  1. HAL_FLASH_Unlock()

  2. FLASH_Program_DoubleWord(0x08030000UL, <data>)

  3. HAL_FLASH_Lock()

The problem is that the data is only written to flash the first time I run this sequence on the chip. On subsequent attempts, no data is written. I’ve also tried calling FLASH_PageErase(0x30) before writing, but that didn’t resolve the issue. Additionally, I attempted to reset the flash to 0xFFFFFFFF manually, which seemed to help intermittently, but I have been unable to reproduce this reliably.

Does anybody have any suggestions on what might be going wrong? Are there any working examples for this chip?

Thank you in advance!

1 REPLY 1
TDK
Super User

HAL_FLASH_Program is used to program, not FLASH_Program_DoubleWord.

HAL_FLASHEx_Erase is the correct function to use to erase a page, not FLASH_PageErase.

Flash can only be written once before it must be erased.

 

Here's an example that uses both of these correctly:

STM32CubeWL/Projects/NUCLEO-WL55JC/Examples/FLASH/FLASH_EraseProgram/Src/main.c at 249cbca4a1b13c5f0cf3a1b6413f356a6e52b7a2 · STMicroelectronics/STM32CubeWL

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