STM32 FSMC总线深入研讨
因为CPU与FPGA通讯的需求,以及对8080总线的了解,首选采用了STM32的FSMC总线,作为片间通讯接口。FSMC能到达16MHz的写入速度,理论上能写20fps的1024*768的图片哈哈。(当然实践上是不可能的,就算是DMA传输,数据源也跟不上,实践上刷模仿的图片每秒10fps,刷的很high)当然这不是本篇的关键,这儿首要研讨STM32的FSMC接口,将速度提高到极限。
1. FSMC协议剖析
如下为ILI9325的8080接口的协议
CS(片选信号):低电平片选有用,高电平失能(默以为高:失能)
RS(数据寄存器):低电平写寄存器,高电平写数据(默以为高:写数据)FSMC默以为低。。。。
RD(读信号) :低电平有用,上升沿写入数据,高电平失能(默以为高,失能)
WR(写信号) :低电平有用,上升沿写入数据,高电平失能(默以为高,失能)
FSMC写SRAM形式如下:
(1)读操作
(2)写操作
HCLK为体系时钟72MHz
综上,剖分出FSMC与8080接口协议异同点
(1)同:CS,RS,RD有用电平都相同,单个字节的写入与读取时序彻底相同
(2)异:
A:8080 默许RS为高,而FSMC默许RS为低
B:8080接口协议能坚持CS,RS等有用,接连写数据,而FSMC以此只能输出一个数据。
C:8080协议没有地址线,而FSMC还有地址线,这使得数据输出不接连。
2. FSMC时序研讨
下图为FSMC写指令与数据的时序图,从中依据上图能够剖分出FSMC能够完成16M的数据写入。FSMC的信号线翻转十分快,这使得%&&&&&%或许FPGA时序规划上得十分谨慎。FSMC最大完成了72MHz(66.7到100MHz之间,实践为72MHz,HCLK)的翻转速度,这要求外部器材支撑那么高的速率。
寄存器装备(寄存器+数据)
接连数据写入(0xBB:写数据开端),指令后,RS默许拉低(FSMC和规范不相同的当地)
数据树立很快
写数据,然后默许RS拉低
全体的时序可模仿为:
task task_writecmd;
input [15:0] cmd;
begin
mcu_cs = 0;
mcu_rs = 0;
mcu_data = cmd;
#20;
mcu_we = 0;
#20;
mcu_we = 1;
#15;
mcu_rs = 1;
mcu_cs = 1;
#20;
end
endtask
task task_writedata;
input [15:0] data;
begin
mcu_cs = 0;
mcu_rs = 1;
mcu_data = data;
#20;
mcu_we = 0;
#20;
mcu_we = 1;
#15;
mcu_rs = 1;
mcu_cs = 1;
#20;
end
endtask
3. FSMC接口初始化
依据手册,相关参数如下表所示。这儿我发现所谓最小值还能设置为最小,但实践速度差不多。FSMC协议时刻参数如下所示:
有人跟我说,手册是保存的;有人跟我说,在小便是默许值了。我不太了解。感觉速度每提高,应该在小便是默许了。不过,横竖我寻求速度的极限。
以下是FSMC-SRAM形式下的初始化代码,共享的一起,期望对你有用。
/* Private typedef -----------------------------------------------------------*/typedef struct{vu16 LCD_REG;vu16 LCD_RAM;} LCD_TypeDef;#define LCD_WriteCmd(cmd) LCD->LCD_REG = cmd#define LCD_WriteData(data) LCD->LCD_RAM = data/* LCD is connected to the FSMC_Bank1_NOR/SRAM4 and NE4 is used as ship select signal */#define LCD_BASE ((u32)(0x60000000 | 0x0C000000))#define LCD ((LCD_TypeDef *) LCD_BASE)void LCD_FSMCConfig(void){ FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;FSMC_NORSRAMTimingInitTypeDef p;/*-- FSMC Configuration ------------------------------------------------------*//*----------------------- SRAM Bank 4 ----------------------------------------*//* FSMC_Bank1_NORSRAM4 configuration *///规范// p.FSMC_AddressSetupTime = 1;// p.FSMC_AddressHoldTime = 2;// p.FSMC_DataSetupTime = 2; // p.FSMC_BusTurnAroundDuration = 1;// p.FSMC_CLKDivision = 1;// p.FSMC_DataLatency = 2;//超快p.FSMC_AddressSetupTime = 0;p.FSMC_AddressHoldTime = 0;p.FSMC_DataSetupTime = 1; p.FSMC_BusTurnAroundDuration = 0;p.FSMC_CLKDivision = 0;p.FSMC_DataLatency = 0;p.FSMC_AccessMode = FSMC_AccessMode_A;/* Color LCD configuration ------------------------------------LCD configured as follow:- Data/Address MUX = Disable- Memory Type = SRAM- Data Width = 16bit- Write Operation = Enable- Extended Mode = Enable- Asynchronous Wait = Disable */FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; //2.0FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /* BANK 4 (of NOR/SRAM Bank 1~4) is enabled */FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);}