apm32s10x_fmc.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*!
  2. * @file apm32s10x_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 2022-12-31
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2022-2023 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 __APM32S10X_FMC_H
  27. #define __APM32S10X_FMC_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32s10x.h"
  33. /** @addtogroup APM32S10x_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup FMC_Driver FMC Driver
  37. @{
  38. */
  39. /** @defgroup FMC_Macros Macros
  40. @{
  41. */
  42. /* Macros description */
  43. /* Values for APM32 Medium-density devices */
  44. #define FLASH_WRP_PAGE_0_3 ((uint32_t)BIT0) /*!< Write protection of page 0 to 3 */
  45. #define FLASH_WRP_PAGE_4_7 ((uint32_t)BIT1) /*!< Write protection of page 4 to 7 */
  46. #define FLASH_WRP_PAGE_8_11 ((uint32_t)BIT2) /*!< Write protection of page 8 to 11 */
  47. #define FLASH_WRP_PAGE_12_15 ((uint32_t)BIT3) /*!< Write protection of page 12 to 15 */
  48. #define FLASH_WRP_PAGE_16_19 ((uint32_t)BIT4) /*!< Write protection of page 16 to 19 */
  49. #define FLASH_WRP_PAGE_20_23 ((uint32_t)BIT5) /*!< Write protection of page 20 to 23 */
  50. #define FLASH_WRP_PAGE_24_27 ((uint32_t)BIT6) /*!< Write protection of page 24 to 27 */
  51. #define FLASH_WRP_PAGE_28_31 ((uint32_t)BIT7) /*!< Write protection of page 28 to 31 */
  52. #define FLASH_WRP_PAGE_32_35 ((uint32_t)BIT8) /*!< Write protection of page 32 to 35 */
  53. #define FLASH_WRP_PAGE_36_39 ((uint32_t)BIT9) /*!< Write protection of page 36 to 39 */
  54. #define FLASH_WRP_PAGE_40_43 ((uint32_t)BIT10) /*!< Write protection of page 40 to 43 */
  55. #define FLASH_WRP_PAGE_44_47 ((uint32_t)BIT11) /*!< Write protection of page 44 to 47 */
  56. #define FLASH_WRP_PAGE_48_51 ((uint32_t)BIT12) /*!< Write protection of page 48 to 51 */
  57. #define FLASH_WRP_PAGE_52_55 ((uint32_t)BIT13) /*!< Write protection of page 52 to 55 */
  58. #define FLASH_WRP_PAGE_56_59 ((uint32_t)BIT14) /*!< Write protection of page 56 to 59 */
  59. #define FLASH_WRP_PAGE_60_63 ((uint32_t)BIT15) /*!< Write protection of page 60 to 63 */
  60. #define FLASH_WRP_PAGE_64_67 ((uint32_t)BIT16) /*!< Write protection of page 64 to 67 */
  61. #define FLASH_WRP_PAGE_68_71 ((uint32_t)BIT17) /*!< Write protection of page 68 to 71 */
  62. #define FLASH_WRP_PAGE_72_75 ((uint32_t)BIT18) /*!< Write protection of page 72 to 75 */
  63. #define FLASH_WRP_PAGE_76_79 ((uint32_t)BIT19) /*!< Write protection of page 76 to 79 */
  64. #define FLASH_WRP_PAGE_80_83 ((uint32_t)BIT20) /*!< Write protection of page 80 to 83 */
  65. #define FLASH_WRP_PAGE_84_87 ((uint32_t)BIT21) /*!< Write protection of page 84 to 87 */
  66. #define FLASH_WRP_PAGE_88_91 ((uint32_t)BIT22) /*!< Write protection of page 88 to 91 */
  67. #define FLASH_WRP_PAGE_92_95 ((uint32_t)BIT23) /*!< Write protection of page 92 to 95 */
  68. #define FLASH_WRP_PAGE_96_99 ((uint32_t)BIT24) /*!< Write protection of page 96 to 99 */
  69. #define FLASH_WRP_PAGE_100_103 ((uint32_t)BIT25) /*!< Write protection of page 100 to 103 */
  70. #define FLASH_WRP_PAGE_104_107 ((uint32_t)BIT26) /*!< Write protection of page 104 to 107 */
  71. #define FLASH_WRP_PAGE_108_111 ((uint32_t)BIT27) /*!< Write protection of page 108 to 111 */
  72. #define FLASH_WRP_PAGE_112_115 ((uint32_t)BIT28) /*!< Write protection of page 112 to 115 */
  73. #define FLASH_WRP_PAGE_116_119 ((uint32_t)BIT29) /*!< Write protection of page 116 to 119 */
  74. #define FLASH_WRP_PAGE_120_123 ((uint32_t)BIT30) /*!< Write protection of page 120 to 123 */
  75. #define FLASH_WRP_PAGE_124_127 ((uint32_t)BIT31) /*!< Write protection of page 124 to 127 */
  76. #define FMC_WRP_PAGE_ALL ((uint32_t)0xFFFFFFFF) /*!< Write protection of page all */
  77. /**@} end of group FMC_Macros */
  78. /** @defgroup FMC_Enumerations Enumerations
  79. @{
  80. */
  81. /**
  82. * @brief Flash Latency
  83. */
  84. typedef enum
  85. {
  86. FMC_LATENCY_0,
  87. FMC_LATENCY_1,
  88. FMC_LATENCY_2
  89. } FMC_LATENCY_T;
  90. /**
  91. * @brief FMC Status
  92. */
  93. typedef enum
  94. {
  95. FMC_STATUS_BUSY = 1, /*!< flash busy */
  96. FMC_STATUS_ERROR_PG, /*!< flash programming error */
  97. FMC_STATUS_ERROR_WRP, /*!< flash write protection error */
  98. FMC_STATUS_COMPLETE, /*!< flash operation complete */
  99. FMC_STATUS_TIMEOUT /*!< flash time out */
  100. } FMC_STATUS_T;
  101. /**
  102. * @brief Option Bytes IWatchdog
  103. */
  104. typedef enum
  105. {
  106. OB_IWDT_HARD = 0x0000,
  107. OB_IWDT_SOTF = 0x0001
  108. } OB_IWDT_T;
  109. /**
  110. * @brief Option Bytes nRST STOP
  111. */
  112. typedef enum
  113. {
  114. OB_STOP_RST = 0x0000,
  115. OB_STOP_NORST = 0x0002
  116. } OB_STOP_T;
  117. /**
  118. * @brief Option Bytes nRST STDBY
  119. */
  120. typedef enum
  121. {
  122. OB_STDBY_RST = 0x0000,
  123. OB_STDBY_NORST = 0x0004
  124. } OB_STDBY_T;
  125. /**
  126. * @brief FMC Interrupts
  127. */
  128. typedef enum
  129. {
  130. FMC_INT_ERR,
  131. FMC_INT_OC
  132. } FMC_INT_T;
  133. /**
  134. * @brief FMC flag
  135. */
  136. typedef enum
  137. {
  138. FMC_FLAG_BUSY = 0x00000001, /*!< FMC Busy flag */
  139. FMC_FLAG_OC = 0x00000020, /*!< FMC End of Operation flag */
  140. FMC_FLAG_PE = 0x00000004, /*!< FMC Program error flag */
  141. FMC_FLAG_WPE = 0x00000010, /*!< FMC Write protected error flag */
  142. FMC_FLAG_OBE = 0x10000001, /*!< FMC Option Byte error flag */
  143. } FMC_FLAG_T;
  144. /**@} end of group FMC_Enumerations */
  145. /** @defgroup FMC_Structures Structures
  146. @{
  147. */
  148. /**
  149. * @brief User Option byte config struct definition
  150. */
  151. typedef struct
  152. {
  153. OB_IWDT_T iwdtSet;
  154. OB_STOP_T stopSet;
  155. OB_STDBY_T stdbySet;
  156. } FMC_UserConfig_T;
  157. /**@} end of group FMC_Structures */
  158. /** @defgroup FMC_Functions Functions
  159. @{
  160. */
  161. /* Initialization and Configuration */
  162. void FMC_ConfigLatency(FMC_LATENCY_T latency);
  163. void FMC_EnableHalfCycleAccess(void);
  164. void FMC_DisableHalfCycleAccess(void);
  165. void FMC_EnablePrefetchBuffer(void);
  166. void FMC_DisablePrefetchBuffer(void);
  167. /* Lock management */
  168. void FMC_Unlock(void);
  169. void FMC_Lock(void);
  170. /* Erase management */
  171. FMC_STATUS_T FMC_ErasePage(uint32_t pageAddr);
  172. FMC_STATUS_T FMC_EraseAllPage(void);
  173. FMC_STATUS_T FMC_EraseOptionBytes(void);
  174. /* Read Write management */
  175. FMC_STATUS_T FMC_ProgramWord(uint32_t address, uint32_t data);
  176. FMC_STATUS_T FMC_ProgramHalfWord(uint32_t address, uint16_t data);
  177. FMC_STATUS_T FMC_ProgramOptionByteData(uint32_t address, uint8_t data);
  178. FMC_STATUS_T FMC_EnableWriteProtection(uint32_t page);
  179. FMC_STATUS_T FMC_EnableReadOutProtection(void);
  180. FMC_STATUS_T FMC_DisableReadOutProtection(void);
  181. FMC_STATUS_T FMC_ConfigUserOptionByte(FMC_UserConfig_T* userConfig);
  182. uint32_t FMC_ReadUserOptionByte(void);
  183. uint32_t FMC_ReadOptionByteWriteProtection(void);
  184. uint8_t FMC_GetReadProtectionStatus(void);
  185. uint8_t FMC_ReadPrefetchBufferStatus(void);
  186. /* Interrupts and flags */
  187. void FMC_EnableInterrupt(FMC_INT_T interrupt);
  188. void FMC_DisableInterrupt(FMC_INT_T interrupt);
  189. uint8_t FMC_ReadStatusFlag(FMC_FLAG_T flag);
  190. void FMC_ClearStatusFlag(uint32_t flag);
  191. /* Status management */
  192. FMC_STATUS_T FMC_ReadStatus(void);
  193. FMC_STATUS_T FMC_WaitForLastOperation(uint32_t timeOut);
  194. /**@} end of group FMC_Functions */
  195. /**@} end of group FMC_Driver */
  196. /**@} end of group APM32S10x_StdPeriphDriver */
  197. #ifdef __cplusplus
  198. }
  199. #endif
  200. #endif /* __APM32S10X_FMC_H */