YMQQ_3390
YMQQ_3390
这家伙很懒,什么也没写!

注册于 5年前

回答
1
文章
0
关注者
0

发布于3年前

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

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

初始化内部SRAM,然后调用

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

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

  1. void FSMC_SRAM_Init(void)
  2. {
  3. /*-- GPIOs Configuration -----------------------------------------------------*/
  4. /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
  5. RCC->AHB1ENR |= 0x00000078;
  6. //PD0,1,4,5,8~15 100M AF OUT_PP UP
  7. //PE0,1,7~15 100M AF OUT_PP UP
  8. //PF0~5,12~15 100M AF OUT_PP UP
  9. //PG0~5,10 100M AF OUT_PP UP
  10. /* Connect PDx pins to FMC Alternate function */
  11. GPIOD->AFR[0] = 0x00CC00CC;
  12. GPIOD->AFR[1] = 0xCCCCCCCC;
  13. /* Configure PDx pins in Alternate function mode */
  14. GPIOD->MODER = 0xAAAA0A0A;
  15. /* Configure PDx pins speed to 100 MHz */
  16. GPIOD->OSPEEDR = 0xFFFF0F0F;
  17. /* Configure PDx pins Output type to push-pull */
  18. GPIOD->OTYPER = 0x00000000;
  19. /* pull-up for PDx pins */
  20. GPIOD->PUPDR = 0x55550505;
  21. /* Connect PEx pins to FMC Alternate function */
  22. GPIOE->AFR[0] = 0xC00000CC;
  23. GPIOE->AFR[1] = 0xCCCCCCCC;
  24. /* Configure PEx pins in Alternate function mode */
  25. GPIOE->MODER = 0xAAAA800A;
  26. /* Configure PEx pins speed to 100 MHz */
  27. GPIOE->OSPEEDR = 0xFFFFC00F;
  28. /* Configure PEx pins Output type to push-pull */
  29. GPIOE->OTYPER = 0x00000000;
  30. /* pull-up for PEx pins */
  31. GPIOE->PUPDR = 0x55554005;
  32. /* Connect PFx pins to FMC Alternate function */
  33. GPIOF->AFR[0] = 0x00CCCCCC;
  34. GPIOF->AFR[1] = 0xCCCC0000;
  35. /* Configure PFx pins in Alternate function mode */
  36. GPIOF->MODER = 0xAA000AAA;
  37. /* Configure PFx pins speed to 100 MHz */
  38. GPIOF->OSPEEDR = 0xFF000FFF;
  39. /* Configure PFx pins Output type to push-pull */
  40. GPIOF->OTYPER = 0x00000000;
  41. /* pull-up for PFx pins */
  42. GPIOF->PUPDR = 0x55000555;
  43. /* Connect PGx pins to FMC Alternate function */
  44. GPIOG->AFR[0] = 0x00CCCCCC;
  45. GPIOG->AFR[1] = 0x00000C00;
  46. /* Configure PGx pins in Alternate function mode */
  47. GPIOG->MODER = 0x00200AAA;
  48. /* Configure PGx pins speed to 100 MHz */
  49. GPIOG->OSPEEDR = 0x00300FFF;
  50. /* Configure PGx pins Output type to push-pull */
  51. GPIOG->OTYPER = 0x00000000;
  52. /* pull-up for PGx pins */
  53. GPIOG->PUPDR = 0x00100555;
  54. /*-- FMC/FSMC Configuration --------------------------------------------------*/
  55. /* Enable the FMC/FSMC interface clock */
  56. RCC->AHB3ENR |= 0x00000001;
  57. //寄存器清零
  58. //bank1有NE1~4,每一个有一个BCR+TCR,所以总共八个寄存器。
  59. //这里我们使用NE3 ,也就对应BTCR[4],[5]。
  60. FSMC_Bank1->BTCR[4]=0X00000000;
  61. FSMC_Bank1->BTCR[5]=0X00000000;
  62. FSMC_Bank1E->BWTR[4]=0X00000000;
  63. //操作BCR寄存器 使用异步模式,模式A(读写共用一个时序寄存器)
  64. //BTCR[偶数]:BCR寄存器;BTCR[奇数]:BTR寄存器
  65. FSMC_Bank1->BTCR[4]|=1<<12;//存储器写使能
  66. FSMC_Bank1->BTCR[4]|=1<<4; //存储器数据宽度为16bit
  67. //操作BTR寄存器 (HCLK=168M, 1个HCLK=6ns
  68. FSMC_Bank1->BTCR[5]|=8<<8; //数据保持时间(DATAST)为9个HCLK 6*9=54ns
  69. FSMC_Bank1->BTCR[5]|=0<<4; //地址保持时间(ADDHLD)未用到
  70. FSMC_Bank1->BTCR[5]|=0<<0; //地址建立时间(ADDSET)为0个HCLK 0ns
  71. //闪存写时序寄存器
  72. FSMC_Bank1E->BWTR[4]=0x0FFFFFFF;//默认值
  73. //使能BANK1区域3
  74. FSMC_Bank1->BTCR[4]|=1<<0;
  75. }

回到
顶部

发布
问题

投诉
建议