cancel
Showing results for 
Search instead for 
Did you mean: 

Issues writing 0s into flash into STMF103

Dioswilson
Associate III

Hello, I am trying to make a write into flash driver but I am having some issues.

I know that the only way to write a 1 to the memory is by clearing the whole page, but I am having issues writing 0s.
By reading the manual I encountered:

Bit 2 PGERR: Programming error
Set by hardware when an address to be programmed contains a value different from
'0xFFFF' before programming.

Does that mean I can only write 0s once to each addres per page clear?

If this is the case, why is that? Wouldn't I be capable of writinng indefinetly when I am not trying to write any 1 in the memory?

1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Super User

Hi,

Flash memory does not allow you to clear or rewrite a single address independently;

you must erase an entire page before rewriting.

So it gives an error, if you try to write to a value thats not 0xffff before .

The error "2" tells exactly this.

Set by hardware when an address to be programmed contains a value different from
'0xFFFF' before programming.

 >Does that mean I can only write 0s once to each address per page clear?

Right.

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

View solution in original post

2 REPLIES 2
AScha.3
Super User

Hi,

Flash memory does not allow you to clear or rewrite a single address independently;

you must erase an entire page before rewriting.

So it gives an error, if you try to write to a value thats not 0xffff before .

The error "2" tells exactly this.

Set by hardware when an address to be programmed contains a value different from
'0xFFFF' before programming.

 >Does that mean I can only write 0s once to each address per page clear?

Right.

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

> Does that mean I can only write 0s once to each addres per page clear?

Yes, other than writing ALL zeroes, which is also allowed at any time.

https://www.st.com/resource/en/programming_manual/cd00283419-stm32f10xxx-flash-memory-microcontrollers-stmicroelectronics.pdf


> If this is the case, why is that? Wouldn't I be capable of writinng indefinetly when I am not trying to write any 1 in the memory?

That's how the chip operates according to the programming manual. It was a design decision. Presumably to avoid overwriting valid data. Some chips allow this, such as the STM32F4 series, but this one does not. Newer families with ECC bits also do not allow this.

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