Skip to content

Commit

Permalink
sample: board: sensortile_box_pro: add ble-fw-upgrade
Browse files Browse the repository at this point in the history
This sample implement the ble firmware upgrade using the AN5471
protocol on uart2 channel.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
  • Loading branch information
avisconti committed Aug 27, 2024
1 parent fe4ae54 commit 1be34d8
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 0 deletions.
11 changes: 11 additions & 0 deletions samples/boards/sensortile_box_pro/ble-fw-upgrade/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024 STMicroelectronics
#
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(sensortile_box_pro)

target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE src/ble_fw.c)
109 changes: 109 additions & 0 deletions samples/boards/sensortile_box_pro/ble-fw-upgrade/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
.. zephyr:code-sample:: sensortile_box_pro_sample_ble_fwupg
:name: ST SensorTile.box Pro BLE Firmware Upgrade

Upgrade the BLE firmware on STEVAL-MKBOXPRO board

Overview
********
This sample provides a simple method to upgrade the firmware for
the BLE chip present on :ref:`sensortile_box_pro_board` board.
It is based on the BlueNRG-LPS UART bootloader protocol explained in `AN5471`_ .

Requirements
************

The application requires a SensorTile.box Pro board connected to the PC
through USB.

To run this sample the console is not strictly needed, but might be useful.
Following is an example for minicom.

.. code-block:: console
$ minicom -D <tty_device> -b 115200
Replace :code:`<tty_device>` with the correct device path automatically created on
the host after the SensorTile.box Pro board gets connected to it,
usually :samp:`/dev/ttyUSB{x}` or :samp:`/dev/ttyACM{x}` (with x being 0, 1, 2, ...).
The ``-b`` option sets baud rate ignoring the value from config.

Building and Running
********************

To build and flash the sample, it is required fetching the controller-only BLE f/w
image for sensortile_box_pro board, which is hosted by external repo
(see `stsw-mkbox-bleco`_ for more information):

To fetch Binary Blobs:

.. code-block:: console
west blobs fetch stm32
Then, build the sample:

.. zephyr-app-commands::
:zephyr-app: samples/boards/sensortile_box_pro/ble-fw-upgrade
:board: sensortile_box_pro
:goals: build flash

Please note that flashing the board requires a few preliminary steps described
in :ref:`sensortile_box_pro_board`.

After flashing, the sample starts and asks the user to acknowledge the f/w update.
User should press :kbd:`y` or :kbd:`Y` to proceed in upgrading the BLE f/w.

.. code-block:: console
Start BLE f/w update (press Y to proceed):
Nevertheless it is not strictly necessary to use the console, as the user may also acknowledge
the f/w update pressing the User BT2 button (see :ref:`sensortile_box_pro_board` board and
check on user manual and/or schematic to see where the button is located and how
it works).

LEDs status
-----------

The blue LED blinks three times with 200ms interval to indicate the procedure is starting.
Then blue LED start blinking very fast to indicate the BLE flash activity is on going.

After BLE flashing is complete:

- If status is OK the green LED blinks three times with 200ms interval and remains on.
- If flashing failed the red LED blinks three times with 200ms interval and remains on.

Console messages
----------------

To properly see messages on your terminale emulatore you may also need to set lineWrap to on.
In case of minicom just enter the menu with :kbd:`Ctrl-A Z` an then press :kbd:`W`.

The sample outputs following messages.

.. code-block:: console
SensorTile.box Pro BLE f/w upgrade
bootloader activated!
ble bootloader version is 4.0
MASS ERASE ok
..............................................................................................
..............................................................................................
..............................................................................................
..............................................................................................
..............................................................................................
..............................................................................................
..............................................................................................
............................................
BLE f/w upgrade ok
References
**********

.. target-notes::

.. _AN5471:
https://www.st.com/resource/en/application_note/an5471-the-bluenrglp-bluenrglps-uart-bootloader-protocol-stmicroelectronics.pdf

.. _stsw-mkbox-bleco:
https://www.st.com/en/embedded-software/stsw-mkbox-bleco.html
2 changes: 2 additions & 0 deletions samples/boards/sensortile_box_pro/ble-fw-upgrade/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_GPIO=y
CONFIG_LOG=y
15 changes: 15 additions & 0 deletions samples/boards/sensortile_box_pro/ble-fw-upgrade/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sample:
description: SensorTile.box Pro board ble firmware upgrade
name: SensorTile.box Pro fw upgrade
tests:
sample.board.sensortile_box_pro.ble-fw-upgrade:
harness: bluetooth
platform_allow: sensortile_box_pro
tags: bluetooth
depends_on:
- gpio
- uart
# This test cannot be run in CI as it requires the presence of a
# f/w blob that is not fetched by CI iself, as mentioned in
# https://docs.zephyrproject.org/latest/contribute/bin_blobs.html#support-and-maintenance
skip: true
13 changes: 13 additions & 0 deletions samples/boards/sensortile_box_pro/ble-fw-upgrade/src/ble_fw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdint.h>

const uint8_t ble_fw_img[] = {
#include <dtm.bin.inc>
};

const uint32_t ble_fw_img_len = sizeof(ble_fw_img);
Loading

0 comments on commit 1be34d8

Please sign in to comment.