里飞网

 找回密码
 立即注册
查看: 4133|回复: 0

FMC—读写SDRAM-W9825G6KH-6

[复制链接]

45

主题

285

帖子

2454

积分

版主

Rank: 7Rank: 7Rank: 7

积分
2454
发表于 2019-12-20 14:34:10 | 显示全部楼层 |阅读模式
FMC—读写SDRAM-W9825G6KH-6
一些注意事项,后面直接看代码
1、W9825G6KH是行地址(row)13bit,列地址(column)9bit,数据16位,4banks,总共32M字节,166MHz/CL3 or 133MHz/CL2,0°C ~ 70°C。
2、可配置为SDRAM1或SDRAM2,SDRAM1地址为0xC0000000,SDRAM2地址为0xD0000000。
3、配置为SDRAM1或2,需与后面配置的自刷新BANK号需一致,否则读写不到数据。
4、地址宽度要配置正确,否则读写会卡死。
5、配置的SDRAM时钟为2分频,即216M/2=108M,一个周期为1000/109=9.259ns==9.3ns。


缩写解析:
CL      =  CAS Latency
tRSC   =  Mode register Set Cycle Time, 加载模式寄存器命令后的延迟
tXSR   =  Exit self refresh to ACTIVE command, 自刷新命令后的延迟
tRAS   =  Active to precharge Command Period, 自刷新时间
tRC     =  Ref/Active to Ref/Active Command Period, 行循环延迟
tWR   =Write Recovery Time,恢复延迟
tRP     = Precharge to Active Command Period, 行预充电延迟
tRCD  = Active to Read/Write Command Delay Time, 行到列延迟


SdramTiming.LoadToActiveDelay = 2;          = tMRD或tRSC, = 2 tCK, 即最少2个时钟周期
SdramTiming.ExitSelfRefreshDelay = 8;        = tXSR, = 72ns, 此处8*9.3=74ns。
SdramTiming.SelfRefreshTime = 5;               = tRAS, = 42ns, 此处5*9.3=46.5ns。
SdramTiming.RowCycleDelay = 7;                 = tRC, = 60ns, 此处7*9.3=65ns。
SdramTiming.WriteRecoveryTime = 2;         =  tWR, =2 tCK,即最少2个时钟周期
SdramTiming.RPDelay = 2;                            = tRP, = 15ns,此处2*9.3=18ns。
SdramTiming.RCDDelay = 2;                         = tRCD, = 15ns,此处2*9.3=18ns。



配置上电时序,需在SDRAM配置后再调用。
  1. void SDRAM_Init_Sequence(uint32_t RefreshCount)
  2. {
  3.   __IO uint32_t tmpmrd = 0;
  4.   FMC_SDRAM_CommandTypeDef Command;
  5.   
  6.   /* Step 1: Configure a clock configuration enable command */
  7.   Command.CommandMode            = FMC_SDRAM_CMD_CLK_ENABLE;
  8.   Command.CommandTarget          = FMC_SDRAM_CMD_TARGET_BANK1;
  9.   Command.AutoRefreshNumber      = 1;
  10.   Command.ModeRegisterDefinition = 0;

  11.   /* Send the command */
  12.   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);

  13.   /* Step 2: Insert 100 us minimum delay */
  14.   /* Inserted delay is equal to 1 ms due to systick time base unit (ms) */
  15.   HAL_Delay(100);
  16.    
  17.   /* Step 3: Configure a PALL (precharge all) command */
  18.   Command.CommandMode            = FMC_SDRAM_CMD_PALL;
  19.   Command.CommandTarget          = FMC_SDRAM_CMD_TARGET_BANK1;
  20.   Command.AutoRefreshNumber      = 1;
  21.   Command.ModeRegisterDefinition = 0;

  22.   /* Send the command */
  23.   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);  
  24.   
  25.   /* Step 4: Configure an Auto Refresh command */
  26.   Command.CommandMode            = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
  27.   Command.CommandTarget          = FMC_SDRAM_CMD_TARGET_BANK1;
  28.   Command.AutoRefreshNumber      = 8;
  29.   Command.ModeRegisterDefinition = 0;

  30.   /* Send the command */
  31.   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
  32.   
  33.   /* Step 5: Program the external memory mode register */
  34.   tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_1          |\
  35.                      SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL   |\
  36.                      SDRAM_MODEREG_CAS_LATENCY_3           |\
  37.                      SDRAM_MODEREG_OPERATING_MODE_STANDARD |\
  38.                      SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
  39.   
  40.   Command.CommandMode            = FMC_SDRAM_CMD_LOAD_MODE;
  41.   Command.CommandTarget          = FMC_SDRAM_CMD_TARGET_BANK1;
  42.   Command.AutoRefreshNumber      = 1;
  43.   Command.ModeRegisterDefinition = tmpmrd;

  44.   /* Send the command */
  45.   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
  46.   
  47.   /* Step 6: Set the refresh rate counter */
  48.   /* Set the device refresh rate */
  49.   HAL_SDRAM_ProgramRefreshRate(&hsdram1, RefreshCount);
  50. }
复制代码


CUBEMX配置
1.png

时序表
2.png

测试结果
3.png

工程代码: F750_SDRAM.rar (965.19 KB, 下载次数: 1089)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|里飞网  

GMT+8, 2024-3-29 15:45 , Processed in 0.104449 second(s), 7 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc. Template By 【未来科技】【 www.wekei.cn 】

快速回复 返回顶部 返回列表