cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to program the flash memory

AADESH
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
STOne-32
ST Employee

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 :

STM32CubeF1/Projects/STM3210E_EVAL/Applications/IAP/IAP_Main at master · STMicroelectronics/STM32CubeF1 · GitHub

 

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.

View solution in original post

6 REPLIES 6
STOne-32
ST Employee

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 :

STM32CubeF1/Projects/STM3210E_EVAL/Applications/IAP/IAP_Main at master · STMicroelectronics/STM32CubeF1 · GitHub

 

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.

AADESH
Associate II

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

 

 

 

 

 

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

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

 

That is correct ! 

Better is say, you can only once write to same possition in one erase cycle, then count writes = count erase on every single place.