1
0

apm32f10x_fmc.h 11 KB

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