/**************************************************************************** **************************************************************************** Startup/Program LM3S : INPUT : OUTPUT : RETURN error code ****************************************************************************/ static BDI_InitTypeT initListLM3S[] = { {BDI_INIT_ARM11_WGPR, 8006, 100 }, // Wakeup time after reset released {BDI_INIT_ARM11_WGPR, 8007, 3 }, // assert reset via Reset Control Register {BDI_INIT_ARM11_WGPR, 13, 0x2000fffc}, // set SP to top of internal SRAM {BDI_INIT_ARM11_WM32, 0x400FE060, 0x078e3ad1}, // RCC : bypass, internal {BDI_INIT_ARM11_WM32, 0x400FE070, 0x07802810}, // RCC2: bypass, internal {BDI_INIT_ARM11_WM32, 0x400FE060, 0x078e3ad0}, // RCC : enable main oscillator {BDI_INIT_ARM11_DELAY, 0, 100 }, // let main oscillator startup {BDI_INIT_ARM11_WM32, 0x400FE060, 0x078e0b80}, // RCC : XTAL is 8 MHz, power-up PLL, select main {BDI_INIT_ARM11_WM32, 0x400FE070, 0x07800800}, // RCC2: power-up PLL, select main {BDI_INIT_ARM11_WM32, 0x400FE060, 0x01ce0b80}, // RCC : set SYSDIV for 50MHz {BDI_INIT_ARM11_WM32, 0x400FE070, 0x01800800}, // RCC2: set SYSDIV for 50MHz {BDI_INIT_ARM11_DELAY, 0, 100 }, // let PLL lock {BDI_INIT_ARM11_WM32, 0x400FE060, 0x01ce0380}, // RCC : clear bypass {BDI_INIT_ARM11_WM32, 0x400FE070, 0x01800000}, // RCC2: clear bypass {BDI_INIT_ARM11_WM32, 0x400FE060, 0x01d40380}, // RCC : set PWMDIV {BDI_INIT_ARM11_WM32, 0x400FE140, 49 }, // USECRL: Flash USec Reload for 50 MHz }; static int StartupLM3S(void) { int result; /* reset and init target */ result = BDI_TargetStartup(100, // 100ms reset time (0L << 16) | (6L << 8) | 4, // little endian, Cortex-M3, 8 MHz JTAG sizeof initListLM3S / sizeof initListLM3S[0], initListLM3S); if (result != BDI_OKAY) return result; return result; } /* StartupLM3S */ static int ProgramLM3S(void) { int result; int sector; DWORD addr; DWORD errorAddr; /* reset and init target */ result = BDI_TargetStartup(100, // 100ms reset time (0L << 16) | (6L << 8) | 4, // little endian, Cortex-M3, 8 MHz JTAG sizeof initListLM3S / sizeof initListLM3S[0], initListLM3S); if (result != BDI_OKAY) return result; /* setup flash type */ result = BDI_FlashSetType(BDI_FLASH_LM3S, 0x40000, 0, 32, 0x20000000); // workspace in internal SRAM if (result != BDI_OKAY) return result; /* erase sectors */ addr = 0x00030000; for (sector = 0; sector < 16; sector++) { printf("erasing sector 0x%08lx ... ", addr); result = BDI_FlashEraseSector(addr); if (result != BDI_OKAY) return result; printf("passed\n"); addr += 0x400; } /* for */ /* program/verify from a file */ printf("programming..."); result = BDI_FlashWriteBinary("e:/temp/dump16k.bin", 0x00030000, &errorAddr); if (result != BDI_OKAY) return result; printf("passed\n"); printf("verifying... "); result = BDI_VerifyBinary("e:/temp/dump16k.bin", 0x00030000, &errorAddr); printf("passed\n"); return result; } /* ProgramLM3S */ static int EraseLM3S(void) { int result; int sector; DWORD addr; /* reset and init target */ result = BDI_TargetStartup(100, // 100ms reset time (0L << 16) | (6L << 8) | 4, // little endian, Cortex-M3, 8 MHz JTAG sizeof initListLM3S / sizeof initListLM3S[0], initListLM3S); if (result != BDI_OKAY) return result; /* setup flash type */ result = BDI_FlashSetType(BDI_FLASH_LM3S, 0x40000, 0, 32, 0x20000000); // workspace in internal SRAM if (result != BDI_OKAY) return result; /* erase sectors */ addr = 0x00030000; for (sector = 0; sector < 16; sector++) { printf("erasing sector 0x%08lx ... ", addr); result = BDI_FlashEraseSector(addr); if (result != BDI_OKAY) return result; printf("passed\n"); addr += 0x400; } /* for */ return result; } /* EraseLM3S */