Application to update the BlueNRG-MS firmware of X-NUCLEO-IDB05A1 component board
Dependencies: mbed X_NUCLEO_IDB0XA1 BLE_API
Fork of BlueNRG-MS-Stack-Updater by
BlueNRG-MS Stack Updater
This program allows to update BlueNRG-MS (X-NUCLEO-IDB05A1) stack image.
It programs BlueNRG-MS with the latest version of stack image provided through a C array: img73.c
The target firmware version is 7.3 (BLE 4.2 compliance). If the update is successful, LED1 blinks slowly; on error, LED1 blinks fast.
Tested platforms
Note
This application should not be used to update the stack image of BlueNRG (X-NUCLEO-IDB04A1) component which is considered deprecated.
main.cpp@11:32a57eea3341, 2019-03-19 (annotated)
- Committer:
- apalmieri
- Date:
- Tue Mar 19 10:22:42 2019 +0000
- Revision:
- 11:32a57eea3341
- Parent:
- 10:59d9c2ef8c6c
Revert to BlueNRG-MS stack img v7.3 (BLE 4.2)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avilei | 0:872cf47093cf | 1 | /* mbed Microcontroller Library |
avilei | 0:872cf47093cf | 2 | * Copyright (c) 2006-2015 ARM Limited |
avilei | 0:872cf47093cf | 3 | * |
avilei | 0:872cf47093cf | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
avilei | 0:872cf47093cf | 5 | * you may not use this file except in compliance with the License. |
avilei | 0:872cf47093cf | 6 | * You may obtain a copy of the License at |
avilei | 0:872cf47093cf | 7 | * |
avilei | 0:872cf47093cf | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
avilei | 0:872cf47093cf | 9 | * |
avilei | 0:872cf47093cf | 10 | * Unless required by applicable law or agreed to in writing, software |
avilei | 0:872cf47093cf | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
avilei | 0:872cf47093cf | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
avilei | 0:872cf47093cf | 13 | * See the License for the specific language governing permissions and |
avilei | 0:872cf47093cf | 14 | * limitations under the License. |
avilei | 0:872cf47093cf | 15 | */ |
avilei | 0:872cf47093cf | 16 | |
avilei | 0:872cf47093cf | 17 | #include "mbed.h" |
avilei | 0:872cf47093cf | 18 | #include "BlueNRGDevice.h" |
avilei | 0:872cf47093cf | 19 | |
avilei | 0:872cf47093cf | 20 | #define BLUENRG_MS_HW_VERSION (0x31) |
avilei | 0:872cf47093cf | 21 | |
avilei | 3:623d051e9eb6 | 22 | // This file defines the array used to store the firmware |
apalmieri | 11:32a57eea3341 | 23 | #include "img73.c" |
avilei | 0:872cf47093cf | 24 | |
avilei | 0:872cf47093cf | 25 | DigitalOut led1(LED1); |
avilei | 0:872cf47093cf | 26 | |
avilei | 0:872cf47093cf | 27 | |
avilei | 0:872cf47093cf | 28 | void error_loop(void) |
avilei | 0:872cf47093cf | 29 | { |
avilei | 0:872cf47093cf | 30 | // Blink fast to signal error condition |
avilei | 0:872cf47093cf | 31 | while (1) { |
avilei | 0:872cf47093cf | 32 | led1 = !led1; |
avilei | 1:d4887d7f5e85 | 33 | wait_ms(80); |
avilei | 0:872cf47093cf | 34 | } |
avilei | 0:872cf47093cf | 35 | } |
avilei | 0:872cf47093cf | 36 | |
avilei | 3:623d051e9eb6 | 37 | // This program updates the firmware of the |
avilei | 3:623d051e9eb6 | 38 | // BlueNRG-MS chip of the X-NUCLEO-IDB05A1 board. |
avilei | 3:623d051e9eb6 | 39 | // The target firmware version is 7.2a |
avilei | 3:623d051e9eb6 | 40 | // If the update is successful, LED1 blinks slowly; |
avilei | 3:623d051e9eb6 | 41 | // on error, LED1 blinks fast. |
avilei | 0:872cf47093cf | 42 | int main(void) |
avilei | 0:872cf47093cf | 43 | { |
avilei | 0:872cf47093cf | 44 | uint8_t hw_version; |
avilei | 0:872cf47093cf | 45 | uint8_t get_hw_version_status; |
avilei | 0:872cf47093cf | 46 | int update_status; |
avilei | 0:872cf47093cf | 47 | BlueNRGDevice* bleDevice; |
avilei | 0:872cf47093cf | 48 | |
avilei | 0:872cf47093cf | 49 | // Keep LED1 turned on to show that update is in progress |
avilei | 0:872cf47093cf | 50 | led1 = 1; |
avilei | 0:872cf47093cf | 51 | |
avilei | 0:872cf47093cf | 52 | bleDevice = (BlueNRGDevice*) createBLEInstance(); |
avilei | 0:872cf47093cf | 53 | get_hw_version_status = bleDevice->getUpdaterHardwareVersion(&hw_version); |
avilei | 0:872cf47093cf | 54 | |
avilei | 0:872cf47093cf | 55 | if (get_hw_version_status != BLE_STATUS_SUCCESS) { |
avilei | 0:872cf47093cf | 56 | printf("ERROR: Unable to get HW version\n\r"); |
avilei | 0:872cf47093cf | 57 | error_loop(); |
avilei | 0:872cf47093cf | 58 | } |
avilei | 0:872cf47093cf | 59 | |
avilei | 0:872cf47093cf | 60 | if ( (hw_version < BLUENRG_MS_HW_VERSION) || (hw_version > BLUENRG_MS_HW_VERSION) ) { |
avilei | 0:872cf47093cf | 61 | printf("Sorry, you're HW version is not supported\n\r"); |
avilei | 0:872cf47093cf | 62 | error_loop(); |
avilei | 0:872cf47093cf | 63 | } |
avilei | 0:872cf47093cf | 64 | |
avilei | 0:872cf47093cf | 65 | printf("Start updating BlueNRG-MS firmware...\n\r"); |
avilei | 0:872cf47093cf | 66 | |
avilei | 0:872cf47093cf | 67 | update_status = bleDevice->updateFirmware(fw_image, sizeof(fw_image)); |
avilei | 0:872cf47093cf | 68 | |
avilei | 0:872cf47093cf | 69 | if (update_status != BLE_STATUS_SUCCESS) { |
avilei | 0:872cf47093cf | 70 | printf("ERROR: Unable to update firmware\n\r"); |
avilei | 0:872cf47093cf | 71 | error_loop(); |
avilei | 0:872cf47093cf | 72 | } |
avilei | 0:872cf47093cf | 73 | |
avilei | 0:872cf47093cf | 74 | printf("Firmware updated successfully!\n\r"); |
avilei | 0:872cf47093cf | 75 | // Blink slowly to signal successful firmware update |
avilei | 0:872cf47093cf | 76 | while (1) { |
avilei | 0:872cf47093cf | 77 | led1 = !led1; |
avilei | 0:872cf47093cf | 78 | wait(1); |
avilei | 0:872cf47093cf | 79 | } |
avilei | 0:872cf47093cf | 80 | } |