2024-09-17 11:31 PM - last edited on 2024-09-18 04:03 AM by SofLit
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;
2024-09-18 04:02 AM
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.
2024-09-18 04:39 AM
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..
2024-09-18 05:00 AM
@Tesla DeLorean yes it reports error on writing in flash memory, it is successfully erasing the page an address is of last page.
2024-09-18 05:08 AM
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
2024-09-24 01:49 AM
@Tesla DeLorean i am getting HAL_error from FLASH_WaitForLastOperation function.