fsmc协议

背景知识:

存储器

存储器可以简单的分为ram和rom。ram和rom最大的区别是掉电是否会丢失。

ram可以分为sram和dram,sram是静态存储器,不需要时刻刷新,dram是动态存储器,需要刷新。

rom掉电不丢失,有flah(nor flash, nand flah),eeprom等存储。

存储器的影响因素有存储容量,读写速度,稳定性,是否需要刷新等。

代码部分

norflash时间初始化结构体

背景知识

先搞清逻辑关系。这是CPU读存储器的时序。CPU索取,存储器付出。我有很多单元,你要读我,至少要把那个单元的门牌号告诉我吧?——这就是地址线,由CPU填写(输出);地址线上非1即0,你放不放地址都这样的,所以,你要告诉我什么时候是“地址”,什么时候是“垃圾”吧?——这就是OE线下降沿的作用,也要CPU填写。(一般来说,要在地址稳定以后,OE才发出下降沿。上面图没有给出这个差别。) 好了,CPU该办的手续已经完了,球到了存储器一边。我要去这个单元找东西,总需要点时间吧?——这就是OE下降沿以后,RAM发出数据的时间间隔。艾玛,累死我了,你要的东西找到了,我放上去了!按说,数据放到总线上了,可是CPU如何才能知道数据来了呢?因为不论是数据还是垃圾,那电线上面总有1、0这些东西。这时出现不同解决方法了。一种方法,由存储器给CPU发出一个通知信号:好了,快来拿!这个信号通常叫做 Data Available,数据可得,简写 DAV,可能有人见过。CPU接到这个信号,自然会做。另一种方法,有老大强势规定:OE下降沿之后,你丫必须在1秒钟之内把东西交出来!我只管时间到就来拿!这是多数存储器遵守的规定。这两种方法,由于是不同的公司提出的,经常以公司名字来命名。Motorola总线,intel总线,听说过吧?OK,明白这些意思,稍微想一想,应当就可以理解各种时序的时间了。以后再不用问人了。另外,手册里经常可以看到,这些时间一般会有最大值、最小值,有些只给出一项。比如上面提到,从OE下降沿到存储器交出数据的时间,在存储器手册里面,这个时间只会给出最大值。因为用户必须按“最长时间”操作,不能有侥幸心理。给出最小值没有实际意义。

typedef struct
{
  uint32_t FSMC_AddressSetupTime;       /*!< Defines the number of HCLK cycles to configure
                                             the duration of the address setup time. 
                                             This parameter can be a value between 0 and 0xF.
                                             @note: It is not used with synchronous NOR Flash memories. */

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

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

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

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

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

  uint32_t FSMC_AccessMode;             /*!< Specifies the asynchronous access mode. 
                                             This parameter can be a value of @ref FSMC_Access_Mode */
}FSMC_NORSRAMTimingInitTypeDef;

FSMC_AddressSetupTime是地址建立时间

FSMC_AddressHoldTime是地址保持时间

FSMC_DataSetupTime是数据建立时间

FSMC_BusTurnAroundDuration数据总线切换方向的时间,比如从读转换到写

FSMC_CLKDivision(对于FSMC_CLK,从AHB总线上使用的分频系数)

FSMC_DataLatency 数据保持时间,仅用于同步模式

FSMC_AccessMode(仅用于extended mode) modeA,modeB,modeC,modeD等会使用不同的读写时序,还有mode1,mode2。一般来说,sram使用mode A,nor flash使用mode B

地址建立,保存时间;数据建立,保存时间得根据数据手册确定。

norflahs/ram初始化结构体介绍

typedef struct
{
  uint32_t FSMC_Bank;                /*!< Specifies the NOR/SRAM memory bank that will be used.
                                          This parameter can be a value of @ref FSMC_NORSRAM_Bank */

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

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

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

  uint32_t FSMC_BurstAccessMode;     /*!< Enables or disables the burst access mode for Flash memory,
                                          valid only with synchronous burst Flash memories.
                                          This parameter can be a value of @ref FSMC_Burst_Access_Mode */
                                       
  uint32_t FSMC_AsynchronousWait;     /*!< Enables or disables wait signal during asynchronous transfers,
                                          valid only with asynchronous Flash memories.
                                          This parameter can be a value of @ref FSMC_AsynchronousWait */

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

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

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

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

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

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

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

  FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct; /*!< Timing Parameters for write and read access if the  ExtendedMode is not used*/  

  FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct;     /*!< Timing Parameters for write access if the  ExtendedMode is used*/      
}FSMC_NORSRAMInitTypeDef;

FSMC_Bank: ram/nor flash有4个区域地址,选择哪个地址。

FSMC_DataAddressMux: 确定数据总线与地址总线是否复用

FSMC_MemoryType: stm32fsmc有4个区域块,nor/flash,2块ram,1块pc card,要选择哪个区域块。

FSMC_MemoryDataWidth:存储器数据数据总线宽度

FSMC_BurstAccessMode:存储器是否启用突发读写模式,普通模式,就是写入一次数据就需要写入一次地址。而突发模式,则是只提供一个地址,连续写入多个数据。

FSMC_AsynchronousWait:异步模式

FSMC_AsynchronousWait:异步模式时,是否等待存储器发出响应再去读写。

FSMC_WaitSignalPolarity:在burst mode下,等待信号的极性。

FSMC_WrapMode:启用该模式时,访问达到存储器的边界地址时,将重新访问起始地址。

FSMC_WaitSignalActive:等待信号在等待状态之前被激活还是之后被激活

FSMC_WriteOperation:是否写使能

FSMC_WaitSignal:在burst模式下,是否开启等待信号。

FSMC_WriteBurst: 是否开启突发读写模式

FSMC_ReadWriteTimingStruct:读时序结构体指针

FSMC_WriteTimingStruct:写时序结构体指针

初始化思路

hal库,固件库,别的种类单片机的fsmc等初始化操作在细节方面肯定有许多不同,所以记住大致的初始化操作就可以了,其余的细节等要用时找datasheet和看例程。

初始化流程:

1:确定存储器的类型,然后确定其存储区域(第几大块,第几小块)。

2:确定存储器数据总线的宽度

3:确定存储器的读写方式。(比如是否采用突发模式,是否开启等待信号,等待信号的极性,等待信号的产生是否在等待周期前,还是在等待周期后)。

4:确定读写时序,比如发出地址信号,存储器找到该信号需要多少时间,发出数据信号,存储器找到该信号需要多久时间。处理器向存储器发出这个地址的时间长度是多久。处理器向存储器发出的数据信号要持续多久。

基本的启动时钟,引脚复用就不叙述了。

效果演示

效果视频

反思:

野火驱动tft lcd的相关代码有几千行左右,该lcd是mcu接口。通过mcu32pin并行接口----ILI9341----vga----lcd进行显示。

如果要懂全部细节,需要大量时间,且不现实,也不符合收益。比如burst mode具体怎么操作,如果死磕,需要大量时间,且并没有收益;再比如lcd 的初始化,那些参数特别复杂,需要花大量时间去看寄存器手册,收益就是懂了lcd得初始化,收益小于付出。

所以对待这些复杂传感器:更好的学习办法是,根据提供得代码和接口进行应用,形成一个大概的框架,等到具体需要得时候再去细究。

参考文章:

stm fmsc驱动tft屏幕应用笔记
​​​微控制器的FSMC到底是咋回事?

  • 18
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值