Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "SakuraIO.h" 00003 00004 Serial pc(USBTX, USBRX); 00005 DigitalOut myled(LED1); 00006 00007 #if defined(TARGET_NUCLEO_F042K6) || defined(TARGET_NUCLEO_F303K8) 00008 // Nucleo-32 series 00009 SPI spi(A6, A5, A4); // mosi, miso, sclk 00010 DigitalOut cs(A3); 00011 I2C i2c(D4, D5); // sda, scl 00012 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_L476RG) 00013 // Nucleo-64 series 00014 SPI spi(D11, D12, D13); // mosi, miso, sclk 00015 DigitalOut cs(D10); 00016 I2C i2c(D14, D15); 00017 #elif defined(TARGET_SAKURAIO_EVB_01) 00018 // sakura.io Evaluation Board(SCO-EVB-01) 00019 SPI spi(PB_15, PB_14, PB_13); // mosi, miso, sclk 00020 DigitalOut cs(PB_12); 00021 I2C i2c(PC_9, PA_8); 00022 #else 00023 // LPC1768 or others. 00024 SPI spi(p5, p6, p7); // mosi, miso, sclk 00025 DigitalOut cs(p8); 00026 I2C i2c(p9, p10); // sda, scl 00027 #endif 00028 00029 //SakuraIO_SPI sakuraio( spi, cs ); 00030 SakuraIO_I2C sakuraio(i2c); 00031 00032 uint8_t updateFirmware() 00033 { 00034 uint8_t ret; 00035 char version[33] = {0}; 00036 00037 wait(1); 00038 00039 // Check module 00040 uint16_t productId = sakuraio.getProductID(); 00041 switch(productId) { 00042 case 0x0001: 00043 pc.printf("SCM-LTE-Beta\r\n"); 00044 break; 00045 case 0x0002: 00046 pc.printf("SCM-LTE-01\r\n"); 00047 break; 00048 default: 00049 pc.printf("Please check connection %d\r\n", productId); 00050 return 1; 00051 } 00052 00053 00054 pc.printf("Get current version\r\n"); 00055 ret = sakuraio.getFirmwareVersion(version); 00056 if((ret = sakuraio.getFirmwareVersion(version)) != CMD_ERROR_NONE) { 00057 pc.printf("Error code=%d\r\n", ret); 00058 return 1; 00059 } 00060 pc.printf("Current: %s\r\n", version); 00061 00062 00063 // Waiting for online 00064 pc.printf("Waiting for online\r\n"); 00065 while(1) { 00066 pc.printf("."); 00067 wait_ms(2000); 00068 if((sakuraio.getConnectionStatus() & 0x80) != 0x00) { 00069 break; 00070 } 00071 } 00072 pc.printf("\r\nOnline\r\n"); 00073 00074 00075 wait_ms(1000); 00076 00077 00078 // Request unlock 00079 pc.printf("Unlock\r\n"); 00080 if((ret = sakuraio.unlock()) != CMD_ERROR_NONE) { 00081 pc.printf("Error code=%d\r\n", ret); 00082 return 1; 00083 } 00084 00085 wait_ms(1000); 00086 00087 // Request firmware update 00088 pc.printf("Starting update\r\n"); 00089 if((ret = sakuraio.updateFirmware()) != CMD_ERROR_NONE) { 00090 pc.printf("Error code=%d\r\n", ret); 00091 return 1; 00092 } 00093 00094 wait_ms(1000); 00095 00096 // Check update status 00097 uint8_t errCode = 0x00; 00098 pc.printf("Waiting for update\r\n"); 00099 while(1) { 00100 00101 wait_ms(1000); 00102 pc.printf("."); 00103 00104 uint8_t updateStatus = sakuraio.getFirmwareUpdateStatus(); 00105 if(updateStatus == 0xff || (updateStatus & 0x80) != 0x00) { 00106 continue; 00107 } else if(updateStatus == 0x00) { 00108 // Success 00109 break; 00110 } else { 00111 // Error 00112 errCode = updateStatus & 0x3f; 00113 break; 00114 } 00115 } 00116 00117 pc.printf("\r\n"); 00118 switch(errCode) { 00119 case 0x00: 00120 return 0; 00121 case 0x01: 00122 pc.printf("Already updated\r\n"); 00123 return 0; 00124 default: 00125 pc.printf("Error code=%d\r\n", errCode); 00126 break; 00127 } 00128 00129 return 1; 00130 } 00131 00132 int main() 00133 { 00134 if(updateFirmware() == 0) { 00135 pc.printf("Update successfull\r\n"); 00136 } else { 00137 pc.printf("Update failure\r\n"); 00138 } 00139 while(1) { 00140 myled = !myled; 00141 wait(1); 00142 } 00143 00144 }
Generated on Thu Jul 14 2022 00:36:11 by
1.7.2