apm32f0xx_fmc.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*!
  2. * @file apm32f0xx_fmc.h
  3. *
  4. * @brief This file contains all the functions prototypes for the FMC firmware library
  5. *
  6. * @version V1.0.3
  7. *
  8. * @date 2022-09-20
  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 useful 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. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F0XX_FMC_H
  27. #define __APM32F0XX_FMC_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32f0xx.h"
  33. /** @addtogroup APM32F0xx_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup FMC_Driver
  37. @{
  38. */
  39. /** @defgroup FMC_Macros Macros
  40. @{
  41. */
  42. /* Macros description */
  43. /* Flash Read protection key */
  44. #define FMC_RP_KEY ((uint32_t)0XA5)
  45. /* Flash key definition */
  46. #define FMC_KEY_1 ((uint32_t)0x45670123)
  47. #define FMC_KEY_2 ((uint32_t)0xCDEF89AB)
  48. #define FMC_OB_KEY_1 ((uint32_t)0x45670123)
  49. #define FMC_OB_KEY_2 ((uint32_t)0xCDEF89AB)
  50. /* Delay definition */
  51. #define FMC_DELAY_ERASE ((uint32_t)0x000B0000)
  52. #define FMC_DELAY_PROGRAM ((uint32_t)0x00002000)
  53. /* 32K and 64K Flash devices */
  54. #if !defined (APM32F030xC) && !defined (APM32F070xB) && !defined (APM32F071xB) && !defined (APM32F072xB) && !defined (APM32F091)
  55. /* Flash write protect page definition */
  56. #define FLASH_WRP_PAGE_0_3 ((uint32_t)0x00000001) /*!< Write protection of page 0 to 3 */
  57. #define FLASH_WRP_PAGE_4_7 ((uint32_t)0x00000002) /*!< Write protection of page 4 to 7 */
  58. #define FLASH_WRP_PAGE_8_11 ((uint32_t)0x00000004) /*!< Write protection of page 8 to 11 */
  59. #define FLASH_WRP_PAGE_12_15 ((uint32_t)0x00000008) /*!< Write protection of page 12 to 15 */
  60. #define FLASH_WRP_PAGE_16_19 ((uint32_t)0x00000010) /*!< Write protection of page 16 to 19 */
  61. #define FLASH_WRP_PAGE_20_23 ((uint32_t)0x00000020) /*!< Write protection of page 20 to 23 */
  62. #define FLASH_WRP_PAGE_24_27 ((uint32_t)0x00000040) /*!< Write protection of page 24 to 27 */
  63. #define FLASH_WRP_PAGE_28_31 ((uint32_t)0x00000080) /*!< Write protection of page 28 to 31 */
  64. #define FLASH_WRP_PAGE_32_35 ((uint32_t)0x00000100) /*!< Write protection of page 32 to 35 */
  65. #define FLASH_WRP_PAGE_36_39 ((uint32_t)0x00000200) /*!< Write protection of page 36 to 39 */
  66. #define FLASH_WRP_PAGE_40_43 ((uint32_t)0x00000400) /*!< Write protection of page 40 to 43 */
  67. #define FLASH_WRP_PAGE_44_47 ((uint32_t)0x00000800) /*!< Write protection of page 44 to 47 */
  68. #define FLASH_WRP_PAGE_48_51 ((uint32_t)0x00001000) /*!< Write protection of page 48 to 51 */
  69. #define FLASH_WRP_PAGE_52_55 ((uint32_t)0x00002000) /*!< Write protection of page 52 to 55 */
  70. #define FLASH_WRP_PAGE_56_59 ((uint32_t)0x00004000) /*!< Write protection of page 56 to 59 */
  71. #define FLASH_WRP_PAGE_60_63 ((uint32_t)0x00008000) /*!< Write protection of page 60 to 63 */
  72. #define FLASH_WRP_PAGE_ALL ((uint32_t)0x0000FFFF) /*!< Write protection of all Sectors */
  73. /* 128K and 256K Flash devices */
  74. #else
  75. /* Flash write protect page definition */
  76. #define FMC_WRP_PAGE_0_1 ((uint32_t)0x00000001) /*!< Write protection of page 0 to 1 */
  77. #define FMC_WRP_PAGE_2_3 ((uint32_t)0x00000002) /*!< Write protection of page 2 to 3 */
  78. #define FMC_WRP_PAGE_4_5 ((uint32_t)0x00000004) /*!< Write protection of page 4 to 5 */
  79. #define FMC_WRP_PAGE_6_7 ((uint32_t)0x00000008) /*!< Write protection of page 6 to 7 */
  80. #define FMC_WRP_PAGE_8_9 ((uint32_t)0x00000010) /*!< Write protection of page 8 to 5 */
  81. #define FMC_WRP_PAGE_10_11 ((uint32_t)0x00000020) /*!< Write protection of page 10 to 5 */
  82. #define FMC_WRP_PAGE_12_13 ((uint32_t)0x00000040) /*!< Write protection of page 12 to 5 */
  83. #define FMC_WRP_PAGE_14_15 ((uint32_t)0x00000080) /*!< Write protection of page 14 to 5 */
  84. #define FMC_WRP_PAGE_16_17 ((uint32_t)0x00000100) /*!< Write protection of page 16 to 15 */
  85. #define FMC_WRP_PAGE_18_19 ((uint32_t)0x00000200) /*!< Write protection of page 18 to 19 */
  86. #define FMC_WRP_PAGE_20_21 ((uint32_t)0x00000400) /*!< Write protection of page 20 to 21 */
  87. #define FMC_WRP_PAGE_22_23 ((uint32_t)0x00000800) /*!< Write protection of page 22 to 23 */
  88. #define FMC_WRP_PAGE_24_25 ((uint32_t)0x00001000) /*!< Write protection of page 24 to 25 */
  89. #define FMC_WRP_PAGE_26_27 ((uint32_t)0x00002000) /*!< Write protection of page 26 to 27 */
  90. #define FMC_WRP_PAGE_28_29 ((uint32_t)0x00004000) /*!< Write protection of page 28 to 29 */
  91. #define FMC_WRP_PAGE_30_31 ((uint32_t)0x00008000) /*!< Write protection of page 30 to 31 */
  92. #define FMC_WRP_PAGE_32_33 ((uint32_t)0x00010000) /*!< Write protection of page 32 to 33 */
  93. #define FMC_WRP_PAGE_34_35 ((uint32_t)0x00020000) /*!< Write protection of page 34 to 35 */
  94. #define FMC_WRP_PAGE_36_37 ((uint32_t)0x00040000) /*!< Write protection of page 36 to 37 */
  95. #define FMC_WRP_PAGE_38_39 ((uint32_t)0x00080000) /*!< Write protection of page 38 to 39 */
  96. #define FMC_WRP_PAGE_40_41 ((uint32_t)0x00100000) /*!< Write protection of page 40 to 41 */
  97. #define FMC_WRP_PAGE_42_43 ((uint32_t)0x00200000) /*!< Write protection of page 42 to 43 */
  98. #define FMC_WRP_PAGE_44_45 ((uint32_t)0x00400000) /*!< Write protection of page 44 to 45 */
  99. #define FMC_WRP_PAGE_46_47 ((uint32_t)0x00800000) /*!< Write protection of page 46 to 47 */
  100. #define FMC_WRP_PAGE_48_49 ((uint32_t)0x01000000) /*!< Write protection of page 48 to 49 */
  101. #define FMC_WRP_PAGE_50_51 ((uint32_t)0x02000000) /*!< Write protection of page 50 to 51 */
  102. #define FMC_WRP_PAGE_52_53 ((uint32_t)0x04000000) /*!< Write protection of page 52 to 53 */
  103. #define FMC_WRP_PAGE_54_55 ((uint32_t)0x08000000) /*!< Write protection of page 54 to 55 */
  104. #define FMC_WRP_PAGE_56_57 ((uint32_t)0x10000000) /*!< Write protection of page 56 to 57 */
  105. #define FMC_WRP_PAGE_58_59 ((uint32_t)0x20000000) /*!< Write protection of page 58 to 59 */
  106. #define FMC_WRP_PAGE_60_61 ((uint32_t)0x40000000) /*!< Write protection of page 20 to 21 */
  107. #define FMC_WRP_PAGE_ALL ((uint32_t)0xFFFFFFFF) /*!< Write protection of page all */
  108. #endif
  109. /**@} end of group FMC_Macros*/
  110. /** @defgroup FMC_Enumerations Enumerations
  111. @{
  112. */
  113. /**
  114. * @brief Flash Latency
  115. */
  116. typedef enum
  117. {
  118. FMC_LATENCY_0, /*!< Flash zero latency cycle */
  119. FMC_LATENCY_1 /*!< Flash one latency cycle */
  120. } FMC_LATENCY_T;
  121. /**
  122. * @brief Flash definition
  123. */
  124. typedef enum
  125. {
  126. FMC_FLAG_BUSY = ((uint8_t)0x01), /*!< Busy flag */
  127. FMC_FLAG_PE = ((uint8_t)0x04), /*!< Program error flag */
  128. FMC_FLAG_WPE = ((uint8_t)0x10), /*!< Write protection flag */
  129. FMC_FLAG_OC = ((uint8_t)0x20), /*!< Operation complete flag */
  130. } FMC_FLAG_T;
  131. /**
  132. * @brief Flash Status
  133. */
  134. typedef enum
  135. {
  136. FMC_STATE_COMPLETE = ((uint8_t)0), /*!< Operation complete */
  137. FMC_STATE_BUSY = ((uint8_t)1), /*!< Busy */
  138. FMC_STATE_PG_ERR = ((uint8_t)2), /*!< Program error */
  139. FMC_STATE_WRP_ERR = ((uint8_t)3), /*!< Write Protection error */
  140. FMC_STATE_TIMEOUT = ((uint8_t)4), /*!< Time out */
  141. } FMC_STATE_T;
  142. /**
  143. * @brief Interrupt source
  144. */
  145. typedef enum
  146. {
  147. FMC_INT_ERROR = ((uint32_t)0x400), /*!< Error interrupt */
  148. FMC_INT_COMPLETE = ((uint32_t)0x1000), /*!< Operation complete interrupt */
  149. } FMC_INT_T;
  150. /**
  151. * @brief Protection Level
  152. */
  153. typedef enum
  154. {
  155. FMC_RDP_LEVEL_0 = ((uint8_t)0xAA), /*!< Protection Level 0 */
  156. FMC_RDP_LEVEL_1 = ((uint8_t)0xBB), /*!< Protection Level 1 */
  157. } FMC_RDP_T;
  158. /**
  159. * @brief Option byte WDG mode activation
  160. */
  161. typedef enum
  162. {
  163. FMC_OB_IWDT_HW = ((uint8_t)0X00), /*!< activated by hardware */
  164. FMC_OB_IWDT_SW = ((uint8_t)0X01), /*!< activated by software */
  165. } FMC_OB_IWDT_T;
  166. /**
  167. * @brief Option byte STOP mode activation
  168. */
  169. typedef enum
  170. {
  171. FMC_OB_STOP_RESET = ((uint8_t)0X00), /*!< Reset generated when entering in STOP */
  172. FMC_OB_STOP_NRST = ((uint8_t)0X02), /*!< No reset generated when entering in STOP */
  173. } FMC_OB_STOP_T;
  174. /**
  175. * @brief Option byte STDBY mode activation
  176. */
  177. typedef enum
  178. {
  179. FMC_OB_STDBY_RESET = ((uint8_t)0X00), /*!< Reset generated when entering in STDBY */
  180. FMC_OB_STDBY_NRST = ((uint8_t)0X04), /*!< No reset generated when entering in STDBY */
  181. } FMC_OB_STDBY_T;
  182. /**
  183. * @brief Flash Option Bytes BOOT0
  184. */
  185. typedef enum
  186. {
  187. FMC_OB_BOOT0_RESET = ((uint8_t)0X00), /*!< BOOT0 Reset */
  188. FMC_OB_BOOT0_SET = ((uint8_t)0X08), /*!< BOOT0 Set */
  189. } FMC_OB_BOOT0_T;
  190. /**
  191. * @brief Flash Option Bytes BOOT1
  192. */
  193. typedef enum
  194. {
  195. FMC_OB_BOOT1_RESET = ((uint8_t)0X00), /*!< BOOT1 Reset */
  196. FMC_OB_BOOT1_SET = ((uint8_t)0X10), /*!< BOOT1 Set */
  197. } FMC_OB_BOOT1_T;
  198. /**
  199. * @brief Flash Option Bytes VDDA Analog Monitoring
  200. */
  201. typedef enum
  202. {
  203. FMC_OB_VDDA_ANALOG_OFF = ((uint8_t)0X00), /*!< Analog monitoring on VDDA Power source OFF */
  204. FMC_OB_VDDA_ANALOG_ON = ((uint8_t)0X20), /*!< Analog monitoring on VDDA Power source ON */
  205. } FMC_OB_VDDA_ANALOG_T;
  206. /**
  207. * @brief Flash Option Bytes SRAM Parity Enable
  208. */
  209. typedef enum
  210. {
  211. FMC_OB_SRAM_PARITY_SET = ((uint8_t)0X00), /*!< SRAM parity enable Set */
  212. FMC_OB_SRAM_PARITY_RESET = ((uint8_t)0X40), /*!< SRAM parity enable reset */
  213. } FMC_OB_SRAM_PARITY_T;
  214. /**
  215. * @brief flash Option Bytes BOOT0SW
  216. */
  217. typedef enum
  218. {
  219. FMC_OB_BOOT0_SW = ((uint8_t)0X00), /*!< BOOT0 pin disabled */
  220. FMC_OB_BOOT0_HW = ((uint8_t)0X80), /*!< BOOT0 pin bonded with GPIO */
  221. } FMC_OB_BOOT0SW_T;
  222. /**@} end of group FMC_Enumerations*/
  223. /** @defgroup FMC_Structures Structures
  224. @{
  225. */
  226. /**
  227. * @brief User Option byte config struct definition
  228. */
  229. typedef struct
  230. {
  231. FMC_OB_IWDT_T iwdtSw;
  232. FMC_OB_STOP_T stopce;
  233. FMC_OB_STDBY_T stdbyce;
  234. } FMC_UserConfig_T;
  235. /**@} end of group FMC_Structures*/
  236. /** @defgroup FMC_Variables Variables
  237. @{
  238. */
  239. /**@} end of group FMC_Variables*/
  240. /** @defgroup FMC_Functions Functions
  241. @{
  242. */
  243. /* Function description */
  244. /* Latency */
  245. void FMC_SetLatency(FMC_LATENCY_T latency);
  246. /* Prefetch Buffer */
  247. void FMC_EnablePrefetchBuffer(void);
  248. void FMC_DisablePrefetchBuffer(void);
  249. uint8_t FMC_ReadPrefetchBufferStatus(void);
  250. /* Lock */
  251. void FMC_Unlock(void);
  252. void FMC_Lock(void);
  253. /* Erase and Program */
  254. FMC_STATE_T FMC_ErasePage(uint32_t pageAddr);
  255. FMC_STATE_T FMC_EraseAllPages(void);
  256. FMC_STATE_T FMC_ProgramWord(uint32_t addr, uint32_t data);
  257. FMC_STATE_T FMC_ProgramHalfWord(uint32_t addr, uint16_t data);
  258. /* FMC Option Bytes Programming functions */
  259. void FMC_UnlockOptionByte(void);
  260. void FMC_LockOptionByte(void);
  261. void FMC_LaunchOptionByte(void);
  262. FMC_STATE_T FMC_EraseOptionByte(void);
  263. FMC_STATE_T FMC_EnableWriteProtection(uint32_t page);
  264. FMC_STATE_T FMC_ConfigReadOutProtection(FMC_RDP_T rdp);
  265. FMC_STATE_T FMC_ConfigOptionByteUser(FMC_UserConfig_T* userConfig);
  266. FMC_STATE_T FMC_EnableOptionByteBOOT(void);
  267. FMC_STATE_T FMC_DisableOptionByteBOOT(void);
  268. FMC_STATE_T FMC_EnableOptionByteVDDA(void);
  269. FMC_STATE_T FMC_DisableOptionByteVDDA(void);
  270. FMC_STATE_T FMC_EnableOptionByteSRAMParity(void);
  271. FMC_STATE_T FMC_DisableOptionByteSRAMParity(void);
  272. FMC_STATE_T FMC_WriteOptionByteUser(uint8_t ob_user);
  273. FMC_STATE_T FMC_ProgramOptionByteData(uint32_t addr, uint8_t data);
  274. uint8_t FMC_ReadOptionByteUser(void);
  275. uint32_t FMC_ReadOptionByteWriteProtection(void);
  276. uint8_t FMC_GetReadProtectionStatus(void);
  277. /* Interrupt and Flag */
  278. void FMC_EnableInterrupt(uint32_t interrupt);
  279. void FMC_DisableInterrupt(uint32_t interrupt);
  280. uint8_t FMC_ReadStatusFlag(FMC_FLAG_T flag);
  281. void FMC_ClearStatusFlag(uint8_t flag);
  282. /* State management */
  283. FMC_STATE_T FMC_ReadState(void);
  284. FMC_STATE_T FMC_WaitForReady(uint32_t timeOut);
  285. #ifdef __cplusplus
  286. }
  287. #endif
  288. #endif /* __APM32F0XX_FMC_H */
  289. /**@} end of group FMC_Functions*/
  290. /**@} end of group FMC_Driver*/
  291. /**@} end of group APM32F0xx_StdPeriphDriver*/