有的芯片如nxp lpc1850没有内部flash,没法直接下载,需要在下载前先对cpu进行一些配置,然后才能下载。
调试时配置文件,主要包含启动配置。
下载时管脚配置文件
Hitex_Flash.ini 启动代码
FUNC void Setup (unsigned int region) { region &= 0xFFFF0000; printf("Debugging image at 0x%08x\n", region); SP = _RDWORD(region); // Setup Stack Pointer PC = _RDWORD(region + 4); // Setup Program Counter _WDWORD(0xE000ED08, region); // Setup Vector Table Offset Register } LOAD "Hitex Flash\\example.axf" INCREMENTAL Setup(0x1C000000); // Get ready to execute image in SRAM or whatever region it is in //g,main
LPC18xx_43xx_ExtFlash16Prog.ini 管脚配置 启动EMC,因为EMC对外部存储器进行控制
FUNC void LPC1850_4350_setupEmc (void) { // Disable the EMC before changing pin configurations _WDWORD(0x40005000, 0x00000000); /* Disable the EMC */ // Data bus pins D[15:0] _WDWORD(0x4008609C, 0x000000F3); /* P1_7: D0 (function 3) */ _WDWORD(0x400860A0, 0x000000F3); /* P1_8: D1 (function 3) */ _WDWORD(0x400860A4, 0x000000F3); /* P1_9: D2 (function 3) */ _WDWORD(0x400860A8, 0x000000F3); /* P1_10: D3 (function 3) */ _WDWORD(0x400860AC, 0x000000F3); /* P1_11: D4 (function 3) */ _WDWORD(0x400860B0, 0x000000F3); /* P1_12: D5 (function 3) */ _WDWORD(0x400860B4, 0x000000F3); /* P1_13: D6 (function 3) */ _WDWORD(0x400860B8, 0x000000F3); /* P1_14: D7 (function 3) */ _WDWORD(0x40086290, 0x000000F2); /* P5_4: D8 (function 2) */ _WDWORD(0x40086294, 0x000000F2); /* P5_5: D9 (function 2) */ _WDWORD(0x40086298, 0x000000F2); /* P5_6: D10 (function 2) */ _WDWORD(0x4008629C, 0x000000F2); /* P5_7: D11 (function 2) */ _WDWORD(0x40086280, 0x000000F2); /* P5_0: D12 (function 2) */ _WDWORD(0x40086284, 0x000000F2); /* P5_1: D13 (function 2) */ _WDWORD(0x40086288, 0x000000F2); /* P5_2: D14 (function 2) */ _WDWORD(0x4008628C, 0x000000F2); /* P5_3: D15 (function 2) */ // Address bus pins A[22:0] _WDWORD(0x40086124, 0x000000F3); /* P2_9: A0 (function 3) */ _WDWORD(0x40086128, 0x000000F3); /* P2_10: A1 (function 3) */ _WDWORD(0x4008612C, 0x000000F3); /* P2_11: A2 (function 3) */ _WDWORD(0x40086130, 0x000000F3); /* P2_12: A3 (function 3) */ _WDWORD(0x40086134, 0x000000F3); /* P2_13: A4 (function 3) */ _WDWORD(0x40086080, 0x000000F2); /* P1_0: A5 (function 2) */ _WDWORD(0x40086084, 0x000000F2); /* P1_1: A6 (function 2) */ _WDWORD(0x40086088, 0x000000F2); /* P1_2: A7 (function 2) */ _WDWORD(0x40086120, 0x000000F3); /* P2_8: A8 (function 3) */ _WDWORD(0x4008611C, 0x000000F3); /* P2_7: A9 (function 3) */ _WDWORD(0x40086118, 0x000000F2); /* P2_6: A10 (function 2) */ _WDWORD(0x40086108, 0x000000F2); /* P2_2: A11 (function 2) */ _WDWORD(0x40086104, 0x000000F2); /* P2_1: A12 (function 2) */ _WDWORD(0x40086100, 0x000000F2); /* P2_0: A13 (function 2) */ _WDWORD(0x40086320, 0x000000F1); /* P6_8: A14 (function 1) */ _WDWORD(0x4008631C, 0x000000F1); /* P6_7: A15 (function 1) */ _WDWORD(0x400866C0, 0x000000F2); /* PD_16: A16 (function 2) */ _WDWORD(0x400866BC, 0x000000F2); /* PD_15: A17 (function 2) */ _WDWORD(0x40086700, 0x000000F3); /* PE_0: A18 (function 3) */ _WDWORD(0x40086704, 0x000000F3); /* PE_1: A19 (function 3) */ _WDWORD(0x40086708, 0x000000F3); /* PE_2: A20 (function 3) */ _WDWORD(0x4008670C, 0x000000F3); /* PE_3: A21 (function 3) */ _WDWORD(0x40086710, 0x000000F3); /* PE_4: A22 (function 3) */ //# Control signals _WDWORD(0x40086094, 0x000000F3); /* P1_5: CS0 (function 3) */ _WDWORD(0x40086098, 0x000000F3); /* P1_6: WE (function 3) */ _WDWORD(0x4008608C, 0x000000F3); /* P1_3: OE (function 3) */ //# Enable the EMC before waitstate configurations _WDWORD(0x40005000, 0x00000001); /* Enable the EMC */ //# Configuration for flash on CS0 (14WS for 70ns memory @ 204 MHz core clock) _WDWORD(0x40005200, 0x00000081); /* CS0: 16 bit, WE */ _WDWORD(0x40005208, 0x00000000); /* CS0: WAITOEN = 0 */ _WDWORD(0x4000520C, 0x0000000E); /* CS0: WAITRD = 14 */ } //# Initialize the external memory interface. If booting in EMC mode, //# the bootloader initializes the EMC, but enables only A[13:0]. LPC1850_4350_setupEmc();
flash芯片算法 kei里面都带着的D:\Program Files\Keil\ARM\Flash\MX29LV320B 后面具体为应用芯片,选定芯片后,打开工程,有FlashDev.c 和FlashPrg.c,编译后,就会产生MX29LV320B.FLM,在flash里添加算法。
struct FlashDevice const FlashDevice = { FLASH_DRV_VERS, // Driver Version, do not modify! "MX29LV320EB Flash", // Device Name EXT16BIT, // Device Type 0x00000000, // Device Start Address 0x00400000, // 1片的Device Size in Bytes (4MB) 2片的0x00800000(8M) 1024, // Programming Page Size 0, // Reserved, must be 0 0xFF, // Initial Content of Erased Memory 100, // Program Page Timeout 100 mSec 1000, // Erase Sector Timeout 1000 mSec // Specify Size and Address of Sectors // Size , Address 0x02000, 0x000000, // Sector Size 8kB (8 Sectors) 根据具体芯片修改 0x04000, 0x0000000 2* 8kB 0x10000, 0x010000, // Sector Size 64kB (63 Sectors) 0x20000, 0x0020000 2* 63kB SECTOR_END };
编写flash1片与2片区别 FlashPrg.c
#if 0 //如果2片 #define CMD_RST (0x0000F0F0) /* Reset Command */ #define CMD_ERS (0x00008080) /* Erase Command */ #define START_CE (0x00001010) /* Start Chip Erase Command */ #define START_SE (0x00003030) /* Start Sector Erase Command */ #define START_LD (0x0000A0A0) /* Start Load Data for Programming */ #define VAL_AA (0x0000AAAA) /* Hex Value 0xAA */ #define VAL_55 (0x00005555) /* Hex Value 0x55 */ #define DQ7 (0x00008080) /* DQ7 bit mask */ #define DQ6 (0x00004040) /* DQ6 bit mask */ #define DQ5 (0x00002020) /* DQ5 bit mask */ #define DQ3 (0x00000808) /* DQ3 bit mask */ #define DQ2 (0x00000404) /* DQ2 bit mask */ #define DQ1 (0x00000202) /* DQ1 bit mask */ #else //1片 #define CMD_RST (0xF0) /* Reset Command */ #define CMD_ERS (0x80) /* Erase Command */ #define START_CE (0x10) /* Start Chip Erase Command */ #define START_SE (0x30) /* Start Sector Erase Command */ #define START_LD (0xA0) /* Start Load Data for Programming */ #define VAL_AA (0xAA) /* Hex Value 0xAA */ #define VAL_55 (0x55) /* Hex Value 0x55 */ #define DQ7 (0x80) /* DQ7 bit mask */ #define DQ6 (0x40) /* DQ6 bit mask */ #define DQ5 (0x20) /* DQ5 bit mask */ #define DQ3 (0x08) /* DQ3 bit mask */ #define DQ2 (0x04) /* DQ2 bit mask */ #define DQ1 (0x02) /* DQ1 bit mask */ #endif
如果,下载成功校验成功,但是仿真时失败,找不到地址时,就把LPC18xx_43xx_ExtFlash16Prog.ini中的地址配置代码添加到Hitex_Flash.ini当中就可以进行仿真了。
下载选择 Internal_SRAM.ini
因为ram可以直接读写所以不需要 管脚等配置
下载ram也不需要对写算法,flash需要
irom1,启动地址与内部ram的一致
Internal_SRAM.ini源码
FUNC void Setup (unsigned int region) { region &= 0xFFFF0000; SP = _RDWORD(region); // Setup Stack Pointer PC = _RDWORD(region + 4); // Setup Program Counter _WDWORD(0xE000ED08, region); // Setup Vector Table Offset Register } LOAD "Internal SRAM\\example.axf" INCREMENTAL Setup(0x10000000); // Get ready to execute image in SRAM or whatever region it is in //g,main