|
项目上用的MCU(LPC1778),要求 SDRAM运行程序,查了很多资料,实现MCU 内部flash 跳转至SDRAM运行程序
前前后后,参考了几个帖子,非常感谢这几个帖子中的调试经验啊啊啊啊:
链接放不上......
直接上图(keil的 配置):
3.SDRAM调试 加载的脚本文件如下:
3.1.1 SDRAM驱动文件 (SDRAM.ini):
- FUNC void PinSel(int p1, int n1, int f1)
- {
- _WDWORD(0x4002C000 + (p1 * 32 + n1) * 4, (1 << 9) | f1);
- }
-
- FUNC void InitSDRAM(void)
- {
- int i;
- PinSel(2,16,1);
- PinSel(2,17,1);
- PinSel(2,18,1);
- PinSel(2,20,1);
- PinSel(2,24,1);
- PinSel(2,28,1);
- PinSel(2,29,1);
-
- for(i = 0; i < 16; i++)
- PinSel(3,i,1);
-
- for(i = 0; i < 15; i++)
- PinSel(4,i,1);
-
- PinSel(4,24,1);
- PinSel(4,25,1);
- _WDWORD(0x400FC1DC, (8 << 16)|(8 << 8)|(0xA << 1));
- _sleep_(8);
- // Initialize EMC
- _WDWORD(0x2009C000, 0x00000001); // CONTROL=1 = Enable EMC
- _WDWORD(0x2009C008, 0x00000000); // CONFIG=0
- _WDWORD(0x2009C100, 0x00000280); // DYNAMICCONFIG0
- _WDWORD(0x2009C104, 0x00000202); // DYNAMICRASCAS0
-
- _WDWORD(0x2009C028, 0x00000001); // DYNAMICREADCONFIG
-
- _WDWORD(0x2009C030, 0x00000001); // DYNAMICRP
- _WDWORD(0x2009C034, 0x00000002); // DYNAMICRAS
- _WDWORD(0x2009C038, 0x00000001); // DYNAMICREX
- _WDWORD(0x2009C03C, 0x00000000); // DYNAMICAPR
- _WDWORD(0x2009C040, 0x00000003); // DYNAMICDAL
- _WDWORD(0x2009C044, 0x00000002); // DYNAMICWR
- _WDWORD(0x2009C048, 0x00000003); // DYNAMICRC
- _WDWORD(0x2009C04C, 0x00000003); // DYNAMICRFC
- _WDWORD(0x2009C050, 0x00000001); // DYNAMICXSR
- _WDWORD(0x2009C054, 0x00000000); // DYNAMICRRD
- _WDWORD(0x2009C058, 0x00000002); // DYNAMICMRD
- _sleep_(100);
- _WDWORD(0x2009C020, 0x00000183); // DYNAMICCONTROL - NOP
- _sleep_(100);
- _WDWORD(0x2009C020, 0x00000103); // DYNAMICCONTROL - PRECHARGE_ALL
-
- _sleep_(100);
- _WDWORD(0x2009C024, 0x00000046); // DYNAMICREFRESH = 1D
- _WDWORD(0x2009C020, 0x00000083); // DYNAMICCONTROL - MODE
- _sleep_(200);
- _RDWORD(0xA0000000 | (0x23<<11)); // Write 16-bit SDRAM Mode register burst 8- this is a read as requested by the SDRAM spec
-
- _WDWORD(0x2009C020, 0x00000000); // DYNAMICCONTROL - NORMAL
-
- _WDWORD(0x2009C100, (1 << 19) | 0x00000280); // DYNAMICCONFIG0
- _sleep_(100);
-
- }
- FUNC void Clock_Setup (void) {
- _WDWORD(0x400FC1A0, 0x00000021); // Enable the crystal oscillator
- // while((_RDWORD(0x400FC1A0) & (1<<6)) == 0); // delay wait for oscillator to start
- _sleep_ (100); // Wait for main oscillator to stabilize
- _WDWORD(0x400FC10C, 0x00000001); // select crystal oscillator
- _WDWORD(0x400FC084, 0x00000028); // Configure PLL0 to multiply x 10 for 120 MHz operation from 12 MHz crystal
- _WDWORD(0x400FC080, 0x00000001); // PLL0 Enable
- _WDWORD(0x400FC08C, 0x000000AA); //
- _WDWORD(0x400FC08C, 0x00000055); //
-
- // while((_RDWORD(0x400FC088) & (1<<10)) == 0); // Wait for PLOCK0
- _sleep_ (100); // Wait for PLOCK0
- _WDWORD(0x400FC0A4, 0x0000002B); // Configure PLL0 to multiply x 10 for 120 MHz operation from 12 MHz crystal
- _WDWORD(0x400FC0A0, 0x00000001); // PLL0 Enable
- _WDWORD(0x400FC0AC, 0x000000AA); //
- _WDWORD(0x400FC0AC, 0x00000055); //
- _sleep_ (100);
- _WDWORD(0x400FC104, 0x00000102); //PLL0 not divide as the cpuclock
- _WDWORD(0x400FC100, 0x00000000); //cpuclock / 2 as the emcclock
- _WDWORD(0x400FC1A8, 0x00000004); //cpuclock / 2 as the pclock
- _WDWORD(0x400FC0C4, 0x00008800); //emcclock gpio enable
- _WDWORD(0x400FC1B0, 0x00000000); //120M support
- }
复制代码
3.1.2 加载的脚本(RAM.ini):
- INCLUDE SDRAM.ini
- FUNC void mpu_region_setup(unsigned int a_addr,
- unsigned int a_region,
- unsigned int a_size,
- unsigned int a_ap,
- unsigned int a_mem_attrib,
- unsigned int a_srd,
- unsigned int a_XN,
- unsigned int a_enable )
- {
- // Setup procedure for each region
- unsigned int temp;
- temp = (a_addr & 0xFFFFFFE0) | (a_region & 0xF) | 0x10 ;
- _WDWORD(0xE000ED9C, temp); // RBAR
- temp = ((a_XN & 0x1)<<28) | ((a_ap & 0x7)<<24) | ((a_mem_attrib & 0x3F)<<16) | ((a_srd&0xFF)<<8) | ((a_size & 0x1F)<<1)| (a_enable & 0x1) ;
- _WDWORD(0xE000EDA0, temp); // RASR
- _WDWORD(0xE000ED24, 1<<18); // usage fault enable
- _WDWORD(0xE000ED94, 5); // MPU enable
- }
- FUNC void Setup (unsigned int region) {
- region &= 0xFF000000;
- // _WDWORD(0x40043100, 0); // Set the shadow pointer to zero (can't map SDRAM to 0)
- SP = _RDWORD(region); // Setup Stack Pointer
- PC = _RDWORD(region + 4); // Setup Program Counter
- _WDWORD(0xE000ED08, region); // Set the vector table offset
- }
- Clock_Setup();
- InitSDRAM();
- LOAD %L INCREMENTAL // Download
- mpu_region_setup( 0xA0000000,0,0x16,3,7,0,0,1);
- Setup(0xA0000000); // Setup for Running
复制代码
3.1.3 调试注意:
1.外设、IO(SDRAM) 请勿重新初始化 ,会造成程序重启
2.SDRAM 调试不能下载操作,得在调试模式调试代码
3.不同的SDRAM器件,需阅读数据手册,重新配置,上面的代码配置的(主频72M、IS42S16400F)
4.重要的代码,推荐强制定位到MCU内部 SRAM区域 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|