Skip to main content
Hossein Haji
Associate III
August 3, 2024
Solved

Issue with FLASH_ProgramHalfWord Function on STM32F103RET6

  • August 3, 2024
  • 2 replies
  • 2471 views

Hello everyone,

I hope you're all doing well.

I'm currently working on a project with the STM32F103RET6, and I've encountered an issue when writing data to a page of Flash memory. I'm using the FLASH_ProgramHalfWord function to write half-word data. While this function works correctly about 90% of the time, occasionally it does not return FLASH_COMPLETE.

To resolve the problem, I find that I need to erase the entire page. If I don't perform the page erase, the issue persists.

The device operates on battery power and initializes from scratch each time it is used.

Has anyone experienced a similar problem or have suggestions on how to address this issue? Any insights or advice would be greatly appreciated.

Thank you!

 

 

Best answer by TDK

> We don't use the HAL library,

Perhaps show your FLASH_ProgramHalfWord function if it's not from HAL then.

> However, we encounter an issue where the FLASH_ProgramHalfWord function does not return FLASH_COMPLETE if some data was previously written to these pages.

You know you can only write data once before you have to erase, right?

It sounds like your program might be writing to those pages during programming. Ensure they aren't being used. Perhaps remove them entirely from the linker file.

 

Edit: Another possibility is that those pages are not written during programming, but also not erased either. In which case your program won't be able to write them. If that's the case, you'll have to do a full chip erase prior to programming or otherwise erase those pages somehow before writing. Plenty of ways to do that.

2 replies

STOne-32
Technical Moderator
August 3, 2024

Dear @Hossein Haji ,

is that possible to know on which page @ address this is happening. Is it on particular page ? Particular Address . And how many devices having such behavior .

It might happen that the Page exceeded that number of recycled / Erase number of our specification while using it for EEPROM emulation or storing Data which is about 10K erase cycle.  You can make a test if fresh devices and see if same behavior ?

Hope it helps ,

STOne-32

Hossein Haji
Associate III
August 4, 2024

In our firmware, we have a memory space where we store 8-byte data records. This space ranges from page address 0x800D000 to 0x807F800, which allows us to store a total of 58,880 records. Before programming the chip, we perform a full erase, assuming that the record space should be set to 0xFF. However, we encounter an issue where the FLASH_ProgramHalfWord function does not return FLASH_COMPLETE if some data was previously written to these pages. This issue persists even after performing a full erase and programming the chip. To ensure that FLASH_ProgramHalfWord works correctly, we need to erase these record spaces again.

STOne-32
Technical Moderator
August 4, 2024

Dear @Hossein Haji ,

Can you please elaborate more on this “This issue persists even after performing a full erase and programming the chip. To ensure that FLASH_ProgramHalfWord works correctly, we need to erase these record spaces again”.

in our STM32F1 series , we have flash pages of 2Kbytes each for HD density .

 

1) a full erase of each page should be done to have 0xFFFF - Virgin area .

2) The you can write 0x0 to each 16-bit at a time etc 

As you have 8-bytes data at a time to write . Is that possible to ensure that your software is always writing to a physical address ending by 0x0 or 0x8 and see what happens ? And avoid writing to 0x2 , 0x4 , 0x6 , 0xA , 0xC , 0xE - this is only an experiment to understand what is happening.

Hope it helps.

STOne-32

 

TDK
Super User
August 3, 2024

FLASH_Program_HalfWord isn't meant to be called directly.

Use HAL_FLASH_Program instead.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Hossein Haji
Associate III
August 4, 2024

We don't use the HAL library, but I noticed that the definition of the HAL_FLASH_Program function does not include any special considerations.

TDK
TDKBest answer
Super User
August 4, 2024

> We don't use the HAL library,

Perhaps show your FLASH_ProgramHalfWord function if it's not from HAL then.

> However, we encounter an issue where the FLASH_ProgramHalfWord function does not return FLASH_COMPLETE if some data was previously written to these pages.

You know you can only write data once before you have to erase, right?

It sounds like your program might be writing to those pages during programming. Ensure they aren't being used. Perhaps remove them entirely from the linker file.

 

Edit: Another possibility is that those pages are not written during programming, but also not erased either. In which case your program won't be able to write them. If that's the case, you'll have to do a full chip erase prior to programming or otherwise erase those pages somehow before writing. Plenty of ways to do that.

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