XMCLib BUG: XMC_SCU_ReadFrom/WriteToRetentionMemory

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
This is the code for the XMC_SCU_ReadFrom/WriteToRetentionMemory functions in xmc4_scu.c:


/* API to write into Retention memory in hibernate domain */
void XMC_SCU_WriteToRetentionMemory(uint32_t address, uint32_t data)
{
uint32_t rmacr;

/* Get the address right */
rmacr = (uint32_t)((address << SCU_GENERAL_RMACR_ADDR_Pos) & (uint32_t)SCU_GENERAL_RMACR_ADDR_Msk);

/* Transfer from RMDATA to Retention memory */
rmacr |= (uint32_t)(SCU_GENERAL_RMACR_RDWR_Msk);

/* Write desired data into RMDATA register */
SCU_GENERAL->RMDATA = data;

/* Write address & direction of transfer into RMACR register */
SCU_GENERAL->RMACR = rmacr;

/* Wait until the update of RMX register in hibernate domain is completed */
while((SCU_GENERAL->MIRRSTS) & SCU_GENERAL_MIRRSTS_RMX_Msk)
{
}
}

/* API to read from Retention memory in hibernate domain */
uint32_t XMC_SCU_ReadFromRetentionMemory(uint32_t address)
{
uint32_t rmacr;

/* Get the address right */
rmacr = ((uint32_t)(address << SCU_GENERAL_RMACR_ADDR_Pos) & (uint32_t)SCU_GENERAL_RMACR_ADDR_Msk);

/* Transfer from RMDATA to Retention memory */
rmacr |= (uint32_t)(SCU_GENERAL_RMACR_RDWR_Msk);

/* Writing an adress & direction of transfer into RMACR register */
SCU_GENERAL->RMACR = rmacr;

/* Wait until the update of RMX register in hibernate domain is completed */
while((SCU_GENERAL->MIRRSTS) & SCU_GENERAL_MIRRSTS_RMX_Msk)
{
}

return (SCU_GENERAL->RMDATA);
}


In both functions, the RDWR bit of the RMACR is set to write using rmacr |= (uint32_t)(SCU_GENERAL_RMACR_RDWR_Msk);. Shouldn't this be omitted from the XMC_SCU_ReadFromRetentionMemory function?

I am also concerned about the lack of checking for the RMX flag before transfers are initiated. It appears the two functions make the assumption that no other code accesses the retention memory.
0 Likes
0 Replies