/** * @brief Display the Main Menu on HyperTerminal * @param None * @retval None */ void Main_Menu(void) { char cmdbuf [CMD_STRING_SIZE] = {0}, cmdname[15] = {0}; /* command input buffer */ int i, j; /* index for command buffer */ int targetFlash; char startAddressStr[10], endAddressStr[10]; int32_t startAddress, endAddress; bool inputFlashArea = false; while (1) { /* loop forever */ printf ("\n\rWiFiMCU> "); getline (&cmdbuf[0], sizeof (cmdbuf)); /* input command line */ for (i = 0; cmdbuf[i] == ' '; i++); /* skip blanks on head */ for (; cmdbuf[i] != 0; i++) { /* convert to upper characters */ cmdbuf[i] = toupper(cmdbuf[i]); } for (i = 0; cmdbuf[i] == ' '; i++); /* skip blanks on head */ for(j=0; cmdbuf[i] != ' '&&cmdbuf[i] != 0; i++,j++) { /* find command name */ cmdname[j] = cmdbuf[i]; } cmdname[j] = '\0'; /***************** Command "0" or "BOOTUPDATE": Update the application *************************/ if(strcmp(cmdname, "BOOTUPDATE") == 0 || strcmp(cmdname, "0") == 0) { if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead Bootloader only...\n\r"); MicoFlashInitialize(MICO_FLASH_FOR_BOOT); SerialUpload(MICO_FLASH_FOR_BOOT, BOOT_START_ADDRESS, "BootLoaderImage.bin", BOOT_FLASH_SIZE); MicoFlashFinalize(MICO_FLASH_FOR_BOOT); continue; } printf ("\n\rUpdating Bootloader...\n\r"); SerialDownload(MICO_FLASH_FOR_BOOT, BOOT_START_ADDRESS, BOOT_FLASH_SIZE); } /***************** Command "1" or "FWUPDATE": Update the MICO application *************************/ else if(strcmp(cmdname, "FWUPDATE") == 0 || strcmp(cmdname, "1") == 0) { if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead MICO application only...\n\r"); MicoFlashInitialize(MICO_FLASH_FOR_APPLICATION); SerialUpload(MICO_FLASH_FOR_APPLICATION, APPLICATION_START_ADDRESS, "ApplicationImage.bin", APPLICATION_FLASH_SIZE); MicoFlashFinalize(MICO_FLASH_FOR_APPLICATION); continue; } printf ("\n\rUpdating MICO application...\n\r"); SerialDownload(MICO_FLASH_FOR_APPLICATION, APPLICATION_START_ADDRESS, APPLICATION_FLASH_SIZE); } /***************** Command "2" or "DRIVERUPDATE": Update the RF driver *************************/ else if(strcmp(cmdname, "DRIVERUPDATE") == 0 || strcmp(cmdname, "2") == 0) { #ifdef MICO_FLASH_FOR_DRIVER if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead RF driver only...\n\r"); MicoFlashInitialize(MICO_FLASH_FOR_DRIVER); SerialUpload(MICO_FLASH_FOR_DRIVER, DRIVER_START_ADDRESS, "DriverImage.bin", DRIVER_FLASH_SIZE); MicoFlashFinalize(MICO_FLASH_FOR_DRIVER); continue; } printf ("\n\rUpdating RF driver...\n\r"); SerialDownload(MICO_FLASH_FOR_DRIVER, DRIVER_START_ADDRESS, DRIVER_FLASH_SIZE); #else printf ("\n\rNo independ flash memory for RF driver, exiting...\n\r"); #endif } /***************** Command "3" or "PARAUPDATE": Update the application *************************/ else if(strcmp(cmdname, "PARAUPDATE") == 0 || strcmp(cmdname, "3") == 0) { if (findCommandPara(cmdbuf, "e", NULL, 0) != -1){ printf ("\n\rErasing MICO settings only...\n\r"); MicoFlashInitialize(MICO_FLASH_FOR_PARA); MicoFlashErase(MICO_FLASH_FOR_PARA, PARA_START_ADDRESS, PARA_END_ADDRESS); MicoFlashFinalize(MICO_FLASH_FOR_PARA); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead MICO settings only...\n\r"); MicoFlashInitialize(MICO_FLASH_FOR_PARA); SerialUpload(MICO_FLASH_FOR_PARA, PARA_START_ADDRESS, "DriverImage.bin", PARA_FLASH_SIZE); MicoFlashFinalize(MICO_FLASH_FOR_PARA); continue; } printf ("\n\rUpdating MICO settings...\n\r"); SerialDownload(MICO_FLASH_FOR_PARA, PARA_START_ADDRESS, PARA_FLASH_SIZE); } /***************** Command "4" or "FLASHUPDATE": : Update the Flash *************************/ else if(strcmp(cmdname, "FLASHUPDATE") == 0 || strcmp(cmdname, "4") == 0) { if (findCommandPara(cmdbuf, "i", NULL, 0) != -1){ targetFlash = MICO_INTERNAL_FLASH; }else if(findCommandPara(cmdbuf, "s", NULL, 200) != -1){ targetFlash = MICO_SPI_FLASH; }else{ printf ("\n\rUnkown target type! Exiting...\n\r"); continue; } inputFlashArea = false; if (findCommandPara(cmdbuf, "start", startAddressStr, 10) != -1){ if(Str2Int((uint8_t *)startAddressStr, &startAddress)==0){ //Found Flash start address printf ("\n\rIllegal start address.\n\r"); continue; }else{ if (findCommandPara(cmdbuf, "end", endAddressStr, 10) != -1){ //Found Flash end address if(Str2Int((uint8_t *)endAddressStr, &endAddress)==0){ printf ("\n\rIllegal end address.\n\r"); continue; }else{ inputFlashArea = true; } }else{ printf ("\n\rFlash end address not found.\n\r"); continue; } } } if(endAddress<startAddress && inputFlashArea == true) { printf ("\n\rIllegal flash address.\n\r"); continue; } if(inputFlashArea != true){ if(targetFlash == MICO_INTERNAL_FLASH){ startAddress = platform_flash_peripherals[MICO_INTERNAL_FLASH].flash_start_addr ; endAddress = platform_flash_peripherals[MICO_INTERNAL_FLASH].flash_start_addr + platform_flash_peripherals[MICO_INTERNAL_FLASH].flash_length - 1; }else{ #ifdef USE_MICO_SPI_FLASH startAddress = platform_flash_peripherals[MICO_SPI_FLASH].flash_start_addr ; endAddress = platform_flash_peripherals[MICO_SPI_FLASH].flash_start_addr + platform_flash_peripherals[MICO_SPI_FLASH].flash_length - 1; #else printf ("\n\rSPI Flash not exist\n\r"); continue; #endif } } if (findCommandPara(cmdbuf, "e", NULL, 0) != -1){ printf ("\n\rErasing flash content From 0x%x to 0x%x\n\r", startAddress, endAddress); MicoFlashInitialize((mico_flash_t)targetFlash); MicoFlashErase((mico_flash_t)targetFlash, startAddress, endAddress); MicoFlashFinalize((mico_flash_t)targetFlash); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead flash content From 0x%x to 0x%x\n\r", startAddress, endAddress); MicoFlashInitialize((mico_flash_t)targetFlash); SerialUpload((mico_flash_t)targetFlash, startAddress, "FlashImage.bin", endAddress-startAddress+1); MicoFlashFinalize((mico_flash_t)targetFlash); continue; } printf ("\n\rUpdating flash content From 0x%x to 0x%x\n\r", startAddress, endAddress); SerialDownload((mico_flash_t)targetFlash, startAddress, endAddress-startAddress+1); } /***************** Command: Reboot *************************/ else if(strcmp(cmdname, "MEMORYMAP") == 0 || strcmp(cmdname, "5") == 0) { #if defined MICO_FLASH_FOR_UPDATE && defined MICO_FLASH_FOR_DRIVER printf(MEMMAP, flash_name[MICO_FLASH_FOR_BOOT],BOOT_START_ADDRESS,BOOT_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_PARA], PARA_START_ADDRESS, PARA_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_APPLICATION], APPLICATION_START_ADDRESS, APPLICATION_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_UPDATE], UPDATE_START_ADDRESS, UPDATE_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_DRIVER], DRIVER_START_ADDRESS, DRIVER_END_ADDRESS); #endif #if !defined MICO_FLASH_FOR_UPDATE && defined MICO_FLASH_FOR_DRIVER printf(MEMMAP, flash_name[MICO_FLASH_FOR_BOOT],BOOT_START_ADDRESS,BOOT_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_PARA], PARA_START_ADDRESS, PARA_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_APPLICATION], APPLICATION_START_ADDRESS, APPLICATION_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_DRIVER], DRIVER_START_ADDRESS, DRIVER_END_ADDRESS); #endif #if defined MICO_FLASH_FOR_UPDATE && !defined MICO_FLASH_FOR_DRIVER printf(MEMMAP, flash_name[MICO_FLASH_FOR_BOOT],BOOT_START_ADDRESS,BOOT_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_PARA], PARA_START_ADDRESS, PARA_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_APPLICATION], APPLICATION_START_ADDRESS, APPLICATION_END_ADDRESS); #endif #if !defined MICO_FLASH_FOR_UPDATE && !defined MICO_FLASH_FOR_DRIVER printf(MEMMAP, flash_name[MICO_FLASH_FOR_BOOT],BOOT_START_ADDRESS,BOOT_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_PARA], PARA_START_ADDRESS, PARA_END_ADDRESS,\ flash_name[MICO_FLASH_FOR_APPLICATION], APPLICATION_START_ADDRESS, APPLICATION_END_ADDRESS); #endif } /***************** Command: Excute the application *************************/ else if(strcmp(cmdname, "BOOT") == 0 || strcmp(cmdname, "6") == 0) { printf ("\n\rBooting.......\n\r"); startApplication(); } /***************** Command: Reboot *************************/ else if(strcmp(cmdname, "REBOOT") == 0 || strcmp(cmdname, "7") == 0) { printf ("\n\rReBooting.......\n\r"); MicoSystemReboot(); break; } else if(strcmp(cmdname, "HELP") == 0 || strcmp(cmdname, "?") == 0) { printf ( menu, MODEL, Bootloader_REVISION ); /* display command menu */ break; } else if(strcmp(cmdname, "") == 0 ) { break; } else{ printf (ERROR_STR, "UNKNOWN COMMAND"); break; } } }
/** * @brief Display the Main Menu on HyperTerminal * @param None * @retval None */ void Main_Menu(void) { char cmdbuf [CMD_STRING_SIZE] = {0}, cmdname[15] = {0}; /* command input buffer */ int i, j; /* index for command buffer */ char startAddressStr[10], endAddressStr[10], flash_dev_str[4]; int32_t startAddress, endAddress; bool inputFlashArea = false; mico_logic_partition_t *partition; mico_flash_t flash_dev; OSStatus err = kNoErr; while (1) { /* loop forever */ printf ("\n\rMXCHIP> "); getline (&cmdbuf[0], sizeof (cmdbuf)); /* input command line */ for (i = 0; cmdbuf[i] == ' '; i++); /* skip blanks on head */ for (; cmdbuf[i] != 0; i++) { /* convert to upper characters */ cmdbuf[i] = toupper(cmdbuf[i]); } for (i = 0; cmdbuf[i] == ' '; i++); /* skip blanks on head */ for(j=0; cmdbuf[i] != ' '&&cmdbuf[i] != 0; i++,j++) { /* find command name */ cmdname[j] = cmdbuf[i]; } cmdname[j] = '\0'; /***************** Command "0" or "BOOTUPDATE": Update the application *************************/ if(strcmp(cmdname, "BOOTUPDATE") == 0 || strcmp(cmdname, "0") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_BOOTLOADER ); if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead Bootloader...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "BootLoaderImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating Bootloader...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_BOOTLOADER, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "1" or "FWUPDATE": Update the MICO application *************************/ else if(strcmp(cmdname, "FWUPDATE") == 0 || strcmp(cmdname, "1") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_APPLICATION ); if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead application...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "ApplicationImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating application...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_APPLICATION, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "2" or "DRIVERUPDATE": Update the RF driver *************************/ else if(strcmp(cmdname, "DRIVERUPDATE") == 0 || strcmp(cmdname, "2") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_RF_FIRMWARE ); if( partition == NULL ){ printf ("\n\rNo flash memory for RF firmware, exiting...\n\r"); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead RF firmware...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "DriverImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating RF driver...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_RF_FIRMWARE, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "3" or "PARAUPDATE": Update the application *************************/ else if(strcmp(cmdname, "PARAUPDATE") == 0 || strcmp(cmdname, "3") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_PARAMETER_1 ); if (findCommandPara(cmdbuf, "e", NULL, 0) != -1){ printf ("\n\rErasing settings...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_PARAMETER_1, 0x0, partition->partition_length ); require_noerr( err, exit); MicoFlashErase( MICO_PARTITION_PARAMETER_1, 0x0, partition->partition_length ); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead settings...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "DriverImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating settings...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_PARAMETER_1, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "4" or "FLASHUPDATE": : Update the Flash *************************/ else if(strcmp(cmdname, "FLASHUPDATE") == 0 || strcmp(cmdname, "4") == 0) { if (findCommandPara(cmdbuf, "dev", flash_dev_str, 1) == -1 ){ printf ("\n\rUnkown target type! Exiting...\n\r"); continue; } if(Str2Int((uint8_t *)flash_dev_str, (int32_t *)&flash_dev)==0){ printf ("\n\rDevice Number Err! Exiting...\n\r"); continue; } if( flash_dev >= MICO_FLASH_MAX ){ printf ("\n\rDevice Err! Exiting...\n\r"); continue; } inputFlashArea = false; if (findCommandPara(cmdbuf, "start", startAddressStr, 10) != -1){ if(Str2Int((uint8_t *)startAddressStr, &startAddress)==0){ //Found Flash start address printf ("\n\rIllegal start address.\n\r"); continue; }else{ if (findCommandPara(cmdbuf, "end", endAddressStr, 10) != -1){ //Found Flash end address if(Str2Int((uint8_t *)endAddressStr, &endAddress)==0){ printf ("\n\rIllegal end address.\n\r"); continue; }else{ inputFlashArea = true; } }else{ printf ("\n\rFlash end address not found.\n\r"); continue; } } } if(endAddress<startAddress && inputFlashArea == true) { printf ("\n\rIllegal address.\n\r"); continue; } if(inputFlashArea != true){ startAddress = platform_flash_peripherals[ flash_dev ].flash_start_addr ; endAddress = platform_flash_peripherals[ flash_dev ].flash_start_addr + platform_flash_peripherals[ flash_dev ].flash_length - 1; } if (findCommandPara(cmdbuf, "e", NULL, 0) != -1){ printf ("\n\rErasing dev%d content From 0x%x to 0x%x\n\r", flash_dev, startAddress, endAddress); platform_flash_init( &platform_flash_peripherals[ flash_dev ] ); platform_flash_disable_protect( &platform_flash_peripherals[ flash_dev ], startAddress, endAddress ); platform_flash_erase( &platform_flash_peripherals[ flash_dev ], startAddress, endAddress ); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead dev%d content From 0x%x to 0x%x\n\r", flash_dev, startAddress, endAddress); SerialUpload(flash_dev, startAddress, "FlashImage.bin", endAddress-startAddress+1); continue; } printf ("\n\rUpdating dev%d content From 0x%x to 0x%x\n\r", flash_dev, startAddress, endAddress); platform_flash_disable_protect( &platform_flash_peripherals[ flash_dev ], startAddress, endAddress ); SerialDownload(flash_dev, startAddress, endAddress-startAddress+1); } /***************** Command: MEMORYMAP *************************/ else if(strcmp(cmdname, "MEMORYMAP") == 0 || strcmp(cmdname, "5") == 0) { printf("\r"); for( i = 0; i <= MICO_PARTITION_PARAMETER_2; i++ ){ partition = MicoFlashGetInfo( (mico_partition_t)i ); if (partition->partition_owner == MICO_FLASH_NONE) continue; printf( "| %11s | Dev:%d | 0x%08x | 0x%08x |\r\n", partition->partition_description, partition->partition_owner, partition->partition_start_addr, partition->partition_length); } } /***************** Command: Excute the application *************************/ else if(strcmp(cmdname, "BOOT") == 0 || strcmp(cmdname, "6") == 0) { printf ("\n\rBooting.......\n\r"); partition = MicoFlashGetInfo( MICO_PARTITION_APPLICATION ); bootloader_start_app( partition->partition_start_addr ); } /***************** Command: Reboot *************************/ else if(strcmp(cmdname, "REBOOT") == 0 || strcmp(cmdname, "7") == 0) { printf ("\n\rReBooting.......\n\r"); MicoSystemReboot(); break; } else if(strcmp(cmdname, "HELP") == 0 || strcmp(cmdname, "?") == 0) { printf ( menu, MODEL, Bootloader_REVISION, HARDWARE_REVISION ); /* display command menu */ break; } else if(strcmp(cmdname, "") == 0 ) { break; } else{ printf (ERROR_STR, "UNKNOWN COMMAND"); break; } exit: continue; } }