Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Flashing and Restoring the Hexiwear Firmware

DZone's Guide to

Flashing and Restoring the Hexiwear Firmware

So, you blew up your KW40 BLE's firmware. It happens. Well, grab a J-Link and head over to GitHub. Let's roll up our sleeves and restore your firmware.

· IoT Zone
Free Resource

Build an open IoT platform with Red Hat—keep it flexible with open source software.

The Hexiwear is a great and versatile device with two microcontrollers on it. Developing firmware on a Hexiwear means changing what was originally on it. And sometimes it happens that I’m not sure if the changes are for good. Or that I accidentally destroyed the firmware on the NXP Kinetis KW40 BLE microcontroller :-(. So I had to find a way to restore the original firmware, and this is what this post is about.

Restoring the Hexiwear Firmware with a Segger J-Link

Restoring the Hexiwear firmware with a Segger J-Link

Because there is no way to rebuild the KW40 firmware (it requires proprietary tools and closed source (library) files), I had to find a way how to re-flash the firmware without the need to rebuild the binaries.

The OpenSDA circuit on the Hexiwear docking station did not work well for me (slow and sometimes failed), so I have used both P&E Multilink and Segger J-Link to program the Hexiwear. That was another reason to build our own docking station, see Prototype of a tiny Hexiwear Docking Station).

In this article, I use the Segger J-Link, as its scripting capabilities make it easy to batch program multiple units: not only for restoring the firmware, but also to program our custom firmware on multiple devices.

To program the binary files, I’m using the J-Link application with a batch file (.bat) and a J-Link Script file (.script):

Script Files

Script files

Binaries

The Segger J-Link accepts binary (bin) files. See Binary (and S19) Files for the mbed Bootloader with Eclipse and GNU ARM Eclipse Plugins for more on creating binary files.

The original binaries from MikroElektrtronika are available on GitHub. There are two binaries, one for the NXP Kinetis K64F and one for the NXP Kinetis KW40:

Hexiwear Images on GitHub

Hexiwear images on GitHub

For restoring the K64F binary, the following DIP switch settings are used:

  • MK64F: both switches in the ON position
  • MKW40: both switches in the OFF position
  • OSDA: OFF (disabled)
Hexiwear DIP Switch Settings for restoring K64F Binary

Hexiwear DIP switch settings for restoring K64F Binary

The batch file has the following content, with a variable pointing to the JLink executable:

REM *******************************************************
REM * Batch file to program a bin file with Segger J-Link *
REM *******************************************************
 
SET JLINK="C:\Program Files (x86)\SEGGER\JLink_V612\JLink.exe"
 
%JLINK% -device MK64FN1M0xxx12 -CommanderScript ./jlink_k64f.script
pause


The above batch file calls the J-Link script jlink_k64f.script , which does the programming with the binary file:

si swd
speed 4000
r
h
loadbin "HEXIWEAR_MK64.bin",0
r
exit


To program the K64F device, run the batch file ProgrammWithJlink_K64F.bat.

Restoring the KW40 Binary

For restoring the K64F binary, the following DIP switch settings are used:

  • MK64F: both switches in the OFF position
  • MKW40: both switches in the ON position
  • OSDA: OFF (disabled)
Hexiwear DIP Switch Settings for restoring KW40 Binary

Hexiwear DIP switch settings for restoring the KW40 binary

The batch file has the following content, with a variable pointing to the JLink executable:

REM *******************************************************
REM * Batch file to program a bin file with Segger J-Link *
REM *******************************************************
 
SET JLINK="C:\Program Files (x86)\SEGGER\JLink_V612\JLink.exe"
 
%JLINK% -device MKW40Z160xxx4 -CommanderScript ./jlink_kw40.script
pause


The above batch file calls the J-Link script jlink_kw40.script which does the programming with the binary file:

si swd
speed 4000
r
h
loadbin "HEXIWEAR_KW40.bin",0
r
exit


To program the KW40 device, run the batch ProgrammWithJlink_KW40.bat file.

With the presented approach, I can easily restore the original firmware or program multiple Hexiwears (or other devices) with a new firmware. You can change the script and batch files for your needs, as they are available on GitHub too.

Happy restoring!

Links

Download Red Hat’s blueprint for building an open IoT platform—open source from cloud to gateways to devices.

Topics:
iot ,firmware ,j-link ,hexiwear ,tutorial

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}