/**************************************************************************** **************************************************************************** Erase/Program Kinetis K70 flash (TWR-K70F120M Tower Module): INPUT : OUTPUT : RETURN error code ****************************************************************************/ static BDI_InitTypeT initListK70[] = { {BDI_INIT_ARM11_WGPR, 8006, 100 }, // Wakeup time after reset released {BDI_INIT_ARM11_WGPR, 8012, 1 }, // memory access via AHB {BDI_INIT_ARM11_WGPR, 8013, 1 }, // 8 TCK's access delay {BDI_INIT_ARM11_WGPR, 13, 0x2000fffc}, // set SP to top of internal SRAM {BDI_INIT_ARM11_WM32, 0x4001F008, 0x00080000}, // FMC_PFB23CR: disable cache {BDI_INIT_ARM11_WM32, 0x4001F004, 0x00080000}, // FMC_PFB01CR: invaliate and disable cache // Disable Watchdog via code execution {BDI_INIT_ARM11_WGPR, 0, 0x40052000}, // WDOG register base address {BDI_INIT_ARM11_WGPR, 1, 0xC520 }, // unlock code A {BDI_INIT_ARM11_WGPR, 2, 0xD928 }, // unlock code B {BDI_INIT_ARM11_WGPR, 3, 0x01D2 }, // New value for WDOG_STCTRLH {BDI_INIT_ARM11_WM16, 0x20000000, 0x81c1 }, // strh r1, [r0, #14] {BDI_INIT_ARM11_WM16, 0x20000002, 0x81c2 }, // strh r2, [r0, #14] {BDI_INIT_ARM11_WM16, 0x20000004, 0x8003 }, // strh r3, [r0, #0] {BDI_INIT_ARM11_WM16, 0x20000006, 0xbe00 }, // bkpt 0x0000 {BDI_INIT_ARM11_EXEC, 0x20000000 }, // execute disable code }; static int StartupK70(void) { int result; /* reset and init target */ result = BDI_TargetStartup(100, // 100ms reset time (0L << 16) | (11L << 8) | 2, // BDI2000: LE, Cortex-M4, 8 MHz // (0L << 16) | (11L << 8) | 4, // BDI3000: LE, Cortex-M4, 8MHz sizeof initListK70 / sizeof initListK70[0], initListK70); return result; } /* StartupK70 */ static int ProgramK70(void) { int result; DWORD addr; DWORD errorAddr; /* reset and init target */ result = BDI_TargetStartup(100, // 100ms reset time (0L << 16) | (11L << 8) | 2, // BDI2000: LE, Cortex-M4, 8 MHz // (0L << 16) | (11L << 8) | 4, // BDI3000: LE, Cortex-M4, 8MHz sizeof initListK70 / sizeof initListK70[0], initListK70); if (result != BDI_OKAY) return result; /* setup flash type */ result = BDI_FlashSetType(BDI_FLASH_FTFE, 0x100000, // 1 MB 0, 32, 0x20000000); // workspace internal SRAM if (result != BDI_OKAY) return result; /* erase the 256kB block */ addr = 0x00000000; printf("erasing block at 0x%08lx ... ", addr); result = BDI_FlashErase(BDI_ERASE_BLOCK, addr); if (result != BDI_OKAY) return result; printf("passed\n"); /* erase the 256kB block */ addr = 0x00040000; printf("erasing block at 0x%08lx ... ", addr); result = BDI_FlashErase(BDI_ERASE_BLOCK, addr); if (result != BDI_OKAY) return result; printf("passed\n"); /* program/verify from a file */ printf("programming..."); result = BDI_FlashWriteBinary("E:/Cygwin/home/bdidemo/arm11/k70f120m.bin", 0x00000000, &errorAddr); if (result != BDI_OKAY) return result; printf("passed\n"); printf("verifing... "); result = BDI_VerifyBinary("E:/Cygwin/home/bdidemo/arm11/k70f120m.bin", 0x00000000, &errorAddr); printf("passed\n"); return result; } /* ProgramK70 */