YMQQ_3390
YMQQ_3390
This guy hasn't written anything yet

注册于 1 year ago

回答
1
文章
0
关注者
0

先在.s文件 里面添加FSMC_SRAM_Init()函数,实现外部SDRAM的初始化如下图:
s文件添加代码.png
然后在初始化的时候先调用

rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);

初始化内部SRAM,然后调用

rt_memheap_init(&system_heap,"sdram",(void *)0x68000000,0x100000);

将外部SDRAM挂载到heap_map里面。编译下载后,就可以用rt_malloc等接口了。
FSMC_SRAM_Init()如下:

void FSMC_SRAM_Init(void)
{
    /*-- GPIOs Configuration -----------------------------------------------------*/
    /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
    RCC->AHB1ENR   |= 0x00000078;
    
    //PD0,1,4,5,8~15    100M AF OUT_PP UP
    //PE0,1,7~15        100M AF OUT_PP UP
    //PF0~5,12~15       100M AF OUT_PP UP
    //PG0~5,10          100M AF OUT_PP UP
    
    /* Connect PDx pins to FMC Alternate function */
    GPIOD->AFR[0]  = 0x00CC00CC;
    GPIOD->AFR[1]  = 0xCCCCCCCC;
    /* Configure PDx pins in Alternate function mode */  
    GPIOD->MODER   = 0xAAAA0A0A;
    /* Configure PDx pins speed to 100 MHz */  
    GPIOD->OSPEEDR = 0xFFFF0F0F;
    /* Configure PDx pins Output type to push-pull */  
    GPIOD->OTYPER  = 0x00000000;
    /* pull-up for PDx pins */ 
    GPIOD->PUPDR   = 0x55550505;
    
    /* Connect PEx pins to FMC Alternate function */
    GPIOE->AFR[0]  = 0xC00000CC;
    GPIOE->AFR[1]  = 0xCCCCCCCC;
    /* Configure PEx pins in Alternate function mode */ 
    GPIOE->MODER   = 0xAAAA800A;
    /* Configure PEx pins speed to 100 MHz */ 
    GPIOE->OSPEEDR = 0xFFFFC00F;
    /* Configure PEx pins Output type to push-pull */  
    GPIOE->OTYPER  = 0x00000000;
    /* pull-up for PEx pins */ 
    GPIOE->PUPDR   = 0x55554005;
    
    /* Connect PFx pins to FMC Alternate function */
    GPIOF->AFR[0]  = 0x00CCCCCC;
    GPIOF->AFR[1]  = 0xCCCC0000;
    /* Configure PFx pins in Alternate function mode */   
    GPIOF->MODER   = 0xAA000AAA;
    /* Configure PFx pins speed to 100 MHz */ 
    GPIOF->OSPEEDR = 0xFF000FFF;
    /* Configure PFx pins Output type to push-pull */  
    GPIOF->OTYPER  = 0x00000000;
    /* pull-up for PFx pins */ 
    GPIOF->PUPDR   = 0x55000555;
    
    /* Connect PGx pins to FMC Alternate function */
    GPIOG->AFR[0]  = 0x00CCCCCC;
    GPIOG->AFR[1]  = 0x00000C00;
    /* Configure PGx pins in Alternate function mode */ 
    GPIOG->MODER   = 0x00200AAA;
    /* Configure PGx pins speed to 100 MHz */ 
    GPIOG->OSPEEDR = 0x00300FFF;
    /* Configure PGx pins Output type to push-pull */  
    GPIOG->OTYPER  = 0x00000000;
    /* pull-up for PGx pins */ 
    GPIOG->PUPDR   = 0x00100555;
    
    /*-- FMC/FSMC Configuration --------------------------------------------------*/
    /* Enable the FMC/FSMC interface clock */
    RCC->AHB3ENR         |= 0x00000001;
    
    //寄存器清零
    //bank1有NE1~4,每一个有一个BCR+TCR,所以总共八个寄存器。
    //这里我们使用NE3 ,也就对应BTCR[4],[5]。        
    FSMC_Bank1->BTCR[4]=0X00000000;
    FSMC_Bank1->BTCR[5]=0X00000000;
    FSMC_Bank1E->BWTR[4]=0X00000000;
    //操作BCR寄存器 使用异步模式,模式A(读写共用一个时序寄存器)
    //BTCR[偶数]:BCR寄存器;BTCR[奇数]:BTR寄存器
    FSMC_Bank1->BTCR[4]|=1<<12;//存储器写使能
    FSMC_Bank1->BTCR[4]|=1<<4; //存储器数据宽度为16bit      
    //操作BTR寄存器   (HCLK=168M, 1个HCLK=6ns       
    FSMC_Bank1->BTCR[5]|=8<<8; //数据保持时间(DATAST)为9个HCLK 6*9=54ns    
    FSMC_Bank1->BTCR[5]|=0<<4; //地址保持时间(ADDHLD)未用到     
    FSMC_Bank1->BTCR[5]|=0<<0; //地址建立时间(ADDSET)为0个HCLK 0ns    
    //闪存写时序寄存器  
    FSMC_Bank1E->BWTR[4]=0x0FFFFFFF;//默认值
    //使能BANK1区域3
    FSMC_Bank1->BTCR[4]|=1<<0;
}

发布
问题