DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

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.

Erich Styger user avatar by
Erich Styger
·
May. 08, 17 · Tutorial
Like (0)
Save
Tweet
Share
3.92K Views

Join the DZone community and get the full member experience.

Join For Free

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

  • GitHub repository
  • Batch Programming with J-Link
Firmware Flashing (cinematography)

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Key Considerations When Implementing Virtual Kubernetes Clusters
  • Integration: Data, Security, Challenges, and Best Solutions
  • Core Machine Learning Metrics
  • How Observability Is Redefining Developer Roles

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: