/**************************************************************************** **************************************************************************** Erase/Program STR912F flash : INPUT : OUTPUT : RETURN error code ****************************************************************************/ static BDI_InitTypeT initListSTR912[] = { {BDI_INIT_ARM_WGPR, 8006, 250 }, // Wakeup time after reset released {BDI_INIT_ARM_WGPR, 8008, 0x40000000}, // Set save debug PC to internal SRAM {BDI_INIT_ARM_WGPR, 8001, 1 }, // Number of JTAG devices before the ARM core {BDI_INIT_ARM_WGPR, 8002, 5 }, // Total IR length before the ARM core {BDI_INIT_ARM_WGPR, 8003, 1 }, // Number of JTAG devices after the ARM core {BDI_INIT_ARM_WGPR, 8004, 8 }, // Total IR length after the ARM core // Set clock to 48MHz via PLL {BDI_INIT_ARM_WM32, 0x5C002004, 0x000BC019}, // SCU_PLLCONF: PLL=ENA,P=3,N=C0,M=19 {BDI_INIT_ARM_DELAY, 0, 100 }, // let PLL lock {BDI_INIT_ARM_WM32, 0x5C002000, 0x00020000}, // SCU_CLKCNTR: MCLK=PLL {BDI_INIT_ARM_WGPR, 8005, 5 }, // BDI3000: Speed-up JTAG clock to 5 MHz // {BDI_INIT_ARM_WGPR, 8005, 3 }, // BDI2000: Speed-up JTAG clock to 4 MHz // {BDI_INIT_ARM_WGPR, 8005, 1 }, // BDI1000: Speed-up JTAG clock to 6 MHz // Setup flash memory interface (FMI) {BDI_INIT_ARM_WM32, 0x54000000, 0x00000004}, // FMI_BBSR : boot bank size = 512k {BDI_INIT_ARM_WM32, 0x5400000C, 0x00000000}, // FMI_BBADR : boot bank addr = 0x00000000 {BDI_INIT_ARM_WM32, 0x54000004, 0x00000002}, // FMI_NBBSR : boot bank size = 32k {BDI_INIT_ARM_WM32, 0x54000010, 0x00020000}, // FMI_NBBADR: boot bank addr = 0x00080000 {BDI_INIT_ARM_WM32, 0x54000018, 0x00000018}, // FMI_CR : enable both flash banks // load an execute code to set Configuration Control Register bit 18 {BDI_INIT_ARM_WM32, 0x40000000, 0xEE3F0F11}, // mrc 15, 1, r0, cr15, cr1, {0} {BDI_INIT_ARM_WM32, 0x40000004, 0xE3800701}, // orr r0, r0, #262144 {BDI_INIT_ARM_WM32, 0x40000008, 0xEE2F0F11}, // mcr 15, 1, r0, cr15, cr1, {0} {BDI_INIT_ARM_WM32, 0x4000000C, 0xEAFFFFFE}, // b $pc {BDI_INIT_ARM_EXEC, 0x40000000, 0x00000000}, // execute code }; static int ProgramSTR912(void) { int result; int sector; DWORD addr; DWORD errorAddr; /* reset and init target */ result = BDI_TargetStartup(100, // 500ms reset time (0L << 16) | (11L << 8) | 7, // little endian, ARM966, 1 MHz JTAG sizeof initListSTR912 / sizeof initListSTR912[0], initListSTR912); if (result != BDI_OKAY) return result; /* setup flash type */ result = BDI_FlashSetType(BDI_FLASH_STR910F, 0x80000, // 512K 0, 16, 0x40000000); // workspace in internal SRAM if (result != BDI_OKAY) return result; /* unlock and erase sectors */ addr = 0; for (sector = 0; sector < 4; sector++) { printf("erasing sector 0x%08lx ... ", addr); result = BDI_SetWord(addr, 0x0060); result = BDI_SetWord(addr, 0x00D0); result = BDI_FlashEraseSector(addr); if (result != BDI_OKAY) return result; printf("passed\n"); addr += 0x10000; } /* for */ /* program/verify from a file */ printf("programming..."); result = BDI_FlashWriteBinary("e:/temp/dump256k.bin", 0x00000000, &errorAddr); if (result != BDI_OKAY) return result; printf("passed\n"); printf("verifying... "); result = BDI_VerifyBinary("e:/temp/dump256k.bin", 0x00000000, &errorAddr); printf("passed\n"); return result; } /* ProgramSTR912 */ /**************************************************************************** **************************************************************************** STR912F ISC Mode : INPUT : OUTPUT : RETURN error code ****************************************************************************/ /* common bit constants */ #define BIT0 (1L<<0) #define BIT1 (1L<<1) #define BIT2 (1L<<2) #define BIT3 (1L<<3) #define BIT4 (1L<<4) #define BIT5 (1L<<5) #define BIT6 (1L<<6) #define BIT7 (1L<<7) #define JTAG_TRST_LOW (JTAG_PORT_LOW << 0) #define JTAG_TRST_HIGH (JTAG_PORT_HIGH << 0) #define JTAG_RESET_LOW (JTAG_PORT_LOW << 2) #define JTAG_RESET_HIGH (JTAG_PORT_HIGH << 2) #define ISC_READY BIT2 static const BYTE ISC_Zeros[] = {0, 0, 0, 0, 0, 0, 0, 0}; static const BYTE ISC_Turbo[] = {0xFF, 0xDF, 0x00}; static const BYTE ISC_Read_Usercode[] = {0x06, 0x1F}; static const BYTE ISC_Configuration[] = {0x07, 0x1F}; static const BYTE ISC_Enable[] = {0x0C, 0x1F}; static const BYTE ISC_Disable[] = {0x0F, 0x1F}; static const BYTE ISC_Noop[] = {0x10, 0x1F}; static const BYTE ISC_Address_Shift[] = {0x11, 0x1F}; static const BYTE ISC_Clr_Status[] = {0x13, 0x1F}; static const BYTE ISC_Prog_Security[] = {0x22, 0x1F}; static const BYTE ISC_Prog_Usercode[] = {0x23, 0x1F}; static const BYTE ISC_Erase[] = {0x30, 0x1F}; static const BYTE TMS_01[] = {0x01}; static const BYTE TMS_0011[] = {0x03}; static int JtagSTR912(void) { int result; int sector; DWORD addr; DWORD errorAddr; BYTE status; DWORD usercode; DWORD configuration; BYTE dataRD[32]; BYTE dataWR[32]; /* open JTAG mode */ result = BDI_DoJtag(JTAG_CMD_OPEN, 0, 0, NULL, NULL); if (result != BDI_OKAY) return result; /* set JTAG clock to 1 MHz */ result = BDI_DoJtag(JTAG_CMD_SPEED, 7, 0, NULL, NULL); /* assert RESET, assert TRST, release TRST */ result = BDI_DoJtag(JTAG_CMD_PORT, JTAG_RESET_LOW, 0, NULL, NULL); result = BDI_DoJtag(JTAG_CMD_PORT, JTAG_TRST_LOW, 0, NULL, NULL); result = BDI_DoJtag(JTAG_CMD_PORT, JTAG_TRST_HIGH, 0, NULL, NULL); /* move to Run-Test/Idle */ result = BDI_DoJtag(JTAG_CMD_CLOCK, 0, 1, NULL, NULL); /* Enable Turbo Programming Mode */ result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 17, ISC_Turbo, dataRD); /* Enter ISC mode */ result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Enable, dataRD); result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 9, ISC_Zeros, dataRD); /* Read Status */ result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Noop, dataRD); result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 9, ISC_Zeros, dataRD); status = dataRD[0]; /* Read User code */ result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Read_Usercode, dataRD); result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 32+1, ISC_Zeros, dataRD); usercode = (DWORD)dataRD[0]; usercode |= (DWORD)dataRD[1] << 8; usercode |= (DWORD)dataRD[2] << 16; usercode |= (DWORD)dataRD[3] << 24; printf("User code is: 0x%08lx\n", usercode); /* read ISC configuration */ result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Configuration, dataRD); result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 32+1, ISC_Zeros, dataRD); configuration = (DWORD)dataRD[0]; configuration |= (DWORD)dataRD[1] << 8; configuration |= (DWORD)dataRD[2] << 16; configuration |= (DWORD)dataRD[3] << 24; /* program user code */ dataWR[4] = 0x00; dataWR[3] = 0x12; dataWR[2] = 0x34; dataWR[1] = 0x56; dataWR[0] = 0x78; result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 4, TMS_0011, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_LAST, 13, ISC_Prog_Usercode, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 4, TMS_0011, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_LAST, 33, dataWR, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 2, TMS_01, NULL); result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Noop, dataRD); do { result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 8+1, ISC_Zeros, dataRD); status = dataRD[0]; } while ((status & ISC_READY) == 0); /* Read New User code */ result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Read_Usercode, dataRD); result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 32+1, ISC_Zeros, dataRD); usercode = (DWORD)dataRD[0]; usercode |= (DWORD)dataRD[1] << 8; usercode |= (DWORD)dataRD[2] << 16; usercode |= (DWORD)dataRD[3] << 24; printf("User code is: 0x%08lx\n", usercode); /* erase user code */ dataWR[8] = 0x00; dataWR[7] = 0x00; dataWR[6] = 0x04; /* set bit 50 in sector register */ dataWR[5] = 0x00; dataWR[4] = 0x00; dataWR[3] = 0x00; dataWR[2] = 0x00; dataWR[1] = 0x00; dataWR[0] = 0x00; result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 4, TMS_0011, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_LAST, 13, ISC_Erase, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 4, TMS_0011, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_LAST, 65, dataWR, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 2, TMS_01, NULL); result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Noop, dataRD); do { result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 8+1, ISC_Zeros, dataRD); status = dataRD[0]; } while ((status & ISC_READY) == 0); /* Read Erased User code */ result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Read_Usercode, dataRD); result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 32+1, ISC_Zeros, dataRD); usercode = (DWORD)dataRD[0]; usercode |= (DWORD)dataRD[1] << 8; usercode |= (DWORD)dataRD[2] << 16; usercode |= (DWORD)dataRD[3] << 24; printf("User code is: 0x%08lx\n", usercode); /* full chip erase */ printf("full chip erase ..."); dataWR[8] = 0xff; dataWR[7] = 0xff; dataWR[6] = 0xff; dataWR[5] = 0xff; dataWR[4] = 0xff; dataWR[3] = 0xff; dataWR[2] = 0xff; dataWR[1] = 0xff; dataWR[0] = 0xff; result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 4, TMS_0011, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_LAST, 13, ISC_Erase, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 4, TMS_0011, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_LAST, 65, dataWR, NULL); result = BDI_DoJtag(JTAG_CMD_SCAN, JTAG_SCAN_TMS, 2, TMS_01, NULL); result = BDI_DoJtag(JTAG_CMD_IRSCAN, 0, 13, ISC_Noop, dataRD); do { result = BDI_DoJtag(JTAG_CMD_DRSCAN, 0, 8+1, ISC_Zeros, dataRD); status = dataRD[0]; } while ((status & ISC_READY) == 0); printf("passed\n"); /* close Turbo mode and exit */ result = BDI_DoJtag(JTAG_CMD_PORT, JTAG_TRST_LOW, 0, NULL, NULL); result = BDI_DoJtag(JTAG_CMD_PORT, JTAG_TRST_HIGH, 0, NULL, NULL); result = BDI_DoJtag(JTAG_CMD_CLOSE, 0, 0, NULL, NULL); /* reset and init target */ result = BDI_TargetStartup(100, // 500ms reset time (0L << 16) | (11L << 8) | 7, // little endian, ARM966, 1 MHz JTAG sizeof initListSTR912 / sizeof initListSTR912[0], initListSTR912); /* setup flash type */ result = BDI_FlashSetType(BDI_FLASH_STR910F, 0x80000, // 512K 0, 16, 0x40000000); // workspace in internal SRAM if (result != BDI_OKAY) return result; /* unlock sectors */ addr = 0; for (sector = 0; sector < 4; sector++) { printf("unlock sector 0x%08lx ... ", addr); result = BDI_SetWord(addr, 0x0060); result = BDI_SetWord(addr, 0x00D0); if (result != BDI_OKAY) return result; printf("passed\n"); addr += 0x10000; } /* for */ /* program/verify from a file */ printf("programming..."); result = BDI_FlashWriteBinary("e:/temp/dump256k.bin", 0x00000000, &errorAddr); if (result != BDI_OKAY) return result; printf("passed\n"); printf("verifying... "); result = BDI_VerifyBinary("e:/temp/dump256k.bin", 0x00000000, &errorAddr); printf("passed\n"); return result; } /* JtagSTR912 */