stm32fxx_STURomCrc32Run.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "stm32fxx_STUlib.h"
  2. /**
  3. * @brief Initializes the pointers to the Flash memory required during
  4. * run-time
  5. * @param : None
  6. * @retval : None
  7. */
  8. void STU_RomCrc32Init(void)
  9. {
  10. pRunCrc32Chk = (uint32_t*)ROM_START;
  11. pRunCrc32ChkInv = ((uint32_t *)(uint32_t)(~(uint32_t)(ROM_START)));
  12. CrcHandle.Instance = CRC;
  13. HAL_CRC_Init(&CrcHandle);
  14. /* Reset CRC Calculation Unit */
  15. __HAL_CRC_DR_RESET(&CrcHandle);
  16. }
  17. /**
  18. * @brief Computes the crc in multiple steps and compare it with the
  19. * ref value when the whole memory has been tested
  20. * @param : None
  21. * @retval : STU_TestStatus (TEST_RUNNING, CLASS_C_DATA_FAIL,
  22. * TEST_FAILURE, TEST_OK)
  23. */
  24. STU_TestStatus STU_RomCrc32Run(void)
  25. {
  26. STU_TestStatus result = CTRL_FLW_ERROR; /* In case of abnormal func exit*/
  27. /* Check Class C var integrity */
  28. if ((((uint32_t)pRunCrc32Chk) ^ ((uint32_t)pRunCrc32ChkInv)) == 0xFFFFFFFFuL)
  29. {
  30. if (pRunCrc32Chk < (uint32_t *)ROM_END)
  31. {
  32. /* the next lines replaces the HAL function call
  33. HAL_CRC_Accumulate(&CrcHandle, (uint32_t *)pRunCrc32Chk, (uint32_t)FLASH_BLOCK_WORDS);
  34. due to bug at IAR linker - check sum computation can't support both big & little endian */
  35. uint32_t index;
  36. for(index = 0; index < (uint32_t)FLASH_BLOCK_WORDS; index++)
  37. {
  38. CRC->DR = (*(pRunCrc32Chk + index));
  39. }
  40. pRunCrc32Chk += FLASH_BLOCK_WORDS; /* Increment pointer to next block */
  41. pRunCrc32ChkInv = ((uint32_t *)~((uint32_t)pRunCrc32Chk));
  42. result = TEST_RUNNING;
  43. }
  44. else
  45. {
  46. if(CRC->DR == *(uint32_t *)(&REF_CRC32))
  47. {
  48. result = TEST_OK;
  49. }
  50. else
  51. {
  52. result = TEST_FAILURE;
  53. }
  54. STU_RomCrc32Init(); /* Prepare next test (or redo it if this one failed) */
  55. }
  56. }
  57. else /* Class C error pRunCrc32Chk */
  58. {
  59. result = CLASS_C_DATA_FAIL;
  60. }
  61. return (result);
  62. }
  63. /******************* END OF FILE***********************************/