Program to update the D7A modem's firmware.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: main.cpp
- Revision:
- 12:beabd59e0c35
- Parent:
- 11:3c6ef9b1be8a
- Child:
- 13:c3324b26d473
--- a/main.cpp Tue Nov 15 14:46:00 2016 +0000 +++ b/main.cpp Fri Jan 06 14:16:49 2017 +0000 @@ -17,9 +17,30 @@ // This is the default root key // if you have changed this key, please specify it here -// For now root key size is always D7A_ROOT_KEY_SIZE (8) -uint8_t root_key[D7A_ROOT_KEY_SIZE] = CUP_DEFAULT_KEY; -uint8_t root_key_size = D7A_ROOT_KEY_SIZE; // XXX: Do not change this +uint8_t root_key[CUP_DEFAULT_KEY_SIZE] = CUP_DEFAULT_KEY; +uint8_t root_key_size = CUP_DEFAULT_KEY_SIZE; + +// ----------------------------------------------- +// Hardware configuration +// ----------------------------------------------- +#if defined(TARGET_STM32L152RE) + #define D7A_PIN_TX (D10) + #define D7A_PIN_RX (D2) + #define D7A_PIN_RTS (D13) + #define D7A_PIN_CTS (D9) + #define D7A_PIN_RESET (A3) + #define DEBUG_LED (NC) + #define DEBUG_BUTTON (USER_BUTTON) +#elif defined(TARGET_STM32L432KC) + #define D7A_PIN_TX (D5) + #define D7A_PIN_RX (D4) + #define D7A_PIN_RTS (D11) + #define D7A_PIN_CTS (D10) + #define D7A_PIN_RESET (D12) + #define DEBUG_LED (D13) // LED1 +#else + #error "Please choose or add the right platform." +#endif // callbacks structure const d7a_callbacks_t callbacks = { @@ -31,11 +52,10 @@ // Com configuration for the DASH7 shield const d7a_com_config_t shield_config = { - .tx = D10, - .rx = D2, - .rts = D13, - .cts = D9, - .rx_buffer_size = 1024, + .tx = D7A_PIN_TX, + .rx = D7A_PIN_RX, + .rts = D7A_PIN_RTS, + .cts = D7A_PIN_CTS, }; // Semaphore for notifiying button presses @@ -69,15 +89,17 @@ uint32_t cup_offset; // Start & initialize - DBG_OPEN(); + DBG_OPEN(DEBUG_LED); PRINT("\r\n-----------------------------------\r\n"); PRINT("---------- D7A WM Updater ---------\r\n"); PRINT("-----------------------------------\r\n"); - DebouncedInterrupt user_interrupt(USER_BUTTON); +#ifdef DEBUG_BUTTON + DebouncedInterrupt user_interrupt(DEBUG_BUTTON); user_interrupt.attach(button_push_isr, IRQ_FALL, 200, true); +#endif - d7a_open(&shield_config, A3, &callbacks); + d7a_open(&shield_config, D7A_PIN_RESET, &callbacks); // Check modem revision D7A_READ(&rev, D7A_FID_FIRMWARE_VERSION, 0, sizeof(d7a_revision_t), NULL); @@ -97,25 +119,23 @@ hw_errors += check_parameter("Hardware version... ", rev.hw_version, CUP_HW_ID); fw_errors += check_parameter("Firmware id... ", rev.fw_version.id, CUP_FW_ID); + PRINT("Checking CUP Slack... "); + cup_offset = (CUP_CODE_SIZE > cup_cfg.src_offset)? CUP_CODE_SIZE - cup_cfg.src_offset : 0; + int32_t cup_slack = cup_cfg.key - cup_offset - CUP_DATA_SIZE; + if (cup_slack < 0) + { + PRINT("Failed. (%d bytes short)\r\n", -cup_slack); + fw_errors++; + } + else + { + PRINT("OK. (%d bytes)\r\n", cup_slack); + } + if (version_old != version_new) { fw_errors += check_parameter("Firmware version major...", rev.fw_version.major, CUP_TARGET_FW_MAJOR); fw_errors += check_parameter("Firmware version minor...", rev.fw_version.minor, CUP_TARGET_FW_MINOR); - - PRINT("Checking CUP Slack... "); - - cup_offset = (CUP_CODE_SIZE > cup_cfg.src_offset)? CUP_CODE_SIZE - cup_cfg.src_offset : 0; - - int32_t cup_slack = cup_cfg.key - cup_offset - CUP_DATA_SIZE; - if (cup_slack < 0) - { - PRINT("Failed. (%d bytes short)\r\n", -cup_slack); - fw_errors++; - } - else - { - PRINT("OK. (%d bytes)\r\n", cup_slack); - } } PRINT("\r\n"); @@ -127,11 +147,12 @@ if (fw_errors) { - PRINT("Please, check that you chose the right Revision in mbed revision tree.\r\n"); - PRINT("You are trying to upgrade from v%d.%d.%d to v%d.%d.%d.\r\n", + PRINT("Please, check that you chose the right Revision in mbed revision tree.\r\n" + "You are trying to upgrade from v%d.%d.%d 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); - PRINT("You can only upgrade to another patch %d.%d.x --> %d.%d.y\r\nor to the next minor %d.%d.x --> %d.%d.0\r\n", + PRINT("You can only upgrade to another patch %d.%d.x --> %d.%d.y\r\n" + "or to the next minor %d.%d.x --> %d.%d.0\r\n", rev.fw_version.major, rev.fw_version.minor, rev.fw_version.major, rev.fw_version.minor, rev.fw_version.major, rev.fw_version.minor, @@ -144,16 +165,13 @@ { PRINT("\r\nSelect the right parameters and recompile.\r\n"); } - else if (version_old == version_new) - { - PRINT("Your modem is up to date! (v%d.%d.%d)\r\n", - rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch); - } + else { if (version_old > version_new) { - PRINT("/!\\ Your modem is at a more recent version (v%d.%d.%d)/!\\\r\n/!\\ Are you sure you want to downgrade to v%d.%d.%d ? /!\\\r\n", + PRINT("/!\\ Your modem is at a more recent version (v%d.%d.%d)/!\\\r\n" + "/!\\ 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); PRINT("PRESS USER BUTTON TO CONFIRM...\r\n"); @@ -161,18 +179,33 @@ 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 PRINT("PRESS USER BUTTON TO START DOWNGRADE...\r\n"); + button_user.wait(); +#endif + cup_start_update(cup_offset); + } + else if (version_old == version_new) + { + PRINT("Your modem is up to date! (v%d.%d.%d)\r\n", + rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch); +#ifdef DEBUG_BUTTON + PRINT("PRESS USER BUTTON TO RETRY UPGRADE...\r\n"); + button_user.wait(); + cup_start_update(cup_offset); +#endif } else { PRINT("Upgrading 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 PRINT("PRESS USER BUTTON TO START UPGRADE...\r\n"); + button_user.wait(); +#endif + cup_start_update(cup_offset); } - - button_user.wait(); - cup_start_update(cup_offset); } // Set main task to lowest priority