2023-09-02 03:42 AM
Hello STMicroelectronics community,
I am currently working on a project that involves using EEPROM memory with an STM32 microcontroller, specifically [STM32L4R5ZI-P]. microcontroller that does not have internal EEPROM, so I need to use the Flash memory for EEPROM emulation. I've installed the xCube EEPROM package, which provides driver layers and specifies the memory address to use.
However, I'm currently facing an issue with not able write or read from Address[0x080FF000U] , while working with flash that is returning with an error = 160, i will be sharing the snippet for your reference.
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
{
HAL_StatusTypeDef status;
uint32_t prog_bit = 0;
/* Process Locked */
__HAL_LOCK(&pFlash);
/* Check the parameters */
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
if(status == HAL_OK)
{
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
/* Deactivate the data cache if they are activated to avoid data misbehavior */
if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
{
/* Disable data cache */
__HAL_FLASH_DATA_CACHE_DISABLE();
pFlash.CacheToReactivate = FLASH_CACHE_DCACHE_ENABLED;
}
else
{
pFlash.CacheToReactivate = FLASH_CACHE_DISABLED;
}
if(TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
{
/* Program double-word (64-bit) at a specified address */
FLASH_Program_DoubleWord(Address, Data);
prog_bit = FLASH_CR_PG;
}
else if((TypeProgram == FLASH_TYPEPROGRAM_FAST) || (TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST))
{
/* Fast program a 32 row double-word (64-bit) at a specified address */
FLASH_Program_Fast(Address, (uint32_t)Data);
/* If it is the last row, the bit will be cleared at the end of the operation */
if(TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST)
{
prog_bit = FLASH_CR_FSTPG;
}
}
else
{
/* Nothing to do */
}
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
/* If the program operation is completed, disable the PG or FSTPG Bit */
if (prog_bit != 0U)
{
CLEAR_BIT(FLASH->CR, prog_bit);
}
/* Flush the caches to be sure of the data consistency */
FLASH_FlushCaches();
}
/* Process Unlocked */
__HAL_UNLOCK(&pFlash);
return status;
}
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
{
/* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
Even if the FLASH operation fails, the BUSY flag will be reset and an error
flag will be set */
uint32_t tickstart = HAL_GetTick();
uint32_t error;
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
{
if(Timeout != HAL_MAX_DELAY)
{
if((HAL_GetTick() - tickstart) >= Timeout)
{
return HAL_TIMEOUT;
}
}
}
error = (FLASH->SR & FLASH_FLAG_SR_ERRORS);
if(error != 0u)
{
/*Save the error code*/
pFlash.ErrorCode |= error;
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(error);
return HAL_ERROR;
}
/* Check FLASH End of Operation flag */
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
{
/* Clear FLASH End of Operation pending bit */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
}
/* If there is an error flag set */
return HAL_OK;
}
here i have provided the function also, where i am facing an error.
could please help me to resolve this issue.
can you please provide any reference to work with microcontroller which we are working.
Thank you.
2023-09-14 04:02 AM
hello,
I have made mass erase to page erase and then also while erasing returns with an error=128.
I will attach snippet of that for reference.
2023-09-26 09:33 AM
Hello,
The address which i used above is correct to write and data which i was sharing should be in 64bit ?
let me know the clarification on address.
Thank you
2023-09-26 11:16 AM
I would recommend starting with an ST example that works and go from there. There are a number of basic errors with the code you've presented:
Here is one such example:
2023-09-27 07:36 AM
Hello,
Thanks for the response and i will check with the above reference.
Thank you
2023-09-27 07:59 AM
Hello,
Can I get any reference for EEPROM emulation using Flash memory like as you shared earlier reference link like that, microcontroller which i was working with STM32L4R5ZI-P. in that previous refered link there i will get for flash memory.
Thank You
2023-09-27 08:26 AM
https://www.st.com/en/embedded-software/x-cube-eeprom.html
\
2023-09-27 10:35 PM
Hello,
Thanks for response. I will check with that.
Thank You
2023-09-28 02:50 AM
Hello,
I have installed this package , but I want one reference which How can I work with package above mentioned ,to the microcontroller{STM32L4R5ZI-P}.so can I get reference to how to use that software which mentioned above.
Thank You
2023-09-28 06:23 AM
Perhaps go to the Documentation tab and look for documents there. Or look online for examples. Lots of resources out there if you look for them. Good luck.
2023-09-29 03:12 AM
Hello,
Thanks for response, I will check with that.
Thank You