src: https://github.com/sakuraio/SakuraIOArduino/tree/master/examples/FirmwareUpdate

Dependencies:   SakuraIO mbed

Files at this revision

API Documentation at this revision

Comitter:
sakurafan
Date:
Mon Jul 24 02:45:01 2017 +0000
Commit message:
1st build

Changed in this revision

SakuraIO.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ad4eb76f11a0 SakuraIO.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SakuraIO.lib	Mon Jul 24 02:45:01 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/sakurafan/code/SakuraIO/#f3b80b2bdb14
diff -r 000000000000 -r ad4eb76f11a0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 24 02:45:01 2017 +0000
@@ -0,0 +1,116 @@
+#include "mbed.h"
+#include "SakuraIO.h"
+
+SakuraIO_I2C sakuraio(p28, p27); // sda, scl (mbed LPC1768)
+
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+
+uint8_t updateFirmware () {
+  uint8_t ret;
+  char version[33] = {0};
+
+  // Check module
+  uint16_t productId = sakuraio.getProductID();
+  switch(productId){
+    case 0x0001:
+      pc.printf("SCM-LTE-Beta\r\n");
+      break;
+    default:
+      pc.printf("Please check connection\r\n");
+      return 1;
+  }
+
+  wait(1);
+
+  // Waiting for online
+  pc.printf("Waiting for online\r\n");
+  while (1) {
+    pc.printf(".");
+    wait(2);
+    if((sakuraio.getConnectionStatus() & 0x80) != 0x00){
+      break;
+    }
+  }
+  pc.printf("\r\n");
+  pc.printf("Online\r\n");
+
+  pc.printf("Get current version\r\n");
+  ret = sakuraio.getFirmwareVersion(version);
+  if((ret = sakuraio.getFirmwareVersion(version)) != CMD_ERROR_NONE){
+    pc.printf("Error code=%d\r\n", ret);
+    return 1;
+  }
+  pc.printf("Current: %s\r\n", version);
+
+  wait(1);
+
+  // Request unlock
+  pc.printf("Unlock\r\n");
+  if((ret = sakuraio.unlock()) != CMD_ERROR_NONE){
+    pc.printf("Error code=%d\r\n", ret);
+    return 1;
+  }
+
+  wait(1);
+
+  // Request firmware update
+  pc.printf("Starting update\r\n");
+  if((ret = sakuraio.updateFirmware()) != CMD_ERROR_NONE){
+    pc.printf("Error code=%d\r\n", ret);
+    return 1;
+  }
+
+  wait(1);
+
+  // Check update status
+  uint8_t errCode = 0x00;
+  pc.printf("Waiting for update\r\n");
+  while(1){
+
+    wait(1);
+    pc.printf(".");
+
+    uint8_t updateStatus = sakuraio.getFirmwareUpdateStatus();
+    if (updateStatus == 0xff || (updateStatus & 0x80) != 0x00) {
+      continue;
+    } else if (updateStatus == 0x00) {
+      // Success
+      break;
+    } else {
+      // Error
+      errCode = updateStatus & 0x3f;
+      break;
+    }
+  }
+
+  pc.printf("\r\n");
+  switch(errCode){
+    case 0x00:
+      return 0;
+    case 0x01:
+      pc.printf("Already updated\r\n");
+      return 0;
+    default:
+      pc.printf("Error code=%d\r\n", errCode);
+      break;
+  }
+
+  return 1;
+}
+
+int main () {
+
+  pc.baud(115200);
+  wait(3);
+  if (updateFirmware() == 0) {
+    pc.printf("Update successfull\r\n");
+  } else {
+    pc.printf("Update failure\r\n");
+  }
+
+  for (;;) {
+    myled = !myled;
+    wait(0.5);
+  }
+}
diff -r 000000000000 -r ad4eb76f11a0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jul 24 02:45:01 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file