#include "stm32fxx_STUlib.h" /** * @brief Initializes the pointers to the Flash memory required during * run-time * @param : None * @retval : None */ void STU_RomCrc32Init(void) { pRunCrc32Chk = (uint32_t*)ROM_START; pRunCrc32ChkInv = ((uint32_t *)(uint32_t)(~(uint32_t)(ROM_START))); CrcHandle.Instance = CRC; HAL_CRC_Init(&CrcHandle); /* Reset CRC Calculation Unit */ __HAL_CRC_DR_RESET(&CrcHandle); } /** * @brief Computes the crc in multiple steps and compare it with the * ref value when the whole memory has been tested * @param : None * @retval : STU_TestStatus (TEST_RUNNING, CLASS_C_DATA_FAIL, * TEST_FAILURE, TEST_OK) */ STU_TestStatus STU_RomCrc32Run(void) { STU_TestStatus result = CTRL_FLW_ERROR; /* In case of abnormal func exit*/ /* Check Class C var integrity */ if ((((uint32_t)pRunCrc32Chk) ^ ((uint32_t)pRunCrc32ChkInv)) == 0xFFFFFFFFuL) { if (pRunCrc32Chk < (uint32_t *)ROM_END) { /* the next lines replaces the HAL function call HAL_CRC_Accumulate(&CrcHandle, (uint32_t *)pRunCrc32Chk, (uint32_t)FLASH_BLOCK_WORDS); due to bug at IAR linker - check sum computation can't support both big & little endian */ uint32_t index; for(index = 0; index < (uint32_t)FLASH_BLOCK_WORDS; index++) { CRC->DR = (*(pRunCrc32Chk + index)); } pRunCrc32Chk += FLASH_BLOCK_WORDS; /* Increment pointer to next block */ pRunCrc32ChkInv = ((uint32_t *)~((uint32_t)pRunCrc32Chk)); result = TEST_RUNNING; } else { if(CRC->DR == *(uint32_t *)(&REF_CRC32)) { result = TEST_OK; } else { result = TEST_FAILURE; } STU_RomCrc32Init(); /* Prepare next test (or redo it if this one failed) */ } } else /* Class C error pRunCrc32Chk */ { result = CLASS_C_DATA_FAIL; } return (result); } /******************* END OF FILE***********************************/