PIO and MegaCoreX - help with pio.ini file

I have some 40 pin dip atmega 4809 chips which I am looking to turn into a few projects.
I have setup my pio.ini (see below) based on the megacorex template found here:

MegaCoreX/PlatformIO.md at master · MCUdude/MegaCoreX · GitHub

And I’ll use the pyupdi programming software and hardware circuit described here to program the chips:
"GitHub - mraardvark/pyupdi: Python UPDI driver for programming "new" tinyAVR and megaAVR devices "

I have 2 questions below, thanks very much for help.
Paul

Question 1
In the pio.ini file there is no mention of MegaCoreX. I have downloaded the megacorex files, do I need to point PIO at them in some way?

Question 2
If I set up a serial port using an FTDI board connected to a 4809 serial hardware port, can I use PIOs debug features via that port? If so, will the following PIO.ini excerpt (from a PIO.ini for an avr328P) work or will I need something different:

debug_tool = avr-stub
debug_port = COM8
lib_deps = jdolinay/avr-debugger@^1.1

My PIO.ini for use with the 4809 below: (based on PIO template)

; PlatformIO template configuration file for MegaCoreX
; https://github.com/MCUdude/MegaCoreX/
;
;   Build options: build flags, source filter
;   Hardware options: oscillator type, BOD, UART number, EEPROM retain
;   Upload options: custom upload port, speed, and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options
; https://github.com/MCUdude/MegaCoreX/blob/master/PlatformIO.md
; https://docs.platformio.org/page/projectconf.html
; https://docs.platformio.org/en/latest/platforms/atmelmegaavr.html
 
[platformio]
; Default build target
default_envs = ATmega4809_pyupdi_upload
 
; Parameters used for all environments
[env]
platform = atmelmegaavr
;framework = arduino
; pk included the line below
 
; Chip in use
board = ATmega4809
; Clock frequency in [Hz]
board_build.f_cpu = 16000000L
; Oscillator type (internal or external)
board_hardware.oscillator = internal
; Arduino pinout variant
board_build.variant = 40pin-default 
 
; Unflag build flags
;build_unflags =
 
; Extra build flags PK - see https://github.com/MCUdude/MegaCoreX/blob/master/PlatformIO.md for options 
;build_flags =
 
; Monitor port is auto detected. Override here
;monitor_port = 
; Serial monitor baud rate
monitor_speed = 9600

[env:ATmega4809_pyupdi_upload]
; Upload protocol for UPDI upload - from PIO help pages ; see bottom of this page https://github.com/MCUdude/MegaCoreX/blob/master/PlatformIO.md for install
upload_speed = 115200
upload_flags = 
    -d
    mega4809
    -c
    $UPLOAD_PORT
    -b
    $upload_speed
    upload_command = pyupdi $UPLOAD_FLAGS -f $source

; Run the following command to upload with this environment
; pio run -e Upload_UART -t upload
;[env:Upload_UART]
; Upload protocol for serial uploads (using Optiboot)
;upload_protocol = arduino
;upload_flags =
;upload_port = /dev/cu.usbserial*
 
 
; run the following command to set fuses
; pio run -e fuses_bootloader -t fuses
; run the following command to set fuses + burn bootloader
; pio run -e fuses_bootloader -t bootloader
;[env:fuses_bootloader]
; Upload protocol for used to set fuses/bootloader
;upload_protocol = ${env:Upload_UPDI.upload_protocol}
;upload_flags =
 
; Hardware settings
board_hardware.bod = 2.7v
board_hardware.eesave = yes
board_hardware.uart = no_bootloader
board_hardware.rstpin = reset

The Arduino-core selection is made per-default through the board = ... choice and in turn stored in the board JSON definition. For example, chhoosing

maps to the file

In which you can also see that the core is defined as MegaCoreX and the used variant is “48pins-standard”.

You don’t have to (read: shouldn’t) download any Arduino core package when using PlatformIO. PlatformIO handles this internally when you choose framework = arduino in conjunction with the chosen core and variant value of the board that you’ve chosen.

This line shouldn’t be indented.

The library that’s being used here doesn’t support the ATMega4809 – only ATMega328 and atmega1280/atmega2560. I could not get it to compile, since the register names are different between those two chips

.pio\libdeps\nano_every\avr-debugger\avr8-stub\avr8-stub.c:769:2: error: 'UCSR0A' undeclared (first use in this function)
  UCSR0A = _BV(U2X0);  /* double UART speed */

I know there’s a compatibility layer for ATmega4809 and ATMega328, but it doesn’t seem to just provide the same register names.

But as a general note, if the thing is programmed via UPDI (“Unified Program and Debug Interface”) then it should be debugable… just needs software support. This and this look interesting in that regard.

But as is stands right now, PlatformIO doesn’t have debugging support for the MegaAVR series.

thanks for all this help Max, it’s made things clearer for me. I asked on the pyupdi github issues forum about debugging and got a recommendation to acquire a SNAP standalone debugger. Can I interface that with PIO if I acquire one?

thanks
Paul

sorry, I missed your ‘right now’ link. So I gather from what you’ve said that there is no way to debug a 4809 currently even with an eternal device, is that correct? If so, do you have an idea when PIO might support debugging for the Mega AVRs?

thanks
Paul

Sadly no, only staff can know about that – there’s in issue open at debug support for microchip development boards · Issue #8 · platformio/platform-atmelmegaavr · GitHub already though.