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 :-).
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’:
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:
Another way is to get the command/script from the GUI Flash Tool:
This is useful for example to program a binary file (see Using Eclipse to Program Binary Files to an Embedded Target ):
This now opens a preview dialog:
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:
Then copy the script to the clipboard:
Store the content to a script/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:
What I did was removing the double-quotes from the variables in my script.
Finally run the script from the command line shell:
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
- MCU-Link Debug Probe: New MCU-Link Debug Probe from NXP
- Community discussion: https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-tool-SWD-JTAG/m-p/1183765
- Debugging LPC in command line mode: https://community.nxp.com/t5/MCUXpresso-General/Debug-LPC54628-in-command-line-using-linkserver-and-gdb-without/m-p/846003
- Using command line tool: https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/Using-the-command-line-flash-programming-tool/m-p/474743
- Using Eclipse to program binaries: https://mcuoneclipse.com/2017/05/06/using-eclipse-to-program-binary-files-to-an-embedded-target/
Handy article Erich – thanks. I’ve used this approach before and the operation is nice and fast.
FYI to your readers – Flash Magic from EmSA (free to use for non-production use, small license fee for production) also supports MCU-Link now: https://www.flashmagictool.com.
LikeLike
Hi Brendon,
thanks for the reference to Flash Magic!
Erich
LikeLike
Pingback: OpenOCD with MCU-Link | MCU on Eclipse
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
LikeLike
Ni Nick,
Yes, I have seen the LinkServer connection rather frequently reporting this ‘Wire ACK Fault’ messages. I’m not sure what is causing them, basically I think it has lost the debug connection (maybe due clocking?).
Are you saying the application has been flashed correctly and runs correctly?
LikeLike
Yes, the application has flashed correctly.
LikeLike
So then it is not that bad. Somehow simply the debugger got confused and disconnected after the programming.
LikeLike
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
LikeLiked 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.
LikeLike