apm32f4xx_smc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*!
  2. * @file apm32f4xx_smc.h
  3. *
  4. * @brief This file contains all the functions prototypes for the SMC 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_SMC_H
  27. #define __APM32F4XX_SMC_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32f4xx.h"
  33. /** @addtogroup APM32F4xx_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup SMC_Driver
  37. @{
  38. */
  39. /** @defgroup SMC_Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief SMC NORSRAM Bank
  44. */
  45. typedef enum
  46. {
  47. SMC_BANK1_NORSRAM_1, /*!< SMC Bank1 NOR/SRAM1 */
  48. SMC_BANK1_NORSRAM_2, /*!< SMC Bank1 NOR/SRAM2 */
  49. SMC_BANK1_NORSRAM_3, /*!< SMC Bank1 NOR/SRAM3 */
  50. SMC_BANK1_NORSRAM_4 /*!< SMC Bank1 NOR/SRAM4 */
  51. } SMC_BANK1_NORSRAM_T;
  52. /**
  53. * @brief SMC NAND and PC Card Bank
  54. */
  55. typedef enum
  56. {
  57. SMC_BANK2_NAND, /*!< SMC Bank2 NAND */
  58. SMC_BANK3_NAND, /*!< SMC Bank3 NAND */
  59. SMC_BANK4_PCCARD /*!< SMC Bank4 PCCARD */
  60. } SMC_BANK_NAND_T;
  61. /**
  62. * @brief SMC_Data_Address_Bus_Multiplexing
  63. */
  64. typedef enum
  65. {
  66. SMC_DATA_ADDRESS_MUX_DISABLE, /*!< Disable data address multiplexing */
  67. SMC_DATA_ADDRESS_MUX_ENABLE /*!< Enable data address multiplexing */
  68. } SMC_DATA_ADDRESS_MUX_T;
  69. /**
  70. * @brief SMC_Memory_Type
  71. */
  72. typedef enum
  73. {
  74. SMC_MEMORY_TYPE_SRAM, /*!< SRAM memory */
  75. SMC_MEMORY_TYPE_PSRAM, /*!< PSRAM memory */
  76. SMC_MEMORY_TYPE_NOR /*!< NORFlash memory */
  77. } SMC_MEMORY_TYPE_T;
  78. /**
  79. * @brief SMC_Data_Width
  80. */
  81. typedef enum
  82. {
  83. SMC_MEMORY_DATA_WIDTH_8BIT, /*!< Set memory data width to 8-bit */
  84. SMC_MEMORY_DATA_WIDTH_16BIT /*!< Set memory data width to 16-bit */
  85. } SMC_MEMORY_DATA_WIDTH_T;
  86. /**
  87. * @brief SMC_Burst_Access_Mode
  88. */
  89. typedef enum
  90. {
  91. SMC_BURST_ACCESS_MODE_DISABLE, /*!< Disable burst access mode */
  92. SMC_BURST_ACCESS_MODE_ENABLE /*!< Enable burst access mode */
  93. } SMC_BURST_ACCESS_MODE_T;
  94. /**
  95. * @brief SMC_AsynchronousWait
  96. */
  97. typedef enum
  98. {
  99. SMC_ASYNCHRONOUS_WAIT_DISABLE, /*!< Disable asynchronous wait */
  100. SMC_ASYNCHRONOUS_WAIT_ENABLE /*!< Enable asynchronous wait */
  101. } SMC_ASYNCHRONOUS_WAIT_T;
  102. /**
  103. * @brief SMC_Wait_Signal_Polarity
  104. */
  105. typedef enum
  106. {
  107. SMC_WAIT_SIGNAL_POLARITY_LOW, /*!< Set low polarity valid */
  108. SMC_WAIT_SIGNAL_POLARITY_HIGH /*!< Set high polarity valid */
  109. } SMC_WAIT_SIGNAL_POLARITY_T;
  110. /**
  111. * @brief SMC Wrapped burst Mode
  112. */
  113. typedef enum
  114. {
  115. SMC_WRAP_MODE_DISABLE, /*!< Disable wrapped burst mode */
  116. SMC_WRAP_MODE_ENABLE /*!< Enable wrapped burst mode */
  117. } SMC_WRAP_MODE_T;
  118. /**
  119. * @brief SMC Wait Timing
  120. */
  121. typedef enum
  122. {
  123. SMC_WAIT_SIGNAL_ACTIVE_BEFORE_WAIT_STATE, /*!< Set wait active before wait state */
  124. SMC_WAIT_SIGNAL_ACTIVE_DURING_WAIT_STATE /*!< Set wait active during wait state */
  125. } SMC_WAIT_SIGNAL_ACTIVE_T;
  126. /**
  127. * @brief SMC Write Operation
  128. */
  129. typedef enum
  130. {
  131. SMC_WRITE_OPERATION_DISABLE, /*!< Disable write operation */
  132. SMC_WRITE_OPERATION_ENABLE /*!< Enable write operation */
  133. } SMC_WRITE_OPERATION_T;
  134. /**
  135. * @brief SMC Wait Signal
  136. */
  137. typedef enum
  138. {
  139. SMC_WAITE_SIGNAL_DISABLE, /*!< Disable wait signal */
  140. SMC_WAITE_SIGNAL_ENABLE /*!< Enable wait signal */
  141. } SMC_WAITE_SIGNAL_T;
  142. /**
  143. * @brief SMC Extended Mode
  144. */
  145. typedef enum
  146. {
  147. SMC_EXTENDEN_MODE_DISABLE, /*!< Disable extended mode */
  148. SMC_EXTENDEN_MODE_ENABLE /*!< Enable extended mode */
  149. } SMC_EXTENDEN_MODE_T;
  150. /**
  151. * @brief SMC Write Burst
  152. */
  153. typedef enum
  154. {
  155. SMC_WRITE_BURST_DISABLE, /*!< Disable write PSRAM burst */
  156. SMC_WRITE_BURST_ENABLE /*!< Enable write PSRAM burst */
  157. } SMC_WRITE_BURST_T;
  158. /**
  159. * @brief SMC WAIT FEATURE
  160. */
  161. typedef enum
  162. {
  163. SMC_WAIT_FEATURE_DISABLE, /*!< Disable wait feature */
  164. SMC_WAIT_FEATURE_ENABLE /*!< Enable wait feature */
  165. } SMC_WAIT_FEATURE_T;
  166. /**
  167. * @brief SMC ECC
  168. */
  169. typedef enum
  170. {
  171. SMC_ECC_DISABLE, /*!< Disable ECC */
  172. SMC_ECC_ENABLE /*!< Enable ECC */
  173. } SMC_ECC_T;
  174. /**
  175. * @brief SMC ECC Page Size
  176. */
  177. typedef enum
  178. {
  179. SMC_ECC_PAGE_SIZE_BYTE_256, /*!< ECC page size = 256 bytes */
  180. SMC_ECC_PAGE_SIZE_BYTE_512, /*!< ECC page size = 512 bytes */
  181. SMC_ECC_PAGE_SIZE_BYTE_1024, /*!< ECC page size = 1024 bytes */
  182. SMC_ECC_PAGE_SIZE_BYTE_2048, /*!< ECC page size = 2048 bytes */
  183. SMC_ECC_PAGE_SIZE_BYTE_4096, /*!< ECC page size = 4096 bytes */
  184. SMC_ECC_PAGE_SIZE_BYTE_8192 /*!< ECC page size = 8192 bytes */
  185. } SMC_ECC_PAGE_SIZE_BYTE_T;
  186. /**
  187. * @brief SMC Access Mode
  188. */
  189. typedef enum
  190. {
  191. SMC_ACCESS_MODE_A, /*!< Access mode A */
  192. SMC_ACCESS_MODE_B, /*!< Access mode B */
  193. SMC_ACCESS_MODE_C, /*!< Access mode C */
  194. SMC_ACCESS_MODE_D /*!< Access mode D */
  195. } SMC_ACCESS_MODE_T;
  196. /**
  197. * @brief SMC Interrupt sources
  198. */
  199. typedef enum
  200. {
  201. SMC_INT_EDGE_RISING = 0x00000008, /*!< Rising edge detection interrupt */
  202. SMC_INT_LEVEL_HIGH = 0x00000010, /*!< High level detection interrupt */
  203. SMC_INT_EDGE_FALLING = 0x00000020 /*!< Falling edge detection interrupt */
  204. } SMC_INT_T;
  205. /**
  206. * @brief SMC Flags
  207. */
  208. typedef enum
  209. {
  210. SMC_FLAG_EDGE_RISING = 0x00000001, /*!< Rising egde detection Flag */
  211. SMC_FLAG_LEVEL_HIGH = 0x00000002, /*!< High level detection Flag */
  212. SMC_FLAG_EDGE_FALLING = 0x00000004, /*!< Falling egde detection Flag */
  213. SMC_FLAG_FIFO_EMPTY = 0x00000040 /*!< FIFO empty Flag */
  214. } SMC_FLAG_T;
  215. /**@} end of group SMC_Enumerations*/
  216. /** @addtogroup SMC_Structure Data Structure
  217. @{
  218. */
  219. /**
  220. * @brief Timing parameters for NOR/SRAM Banks
  221. */
  222. typedef struct
  223. {
  224. uint8_t addressSetupTime; /*!< Set address setup time */
  225. uint8_t addressHodeTime; /*!< Set address-hold setup time */
  226. uint8_t dataSetupTime; /*!< Set data setup time */
  227. uint8_t busTurnaroundTime; /*!< Set bus turnaround time */
  228. uint8_t clockDivision; /*!< Set clock divide radio */
  229. uint8_t dataLatency; /*!< Set data latency */
  230. SMC_ACCESS_MODE_T accessMode; /*!< Set access mode */
  231. } SMC_NORSRAMTimingConfig_T;
  232. /**
  233. * @brief SMC NOR/SRAM Config structure
  234. */
  235. typedef struct
  236. {
  237. SMC_BANK1_NORSRAM_T bank; /*!< NORSRAM bank selection */
  238. SMC_DATA_ADDRESS_MUX_T dataAddressMux; /*!< Data address bus multiplexing selection */
  239. SMC_MEMORY_TYPE_T memoryType; /*!< Memory type selection */
  240. SMC_MEMORY_DATA_WIDTH_T memoryDataWidth; /*!< Data width selection */
  241. SMC_BURST_ACCESS_MODE_T burstAcceesMode; /*!< Set burst access mode */
  242. SMC_ASYNCHRONOUS_WAIT_T asynchronousWait; /*!< Set asynchronous wait */
  243. SMC_WAIT_SIGNAL_POLARITY_T waitSignalPolarity; /*!< Set wait signal polarity */
  244. SMC_WRAP_MODE_T wrapMode; /*!< Set wrapped burst mode */
  245. SMC_WAIT_SIGNAL_ACTIVE_T waitSignalActive; /*!< Set wait timing */
  246. SMC_WRITE_OPERATION_T writeOperation; /*!< Set write operation */
  247. SMC_WAITE_SIGNAL_T waiteSignal; /*!< Set wait signal */
  248. SMC_EXTENDEN_MODE_T extendedMode; /*!< Set extended mode */
  249. SMC_WRITE_BURST_T writeBurst; /*!< Set write burst */
  250. SMC_NORSRAMTimingConfig_T* readWriteTimingStruct; /*!< Read and write timing */
  251. SMC_NORSRAMTimingConfig_T* writeTimingStruct; /*!< Write timing */
  252. } SMC_NORSRAMConfig_T;
  253. /**
  254. * @brief Timing parameters for NAND and PCCARD Banks
  255. */
  256. typedef struct
  257. {
  258. uint8_t setupTime; /*!< Set setup address time( 0x01 ~ 0xFE ) */
  259. uint8_t waitSetupTime; /*!< Set assert the command time ( 0x01 ~ 0xFE ) */
  260. uint8_t holdSetupTime; /*!< Set hold address time ( 0x01 ~ 0xFE ) */
  261. uint8_t HiZSetupTime; /*!< Set the time of keep in HiZ ( 0x00 ~ 0xFE ) */
  262. } SMC_NAND_PCCARDTimingConfig_T;
  263. /**
  264. * @brief SMC NAND Config structure
  265. */
  266. typedef struct
  267. {
  268. SMC_BANK_NAND_T bank; /*!< SMC NAND and PC Card Bank */
  269. SMC_WAIT_FEATURE_T waitFeature; /*!< Set wait feature */
  270. SMC_MEMORY_DATA_WIDTH_T memoryDataWidth; /*!< Data width selection */
  271. SMC_ECC_T ECC; /*!< Set ECC */
  272. SMC_ECC_PAGE_SIZE_BYTE_T ECCPageSize; /*!< Set ECC page size */
  273. uint8_t TCLRSetupTime; /*!< Set the delay time of CLE to RE */
  274. uint8_t TARSetupTime; /*!< Set the delay time of ALE to RE */
  275. SMC_NAND_PCCARDTimingConfig_T* commonSpaceTimingStruct; /*!< Common space timing */
  276. SMC_NAND_PCCARDTimingConfig_T* attributeSpaceTimingStruct; /*!< Attribute space timing */
  277. } SMC_NANDConfig_T;
  278. /**
  279. * @brief SMC PCCARD Config structure
  280. */
  281. typedef struct
  282. {
  283. SMC_WAIT_FEATURE_T waitFeature; /*!< Set wait feature */
  284. uint32_t TCLRSetupTime; /*!< Set the delay time of CLE to RE */
  285. uint32_t TARSetupTime; /*!< Set the delay time of ALE to RE */
  286. SMC_NAND_PCCARDTimingConfig_T* commonSpaceTimingStruct; /*!< Common space timing */
  287. SMC_NAND_PCCARDTimingConfig_T* attributeSpaceTimingStruct; /*!< Attribute space timing */
  288. SMC_NAND_PCCARDTimingConfig_T* IOSpaceTimingStruct; /*!< IO space timing */
  289. } SMC_PCCARDConfig_T;
  290. /**@} end of group SMC_Structure*/
  291. /** @defgroup SMC_Functions
  292. @{
  293. */
  294. /* SMC reset */
  295. void SMC_ResetNORSRAM(SMC_BANK1_NORSRAM_T bank);
  296. void SMC_ResetNAND(SMC_BANK_NAND_T bank);
  297. void SMC_ResetPCCard(void);
  298. /* SMC Configuration */
  299. void SMC_ConfigNORSRAM(SMC_NORSRAMConfig_T* smcNORSRAMConfig);
  300. void SMC_ConfigNAND(SMC_NANDConfig_T* smcNANDConfig);
  301. void SMC_ConfigPCCard(SMC_PCCARDConfig_T* smcPCCardConfig);
  302. void SMC_ConfigNORSRAMStructInit(SMC_NORSRAMConfig_T* smcNORSRAMConfig);
  303. void SMC_ConfigNANDStructInit(SMC_NANDConfig_T* smcNANDConfig);
  304. void SMC_ConfigPCCardStructInit(SMC_PCCARDConfig_T* smcPCCardConfig);
  305. /* SMC bank control */
  306. void SMC_EnableNORSRAM(SMC_BANK1_NORSRAM_T bank);
  307. void SMC_DisableNORSRAM(SMC_BANK1_NORSRAM_T bank);
  308. void SMC_EnableNAND(SMC_BANK_NAND_T bank);
  309. void SMC_DisableNAND(SMC_BANK_NAND_T bank);
  310. void SMC_EnablePCCARD(void);
  311. void SMC_DisablePCCARD(void);
  312. void SMC_EnableNANDECC(SMC_BANK_NAND_T bank);
  313. void SMC_DisableNANDECC(SMC_BANK_NAND_T bank);
  314. uint32_t SMC_ReadECC(SMC_BANK_NAND_T bank);
  315. /* Interrupt and flag */
  316. void SMC_EnableInterrupt(SMC_BANK_NAND_T bank, uint32_t interrupt);
  317. void SMC_DisableInterrupt(SMC_BANK_NAND_T bank, uint32_t interrupt);
  318. uint16_t SMC_ReadStatusFlag(SMC_BANK_NAND_T bank, SMC_FLAG_T flag);
  319. void SMC_ClearStatusFlag(SMC_BANK_NAND_T bank, uint32_t flag);
  320. uint16_t SMC_ReadIntFlag(SMC_BANK_NAND_T bank, SMC_INT_T flag);
  321. void SMC_ClearIntFlag(SMC_BANK_NAND_T bank, uint32_t flag);
  322. #ifdef __cplusplus
  323. }
  324. #endif
  325. #endif /* __APM32F4XX_SMC_H */
  326. /**@} end of group SMC_Enumerations */
  327. /**@} end of group SMC_Driver */
  328. /**@} end of group APM32F4xx_StdPeriphDriver */