How to debug a specific target in my platform.ini?

I’d like to specifically debug the second board without having to restructure the whole file again in order to have the debugged target as the first env:... target which seems to be the one being debugged, if I use the Visual Studio Code Debugging interface and click the Green Play button there.

Would be nice to know if that’s possible.

My ini file:

[common]

default_src_filter = 
  +<*> 
  -<.git/> 
  -<.svn/> 
  -<example/> 
  -<examples/> 
  -<test/> 
  -<tests/> 
  -<target/>

# platformIO seems to have an inconsistent behaviour in regard to the
# starting directory. sometimes target/ needs to be prefixed with src/ 
# and sometimes it doesn't need to

[env:stm32f407vg]
platform = ststm32
board = disco_f407vg
framework = cmsis

src_filter = 
  ${common.default_src_filter} 
  +<traget/STM32F407VG/>

build_flags = 
  -Wl,-T"scripts/target/STM32F407VG/STM32F407VG.ld"
  -D STM32F407VG
  -D DEBUG

upload_protocol = stlink
upload_port = /dev/cu.usbmodem14103
debug_tool = stlink


[env:lpc1768]
platform = nxplpc
board = lpc1768

src_filter = 
  ${common.default_src_filter} 
  +<traget/MCB1760/>

build_flags = 
  -Wl,-T"scripts/target/MCB1760/LPC1768.ld"
  -D MCB1760 
  -D DEBUG

extra_scripts = scripts/target/MCB1760/firmware_patch.py

# J-Link Probe
upload_protocol = jlink-jtag
debug_tool = jlink


# ULINK-ME Probe
;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


# Blackmagic Probe
;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


[env:myAVR_Board_MK2_2.20]
platform = atmelavr
board = ATmega328P

src_filter = 
  ${common.default_src_filter} 
  +<traget/MYAVR_BOARD_MK2/>

# build and debugging flags
build_flags = 
  -D MYAVR_BOARD_MK2
  -D DEBUG

# upload port.
upload_port = /dev/cu.SLAB_USBtoUART
upload_protocol = avr911
upload_speed = 19200
upload_flags = -e



[env:Arduino_UNO]
platform = atmelavr
board = uno

src_filter = 
  ${common.default_src_filter} 
  +<traget/ARDUINO_UNO/>

# build and debugging flags
build_flags = 
  -D ARDUINO_UNO
  -D DEBUG

# upload port.
upload_port = /dev/cu.usbmodem14101


1 Like

Do the subfolders for the task have their own debug button? Redirecting...

Hm seems like a case for a feature-request in Issues · platformio/platformio-core · GitHub to me, the Pre-Debug targets will just compile the firmware in debug mode. Or am I overseeing the option to start a per-environment session, @valeros?

1 Like

Unfortunately, there is no convenient way to do this at the moment:

Please note that PIO Unified Debugger will use the first declared build environment in "platformio.ini" (Project Configuration File) if default_envs option is not specified

2 Likes

^^^ Just incase it wasn’t obvious… that’s the answer to your question @jxsl13 … use default_envs to set the debug environment :wink:

1 Like