UART DFU - Upgrading BGM111 by EFM32PG example

by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero Employee</font></font> </a> Kevin_Fu on ‎01-17-2017 12:52 AM
  1. Introduction and preparations

This article demonstrates how to use an external MCU to upgrade devices under NCP mode, it aims at providing a base code, which is as simple as possible, to make it can be easily migrated to the real use case. Before starting with this sample code, please have a look at the below resources.

Please go through above resources first, it could be a good starting point, you can get many information such as how to generate ebl file, how to do a simple DFU and verify it.

 

  1. Environments

SDK – Simplicity Studio v4 and Bluetooth Smart SDK v2.1.1

Kits – EFM32PG(SLSTK3401) acts as NCP HOST and BGM111v2(WSTK6101) acts as NCP TARGET

Serial configuration

Baud rate: 115200

Data bits: 8

Stop bit: 1

Flow control: False

  1. Connection and peripherals

Both kits are powered by USB. The connection between them is shown as below table.

Expansion header(EFM32PG)

Expansion header(BGM111v2)

GND

GND

PIN9(PD10) – UART TX

PIN14(PA1. UART_RX)

PIN11(PD11) – UART RX

PIN12(PA0. UART_TX)

 IMG_4001.JPG

The peripherals used by this sample code are shown below.

EFM32PG

Functionality

BGM111

Functionality

UART1

BGAPI

UART1

BGAPI

UART0

Print debug information to USB-UART port

 

 

 

  1. Getting started with the sample code

There are 2 projects in the sample code, UART_DFU_PG and ncp-empty-test. Import them to your SSv4. Note that both projects are based on the IAR 7.8 compiler, if the default importing setting is GNU, please change to IAR manually.

Below is the step by step instruction to upgrade the device name, which is the simplest way to demonstrate UART DFU.

  • Download the ncp-empty-test project to your BGM111v2 kit, the default device name is “BLE_DEVICE”. Note that this project is not the same as the example project, and the difference is the bootloader. The default bootloader supports OTA DFU, we need to change it to support UART DFU. The source code of bootloader is located at C:\SiliconLabs\SimplicityStudio\v4\developer\stacks\ble\v2.1.1.0\protocol\bluetooth_2.1\ble_stack\bootloader

There will be a detailed description on the bootloader in the UART DFU application note, so I won’t spend much words on describing it. The only thing you need to do is modifying uart_config.h file to fit your own uart setting, then build and binbootloader.o will be generated in the Exe folder.Modify the project setting to use the new bootloader instead of the default one. See below picture.QQ图片20170105170353.png

 

  • Open ‘ncp-empty-test.isc’ to modify the device name, then save and click ‘Generate’ button. Build the project and double click the ‘create_ebl_files.bat’ file which is located in your project explorer. The output_ebl folder will be generated automatically. Also, you can directly use the files in output_ebl since they are generated previously with the device name “OTA_DONE10”.

QQ图片20170105154703.png

  • In the UART DFU host example, the ebl file is read as stream and directly sent to the NCP target without any modification. So we can make a copy of them and modify the file suffixes to .bin such as stack.ebl to stack.bin.
  • Open stack.bin with editor, record its size. Open the main.c of UART_DFU_PG project, modify the variable ‘eblSize’ to the size of your bin file. See below picture.

QQ图片20170105160512.pngQQ图片20170105160531.png

  • You can get the flash size of UART_DFU_PG project by looking into the map file or open the output file by editor. If you don’t modify anything of the sample code, the flash size used should be 0x1D48, which is the sum of readonly code memory and readonly data memory of the map file.
  • Open Simplicity Commander, program the stack.bin file into your PG kit with starting address larger than the flash size used by UART_DFU_PG, for example, 0x6800 in the sample code. Please make sure the sum of this starting address and the bin file size doesn’t larger than the whole flash size of EFM32PG(256K). Then modify the symbol “EBL_FILE_START_ADDRESS” in main.c to your setting value. See below pictures.

QQ图片20170105161933.pngQQ图片20170105161849.png

  • To make sure you can get the debug information correctly, you probably need to add "#define RETARGET_VCOM" to the file retargetserialconfig.h which is located in the Includes folder of the UART_DFU_PG project. Program the UART_DFU_PG project into your PG kit by clicking 1.png. To avoid losing the debug information, please set up the serial terminal before running the host program. Note that the serial terminal should be connected to the PG kit, NOT BGM111. Click 2.png, wait for DFU finished. Then you can connect to the device to verify the device name changes or not, which can indicate if the upgrading really takes effect or not. Because of the cache of smartphone, you probably need to connect and disconnect once to get the new device name. See below picture.

 UART_DFU.png

  • Repeating the above steps can also be used for app.ebl upgrading, or full.ebl.