Flashing and Restoring the Hexiwear Firmware

The Hexiwear device 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.

Segger J-Link

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 Multilinks and Segger J-Links to program the Hexiwear. That was another reason to build our own docking station, see “Prototype of tiny Hexiwear Docking Station“).

In this article I use the Segger J-Link as its scripting capabilities makes it easy to batch program multiple units: not only for restoring the firmware, but as well 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” how to create binary files.

The originally 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

Restoring the K64F Binary

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 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 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.

Summary

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

Happy Restoring 🙂

Links

Advertisements

18 thoughts on “Flashing and Restoring the Hexiwear Firmware

  1. Pingback: Reprogramming the Mikroelektronika Hexiwear Dockingstation | MCU on Eclipse

  2. Hey Erich!

    I too destroyed the KW40Z firmware and I’m having some trouble restoring it to the initial state.
    I tought I could just drag and drop the default firmware binary into the DAPLINK interface from the docking station, but when I try to do so, if I connect it with the Hexiwear on, and KW40Z switches on, it shows up in Manteinance Mode.
    To get around this I power it with all the switches except the OpenSDA switch off, so it comes up as DAPLINK, and then put the KW40Z switches on and copy the binary to DAPLINK. After doing this, the HID disconnects and connects back on, coming back with a FAIL.txt file that reads “The transfer timed out.”
    Any idea of how i can fix this?

    Thanks for your help

    Jaime

    Like

  3. Hey Enrich,

    I want to restore KW40 code for hexiwear. As per mentioned method, I didnt find ” jlink_kw40.script ” in my project to make changes. Also please help in making connection of J-LINK (EDU) with Hexiwear doking station.

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s