stm32f10x_fsmc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
  2. * File Name : stm32f10x_fsmc.h
  3. * Author : MCD Application Team
  4. * Version : V2.0.3Patch1
  5. * Date : 04/06/2009
  6. * Description : This file contains all the functions prototypes for the
  7. * FSMC firmware library.
  8. ********************************************************************************
  9. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  10. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  11. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  12. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  13. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  14. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  15. *******************************************************************************/
  16. /* Define to prevent recursive inclusion -------------------------------------*/
  17. #ifndef __STM32F10x_FSMC_H
  18. #define __STM32F10x_FSMC_H
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32f10x_map.h"
  21. /* Exported types ------------------------------------------------------------*/
  22. /* Timing parameters For NOR/SRAM Banks */
  23. typedef struct
  24. {
  25. u32 FSMC_AddressSetupTime;
  26. u32 FSMC_AddressHoldTime;
  27. u32 FSMC_DataSetupTime;
  28. u32 FSMC_BusTurnAroundDuration;
  29. u32 FSMC_CLKDivision;
  30. u32 FSMC_DataLatency;
  31. u32 FSMC_AccessMode;
  32. }FSMC_NORSRAMTimingInitTypeDef;
  33. /* FSMC NOR/SRAM Init structure definition */
  34. typedef struct
  35. {
  36. u32 FSMC_Bank;
  37. u32 FSMC_DataAddressMux;
  38. u32 FSMC_MemoryType;
  39. u32 FSMC_MemoryDataWidth;
  40. u32 FSMC_BurstAccessMode;
  41. u32 FSMC_WaitSignalPolarity;
  42. u32 FSMC_WrapMode;
  43. u32 FSMC_WaitSignalActive;
  44. u32 FSMC_WriteOperation;
  45. u32 FSMC_WaitSignal;
  46. u32 FSMC_ExtendedMode;
  47. u32 FSMC_WriteBurst;
  48. /* Timing Parameters for write and read access if the ExtendedMode is not used*/
  49. FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct;
  50. /* Timing Parameters for write access if the ExtendedMode is used*/
  51. FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct;
  52. }FSMC_NORSRAMInitTypeDef;
  53. /* Timing parameters For FSMC NAND and PCCARD Banks */
  54. typedef struct
  55. {
  56. u32 FSMC_SetupTime;
  57. u32 FSMC_WaitSetupTime;
  58. u32 FSMC_HoldSetupTime;
  59. u32 FSMC_HiZSetupTime;
  60. }FSMC_NAND_PCCARDTimingInitTypeDef;
  61. /* FSMC NAND Init structure definition */
  62. typedef struct
  63. {
  64. u32 FSMC_Bank;
  65. u32 FSMC_Waitfeature;
  66. u32 FSMC_MemoryDataWidth;
  67. u32 FSMC_ECC;
  68. u32 FSMC_ECCPageSize;
  69. u32 FSMC_TCLRSetupTime;
  70. u32 FSMC_TARSetupTime;
  71. /* FSMC Common Space Timing */
  72. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_CommonSpaceTimingStruct;
  73. /* FSMC Attribute Space Timing */
  74. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_AttributeSpaceTimingStruct;
  75. }FSMC_NANDInitTypeDef;
  76. /* FSMC PCCARD Init structure definition */
  77. typedef struct
  78. {
  79. u32 FSMC_Waitfeature;
  80. u32 FSMC_TCLRSetupTime;
  81. u32 FSMC_TARSetupTime;
  82. /* FSMC Common Space Timing */
  83. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_CommonSpaceTimingStruct;
  84. /* FSMC Attribute Space Timing */
  85. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_AttributeSpaceTimingStruct;
  86. /* FSMC IO Space Timing */
  87. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_IOSpaceTimingStruct;
  88. }FSMC_PCCARDInitTypeDef;
  89. /* Exported constants --------------------------------------------------------*/
  90. /*-------------------------------FSMC Banks definitions ----------------------*/
  91. #define FSMC_Bank1_NORSRAM1 ((u32)0x00000000)
  92. #define FSMC_Bank1_NORSRAM2 ((u32)0x00000002)
  93. #define FSMC_Bank1_NORSRAM3 ((u32)0x00000004)
  94. #define FSMC_Bank1_NORSRAM4 ((u32)0x00000006)
  95. #define FSMC_Bank2_NAND ((u32)0x00000010)
  96. #define FSMC_Bank3_NAND ((u32)0x00000100)
  97. #define FSMC_Bank4_PCCARD ((u32)0x00001000)
  98. #define IS_FSMC_NORSRAM_BANK(BANK) (((BANK) == FSMC_Bank1_NORSRAM1) || \
  99. ((BANK) == FSMC_Bank1_NORSRAM2) || \
  100. ((BANK) == FSMC_Bank1_NORSRAM3) || \
  101. ((BANK) == FSMC_Bank1_NORSRAM4))
  102. #define IS_FSMC_NAND_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  103. ((BANK) == FSMC_Bank3_NAND))
  104. #define IS_FSMC_GETFLAG_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  105. ((BANK) == FSMC_Bank3_NAND) || \
  106. ((BANK) == FSMC_Bank4_PCCARD))
  107. #define IS_FSMC_IT_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  108. ((BANK) == FSMC_Bank3_NAND) || \
  109. ((BANK) == FSMC_Bank4_PCCARD))
  110. /*------------------------------- NOR/SRAM Banks -----------------------------*/
  111. /* FSMC Data/Address Bus Multiplexing ----------------------------------------*/
  112. #define FSMC_DataAddressMux_Disable ((u32)0x00000000)
  113. #define FSMC_DataAddressMux_Enable ((u32)0x00000002)
  114. #define IS_FSMC_MUX(MUX) (((MUX) == FSMC_DataAddressMux_Disable) || \
  115. ((MUX) == FSMC_DataAddressMux_Enable))
  116. /* FSMC Memory Type ----------------------------------------------------------*/
  117. #define FSMC_MemoryType_SRAM ((u32)0x00000000)
  118. #define FSMC_MemoryType_PSRAM ((u32)0x00000004)
  119. #define FSMC_MemoryType_NOR ((u32)0x00000008)
  120. #define IS_FSMC_MEMORY(MEMORY) (((MEMORY) == FSMC_MemoryType_SRAM) || \
  121. ((MEMORY) == FSMC_MemoryType_PSRAM)|| \
  122. ((MEMORY) == FSMC_MemoryType_NOR))
  123. /* FSMC Data Width ----------------------------------------------------------*/
  124. #define FSMC_MemoryDataWidth_8b ((u32)0x00000000)
  125. #define FSMC_MemoryDataWidth_16b ((u32)0x00000010)
  126. #define IS_FSMC_MEMORY_WIDTH(WIDTH) (((WIDTH) == FSMC_MemoryDataWidth_8b) || \
  127. ((WIDTH) == FSMC_MemoryDataWidth_16b))
  128. /* FSMC Burst Access Mode ----------------------------------------------------*/
  129. #define FSMC_BurstAccessMode_Disable ((u32)0x00000000)
  130. #define FSMC_BurstAccessMode_Enable ((u32)0x00000100)
  131. #define IS_FSMC_BURSTMODE(STATE) (((STATE) == FSMC_BurstAccessMode_Disable) || \
  132. ((STATE) == FSMC_BurstAccessMode_Enable))
  133. /* FSMC Wait Signal Polarity -------------------------------------------------*/
  134. #define FSMC_WaitSignalPolarity_Low ((u32)0x00000000)
  135. #define FSMC_WaitSignalPolarity_High ((u32)0x00000200)
  136. #define IS_FSMC_WAIT_POLARITY(POLARITY) (((POLARITY) == FSMC_WaitSignalPolarity_Low) || \
  137. ((POLARITY) == FSMC_WaitSignalPolarity_High))
  138. /* FSMC Wrap Mode ------------------------------------------------------------*/
  139. #define FSMC_WrapMode_Disable ((u32)0x00000000)
  140. #define FSMC_WrapMode_Enable ((u32)0x00000400)
  141. #define IS_FSMC_WRAP_MODE(MODE) (((MODE) == FSMC_WrapMode_Disable) || \
  142. ((MODE) == FSMC_WrapMode_Enable))
  143. /* FSMC Wait Timing ----------------------------------------------------------*/
  144. #define FSMC_WaitSignalActive_BeforeWaitState ((u32)0x00000000)
  145. #define FSMC_WaitSignalActive_DuringWaitState ((u32)0x00000800)
  146. #define IS_FSMC_WAIT_SIGNAL_ACTIVE(ACTIVE) (((ACTIVE) == FSMC_WaitSignalActive_BeforeWaitState) || \
  147. ((ACTIVE) == FSMC_WaitSignalActive_DuringWaitState))
  148. /* FSMC Write Operation ------------------------------------------------------*/
  149. #define FSMC_WriteOperation_Disable ((u32)0x00000000)
  150. #define FSMC_WriteOperation_Enable ((u32)0x00001000)
  151. #define IS_FSMC_WRITE_OPERATION(OPERATION) (((OPERATION) == FSMC_WriteOperation_Disable) || \
  152. ((OPERATION) == FSMC_WriteOperation_Enable))
  153. /* FSMC Wait Signal ----------------------------------------------------------*/
  154. #define FSMC_WaitSignal_Disable ((u32)0x00000000)
  155. #define FSMC_WaitSignal_Enable ((u32)0x00002000)
  156. #define IS_FSMC_WAITE_SIGNAL(SIGNAL) (((SIGNAL) == FSMC_WaitSignal_Disable) || \
  157. ((SIGNAL) == FSMC_WaitSignal_Enable))
  158. /* FSMC Extended Mode --------------------------------------------------------*/
  159. #define FSMC_ExtendedMode_Disable ((u32)0x00000000)
  160. #define FSMC_ExtendedMode_Enable ((u32)0x00004000)
  161. #define IS_FSMC_EXTENDED_MODE(MODE) (((MODE) == FSMC_ExtendedMode_Disable) || \
  162. ((MODE) == FSMC_ExtendedMode_Enable))
  163. /* FSMC Write Burst ----------------------------------------------------------*/
  164. #define FSMC_WriteBurst_Disable ((u32)0x00000000)
  165. #define FSMC_WriteBurst_Enable ((u32)0x00080000)
  166. #define IS_FSMC_WRITE_BURST(BURST) (((BURST) == FSMC_WriteBurst_Disable) || \
  167. ((BURST) == FSMC_WriteBurst_Enable))
  168. /* FSMC Address Setup Time ---------------------------------------------------*/
  169. #define IS_FSMC_ADDRESS_SETUP_TIME(TIME) ((TIME) <= 0xF)
  170. /* FSMC Address Hold Time ----------------------------------------------------*/
  171. #define IS_FSMC_ADDRESS_HOLD_TIME(TIME) ((TIME) <= 0xF)
  172. /* FSMC Data Setup Time ------------------------------------------------------*/
  173. #define IS_FSMC_DATASETUP_TIME(TIME) (((TIME) > 0) && ((TIME) <= 0xFF))
  174. /* FSMC Bus Turn around Duration ---------------------------------------------*/
  175. #define IS_FSMC_TURNAROUND_TIME(TIME) ((TIME) <= 0xF)
  176. /* FSMC CLK Division ---------------------------------------------------------*/
  177. #define IS_FSMC_CLK_DIV(DIV) ((DIV) <= 0xF)
  178. /* FSMC Data Latency ---------------------------------------------------------*/
  179. #define IS_FSMC_DATA_LATENCY(LATENCY) ((LATENCY) <= 0xF)
  180. /* FSMC Access Mode ----------------------------------------------------------*/
  181. #define FSMC_AccessMode_A ((u32)0x00000000)
  182. #define FSMC_AccessMode_B ((u32)0x10000000)
  183. #define FSMC_AccessMode_C ((u32)0x20000000)
  184. #define FSMC_AccessMode_D ((u32)0x30000000)
  185. #define IS_FSMC_ACCESS_MODE(MODE) (((MODE) == FSMC_AccessMode_A) || \
  186. ((MODE) == FSMC_AccessMode_B) || \
  187. ((MODE) == FSMC_AccessMode_C) || \
  188. ((MODE) == FSMC_AccessMode_D))
  189. /*----------------------------- NAND and PCCARD Banks ------------------------*/
  190. /* FSMC Wait feature ---------------------------------------------------------*/
  191. #define FSMC_Waitfeature_Disable ((u32)0x00000000)
  192. #define FSMC_Waitfeature_Enable ((u32)0x00000002)
  193. #define IS_FSMC_WAIT_FEATURE(FEATURE) (((FEATURE) == FSMC_Waitfeature_Disable) || \
  194. ((FEATURE) == FSMC_Waitfeature_Enable))
  195. /* FSMC Memory Data Width ----------------------------------------------------*/
  196. #define FSMC_MemoryDataWidth_8b ((u32)0x00000000)
  197. #define FSMC_MemoryDataWidth_16b ((u32)0x00000010)
  198. #define IS_FSMC_DATA_WIDTH(WIDTH) (((WIDTH) == FSMC_MemoryDataWidth_8b) || \
  199. ((WIDTH) == FSMC_MemoryDataWidth_16b))
  200. /* FSMC ECC ------------------------------------------------------------------*/
  201. #define FSMC_ECC_Disable ((u32)0x00000000)
  202. #define FSMC_ECC_Enable ((u32)0x00000040)
  203. #define IS_FSMC_ECC_STATE(STATE) (((STATE) == FSMC_ECC_Disable) || \
  204. ((STATE) == FSMC_ECC_Enable))
  205. /* FSMC ECC Page Size --------------------------------------------------------*/
  206. #define FSMC_ECCPageSize_256Bytes ((u32)0x00000000)
  207. #define FSMC_ECCPageSize_512Bytes ((u32)0x00020000)
  208. #define FSMC_ECCPageSize_1024Bytes ((u32)0x00040000)
  209. #define FSMC_ECCPageSize_2048Bytes ((u32)0x00060000)
  210. #define FSMC_ECCPageSize_4096Bytes ((u32)0x00080000)
  211. #define FSMC_ECCPageSize_8192Bytes ((u32)0x000A0000)
  212. #define IS_FSMC_ECCPAGE_SIZE(SIZE) (((SIZE) == FSMC_ECCPageSize_256Bytes) || \
  213. ((SIZE) == FSMC_ECCPageSize_512Bytes) || \
  214. ((SIZE) == FSMC_ECCPageSize_1024Bytes) || \
  215. ((SIZE) == FSMC_ECCPageSize_2048Bytes) || \
  216. ((SIZE) == FSMC_ECCPageSize_4096Bytes) || \
  217. ((SIZE) == FSMC_ECCPageSize_8192Bytes))
  218. /* FSMC TCLR Setup Time ------------------------------------------------------*/
  219. #define IS_FSMC_TCLR_TIME(TIME) ((TIME) <= 0xFF)
  220. /* FSMC TAR Setup Time -------------------------------------------------------*/
  221. #define IS_FSMC_TAR_TIME(TIME) ((TIME) <= 0xFF)
  222. /* FSMC Setup Time ----------------------------------------------------*/
  223. #define IS_FSMC_SETUP_TIME(TIME) ((TIME) <= 0xFF)
  224. /* FSMC Wait Setup Time -----------------------------------------------*/
  225. #define IS_FSMC_WAIT_TIME(TIME) ((TIME) <= 0xFF)
  226. /* FSMC Hold Setup Time -----------------------------------------------*/
  227. #define IS_FSMC_HOLD_TIME(TIME) ((TIME) <= 0xFF)
  228. /* FSMC HiZ Setup Time ------------------------------------------------*/
  229. #define IS_FSMC_HIZ_TIME(TIME) ((TIME) <= 0xFF)
  230. /* FSMC Interrupt sources ----------------------------------------------------*/
  231. #define FSMC_IT_RisingEdge ((u32)0x00000008)
  232. #define FSMC_IT_Level ((u32)0x00000010)
  233. #define FSMC_IT_FallingEdge ((u32)0x00000020)
  234. #define IS_FSMC_IT(IT) ((((IT) & (u32)0xFFFFFFC7) == 0x00000000) && ((IT) != 0x00000000))
  235. #define IS_FSMC_GET_IT(IT) (((IT) == FSMC_IT_RisingEdge) || \
  236. ((IT) == FSMC_IT_Level) || \
  237. ((IT) == FSMC_IT_FallingEdge))
  238. /* FSMC Flags ----------------------------------------------------------------*/
  239. #define FSMC_FLAG_RisingEdge ((u32)0x00000001)
  240. #define FSMC_FLAG_Level ((u32)0x00000002)
  241. #define FSMC_FLAG_FallingEdge ((u32)0x00000004)
  242. #define FSMC_FLAG_FEMPT ((u32)0x00000040)
  243. #define IS_FSMC_GET_FLAG(FLAG) (((FLAG) == FSMC_FLAG_RisingEdge) || \
  244. ((FLAG) == FSMC_FLAG_Level) || \
  245. ((FLAG) == FSMC_FLAG_FallingEdge) || \
  246. ((FLAG) == FSMC_FLAG_FEMPT))
  247. #define IS_FSMC_CLEAR_FLAG(FLAG) ((((FLAG) & (u32)0xFFFFFFF8) == 0x00000000) && ((FLAG) != 0x00000000))
  248. /* Exported macro ------------------------------------------------------------*/
  249. /* Exported functions ------------------------------------------------------- */
  250. void FSMC_NORSRAMDeInit(u32 FSMC_Bank);
  251. void FSMC_NANDDeInit(u32 FSMC_Bank);
  252. void FSMC_PCCARDDeInit(void);
  253. void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
  254. void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
  255. void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
  256. void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
  257. void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
  258. void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
  259. void FSMC_NORSRAMCmd(u32 FSMC_Bank, FunctionalState NewState);
  260. void FSMC_NANDCmd(u32 FSMC_Bank, FunctionalState NewState);
  261. void FSMC_PCCARDCmd(FunctionalState NewState);
  262. void FSMC_NANDECCCmd(u32 FSMC_Bank, FunctionalState NewState);
  263. u32 FSMC_GetECC(u32 FSMC_Bank);
  264. void FSMC_ITConfig(u32 FSMC_Bank, u32 FSMC_IT, FunctionalState NewState);
  265. FlagStatus FSMC_GetFlagStatus(u32 FSMC_Bank, u32 FSMC_FLAG);
  266. void FSMC_ClearFlag(u32 FSMC_Bank, u32 FSMC_FLAG);
  267. ITStatus FSMC_GetITStatus(u32 FSMC_Bank, u32 FSMC_IT);
  268. void FSMC_ClearITPendingBit(u32 FSMC_Bank, u32 FSMC_IT);
  269. #endif /*__STM32F10x_FSMC_H */
  270. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/