1. Example description

This example shows how software updates over Bluetooth can be added to a microcontroller which does not have built in Bluetooth. In this example, an STM32F4 board is used as the target of the software update. Bluetooth is added using a DA14531 module. The example can be downloaded from Here

You can watch this demo video:

Demonstration of Dialog SmartBond™ DA14531 Module BLE SUOTA

2. HW and SW configuration

2.1. Required Hardware

Here is a list of all the used hardware for this example:

  • Clicker 2 for STM32 by Mikroe (called STM32 from here on)
  • BLE TINY Click by Mikroe (Click board™ containing the DA14531 BLE SoC)
  • SEGGER J-Link

2.2. Hardware configuration

The hardware is configured as follows:

  • The BLE TINY Click goes in the second mikroBUS™ slot of the STM32
  • The STM32 is connected to the SEGGER J-Link according to the wiring below: hardware_setup

2.3. Required software for the project

The following software is used for this part of the example:

  • STM32cubeIDE
  • SEGGER J-Link tools
  • The Dialog SUOTA app for Android or IOS

3. How to run the example

3.1. Initial Setup

This example uses a secondary bootloader. The binary of this bootloader is provided in the demo binaries folder. To run this example, Secondary_bootloader.bin must be written to flash. A tutorial on flashing the device is provided here, please make sure the bootable box is checked when loading the binary.

3.2. Running the example from the provided binaries

Use an external programmer to program STM32.bin from Demo binaries to STM32F4 flash. In this example we use a SEGGER J-Link with J-Link Commander. Flashing the STM32F407VG is pretty straightforward using J-Link Commander, the commands are listed below.

  • Type connect, J-Link Commander will prompt for a few parameters. Device is STM32F407VG, for target interface we use JTAG. Other parameters can be left default.
  • Type r to reset and halt the core.
  • loadfile <PathToSTM32.bin> to program the flash
  • go to start executing the newly programmed code After the go command, LED 1 should start blinking. The STM will also upload the SUOTA BLE firmware to the DA14531.

The setup is now ready for SUOTA, just as in the video above.

3.3. Software configuration

Opening the projects The three project can each be found within the folder STM32-software, the contents of this folder should look like the following:

folder_contents

The insides of these folders should look like the following image, but with differing names for stm32_image and stm32_suota_image.

project_contents

To open one of the projects open up STM32cubeIDE and click File in the upper left corner. Next click Open Project From File System to open up the project import window. Click on the Directory… button and select the folder containing the three projects. The screen should look like the following after these steps:

project_import

Press Finish to import the project, the project structure on the left should look like the following:

project_structure

Right click on the stm32_bootloader project en go to Run As and select 1 STM32 Cortex-M C/C++ Application, if this option is not available or the configuration should be changed click Run Configurations… which looks like the following image.

run_configuration

To create a configuration click the on the New launch configuration button. Afterwards go to the Debugger tab and change Debug probe to SEGGER J-LINK. Make sure SWD is selected and enter the serial number of the J-link. Click Apply and try to run again or press Run. Repeat this for the other projects, press the reset button on the STM32 to start from the bootloader. Now all software should be loaded and a new image can be uploaded through the SUOTA app.

4. Uploading a new image

Provided in the root of the example folder are two binary files named as follows: stm32_led1_suota1.bin and stm32_led2_suota0.bin. These files should be place in the Suota folder of the phone that is used for the update of the STM32.

Once the app starts the following device should appear in the list.

old_flashed_image

Click on the device and waits for its info to load:

selected_device_info

Press the UPDATE DEVICE button.

The following screen should appear with images that can be loaded to the STM32:

image_selection

Select the image stm32_led2_suota0.bin.

Once the image has been selected the following screen pops up. Leave this screen as is, as the settings have no impact on this image transfer.

image_settings

Press SEND TO DEVICE and the update process will start.

If everything went succesfull a pop up should appear asking if the system should be restarted, press OK. Now the screen should look like this:

upload_completed

Press CLOSE which takes you to the first screen again.

Now on the first screen press the SCAN button and the device should appear with its new name.

new_flash

On the STM32 the left LED should have stopped blinking and the second LED should have started blinking. This indicates that the process has been a succes.

5. Explanation of software

First point of attention is the way this demo is setup in the memory for the STM32. The demo consists out of a bootloader, an update program and the firnware, wit heach part being stored in its own memory section. The memory is setup in the following manner:

stm32_memory_map

Sidenote: This is the setup for the STM32F407VGT6 and can be changed for other STM32s by editing the associated linker scripts and system_stm32f4xx.c or the system_stm32xxxx.c if using another line of STM32s.

5.1. The bootloader

The bootloaders job is to check for the memory locations 0x0802_0000 to see if a valid image is present. At the moment the loader does this by checking if the first 32 bit integer of the location is valid. This is the beginning of the stack pointer for the program, and should always be between 0x2000_000 and 0x2001_FFFF as this is the SRAM within the STM32. If this cannot be found than the system starts in the suota update mode, located at address 0x0801_0000.

boot_process

This bootloader is located at memory address 0x0800_0000 as this is where the STM32 starts running code from after it has ran its own internal bootloader.

5.2. The suota image

When this image starts the STM32 is prepared to write to the flash memory. It receives packets from the DA14531 and stores them in the flash at the specified location. Once the update has been completed the SUOTA image starts the code that was just uploaded. The flow of this code is as follows:

suota_process

This image is located at 0x0801_0000.

5.3. The Firmware image

This image is the main firmware of the system, it specifies the main behavior of the STM32 and contains the firmware of the DA14531. The code starts by booting the DA14531 with its firmware. Afterwards the code starts executing its own behavior, whilst waiting for packets from the DA14531. Once it receives a valid packet to start updating the STM32 starts the suota image. The flow of the code is as follows:

firmware_process

5.4. Explanation

This example modifies the included SUOTA profile of the SDK to update an external microcontroller with the existing SUOTA app. This is done by modifying the existing write functions to write received data out over UART to an external MCU. The diagram below shows the flow of the SUOTA process as implemented in this example.

SUOTA flowchart

The flowchart is pretty big, but there are only 4 commands used for the uart communication. These are shown below.

| Command | Start | Command LSB | Parameter length(LSB first) | Parameters | | |———————–|——-|————-|—————————–|—————————————————|—————————————| | Ack | 0xAA | 0x01 | 0x01 | command(1 byte) | Error code(1 byte, 0x00 means all OK) | | Start software update | 0xAA | 0x80 | 0x00 | | | | Program flash | 0xAA | 0x81 | 0x0004 + data length | Flash adress offset(4 bytes), example: 0x00000100 | Data to program | | Checksum + reboot | 0xAA | 0x82 | 0x0001 | CRC checksum | |

The implementation of these commands for STM32 is in DLG_UART.c. And the SUOTA command implementation for DA14531 is in user_external_communication.c both these files can be modified to suit your project needs.

6. Known Limitations

7. License


Copyright (c) 2021 Dialog Semiconductor. All rights reserved.

This software (“Software”) is owned by Dialog Semiconductor. By using this Software you agree that Dialog Semiconductor retains all intellectual property and proprietary rights in and to this Software and any use, reproduction, disclosure or distribution of the Software without express written permission or a license agreement from Dialog Semiconductor is strictly prohibited. This Software is solely for use on or in conjunction with Dialog Semiconductor products.

EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES OR AS REQUIRED BY LAW, THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES OR BY LAW, IN NO EVENT SHALL DIALOG SEMICONDUCTOR BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE SOFTWARE.