紧接上一篇,如果程序改来改去还是太大对不进STM32的内存怎么办?只能用下载到flash然后调试了吗?其实还可以下载到外扩的SRAM里,这样就几乎能搞定所有的普通程序了。唯一的缺点是在这种情况下,程序会跑得比较慢,whatever,能调试才是正道。
板子还是红牛默认配置,这货带了256x16bit的SRAM一片,接在FSMC上,下面介绍怎么配置成使用这片外扩SRAM进程程序调试。
首先要知道一点,红牛这个SRAM的基址是0x68000000,于是我们就把ROM的基址设置成这个。RAM就保持0x20000000就行了,其实也可以用SRAM的,不过本文不涉及到这个。
这里要改成这样,使用初始化脚本来辅助程序的下载,脚本内容如下(保存成exram.ini即可):
FUNC void Setup (void) {
SP = _RDWORD(0x68000000); // Setup Stack Pointer
PC = _RDWORD(0x68000004); // Setup Program Counter
_WDWORD(0xE000ED08, 0x68000000); // Setup Vector Table Offset Register
}
FUNC void InitSRAM (void) {//InitRCCC
_WDWORD(0x40021000, 0x00005083);
_WDWORD(0x40021004, 0x00000000);
_WDWORD(0x40021004, 0x00000000);
_WDWORD(0x40021000, 0x00005083);
_WDWORD(0x40021004, 0x00000000);
_WDWORD(0x40021008, 0x009F0000);
_WDWORD(0x40021000, 0x00015083);_sleep_ (100); // Wait for PLL lock
_WDWORD(0x40022000, 0x00000030);_WDWORD(0x40022000, 0x00000030);
_WDWORD(0x40022000, 0x00000032);
_WDWORD(0x40021004, 0x00000000);
_WDWORD(0x40021004, 0x00000000);
_WDWORD(0x40021004, 0x00000400);
_WDWORD(0x40021004, 0x00000400);
_WDWORD(0x40021004, 0x001D0400);
_WDWORD(0x40021000, 0x01035083);
_sleep_ (100);
_WDWORD(0x40021004, 0x001D0400);
_WDWORD(0x40021004, 0x001D0402);
_sleep_ (100);
_WDWORD(0x40021014, 0x00000114); /* Enable AHBPeriphClock */_WDWORD(0x40021018, 0x000001E0); /* Enable APB2PeriphClock */
/* GPIO Configuration for FSMC */_WDWORD(0x40011400, 0x44BB44BB);
_WDWORD(0x40011404, 0xBBBBBBBB);
_WDWORD(0x40011800, 0xB44448BB); /* NBL0, NBL1 & adress configuration */
_WDWORD(0x40011804, 0xBBBBBBBB);
_WDWORD(0x40011C00, 0x43BBBBBB);
_WDWORD(0x40011C04, 0xBBBB4344);
_WDWORD(0x40012000, 0x44BBBBBB);
_WDWORD(0x40012004, 0x44444B44); /* NE3 configuration */
_WDWORD(0xA0000010, 0x00001010); /* FSMC Configuration */_WDWORD(0xA0000014, 0x10000200); /* FSMC_DataSetupTime = 2; */
_WDWORD(0xA0000010, 0x00001011); /* Enable FSMC Bank1_SRAM Bank */
_sleep_ (200);}
InitSRAM(); // Setup FSMC for SRAMLOAD ../output/STM32-DEMO.axf INCREMENTAL // Download
Setup(); // Setup for Running
g, main
JLink的设置和上一篇一样。
经过上面这样的简单设置,就可以愉快的调试程序了,再也不用担心flash突然阵亡了。