你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】STM32 FSMC相关函数和类型

[复制链接]
STMCU小助手 发布时间:2022-3-29 09:52
01. 概述
FSMC 相关的库函数分布在 stm32f4xx_fsmc.c 文件和头文件 stm32f4xx_fsmc.h 中。

02. 相关类型
FSMC_NORSRAMTimingInitTypeDef类型


  1. /**
  2.   * @brief  Timing parameters For NOR/SRAM Banks  
  3.   */
  4. typedef struct
  5. {
  6.   uint32_t FSMC_AddressSetupTime;       /*!< Defines the number of HCLK cycles to configure
  7.                                              the duration of the address setup time.
  8.                                              This parameter can be a value between 0 and 0xF.
  9.                                              @note This parameter is not used with synchronous NOR Flash memories. */

  10.   uint32_t FSMC_AddressHoldTime;        /*!< Defines the number of HCLK cycles to configure
  11.                                              the duration of the address hold time.
  12.                                              This parameter can be a value between 0 and 0xF.
  13.                                              @note This parameter is not used with synchronous NOR Flash memories.*/

  14.   uint32_t FSMC_DataSetupTime;          /*!< Defines the number of HCLK cycles to configure
  15.                                              the duration of the data setup time.
  16.                                              This parameter can be a value between 0 and 0xFF.
  17.                                              @note This parameter is used for SRAMs, ROMs and asynchronous multiplexed NOR Flash memories. */

  18.   uint32_t FSMC_BusTurnAroundDuration;  /*!< Defines the number of HCLK cycles to configure
  19.                                              the duration of the bus turnaround.
  20.                                              This parameter can be a value between 0 and 0xF.
  21.                                              @note This parameter is only used for multiplexed NOR Flash memories. */

  22.   uint32_t FSMC_CLKDivision;            /*!< Defines the period of CLK clock output signal, expressed in number of HCLK cycles.
  23.                                              This parameter can be a value between 1 and 0xF.
  24.                                              @note This parameter is not used for asynchronous NOR Flash, SRAM or ROM accesses. */

  25.   uint32_t FSMC_DataLatency;            /*!< Defines the number of memory clock cycles to issue
  26.                                              to the memory before getting the first data.
  27.                                              The parameter value depends on the memory type as shown below:
  28.                                               - It must be set to 0 in case of a CRAM
  29.                                               - It is don't care in asynchronous NOR, SRAM or ROM accesses
  30.                                               - It may assume a value between 0 and 0xF in NOR Flash memories
  31.                                                 with synchronous burst mode enable */

  32.   uint32_t FSMC_AccessMode;             /*!< Specifies the asynchronous access mode.
  33.                                              This parameter can be a value of @ref FSMC_Access_Mode */
  34. }FSMC_NORSRAMTimingInitTypeDef;
复制代码

FSMC_NORSRAMInitTypeDef类型

  1. /**
  2.   * @brief  FSMC NOR/SRAM Init structure definition
  3.   */
  4. typedef struct
  5. {
  6.   uint32_t FSMC_Bank;                /*!< Specifies the NOR/SRAM memory bank that will be used.
  7.                                           This parameter can be a value of @ref FSMC_NORSRAM_Bank */

  8.   uint32_t FSMC_DataAddressMux;      /*!< Specifies whether the address and data values are
  9.                                           multiplexed on the data bus or not.
  10.                                           This parameter can be a value of @ref FSMC_Data_Address_Bus_Multiplexing */

  11.   uint32_t FSMC_MemoryType;          /*!< Specifies the type of external memory attached to
  12.                                           the corresponding memory bank.
  13.                                           This parameter can be a value of @ref FSMC_Memory_Type */

  14.   uint32_t FSMC_MemoryDataWidth;     /*!< Specifies the external memory device width.
  15.                                           This parameter can be a value of @ref FSMC_Data_Width */

  16.   uint32_t FSMC_BurstAccessMode;     /*!< Enables or disables the burst access mode for Flash memory,
  17.                                           valid only with synchronous burst Flash memories.
  18.                                           This parameter can be a value of @ref FSMC_Burst_Access_Mode */

  19.   uint32_t FSMC_AsynchronousWait;     /*!< Enables or disables wait signal during asynchronous transfers,
  20.                                           valid only with asynchronous Flash memories.
  21.                                           This parameter can be a value of @ref FSMC_AsynchronousWait */                                          

  22.   uint32_t FSMC_WaitSignalPolarity;  /*!< Specifies the wait signal polarity, valid only when accessing
  23.                                           the Flash memory in burst mode.
  24.                                           This parameter can be a value of @ref FSMC_Wait_Signal_Polarity */

  25.   uint32_t FSMC_WrapMode;            /*!< Enables or disables the Wrapped burst access mode for Flash
  26.                                           memory, valid only when accessing Flash memories in burst mode.
  27.                                           This parameter can be a value of @ref FSMC_Wrap_Mode */

  28.   uint32_t FSMC_WaitSignalActive;    /*!< Specifies if the wait signal is asserted by the memory one
  29.                                           clock cycle before the wait state or during the wait state,
  30.                                           valid only when accessing memories in burst mode.
  31.                                           This parameter can be a value of @ref FSMC_Wait_Timing */

  32.   uint32_t FSMC_WriteOperation;      /*!< Enables or disables the write operation in the selected bank by the FSMC.
  33.                                           This parameter can be a value of @ref FSMC_Write_Operation */

  34.   uint32_t FSMC_WaitSignal;          /*!< Enables or disables the wait state insertion via wait
  35.                                           signal, valid for Flash memory access in burst mode.
  36.                                           This parameter can be a value of @ref FSMC_Wait_Signal */

  37.   uint32_t FSMC_ExtendedMode;        /*!< Enables or disables the extended mode.
  38.                                           This parameter can be a value of @ref FSMC_Extended_Mode */

  39.   uint32_t FSMC_WriteBurst;          /*!< Enables or disables the write burst operation.
  40.                                           This parameter can be a value of @ref FSMC_Write_Burst */

  41.   FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct; /*!< Timing Parameters for write and read access if the  Extended Mode is not used*/  

  42.   FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct;     /*!< Timing Parameters for write access if the  Extended Mode is used*/      
  43. }FSMC_NORSRAMInitTypeDef;
复制代码

FSMC_NAND_PCCARDTimingInitTypeDef类型

  1. /**
  2.   * @brief  Timing parameters For FSMC NAND and PCCARD Banks
  3.   */
  4. typedef struct
  5. {
  6.   uint32_t FSMC_SetupTime;      /*!< Defines the number of HCLK cycles to setup address before
  7.                                      the command assertion for NAND Flash read or write access
  8.                                      to common/Attribute or I/O memory space (depending on
  9.                                      the memory space timing to be configured).
  10.                                      This parameter can be a value between 0 and 0xFF.*/

  11.   uint32_t FSMC_WaitSetupTime;  /*!< Defines the minimum number of HCLK cycles to assert the
  12.                                      command for NAND Flash read or write access to
  13.                                      common/Attribute or I/O memory space (depending on the
  14.                                      memory space timing to be configured).
  15.                                      This parameter can be a number between 0x00 and 0xFF */

  16.   uint32_t FSMC_HoldSetupTime;  /*!< Defines the number of HCLK clock cycles to hold address
  17.                                      (and data for write access) after the command de-assertion
  18.                                      for NAND Flash read or write access to common/Attribute
  19.                                      or I/O memory space (depending on the memory space timing
  20.                                      to be configured).
  21.                                      This parameter can be a number between 0x00 and 0xFF */

  22.   uint32_t FSMC_HiZSetupTime;   /*!< Defines the number of HCLK clock cycles during which the
  23.                                      data bus is kept in HiZ after the start of a NAND Flash
  24.                                      write access to common/Attribute or I/O memory space (depending
  25.                                      on the memory space timing to be configured).
  26.                                      This parameter can be a number between 0x00 and 0xFF */
  27. }FSMC_NAND_PCCARDTimingInitTypeDef;
复制代码

FSMC_NANDInitTypeDef类型

  1. /**
  2.   * @brief  FSMC NAND Init structure definition
  3.   */
  4. typedef struct
  5. {
  6.   uint32_t FSMC_Bank;              /*!< Specifies the NAND memory bank that will be used.
  7.                                       This parameter can be a value of @ref FSMC_NAND_Bank */

  8.   uint32_t FSMC_Waitfeature;      /*!< Enables or disables the Wait feature for the NAND Memory Bank.
  9.                                        This parameter can be any value of @ref FSMC_Wait_feature */

  10.   uint32_t FSMC_MemoryDataWidth;  /*!< Specifies the external memory device width.
  11.                                        This parameter can be any value of @ref FSMC_Data_Width */

  12.   uint32_t FSMC_ECC;              /*!< Enables or disables the ECC computation.
  13.                                        This parameter can be any value of @ref FSMC_ECC */

  14.   uint32_t FSMC_ECCPageSize;      /*!< Defines the page size for the extended ECC.
  15.                                        This parameter can be any value of @ref FSMC_ECC_Page_Size */

  16.   uint32_t FSMC_TCLRSetupTime;    /*!< Defines the number of HCLK cycles to configure the
  17.                                        delay between CLE low and RE low.
  18.                                        This parameter can be a value between 0 and 0xFF. */

  19.   uint32_t FSMC_TARSetupTime;     /*!< Defines the number of HCLK cycles to configure the
  20.                                        delay between ALE low and RE low.
  21.                                        This parameter can be a number between 0x0 and 0xFF */

  22.   FSMC_NAND_PCCARDTimingInitTypeDef*  FSMC_CommonSpaceTimingStruct;   /*!< FSMC Common Space Timing */

  23.   FSMC_NAND_PCCARDTimingInitTypeDef*  FSMC_AttributeSpaceTimingStruct; /*!< FSMC Attribute Space Timing */
  24. }FSMC_NANDInitTypeDef;
复制代码

FSMC_PCCARDInitTypeDef类型


  1. /**
  2.   * @brief  FSMC PCCARD Init structure definition
  3.   */

  4. typedef struct
  5. {
  6.   uint32_t FSMC_Waitfeature;    /*!< Enables or disables the Wait feature for the Memory Bank.
  7.                                     This parameter can be any value of @ref FSMC_Wait_feature */

  8.   uint32_t FSMC_TCLRSetupTime;  /*!< Defines the number of HCLK cycles to configure the
  9.                                      delay between CLE low and RE low.
  10.                                      This parameter can be a value between 0 and 0xFF. */

  11.   uint32_t FSMC_TARSetupTime;   /*!< Defines the number of HCLK cycles to configure the
  12.                                      delay between ALE low and RE low.
  13.                                      This parameter can be a number between 0x0 and 0xFF */


  14.   FSMC_NAND_PCCARDTimingInitTypeDef*  FSMC_CommonSpaceTimingStruct; /*!< FSMC Common Space Timing */

  15.   FSMC_NAND_PCCARDTimingInitTypeDef*  FSMC_AttributeSpaceTimingStruct;  /*!< FSMC Attribute Space Timing */

  16.   FSMC_NAND_PCCARDTimingInitTypeDef*  FSMC_IOSpaceTimingStruct; /*!< FSMC IO Space Timing */  
  17. }FSMC_PCCARDInitTypeDef;
复制代码

相关宏定义

  1. /** @defgroup FSMC_Exported_Constants
  2.   * @{
  3.   */

  4. /** @defgroup FSMC_NORSRAM_Bank
  5.   * @{
  6.   */
  7. #define FSMC_Bank1_NORSRAM1                      ((uint32_t)0x00000000)
  8. #define FSMC_Bank1_NORSRAM2                      ((uint32_t)0x00000002)
  9. #define FSMC_Bank1_NORSRAM3                      ((uint32_t)0x00000004)
  10. #define FSMC_Bank1_NORSRAM4                      ((uint32_t)0x00000006)
  11. /**
  12.   * @}
  13.   */

  14. /** @defgroup FSMC_NAND_Bank
  15.   * @{
  16.   */  
  17. #define FSMC_Bank2_NAND                          ((uint32_t)0x00000010)
  18. #define FSMC_Bank3_NAND                          ((uint32_t)0x00000100)
  19. /**
  20.   * @}
  21.   */

  22. /** @defgroup FSMC_PCCARD_Bank
  23.   * @{
  24.   */   
  25. #define FSMC_Bank4_PCCARD                        ((uint32_t)0x00001000)
  26. /**
  27.   * @}
  28.   */

  29. #define IS_FSMC_NORSRAM_BANK(BANK) (((BANK) == FSMC_Bank1_NORSRAM1) || \
  30.                                     ((BANK) == FSMC_Bank1_NORSRAM2) || \
  31.                                     ((BANK) == FSMC_Bank1_NORSRAM3) || \
  32.                                     ((BANK) == FSMC_Bank1_NORSRAM4))

  33. #define IS_FSMC_NAND_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  34.                                  ((BANK) == FSMC_Bank3_NAND))

  35. #define IS_FSMC_GETFLAG_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  36.                                     ((BANK) == FSMC_Bank3_NAND) || \
  37.                                     ((BANK) == FSMC_Bank4_PCCARD))

  38. #define IS_FSMC_IT_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  39.                                ((BANK) == FSMC_Bank3_NAND) || \
  40.                                ((BANK) == FSMC_Bank4_PCCARD))

  41. /** @defgroup FSMC_NOR_SRAM_Controller
  42.   * @{
  43.   */

  44. /** @defgroup FSMC_Data_Address_Bus_Multiplexing
  45.   * @{
  46.   */

  47. #define FSMC_DataAddressMux_Disable                ((uint32_t)0x00000000)
  48. #define FSMC_DataAddressMux_Enable                 ((uint32_t)0x00000002)
  49. #define IS_FSMC_MUX(MUX) (((MUX) == FSMC_DataAddressMux_Disable) || \
  50.                           ((MUX) == FSMC_DataAddressMux_Enable))
  51. /**
  52.   * @}
  53.   */

  54. /** @defgroup FSMC_Memory_Type
  55.   * @{
  56.   */

  57. #define FSMC_MemoryType_SRAM                     ((uint32_t)0x00000000)
  58. #define FSMC_MemoryType_PSRAM                    ((uint32_t)0x00000004)
  59. #define FSMC_MemoryType_NOR                      ((uint32_t)0x00000008)
  60. #define IS_FSMC_MEMORY(MEMORY) (((MEMORY) == FSMC_MemoryType_SRAM) || \
  61.                                 ((MEMORY) == FSMC_MemoryType_PSRAM)|| \
  62.                                 ((MEMORY) == FSMC_MemoryType_NOR))
  63. /**
  64.   * @}
  65.   */

  66. /** @defgroup FSMC_Data_Width
  67.   * @{
  68.   */

  69. #define FSMC_MemoryDataWidth_8b                  ((uint32_t)0x00000000)
  70. #define FSMC_MemoryDataWidth_16b                 ((uint32_t)0x00000010)
  71. #define IS_FSMC_MEMORY_WIDTH(WIDTH) (((WIDTH) == FSMC_MemoryDataWidth_8b) || \
  72.                                      ((WIDTH) == FSMC_MemoryDataWidth_16b))
  73. /**
  74.   * @}
  75.   */

  76. /** @defgroup FSMC_Burst_Access_Mode
  77.   * @{
  78.   */

  79. #define FSMC_BurstAccessMode_Disable             ((uint32_t)0x00000000)
  80. #define FSMC_BurstAccessMode_Enable              ((uint32_t)0x00000100)
  81. #define IS_FSMC_BURSTMODE(STATE) (((STATE) == FSMC_BurstAccessMode_Disable) || \
  82.                                   ((STATE) == FSMC_BurstAccessMode_Enable))
  83. /**
  84.   * @}
  85.   */

  86. /** @defgroup FSMC_AsynchronousWait
  87.   * @{
  88.   */
  89. #define FSMC_AsynchronousWait_Disable            ((uint32_t)0x00000000)
  90. #define FSMC_AsynchronousWait_Enable             ((uint32_t)0x00008000)
  91. #define IS_FSMC_ASYNWAIT(STATE) (((STATE) == FSMC_AsynchronousWait_Disable) || \
  92.                                  ((STATE) == FSMC_AsynchronousWait_Enable))
  93. /**
  94.   * @}
  95.   */

  96. /** @defgroup FSMC_Wait_Signal_Polarity
  97.   * @{
  98.   */
  99. #define FSMC_WaitSignalPolarity_Low              ((uint32_t)0x00000000)
  100. #define FSMC_WaitSignalPolarity_High             ((uint32_t)0x00000200)
  101. #define IS_FSMC_WAIT_POLARITY(POLARITY) (((POLARITY) == FSMC_WaitSignalPolarity_Low) || \
  102.                                          ((POLARITY) == FSMC_WaitSignalPolarity_High))
  103. /**
  104.   * @}
  105.   */

  106. /** @defgroup FSMC_Wrap_Mode
  107.   * @{
  108.   */
  109. #define FSMC_WrapMode_Disable                    ((uint32_t)0x00000000)
  110. #define FSMC_WrapMode_Enable                     ((uint32_t)0x00000400)
  111. #define IS_FSMC_WRAP_MODE(MODE) (((MODE) == FSMC_WrapMode_Disable) || \
  112.                                  ((MODE) == FSMC_WrapMode_Enable))
  113. /**
  114.   * @}
  115.   */

  116. /** @defgroup FSMC_Wait_Timing
  117.   * @{
  118.   */
  119. #define FSMC_WaitSignalActive_BeforeWaitState    ((uint32_t)0x00000000)
  120. #define FSMC_WaitSignalActive_DuringWaitState    ((uint32_t)0x00000800)
  121. #define IS_FSMC_WAIT_SIGNAL_ACTIVE(ACTIVE) (((ACTIVE) == FSMC_WaitSignalActive_BeforeWaitState) || \
  122.                                             ((ACTIVE) == FSMC_WaitSignalActive_DuringWaitState))
  123. /**
  124.   * @}
  125.   */

  126. /** @defgroup FSMC_Write_Operation
  127.   * @{
  128.   */
  129. #define FSMC_WriteOperation_Disable                     ((uint32_t)0x00000000)
  130. #define FSMC_WriteOperation_Enable                      ((uint32_t)0x00001000)
  131. #define IS_FSMC_WRITE_OPERATION(OPERATION) (((OPERATION) == FSMC_WriteOperation_Disable) || \
  132.                                             ((OPERATION) == FSMC_WriteOperation_Enable))                        
  133. /**
  134.   * @}
  135.   */

  136. /** @defgroup FSMC_Wait_Signal
  137.   * @{
  138.   */
  139. #define FSMC_WaitSignal_Disable                  ((uint32_t)0x00000000)
  140. #define FSMC_WaitSignal_Enable                   ((uint32_t)0x00002000)
  141. #define IS_FSMC_WAITE_SIGNAL(SIGNAL) (((SIGNAL) == FSMC_WaitSignal_Disable) || \
  142.                                       ((SIGNAL) == FSMC_WaitSignal_Enable))
  143. /**
  144.   * @}
  145.   */

  146. /** @defgroup FSMC_Extended_Mode
  147.   * @{
  148.   */
  149. #define FSMC_ExtendedMode_Disable                ((uint32_t)0x00000000)
  150. #define FSMC_ExtendedMode_Enable                 ((uint32_t)0x00004000)

  151. #define IS_FSMC_EXTENDED_MODE(MODE) (((MODE) == FSMC_ExtendedMode_Disable) || \
  152.                                      ((MODE) == FSMC_ExtendedMode_Enable))
  153. /**
  154.   * @}
  155.   */

  156. /** @defgroup FSMC_Write_Burst
  157.   * @{
  158.   */

  159. #define FSMC_WriteBurst_Disable                  ((uint32_t)0x00000000)
  160. #define FSMC_WriteBurst_Enable                   ((uint32_t)0x00080000)
  161. #define IS_FSMC_WRITE_BURST(BURST) (((BURST) == FSMC_WriteBurst_Disable) || \
  162.                                     ((BURST) == FSMC_WriteBurst_Enable))
  163. /**
  164.   * @}
  165.   */

  166. /** @defgroup FSMC_Address_Setup_Time
  167.   * @{
  168.   */
  169. #define IS_FSMC_ADDRESS_SETUP_TIME(TIME) ((TIME) <= 0xF)
  170. /**
  171.   * @}
  172.   */

  173. /** @defgroup FSMC_Address_Hold_Time
  174.   * @{
  175.   */
  176. #define IS_FSMC_ADDRESS_HOLD_TIME(TIME) ((TIME) <= 0xF)
  177. /**
  178.   * @}
  179.   */

  180. /** @defgroup FSMC_Data_Setup_Time
  181.   * @{
  182.   */
  183. #define IS_FSMC_DATASETUP_TIME(TIME) (((TIME) > 0) && ((TIME) <= 0xFF))
  184. /**
  185.   * @}
  186.   */

  187. /** @defgroup FSMC_Bus_Turn_around_Duration
  188.   * @{
  189.   */
  190. #define IS_FSMC_TURNAROUND_TIME(TIME) ((TIME) <= 0xF)
  191. /**
  192.   * @}
  193.   */

  194. /** @defgroup FSMC_CLK_Division
  195.   * @{
  196.   */
  197. #define IS_FSMC_CLK_DIV(DIV) ((DIV) <= 0xF)
  198. /**
  199.   * @}
  200.   */

  201. /** @defgroup FSMC_Data_Latency
  202.   * @{
  203.   */
  204. #define IS_FSMC_DATA_LATENCY(LATENCY) ((LATENCY) <= 0xF)
  205. /**
  206.   * @}
  207.   */

  208. /** @defgroup FSMC_Access_Mode
  209.   * @{
  210.   */
  211. #define FSMC_AccessMode_A                        ((uint32_t)0x00000000)
  212. #define FSMC_AccessMode_B                        ((uint32_t)0x10000000)
  213. #define FSMC_AccessMode_C                        ((uint32_t)0x20000000)
  214. #define FSMC_AccessMode_D                        ((uint32_t)0x30000000)
  215. #define IS_FSMC_ACCESS_MODE(MODE) (((MODE) == FSMC_AccessMode_A) || \
  216.                                    ((MODE) == FSMC_AccessMode_B) || \
  217.                                    ((MODE) == FSMC_AccessMode_C) || \
  218.                                    ((MODE) == FSMC_AccessMode_D))
  219. /**
  220.   * @}
  221.   */

  222. /**
  223.   * @}
  224.   */

  225. /** @defgroup FSMC_NAND_PCCARD_Controller
  226.   * @{
  227.   */

  228. /** @defgroup FSMC_Wait_feature
  229.   * @{
  230.   */
  231. #define FSMC_Waitfeature_Disable                 ((uint32_t)0x00000000)
  232. #define FSMC_Waitfeature_Enable                  ((uint32_t)0x00000002)
  233. #define IS_FSMC_WAIT_FEATURE(FEATURE) (((FEATURE) == FSMC_Waitfeature_Disable) || \
  234.                                        ((FEATURE) == FSMC_Waitfeature_Enable))
  235. /**
  236.   * @}
  237.   */


  238. /** @defgroup FSMC_ECC
  239.   * @{
  240.   */
  241. #define FSMC_ECC_Disable                         ((uint32_t)0x00000000)
  242. #define FSMC_ECC_Enable                          ((uint32_t)0x00000040)
  243. #define IS_FSMC_ECC_STATE(STATE) (((STATE) == FSMC_ECC_Disable) || \
  244.                                   ((STATE) == FSMC_ECC_Enable))
  245. /**
  246.   * @}
  247.   */

  248. /** @defgroup FSMC_ECC_Page_Size
  249.   * @{
  250.   */
  251. #define FSMC_ECCPageSize_256Bytes                ((uint32_t)0x00000000)
  252. #define FSMC_ECCPageSize_512Bytes                ((uint32_t)0x00020000)
  253. #define FSMC_ECCPageSize_1024Bytes               ((uint32_t)0x00040000)
  254. #define FSMC_ECCPageSize_2048Bytes               ((uint32_t)0x00060000)
  255. #define FSMC_ECCPageSize_4096Bytes               ((uint32_t)0x00080000)
  256. #define FSMC_ECCPageSize_8192Bytes               ((uint32_t)0x000A0000)
  257. #define IS_FSMC_ECCPAGE_SIZE(SIZE) (((SIZE) == FSMC_ECCPageSize_256Bytes) || \
  258.                                     ((SIZE) == FSMC_ECCPageSize_512Bytes) || \
  259.                                     ((SIZE) == FSMC_ECCPageSize_1024Bytes) || \
  260.                                     ((SIZE) == FSMC_ECCPageSize_2048Bytes) || \
  261.                                     ((SIZE) == FSMC_ECCPageSize_4096Bytes) || \
  262.                                     ((SIZE) == FSMC_ECCPageSize_8192Bytes))
  263. /**
  264.   * @}
  265.   */

  266. /** @defgroup FSMC_TCLR_Setup_Time
  267.   * @{
  268.   */
  269. #define IS_FSMC_TCLR_TIME(TIME) ((TIME) <= 0xFF)
  270. /**
  271.   * @}
  272.   */

  273. /** @defgroup FSMC_TAR_Setup_Time
  274.   * @{
  275.   */
  276. #define IS_FSMC_TAR_TIME(TIME) ((TIME) <= 0xFF)
  277. /**
  278.   * @}
  279.   */

  280. /** @defgroup FSMC_Setup_Time
  281.   * @{
  282.   */
  283. #define IS_FSMC_SETUP_TIME(TIME) ((TIME) <= 0xFF)
  284. /**
  285.   * @}
  286.   */

  287. /** @defgroup FSMC_Wait_Setup_Time
  288.   * @{
  289.   */
  290. #define IS_FSMC_WAIT_TIME(TIME) ((TIME) <= 0xFF)
  291. /**
  292.   * @}
  293.   */

  294. /** @defgroup FSMC_Hold_Setup_Time
  295.   * @{
  296.   */
  297. #define IS_FSMC_HOLD_TIME(TIME) ((TIME) <= 0xFF)
  298. /**
  299.   * @}
  300.   */

  301. /** @defgroup FSMC_HiZ_Setup_Time
  302.   * @{
  303.   */
  304. #define IS_FSMC_HIZ_TIME(TIME) ((TIME) <= 0xFF)
  305. /**
  306.   * @}
  307.   */

  308. /** @defgroup FSMC_Interrupt_sources
  309.   * @{
  310.   */
  311. #define FSMC_IT_RisingEdge                       ((uint32_t)0x00000008)
  312. #define FSMC_IT_Level                            ((uint32_t)0x00000010)
  313. #define FSMC_IT_FallingEdge                      ((uint32_t)0x00000020)
  314. #define IS_FSMC_IT(IT) ((((IT) & (uint32_t)0xFFFFFFC7) == 0x00000000) && ((IT) != 0x00000000))
  315. #define IS_FSMC_GET_IT(IT) (((IT) == FSMC_IT_RisingEdge) || \
  316.                             ((IT) == FSMC_IT_Level) || \
  317.                             ((IT) == FSMC_IT_FallingEdge))
  318. /**
  319.   * @}
  320.   */

  321. /** @defgroup FSMC_Flags
  322.   * @{
  323.   */
  324. #define FSMC_FLAG_RisingEdge                     ((uint32_t)0x00000001)
  325. #define FSMC_FLAG_Level                          ((uint32_t)0x00000002)
  326. #define FSMC_FLAG_FallingEdge                    ((uint32_t)0x00000004)
  327. #define FSMC_FLAG_FEMPT                          ((uint32_t)0x00000040)
  328. #define IS_FSMC_GET_FLAG(FLAG) (((FLAG) == FSMC_FLAG_RisingEdge) || \
  329.                                 ((FLAG) == FSMC_FLAG_Level) || \
  330.                                 ((FLAG) == FSMC_FLAG_FallingEdge) || \
  331.                                 ((FLAG) == FSMC_FLAG_FEMPT))

  332. #define IS_FSMC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFF8) == 0x00000000) && ((FLAG) != 0x00000000))
复制代码

03. 相关函数
  1. /* NOR/SRAM Controller functions **********************************************/
  2. void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank);
  3. void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
  4. void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
  5. void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState);

  6. /* NAND Controller functions **************************************************/
  7. void FSMC_NANDDeInit(uint32_t FSMC_Bank);
  8. void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
  9. void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
  10. void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState);
  11. void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState);
  12. uint32_t FSMC_GetECC(uint32_t FSMC_Bank);

  13. /* PCCARD Controller functions ************************************************/
  14. void FSMC_PCCARDDeInit(void);
  15. void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
  16. void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
  17. void FSMC_PCCARDCmd(FunctionalState NewState);

  18. /* Interrupts and flags management functions **********************************/
  19. void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState);
  20. FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG);
  21. void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG);
  22. ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT);
  23. void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT);
复制代码

04. 结构体封装
  1. typedef struct
  2. {
  3.   __IO uint32_t BTCR[8];    /*!< NOR/PSRAM chip-select control register(BCR) and chip-select timing register(BTR), Address offset: 0x00-1C */   
  4. } FSMC_Bank1_TypeDef;

  5. /**
  6.   * @brief Flexible Static Memory Controller Bank1E
  7.   */

  8. typedef struct
  9. {
  10.   __IO uint32_t BWTR[7];    /*!< NOR/PSRAM write timing registers, Address offset: 0x104-0x11C */
  11. } FSMC_Bank1E_TypeDef;

  12. /**
  13.   * @brief Flexible Static Memory Controller Bank2
  14.   */

  15. typedef struct
  16. {
  17.   __IO uint32_t PCR2;       /*!< NAND Flash control register 2,                       Address offset: 0x60 */
  18.   __IO uint32_t SR2;        /*!< NAND Flash FIFO status and interrupt register 2,     Address offset: 0x64 */
  19.   __IO uint32_t PMEM2;      /*!< NAND Flash Common memory space timing register 2,    Address offset: 0x68 */
  20.   __IO uint32_t PATT2;      /*!< NAND Flash Attribute memory space timing register 2, Address offset: 0x6C */
  21.   uint32_t      RESERVED0;  /*!< Reserved, 0x70                                                            */
  22.   __IO uint32_t ECCR2;      /*!< NAND Flash ECC result registers 2,                   Address offset: 0x74 */
  23. } FSMC_Bank2_TypeDef;

  24. /**
  25.   * @brief Flexible Static Memory Controller Bank3
  26.   */

  27. typedef struct
  28. {
  29.   __IO uint32_t PCR3;       /*!< NAND Flash control register 3,                       Address offset: 0x80 */
  30.   __IO uint32_t SR3;        /*!< NAND Flash FIFO status and interrupt register 3,     Address offset: 0x84 */
  31.   __IO uint32_t PMEM3;      /*!< NAND Flash Common memory space timing register 3,    Address offset: 0x88 */
  32.   __IO uint32_t PATT3;      /*!< NAND Flash Attribute memory space timing register 3, Address offset: 0x8C */
  33.   uint32_t      RESERVED0;  /*!< Reserved, 0x90                                                            */
  34.   __IO uint32_t ECCR3;      /*!< NAND Flash ECC result registers 3,                   Address offset: 0x94 */
  35. } FSMC_Bank3_TypeDef;

  36. /**
  37.   * @brief Flexible Static Memory Controller Bank4
  38.   */

  39. typedef struct
  40. {
  41.   __IO uint32_t PCR4;       /*!< PC Card  control register 4,                       Address offset: 0xA0 */
  42.   __IO uint32_t SR4;        /*!< PC Card  FIFO status and interrupt register 4,     Address offset: 0xA4 */
  43.   __IO uint32_t PMEM4;      /*!< PC Card  Common memory space timing register 4,    Address offset: 0xA8 */
  44.   __IO uint32_t PATT4;      /*!< PC Card  Attribute memory space timing register 4, Address offset: 0xAC */
  45.   __IO uint32_t PIO4;       /*!< PC Card  I/O space timing register 4,              Address offset: 0xB0 */
  46. } FSMC_Bank4_TypeDef;

复制代码

收藏 评论0 发布时间:2022-3-29 09:52

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版