Programming the Atmega4809

I recently bought the Atmega4809 TQFP package as I loved its specifications.
http://www.microchipdirect.com/product/ATMEGA4809

But I have no idea to how to program it without the ATMEL-ICE or the Xplained pro board as they are quite expensive.
Could someone suggest some other way to program the controller using an arduino uno maybe? please help!

Probably it will not be so easy to program it using an Arduino. This one looks pretty different from all other ATmegas. You have to go from basics.

There are patches for implementing PDI on USBASP programmers: ATxmega and company: ATxmega programmer for $0.50
It should be possible to do something similar with the "Arduino as ISP" sketch (Hmm. Perhaps not, since the protocol it uses doesn't include PDI commands? I dunno.)

Getting support for the new chip in avrdude may also be a problem.

Ah - a more recent version, written as an Arduino Sketch....

What about the ISP MKII Clones?

I thought there were plans to use this in an official Arduino board? But there has been no word of it for months... Making an Arduino core that works with the new peripherals will be a big job, since they are so different - the capability is so far beyond what the normal AVRs can do - I think the harder part is figuring out how to present them in a simple, Arduino-y way.

The Arduino Uno WiFi rev2 will use the ATmega4809. I believe the first indication of how this will be accomplished was made public today. It looks like they are creating a dedicated hardware package for the "megaAVR" architecture:

My initial reaction is that I would prefer that they added ATmega4809 support to the Arduino AVR Boards hardware package but I do understand that the ATmega4809 is significantly different. I haven't looked at the hardware package at all.

// ATMEGA4809 / ARDUINO
//
//						SCL  SDA
//					   (A5*)(A4*)	   (7)  (2)			   (R)		(3~) (6~)
//				   PA4  PA3  PA2  PA1  PA0  GND  VDD  UPDI PF6  PF5  PF4  PF3
//
// 					48   47   46   45   44   43   42   41   40   39   38   37
//				 + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
//		  PA5   1|															   |36  PF2
//		  PA6   2|															   |35  PF1 (TOSC2)
//	      PA7   3|															   |34  PF0 (TOSC1)
//   (9~) PB0   4|															   |33  PE3 (8)
//  (10~) PB1   5|															   |32  PE2
//   (5~) PB2   6|															   |31  PE1
//		  PB3   7|							48pin QFN						   |30  PE0
//   (Tx) PB4   8|															   |29  GND
//   (Rx) PB5   9|															   |28  AVDD
//	(11~) PC0  10|															   |27  PD7 (VREF)
//	 (12) PC1  11|															   |26  PD6
//	 (13) PC2  12|															   |25  PD5 (A5)
//			     + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
//		   			13   14   15   16   17   18   19   20   21   22   23   24
//
//	                PC3  VDD  GND  PC4  PC5  PC6  PC7  PD0  PD1  PD2  PD3  PD4
//				   (10~*)		   (1)	(0)	 (4)	   (A0) (A1) (A2) (A3) (A4)

Let me untabify that for you...

// ATMEGA4809 / ARDUINO
//
//                      SCL  SDA
//                     (A5*)(A4*)      (7)  (2)            (R)      (3~) (6~)
//                 PA4  PA3  PA2  PA1  PA0  GND  VDD  UPDI PF6  PF5  PF4  PF3
//
//                  48   47   46   45   44   43   42   41   40   39   38   37
//              + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
//        PA5   1|                                                             |36  PF2
//        PA6   2|                                                             |35  PF1 (TOSC2)
//        PA7   3|                                                             |34  PF0 (TOSC1)
//   (9~) PB0   4|                                                             |33  PE3 (8)
//  (10~) PB1   5|                                                             |32  PE2
//   (5~) PB2   6|                                                             |31  PE1
//        PB3   7|                          48pin QFN                          |30  PE0
//   (Tx) PB4   8|                                                             |29  GND
//   (Rx) PB5   9|                                                             |28  AVDD
//  (11~) PC0  10|                                                             |27  PD7 (VREF)
//  (12) PC1  11|                                                              |26  PD6
//  (13) PC2  12|                                                              |25  PD5 (A5)
//               + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
//                  13   14   15   16   17   18   19   20   21   22   23   24
//
//                  PC3  VDD  GND  PC4  PC5  PC6  PC7  PD0  PD1  PD2  PD3  PD4
//                 (10~*)          (1)  (0) (4)    (A0) (A1) (A2) (A3) (A4)

Ugh, that pins_arduino.h looks like there was a war between tabs and spaces and everyone lost.

Well, crap. The ugly picture doesn't agree with the tables in pins_arduino.h :frowning:

Picture...
//  (11~) PC0  10|
//   (12) PC1  11|
//   (13) PC2  12|

Table:
const uint8_t PROGMEM digital_pin_to_port[] = {
  :
    PE, // 11 PE0
    PE, // 12 PE1
    PE, // 13 PE2
  :

There's also something screwy with the Arduino pin labels along the top. They all seem to be shifted over one to the right but the A5* and A4* are just wrong.

ATmega4809 pinout spreadsheet - I find it useful to create these when I'm learning about a new chip...

FIRST Issue, with corrected (?) table

// ATMEGA4809 / ARDUINO
//
//                      SCL  SDA
//                     (A5*)(A4*) (7)  (2)                 (R)  (3~) (6~)
//                 PA4  PA3  PA2  PA1  PA0  GND  VDD  UPDI PF6  PF5  PF4  PF3
//
//                  48   47   46   45   44   43   42   41   40   39   38   37
//              + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
//        PA5   1|                                                             |36  PF2
//        PA6   2|                                                             |35  PF1 (TOSC2)
//        PA7   3|                                                             |34  PF0 (TOSC1)
//   (9~) PB0   4|                                                             |33  PE3 (8)
//  (10~) PB1   5|                                                             |32  PE2 (13)
//   (5~) PB2   6|                                                             |31  PE1 (12)
//        PB3   7|                          48pin QFN                          |30  PE0 (11~)
//   (Tx) PB4   8|                                                             |29  GND
//   (Rx) PB5   9|                                                             |28  AVDD
//        PC0  10|                                                             |27  PD7 (VREF)
//        PC1  11|                                                             |26  PD6
//        PC2  12|                                                             |25  PD5 (A5)
//               + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
//                  13   14   15   16   17   18   19   20   21   22   23   24
//
//                  PC3  VDD  GND  PC4  PC5  PC6  PC7  PD0  PD1  PD2  PD3  PD4
//                                 (1)  (0)  (4)       (A0) (A1) (A2) (A3) (A4)

Exciting news! Finally!

I think putting it in a different hardware package makes sense - there is virtually no code that can be shared between them.

// ATMEGA4809 / ARDUINO
//                   (24, (21, (20,                          (40, (3~, (6~, (36,
//                   Tx0) SCL) SDA) (7)  (2)                 nRST)Rx2) Tx2) NINA)
//                   PA4  PA3  PA2  PA1  PA0  GND  VDD  UPDI PF6  PF5  PF4  PF3
//
//                    48   47   46   45   44   43   42   41   40   39   38   37
//                + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
// (23,Rx0) PA5   1| NINA                                                        |36  PF2 (35,NINA)
//(28,NINA) PA6   2|                                                             |35  PF1 (38,TOSC2)
//(29,NINA) PA7   3|                                                             |34  PF0 (37,TOSC1)
//     (9~) PB0   4|                       48pin QFN                             |33  PE3 (8,A11)
//    (10~) PB1   5|                                                             |32  PE2 (13,A10)
//     (5~) PB2   6|                                                             |31  PE1 (12,A9)
// (30,IMU) PB3   7|                                                             |30  PE0 (11~,A8)
// (27,Tx3) PB4   8| EDGB              EDGB is 32u4 USB bridge                   |29  GND
// (26,Rx3) PB5   9| EDGB              NINA is WiFi                              |28  AVDD
//(32,MOSI) PC0  10|                   IMU is Inertial Measurement Unit          |27  PD7 (39,A7)
//(33,MISO) PC1  11|                                                             |26  PD6 (25,LED_BUILTIN)
// (34,SCK) PC2  12|                   USART2 is not set up                      |25  PD5 (19,A5)
//                 + ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ +
//                    13   14   15   16   17   18   19   20   21   22   23   24
//
//                    PC3  VDD  GND  PC4  PC5  PC6  PC7  PD0  PD1  PD2  PD3  PD4
//                    (22,           (1,  (0,  (4)  (31, (14, (15, (16, (17, (18,
//                    nSS)           Tx1) Rx1)      IMU) A0)  A1)  A2)  A3)  A4)

Some questions remain:

Is Slave Select not on pin 10? If it is on 22 then where will that be available at?

USART2 seems to be an alt on pins 3 and 6, why is it not set up with the serial library.

Is Slave Select not on pin 10? If it is on 22 then where will that be available at?

Perhaps it is not available. That would prevent the board from being used as an SPI slave, and sidestep the issue that occasionally comes up with "You can't use pin10 as an input if you're using the SPI interface, even if you're using a pin other than pin10 for chip select." (although it seems that the 4809 SPI controller has other ways around that, anyway.)

USART2 seems to be an alt on pins 3 and 6, why is it not set up with the serial library.

Sheesh. Serial to the USB, separate Serial on pin0/1, separate Serial to the WiFi, and you want MORE? Hmmph! Maybe they were worried about using up that extra RAM all on infrastructure...
Waiting for schematic, I guess...

I have successfully made the LED on my Xplained Pro 4809 board blink, using the Uno2018 core!

Add to /packages/arduino/hardware/megaavr/1.6.23/boards.txt:

##############################################################

xpro4809.name=Atmel Xplained 4809 Pro

xpro4809.vid.0=0x03eb
xpro4809.pid.0=0x2111

xpro4809.upload.tool=avrdude
xpro4809.upload.protocol=xplainedpro_updi
xpro4809.upload.maximum_size=37168
xpro4809.upload.maximum_data_size=6144
xpro4809.upload.speed=115200

xpro4809.build.mcu=atmega4809
xpro4809.build.f_cpu=16000000L
xpro4809.build.board=AVR_UNO_WIFI_REV2
xpro4809.build.core=arduino
xpro4809.build.variant=uno2018
#xpro4809.build.extra_flags=-B{runtime.tools.atpack.path}/gcc/dev/{build.mcu}

xpro4809.bootloader.tool=avrdude
xpro4809.bootloader.SYSCFG0=0xC9
xpro4809.fuses.file=fuses_4809.bin

menu.mode=Registers emulation
xpro4809.menu.mode.on=ATMEGA328
xpro4809.menu.mode.on.build.extra_flags=-DUNO_WIFI_REV2_328MODE
xpro4809.menu.mode.off=None (ATMEGA4809)
##############################################################

(with this, you have to manually look up pin equivalents and a bunch of stuff may not work, but it's just a quick hack...)

Sigh. Max digitalWrite pin-toggle speed down to less than 100kHz.