BLE Central and Peripheral with Pingpong OTA Example

Source Code Path: example/ble/central_and_peripheral_with_pingpong_ota

Supported Platforms

Projects with flash table programmed in mpi5

Overview

This example demonstrates how the platform can function as both GAP central and peripheral, as well as GATT client and server simultaneously. It also shows how to upgrade the project using the pingpong method

Example Usage

  1. The Finsh commands for this example can be printed by entering ‘diss help’ to show command usage.

  2. When acting as a peripheral device, it will start advertising on boot with a name formatted as SIFLI_APP-xx-xx-xx-xx-xx-xx, where xx represents the device’s Bluetooth address. You can connect using a mobile BLE APP.

  3. When acting as a central device, you can search for other peripheral devices through finsh commands and initiate connections.

  4. When acting as a GATT server, you can perform write and read operations on the mobile terminal, or enable CCCD, and the device will update the characteristic value every second.

  5. When acting as a GATT client, you can search and display the server’s database through finsh commands, and perform read or write operations on characteristic values.

  6. Connect the board through the SIFLE BLE APP, select a file, and perform the upgrade

Hardware Requirements

Before running this example, you need to prepare:

Compilation and Flashing

Switch to the example project directory and run the scons command to compile:

> scons --board=sf32lb58-lcd_n16r64n4 -j8

Switch to the example project/build_xx directory, run uart_download.bat, and select the port as prompted to download:

$ ./uart_download.bat
     Uart Download
please input the serial port num:5

For detailed steps on compilation and downloading, please refer to the relevant introduction in Quick Start.

Expected Results

After the example starts up:

  1. The board can be discovered and connected by a mobile BLE APP, which can perform GATT characteristic read/write operations.

  2. The board can scan for other BLE devices, connect to them, discover their GATT database, and perform GATT read/write operations.

  3. The upgrade can be performed via the APP. You can confirm whether the upgrade succeeded through the following steps:

    a. First compile and flash a firmware build to the board as the original firmware before the upgrade.

    b. Open src/main.c, add the following line at the beginning of the main function, then save and recompile (recompiling is enough — do not flash it to the board again, otherwise the log would be printed before the upgrade):

    rt_kprintf("Upgrade succeeded\n");
    

    text

    c. Use the firmware recompiled in step b to build the HCPU upgrade package, then perform the upgrade via the APP. If the upgraded firmware prints “Upgrade succeeded” over the serial port at runtime, the upgrade succeeded.

Troubleshooting

Reference Documentation

Update History

Version

Date

Release Notes

0.0.1

07/2025

Initial version

No newline at end of right file.