If you just want to use the pre-existing Arduino core (in the MegaCoreX variant) for the ATMega4809 chip, you just have to tell PlatformIO to include that as your framework.
See board docs.
So you would do a normal platformio.ini
[env:ATmega4809]
platform = atmelmegaavr
board = ATmega4809
framework = arduino
and then create a src\main.cpp
where you would start using the Arduino core functions (and intended function structure)
#include <Arduino.h>
const int blinky_pin = PIN_PC3;
void setup() {
//UART init @ 9600 baud
Serial.begin(9600);
//print on UART with line ending
Serial.println("Hello, world!!");
//set GPIO pin to OUTPUT (push-pull)
pinMode(blinky_pin, OUTPUT);
}
void loop() {
//print on UART with line ending
Serial.println("Hello there");
//delay, set high, delay, set low
delay(1000);
digitalWrite(blinky_pin, HIGH);
delay(1000);
digitalWrite(blinky_pin, LOW);
}
Then when you build it you can also see the packages that are being used
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATmega4809.html
PLATFORM: Atmel megaAVR (1.3.0) > ATmega4809
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 48KB Flash
PACKAGES:
- framework-arduino-megaavr-megacorex 1.0.7
- toolchain-atmelavr 2.70300.201015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
No dependencies
...
Building .pio\build\ATmega4809\firmware.hex
Checking size .pio\build\ATmega4809\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 2.6% (used 161 bytes from 6144 bytes)
Flash: [= ] 5.9% (used 2894 bytes from 49152 bytes)
==================== [SUCCESS] Took 1.88 seconds ====================
(notice framework-arduino-megaavr-megacorex 1.0.7
)
That’s how you use the existing UART functionality in the Arduino core the ATMega4809 (note that Serial
is an instance of the UartClass
class instantiated with the argument UART0 and some other pins, see here).
That of course builds the whole Arduino core with the firmware, too, once we set framework = arduino
.
Or am I misunderstanding your question?
Note: If you’re using a board like the Arduino Nano Every, that is a seperate board (Arduino Nano Every — PlatformIO latest documentation) and also uses a different Arduino core implementaiton. Note MegaCoreX but GitHub - arduino/ArduinoCore-megaavr: Arduino Core for the ATMEGA4809 CPU.