Hi and thanks for your patience.
I’m still trying to debug the Keil MCB1760 wit the Microcontroller LPC1768 properly.
I have got three probes at my disposal, one being the ULINK-ME, one being the Blackmagic Probe and one being the J-Link EDU Mini.
As weird stuff keeps on happening whenever I try to run any firmware other than one that contains the Mbed framework(debugs properly), I’m back at trying the ULINK-ME again.
PlatformIO.ini depending on the probe I use:
[env:lpc1768]
platform = nxplpc
board = lpc1768
;framework = mbed
; ULINK-ME Probe
build_flags = -D MCB1700
extra_scripts = extra_script.py
;
upload_protocol = custom
upload_flags =
-f
scripts/interface/cmsis-dap.cfg
-f
scripts/board/mcb1700.cfg
debug_tool = custom
debug_server =
$PLATFORMIO_CORE_DIR/packages/tool-openocd/bin/openocd
-f
../scripts/interface/cmsis-dap.cfg
-f
../scripts/board/mcb1700.cfg
;J-Link Probe
upload_protocol = jlink-jtag
debug_tool = jlink
;Blackmagic Probe
extra_scripts = extra_script.py
upload_protocol = blackmagic
upload_port = /dev/cu.usbmodem79AC68971
debug_tool = custom
debug_port = /dev/cu.usbmodem79AC68971
debug_init_cmds =
target extended-remote $DEBUG_PORT
monitor swdp_scan
attach 1
set mem inaccessible-by-default off
$INIT_BREAK
$LOAD_CMDS
When flashing a basic firmware:
main.cpp
#include <LPC17xx/LPC17xx.h>
#ifdef __cplusplus
extern "C" {
#endif
void delay_ms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<6000;j++);
}
/* start the main program */
int main()
{
SystemInit(); //Clock and PLL configuration
LPC_PINCON->PINSEL4 = 0x000000; //Configure the PORT2 Pins as GPIO;
LPC_GPIO2->FIODIR = 0xffffffff; //Configure the PORT2 pins as OUTPUT;
while(1)
{
LPC_GPIO2->FIOPIN = 0xffffffff; // Make all the Port pins as high
delay_ms(100);
LPC_GPIO2->FIOPIN = 0x00; // Make all the Port pins as low
delay_ms(100);
}
}
#ifdef __cplusplus
}
#endif
I’m getting this terminal output:
> Executing task: platformio run --target upload <
Processing lpc1768 (platform: nxplpc; board: lpc1768)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nxplpc/lpc1768.html
PLATFORM: NXP LPC 4.4.0 > NXP mbed LPC1768
HARDWARE: LPC1768 96MHz, 64KB RAM, 512KB Flash
DEBUG: Current (custom) On-board (cmsis-dap) External (blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <LPC17xx>
Compiling .pio/build/lpc1768/src/main.o
Compiling .pio/build/lpc1768/libcb3/LPC17xx/core_cm3.o
Compiling .pio/build/lpc1768/libcb3/LPC17xx/startup_LPC17xx.o
Compiling .pio/build/lpc1768/libcb3/LPC17xx/system_LPC17xx.o
Archiving .pio/build/lpc1768/libcb3/libLPC17xx.a
Indexing .pio/build/lpc1768/libcb3/libLPC17xx.a
Linking .pio/build/lpc1768/firmware.elf
Building .pio/build/lpc1768/firmware.bin
Checking size .pio/build/lpc1768/firmware.elf
post_bin_file([".pio/build/lpc1768/firmware.bin"], [".pio/build/lpc1768/firmware.elf"])
==== Post building BIN file ====
Firmware path: .pio/build/lpc1768/firmware.bin
Memory Usage -> http://bit.ly/pio-memory-usage
DATA: [ ] 0.2% (used 124 bytes from 65536 bytes)
PROGRAM: [ ] 0.1% (used 632 bytes from 524288 bytes)
Wrote checksum 0x2b6aa66 into binary.
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, custom, jlink, mbed
CURRENT: upload_protocol = custom
Uploading .pio/build/lpc1768/firmware.bin
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 10 kHz
Info : SWD DPIDR 0x2ba01477
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Info : High speed (adapter_khz 12500) may be limited by adapter firmware.
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Info : SWD DPIDR 0x2ba01477
Error: lpc17xx.cpu -- clearing lockup after double fault
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x60000003 pc: 0x4b07b508 msp: 0xbf00b5d8
Polling target lpc17xx.cpu failed, trying to reexamine
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints
shutdown command invoked
========================================================================================== [SUCCESS] Took 13.99 seconds ==========================================================================================
Terminal will be reused by tasks, press any key to close it.
And this debug terminal log:
Debug console log
Reading symbols from /Users/john/Documents/PlatformIO/Projects/Testing_MCB1768/.pio/build/lpc1768/firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = custom
PlatformIO: Initializing remote target...
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : tcl server disabled
Info : telnet server disabled
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 10 kHz
Info : SWD DPIDR 0x2ba01477
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection from pipe
0x00000000 in ?? ()
Temporary breakpoint 1 at 0x80ea: file src/main.cpp, line 18.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Warn : keep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (1992). Workaround: increase "set remotetimeout" in GDB
Info : High speed (adapter_khz 12500) may be limited by adapter firmware.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Warn : keep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (1974). Workaround: increase "set remotetimeout" in GDB
Info : High speed (adapter_khz 12500) may be limited by adapter firmware.
Loading section .init, size 0xc lma 0x8000
Loading section .text, size 0x22c lma 0x800c
Loading section .fini, size 0xc lma 0x8238
Loading section .rodata, size 0x4 lma 0x8244
Loading section .ARM.exidx, size 0x8 lma 0x8248
Loading section .eh_frame, size 0x4 lma 0x8250
Loading section .init_array, size 0x4 lma 0x18254
Loading section .fini_array, size 0x4 lma 0x18258
Loading section .data, size 0x60 lma 0x1825c
Info : Flash write discontinued at 0x00008254, next section at 0x00018254
Warn : offset 0x18254 breaks required alignment 0x100
Error: error writing to flash at address 0x00000000 at offset 0x00018254
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Warn : keep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (1952). Workaround: increase "set remotetimeout" in GDB
.pioinit:16: Error in sourced command file:
Error finishing flash operation
When trying to debug with J-Link:
The upload doesn’t throw any errors, but debugging throws this here:
Reading symbols from /Users/john/Documents/PlatformIO/Projects/Testing_MCB1768/.pio/build/lpc1768/firmware.elf...
SEGGER J-Link GDB Server V6.50a Command Line Version
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...
JLinkARM.dll V6.50a (DLL compiled Aug 26 2019 10:26:25)
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: yes
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...
J-Link is connected.
Firmware: J-Link EDU Mini V1 compiled Aug 27 2019 09:26:01
Hardware: V1.00
S/N: 801015042
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.27 V
Listening on TCP/IP port 2331
Connecting to target...WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1.
Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
0x4b07b508 in ?? ()
Temporary breakpoint 1 at 0x80ea: file src/main.cpp, line 18.
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x4B07B508)
Received monitor command: reset
Resetting target
Resetting target
Loading section .init, size 0xc lma 0x8000
Loading section .text, size 0x22c lma 0x800c
Loading section .fini, size 0xc lma 0x8238
Loading section .rodata, size 0x4 lma 0x8244
Loading section .ARM.exidx, size 0x8 lma 0x8248
Loading section .eh_frame, size 0x4 lma 0x8250
Loading section .init_array, size 0x4 lma 0x18254
Loading section .fini_array, size 0x4 lma 0x18258
Loading section .data, size 0x60 lma 0x1825c
Start address 0x8074, load size 700
Writing register (PC = 0x 8074)
Transfer rate: 341 KB/sec, 77 bytes/write.
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x00008074)
Received monitor command: reset
Resetting target
Resetting target
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
Starting target CPU...
WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1.
...Target halted (DBGRQ, PC = 0x4B07B508)
Reading all registers
Program
received signal SIGTRAP, Trace/breakpoint trap.
0x4b07b508 in ?? ()
pio_reset_target
Received monitor command: reset
Resetting target
Resetting target
GDB closed TCP/IP connection
And with the blackmagic probe:
The flashing also seems to work, but the debugging part fails with a segmentation fault.
Reading symbols from /Users/john/Documents/PlatformIO/Projects/Testing_MCB1768/.pio/build/lpc1768/firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = custom
PlatformIO: Initializing remote target...
Target voltage: 3.3V
Available Targets:
No. Att Driver
1 LPC17xx M3/M4
0x10000036 in ?? ()
Temporary breakpoint 1 at 0x80ea: file src/main.cpp, line 18.
Loading section .init, size 0xc lma 0x8000
Loading section .text, size 0x22c lma 0x800c
Loading section .fini, size 0xc lma 0x8238
Loading section .rodata, size 0x4 lma 0x8244
Loading section .ARM.exidx, size 0x8 lma 0x8248
Loading section .eh_frame, size 0x4 lma 0x8250
Loading section .init_array, size 0x4 lma 0x18254
Loading section .fini_array, size 0x4 lma 0x18258
Loading section .data, size 0x60 lma 0x1825c
Start address 0x8074, load size 700
Transfer rate: 770 bytes/sec, 77 bytes/write.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.
Program
received signal SIGSEGV, Segmentation fault.
0xfffffffe in ?? ()