apm32f4xx_fmc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*!
  2. * @file apm32f4xx_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-06-23
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2021-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. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F4XX_FMC_H
  27. #define __APM32F4XX_FMC_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32f4xx.h"
  33. /** @addtogroup APM32F4xx_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup FMC_Driver
  37. @{
  38. */
  39. /** @defgroup FMC_Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief FMC Status
  44. */
  45. typedef enum
  46. {
  47. FMC_BUSY = 1, /*!< Busy */
  48. FMC_ERROR_RD, /*!< Reserved */
  49. FMC_ERROR_PGS, /*!< Programming Sequence Error */
  50. FMC_ERROR_PGP, /*!< Programming Parallelism Error */
  51. FMC_ERROR_PGA, /*!< Programming Alignment Error */
  52. FMC_ERROR_WRP, /*!< Write Protection Error */
  53. FMC_ERROR_PROGRAM, /*!< Programming Error */
  54. FMC_ERROR_OPERATION, /*!< Operation Error */
  55. FMC_COMPLETE /*!< Operation Complete */
  56. } FMC_STATUS_T;
  57. /**
  58. * @brief FMC Latency
  59. */
  60. typedef enum
  61. {
  62. FMC_LTNCY_0 = ((uint8_t)0x0000), /*!< FMC 0 Latency cycle */
  63. FMC_LTNCY_1 = ((uint8_t)0x0001), /*!< FMC 1 Latency cycle */
  64. FMC_LTNCY_2 = ((uint8_t)0x0002), /*!< FMC 2 Latency cycles */
  65. FMC_LTNCY_3 = ((uint8_t)0x0003), /*!< FMC 3 Latency cycles */
  66. FMC_LTNCY_4 = ((uint8_t)0x0004), /*!< FMC 4 Latency cycles */
  67. FMC_LTNCY_5 = ((uint8_t)0x0005), /*!< FMC 5 Latency cycles */
  68. FMC_LTNCY_6 = ((uint8_t)0x0006), /*!< FMC 6 Latency cycles */
  69. FMC_LTNCY_7 = ((uint8_t)0x0007), /*!< FMC 7 Latency cycles */
  70. FMC_LTNCY_8 = ((uint8_t)0x0008), /*!< FMC 8 Latency cycles */
  71. FMC_LTNCY_9 = ((uint8_t)0x0009), /*!< FMC 9 Latency cycles */
  72. FMC_LTNCY_10 = ((uint8_t)0x000A), /*!< FMC 10 Latency cycles */
  73. FMC_LTNCY_11 = ((uint8_t)0x000B), /*!< FMC 11 Latency cycles */
  74. FMC_LTNCY_12 = ((uint8_t)0x000C), /*!< FMC 12 Latency cycles */
  75. FMC_LTNCY_13 = ((uint8_t)0x000D), /*!< FMC 13 Latency cycles */
  76. FMC_LTNCY_14 = ((uint8_t)0x000E), /*!< FMC 14 Latency cycles */
  77. FMC_LTNCY_15 = ((uint8_t)0x000F) /*!< FMC 15 Latency cycles */
  78. } FMC_LATENCY_T;
  79. /**
  80. * @brief FMC Voltage Range
  81. */
  82. typedef enum
  83. {
  84. FMC_VOLTAGE_1 = (uint8_t)0x00, /*!< when the device voltage range is 1.8V to 2.1V,
  85. the operation will be done by byte (8-bit) */
  86. FMC_VOLTAGE_2 = (uint8_t)0x01, /*!< when the device voltage range is 2.1V to 2.7V,
  87. the operation will be done by half word (16-bit) */
  88. FMC_VOLTAGE_3 = (uint8_t)0x02, /*!< when the device voltage range is 2.7V to 3.6V,
  89. the operation will be done by word (32-bit) */
  90. FMC_VOLTAGE_4 = (uint8_t)0x03, /*!< when the device voltage range is 2.7V to 3.6V + External Vpp,
  91. the operation will be done by double word (64-bit) */
  92. } FMC_VOLTAGE_T;
  93. /**
  94. * @brief FMC Sectors
  95. */
  96. typedef enum
  97. {
  98. FMC_SECTOR_0 = ((uint16_t)0x0000), /*!< Sector number 0 */
  99. FMC_SECTOR_1 = ((uint16_t)0x0008), /*!< Sector number 1 */
  100. FMC_SECTOR_2 = ((uint16_t)0x0010), /*!< Sector number 2 */
  101. FMC_SECTOR_3 = ((uint16_t)0x0018), /*!< Sector number 3 */
  102. FMC_SECTOR_4 = ((uint16_t)0x0020), /*!< Sector number 4 */
  103. FMC_SECTOR_5 = ((uint16_t)0x0028), /*!< Sector number 5 */
  104. FMC_SECTOR_6 = ((uint16_t)0x0030), /*!< Sector number 6 */
  105. FMC_SECTOR_7 = ((uint16_t)0x0038), /*!< Sector number 7 */
  106. FMC_SECTOR_8 = ((uint16_t)0x0040), /*!< Sector number 8 */
  107. FMC_SECTOR_9 = ((uint16_t)0x0048), /*!< Sector number 9 */
  108. FMC_SECTOR_10 = ((uint16_t)0x0050), /*!< Sector number 10 */
  109. FMC_SECTOR_11 = ((uint16_t)0x0058), /*!< Sector number 11 */
  110. FMC_SECTOR_12 = ((uint16_t)0x0080), /*!< Sector number 12 */
  111. FMC_SECTOR_13 = ((uint16_t)0x0088), /*!< Sector number 13 */
  112. FMC_SECTOR_14 = ((uint16_t)0x0090), /*!< Sector number 14 */
  113. FMC_SECTOR_15 = ((uint16_t)0x0098), /*!< Sector number 15 */
  114. FMC_SECTOR_16 = ((uint16_t)0x00A0), /*!< Sector number 16 */
  115. FMC_SECTOR_17 = ((uint16_t)0x00A8), /*!< Sector number 17 */
  116. FMC_SECTOR_18 = ((uint16_t)0x00B0), /*!< Sector number 18 */
  117. FMC_SECTOR_19 = ((uint16_t)0x00B8), /*!< Sector number 19 */
  118. FMC_SECTOR_20 = ((uint16_t)0x00C0), /*!< Sector number 20 */
  119. FMC_SECTOR_21 = ((uint16_t)0x00C8), /*!< Sector number 21 */
  120. FMC_SECTOR_22 = ((uint16_t)0x00D0), /*!< Sector number 22 */
  121. FMC_SECTOR_23 = ((uint16_t)0x00D8) /*!< Sector number 23 */
  122. } FMC_SECTOR_T;
  123. /**
  124. * @brief Option Bytes Write Protection
  125. */
  126. typedef enum
  127. {
  128. FMC_OPT_WRP_SECTOR_0 = (uint32_t)0x00000001, /*!< Write protection of sector 0 */
  129. FMC_OPT_WRP_SECTOR_1 = (uint32_t)0x00000002, /*!< Write protection of sector 1 */
  130. FMC_OPT_WRP_SECTOR_2 = (uint32_t)0x00000004, /*!< Write protection of sector 2 */
  131. FMC_OPT_WRP_SECTOR_3 = (uint32_t)0x00000008, /*!< Write protection of sector 3 */
  132. FMC_OPT_WRP_SECTOR_4 = (uint32_t)0x00000010, /*!< Write protection of sector 4 */
  133. FMC_OPT_WRP_SECTOR_5 = (uint32_t)0x00000020, /*!< Write protection of sector 5 */
  134. FMC_OPT_WRP_SECTOR_6 = (uint32_t)0x00000040, /*!< Write protection of sector 6 */
  135. FMC_OPT_WRP_SECTOR_7 = (uint32_t)0x00000080, /*!< Write protection of sector 7 */
  136. FMC_OPT_WRP_SECTOR_8 = (uint32_t)0x00000100, /*!< Write protection of sector 8 */
  137. FMC_OPT_WRP_SECTOR_9 = (uint32_t)0x00000200, /*!< Write protection of sector 9 */
  138. FMC_OPT_WRP_SECTOR_10 = (uint32_t)0x00000400, /*!< Write protection of sector 10 */
  139. FMC_OPT_WRP_SECTOR_11 = (uint32_t)0x00000800, /*!< Write protection of sector 11 */
  140. FMC_OPT_WRP_SECTOR_12 = (uint32_t)0x00000001, /*!< Write protection of sector 12 */
  141. FMC_OPT_WRP_SECTOR_13 = (uint32_t)0x00000002, /*!< Write protection of sector 13 */
  142. FMC_OPT_WRP_SECTOR_14 = (uint32_t)0x00000004, /*!< Write protection of sector 14 */
  143. FMC_OPT_WRP_SECTOR_15 = (uint32_t)0x00000008, /*!< Write protection of sector 15 */
  144. FMC_OPT_WRP_SECTOR_16 = (uint32_t)0x00000010, /*!< Write protection of sector 16 */
  145. FMC_OPT_WRP_SECTOR_17 = (uint32_t)0x00000020, /*!< Write protection of sector 17 */
  146. FMC_OPT_WRP_SECTOR_18 = (uint32_t)0x00000040, /*!< Write protection of sector 18 */
  147. FMC_OPT_WRP_SECTOR_19 = (uint32_t)0x00000080, /*!< Write protection of sector 19 */
  148. FMC_OPT_WRP_SECTOR_20 = (uint32_t)0x00000100, /*!< Write protection of sector 20 */
  149. FMC_OPT_WRP_SECTOR_21 = (uint32_t)0x00000200, /*!< Write protection of sector 21 */
  150. FMC_OPT_WRP_SECTOR_22 = (uint32_t)0x00000400, /*!< Write protection of sector 22 */
  151. FMC_OPT_WRP_SECTOR_23 = (uint32_t)0x00000800, /*!< Write protection of sector 23 */
  152. FMC_OPT_WRP_SECTOR_All = (uint32_t)0x00000FFF /*!< Write protection of sector 24 */
  153. } FMC_OPT_WRP_T;
  154. /**
  155. * @brief FMC Option Bytes Read Protection
  156. */
  157. typedef enum
  158. {
  159. FMC_OPT_RDP_LV0 =(uint8_t)0xAA, /*!< No protection */
  160. FMC_OPT_RDP_LV1 =(uint8_t)0x55 /*!< Read protection of the memory */
  161. } FMC_OPT_RDP_T;
  162. /**
  163. * @brief FMC Option Bytes Independent Watchdog
  164. */
  165. typedef enum
  166. {
  167. FMC_OPT_IWDT_SOFT = (uint8_t)0x20, /*!< Software IWDT selected */
  168. FMC_OPT_IWDT_HARD = (uint8_t)0x00 /*!< Hardware IWDT selected */
  169. } FMC_OPT_IWDT_T;
  170. /**
  171. * @brief FMC Option Bytes nRST STOP
  172. */
  173. typedef enum
  174. {
  175. FMC_OPT_STOP_NORST = (uint8_t)0x40, /*!< No reset generated when entering in STOP */
  176. FMC_OPT_STOP_RST = (uint8_t)0x00 /*!< Reset generated when entering in STOP */
  177. } FMC_OPT_STOP_T;
  178. /**
  179. * @brief FMC Option Bytes nRST STDBY
  180. */
  181. typedef enum
  182. {
  183. FMC_OPT_STDBY_NORST = (uint8_t)0x80, /*!< No reset generated when entering in STANDBY */
  184. FMC_OPT_STDBY_RST = (uint8_t)0x00 /*!< Reset generated when entering in STANDBY */
  185. } FMC_OPT_STDBY_T;
  186. /**
  187. * @brief FMC BOR Reset Level
  188. */
  189. typedef enum
  190. {
  191. FMC_OPT_BOR_LV3 = (uint8_t)0x00, /*!< Supply voltage ranges from 2.7 to 3.6 V */
  192. FMC_OPT_BOR_LV2 = (uint8_t)0x04, /*!< Supply voltage ranges from 2.4 to 2.7 V */
  193. FMC_OPT_BOR_LV1 = (uint8_t)0x08, /*!< Supply voltage ranges from 2.1 to 2.4 V */
  194. FMC_OPT_BOR_OFF = (uint8_t)0x0C /*!< Supply voltage ranges from 1.62 to 2.1 V */
  195. } FMC_OPT_BOR_T;
  196. /**
  197. * @brief FMC Dual Boot
  198. */
  199. typedef enum
  200. {
  201. FMC_OPT_BOOTEN = (uint8_t)0x10, /*!< Dual boot mode enable */
  202. FMC_OPT_BOOTDIS = (uint8_t)0x00 /*!< Dual boot mode disable */
  203. } FMC_OPT_BOOT_T;
  204. /**
  205. * @brief FMC Interrupts
  206. */
  207. typedef enum
  208. {
  209. FMC_INT_OC = (uint32_t)0x01000000, /*!< Operation Complete Interrupt */
  210. FMC_INT_ERR = (uint32_t)0x02000000 /*!< Error Interrupt */
  211. } FMC_INT_T;
  212. /**
  213. * @brief FMC Flags
  214. */
  215. typedef enum
  216. {
  217. FMC_FLAG_ENDOP = (uint32_t)0x00000001, /*!< FMC End of Operation flag */
  218. FMC_FLAG_ERROP = (uint32_t)0x00000002, /*!< FMC operation Error flag */
  219. FMC_FLAG_ERRWRP = (uint32_t)0x00000010, /*!< FMC Write protected error flag */
  220. FMC_FLAG_ERRPGA = (uint32_t)0x00000020, /*!< FMC Programming Alignment error flag */
  221. FMC_FLAG_ERRPGP = (uint32_t)0x00000040, /*!< FMC Programming Parallelism error flag */
  222. FMC_FLAG_ERRPGS = (uint32_t)0x00000080, /*!< FMC Programming Sequence error flag */
  223. FMC_FLAG_BUSY = (uint32_t)0x00010000 /*!< FMC Busy flag */
  224. } FMC_FLAG_T;
  225. /**
  226. * @brief FMC Program Parallelism
  227. */
  228. typedef enum
  229. {
  230. FMC_PSIZE_BYTE = (uint32_t)0x00000000, /*!< Set program parallelism to 8-bit */
  231. FMC_PSIZE_HALF_WORD = (uint32_t)0x00000100, /*!< Set program parallelism to 16-bit */
  232. FMC_PSIZE_WORD = (uint32_t)0x00000200, /*!< Set program parallelism to 32-bit */
  233. FMC_PSIZE_DOUBLE_WORD = (uint32_t)0x00000300 /*!< Set program parallelism to 64-bit */
  234. } FMC_PSIZE_T;
  235. /**@} end of group FMC_Enumerations*/
  236. /** @defgroup FMC_Macros Macros
  237. @{
  238. */
  239. #define PMC_RDP_KEY ((uint16_t)0x00A5)
  240. #define FMC_KEY1 ((uint32_t)0x45670123)
  241. #define FMC_KEY2 ((uint32_t)0xCDEF89AB)
  242. #define FMC_OPT_KEY1 ((uint32_t)0x08192A3B)
  243. #define FMC_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
  244. /* FMC ACCTRL register Bits definition */
  245. #define FMC_ACCTRL_PREFEN ((uint32_t)0x00000100)
  246. #define FMC_ACCTRL_ICACHEEN ((uint32_t)0x00000200)
  247. #define FMC_ACCTRL_DCACHEEN ((uint32_t)0x00000400)
  248. #define FMC_ACCTRL_ICACHERST ((uint32_t)0x00000800)
  249. #define FMC_ACCTRL_DCACHERST ((uint32_t)0x00001000)
  250. /* FMC CTRL register Bits definition */
  251. #define FMC_CTRL_PG ((uint32_t)0x00000001)
  252. #define FMC_CTRL_SERS ((uint32_t)0x00000002)
  253. #define FMC_CTRL_MERS ((uint32_t)0x00000004)
  254. #define FMC_CTRL_SNUM ((uint32_t)0x00000008)
  255. #define FMC_CTRL_START ((uint32_t)0x00010000)
  256. #define FMC_CTRL_LOCK ((uint32_t)0x80000000)
  257. /* FMC OPTCTRL register Bits definition */
  258. #define FMC_OPTCTRL_OPTLOCK ((uint32_t)0x00000001)
  259. #define FMC_OPTCTRL_OPTSTART ((uint32_t)0x00000002)
  260. #define FMC_OPTCTRL_BORLVL ((uint32_t)0x0000000C)
  261. /* ACCTRL register byte 0 (Bits[7:0]) base address */
  262. #define ACCTRL_BYTE0_ADDRESS ((uint32_t)0x40023C00)
  263. /* OPTCTRL register byte 0 (Bits[7:0]) base address */
  264. #define OPTCTRL_BYTE0_ADDRESS ((uint32_t)0x40023C14)
  265. /* OPTCTRL register byte 1 (Bits[15:8]) base address */
  266. #define OPTCTRL_BYTE1_ADDRESS ((uint32_t)0x40023C15)
  267. /* OPTCTRL register byte 2 (Bits[23:16]) base address */
  268. #define OPTCTRL_BYTE2_ADDRESS ((uint32_t)0x40023C16)
  269. /* OPTCTRL register byte 3 (Bits[31:24]) base address */
  270. #define OPTCTRL_BYTE3_ADDRESS ((uint32_t)0x40023C17)
  271. /**@} end of group FMC_Macros*/
  272. /** @defgroup FMC_Functions
  273. @{
  274. */
  275. /* FMC Interface configuration functions */
  276. void FMC_ConfigLatency(FMC_LATENCY_T latency);
  277. void FMC_EnablePrefetchBuffer(void);
  278. void FMC_DisablePrefetchBuffer(void);
  279. void FMC_EnableInstructionCache(void);
  280. void FMC_DisableInstructionCache(void);
  281. void FMC_EnableDataCache(void);
  282. void FMC_DisableDataCache(void);
  283. void FMC_ResetInstructionCache(void);
  284. void FMC_ResetDataCache(void);
  285. /* FMC Memory Programming functions */
  286. void FMC_Unlock(void);
  287. void FMC_Lock(void);
  288. FMC_STATUS_T FMC_EraseSector(FMC_SECTOR_T sector, FMC_VOLTAGE_T voltageRange);
  289. FMC_STATUS_T FMC_EraseAllSectors(FMC_VOLTAGE_T voltageRange);
  290. FMC_STATUS_T FMC_ProgramDoubleWord(uint32_t address, uint64_t data);
  291. FMC_STATUS_T FMC_ProgramWord(uint32_t address, uint32_t data);
  292. FMC_STATUS_T FMC_ProgramHalfWord(uint32_t address, uint16_t data);
  293. FMC_STATUS_T FMC_ProgramByte(uint32_t address, uint8_t data);
  294. /* Option Bytes Programming functions */
  295. void FMC_UnlockOptionByte(void);
  296. void FMC_LockOptionByte(void);
  297. void FMC_OPT_EnableWriteProtect(FMC_OPT_WRP_T wrp);
  298. void FMC_OPT_DisableWriteProtect(FMC_OPT_WRP_T wrp);
  299. void FMC_OPT_ConfigReadProtect(FMC_OPT_RDP_T rdp);
  300. void FMC_OPT_ConfigUser(FMC_OPT_IWDT_T iwdt, FMC_OPT_STOP_T stop, FMC_OPT_STDBY_T stdby);
  301. void FMC_OPT_ConfigBrownoutReset(FMC_OPT_BOR_T bor);
  302. FMC_STATUS_T FMC_OPT_Launch(void);
  303. uint8_t FMC_OPT_ReadUser(void);
  304. uint16_t FMC_OPT_ReadWriteProtect(void);
  305. uint8_t FMC_OPT_ReadProtectLevel(void);
  306. uint8_t FMC_OPT_ReadBrownoutReset(void);
  307. /* Interrupts and flags management functions */
  308. void FMC_EnableInterrupt(uint32_t interrupt);
  309. void FMC_DisableInterrupt(uint32_t interrupt);
  310. uint8_t FMC_ReadStatusFlag(FMC_FLAG_T flag);
  311. void FMC_ClearStatusFlag(uint32_t flag);
  312. FMC_STATUS_T FMC_ReadStatus(void);
  313. FMC_STATUS_T FMC_WaitForLastOperation(void);
  314. #ifdef __cplusplus
  315. }
  316. #endif
  317. #endif /* __APM32F4XX_FMC_H */
  318. /**@} end of group FMC_Enumerations */
  319. /**@} end of group FMC_Driver */
  320. /**@} end of group APM32F4xx_StdPeriphDriver */