2024-11-15 10:13 AM
Hi ST Support Team,
I am using the stm32f103rct6 mcu in my custom board. I am using the inbuild flash API's to write data into the flash memory.
I have checked the erase api is working properly, I am able to see the 0xff at all locations without any issue.
But when i try to write at any specific flash address, the "status= HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,addr, (uint64_t)dataBuf[i]);"
. The function completes properly without error but dosen't write the data at that location and returning the 0xFF.
I have attached my project, please check and let me know if i am doing anything wrong.
Thank you in advance.
Best Regards,
Aadesh
Solved! Go to Solution.
2024-11-15 02:13 PM - edited 2024-11-15 11:07 PM
Dear @AADESH ,
Welcome in STCommunity, and thanks for sharing your project and question.
This MCU part is from the STM32F1 High-density line having pages of 2Kbytes each. I would recommend to see this example in Github for our IAP demonstration , In Application Programming using Ymodem which is close to your example :
Then you can see the Flash routines in this file : STM32CubeF1/Projects/STM3210E_EVAL/Applications/IAP/IAP_Main/Src/flash_if.c at master · STMicroelectronics/STM32CubeF1 · GitHub
Hope it helps you.
STOne-32.
2024-11-15 02:13 PM - edited 2024-11-15 11:07 PM
Dear @AADESH ,
Welcome in STCommunity, and thanks for sharing your project and question.
This MCU part is from the STM32F1 High-density line having pages of 2Kbytes each. I would recommend to see this example in Github for our IAP demonstration , In Application Programming using Ymodem which is close to your example :
Then you can see the Flash routines in this file : STM32CubeF1/Projects/STM3210E_EVAL/Applications/IAP/IAP_Main/Src/flash_if.c at master · STMicroelectronics/STM32CubeF1 · GitHub
Hope it helps you.
STOne-32.
2024-11-15 10:53 PM
Hello @STOne-32,
Thank you for the support,
by using the function from the flash_if.c file i am able to write into the flash properly.
I am developing the FOTA application for the STM32F103RCT6 mcu, I have already worked on it for the STM32F446RE MCU and tried to used the same flash write sequence with needed modifications as per the STM32F103RCT6 reference manual. However, i am not able to find what i was doing wrong previously.
I have another question regarding flash endurance calculation, If i am writing into the flash memory by reading each line in the hex file,
below is the sequence,
1) receive 1 line over SPI
2) Unlock flash
3) write flash
4) lock flash
5) repeat 1-4 for all hex lines (NO OF HEX LINES CAN BE 500, 1000, 10000)
How the flash endurance is calculated for above flash write algorithm?
will the endurance=no of hex lines written.
Could you please let me know what is the recommended way to write into flash? do i need to make buffer of page size(2k) into RAM and write it at once in flash?
Best Regards,
Aadesh
2024-11-15 11:21 PM
Dear @AADESH ,
Glad to see you managed get it working . Regarding Endurance of our Flash / this is based only on Page “Erase” cycle that means when the flash cells are all back to 0xFF.
You can write as you want once a full page is erased , it does not matter how many time a word is written .it is up to You to optimize transmission speed and overall process if you program Line by line or word based .
have a good day,
STOne-32
2024-11-16 12:55 AM
Hi @STOne-32 ,
Whatever i have read regarding the flash endurance, i everywhere get same statement that the flash endurance is calculated for each erase/program instance to specific sector/page of the flash memory.
do you mean writing to the flash dosen't reduces the flash endurance and only the erase operation does?
Best Regards,
Aadesh
2024-11-16 05:50 AM
That is correct !
2024-11-16 06:43 AM
Better is say, you can only once write to same possition in one erase cycle, then count writes = count erase on every single place.