Need help getting STLINK talking to/programming an SKR1.4T 3D Printer CPU

Yeah okay the problem is that it definitely doesn’t like reset_config none seperate as an argument, and thinks those are seperate flags – -c needs that as one string arg.

Remove these two lines in the platformio.ini file and retry. If openocd cannot reset the board, edit the python script

to say

UPLOADCMD="$UPLOADER $UPLOADERFLAGS -c \"reset_config none separate\""

Max - tried your throughs and no mater what I use, I get “unexpected command line argument. In the following example, I set UPLOADERFLAGS = [”-c", “exit”] and still no joy.

Building in release mode
Checking size .pio\build\LPC1769\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [======    ]  59.0% (used 19304 bytes from 32736 bytes)
Flash: [=====     ]  47.7% (used 226676 bytes from 475136 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, custom, jlink, mbed
CURRENT: upload_protocol = custom
Uploading .pio\build\LPC1769\firmware.bin
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Unexpected command line argument: reset
*** [upload] Error 1

Also tried just program, just verify, just reset, just shutdown and all gave me command line errors argument errors. It is as through the Stlink command set (what ever that is) is not available or wasn’t initialized in openocd. I’m about ready to throw in the towl with this approach and toss this ‘bricked/not upgradable’ SKR board. It appears that this approach is ‘above my pay grade’ Thanks for trying.

Watching this. Same exact scenario here. Hoping for the best!

@Ed-EE-Eng Do you need to put 3.3v on ISP BOOT to get that to work? If so, are you just adding a jumper over R28?

Actually I think this is where it wrongly read reset as a seperate argument. Somehow it must be changed so that the commandline says openocd [..] -c "program {{$SOURCE}} verify reset; shutdown" and not openocd [..] -c program {{$SOURCE}} verify reset; shutdown. Verify that this is happening with pio run -t upload -v to see the used openocd invocation.

This thread is relevant to me. I want to debug the firmware but instead of using STLINK or hardware debugger. Is it possible to use USB interface? I just want to step into the main Marlin program.

No, you will need a SWD debugger of some kind for this, e.g. a JLink or STLink or BMP. Without that, one would need a GDB stub running as part of the firmware to communicate with the GDB client on the PC, but no such implementation exists to my knowledge.

Thank you Max for your response.

I have ordered STLink. Is there any tutorial where I can setup STLink with PIO and SKR 1.4Turbo using Marlin? Please note that SKR 1.4 Turbo is LPC1769 based.

Sadly a few have tried as can be in read this thread, but none succeded finally.

In theory all it needs is that a SWD probe, like an ST-Link, is connected to the target microcontroller via the SWD connections (SWDIO, SWDCLK, GND), then OpenOCD should be able to establish a connection to it for flashing + debugging, at which point it is ‘just’ a matter of teaching PlatformIO to do the correct OpenOCD invocations.

I’ll read up on the thread again and prepare an example with which some things can be tried.

Thank you Max.

Yes, this thread is there but i think “teaching PlatformIO to do the correct OpenOCD invocations” is little bit murky to me.

I will be looking forward for your example. Meanwhile I am waiting for my STLINK.

I think folks from Bigtreetech or Marlin should also share how they use to debug when developing SKR 1.4Turbo :slight_smile:

I’ve read up on the thread and decided to do some updates to the example and my forked version of the nxp platform code. For me it now looks like building works, and upload and debug is attempted with the right commandds (it uses pyocd at the moment).

Please try and clone the example GitHub - maxgerhardt/pio-nxp-lpc1769-arduino-test: Simple project for testing Arduino support on the NXP LPC1769 chip using a custom platform., then build and upload it. The project is preconfigured for the cmsis-dap (that an ST-Link is compatible with) type upload and debugging. Let’s get a normal upload + LED blinky working first.

Sidenote: If PyOCD says that it can’t find a connected debug probe and you’re using Windows, you will need to install libusb for Python (copying of a libusb-1.0.dll file in the Python installation directory).

Sidenote 2: The SWD pins on the board can be found per this.

1 Like

Will try the example. It will take few days for the STLINK to ship. Will update once I try.

I was wondering, since the SKR 1.4T board is already talking to the PC(Windows) thru USB, there should be some way to use the USB interface directly (instead of going thru the STLINK) to activate the debugging.

Hi Max,

For SWD connection with SKR 1.4Turbo, please confirm if I only need to connect SWDIO, GND and SWCLK pins of STLINK-V2(pin 7,8,9) with SKR 1.4Turbo only?

Thanks.

Never mind, i was able to figure it out.
pin 1 of STLINK to 3.3V of SKR 1.4 Turbo
pin 7 to SWDIO
pin 8 to GND
pin 9 to CLK
pin 15 to RST.

Max, I was able to get your “pio-nxp-lpc1769-arduino-test” working in debug mode.

Let me know what all modifications to make to get the debug working for Marlin FW.

Thanks.

Actually, creating a forked platform versions and adding cmsis-dap support via the Python code may have been overkill. The board already declares cmsis-dap debugging support via pyOCD, so the should do the same as my modified platform.

Just try and change to the Marlin envirnoment for your LPC1769 board with the switcher and press the debug button. It should start to invoke PyOCD. Does that just work?

In fresh Marlin repo from git, I added below lines in platformio.ini in [common_LPC].


debug_tool = cmsis-dap

;debug_tool = custom

debug_server =

openocd

-f

../scripts/interface/stlink.cfg

-f

../scripts/target/lpc17xx.cfg

The debug is launching but it fails to put a break point.


PlatformIO Unified Debugger → Redirecting...

PlatformIO: debug_tool = cmsis-dap

PlatformIO: Initializing remote target…

GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:42)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.org/doc/doxygen/bugs.html

Info : auto-selecting first available session transport “hla_swd”. To override use ‘transport select ’.

Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD

adapter speed: 10 kHz

adapter_nsrst_delay: 200

Info : tcl server disabled

Info : telnet server disabled

Info : clock speed 10 kHz

Error: read version failed

2

.pioinit:13: Error in sourced command file:

Remote communication error. Target disconnected.: Success.


What happens if you do not modify it in any way and just press the debug button? It should use pyocd.

Hi Max,

I first tried with how you asked. So, I opened my Marlin project in the same Visual Studio Code(thru PIO) where “pio-nxp-lpc1769-arduino-test” was launched in debug mode. Then I switched to Marlin project and clicked debug. The breakpoint happened in “pio-nxp-lpc1769-arduino-test” instead of happening in Marlin.

I am not fully aware of how “switcher” works and could be making some mistake while I switch between projects.

Ok looks good with Marlin. The Marlin program is going into the debug mode.

I am not sure what is the “Segmentation Fault”. The debug does not stop at breakpoint which is set in MarlinCore.cpp. Any idea why it is not going in the MarlinCore.cpp breakpoint?