Skip to main content
Associate II
July 25, 2024
Solved

Flash erase and program

HI,

I cannot delete page 15, or other pages, of the STM32C031K6T6 flash chip.

 

HAL_StatusTypeDef status;
EraseInitStruct.TypeErase=FLASH_TYPEERASE_PAGES;
EraseInitStruct.NbPages=1;
EraseInitStruct.Page=15;
status = HAL_FLASH_Unlock();
status = HAL_FLASHEx_Erase (&EraseInitStruct, &PageError);
status = HAL_FLASH_Lock();

 

Where am I wrong? Can someone help me?

Thanks everyone in advance.

 

 

 

This topic has been closed for replies.
TDK
TDKBest answer
July 25, 2024

Why can't you erase the page? What happens when you try? What sort of errors or bad behavior do you get vs what do you expect? Be specific, look at the FLASH peripheral registers to determine issues.

Verify write protection settings in option bytes using STM32CubeProgrammer.

 

Example code is here:

STM32CubeC0/Projects/NUCLEO-C071RB/Examples/FLASH/FLASH_EraseProgram/Src/main.c at 291f417c07b8e6f997a555b4abafa861551d22e3 · STMicroelectronics/STM32CubeC0 (github.com)

 

Note that it clears OPTVERR flag. Probably this is an issue of not clearing flags before trying. The debugger is known to set flags that shouldn't be set.

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

1 reply

TDK
TDKBest answer
July 25, 2024

Why can't you erase the page? What happens when you try? What sort of errors or bad behavior do you get vs what do you expect? Be specific, look at the FLASH peripheral registers to determine issues.

Verify write protection settings in option bytes using STM32CubeProgrammer.

 

Example code is here:

STM32CubeC0/Projects/NUCLEO-C071RB/Examples/FLASH/FLASH_EraseProgram/Src/main.c at 291f417c07b8e6f997a555b4abafa861551d22e3 · STMicroelectronics/STM32CubeC0 (github.com)

 

Note that it clears OPTVERR flag. Probably this is an issue of not clearing flags before trying. The debugger is known to set flags that shouldn't be set.

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