cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing EEPROM emulation to STM32H743ZI2 nucleo board. To sum up, I want to program my FLASH memory by halfword(16-bit) chunk. Please click for further details.

EKosa.1
Associate III

I am trying to program my flash halfword per halfword. There is no HAL library to achieve this work so I am working with registers.

After erasing the specific sector that I want to write, I am trying to change the control register 1 with below code.

0693W00000D2ei4QAB.pngWhich is 0101 0010 in binary (You can check The CR1 register from the ref manual for further details).

https://www.st.com/resource/en/reference_manual/dm00314099-stm32h742-stm32h743-753-and-stm32h750-value-line-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf

While debugging, I can see that FLASH->CR1 register goes 0x12 in HEX, 0001 0010 in binary. I cant set 6th bit for a reason that I can not understand. I tried to change bits one by one too. Still cant set the FW1(6th) bit. Thats what I am asking. I cant program my flash with halfword chunks. Any application code, any help will be appreciated.

I can write with hal library(256 bits). I am trying to say here that there is no problem except mentioned situation above.

eymen

1 ACCEPTED SOLUTION

Accepted Solutions
Guillaume K
ST Employee

I'm not sure, but maybe it is needed to set bit 6 (FW1) after writing 16-bit data to Flash address.

Be careful:

Overall the STM32H7 prefers the Flash memory to be written in 256-bit sections.

You can use the Force Write bit but there are consequences. As written in reference manual:

"FW1 forces a write operation even if the write buffer is not full. In this case all bits not written

are set to 1 by hardware. "

Also:

"Note: Using a force-write operation prevents the application from updating later the missing

bits with something else than 1, because it is likely that it will lead to permanent ECC

error."

Maybe a better solution would be to read a 256-bit Flash chunk into RAM, update the 16-bit part you want to update in the RAM buffer, then write it back to Flash memory as a full 256-bit section. Thus you avoid to handle the Force Write bit and you can update later the other parts of the 256-bit sector.

View solution in original post

6 REPLIES 6
Guillaume K
ST Employee

Hello

did you check the error bits in FLASH_SR1 ? any error must be cleared before writing in Flash.

Hello Mr. Guillaume,

Yeah I checked it right now. It is 0 (0x00) until *(__IO uint16_t*)Address = Data; line. When it comes to this line it becomes 0x02 which is 0010 in binary. So I checked it in ref manual, It is the Bit 1 WBNE1: Bank 1 write buffer not empty flag. And I think its natural to see it set right?

eymen

0x01 is 1 in binary. So bit 0.

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

Right! I corrected that. Thanks!

Guillaume K
ST Employee

I'm not sure, but maybe it is needed to set bit 6 (FW1) after writing 16-bit data to Flash address.

Be careful:

Overall the STM32H7 prefers the Flash memory to be written in 256-bit sections.

You can use the Force Write bit but there are consequences. As written in reference manual:

"FW1 forces a write operation even if the write buffer is not full. In this case all bits not written

are set to 1 by hardware. "

Also:

"Note: Using a force-write operation prevents the application from updating later the missing

bits with something else than 1, because it is likely that it will lead to permanent ECC

error."

Maybe a better solution would be to read a 256-bit Flash chunk into RAM, update the 16-bit part you want to update in the RAM buffer, then write it back to Flash memory as a full 256-bit section. Thus you avoid to handle the Force Write bit and you can update later the other parts of the 256-bit sector.

***"I'm not sure, but maybe it is needed to set bit 6 (FW1) after writing 16-bit data to Flash address."***

Exactly! It worked. From my understandings FW1 bit works like a toggle bit. After pointed the address that Iwant to write, you need to toggle the Force Write bit and thats it.

***Note: Using a force-write operation prevents the application from updating later the missing

bits with something else than 1, because it is likely that it will lead to permanent ECC

error."***

Yes, writen data could change when I toggle the FW1 bit. Its described in 5th mention. https://community.st.com/s/question/0D50X00009XkXbw/stm32h7-hal-flash-program

***Maybe a better solution would be to read a 256-bit Flash chunk into RAM, update the 16-bit part you want to update in the RAM buffer, then write it back to Flash memory as a full 256-bit section. Thus you avoid to handle the Force Write bit and you can update later the other parts of the 256-bit sector.***

Sounds good.

Thanks for the help!