Program to update the D7A modem's firmware.

Dependencies:   modem_ref_helper DebouncedInterrupt

Revision:
18:a8a640941018
Parent:
17:05c9ec970a6d
Child:
20:100143cecc41
--- a/main.cpp	Tue Mar 14 15:18:05 2017 +0000
+++ b/main.cpp	Mon Apr 24 16:40:03 2017 +0000
@@ -38,6 +38,7 @@
     #define D7A_PIN_CTS             (D10)
     #define D7A_PIN_RESET           (D12)
     #define DEBUG_LED               (D13) // LED1
+    #define DEBUG_BUTTON            (D9)
 #else
     #error "Please choose or add the right platform."
 #endif
@@ -99,8 +100,10 @@
     //PRINT("key: %d data: %d code: %d src: %d\r\n", cup_cfg->key, cup->data_size, cup->code_size, cup_cfg->src_offset);
     PRINT("Checking CUP Slack...              ");
     
-    int32_t data_size = (((cup->data_size/256)+1)*256);
-    int32_t cup_slack = cup_cfg->key - data_size;
+    //int32_t data_size = (((cup->data_size/256)+1)*256);
+    int32_t cup_slack = cup_cfg->key - cup->data_size;
+    
+    cup_slack = ((cup_slack/256)*256);
     
     if (cup_slack < 0)
     {
@@ -253,25 +256,27 @@
                       "/!\\ Are you sure you want to downgrade to v%d.%d.%d ? /!\\\r\n",
                         rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch,
                         cup->fw_major, cup->fw_minor, cup->fw_patch);
+#ifdef DEBUG_BUTTON
                 PRINT("PRESS USER BUTTON TO CONFIRM...\r\n");
                 button_user.wait();
+#endif
                 PRINT("\r\nDowngrading firmware: v%d.%d.%d --> v%d.%d.%d\r\n", 
                         rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch,
                         cup->fw_major, cup->fw_minor, cup->fw_patch);
-    #ifdef DEBUG_BUTTON
+#ifdef DEBUG_BUTTON
                 PRINT("PRESS USER BUTTON TO START DOWNGRADE...\r\n");
                 button_user.wait();
-    #endif
+#endif
             }
             else if (version_old != version_new)
             {
                 PRINT("\r\nUpgrading firmware: v%d.%d.%d --> v%d.%d.%d\r\n", 
                         rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch,
                         cup->fw_major, cup->fw_minor, cup->fw_patch);
-    #ifdef DEBUG_BUTTON
+#ifdef DEBUG_BUTTON
                 PRINT("PRESS USER BUTTON TO START UPGRADE...\r\n");
                 button_user.wait();
-    #endif
+#endif
             }
         
             cup_start_update(cup_slack, bootloader);