本帖最后由 pq113_6 于 2022-6-19 11:48 编辑
板子是GD32450I_EVAL_Demo,SDRAM初始化已经OK。测试代码: uint8_t *pbAddr = (uint8_t *)EXMC_SDRAM_ADDR0;
uint16_t i;
uint16_t max = 4;
uint8_t *pbTemp;
Printf("SDRAM Test Start:%x\n", sdramPage * 1024);
for (i = 0; i < max; i++)
{
pbTemp = (uint8_t *)(pbAddr + (uint32_t)sdramPage * 1024 + i);
*(uint8_t *)pbTemp = (i & 0xff);
}
for (i = 0; i < max; i++)
{
pbTemp = (uint8_t *)(pbAddr + (uint32_t)sdramPage * 1024 + i);
if(*pbTemp != (i & 0xff))
{
Printf("SDRAM Test Fail: %x != %x, ", i, *pbTemp);
Printf("addr = 0x%x\n", pbTemp);
}
}
打印出来的结果:
SDRAM Test Fail: 0 != 2, addr = 0xc0000000
SDRAM Test Fail: 1 != 3, addr = 0xc0000001
总是第0,1字节是正确的,第2,3字节错误。
但是换一种写法:
*pbAddr = 0x00;
*(pbAddr + 1) = 0x1;
*(pbAddr + 2) = 0x2;
*(pbAddr + 3) = 0x3;
*(pbAddr + 1024) = 0xA5;
*(pbAddr + 1024 + 1) = 0x5A;
Printf("[%x] = 0x%x\n", (uint32_t)pbAddr, *pbAddr);
Printf("[%x] = 0x%x\n", (uint32_t)(pbAddr + 1), *(pbAddr + 1));
Printf("[%x] = 0x%x\n", (uint32_t)(pbAddr + 2), *(pbAddr + 2));
Printf("[%x] = 0x%x\n", (uint32_t)(pbAddr + 3), *(pbAddr + 3));
Printf("[%x] = 0x%x\n", (uint32_t)(pbAddr + 1024), *(pbAddr + 1024));
Printf("[%x] = 0x%x\n", (uint32_t)(pbAddr + 1024 + 1), *(pbAddr + 1024 + 1));
打印结果:
[c0000000] = 0x0
[c0000001] = 0x1
[c0000002] = 0x2
[c0000003] = 0x3
[c0000400] = 0xa5
[c0000401] = 0x5a
结果是对的。
|