ST / Mbed 2 deprecated BlueNRG-MS-Stack-Updater

Dependencies:   mbed X_NUCLEO_IDB0XA1 BLE_API

Fork of BlueNRG-MS-Stack-Updater by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2015 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "mbed.h"
00018 #include "BlueNRGDevice.h"
00019 
00020 #define BLUENRG_MS_HW_VERSION (0x31)
00021 
00022 // This file defines the array used to store the firmware
00023 #include "img73.c"
00024 
00025 DigitalOut led1(LED1);
00026 
00027 
00028 void error_loop(void)
00029 {
00030     // Blink fast to signal error condition
00031     while (1) {
00032         led1 = !led1;
00033         wait_ms(80);
00034     }
00035 }
00036 
00037 // This program updates the firmware of the
00038 // BlueNRG-MS chip of the X-NUCLEO-IDB05A1 board.
00039 // The target firmware version is 7.2a
00040 // If the update is successful, LED1 blinks slowly;
00041 // on error, LED1 blinks fast.
00042 int main(void)
00043 {
00044     uint8_t hw_version;
00045     uint8_t get_hw_version_status;
00046     int update_status;
00047     BlueNRGDevice* bleDevice;
00048 
00049     // Keep LED1 turned on to show that update is in progress
00050     led1 = 1;
00051 
00052     bleDevice = (BlueNRGDevice*) createBLEInstance();
00053     get_hw_version_status = bleDevice->getUpdaterHardwareVersion(&hw_version);
00054     
00055     if (get_hw_version_status != BLE_STATUS_SUCCESS) {
00056         printf("ERROR: Unable to get HW version\n\r");
00057         error_loop();
00058     }
00059     
00060     if ( (hw_version < BLUENRG_MS_HW_VERSION) || (hw_version > BLUENRG_MS_HW_VERSION) ) {
00061         printf("Sorry, you're HW version is not supported\n\r");
00062         error_loop();
00063     }
00064 
00065     printf("Start updating BlueNRG-MS firmware...\n\r");
00066     
00067     update_status = bleDevice->updateFirmware(fw_image, sizeof(fw_image));
00068 
00069     if (update_status != BLE_STATUS_SUCCESS) {
00070         printf("ERROR: Unable to update firmware\n\r");
00071         error_loop();
00072     }
00073     
00074     printf("Firmware updated successfully!\n\r");
00075     // Blink slowly to signal successful firmware update
00076     while (1) {
00077         led1 = !led1;
00078         wait(1);
00079     }
00080 }