按照例程来测试下SDRAM存储器配置和读写。
1、芯片内部的SDRAM结构图
2、SDRAM设备连接图
SDRAM存储器在芯片部分封装,接口也看不到,按照测试例程来学习SDARAM存储器的配置和读写。
3、sdram.c
#include "SWM341.h"
void MemoryInit(void)
{
SDRAM_InitStructure SDRAM_InitStruct;
PORT_Init(PORTM, PIN13, PORTM_PIN13_SDR_CLK, 0);
PORT_Init(PORTM, PIN14, PORTM_PIN14_SDR_CKE, 0);
PORT_Init(PORTB, PIN7, PORTB_PIN7_SDR_WE, 0);
PORT_Init(PORTB, PIN8, PORTB_PIN8_SDR_CAS, 0);
PORT_Init(PORTB, PIN9, PORTB_PIN9_SDR_RAS, 0);
PORT_Init(PORTB, PIN10, PORTB_PIN10_SDR_CS, 0);
PORT_Init(PORTE, PIN15, PORTE_PIN15_SDR_BA0, 0);
PORT_Init(PORTE, PIN14, PORTE_PIN14_SDR_BA1, 0);
PORT_Init(PORTN, PIN14, PORTN_PIN14_SDR_A0, 0);
PORT_Init(PORTN, PIN13, PORTN_PIN13_SDR_A1, 0);
PORT_Init(PORTN, PIN12, PORTN_PIN12_SDR_A2, 0);
PORT_Init(PORTN, PIN11, PORTN_PIN11_SDR_A3, 0);
PORT_Init(PORTN, PIN10, PORTN_PIN10_SDR_A4, 0);
PORT_Init(PORTN, PIN9, PORTN_PIN9_SDR_A5, 0);
PORT_Init(PORTN, PIN8, PORTN_PIN8_SDR_A6, 0);
PORT_Init(PORTN, PIN7, PORTN_PIN7_SDR_A7, 0);
PORT_Init(PORTN, PIN6, PORTN_PIN6_SDR_A8, 0);
PORT_Init(PORTN, PIN3, PORTN_PIN3_SDR_A9, 0);
PORT_Init(PORTN, PIN15, PORTN_PIN15_SDR_A10, 0);
PORT_Init(PORTN, PIN2, PORTN_PIN2_SDR_A11, 0);
PORT_Init(PORTM, PIN15, PORTM_PIN15_SDR_A12, 0);
PORT_Init(PORTE, PIN7, PORTE_PIN7_SDR_D0, 1);
PORT_Init(PORTE, PIN6, PORTE_PIN6_SDR_D1, 1);
PORT_Init(PORTE, PIN5, PORTE_PIN5_SDR_D2, 1);
PORT_Init(PORTE, PIN4, PORTE_PIN4_SDR_D3, 1);
PORT_Init(PORTE, PIN3, PORTE_PIN3_SDR_D4, 1);
PORT_Init(PORTE, PIN2, PORTE_PIN2_SDR_D5, 1);
PORT_Init(PORTE, PIN1, PORTE_PIN1_SDR_D6, 1);
PORT_Init(PORTE, PIN0, PORTE_PIN0_SDR_D7, 1);
PORT_Init(PORTE, PIN8, PORTE_PIN8_SDR_D8, 1);
PORT_Init(PORTE, PIN9, PORTE_PIN9_SDR_D9, 1);
PORT_Init(PORTE, PIN10, PORTE_PIN10_SDR_D10, 1);
PORT_Init(PORTE, PIN11, PORTE_PIN11_SDR_D11, 1);
PORT_Init(PORTE, PIN12, PORTE_PIN12_SDR_D12, 1);
PORT_Init(PORTE, PIN13, PORTE_PIN13_SDR_D13, 1);
PORT_Init(PORTC, PIN14, PORTC_PIN14_SDR_D14, 1);
PORT_Init(PORTC, PIN15, PORTC_PIN15_SDR_D15, 1);
PORT_Init(PORTB, PIN6, PORTB_PIN6_SDR_LDQM, 0);
PORT_Init(PORTM, PIN12, PORTM_PIN12_SDR_UDQM,0);
SDRAM_InitStruct.Size = SDRAM_SIZE_8MB;
SDRAM_InitStruct.ClkDiv = SDRAM_CLKDIV_1;
SDRAM_InitStruct.CASLatency = SDRAM_CASLATENCY_2;
SDRAM_InitStruct.TimeTRP = SDRAM_TRP_3;
SDRAM_InitStruct.TimeTRCD = SDRAM_TRCD_3;
SDRAM_InitStruct.TimeTRFC = SDRAM_TRFC_15;
SDRAM_Init(&SDRAM_InitStruct);
}
#define SDRAM_SIZE (0x100000 * 2)
void sdram_test(void)
{
uint32_t i;
uint32_t val;
/* Word Test */
for(i = 0; i < SDRAM_SIZE; i += 4)
{
*((volatile uint32_t *)(SDRAMM_BASE + i)) = i;
}
for(i = 0; i < SDRAM_SIZE; i += 4)
{
val = *((volatile uint32_t *)(SDRAMM_BASE + i));
if(val != i)
{
printf("Word Test Error: 0x%08X expected, 0x%08X get\r\n", i, val);
//while(1);
}
}
printf("Word Test Pass!\r\n");
}
4、main.c
#include "SWM341.h"
#include "delay.h"
#include "usart.h"
#include "sdram.h"
int main(void)
{
SystemInit();
SerialInit();
MemoryInit();
//GPIO_Init(GPIOA, PIN0, 0, 1, 0, 0); //输入,上拉使能,接KEY
GPIO_Init(GPIOA, PIN5, 1, 0, 0, 0); //输出, 接LED
sdram_test();
while(1==1)
{
GPIO_InvBit(GPIOA, PIN5);
delay_us(100000);
}
}
5、程序运行
程序运行后,在串口打印测试信息
|