a、首先是时间参数的配置,我们在初始化的时候设置的bank4,所以这里对应的也是bank4,本函数主要使用了两种类型的结构体对FSMC进行配置,第一种- S/ t, o% A! f% T v# d( e1 h
为 FSMC_NORSRAMInitTypeDef类型的结构体主要用于NOR FLASH的模式配置,包括存储器类型、数据宽度等。另一种的类型为FSMC_NORSRAMTimingInitTypeDef ( c3 N5 L% S5 ^$ n# f2 M0 U j
首先是这个结构体FSMC_NORSRAMTimingInitTypeDef,找到他的定义: 成员变量有
( {' ~; X: U$ \4 c) H) l
- uint32_t FSMC_AccessMode
- uint32_t FSMC_AddressHoldTime
- uint32_t FSMC_AddressSetupTime
- uint32_t FSMC_BusTurnAroundDuration
- uint32_t FSMC_CLKDivision
- uint32_t FSMC_DataLatency
- uint32_t FSMC_DataSetupTime |8 `- K# u5 J3 X/ j+ S
uint32_t FSMC_AccessMode uint32_t FSMC_AddressHoldTime uint32_t FSMC_AddressSetupTime uint32_t FSMC_BusTurnAroundDuration uint32_t FSMC_CLKDivision uint32_t FSMC_DataLatency uint32_t FSMC_DataSetupTime
# z' ]$ i# y4 F3 T. ~" z
r8 a1 t f' w" {' q | FSMC_AccessMode:Specifies the asynchronous access mode,用于同步模式,它的取值有以下几种,参考手册上面显示:模式A —— SRAM/PSRAM(CRAM) OE翻转,所以这里我们选择的是模式A
3 w$ g% B' {" h) C5 o! T0 \| #define | | #define | | #define | | #define | |
0 D8 d; n6 q/ G' U: I% m3 e7 Y/ Y
0 v. P& o- H$ E2 K& x |& v | | 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.地址保持的时钟周期! | | 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. 明显是地址建立飞时间周期 | | 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.这个应该是指总线翻转周期么,不是很了解 | | 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
- k7 r7 ?; ~' S8 R& K' J明显是指HCLK的分频系数
' S! r# q% ^4 p' b+ k0 x | | | | |
通过对比,发现上述配置是可行的,不过大家也可以按照要求更改。理论上,在速度要求不是很高的场合,大一点是没有关系的,但是下限得注意,具体是多少,我也走不知道,等以后再说吧! 然后就是看这个结构体了FSMC_NORSRAMInitStructure,成员如下: uint32_t | | uint32_t | | uint32_t | | uint32_t | | uint32_t | | uint32_t | | uint32_t | | | | uint32_t | | uint32_t | | uint32_t | | uint32_t | | uint32_t | | uint32_t | | | |
/ @! g/ E( ~! \7 g: F* k/ Y: W
4 H: S5 m5 B1 p! c" {- B
似乎有些复杂,同时也说明了它的功能强大吧! | FSMC_AsynchronousWait:Enables or disables wait signal during asynchronous transfers, valid only with asynchronous Flash memories,明显就是使能等待同步信号否? | | FSMC_Bank:这个应该是bank的选择吧,明显取值有以下几种:4 T* n8 c5 W4 h, l
| #define | | #define | | #define | | #define | | + Z6 P6 N- r' d* X0 f f& Q
| | FSMC_BurstAccessMode:Enables or disables the burst access mode for Flash memory, valid only with synchronous burst Flash memories.这个什么呢?不懂继续看吧! | | FSMC_DataAddressMux:Specifies whether the address and data values are multiplexed on the databus or not,数据地址引脚是否复用,明显这里我们不需要!! | | | | | | FSMC_MemoryType:Specifies the type of external memory attached to the corresponding memory bank.意思应该是当我们外扩存储器的时候,分配哪一个bank吧,看取值。应该是0-3吧!看结果似乎有些问题,它是指外扩的存储器类型 | | / m4 Z! q. B! }$ q( o; I- e* l
| | FSMC_WaitSignal:Enables or disables the wait-state insertion via wait signal等待信号,等待状态与否 | | | | FSMC_WaitSignalPolarity:Specifies the wait signal polarity, valid only when accessing the Flash memory in burst mode,是指奇偶校验信号么?但是这个只需在flash的burst模式里面设置。 | | FSMC_WrapMode:Enables or disables the Wrapped burst access mode for Flash memory翻转模式? | | | | | | FSMC_WriteTimingStruct0 I* Y' R7 L' C+ M5 f, w# r% a
FSMC_ReadWriteTimingStruct还有两个这样的结构体! Timing Parameters for write and read access if the ExtendedMode is not used ,当我们没有使用外扩模式的时候需要配置,显然这里需要配置的!3 ?8 I) F9 x, F2 o1 |
这两个结构体就是上面分析了的。所以我们只要执行这个语句,就能完成FSMC的配置了; A0 q: R+ I4 s; L$ p2 D: e8 Y
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
" y3 G7 q8 M. @, W' i6 J, f1 I; d+ V4 e; {) j6 B
至此分析完毕!- K; V- y7 ]; C3 w9 {
然后就是简单的初始化TFT了
0 T. L# j: l. z+ e 个人觉得有几点需要注意的地方,也总结一下!+ r) q0 N9 N$ y4 _; |+ O7 C. {
关于使用16位宽的时候的地址的问题!
/ `# ^- e7 I# V5 D7 v 用的第17位,插16位的线8 n# w7 Y1 ]8 U1 W. Z" a+ ^
假如我们这样访问*(volatile unsigned short int *)(0x60020000)=val
' x+ O. X# r, d |
这时候该地址的bit17位为1,因为我们使用16位宽模式,先看下面一张图
z" @4 z- [5 a% C6 ^ q; g0 h# |+ N ]- ]+ D# ]
|