您的位置 首页 测评

STM32F407 外扩SRAM

字节控制功能。支持高/低字节控制。看看实现IS62WV51216的访问,需要对FSMC进行哪些配置。这里就做一个概括性的讲解。步骤如下:1)使能FSM…

字节操控功用。支撑高/低字节操控。

看看完成IS62WV51216的拜访,需要对FSMC进行哪些装备。这儿就做一个概括性的解说。过程如下:

1)使能FSMC时钟,并装备FSMC相关的IO及其时钟使能。

要运用FSMC,当然首先得敞开其时钟。然后需要把FSMC_D0~15,FSMCA0~18等相关IO口,悉数装备为复用输出,并使能各IO组的时钟。

使能FSMC时钟的办法:

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);

关于其他IO口设置的办法前面解说很具体,这儿不做过多的解说。

2)设置FSMCBANK1区域3。

此部分包含设置区域3的存储器的作业形式、位宽和读写时序等。咱们运用形式A、16位宽,读写共用一个时序寄存器。运用的函数是:

void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)

3)使能BANK1区域3。

使能BANK的办法跟前面LCD试验相同,函数是:

void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState);

经过以上几个过程,完成了FSMC的装备,能够拜访IS62WV51216了,这儿还需要注意,由于咱们运用的是BANK1的区域3,所以HADDR[27:26]=10,故外部内存的首地址为0X68000000。

代码:

#include "fsmc_sram.h"#define Bank1_SRAM3_ADDR ((u32)(0x68000000))void GPIO_SRAM_Init(void){GPIO_InitTypeDef GPIO_InitStructure;RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2 |GPIO_Pin_3 |GPIO_Pin_14|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_15;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;GPIO_Init(GPIOF, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2 |GPIO_Pin_3 |GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_10;GPIO_Init(GPIOG, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4 |GPIO_Pin_5 |GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;GPIO_Init(GPIOD, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_15|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14;GPIO_Init(GPIOE, &GPIO_InitStructure);GPIO_PinAFConfig(GPIOD, GPIO_PinSource0,  GPIO_AF_FSMC);//D2GPIO_PinAFConfig(GPIOD, GPIO_PinSource1,  GPIO_AF_FSMC);//D3GPIO_PinAFConfig(GPIOD, GPIO_PinSource4,  GPIO_AF_FSMC);//NOEGPIO_PinAFConfig(GPIOD, GPIO_PinSource5,  GPIO_AF_FSMC);//NWEGPIO_PinAFConfig(GPIOD, GPIO_PinSource8,  GPIO_AF_FSMC);//D13GPIO_PinAFConfig(GPIOD, GPIO_PinSource9,  GPIO_AF_FSMC);//D14GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC);//D15GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC);//A16GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FSMC);//A17GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FSMC);//A18GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);//D0GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);//D1GPIO_PinAFConfig(GPIOE, GPIO_PinSource0,  GPIO_AF_FSMC);//NBL0GPIO_PinAFConfig(GPIOE, GPIO_PinSource1,  GPIO_AF_FSMC);//NBL1GPIO_PinAFConfig(GPIOE, GPIO_PinSource7,  GPIO_AF_FSMC);//D4GPIO_PinAFConfig(GPIOE, GPIO_PinSource8,  GPIO_AF_FSMC);//D5GPIO_PinAFConfig(GPIOE, GPIO_PinSource9,  GPIO_AF_FSMC);//D6GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FSMC);//D7GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_FSMC);//D8GPIO_PinAFConfig(GPIOE, GPIO_PinSource12, GPIO_AF_FSMC);//D9GPIO_PinAFConfig(GPIOE, GPIO_PinSource13, GPIO_AF_FSMC);//D10GPIO_PinAFConfig(GPIOE, GPIO_PinSource14, GPIO_AF_FSMC);//D11GPIO_PinAFConfig(GPIOE, GPIO_PinSource15, GPIO_AF_FSMC);//D12GPIO_PinAFConfig(GPIOG, GPIO_PinSource0,  GPIO_AF_FSMC);//A10GPIO_PinAFConfig(GPIOG, GPIO_PinSource1,  GPIO_AF_FSMC);//A11GPIO_PinAFConfig(GPIOG, GPIO_PinSource2,  GPIO_AF_FSMC);//A12GPIO_PinAFConfig(GPIOG, GPIO_PinSource3,  GPIO_AF_FSMC);//A13GPIO_PinAFConfig(GPIOG, GPIO_PinSource4,  GPIO_AF_FSMC);//A14GPIO_PinAFConfig(GPIOG, GPIO_PinSource5,  GPIO_AF_FSMC);//A15GPIO_PinAFConfig(GPIOG, GPIO_PinSource10, GPIO_AF_FSMC);//NE3GPIO_PinAFConfig(GPIOF, GPIO_PinSource0,  GPIO_AF_FSMC);//A0GPIO_PinAFConfig(GPIOF, GPIO_PinSource1,  GPIO_AF_FSMC);//A1GPIO_PinAFConfig(GPIOF, GPIO_PinSource2,  GPIO_AF_FSMC);//A2GPIO_PinAFConfig(GPIOF, GPIO_PinSource3,  GPIO_AF_FSMC);//A3GPIO_PinAFConfig(GPIOF, GPIO_PinSource4,  GPIO_AF_FSMC);//A4GPIO_PinAFConfig(GPIOF, GPIO_PinSource5,  GPIO_AF_FSMC);//A5GPIO_PinAFConfig(GPIOF, GPIO_PinSource12, GPIO_AF_FSMC);//A6GPIO_PinAFConfig(GPIOF, GPIO_PinSource13, GPIO_AF_FSMC);//A7GPIO_PinAFConfig(GPIOF, GPIO_PinSource14, GPIO_AF_FSMC);//A8GPIO_PinAFConfig(GPIOF, GPIO_PinSource15, GPIO_AF_FSMC);//A9}void FSMC_SRAM_Init(void){    FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;FSMC_NORSRAMTimingInitTypeDef p;p.FSMC_AddressSetupTime = 0x00;     //地址树立时刻(ADDSET)为1个HCLK 1/36M=27nsp.FSMC_AddressHoldTime = 0x00;     //地址坚持时刻(ADDHLD)形式A未用到    p.FSMC_DataSetupTime = 0x03;         //数据坚持时刻(DATAST)为3个HCLK 4/72M=55ns(对EM的SRAM芯片)    p.FSMC_BusTurnAroundDuration = 0x00;p.FSMC_CLKDivision = 0x00;p.FSMC_DataLatency = 0x00;p.FSMC_AccessMode = FSMC_AccessMode_A;     //形式AFSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;// 这儿咱们运用NE3 ,也就对应BTCR[4],[5]。FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM;// FSMC_MemoryType_SRAM; //SRAMFSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;//存储器数据宽度为16bitFSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable;// FSMC_BurstAccessMode_Disable;FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable;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_WriteBurst = FSMC_WriteBurst_Disable;FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; //读写相同时序FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC装备FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); // 使能BANK3                                        }void SRAM_Init(void){GPIO_SRAM_Init();FSMC_SRAM_Init();}/* -------------------------------在指定地址开端,接连写入n个字节.pBuffer:字节指针WriteAddr:要写入的地址n:要写入的字节数--------------------------------*/void FSMC_SRAM_WriteBuffer(u8* pBuffer,u32 WriteAddr,u32 n){for(;n!=0;n--){                                        *(vu8*)(Bank1_SRAM3_ADDR+WriteAddr)=*pBuffer;    WriteAddr+=2;pBuffer++;}}/*-------------------------------在指定地址开端,接连读出n个字节.pBuffer:字节指针ReadAddr:要读出的开始地址n:要写入的字节数--------------------------------*/void FSMC_SRAM_ReadBuffer(u8* pBuffer,u32 ReadAddr,u32 n){for(;n!=0;n--){                                            *pBuffer++=*(vu8*)(Bank1_SRAM3_ADDR+ReadAddr);ReadAddr+=2;}}/*-------------------------------测试函数在指定地址写入1个字节addr:地址data:要写入的数据-------------------------------*/void fsmc_sram_test_write(u8 data,u32 addr){            FSMC_SRAM_WriteBuffer(&data,addr,1); //写入1个字节}/*------------------------------读取1个字节addr:要读取的地址返回值:读取到的数据------------------------------*/u8 fsmc_sram_test_read(u32 addr){u8 data;FSMC_SRAM_ReadBuffer(&data,addr,1);return data;} 

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ceping/276285.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部