PIO debugger won't work in VSCode

I have a problem starting the debugger. I am running VSCode with PIO, both updated.
I am trying to debug code for RISC-V board HiFIve 1 rev b
this is the errors i get

Connecting to J-Link...

Reading symbols from c:\Users\ialek\Documents\PlatformIO\Projects\superBlink\.pio\build\hifive1-revb\firmware.elf...
undefinedC:\Users\ialek\.platformio\packages\toolchain-riscv\bin\riscv64-unknown-elf-gdb.exe: warning: Couldn't determine a path for the index cache directory.

PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...
.pioinit:14: Error in sourced command file:
:2331: No connection could be made because the target machine actively refused it.
1 Like

So how exactly did you connect the debugger to the target board?

I have to connect the debugger to the board?
This is my first time working on a board so i dont know. I was just following a tutorial online and he ran debugger without connecting the board. I obviously tried connecting it.

Oh actually the debugger is supposed to be on-board. So, I currently donā€™t know why that is. Maybe someone with the hardware (HiFive1 Rev B) can help here to test it (@valeros, @ivankravets)?

1 Like

Could you navigate to C:\Users\ialek\.platformio\packages\tool-jlink\Drivers and install Windows drivers for J-Link?

JLink installed, but the debugger still wonā€™t work. At the end the board disconnects from computer and connects back in. Sorry for the problems, learning this the first time so not quiet sure what I am doing wrong. This is all running on Windows by the way.
I am following this tutorial

https://www.youtube.com/watch?v=Xmes__VpfiA&list=PL6noQ0vZDAdh_aGvqKvxd0brXImHXMuLY&index=8

ERROR: Can not read register 4096 (X0) while CPU is running
ERROR: Can not read register 4096 (X0) while CPU is running
indent preformatted text by 4 spaces
Program
received signal SIGTRAP, Trace/breakpoint trap.
0xdeadbeef in ?? ()
WARNING: CPU could not be halted
ERROR: Communication timed out: Requested 4 bytes, received 0 bytes !
Could not start CPU core. (ErrorCode: -1)
WARNING: Target connection lost.

What is your platformio.ini?

Hello,
What exactly do you mean by your advise? I have downloaded the complete support package for J-Link from Segger and I installed it sepparately. In my case I have no folder ā€œtool-jlink\Driversā€ under .platformio\packages.

^^ Does PlatformIO need to see/use this folder?

(Iā€™m getting the same error as Ivan_Aleksyeyenko on trying to debug Marlin SW on MKS_Sbase board)
Thanks
dzejaar

@dzejaar Are you on Windows also? I just checked on Linux, and thereā€™s no ~/.platformio/packages/tool-jlink/drivers folder here eitherā€¦ so it is probably specific to the Windows tool-jlink package. If youā€™re on Windows, and that folder is missing (%userprofile%\.platformio\packages\tool-jlink), it suggests the tool-jlink package wasnā€™t installed properly. You can delete the folder tool-jlink folder, and PlatformIO will re-install it.

If youā€™ve installed the drivers separately, that should be fineā€¦ it just means you have gotten past the initial error ā€¦ basically that the programmer could not be detected. Since youā€™ve gotten to the same error as @Ivan_Aleksyeyenko, maybe you can show the contents of your platformio.ini so that can be checked?

I wonā€™t be able to help much more as Iā€™m not familiar with this hardware.

@pfeerick Yes, Iā€™m on Win10. I didnā€™t get the point about missing folder probably: The folder %userprofile%\.platformio\packages\tool-jlink is not existing, hence I canā€™t delete it and PIO is not willing to re-install it (Iā€™m trying to find workaround for couple of days and there were lot of restarts of PIO as well of Windows).

Here the related part of my platforio.ini :

[platformio]
src_dir      = Marlin
build_dir    = .pioenvs
lib_dir      = .piolib
libdeps_dir  = .piolibdeps
boards_dir   = buildroot/share/PlatformIO/boards
default_envs = LPC1768

[common]
default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
extra_scripts = pre:buildroot/share/PlatformIO/scripts/common-cxxflags.py
build_flags = -fmax-errors=5 -g -D__MARLIN_FIRMWARE__
lib_deps =
U8glib-HAL=h??ps://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip
[LiquidCrystal@1.3.4](mailto:LiquidCrystal@1.3.4)
TMCStepper@>=0.5.0,<1.0.0
Adafruit [NeoPixel@1.2.5](mailto:NeoPixel@1.2.5)
LiquidTWI2=h??ps://github.com/lincomatic/LiquidTWI2/archive/master.zip
Arduino-L6470=h??ps://github.com/ameyer/Arduino-L6470/archive/dev.zip
SailfishLCD=h??ps://github.com/mikeshub/SailfishLCD/archive/master.zip
SailfishRGB_LED=h??ps://github.com/mikeshub/SailfishRGB_LED/archive/master.zip
SlowSoftI2CMaster=h??ps://github.com/mikeshub/SlowSoftI2CMaster/archive/master.zip

#################################
#                               #
#   Unique Core Architectures   #
#                               #
#  Add a new "env" below if no  #
# entry has values suitable to  #
#   build for a given board.    #
#                               #
#################################

#
# NXP LPC176x ARM Cortex-M3
#
[env:LPC1768]
#platform          = h??ps://github.com/p3p/pio-nxplpc-arduino-lpc176x/archive/master.zip
platform = C:\Users\Jirka\.platformio\platforms\nxplpc-arduino-lpc176x
framework         = arduino
board             = nxp_lpc1768
build_flags       = -DTARGET_LPC1768 -DU8G_HAL_LINKS -IMarlin/src/HAL/HAL_LPC1768/include -IMarlin/src/HAL/HAL_LPC1768/u8g ${common.build_flags}
# debug options for backtrace
#  -funwind-tables
#  -mpoke-function-name
debug_tool = jlink
upload_protocol = jlink
#debug_server = C:\Program Files (x86)\SEGGER\JLink\JLinkGDBServerCL.exe -singlerun -if SWD -select USB -port 2331 -device LPC1768
lib_ldf_mode      = off
lib_compat_mode   = strict
extra_scripts     = Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
src_filter        = ${common.default_src_filter} +<src/HAL/HAL_LPC1768>
monitor_speed     = 250000
lib_deps          = Servo
LiquidCrystal
U8glib-HAL=h??ps://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip
TMCStepper@>=0.5.0,<1.0.0
Adafruit NeoPixel=h??ps://github.com/p3p/Adafruit_NeoPixel/archive/master.zip
SailfishLCD=h??ps://github.com/mikeshub/SailfishLCD/archive/master.zip

===================================================================

BTW, recently I saw different error - from DEBUG CONSOLE:

undefinedSEGGER J-Link GDB Server V6.52e Command Line Version
JLinkARM.dll V6.52e (DLL compiled Oct 16 2019 12:16:54)
Command line: -singlerun -if SWD -select USB -device LPC1768 -port 2331
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               on
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 LPC1768
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
Reading symbols from d:\project\MKS_Mrl2_CTC\.pioenvs\LPC1768\firmware.elf...
undefinedC:\Users\Jirka\.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.
J-Link is connected.
Firmware: J-Link ARM Lite V8 compiled Mar 14 2018 16:03:26
Hardware: V8.00
S/N: 228001020
Checking target voltage...
Target voltage: 3.27 V
ERROR: Failed to listen at socket (Err = -1)
ERROR: Failed to open listener port 2331
Restoring target state and closing J-Link connection...
Shutting down...
Failed to open listener port 2331
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...
0x1fff0ba4 in ?? ()
Temporary breakpoint 1 at 0x26c4c: file C:\users\jirka\.platformio\packages\framework-arduino-lpc176x\cores\arduino\main.cpp, line 43.
Resetting target
Loading section .text, size 0x3d02c lma 0x4000
Loading section .ARM.exidx, size 0x8 lma 0x4102c
Loading section .data, size 0x3b4 lma 0x41034
Start address 0x25d34, load size 250856
Transfer rate: 34996 KB/sec, 13936 bytes/write.
Resetting target
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
pio_reset_target

===================================================================

sorry for ā€œh??psā€, but new users (as Iā€™m) have limited amount of links within message to 2.
I see, that at least preview makes interpretation of some specal chars like bracketsā€¦ I hope, that there is a way, how you can disable it in order to see, what my platformio.ini really contains?

Just copy and paste the contents of it into a reply with triple backticks ``` before and after it so itā€™s treated as a code block.

lolā€¦ I was just about to say ā€œor try again, as Iā€™ve just bumped your trust level on the forumā€ ā€¦ and youā€™ve already posted it.

thanx for the hint with ā€œ```ā€ :slight_smile:

No problemā€¦ doing that should also work around the link permission issue, as itā€™s not a link any-moreā€¦ anyway, your forum permissions should be fine nowā€¦

erā€¦ are those lib_deps rightā€¦ you might want to copy and paste that platformio.ini in again within the backticksā€¦ some of that might have been auto-converted when you originally pasted that in (normally I put in both sets of backticks so the forum doesnā€™t try to re-interpret anything when you paste it).

i.e.

[LiquidCrystal@1.3.4](mailto:LiquidCrystal@1.3.4)

doesnā€™t look right! :open_mouth:

It should be this (if youā€™re using the stock marlin 2.x platformio.ini)

lib_deps =
  U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip
  LiquidCrystal@1.3.4
  TMCStepper@>=0.5.0,<1.0.0
  Adafruit NeoPixel@1.2.5
  LiquidTWI2=https://github.com/lincomatic/LiquidTWI2/archive/master.zip
  Arduino-L6470=https://github.com/ameyer/Arduino-L6470/archive/dev.zip
  SailfishLCD=https://github.com/mikeshub/SailfishLCD/archive/master.zip
  SailfishRGB_LED=https://github.com/mikeshub/SailfishRGB_LED/archive/master.zip
  SlowSoftI2CMaster=https://github.com/mikeshub/SlowSoftI2CMaster/archive/master.zip

platformio.ini:

[platformio]
src_dir      = Marlin
build_dir    = .pioenvs
lib_dir      = .piolib
libdeps_dir  = .piolibdeps
boards_dir   = buildroot/share/PlatformIO/boards
default_envs = LPC1768


[common]
default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
extra_scripts = pre:buildroot/share/PlatformIO/scripts/common-cxxflags.py
build_flags = -fmax-errors=5 -g -D__MARLIN_FIRMWARE__
lib_deps =
U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip
  LiquidCrystal@1.3.4
  TMCStepper@>=0.5.0,<1.0.0
  Adafruit NeoPixel@1.2.5
LiquidTWI2=https://github.com/lincomatic/LiquidTWI2/archive/master.zip
Arduino-L6470=https://github.com/ameyer/Arduino-L6470/archive/dev.zip
SailfishLCD=https://github.com/mikeshub/SailfishLCD/archive/master.zip
SailfishRGB_LED=https://github.com/mikeshub/SailfishRGB_LED/archive/master.zip
SlowSoftI2CMaster=https://github.com/mikeshub/SlowSoftI2CMaster/archive/master.zip

#################################
#                               #
#   Unique Core Architectures   #
#                               #
#  Add a new "env" below if no  #
# entry has values suitable to  #
#   build for a given board.    #
#                               #
#################################


#
# NXP LPC176x ARM Cortex-M3
#
[env:LPC1768]
#platform          = https://github.com/p3p/pio-nxplpc-arduino-lpc176x/archive/master.zip
platform = C:\Users\Jirka\.platformio\platforms\nxplpc-arduino-lpc176x
framework         = arduino
board             = nxp_lpc1768
build_flags       = -DTARGET_LPC1768 -DU8G_HAL_LINKS -IMarlin/src/HAL/HAL_LPC1768/include -IMarlin/src/HAL/HAL_LPC1768/u8g ${common.build_flags}
# debug options for backtrace
#  -funwind-tables
#  -mpoke-function-name
debug_tool = jlink
upload_protocol = jlink
#debug_server = C:\Program Files (x86)\SEGGER\JLink\JLinkGDBServerCL.exe -singlerun -if SWD -select USB -port 2331 -device LPC1768
lib_ldf_mode      = off
lib_compat_mode   = strict
extra_scripts     = Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
src_filter        = ${common.default_src_filter} +<src/HAL/HAL_LPC1768>
monitor_speed     = 250000
lib_deps          = Servo
  LiquidCrystal
U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip
  TMCStepper@>=0.5.0,<1.0.0
  Adafruit NeoPixel=https://github.com/p3p/Adafruit_NeoPixel/archive/master.zip
SailfishLCD=https://github.com/mikeshub/SailfishLCD/archive/master.zip
1 Like

and the most recent status of error from DEBUG CONSOLE:

undefinedSEGGER J-Link GDB Server V6.52e Command Line Version
JLinkARM.dll V6.52e (DLL compiled Oct 16 2019 12:16:54)
Command line: -singlerun -if SWD -select USB -device LPC1768 -port 2331
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               on
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 LPC1768
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
Reading symbols from d:\project\MKS_Mrl2_CTC\.pioenvs\LPC1768\firmware.elf...
undefinedC:\Users\Jirka\.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.
J-Link is connected.
Firmware: J-Link ARM Lite V8 compiled Mar 14 2018 16:03:26
Hardware: V8.00
S/N: 228001020
Checking target voltage...
Target voltage: 3.27 V
ERROR: Failed to listen at socket (Err = -1)
ERROR: Failed to open listener port 2331
Restoring target state and closing J-Link connection...
Shutting down...
Failed to open listener port 2331
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...
0x1fff0ba4 in ?? ()
Temporary breakpoint 1 at 0x26c4c: file C:\users\jirka\.platformio\packages\framework-arduino-lpc176x\cores\arduino\main.cpp, line 43.
Resetting target
Loading section .text, size 0x3d02c lma 0x4000
Loading section .ARM.exidx, size 0x8 lma 0x4102c
Loading section .data, size 0x3b4 lma 0x41034
Start address 0x25d34, load size 250856
Transfer rate: 34996 KB/sec, 13936 bytes/write.
Resetting target
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
pio_reset_target
1 Like

one comment more: The J-Link Lite, Iā€™m using, is couple of years old device. Iā€™ve checked within JLinkConfig from Segger, whether there is newer firmware, but the latest FW is inside (SEGGER doesnā€™t support this device anymore). So Iā€™m not sure, whether this canā€™t be the root cause.
I have ordered new full J-Link clone already, but it will take month or twoā€¦

On the other side: By using JFlashLite.exe I can connect to the LPC1768 and erase it without any error, so the J-Link, LPC1768 and connection are OK.

1 Like

Thanks for all of that :slight_smile:

Since this is a custom NXP board packageā€¦ namely originally https://github.com/p3p/pio-nxplpc-arduino-lpc176x ā€¦ Iā€™m now running away terribly fast, and leaving it for @ivankravets to have a look at the last couple of posts and reveal all! :laughing:

Since you have a baseline of the J-Link Lite working with the JFlashLite software, I hope itā€™s just a configuration issueā€¦ although some google searching of OpenOCD + jlink lite isnā€™t saying anything promisingā€¦ it seems like one of the side-effects of if being the ā€˜liteā€™ version is that itā€™s pretty much only supported by Seggerā€¦ :frowning: Hopefully someone can tell me that Iā€™m wrong! :wink:

I take it you canā€™t upload OR debug via PlatformIO?

1 Like

:slight_smile: Thanx a lot for your effort!
As I said, to be sure I ordered the full J-Link clne already.
I canā€™t try upload at the moment - the reason, why I desperately need DEBUGGING is, that something is recently burn out on my MKS_SBASE board and the Marlin firmware (version tested before an accident with board) causes very loud ā€œhot end temperatureā€ sound alarmā€¦ my local time is 5AM, my family sleeps :wink:

As workaround I just created new small test program for LPC1768 from the scratch and tried to upload it - I got promisingly looking log till the sentence ā€œWriting target memory failed.ā€:

> Executing task: C:\Users\Jirka\.platformio\penv\Scripts\platformio.exe run --target upload <

Processing nxp_lpc1768 (platform: nxplpc-arduino-lpc176x; board: nxp_lpc1768; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nxplpc-arduino-lpc176x/nxp_lpc1768.html
PLATFORM: NXP Arduino LPC176x 0.0.2 > NXP LPC1768
HARDWARE: LPC1768 100MHz, 31.80KB RAM, 464KB Flash
DEBUG: Current (jlink) On-board (cmsis-dap) External (blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.80201.190214 (8.2.1), framework-arduino-lpc176x 0.1.3
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Linking .pio\build\nxp_lpc1768\firmware.elf
Building .pio\build\nxp_lpc1768\firmware.bin
Checking size .pio\build\nxp_lpc1768\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   3.3% (used 1077 bytes from 32568 bytes)
PROGRAM: [          ]   2.9% (used 13656 bytes from 475136 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed
CURRENT: upload_protocol = jlink
Uploading .pio\build\nxp_lpc1768\firmware.bin
SEGGER J-Link Commander V6.52e (Compiled Oct 16 2019 12:18:04)
DLL version V6.52e, compiled Oct 16 2019 12:16:54


J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...O.K.
Firmware: J-Link ARM Lite V8 compiled Mar 14 2018 16:03:26
Hardware version: V8.00
S/N: 228001020
VTref=3.274V
Target connection not established yet but required for command.
Device "LPC1768" selected.


Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x412FC230. Implementer code: 0x41 (ARM)
Found Cortex-M3 r2p0, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 002BB000 SCS
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 002BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 002BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 002BB923 TPIU-Lite
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 002BB924 ETM-M3
Cortex-M3 identified.
PC = 1FFF0BA2, CycleCnt = FDD1B8FC
R0 = F0000000, R1 = 10000124, R2 = 00000105, R3 = 40084000
R4 = 2009C000, R5 = 00000002, R6 = 40008000, R7 = 00000000
R8 = 4002C000, R9 = 35DF789E, R10= 792E0881, R11= 993EB519
R12= 00000107
SP(R13)= 10007FB8, MSP= 10007FB8, PSP= 6FFD9548, R14(LR) = 1FFF0CBF
XPSR = A1000000: APSR = NzCvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
FPU regs: FPU not enabled / not implemented on connected CPU.

Downloading file [.pio\build\nxp_lpc1768\firmware.bin]...
Writing target memory failed.

Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.


Script processing completed.

Iā€™m going to quit now and tomorrow I will try to reinstall all J-Link related drivers and tools and let PlatformIO to try to install own versions.

Thank you, pfeerick!
brgds
dzejaar

Please file an issue here Issues Ā· platformio/platform-nxplpc Ā· GitHub

1 Like