|
本帖最后由 blade4414 于 2012-10-21 10:17 编辑
一直在探索LPC1788的SDRAM使用,我的目标是在片内运行u-boot,将应用程序下载到nandflash中,再加载到SDRAM中,最后在SDRAM中运行。
使用的软硬件环境:MDKV4.10,JLINK V7,自制1788学习板。
目前调试中遇到问题,希望关注1788,或者对KEIL和CM3内核比较熟的朋友一起讨论一下。
我是使用了一个SDRAM测试程序修改而来的,
第一步、SDRAM的测试全部OK了。
第二步、仿照OpenOCD的SDRAM调试配置文件写了MPU初始化:
p = (unsigned int *)0xE000ED94 ;
*p = (unsigned int )0x00000000;
nop();nop();nop();nop();nop();nop();nop();nop();nop();nop();
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0x00000010;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x1004003f;
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0x00000011;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x0306E23b;
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0x40000012;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x13050033;
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0x80000013;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x1305001f;
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0xa0000014;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x03070031;
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0xe0000015;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x13040027;
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0xe0000016;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x00000000;
p = (unsigned int *)0xE000ED9C ;
*p = (unsigned int )0x1000E017;
p = (unsigned int *)0xE000EDA0 ;
*p = (unsigned int )0x10060009;
p = (unsigned int *)0xE000ED94 ;
*p = (unsigned int )0x00000001;
nop();nop();nop();nop();nop();nop();nop();nop();nop();nop();
第三步:实现跳转代码,跳转到SDRAM中运行程序。
#define USER_FLASH_START 0xa0000000
void execute_user_code(void)
{
volatile void (*user_code_entry)(void);
/* Change the Vector Table to the USER_FLASH_START
in case the user application uses interrupts */
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, USER_FLASH_START);
SCB->VTOR = 0; /* 重新映射向量表 */
//user_code_entry = (void (*)(void))((USER_FLASH_START)+4);
user_code_entry = (void (*)(void))((USER_FLASH_START));
user_code_entry();
}
测试中发现,有时PC能够跑到0xa000 0000 处,有时出现HARDFAULT.非常奇怪,一次偶然中发现,单步调试时在汇编代码调试窗口,每STEP一下,点一下鼠标,就可以运行到内存中去,而全速运行或者脱机跑时都会失败。
怎么直观的知道代码到SDRAM中去了?我的方法是实现一个位置无关的点灯代码:
__asm void LED_OFF(void)
{
//LDR R1, =0x200980B8
MOV32 R1, #0x200980B8
MOV R2, #0x00000004
STR R2,[R1]
BX LR
}
__asm void LED_ON(void)
{
//LDR R1, =0x200980BC
MOV32 R1, #0x200980BC
MOV R2, #0x00000004
STR R2,[R1]
BX LR
}
先调用一下,反汇编后知道其二进制代码:
uint16_t LEDOFF[] = {0xf248,0x01b8,0xf2c2,0x0109,0xf04f,0x0204,0x600a,0x4770}; //关闭P5.2 LED的二进制程序
uint16_t LEDON[] = {0xf248,0x01bc,0xf2c2,0x0109,0xf04f,0x0204,0x600a,0x4770}; //打开P5.2 LED的二进制程序
再在SDRAM初始化后,写到我PC要跳转的目标内存中。
HARDFAULT时根据KEIL IDE反馈的信息 NVIC_FAULT_STAT推断是invstateS错误,MSR指令使用错误?可是反汇编中我没有看到MSR指令.
keil ide中STEP时点击IDE的反汇编窗口,是否通过JLINK对芯片做了一些读写操作,这个也可能是单步和全速效果不同的原因。
上程序:
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|