点击(此处)折叠或打开
- typedef struct
- {
- uint32_t FSMC_Bank;//nor被分为四块,其中这个参数是说明对那个块编程
- uint32_t FSMC_DataAddressMux;//地址\数据是否复用
- uint32_t FSMC_MemoryType;//存储器类型
- uint32_t FSMC_MemoryDataWidth;//数据总线宽度 8位/16位
- uint32_t FSMC_BurstAccessMode;//是否进行成组模式访问
- uint32_t FSMC_WaitSignalPolarity;//等待信号有效级性
- uint32_t FSMC_WrapMode;//该位决定控制器是否支持把非对齐的AHB成组操作分割成2次线性操作;该位仅在存储器的成组模式下有效。
- uint32_t FSMC_WaitSignalActive;//当闪存存储器处于成组传输模式时,NWAIT信号指示从闪存存储器出来的数据是否有效或是否需要插入等待周期。该位决定存储器是在等待状态之前的一个时钟周期产生NWAIT信号,还是在等待状态期间产生NWAIT信号。
- uint32_t FSMC_WriteOperation;//该位指示FSMC是否允许/禁止对存储器的写操作。
- uint32_t FSMC_WaitSignal;//当闪存存储器处于成组传输模式时,这一位允许/禁止通过NWAIT信号插入等待状态。
- uint32_t FSMC_ExtendedMode;//该位允许FSMC使用FSMC_BWTR寄存器,即允许读和写使用不同的时序。
- uint32_t FSMC_WriteBurst; //对于处于成组传输模式的闪存存储器,这一位允许/禁止通过NWAIT信号插入等待状态。读操作的同步成组传输协议使能位是FSMC_BCRx寄存器的BURSTEN位。
- FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct;//读时序配置指针
- FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct;//写时序配置指针
- }FSMC_NORSRAMInitTypeDef;
点击(此处)折叠或打开
- typedef struct
- {
- uint32_t FSMC_AddressSetupTime;//这些位定义地址的建立时间,适用于SRAM、ROM和异步总线复用模式的 NOR闪存操作。
- uint32_t FSMC_AddressHoldTime;//这些位定义地址的保持时间,适用于SRAM、ROM和异步总线复用模式的 NOR闪存操作。
- uint32_t FSMC_DataSetupTime;//这些位定义数据的保持时间,适用于SRAM、ROM和异步总线复用模式的NOR闪存操作。
- uint32_t FSMC_BusTurnAroundDuration;//这些位用于定义一次读操作之后在总线上的延迟(仅适用于总线复用模式的NOR闪存操作),一次读操作之后控制器需要在数据总线上为下次操作送出地址,这个延迟就是为了防止总线冲突。如果扩展的存储器系统不包含总线复用模式的存储器,或最慢的存储器可以在6个HCLK时钟周期内将数据总线恢复到高阻状态,可以设置这个参数为其最小值。
- uint32_t FSMC_CLKDivision;//定义CLK时钟输出信号的周期,以HCLK周期数表示:
- uint32_t FSMC_DataLatency;//处于同步成组模式的NOR闪存,需要定义在读取第一个数据之前等待的存储器周期数目。 这个时间参数不是以HCLK表示,而是以闪存时钟(CLK)表示。在访问异步NOR闪存、SRAM或ROM时,这个参数不起作用。操作CRAM时,这个参数必须为0。
- uint32_t FSMC_AccessMode; //访问模式
- }FSMC_NORSRAMTimingInitTypeDef;
点击(此处)折叠或打开
- void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
- {
- /* 验证参数*/
- assert_param(IS_FSMC_NORSRAM_BANK(FSMC_NORSRAMInitStruct->FSMC_Bank));
- assert_param(IS_FSMC_MUX(FSMC_NORSRAMInitStruct->FSMC_DataAddressMux));
- assert_param(IS_FSMC_MEMORY(FSMC_NORSRAMInitStruct->FSMC_MemoryType));
- assert_param(IS_FSMC_MEMORY_WIDTH(FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth));
- assert_param(IS_FSMC_BURSTMODE(FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode));
- assert_param(IS_FSMC_WAIT_POLARITY(FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity));
- assert_param(IS_FSMC_WRAP_MODE(FSMC_NORSRAMInitStruct->FSMC_WrapMode));
- assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive));
- assert_param(IS_FSMC_WRITE_OPERATION(FSMC_NORSRAMInitStruct->FSMC_WriteOperation));
- assert_param(IS_FSMC_WAITE_SIGNAL(FSMC_NORSRAMInitStruct->FSMC_WaitSignal));
- assert_param(IS_FSMC_EXTENDED_MODE(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode));
- assert_param(IS_FSMC_WRITE_BURST(FSMC_NORSRAMInitStruct->FSMC_WriteBurst));
- assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime));
- assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime));
- assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime));
- assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration));
- assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision));
- assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency));
- assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode));
- /* 将控制参数组合成32位数据送给 FSMC_Bank 寄存器,其中 FSMC_Bank 为偏移地址*/
- FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] =
- (uint32_t)FSMC_NORSRAMInitStruct->FSMC_DataAddressMux |
- FSMC_NORSRAMInitStruct->FSMC_MemoryType |
- FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth |
- FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode |
- FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity |
- FSMC_NORSRAMInitStruct->FSMC_WrapMode |
- FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive |
- FSMC_NORSRAMInitStruct->FSMC_WriteOperation |
- FSMC_NORSRAMInitStruct->FSMC_WaitSignal |
- FSMC_NORSRAMInitStruct->FSMC_ExtendedMode |
- FSMC_NORSRAMInitStruct->FSMC_WriteBurst;
- //如果为NOR内存
- if(FSMC_NORSRAMInitStruct->FSMC_MemoryType == FSMC_MemoryType_NOR)
- {
- //允许对NOR闪存存储器的访问操作
- FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] |= (uint32_t)BCR_FACCEN_Set;
- }
- /* 将参数组合,操作时序配置寄存器 FSMC_Bank 为偏移地址 +1(+4)指向时序配置寄存器*/
- FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank+1] =
- (uint32_t)FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime << 4) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime << 8) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision << 20) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency << 24) |
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode;
- /* 是否使用写时序*/
- if(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode == FSMC_ExtendedMode_Enable)
- {
- //写时序配置参数是否正确
- assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime));
- assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime));
- assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime));
- assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision));
- assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency));
- assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode));
- //正确则组合参数赋给写时序配置寄存器其中 FSMC_Bank和上面一样为偏移地址,则基地址为写时序配置寄存器组的基地址
- FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] =
- (uint32_t)FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime |
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime << 4 )|
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime << 8) |
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision << 20) |
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency << 24) |
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode;
- }
- else
- {
- //否则写时序配置寄存器无效
- FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 0x0FFFFFFF;
- }
- }