有的芯片如nxp lpc1850沒有內部flash,無法直接下載,須要在下載前先對cpu進行一些配置,而後才能下載。算法
調試時配置文件,主要包含啓動配置。spa
下載時管腳配置文件調試
Hitex_Flash.ini 啓動代碼code
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對外部存儲器進行控制ip
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裏添加算法。ci
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當中就能夠進行仿真了。flash
下載選擇 Internal_SRAM.iniit
由於ram能夠直接讀寫因此不須要 管腳等配置io
下載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