I want to calculate the CRC value of some data in STM32 micro controller. The HAL function to calculate the CRC has the following footprint:
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
My data are stored in a struct:
struct caldata_tag {
float K_P_Htng;
uint16_t K_I_Htng;
uint16_t K_D_Htng;
uint16_t K_P_Coolg; } caldata;
Who is the safest and appropriate way to pass the struct to the HAL_CRC_Calculate() function?
I am thinking about this :
#define U32BUFFERSIZE sizeof(struct caldata_tag)/sizeof(uint32_t)
uint32_t buffer[U32BUFFERSIZE];
uint32_t crcValue;
/* calculate the crc value of the data */
memcpy(buffer,&localStruct,U32BUFFERSIZE);
crcValue = HAL_CRC_Calculate(&CrcHandle,buffer,U32BUFFERSIZE);
but I am thinking that is an ugly way, could you tell me if it is ok? OR if you have a better idea?