apm32f10x_fmc.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*!
  2. * @file apm32f10x_fmc.h
  3. *
  4. * @brief This file contains all the functions prototypes for the FMC firmware library
  5. *
  6. * @version V1.0.1
  7. *
  8. * @date 2021-03-23
  9. *
  10. */
  11. #ifndef __APM32F10X_FMC_H
  12. #define __APM32F10X_FMC_H
  13. #include "apm32f10x.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /** @addtogroup Peripherals_Library Standard Peripheral Library
  18. @{
  19. */
  20. /** @addtogroup FMC_Driver FMC Driver
  21. @{
  22. */
  23. /** @addtogroup FMC_Enumerations Enumerations
  24. @{
  25. */
  26. /**
  27. * @brief Flash Latency
  28. */
  29. typedef enum
  30. {
  31. FMC_LATENCY_0,
  32. FMC_LATENCY_1,
  33. FMC_LATENCY_2
  34. } FMC_LATENCY_T;
  35. /**
  36. * @brief FMC Status
  37. */
  38. typedef enum
  39. {
  40. FMC_STATUS_BUSY = 1, //!< flash busy
  41. FMC_STATUS_ERROR_PG, //!< flash programming error
  42. FMC_STATUS_ERROR_WRP, //!< flash write protection error
  43. FMC_STATUS_COMPLETE, //!< flash operation complete
  44. FMC_STATUS_TIMEOUT //!< flash time out
  45. } FMC_STATUS_T;
  46. /**
  47. * @brief Option Bytes IWatchdog
  48. */
  49. typedef enum
  50. {
  51. OB_IWDT_HARD = 0x0000,
  52. OB_IWDT_SOTF = 0x0001
  53. } OB_IWDT_T;
  54. /**
  55. * @brief Option Bytes nRST STOP
  56. */
  57. typedef enum
  58. {
  59. OB_STOP_RST = 0x0000,
  60. OB_STOP_NORST = 0x0002
  61. } OB_STOP_T;
  62. /**
  63. * @brief Option Bytes nRST STDBY
  64. */
  65. typedef enum
  66. {
  67. OB_STDBY_RST = 0x0000,
  68. OB_STDBY_NORST = 0x0004
  69. } OB_STDBY_T;
  70. /**
  71. * @brief FMC Interrupts
  72. */
  73. typedef enum
  74. {
  75. FMC_INT_ERR,
  76. FMC_INT_OC
  77. } FMC_INT_T;
  78. /**
  79. * @brief FMC flag
  80. */
  81. typedef enum
  82. {
  83. FMC_FLAG_BUSY = 0x00000001, //!< FMC Busy flag
  84. FMC_FLAG_OC = 0x00000020, //!< FMC End of Operation flag
  85. FMC_FLAG_PE = 0x00000004, //!< FMC Program error flag
  86. FMC_FLAG_WPE = 0x00000010, //!< FMC Write protected error flag
  87. FMC_FLAG_OBE = 0x10000001, //!< FMC Option Byte error flag
  88. } FMC_FLAG_T;
  89. /**@} end of group FMC_Enumerations*/
  90. /** @addtogroup FMC_Macros Macros
  91. @{
  92. */
  93. /** Macros description */
  94. /** Values for APM32 Low and Medium density devices */
  95. #define FLASH_WRP_PAGE_0_3 ((uint32_t)BIT0) //!< Write protection of page 0 to 3
  96. #define FLASH_WRP_PAGE_4_7 ((uint32_t)BIT1) //!< Write protection of page 4 to 7
  97. #define FLASH_WRP_PAGE_8_11 ((uint32_t)BIT2) //!< Write protection of page 8 to 11
  98. #define FLASH_WRP_PAGE_12_15 ((uint32_t)BIT3) //!< Write protection of page 12 to 15
  99. #define FLASH_WRP_PAGE_16_19 ((uint32_t)BIT4) //!< Write protection of page 16 to 19
  100. #define FLASH_WRP_PAGE_20_23 ((uint32_t)BIT5) //!< Write protection of page 20 to 23
  101. #define FLASH_WRP_PAGE_24_27 ((uint32_t)BIT6) //!< Write protection of page 24 to 27
  102. #define FLASH_WRP_PAGE_28_31 ((uint32_t)BIT7) //!< Write protection of page 28 to 31
  103. /** Values for APM32 Medium-density devices */
  104. #define FLASH_WRP_PAGE_32_35 ((uint32_t)BIT8) //!< Write protection of page 32 to 35
  105. #define FLASH_WRP_PAGE_36_39 ((uint32_t)BIT9) //!< Write protection of page 36 to 39
  106. #define FLASH_WRP_PAGE_40_43 ((uint32_t)BIT10) //!< Write protection of page 40 to 43
  107. #define FLASH_WRP_PAGE_44_47 ((uint32_t)BIT11) //!< Write protection of page 44 to 47
  108. #define FLASH_WRP_PAGE_48_51 ((uint32_t)BIT12) //!< Write protection of page 48 to 51
  109. #define FLASH_WRP_PAGE_52_55 ((uint32_t)BIT13) //!< Write protection of page 52 to 55
  110. #define FLASH_WRP_PAGE_56_59 ((uint32_t)BIT14) //!< Write protection of page 56 to 59
  111. #define FLASH_WRP_PAGE_60_63 ((uint32_t)BIT15) //!< Write protection of page 60 to 63
  112. #define FLASH_WRP_PAGE_64_67 ((uint32_t)BIT16) //!< Write protection of page 64 to 67
  113. #define FLASH_WRP_PAGE_68_71 ((uint32_t)BIT17) //!< Write protection of page 68 to 71
  114. #define FLASH_WRP_PAGE_72_75 ((uint32_t)BIT18) //!< Write protection of page 72 to 75
  115. #define FLASH_WRP_PAGE_76_79 ((uint32_t)BIT19) //!< Write protection of page 76 to 79
  116. #define FLASH_WRP_PAGE_80_83 ((uint32_t)BIT20) //!< Write protection of page 80 to 83
  117. #define FLASH_WRP_PAGE_84_87 ((uint32_t)BIT21) //!< Write protection of page 84 to 87
  118. #define FLASH_WRP_PAGE_88_91 ((uint32_t)BIT22) //!< Write protection of page 88 to 91
  119. #define FLASH_WRP_PAGE_92_95 ((uint32_t)BIT23) //!< Write protection of page 92 to 95
  120. #define FLASH_WRP_PAGE_96_99 ((uint32_t)BIT24) //!< Write protection of page 96 to 99
  121. #define FLASH_WRP_PAGE_100_103 ((uint32_t)BIT25) //!< Write protection of page 100 to 103
  122. #define FLASH_WRP_PAGE_104_107 ((uint32_t)BIT26) //!< Write protection of page 104 to 107
  123. #define FLASH_WRP_PAGE_108_111 ((uint32_t)BIT27) //!< Write protection of page 108 to 111
  124. #define FLASH_WRP_PAGE_112_115 ((uint32_t)BIT28) //!< Write protection of page 112 to 115
  125. #define FLASH_WRP_PAGE_116_119 ((uint32_t)BIT29) //!< Write protection of page 116 to 119
  126. #define FLASH_WRP_PAGE_120_123 ((uint32_t)BIT30) //!< Write protection of page 120 to 123
  127. #define FLASH_WRP_PAGE_124_127 ((uint32_t)BIT31) //!< Write protection of page 124 to 127
  128. /** Values only for APM32 High-density devices */
  129. #define FLASH_WRP_PAGE_0_1 ((uint32_t)BIT0) //!< Write protection of page 0 to 1
  130. #define FLASH_WRP_PAGE_2_3 ((uint32_t)BIT1) //!< Write protection of page 2 to 3
  131. #define FLASH_WRP_PAGE_4_5 ((uint32_t)BIT2) //!< Write protection of page 4 to 5
  132. #define FLASH_WRP_PAGE_6_7 ((uint32_t)BIT3) //!< Write protection of page 6 to 7
  133. #define FLASH_WRP_PAGE_8_9 ((uint32_t)BIT4) //!< Write protection of page 8 to 9
  134. #define FLASH_WRP_PAGE_10_11 ((uint32_t)BIT5) //!< Write protection of page 10 to 11
  135. #define FLASH_WRP_PAGE_12_13 ((uint32_t)BIT6) //!< Write protection of page 12 to 13
  136. #define FLASH_WRP_PAGE_14_15 ((uint32_t)BIT7) //!< Write protection of page 14 to 15
  137. #define FLASH_WRP_PAGE_16_17 ((uint32_t)BIT8) //!< Write protection of page 16 to 17
  138. #define FLASH_WRP_PAGE_18_19 ((uint32_t)BIT9) //!< Write protection of page 18 to 19
  139. #define FLASH_WRP_PAGE_20_21 ((uint32_t)BIT10) //!< Write protection of page 20 to 21
  140. #define FLASH_WRP_PAGE_22_23 ((uint32_t)BIT11) //!< Write protection of page 22 to 23
  141. #define FLASH_WRP_PAGE_24_25 ((uint32_t)BIT12) //!< Write protection of page 24 to 25
  142. #define FLASH_WRP_PAGE_26_27 ((uint32_t)BIT13) //!< Write protection of page 26 to 27
  143. #define FLASH_WRP_PAGE_28_29 ((uint32_t)BIT14) //!< Write protection of page 28 to 29
  144. #define FLASH_WRP_PAGE_30_31 ((uint32_t)BIT15) //!< Write protection of page 30 to 31
  145. #define FLASH_WRP_PAGE_32_33 ((uint32_t)BIT16) //!< Write protection of page 32 to 33
  146. #define FLASH_WRP_PAGE_34_35 ((uint32_t)BIT17) //!< Write protection of page 34 to 35
  147. #define FLASH_WRP_PAGE_36_37 ((uint32_t)BIT18) //!< Write protection of page 36 to 37
  148. #define FLASH_WRP_PAGE_38_39 ((uint32_t)BIT19) //!< Write protection of page 38 to 39
  149. #define FLASH_WRP_PAGE_40_41 ((uint32_t)BIT20) //!< Write protection of page 40 to 41
  150. #define FLASH_WRP_PAGE_42_43 ((uint32_t)BIT21) //!< Write protection of page 42 to 43
  151. #define FLASH_WRP_PAGE_44_45 ((uint32_t)BIT22) //!< Write protection of page 44 to 45
  152. #define FLASH_WRP_PAGE_46_47 ((uint32_t)BIT23) //!< Write protection of page 46 to 47
  153. #define FLASH_WRP_PAGE_48_49 ((uint32_t)BIT24) //!< Write protection of page 48 to 49
  154. #define FLASH_WRP_PAGE_50_51 ((uint32_t)BIT25) //!< Write protection of page 50 to 51
  155. #define FLASH_WRP_PAGE_52_53 ((uint32_t)BIT26) //!< Write protection of page 52 to 53
  156. #define FLASH_WRP_PAGE_54_55 ((uint32_t)BIT27) //!< Write protection of page 54 to 55
  157. #define FLASH_WRP_PAGE_56_57 ((uint32_t)BIT28) //!< Write protection of page 56 to 57
  158. #define FLASH_WRP_PAGE_58_59 ((uint32_t)BIT29) //!< Write protection of page 58 to 59
  159. #define FLASH_WRP_PAGE_60_61 ((uint32_t)BIT30) //!< Write protection of page 60 to 61
  160. #define FLASH_WRP_PAGE_62_127 ((uint32_t)BIT31) //!< Write protection of page 62 to 127
  161. #define FMC_WRP_PAGE_ALL ((uint32_t)0xFFFFFFFF) //!< Write protection of page all */
  162. /**@} end of group FMC_Macros*/
  163. /** @addtogroup FMC_Structure Data Structure
  164. @{
  165. */
  166. /**
  167. * @brief User Option byte config struct definition
  168. */
  169. typedef struct
  170. {
  171. OB_IWDT_T iwdtSet;
  172. OB_STOP_T stopSet;
  173. OB_STDBY_T stdbySet;
  174. } FMC_UserConfig_T;
  175. /**@} end of group FMC_Structure*/
  176. /** @addtogroup FMC_Fuctions Fuctions
  177. @{
  178. */
  179. /** Initialization and Configuration */
  180. void FMC_ConfigLatency(FMC_LATENCY_T latency);
  181. void FMC_EnableHalfCycleAccess(void);
  182. void FMC_DisableHalfCycleAccess(void);
  183. void FMC_EnablePrefetchBuffer(void);
  184. void FMC_DisablePrefetchBuffer(void);
  185. /** Lock management */
  186. void FMC_Unlock(void);
  187. void FMC_Lock(void);
  188. /** Erase management */
  189. FMC_STATUS_T FMC_ErasePage(uint32_t pageAddr);
  190. FMC_STATUS_T FMC_EraseAllPage(void);
  191. FMC_STATUS_T FMC_EraseOptionBytes(void);
  192. /** Read Write management */
  193. FMC_STATUS_T FMC_ProgramWord(uint32_t address, uint32_t data);
  194. FMC_STATUS_T FMC_ProgramHalfWord(uint32_t address, uint16_t data);
  195. FMC_STATUS_T FMC_ProgramOptionByteData(uint32_t address, uint8_t data);
  196. FMC_STATUS_T FMC_EnableWriteProtection(uint32_t page);
  197. FMC_STATUS_T FMC_EnableReadOutProtection(void);
  198. FMC_STATUS_T FMC_DisableReadOutProtection(void);
  199. FMC_STATUS_T FMC_ConfigUserOptionByte(FMC_UserConfig_T* userConfig);
  200. uint32_t FMC_ReadUserOptionByte(void);
  201. uint32_t FMC_ReadOptionByteWriteProtection(void);
  202. uint8_t FMC_GetReadProtectionStatus(void);
  203. uint8_t FMC_ReadPrefetchBufferStatus(void);
  204. /** Interrupts and flags */
  205. void FMC_EnableInterrupt(FMC_INT_T interrupt);
  206. void FMC_DisableInterrupt(FMC_INT_T interrupt);
  207. uint8_t FMC_ReadStatusFlag(FMC_FLAG_T flag);
  208. void FMC_ClearStatusFlag(FMC_FLAG_T flag);
  209. /** Status management */
  210. FMC_STATUS_T FMC_ReadStatus(void);
  211. FMC_STATUS_T FMC_WaitForLastOperation(uint32_t timeOut);
  212. /**@} end of group FMC_Fuctions*/
  213. /**@} end of group FMC_Driver*/
  214. /**@} end of group Peripherals_Library*/
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif /* __APM32F10X_FMC_H */