📄 smi.c.svn-base
字号:
else { /*** Put SMI in HW mode ***/ SMICntl->SMI_CR1 &= ~(SW_MODE); /*** Reloading CR1-2 ***/ return(0); } } else { /*** Put SMI in HW mode ***/ SMICntl->SMI_CR1 &= ~(SW_MODE); /*** Reloading CR1-2 ***/ return(-1); } }/***************************** SECTOR Erase ****************************/int smi_sector_erase(unsigned int bank, unsigned int sector){/**** NOTE: SECTOR ERASE IS PERFORMED IN SW MODE ****/ unsigned int B_SEL; unsigned int SAVE_CR1; unsigned int SAVE_CR2; unsigned int sect_add; unsigned int Instruction; unsigned int WM; switch(bank) { case BANK0: B_SEL = BANK0_SEL; WM = WM0; break; case BANK1: B_SEL = BANK1_SEL; WM = WM1; break; case BANK2: B_SEL = BANK2_SEL; WM = WM2; break; case BANK3: B_SEL = BANK3_SEL; WM = WM3; break; } /*** Calculating Instrucion to be sent ***/ sect_add = sector * BANK_SIZE; Instruction = ((sect_add>>8)&0x0000FF00)|SECTOR_ERASE; /*** Saving CR1-2 ***/ /*** Clearing Error Flags ***/ if (smi_read_id(bank) == ST_M25P64) { /*** Programming CR1 in a Known State ***/ SMICntl->SMI_CR1 |= SW_MODE; /*** Clear TFF ***/ SMICntl->SMI_SR &= ~TFF; /*** Check if Flash is WIP in HW mode***/ SMICntl->SMI_CR2 = B_SEL | RD_STATUS_REG; while (!(SMICntl->SMI_SR & TFF)); while (SMICntl->SMI_SR & WIP_BIT) { SMICntl->SMI_SR &= ~TFF; SMICntl->SMI_CR2 = B_SEL | RD_STATUS_REG; while (!(SMICntl->SMI_SR & TFF)); } /*** Clear TFF ***/ SMICntl->SMI_SR &= ~TFF; /*********** Put the Flash in WE and check ************/ SMICntl->SMI_CR2 = WE | B_SEL; while (!(SMICntl->SMI_SR & TFF)); /*** Clear TFF ***/ SMICntl->SMI_SR &= ~TFF; /*** Check if Flash is WEL in HW mode***/ SMICntl->SMI_CR2 = B_SEL | RD_STATUS_REG; while (!(SMICntl->SMI_SR & TFF)); while (!(SMICntl->SMI_SR & WEL_BIT)) { SMICntl->SMI_SR &= ~TFF; SMICntl->SMI_CR2 = B_SEL | RD_STATUS_REG; while (!(SMICntl->SMI_SR & TFF)); } /*** Send SectorErase command in SW Mode ***/ SMICntl->SMI_TR = Instruction; SMICntl->SMI_CR2 = B_SEL | SEND | TX_LEN_4; while (!(SMICntl->SMI_SR & TFF)); /*** Clear TFF ***/ SMICntl->SMI_SR &= ~TFF; /*** Check if Flash is WIP in HW mode***/ SMICntl->SMI_CR2 = B_SEL | RD_STATUS_REG; while (!(SMICntl->SMI_SR & TFF)); while (SMICntl->SMI_SR & WIP_BIT) { SMICntl->SMI_SR &= ~TFF; SMICntl->SMI_CR2 = B_SEL | RD_STATUS_REG; while (!(SMICntl->SMI_SR & TFF)); } /*** Clear TFF ***/ SMICntl->SMI_SR &= ~TFF; /*** Checking for Errors ***/ if ((SMICntl->SMI_SR & (ERF1 | ERF2))) { /*** Put SMI in HW mode ***/ SMICntl->SMI_CR1 &= ~(SW_MODE); /*** Reloading CR1-2 ***/ return(-1); } else { /*** Put SMI in HW mode ***/ SMICntl->SMI_CR1 &= ~(SW_MODE); /*** Reloading CR1-2 ***/ return(0); } } else { /*** Put SMI in HW mode ***/ SMICntl->SMI_CR1 &= ~(SW_MODE); /*** Reloading CR1-2 ***/ return(-1); } }/***********************************************************************//***********************************************************************//********************************* Test ********************************//***********************************************************************/void smi_test(){ static char schedule; static char in_buf; int writeres; unsigned int i; unsigned int data; unsigned int IDFLASH; unsigned int STATUSREG; unsigned int flash_addr; unsigned int MEM_addr[4] = { 7, 6, 8, 9}; unsigned int RES_addr[4]; unsigned int temporary[65]; unsigned int prog_length; unsigned int n_sec; unsigned int *sdram_p, *flash_p; writeres = 0; schedule = 'r'; while(schedule != 's') { UART_tx_vec("SPEArHead SMI and FLASH tests",strlen("SPEArHead SMI and FLASH tests")); while (!(UART_putc(13))); while (!(UART_putc(10))); UART_tx_vec("Flash Test v3.2",strlen("Flash Test v3.2")); UART_tx_vec("select a test:",strlen("select a test:")); UART_tx_vec("O -> for READ DEVICE ID test;",strlen("O -> for READ DEVICE ID test;")); UART_tx_vec("1 -> for READ STATUS REGISTER test;",strlen("1 -> for READ STATUS REGISTER test;")); UART_tx_vec("2 -> for READ DATA test;",strlen("2 -> for READ DATA test;")); UART_tx_vec("3 -> for WRITE DATA test;",strlen("3 -> for WRITE DATA test;")); UART_tx_vec("4 -> for SECTOR ERASE test;",strlen("4 -> for SECTOR ERASE test;")); UART_tx_vec("5 -> for FULL (not interactive) test",strlen("5 -> for FULL (not interactive) test")); UART_tx_vec("6 -> for testing flashing code",strlen("6 -> for testing flashing code")); UART_tx_vec("f -> for DOWNLOAD code",strlen("f -> for DOWNLOAD code")); while (!(UART_putc(13))); while (!(UART_putc(10))); while (!(UART_getc(&in_buf))); switch(in_buf) { case '0': UART_tx_vec("FLASH READ DEVICE ID test selected",strlen("FLASH READ DEVICE ID test selected")); UART_tx_vec("Reading FLASH ID", strlen("Reading FLASH ID")); IDFLASH = smi_read_id(BANK0); UART_tx_vec("ID read is ", strlen("ID read is ")); UART_print_ex(IDFLASH); if (IDFLASH == ST_M25P64) { UART_tx_vec("The Flash connected is : ST M25P64 FLASH", strlen("The Flash connected is : ST M25P64 FLASH")); } break; case '1': UART_tx_vec("FLASH READ STATUS REGISTER test selected",strlen("FLASH READ STATUS REGISTER test selected")); UART_tx_vec("Reading FLASH Status Register", strlen("Reading FLASH Status Register")); STATUSREG = smi_read_sr(BANK0); UART_tx_vec("SR read is ", strlen("SR read is ")); UART_print_ex(STATUSREG); break; case '2': UART_tx_vec("FLASH READ DATA test selected",strlen("FLASH READ DATA test selected")); UART_tx_vec("Please, enter an address",strlen("Please, enter an address")); UART_tx_vec("betwewn 0x96010000 and 0x967FFFFF",strlen("betwewn 0x96010000 and 0x967FFFFF"));/* LEGGI L'INDIRIZZO */ flash_addr = (127 * BANK_SIZE); smi_read((unsigned int*)flash_addr,RES_addr,4,BANK0); UART_tx_vec("Read Value", strlen("Read Value")); for (i=0; i<4; i++) { UART_print_ex(RES_addr[i]); } break; case '3': UART_tx_vec("FLASH WRITE DATA test selected",strlen("FLASH WRITE DATA test selected")); UART_tx_vec("Please, enter an address",strlen("Please, enter an address")); UART_tx_vec("betwewn 0x96010000 and 0x967FFFFF",strlen("betwewn 0x96010000 and 0x967FFFFF"));/* LEGGI L'INDIRIZZO */ UART_tx_vec("Enter the value to be written",strlen("Enter the value to be written")); UART_tx_vec("in HEX Format (0x........)",strlen("in HEX Format (0x........)"));/* LEGGI IL VALORE */ flash_addr = (127 * BANK_SIZE); writeres=smi_write(MEM_addr,(unsigned int*)flash_addr,4,BANK0); if (writeres < 0) { UART_tx_vec("It seems that the sector is not yet erased",strlen("It seems that the sector is not yet erased")); UART_tx_vec("please erase the following sector",strlen("please erase the following sector")); UART_print_ex(flash_addr/BANK_SIZE); } smi_read((unsigned int*)flash_addr,RES_addr,4,BANK0); /* for (i=0; i<4; i++) { UART_tx_vec("Read Value", strlen("Read Value")); UART_print_ex(RES_addr[i]); } */ break; case '4': UART_tx_vec("FLASH SECTOR ERASE test selected",strlen("FLASH SECTOR ERASE test selected")); UART_tx_vec("Please, enter a sector number between 1 and 127",strlen("Please, enter a sector number betwewn 1 and 127")); UART_tx_vec("(in sector nr.0 there is the code)",strlen("(in sector nr.0 there is the code)"));/* LEGGI IL SETTORE e controlla che e' tra 1 e 127 e cambia qui sotto */ if ((smi_sector_erase(BANK0, 127))==0) { UART_tx_vec("Sector Erase OK", strlen("Sector Erase OK")); } else { UART_tx_vec("Sector Erase ERROR", strlen("Sector Erase ERROR")); } UART_tx_vec("Sector Erase End", strlen("Sector Erase End")); break; case '5': UART_tx_vec("FULL test selected",strlen("FULL test selected")); UART_tx_vec("Reading FLASH ID", strlen("Reading FLASH ID")); IDFLASH = smi_read_id(BANK0); UART_tx_vec("ID read is ", strlen("ID read is ")); UART_print_ex(IDFLASH); if (IDFLASH == ST_M25P64) { UART_tx_vec("The Flash connected is : ST M25P64 FLASH", strlen("The Flash connected is : ST M25P64 FLASH")); } UART_tx_vec("Reading FLASH Status Register", strlen("Reading FLASH Status Register")); STATUSREG = smi_read_sr(BANK0); STATUSREG = smi_read_sr(BANK0); STATUSREG = smi_read_sr(BANK0); UART_tx_vec("SR read is ", strlen("SR read is ")); UART_print_ex(STATUSREG); UART_tx_vec("Press a key to continue",strlen("Press a key to continue")); while (!(UART_getc(&in_buf))); UART_tx_vec("Erase Sector 127", strlen("SPEArHead SMI and FLASH tests - Sector Erase")); if ((smi_sector_erase(BANK0, 127))==0) { UART_tx_vec("Press a key to continue",strlen("Press a key to continue")); while (!(UART_getc(&in_buf))); UART_tx_vec("Writing more then 1 page", strlen("Writing more then 1 page")); UART_tx_vec("in one time", strlen("in one time")); UART_tx_vec("Press a key to continue",strlen("Press a key to continue")); while (!(UART_getc(&in_buf))); flash_addr = (127 * BANK_SIZE)+0x108; for (i=0; i<150; i++) { temporary[i] = i; } writeres=smi_write(temporary,(unsigned int*)flash_addr,150,BANK0); UART_tx_vec("Press a key to continue",strlen("Press a key to continue")); while (!(UART_getc(&in_buf))); smi_read((unsigned int*)flash_addr,temporary,150,BANK0); UART_tx_vec("Reading value written in more than 1 page", strlen("Reading value written in more than 1 page")); UART_tx_vec("in one time", strlen("in one time")); for (i=0; i<150; i++) { UART_print_ex(temporary[i]); } } else { UART_tx_vec("Sector Erase ERROR", strlen("Sector Erase ERROR")); } break; case '6': UART_tx_vec("PROG FLASH",strlen("PROG FLASH")); prog_length = (0x20000/4)+1; /* nr of word ( size /4 ) + 1 */ n_sec = (prog_length/0x4000 ) + 1; /* prog length / +1 */ // start from sector 125 for (i=125; i<125 + n_sec; i++) { UART_tx_vec("Erasing Sector Nr",strlen("Erasing Sector Nr")); UART_print_ex(i); smi_sector_erase(BANK0, i); } UART_tx_vec("Programming Flash",strlen("Programming Flash")); smi_write(0x50000,125*BANK_SIZE,prog_length,BANK0); // compare data sdram_p = 0x50000; flash_p = 0x96000000 + 125*BANK_SIZE; for (i = 0; i < prog_length; i++) { if (flash_p[i] != sdram_p[i]) { UART_tx_vec("---- Data differ !!!!",strlen("---- Data differ !!!!")); UART_print_ex(flash_p + i); UART_print_ex(sdram_p + i); break; } } UART_tx_vec("Programming Flash Completed",strlen("Programming Flash Completed")); break; case 'f': UART_tx_vec("PROG FLASH",strlen("PROG FLASH")); prog_length = (0x50000/4)+1; /* nr of word ( size /4 ) + 1 */ n_sec = (prog_length/0x4000 ) + 1; /* prog length / +1 */ for (i=0; i<n_sec; i++) { UART_tx_vec("Erasing Sector Nr",strlen("Erasing Sector Nr")); UART_print_ex(i); smi_sector_erase(BANK0, i); } UART_tx_vec("Programming Flash",strlen("Programming Flash")); smi_write(0x50000,0x00000000,prog_length,BANK0); // compare code sdram_p = 0x50000; flash_p = 0x96000000; for (i = 0; i < prog_length; i++) { if (flash_p[i] != sdram_p[i]) { UART_tx_vec("---- Data differ !!!!",strlen("---- Data differ !!!!")); UART_print_ex(flash_p + i); UART_print_ex(sdram_p + i); break; } } UART_tx_vec("Programming Flash Completed",strlen("Programming Flash Completed")); break; } while (!(UART_putc(13))); while (!(UART_putc(10))); UART_tx_vec("press s to stop r to run again",strlen("press s to stop r to run again")); while (!(UART_getc(&schedule))); while (!(UART_putc(13))); while (!(UART_putc(10))); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -