BL652 Over-the-Air (OTA) Updates using VSP Mode

Over-the-Air (OTA) updates are incredibly useful in applications where plugging in a cable is inconvenient or impossible. This is increasingly the case in IoT products with extremely small form factors. I’ve recently used the BL652 BLE Module from Laird in a number of projects. Laird’s SmartBASIC run-time engine supports Over-the-Air (OTA) updating of SmartBASIC applications. Here are my thoughts on getting it to work successfully.

BL652 Module

The BL652 is based on Nordic Semiconductor’s very popular nRF52832 SoC. At the heart of the nRF52832 SoC is an ARM Cortex-M4 32-bit processor. The nRF52832 can be programmed using the two-pin Serial Wire Debug (SWD) interface available on the ARM architecture. For developers with the appropriate knowledge level, hardware and inclination, this allows the BL652 to be operated with entirely custom firmware or with low level control over the Nordic Semiconductor SoftDevice running on the nRF52832.

SmartBASIC Applications and Run-Time Engine (Interpreter)

For many developers working on BLE applications, accelerated product development time and ease of use is more important than low level control. For those reasons, Laird developed the SmartBASIC programming language and associated run-time engine to execute SmartBASIC applications running on modules such as the BL652.

SmartBASIC is derived from the BASIC programming language. It is very easy to use with a simple code syntax. User applications written in SmartBASIC are anticipated to be “event driven”. This reflects the typical use case for BLE modules in embedded systems.

When the BL652 module is shipped by Laird, it comes pre-loaded with a SmartBASIC run-time engine. During module operation, this run-time engine interprets the user’s SmartBASIC code to execute the application.

For SmartBASIC application development and downloading, Laird provide a terminal emulator called UwTerminalX. UxTerminalX will be used to interact with the SmartBASIC run-time engine running in the BL652 module to download the user’s SmartBASIC application.

The SmartBASIC Core Functionality User Guide is a very thorough resource if you are interested in learning more about SmartBASIC.

Downloading SmartBASIC Applications to the BL652

The BL652 ships with the initial Production Release (v28.6.1.2) of its SmartBASIC run-time engine pre-programmed. Obviously, the user’s SmartBASIC application code is not pre-programmed on the module when it arrives. The user’s SmartBASIC application must be downloaded to the module. This can be done in many ways:

  1. Through the UART Interface (Serial Port) on the BL652.
  2. Through the SWD Interface on the BL652.
  3. Wirelessly “Over-the-Air” using the Virtual Serial Port (VSP) on the BL652.

During development (and in some product configurations), it is common to download the user’s SmartBASIC application to the BL652 module over its UART Interface. This is option 1 above. A computer (running UwTerminalX) or an embedded host processor communicates with the BL652 over a UART interface, i.e. through a serial port. This is the approach commonly used when working with the BL652 Development Kit (DVK-BL652).

In a production environment, option 2 in above list may be the most appropriate programming approach. It is possible to rapidly program the latest version of the SmartBASIC run-time engine and a user’s SmartBASIC application on to the BL652 in a single operation over the SWD interface.

Option 3 provides an interesting alternative to the first two options. Unlike the first two options listed above, this method does not require a physical connection between the programmer and the BL652 module to be programmed.

What is the Virtual Serial Port (VSP)?

The BL652 running the SmartBASIC run-time engine has a physical UART interface, i.e. serial port.

In SmartBASIC Interactive/Development Mode, this UART is used to interact with the SmartBASIC run-time engine using AT commands and to download a user’s SmartBASIC applications.

In SmartBASIC Run-Time Mode, this UART is available for use by the user’s SmartBASIC application, e.g. to communicate with a peripheral in the user’s product.

The Virtual Serial Port (VSP) provides similar functionality over BLE.

In VSP Command Mode, AT commands that are sent over BLE to a VSP Service running on the BL652 will be handled by the SmartBASIC run-time engine. The SmartBASIC run-time engine will send back appropriate responses to the AT commands. A SmartBASIC application can be downloaded to the BL652 wirelessly in VSP Command Mode. This is a very useful feature!

In VSP Bridge to UART Mode, data sent over BLE to a VSP Service running on the BL652 will be passed to the physical UART interface. For example, an app running on a smartphone (with a BLE interface) could communicate directly with a peripheral in the user’s product.

Further information on the Virtual Serial Port (VSP) is provided in the BL652 Datasheet and BL652 SmartBASIC Extensions User Guide.

Enabling VSP Command Mode

VSP Command Mode can be enabled at module power-up or reset.

To enable VSP Command Mode, the following conditions must be met:

  1. SIO_02 (Pin 23) must be externally driven or pulled high.
  2. SIO_13/nAutoRun (Pin 28) must be externally driven or pulled low.
  3. There must be no $autorun$ application present in the BL652 filesystem.

Condition 3 is subtle. Condition 2 states that the nAutoRun pin must be pulled low. Under those circumstances, if an $autorun$ file is present in the filesystem, it will load automatically and VSP Command Mode will not be enabled. The ERASEFILESYSTEM function can be used in a SmartBASIC application to erase an $autorun$ application, if required.

Below, using the nRF Connect for mobile app from Nordic Semiconductor, a BL652 is seen advertising in VSP Command Mode.

After the BL652 enters VSP Command Mode (through a module power-up or reset), it will advertise until a BLE connection is made or a timeout period elapses. The timeout period isn’t very long – less than a minute. The Device Name is always “LAIRD BL652”. The 6-byte Device Address (MAC Address) is different for each device.

BL652 Advertising in VSP Command Mode captured on nRF Connect App

For products incorporating the BL652, it is usually a good idea to permit external configuration of the SIO_02 and SIO_13 pins. To keep the required area, BOM cost and access to a minimum, this can be done with test points, jumper links, pull-up/pull-down resistors or miniature push buttons, as appropriate. An example implementation from a recent project that I worked on is shown below.

BL652 - SIO_02 and SIO_13 - Example Configuration

OTA Programming with the BL652 Development Kit

The BL652 Development Kit (DVK-BL652), shown below, can be used to wirelessly download SmartBASIC applications to a target BL652 module.

BL652 Development Kit (DVK-BL652)

Laird provide an explanation of how to use the BL652 Development Kit to program modules wirelessly in the OTA Loading of smartBASIC Applications – BL652 to BL652 Application Note.

Here, I will provide an alternative explanation based on the same approach.

Principle of Operation

When downloading SmartBASIC applications wirelessly between two BL652 devices, Laird’s Virtual Serial Port (VSP) BLE Service is used in both devices.

BL652 - OTA Programming - Principle of Operation

Development Kit BL652

The BL652 on the Development Kit operates in a pass-through mode. This is the use case for the VSP Bridge to UART Mode, described above.

The physical UART interface on this BL652 is connected to a PC running UwTerminalX. The BLE interface is connected to the BLE interface on the target BL652.

It receives data on its physical UART interface (from UwTerminalX) and transmits this data over its BLE interface. Similarly, it receives data over its BLE interface and transmit this data over its physical UART interface (to UwTerminalX).

In effect, AT Commands and Responses pass between UwTerminalX and the BLE interface.

The $autorun$.VSP.UART.bridge.outgoing.sb SmartBASIC application, available in the BL652 Sample Applications Library, implements the required functionality on the Development Kit BL652.

Target BL652

The target BL652 operates in VSP Command Mode (once configured to do so at power-up or reset).

The BLE interface is connected to the BLE interface on the Development Kit BL652. Data received from the BLE interface, typically AT commands, is handled by the SmartBASIC run-time engine. Data transmitted to the BLE interface, typically responses to AT commands, is generated by the SmartBASIC run-time engine.

BLE Interface Connection

For the Development Kit and target BL652 devices to communicate, a BLE connection needs to be established.

In VSP Command Mode, the BL652 behaves as a “server” awaiting connections. As the target device is operating in VSP Command Mode, the Development Kit device will need to act as a “client” and connect to the target device. This is reflected in the file name of the SmartBASIC application mentioned above, $autorun$.VSP.UART.bridge.outgoing.sb.

Connection Parameters

The Development Kit device needs to know what target device to connect to. For this reason, the Device Address (MAC Address) of the target device must be known. The Device Address can be determined in many ways. It may be convenient to use the nRF Connect for mobile app from Nordic Semiconductor to do so.

Before running the $autorun$.VSP.UART.bridge.outgoing.sb SmartBASIC application on the Development Kit, the Device Address of the target device must be updated in the application source code.

This is done in the line beginning with #define BTAddr. A seven-byte value is expected. The first byte indicates the address type and the remaining six bytes indicate the actual Device Address. A value of 0x01 for the first byte indicates a Random, Static Device Address. A value of 0x00 for the first byte indicates a Public (i.e. IEEE defined) Device Address.

For the SmartBASIC application to attempt to connect to the target device automatically, #define CONNECT_ON_STARTUP 0 should be changed to #define CONNECT_ON_STARTUP 1 in the application source code.

SmartBASIC Application Download

Once a connection has been established between the Development Kit and the target device, UwTerminalX can be used to interact with the target device in the usual manner.

The “XCompile + Load” command can be used to download a SmartBASIC application to the target device. The download speed may be slower than with a wired UART connection to the target device but given the convenience, the trade off is well worth it.

BL652 - OTA Programming - UwTerminalX Screenshot

About Me

I’m an experienced Electronic Engineer focused on Mixed-Signal Electronics, Embedded Systems and the Internet of Things (IoT).

Please contact me if you’d like to discuss how I can help bring your product to market, resolve existing product issues or provide relevant industry insights.

Podcasts for Electronic Engineers, Hackers and Makers

Podcasts are a great way of keeping up to date with what is happening in the fields of electronics and embedded systems. They also offer the opportunity to learn from the experiences of others in the wider technical community.

There are three podcasts that I listen to regularly. All three podcasts are well produced and frequently release new episodes. Each podcast has a slightly different focus – based mainly on the background of the hosts.

The Amp Hour

The Amp Hour is co-hosted by Dave Jones (EEVBlog) and Chris Gammell (Contextual Electronics). New episodes are released weekly.

Dave is based in Sydney, Australia and Chris is based in Chicago, USA. Despite having hosted well over 300 episodes together, the two only met in person quite recently when Chris dropped in on Dave down under!

Both Dave and Chris are hardware engineers. Naturally then, some of the most informative episodes have been hardware related.

Dave and Chris regularly interview guests on The Amp Hour. The two co-hosts have different but complementary interview styles, and this generally works quite well.

The guest list is enviable. As the podcast has a technical rather than business focus, the interviews with startup founders, CTOs, etc. are usually more engaging and open than one might expect.

Twitter:
The Amp Hour
Dave Jones
Chris Gammell

My Favourite Episodes:
#77 – An Interview with Dr. Howard Johnson – Winsome Waveform Wizardry
#196 – An Interview with Mike Engelhardt – SPICE Simulator Synteresis

Embedded.fm

As the name suggests, Embedded.fm is a podcast with a focus on Embedded Systems. Elecia White and Christopher White co-host the podcast and release a new episode on a weekly basis.

This podcast tends to have more of a focus (and expertise) on embedded software and algorithms than The Amp Hour. The two podcasts complement each other very well. Occasionally, the two shows hold crossover episodes.

Elecia and Christopher have a light-hearted and jovial interview style, but both can get right to the heart of the most technical matters in a very accessible manner. My ears perk right up any time a Kalman Filter is mentioned!

Elecia and Christopher run Logical Elegance – a California based consulting company.

Elecia is also the author of Making Embedded Systems: Design Patterns for Great Software.

Twitter:
Embedded.fm
Elecia White
Christopher White

My Favourite Episodes:
9: Kidnapped and blindfolded
53: Being a Grownup Engineer (with Jack Ganssle)

The Engineering Commons

The Engineering Commons tends to have a broader focus than either The Amp Hour or Embedded.fm podcasts. With multiple co-hosts and a focus on all aspects of engineering, conversations with multiple perspectives tend to evolve over the course of each show.

Episodes are released less frequently than that the other two podcasts – perhaps once or twice a month on average.

The broad range of topics covered on The Engineering Commons makes this podcast of great interest to anybody wishing to become a well-rounded professional engineer.

Twitter:
The Engineering Commons
Jeff Shelton
Carmen Parisi