Program to update the D7A modem's firmware.

Dependencies:   modem_ref_helper DebouncedInterrupt

Revision:
4:23cb73bb11b3
Parent:
3:a59c8d77006b
Child:
5:ac38f09fd179
--- a/cup.cpp	Wed Oct 26 14:13:58 2016 +0000
+++ b/cup.cpp	Wed Oct 26 15:06:49 2016 +0000
@@ -15,7 +15,6 @@
 signature(CUP_SIGNATURE),
 nb_archives(CUP_NB_ARCHIVES),
 word_size(CUP_WORD_SIZE),
-fw_id(0),
 fw_major(CUP_FW_MAJOR),
 fw_minor(CUP_FW_MINOR),
 fw_patch(CUP_FW_PATCH),
@@ -56,7 +55,7 @@
     
     max_size -= offset;
     int32_t slack = max_size - this->data_size;
-    ASSERT(slack >= 0, "Not enough space to store archive! (%d bytes short)\r\n", slack);
+    ASSERT(slack >= 0, "Not enough space to store archive! (%d bytes short)\r\n", -slack);
     
     D7A_WRITE((uint8_t*)&cfg, CUP_CFG_FID, 0, 4, root_key);
     
@@ -83,7 +82,7 @@
     }
     
     float time_s = tim.read();
-    PRINT("File[%d] %d bytes written in %.2f sec (%.2f kB/s)\r\n", CUP_CODE_FID, this->data_size, time_s, (this->data_size/time_s)/1024.0);
+    PRINT("CUP: %d bytes written in %.2f sec (%.2f kB/s)\r\n", this->data_size, time_s, (this->data_size/time_s)/1024.0);
     
     // Force PFLASH-cache flushing
     D7A_FLUSH(CUP_CODE_FID, root_key);
@@ -96,6 +95,21 @@
         
     D7A_WRITE((uint8_t*)&cfg, CUP_CFG_FID, 0, 12, root_key);
     
-    PRINT("CUP Done.\r\nPlease wait for reboot...\r\n");
+    PRINT("Done.\r\nWaiting for reboot...\r\n");
+    
+    d7a_wait_ready();
+    
+    D7A_READ(&cfg, CUP_CFG_FID, 0, 2, root_key);
+    
+    if (cfg.cmd)
+    {
+        PRINT("/!\\ CUP Error %d /!\\\r\n", cfg.cmd);
+    }
+    else
+    {
+        PRINT("CUP OK\r\nResetting...\r\n");
+        FLUSH();
+        NVIC_SystemReset();
+    }
 }
     
\ No newline at end of file