Portenta C33 J-Link Debug Failure

I’m using a J-Link EDU connected via USB. I was previously able to debug on the Portenta C33. It was a little finicky, but it did actually work.

I’m not sure what changed, but PlatformIO is no longer able to debug:

JLinkARM.dll V7.88k (DLL compiled Jul  5 2023 15:00:17)

Command line: -singlerun -if SWD -select USB -device R7FA6M5BH -port 2331 -speed 5000
-----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:                 R7FA6M5BH
Target device parameters:      none
Target interface:              SWD
Target interface speed:        5000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link EDU Mini V1 compiled Dec  4 2023 10:24:48
Hardware: V1.00
S/N: 801015613
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.29 V
Listening on TCP/IP port 2331
Connecting to target...
Halting core...
Core security extensions: Implemented
Connected to target
Waiting for GDB connection...
Reading symbols from /home/zak/Development/PlatformIO/blink/.pio/build/portenta_c33/firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...
Connected to 127.0.0.1
GDB client (conn. 13) requested target.xml from GDB Server
Reading common registers: 
Read register 'r0' (4 bytes) from hardware: 0xF4AA9400
Read register 'r1' (4 bytes) from hardware: 0x40420F00
Read register 'r2' (4 bytes) from hardware: 0xE8030000
Read register 'r3' (4 bytes) from hardware: 0xFFFFFFFF
Read register 'r4' (4 bytes) from hardware: 0x40000100
Read register 'r5' (4 bytes) from hardware: 0x00000000
Read register 'r6' (4 bytes) from hardware: 0x00A50000
Read register 'r7' (4 bytes) from hardware: 0xDC8A0020
Read register 'r8' (4 bytes) from hardware: 0x0A030000
Read register 'r9' (4 bytes) from hardware: 0x01000000
Read register 'r10' (4 bytes) from hardware: 0xA5AF1EED
Read register 'r11' (4 bytes) from hardware: 0x385F97EA
Read register 'r12' (4 bytes) from hardware: 0x05000000
Read register 'sp' (4 bytes) from hardware: 0xD8FD0720
Read register 'lr' (4 bytes) from hardware: 0x1B020100
Read register 'pc' (4 bytes) from hardware: 0x309E0100
Read register 'xpsr' (4 bytes) from hardware: 0x00000029
Read 2 bytes @ address 0x0001C65C (Data = 0xF8D7)
Read 2 bytes @ address 0x0001D664 (Data = 0x0A49)
Read 4 bytes @ address 0x00019E30 (Data = 0xD1FB2800)
0x00019e30 in sci_uart_rxi_isr () at ../ra/fsp/src/r_sci_uart/r_sci_uart.c:1817
1817	../ra/fsp/src/r_sci_uart/r_sci_uart.c: No such file or directory.
Received monitor command: clrbp
Received monitor command: speed auto
Select auto target interface speed (2000 kHz)
Select auto target interface speed (2000 kHz)
Received monitor command: reset
Resetting target
Resetting target
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x00002400)
Loading section .text, size 0xfdb8 lma 0x10000
Downloading 15872 bytes @ address 0x00010000
Downloading 15984 bytes @ address 0x00013E00
Downloading 15904 bytes @ address 0x00017C70
Downloading 16048 bytes @ address 0x0001BA90
Downloading 1144 bytes @ address 0x0001F940
Loading section .ARM.extab, size 0xcc lma 0x1fdb8
Loading section .ARM.exidx, size 0x188 lma 0x1fe84
Downloading 204 bytes @ address 0x0001FDB8
Downloading 392 bytes @ address 0x0001FE84
Loading section .data, size 0x8b8 lma 0x2000c
Downloading 2232 bytes @ address 0x0002000C
Start address 0x1c188, load size 67780
Writing register 'pc' = 0x0001C188
Read 2 bytes @ address 0x0001C65C (Data = 0xB508)
Read 2 bytes @ address 0x0001D664 (Data = 0x4770)
Transfer rate: 16547 KB/sec, 8472 bytes/write.
Read 4 bytes @ address 0x0001C188 (Data = 0xF000B508)
Reading 64 bytes @ address 0x00010200
Read 2 bytes @ address 0x00010232 (Data = 0xF000)
Temporary breakpoint 1 at 0x10232: file /home/zak/.platformio/packages/framework-arduinorenesas-portenta/variants/PORTENTA_C33/tmp_gen_c_files/main.c, line 5.
PlatformIO: Initialization completed
Reading 64 bytes @ address 0x0001C180
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Setting breakpoint @ address 0x00010232, Kind = 2, Type = THUMB, BPHandle = 0x0001
Starting target CPU...
Reading common registers: Read register 'r0' (4 bytes) from hardware: 0xD8080020
Read register 'r1' (4 bytes) from hardware: 0x00000000
Read register 'r2' (4 bytes) from hardware: 0x9C260000
Read register 'r3' (4 bytes) from hardware: 0x00EE0720
Read register 'r4' (4 bytes) from hardware: 0x00000000
Read register 'r5' (4 bytes) from hardware: 0x00000000
Read register 'r6' (4 bytes) from hardware: 0x00000000
Read register 'r7' (4 bytes) from hardware: 0x00000000
Read register 'r8' (4 bytes) from hardware: 0x0A030000
Read register 'r9' (4 bytes) from hardware: 0x01000000
Read register 'r10' (4 bytes) from hardware: 0xA5AF1EED
Read register 'r11' (4 bytes) from hardware: 0x385F97EA
Read register 'r12' (4 bytes) from hardware: 0xF4010000
Read register 'sp' (4 bytes) from hardware: 0x00EE0720
Read register 'lr' (4 bytes) from hardware: 0xF9FFFFFF
Read register 'pc' (4 bytes) from hardware: 0x84C10100
Read register 'xpsr' (4 bytes) from hardware: 0x03000029

Program
 received signal SIGTRAP, Trace/breakpoint trap.
Removing breakpoint @ address 0x00010232, Size = 2
Read 4 bytes @ address 0x0001C184 (Data = 0x4770BE00)
Default_Handler () at ../ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c:84
84	../ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c: No such file or directory.
Read 4 bytes @ address 0x2007EE1C (Data = 0x54A898B4)
Reading 64 bytes @ address 0x2007EE00
WARNING: Failed to read memory @ address 0x99AFEFFC
(2) WARNING: Failed to read memory @ address 0xCBEA8484
Reading 64 bytes @ address 0x0001C180

When I clicked the STOP symbol (square), then I received the additional logs:

pio_reset_run_target
Received monitor command: clrbp
Received monitor command: reset
Resetting target
Resetting target
Received monitor command: go
Starting target CPU...
GDB closed TCP/IP connection (Socket 13)
undefinedLoop <_UnixSelectorEventLoop running=False closed=True debug=False> that handles pid 460542 is closed

VSCode Details:

Version: 1.85.1
Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
Date: 2023-12-13T09:47:11.635Z
Electron: 25.9.7
ElectronBuildId: 25551756
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Linux x64 6.2.0-39-generic
PlatformIO Version: 3.3.2
Platform: Renesas RA v1.3.1

platformio.ini

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter, extra scripting
;   Upload options: custom port, speed and extra flags
;   Library options: dependencies, extra library storages
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:portenta_c33]
platform = renesas-ra
board = portenta_c33
framework = arduino

; Build Options
build_flags =
    -Wall
    -Wextra
    ; -Wpedantic
    ; -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
    ; -D RELEASE
    ; -O3
    -Og

; Upload Options
    upload_protocol = jlink

; Debug Options
    debug_tool = jlink
; debug_init_break = tbreak setup

If I manually call the J-Link GDB Server and GDB from the command line, then I can debug successfully.

J-Link GDB Server:

JLinkGDBServerExe -singlerun -if SWD -select USB -device R7FA6M5BH -port 2331 -speed 5000

GDB:

~/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gdb -tui -ex 'target extended-remote :2331' -ex 'tbreak Blink.cpp:setup' ~/Development/PlatformIO/blink/.pio/build/portenta_c33/firmware.elf

I’m not sure how these are different, but I am unable to debug using the PlatformIO GUI.

PlatformIO seems to use an equivalent JLink invocation based on thel ogs above. It however doesn’t seem to advance further to the main() (or setup()) function after hitting the Default_Handler interrupt.

You can try to add debug_init_break = b setup in the platformio.ini to make it advance to setup(). If it’s still stuck, does pressing the reset button once make it hit the breakpoint?

To get my desired experience, I invoke GDB as follows:

~/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gdb -tui -ex 'target extended-remote :2331' -ex 'tbreak setup' -ex 'monitor reset' -ex 'continue'  ~/Development/PlatformIO/blink/.pio/build/portenta_c33/firmware.elf

It’s very similar to what I originally posted, but it ensures the debugger snaps to the break point on setup().

I’m using the following platformio.ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter, extra scripting
;   Upload options: custom port, speed and extra flags
;   Library options: dependencies, extra library storages
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:portenta_c33]
platform = renesas-ra
board = portenta_c33
framework = arduino

; Build Options
build_flags =
    -Wall
    -Wextra
    -Og

; Upload Options
upload_protocol = jlink

; Debug Options
debug_tool = jlink
debug_init_break = tbreak setup

In order to match the experience from the command line, I have to first wait for the debugger to fail.

During the failure, the following two files pop open, Reset_Handler.dbgasm and Default_Handler.dbgasm.

After I press Restart (Ctrl+Shirt+F5), then I get the same experience as I would normally get on the command line.

Odd, no?

It gets even more odd…

Frequently, and sporadically, I encounter the following error while debugging:

This occurs when debugging from either the command line or the PlatformIO GUI.

The logs report the program received a signal:

Thread 2 received signal SIGTRAP, Trace/breakpoint trap.
0x0001491e in usbd_control_xfer_cb (rhport=1 '\001', ep_addr=128 '\200', result=XFER_RESULT_SUCCESS, xferred_bytes=18)
    at /home/zak/.platformio/packages/framework-arduinorenesas-portenta/cores/arduino/tinyusb/device/usbd_control.c:173

It can normally be resolved by typing start + y on the GDB terminal or pressing Restart (Ctrl+Shirt+F5) in the GUI.

Interestingly, this only seems to occur with the binary produced by PlatformIO and NOT with a binary produced by the Arduino IDE v2.

Just hazarding a guess, but it seems like there may be some inappropriate flags provided to the compiler by PlatformIO.

Here is the compiler output from the Arduino IDE v2.

FQBN: arduino:renesas_portenta:portenta_c33
Using board 'portenta_c33' from platform in folder: /home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5
Using core 'arduino' from platform in folder: /home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5

Detecting libraries used...
/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=200000000 -std=gnu++17 -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino" -DARDUINO_PORTENTA_C33 -DARDUINO_ARCH_RENESAS_PORTENTA -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/defines.txt -DLWIP_DNS=1 -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/tinyusb -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated-avr-comp -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33 -iprefix/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5 @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/includes.txt /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/sketch/BlinkDebug.ino.cpp -o /dev/null
Generating function prototypes...
/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=200000000 -std=gnu++17 -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino" -DARDUINO_PORTENTA_C33 -DARDUINO_ARCH_RENESAS_PORTENTA -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/defines.txt -DLWIP_DNS=1 -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/tinyusb -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated-avr-comp -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33 -iprefix/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5 @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/includes.txt /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/sketch/BlinkDebug.ino.cpp -o /tmp/2173536585/sketch_merged.cpp
/home/zak/.arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/2173536585/sketch_merged.cpp
Compiling sketch...
/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -Wall -Wextra -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -MMD -nostdlib -DF_CPU=200000000 -MMD -std=gnu++17 -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -DARDUINO=10607 "-DPROJECT_NAME=\"/tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino\"" -DARDUINO_PORTENTA_C33 -DARDUINO_ARCH_RENESAS_PORTENTA -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/defines.txt -DLWIP_DNS=1 -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/tinyusb -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated-avr-comp -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33 -iprefix/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5 @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/includes.txt /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/sketch/BlinkDebug.ino.cpp -o /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/sketch/BlinkDebug.ino.cpp.o
Compiling libraries...
Compiling core...
Using previously compiled file: /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/tmp_gen_c_files/common_data.c.o
Using previously compiled file: /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/tmp_gen_c_files/pin_data.c.o
Using previously compiled file: /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/variant.cpp.o
Using previously compiled file: /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/tmp_gen_c_files/main.c.o
Using precompiled core: /tmp/arduino/cores/arduino_renesas_portenta_portenta_c33_6f630dca8d5eb29b7ef91b56c46bda6c/core.a
Linking everything together...
/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -Wl,--gc-sections --specs=nosys.specs -Wall -Wextra -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -o /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino.elf -L/tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA -L/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33 -T/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/fsp.ld /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/sketch/BlinkDebug.ino.cpp.o /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/tmp_gen_c_files/common_data.c.o /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/tmp_gen_c_files/main.c.o /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/tmp_gen_c_files/pin_data.c.o /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/core/variant.cpp.o -Wl,--whole-archive -Wl,--start-group /home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/libs/libfsp.a /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/../../cores/arduino_renesas_portenta_portenta_c33_6f630dca8d5eb29b7ef91b56c46bda6c/core.a -Wl,--no-whole-archive -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -Wl,--end-group -Wl,-Map,/tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino.map
/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-objcopy -O binary -j .text -j .data /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino.elf /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino.bin
/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-objcopy -O ihex -j .text -j .data /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino.elf /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino.hex

/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-size -A /tmp/arduino/sketches/6E18701710D06A6EAAFD2F664971D8EA/BlinkDebug.ino.elf
Sketch uses 94332 bytes (4%) of program storage space. Maximum is 2097152 bytes.
Global variables use 20720 bytes (3%) of dynamic memory, leaving 502904 bytes for local variables. Maximum is 523624 bytes.