cancel
Showing results for 
Search instead for 
Did you mean: 

unable to write in flash memory.

Rohit007
Associate III

Hi,

i am using STM32G0C1RET6 MCU board, i am unable to write in flash memory. i am using an 8 byte structure to put data at that location. but I don't know what is going wrong. please, help... I have given some part of the code below,

 

static FLASH_EraseInitTypeDef EraseInitStruct;

uint32_t PAGError;

/* Unlock the Flash to enable the flash control register access *************/

HAL_FLASH_Unlock();

/* Erase the user Flash area */



/* Get the number of pages to erase */



//uint32_t StartPage = StartPageAddress;

//uint32_t EndPageAddress = 0x0801FFFF;

//uint8_t NbPages = 1; /*!< Number of pages to be erased.



/* Fill EraseInit structure*/

EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;

EraseInitStruct.Banks = FLASH_CR_MER2;

EraseInitStruct.Page = 383;

EraseInitStruct.NbPages = 1;



if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGError) != HAL_OK) {

DEBUG_PR("PAGE ERASE FAILED\r\n");

return HAL_FLASH_GetError ();

} else {

DEBUG_PR("PAGE ERASED\r\n");

}



if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, StartPageAddress, gt_s.pan_motor) == HAL_OK) {

DEBUG_PR("DATA WROTE in FLASH MEMORY");

} else {

DEBUG_PR("FAILED TO WRITE IN FLASH\r\n");

return HAL_FLASH_GetError ();

}

HAL_FLASH_Lock();

return 0;
5 REPLIES 5
SofLit
ST Employee

Hello @Rohit007 ,

Please kindly use </> button to paste your code. I'm editing your post then ..

Please review our recommendations on posting in this community.

Thank you for your understanding.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Does it report an error?

You have it instrumented what does it output?

Does it erase the memory?

What's the address?

In presenting the problem clearly you might be able to understand the issue yourself.

Break it down explain your observations..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@Tesla DeLorean  yes it reports error on writing in flash memory, it is successfully erasing the page an address is of last page.

 

What error does the HAL function actually report.

What IS the address?

Is it correctly aligned with the expectation of the FLASH array and write line widths?

Be specific, not unduly vague, it's the details that matter

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Rohit007
Associate III

@Tesla DeLorean i am getting HAL_error from FLASH_WaitForLastOperation function.