HAL_EFlash.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. ******************************************************************************
  3. * @file HAL_EFlash.c
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief EFlash HAL module driver.
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the internal FLASH memory:
  9. * @ Program operations functions
  10. * @ Erase operations functions
  11. ******************************************************************************
  12. */
  13. #include "ACM32Fxx_HAL.h"
  14. /*********************************************************************************
  15. * Function : HAL_EFlash_Init
  16. * Description : Configure eflash parameter as system clock
  17. * Input : system clock frequency
  18. * Output : None
  19. * Author : Chris_Kyle
  20. **********************************************************************************/
  21. void HAL_EFlash_Init(uint32_t fu32_freq)
  22. {
  23. HAL_EFlash_Init_Para(fu32_freq);
  24. }
  25. #if (__ACCELERATE_EH_PRESENT == 0)
  26. /*********************************************************************************
  27. * Function : HAL_EFlash_Erase_Page
  28. * Description : Erase a Page, TERASE has been configured in System_Clock_Init()
  29. * Input :
  30. * Output : false: FAIL
  31. true: SUCCESS
  32. * Author : Chris_Kyle
  33. **********************************************************************************/
  34. bool HAL_EFlash_ErasePage(uint32_t fu32_Addr)
  35. {
  36. EFC->CTRL |= EFC_CTRL_PAGE_ERASE_MODE;
  37. EFC->SEC = 0x55AAAA55;
  38. *((volatile uint32_t *)fu32_Addr) = 0;
  39. while (!(EFC->STATUS & EFC_STATUS_EFLASH_RDY));
  40. EFC->CTRL &= ~EFC_CTRL_PAGE_ERASE_MODE;
  41. return true;
  42. }
  43. /*********************************************************************************
  44. * Function : HAL_EFlash_Programe
  45. * Description : Program a word, TPROG has been configured in System_Clock_Init()
  46. * Input :
  47. * Output : false: FAIL
  48. true: SUCCESS
  49. * Author : Chris_Kyle
  50. **********************************************************************************/
  51. bool HAL_EFlash_Program_Word(uint32_t fu32_Addr, uint32_t fu32_Data)
  52. {
  53. if (fu32_Addr % 4)
  54. {
  55. return false;
  56. }
  57. EFC->CTRL |= EFC_CTRL_PROGRAM_MODE;
  58. EFC->SEC = 0x55AAAA55;
  59. *((volatile uint32_t *)fu32_Addr) = fu32_Data;
  60. while (!(EFC->STATUS & EFC_STATUS_EFLASH_RDY));
  61. EFC->CTRL &= ~EFC_CTRL_PROGRAM_MODE;
  62. return true;
  63. }
  64. #else
  65. /*********************************************************************************
  66. * Function : HAL_EFlash_Erase_Page
  67. * Description : Erase a Page, TERASE has been configured in System_Clock_Init()
  68. * Input :
  69. * Output : false: FAIL
  70. true: SUCCESS
  71. * Author : Chris_Kyle
  72. **********************************************************************************/
  73. bool HAL_EFlash_ErasePage(uint32_t fu32_Addr)
  74. {
  75. HAL_EFlash_ErasePage_EX(fu32_Addr);
  76. return true;
  77. }
  78. /*********************************************************************************
  79. * Function : HAL_EFlash_Programe
  80. * Description : Program a word, TPROG has been configured in System_Clock_Init()
  81. * Input :
  82. * Output : false: FAIL
  83. true: SUCCESS
  84. * Author : Chris_Kyle
  85. **********************************************************************************/
  86. bool HAL_EFlash_Program_Word(uint32_t fu32_Addr, uint32_t fu32_Data)
  87. {
  88. if (fu32_Addr % 4)
  89. {
  90. return false;
  91. }
  92. HAL_EFlash_Program_Word_EX(fu32_Addr, fu32_Data);
  93. return true;
  94. }
  95. #endif