1
0

HAL_EFLASH.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /*
  26. * Function : HAL_EFlash_Erase_Page
  27. * Description : Erase a Page, TERASE has been configured in System_Clock_Init()
  28. * Input :
  29. * Outpu : false: FAIL
  30. true: SUCCESS
  31. * Author : Chris_Kyle Data : 2020年
  32. **********************************************************************************/
  33. bool HAL_EFlash_ErasePage(uint32_t fu32_Addr)
  34. {
  35. EFC->CTRL |= EFC_CTRL_PAGE_ERASE_MODE;
  36. EFC->SEC = 0x55AAAA55;
  37. *((volatile uint32_t *)fu32_Addr) = 0;
  38. while (!(EFC->STATUS & EFC_STATUS_EFLASH_RDY));
  39. EFC->CTRL &= ~EFC_CTRL_PAGE_ERASE_MODE;
  40. return true;
  41. }
  42. /*********************************************************************************
  43. * Function : HAL_EFlash_Programe
  44. * Description : Program a word, TPROG has been configured in System_Clock_Init()
  45. * Input :
  46. * Outpu : false: FAIL
  47. true: SUCCESS
  48. * Author : Chris_Kyle Data : 2020年
  49. **********************************************************************************/
  50. bool HAL_EFlash_Program_Word(uint32_t fu32_Addr, uint32_t fu32_Data)
  51. {
  52. if (fu32_Addr % 4)
  53. {
  54. return false;
  55. }
  56. EFC->CTRL |= EFC_CTRL_PROGRAM_MODE;
  57. EFC->SEC = 0x55AAAA55;
  58. *((volatile uint32_t *)fu32_Addr) = fu32_Data;
  59. while (!(EFC->STATUS & EFC_STATUS_EFLASH_RDY));
  60. EFC->CTRL &= ~EFC_CTRL_PROGRAM_MODE;
  61. return true;
  62. }