Standalone and Command Line Programmer with MCUXpresso

The MCU-Link is a $10 CMSIS-DAP capable debug probe which works out-of-the box with the MCUXpresso Eclipse based IDE. This is great for development, but how can I programming with the push of a button or a script? The answer is no: there is an easy way to use the debug probe outside Eclipse from a shell script, and you can use that MCU-Link probe to do the job. This is especially useful as with the example below where I have to program 60 boards this week-end :-).

Programming Boards with MCU-Link using command line

Batch Programming Boards with MCU-Link

Outline

The idea is to use the existing infrastructure: no need to install extra plugins, no need to mess up with installing other frameworks or programming languages. Simply use what I already have installed.

Preconditions

I’m using the NXP MCUXpresso IDE V11.2.1 with the MCU-Link debug probe. You should have a project with a working debug launch (.launch) configuration.

Command Line

Double-click on .launch file to edit it. This opens the settings. Go the ‘GUI Flash Tool’ and turn on ‘Preview command’:

Preview Command

Preview Command

This will trigger a dialog with the command line used for the flash tool. Apply the settings and close the dialog.

With the project selected, use the desired operation, for example programming the flash:

Program Flash Action

Program Flash Action

Another way is to get the command/script from the GUI Flash Tool:

GUI Flash Tool

GUI Flash Tool

This is useful for example to program a binary file (see Using Eclipse to Program Binary Files to an Embedded Target ):

Preview Command for programming a bin file

Preview Command for programming a bin file

This now opens a preview dialog:

Preview of Command

Preview of Command

The beauty of this is that I don’t have to find the correct parameters, the settings of the device or other complicated steps to get the job done: It is basically using what I have used to program the board during development, but as command line script :-).

Select the shell script to be used:

shell script selection

shell script selection

Then copy the script to the clipboard:

Copy script to the clipboard

Copy script to the clipboard

Store the content to a script/batch file:

batch file

batch file

I noticed a problem if the workspace folder has spaces. Because the path variable is double-quoted and the string combination is double-quoted too, it leads to a wrong path:

double quoted paths

double quoted paths

What I did was removing the double-quotes from the variables in my script.

Finally run the script from the command line shell:

running script

running script

That way I can easily program a larger batch of my boards without the need to run Eclipse or a GUI.

Summary

The MCUXpresso IDE already has everything built-in to provide standalone programming from the command line shell. I get the script files from the IDE and then can use and tweak them in my scripting environment. This does not only work for the MCU-Link, but any supported debug probe such as the P&E Multilink and the SEGGER J-Link. So that way I can easily do a batch programming of many boards. If tapping more into a production environment, I recommend that you have a look at the Cyclone solutions from PEMicro or the SEGGER Flasher, as that way you even don’t need a host PC.

Happy flashing đŸ™‚

Links

11 thoughts on “Standalone and Command Line Programmer with MCUXpresso

  1. Pingback: OpenOCD with MCU-Link | MCU on Eclipse

  2. Thanks Erich
    This seems to work fine for me from the command line but I do get the following error (?) message right at the end, should I be worried about it?

    regards Nick

    ……….
    Nc: Sectors written: 4, unchanged: 0, total: 4
    Nc: Closing flash driver MIMXRT1060_SFDP_QSPI.cfx
    Nt: Loaded 0x330F0 bytes in 4028ms (about 51kB/s)
    Nt: Reset target (system)
    Nc: Starting execution using system reset
    Nc: state – running or following reset request – re-read of state failed – rc Nn(05). Wire ACK Fault in DAP access
    Xw:
    Nc: error closing down debug session – Nn(05). Wire ACK Fault in DAP access

    Like

  3. Hi Erich, I was just using an MCU LINK and the above command line method to update some boards, and worryingly after a few program cycles one of the boards became bricked. I was able to recover the board by using Jay Hengs MCU BOOT to erase the flash, but this is very concerning! Are there any known issues with either the MCU LINK itself or the above method that might cause this to happen? Many thanks, Nick

    Liked by 1 person

    • I’m not aware of any issues. But what I had in the past (independent of MCU-Link) is that you have to make sure the power supply to the board while programming must be solid. I had faced issues in the past with this if there were some brown-outs.

      Like

  4. Just wanted to leave a note of appreciation. I’m working on a tester/programmer for a KL27 based device (DIY project) and this guide helped me leap forward in the process automation.

    Many thanks!
    Jiri N.

    Like

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.