rfWsnNodeExtFlashOadClient Example
Example Summary
The WSN Concentrator OAD (rfWsnConcentratorOad_CC1352R1_LAUNCHXL) and Node OAD (rfWsnNodeExtFlashOad_CC1352R1_LAUNCHXL) examples illustrate how to create a simple Wireless Sensor Network, where the Concentrator device listens for packets from the Nodes. These examples form a one-to-many network where the nodes send messages to the concentrator.
This example showcases the use of several Tasks, Semaphores and Events to receive packets, send acknowledgements and display the received data on the LCD. For the radio layer, this example uses the EasyLink API which provides an easy-to-use API for the most frequently used radio operations.
Refer to EasyLink API for more information on the EasyLink API.
Peripherals Exercised
Board_PIN_LED0
- Toggled when the a packet is sentBoard_ADCCHANNEL_A0
- Used to measure the Analog Light Sensor by the SCE taskBoard_PIN_BUTTON0
- Selects fast report or slow report mode. In slow report mode the sensor data is sent every 5s or as fast as every 1s if there is a significant change in the ADC reading. in fast reporting mode the sensor data is sent every 1s regardless of the change in ADC value. The default is slow reporting mode.
The example also supports Over The Air Update (OAD), where new FW can be loaded over OAD. There must be an OAD Server, which is included in the concentrator, and an OAD client which is included in the node. Furthermore the OAD client must have a BIM (Boot Image Manager) loaded as well to correctly manage OAD image changes.
This example can also be used with a BLE Factory image to complete BLE OAD of an Easylink image.
This example and any of its features will not work standalone without both the concentrator and the BIM. Follow the rest of this document to learn how to prepare and perform the example demos.
Resources & Jumper Settings
If you’re using an IDE (such as CCS or IAR), please refer to Board.html in your project directory for resources used and board-specific jumper settings. Otherwise, you can find Board.html in the directory <SDK_INSTALL_DIR>/source/ti/boards/<BOARD>.
Generating the required binary images for OAD
For generating the images the following tools are required:
CCSv7
https://processors.wiki.ti.com/index.php/Download_CCSsimplelink_cc13x0_sdk_1_60_00_xx
https://www.ti.com/tool/simplelink-cc13x0-sdkPython 2.7
Python intelhex-2.1
Python crcmod-1.7
To use this project it is required to have three images.
- rfWsnNodeExtFlashOad_CC1352R1_app.bin (generated from this project)
- rfWsnConcentratorOad_CC1352R1.hex
- bim_extflash_cc1352lp.hex
The prebuilt BIM binary is located in the hexfiles directory:
<SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/easylink/hexfiles/offChipOad/ccs/bim_extflash_cc1352lp.hex
The concentratorOadServer image can be created by following the README for the concentrator project
<SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/easylink/rfWsnConcentratorOadServer
Building the node binary file in CCS
- Import the CCS project into CCS(for more information consult the Examples Users Guide in the proprietary-rf documentation)
Add a post build step to create the OAD BIN. In Project->Properties->CCS Build, Steps Tab add the following post build steps:
${CG_TOOL_HEX} -order MS --memwidth=8 --romwidth=8 --intel -o ${ProjName}.hex ${ProjName}.out ${COM_TI_SIMPLELINK_CC13X2_SDK_INSTALL_DIR}/tools/common/oad/oad_image_tool --verbose ccs ${PROJECT_LOC} 7 -hex1 ${ConfigName}/${ProjName}.hex -o ${ConfigName}/${ProjName}
- Update the FW version number by changing the
SOFTWARE_VER
define in oad/native_oad/oad_image_header_app.c - For a bin image that needs programming through OAD (and not CCS or Uniflash) you need to define EXT_OAD_IMG
- build
The OAD bin will be generated in the Debug dir in the project, depending on step 7 this can be programmed via OAD or directly into flash with Uniflash. Note that when programming the .out file in CCS the application will run, but as the CRC is not set when rebooted the BIM will not boot the image. During development the JTAG_DEBUG define in the BIM can be used to avoid this issue.
Using the OAD example
To be safe the external flash of the Concentrator and the Node should be wiped before running the example. To do this, program both LP boards with erase_storage_offchip_cc13x2lp.hex. The program will flash the LED’s while erasing and once finished the LED’s will stop flashing. Allow the application to run until the external flash has been erased and the LED’s stop flashing.
The wipe flash FW can be found in below location and should be downloaded with Uniflash programmer: <SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/easylink/hexfiles/OffchipOad/ccs/erase_storage_offchip_cc13x2lp.hex
Using Uniflash, load the appropriate file(s) onto the CC1352R1_LAUNCHXL board.
- CC1352R1_LAUNCXL A - load the concentrator image you built. Prebuilt image located here
<SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/easylink/hexfiles/offChipOad/ccs/rfWsnConcentratorOad_CC1352R1_868.hex
- CC1352R1_LAUNCHXL B - load the node application image you built. Prebuilt image located here
<SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/easylink/hexfiles/offChipOad/ccs/rfWsnNodeExtFlashOad_CC1352R1_868_app_v1.bin
and then load the bim<SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/easylink/hexfiles/offChipOad/ccs/bim_extflash_cc1352lp.hex
Connect CC1352R1_LAUNCHXL A (concentrator) and CC1352R1_LAUNCHXL B (node) to the USB of a PC.
The Concentrator will display the below on the UART terminal when Nodes start sending data:
Nodes Value SW RSSI
0x0b 0887 0 -080
0xdb 1036 0 -079
0x91 0940 0 -079
*Action: Update available FW
Info: Available FW unknown
cmd:
The Nodes will display the following once the 1st sensor reading has been sent (after 10s of booting):
Node ID: 0x95
Node ADC Reading: 0012
The new node image for OAD can be loaded into the external flash of the Concentrator using the oad_write_bin.py script. The action must first be selected using BTN-2. Press BTN-2 until the Action is set to Update available FW
, then Press BTN-1 and Press BTN-2 to execute the action. The terminal will display:
Waiting for Node FW update...
The image is loaded into the external flash using the UART. Therefore, the UART terminal must first be closed to free the com port. After the com port is free, run the python script:
cd <SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/easylink/hexfiles/offChipOad/ccs
python ../../../../../../../tools/easylink/oad/oad_write_bin.py /dev/ttyS28 rfWsnNodeExtFlashOad_CC1352R1_868_app_v2.bin
After the download the UART terminal can be re-opened and the “Available FW” will be updated to reflect the new FW.
The current FW version running on the node can be requested using the Send FW Ver Req
action. This is done by pressing BTN-1 until Action
is selected. Then press BTN-2 until the Action is set to Update available FW
, The Press BTN-1 until intended device is selected. Press BTN-2 to execute the action.
The next time the node sends data it will respond and the FW version will be displayed:
Nodes Value SW RSSI
0x0b 0887 0 -080
0xdb 1036 0 -079
*0x91 0940 0 -079
Action: Update available FW
Info: Node 0x91 FW sv:0001, bv:01
Where:
sv
is the FW version numberbv
is the version number of the BIM
The FW running on the nodes can now be updated to the available FW on the concentrator. The Action
must first be selected using BTN-1. The Press BTN-2 until the Action is set to Update node FW
, and Press BTN-1 until the intended device is selected. Press BTN-2 to execute the action.
The next time the node sends data it will respond to the FW update request and start requesting OAD blocks. The display is updated as the OAD blocks are sent:
Nodes Value SW RSSI
0x0b 0887 0 -080
0xdb 1036 0 -079
*0x91 0940 0 -079
Action: Update available FW
Info: OAD Block 14 of 1089
Once the OAD has completed the node will reset to the BIM (if not you may need to do a manual reset). After resetting the node will be shown on the concentrator with a new node ID. A FW version request can be performed to verify that the OAD has completed successfully and FW version 2 is running:
Nodes Value SW RSSI
0x0b 0887 0 -080
0xdb 1036 0 -079
*0xe2 0940 0 -079
Action: Update available FW
Info: Node 0x91 FW sv:0002, bv:01
BLE OAD of an Easylink Image
When the LEFT Button is held down and a reset occurs (RESET Button or cord unplug/plug in) the rfWsnNodeExtFlashOad project will perform the markSwitch function that invalidates itself as a bootable image candidate and performs a soft reset of the device. This will cause the BIM to boot up like normal, however, when the BIM checks to see if the image that is currently in internal flash (Easylink rfWsnNodeExtFlashOad) it will see that the image is no longer valid. This will cause the BIM to copy the current Factory Image that is stored in External Flash to Internal Flash and perform a soft reset. Now when the BIM boots up again, the current running image (Factory Image) will be valid and the BIM will let the current image start execution.
In order for this functionality to be useful however, one first needs to have a Factory Image saved into External Flash. Luckily, when the BIM boots up and there is no current Factory Image and the current internal image is valid, a copy of the current internal image will be made effectively creating a backup of the current image. This is useful, but will not provide any special functionality other than redundancy. Instead you can first flash the LP with the BLE Simple Peripheral OAD application and BIM so that it creates a backup of that image. Then using BLE OAD send the Easylink Image to the LP. Now, whenever you want, you can switch to the Factory Image and upgrade to any image you want.
To achieve this demo you will need at least two 13X2 LaunchPads.
Using Uniflash load <SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/ble5/hexfiles/ble5_host_test_cc13x2r1lp_app.hex
into a CC1352R1_LAUNCHXL A
Using Uniflash load <SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/ble5/hexfiles/oad/ble5_simple_peripheral_oad_offchip_cc13x2r1lp_app_FlashROM_Release_oad.bin
onto CC1352R1_LAUNCHXL B
Using Uniflash load <SDK_DIR>/examples/rtos/CC1352R1_LAUNCHXL/ti154stack/hexfiles/oad/bim_offchip_cc13x2lp.hex
onto CC1352R1_LAUNCHXL B as well.
Open up Btool which can be found in
<SDK_DIR>/tools/ble5stack/btool
and select port corresponding to CC1352R1_LAUNCHXL A. All other Serial Port Settings should be left at the defaults. Now Select the Scan
button in the GUI and when the scan has completed Establish
a connection with the CC1352R1_LAUNCHXL B’s BLE Address. **Note that the BLE Address can be seen by looking at UART output of the CC1352R1_LAUNCHXL B or by using Uniflash->Settings & Utilities->Read Primary BLE Address
When the connection has been established you can now switch over to the Over The Air Download
tab in the top left hand corner of the GUI.
Now select Read Image File
and navigate to the 13x2 Easylink rfWsnNodeExtFlashOad image you created earlier. Make sure to select the OAD To External Flash
check box and the Send
the image.
When the OAD has completed, CC1352R1_LAUNCHXL B will boot up into the new rfWsnNodeExtFlashOad image and you can perform native OAD as described above in this document. When the time comes you would like to switch back to the BLE Factory Image that was saved into the External Flash simply hold the LEFT button and reset the device.
CC1352R1_LAUNCHXL A will now boot into the BLE Simple Peripheral OAD image again and you can repeat the process as much as you’d like!
Application Design Details
This examples consists of two tasks, one application task and one radio protocol task. It also consists of a Sensor Controller Engine (SCE) Task which samples the ADC.
On initialization the CM3 application sets the minimum report interval and the minimum change value which is used by the SCE task to wake up the CM3. The ADC task on the SCE checks the ADC value once per second. If the ADC value has changed by the minimum change amount since the last time it notified the CM3, it wakes it up again. If the change is less than the masked value, then it does not wake up the CM3 unless the minimum report interval time has expired.
The NodeTask waits to be woken up by the SCE. When it wakes up it toggles
Board_PIN_LED1
and sends the new ADC value to the NodeRadioTask.The NodeRadioTask handles the radio protocol. This sets up the EasyLink API and uses it to send new ADC values to the concentrator. After each sent packet it waits for an ACK packet back. If it does not get one, then it retries three times. If it did not receive an ACK by then, then it gives up.
RadioProtocol.h can also be used to change the PHY settings to be either the default IEEE 802.15.4g 50kbit, Long Range Mode or custom settings. In the case of custom settings, the smartrf_settings.c file is used. This can be changed either by exporting from Smart RF Studio or directly in the file.
References
- For more information on the EasyLink API and usage refer to SimpleLink-EasyLink.