platformio / platform-nxplpc

NXP LPC: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/nxplpc
Apache License 2.0
8 stars 12 forks source link

LPC1768 debugging via J-Link #18

Open dzejaar opened 4 years ago

dzejaar commented 4 years ago

Hi all, I need to debug LPC1768 in MKS SBASE v1.3; my origin target was to debug Marlin 2.0. OS is Windows 10 Pro 64bit. I'm using the older original SEGGER version of J-Link Lite. I'm able to connect to the board and talk to LPC1768 via SEGGER's tools, but I didn't manage to get debugging from Platformio working. In order to reduce complexity, I tried to make naked LPC17xx project within Platformio from the scratch, compiled t and ended with following report by trying the debug:

> 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.

Due to doubts about Platformio's support for old J-Link Lite I made following steps just now:

[env:nxp_lpc1768]
platform = nxplpc-arduino-lpc176x
board = nxp_lpc1768
framework = arduino
debug_tool = jlink
upload_protocol = jlink

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 Compiling .pio\build\nxp_lpc1768\src\main.cpp.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\debug_frmwrk.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_adc.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_can.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_clkpwr.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_dac.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_emac.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_exti.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_gpdma.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_gpio.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_i2c.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_i2s.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_iap.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_libcfg_default.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_mcpwm.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_nvic.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_pinsel.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_pwm.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_qei.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_rit.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_rtc.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_spi.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_ssp.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_systick.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_timer.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_uart.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\driver\lpc17xx_wdt.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\chanfs\ff.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\chanfs\ffunicode.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\chanfs\mmc_ssp.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\chanfs\rtc176x.c.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\usb\cdcuser.cpp.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\usb\mscuser.cpp.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\usb\usbcore.cpp.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\usb\usbdesc.cpp.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\usb\usbhw.cpp.o Compiling .pio\build\nxp_lpc1768\CMSIS\lib\usb\usbuser.cpp.o Compiling .pio\build\nxp_lpc1768\CMSIS\system\startup_LPC17xx.S.o Compiling .pio\build\nxp_lpc1768\CMSIS\system\system_LPC17xx.c.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\CDCSerial.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\HardwarePWM.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\HardwareSerial0.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\HardwareSerial1.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\HardwareSerial2.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\HardwareSerial3.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\Print.cpp.o Archiving .pio\build\nxp_lpc1768\libCMSIS.a Compiling .pio\build\nxp_lpc1768\FrameworkArduino\SoftwarePWM.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\SoftwareSPI.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\SoftwareSerial.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\Stream.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\Tone.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\WInterrupts.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\Wire.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\arduino.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\main.cpp.o Compiling .pio\build\nxp_lpc1768\FrameworkArduino\pwm.cpp.o Archiving .pio\build\nxp_lpc1768\libFrameworkArduino.a 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 'JLink.exe' is not recognized as an internal or external command, operable program or batch file. *** [upload] Error 1 ================================================================================================== [FAILED] Took 5.08 seconds ================================================================================================== The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.


and DEBUG CONSOLE:

undefinedError: Could not launch Debug Server 'JLinkGDBServerCL.exe'. Please check that it is installed and is included in a system PATH


- I'm very fresh PlatformIO beginner, so I'm not sure, whether my expectation, that Platformio is able to detect J-Link by itself and install all needed SW is correct, hence next step -> I do install SEGGER J-Link package V652e once more by myself... (for the installation I selected "New Instance")
- I added the correct path to GDB server into system PATH variable as well
- Connection J-Link Pro <-> LPC1768 works, I can erase and program FLASH of LPC
- attempt for debugging session -> the same result as above (before installin SEEGER's J-Link package) - and the result is pretty much the same, I have seen with origin Marlin project and that old J-Link Lite:

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 c:\Users\Jirka\Documents\PlatformIO\Projects\LPC1768_JLink.pio\build\nxp_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. PlatformIO Unified Debugger -> http://bit.ly/pio-debug PlatformIO: debug_tool = jlink PlatformIO: Initializing remote target... .pioinit:14: Error in sourced command file: :2331: Nemohlo b�t vytvo�eno ��dn� p�ipojen�, proto�e c�lov� po��ta� je aktivn� odm�tl.

(the last sentence says: "Connection wasn't established because it was actively refused by target computer")
-----

- Interesting change did happen when I started the SEGGER's GDB server manualy before trying the degbugging session in Platformio - 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 c:\Users\Jirka\Documents\PlatformIO\Projects\LPC1768_JLink.pio\build\nxp_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. PlatformIO Unified Debugger -> http://bit.ly/pio-debug PlatformIO: debug_tool = jlink PlatformIO: Initializing remote target... 0x1fff0ba4 in ?? () Temporary breakpoint 1 at 0x45d4: file C:\Users\Jirka.platformio\packages\framework-arduino-lpc176x\cores\arduino\main.cpp, line 43. J-Link is connected. Firmware: J-Link Pro V4 compiled Aug 12 2019 10:38:28 Hardware: V4.00 S/N: 174300738 Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB Checking target voltage... Target voltage: 3.33 V ERROR: Failed to listen at socket (Err = -1) ERROR: Failed to open listener port 2331 Resetting target Loading section .text, size 0x33ec lma 0x4000 Loading section .ARM.exidx, size 0x8 lma 0x73ec Loading section .data, size 0x28c lma 0x73f4 Start address 0x41e8, load size 13952 Restoring target state and closing J-Link connection... Transfer rate: 3406 KB/sec, 4650 bytes/write. Shutting down... Failed to open listener port 2331 Resetting target PlatformIO: Initialization completed PlatformIO: Resume the execution to debug_init_break = tbreak main PlatformIO: More configuration options -> http://bit.ly/pio-debug



========================
Sorry for long message. I just wanted to provide you with as much of details as possible, because I have to return back the J-Link Pro tomorrow morning.

May i please ask you for creating smallest possible project for generic LPC1768 and configure it for successful debugging via J-Link? 
With such a working reference it might be easier for me to investigate for root cause on my side.
Thank you in advance

brgds
dzejaar
dzejaar commented 4 years ago

Hi all, I have update: I tested Nucleo L053 board (STM32L053) with the same J-Link Lite device. I made very simple program within Platformio from the scratch; platformio.ini follows:

platform = ststm32
board = nucleo_l053r8
framework = arduino
debug_tool = jlink
upload_protocol = jlink

When I compiled the project, I spotted message from Platformio about installing j-link... something. Such a message DID NOT appear when I compiled the same project for LPC1768! I don't need to add, that uploading as well as debugging after that was possible without a problem, do I? ;-) So I guess, that somewhere within Platformio is missing step in term of installing j-link related utilities in case of LPC1768 platform or board is selected.

As next step I connected J-Link Lite back to board with LPC1768, adapted platformio.ini (below), made build and tried upload and debug. Both actions (upload and starting debug session) have failed.

platformio.ini for LPC1768:

[env:nxp_lpc1768]
platform = nxplpc-arduino-lpc176x
board = nxp_lpc1768
framework = arduino
debug_tool = jlink
upload_protocol = jlink

#[env:nucleo_l053r8]
#platform = ststm32
#board = nucleo_l053r8
#framework = arduino
#debug_tool = jlink
#upload_protocol = jlink
dzejaar commented 4 years ago

Further update: I would say, that the issue is not related to J-Link at all, but it is LPC1768 specific. Or maybe NXP's LPCxxxx MCUs specific. I have built up Blackmagic Probe today in order to test different programmer/debugger. PlatformIO is capable to use this Blackmagic Probe without any problem for uploading as well as for debugging simple test program on STM32L053.
Trying uplod or debug on LPC1768 it doesn't work,

Upload to STM32L053:

Processing nucleo_l053r8 (platform: ststm32; board: nucleo_l053r8; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_l053r8.html
PLATFORM: ST STM32 5.6.0 > ST Nucleo L053R8
HARDWARE: STM32L053R8T6 32MHz, 8KB RAM, 64KB Flash
DEBUG: Current (blackmagic) On-board (stlink) External (blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-arduinoststm32 3.10601.190716 (1.6.1), tool-stm32duino 1.0.1, tool-openocd 2.1000.190707 (10.0), tool-dfuutil 1.9.190708
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 7 compatible libraries
Scanning dependencies...
No dependencies
Checking size .pio\build\nucleo_l053r8\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   9.3% (used 764 bytes from 8192 bytes)
PROGRAM: [==        ]  15.1% (used 9896 bytes from 65536 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, jlink, mbed, stlink
CURRENT: upload_protocol = blackmagic
Looking for BlackMagic port...
Auto-detected: \\.\COM18
Uploading .pio\build\nucleo_l053r8\firmware.elf
Target voltage: unknown
Available Targets:
No. Att Driver
 1      STM32L0x
0x080006a0 in HAL_DMA_Abort_IT ()
Loading section .isr_vector, size 0xc0 lma 0x8000000
Loading section .text, size 0x2528 lma 0x80000c0
Loading section .rodata, size 0x178 lma 0x80025e8
Loading section .init_array, size 0x10 lma 0x8002760
Loading section .fini_array, size 0x4 lma 0x8002770
Loading section .data, size 0x8 lma 0x8002774
Start address 0x8002180, load size 10108
Transfer rate: 6 KB/sec, 673 bytes/write.
Section .isr_vector, range 0x8000000 -- 0x80000c0: matched.
Section .text, range 0x80000c0 -- 0x80025e8: matched.
Section .rodata, range 0x80025e8 -- 0x8002760: matched.
Section .init_array, range 0x8002760 -- 0x8002770: matched.
Section .fini_array, range 0x8002770 -- 0x8002774: matched.
Section .data, range 0x8002774 -- 0x800277c: matched.
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
================================================================================================== [SUCCESS] Took 4.27 seconds ==================================================================================================
dzejaar commented 4 years ago

Hi all, I would highly appreciate any hint, what to try as next. I don't believe, that I'm the first guy, who is trying to use PlatformIO for LPC1768 debugging via J-Link ;-)