noopkat / avrgirl-arduino

:girl: :pager: A NodeJS library for flashing compiled sketch files to Arduino microcontroller boards.
MIT License
506 stars 129 forks source link

Is it possible to add ATmega4809 support? #252

Closed seisfeld closed 1 year ago

seisfeld commented 2 years ago

Description

Is it possible to add support for the ATmega4809 series of Chips? I have a custom made PCB with that MCU. I use this Board Support Package in the Arduino IDE. The ATmega4809 has an Optiboot Bootloader (so not using UPDI) listening on UART0 and flashing sketches with the Arduino IDE (avrdude) works perfectly. Since our userbase is not very tech savvy I'd love to use the webserial demo to flash pre built hex files. I can get it working perfectly using a vanilla Arduino Uno but no dice with the ATmega4809.

I managed to modify the UNO entry in avrgirl so the upload finishes without an error but after flashing the sketch does not start. Re-flashing with the Arduino IDE afterwards works fine though.

Here is what I modified:

diff --git a/dist/avrgirl-arduino.global.js b/dist/avrgirl-arduino.global.js
index 78e4504..21cbc24 100644
--- a/dist/avrgirl-arduino.global.js
+++ b/dist/avrgirl-arduino.global.js
@@ -182,9 +182,9 @@ var boards = [
   {
     name: 'uno',
     baud: 115200,
-    signature: Buffer.from([0x1e, 0x95, 0x0f]),
+    signature: Buffer.from([0x1e, 0x96, 0x51]),
     pageSize: 128,
-    numPages: 256,
+    numPages: 384,
     timeout: 400,
     productId: ['0x0043', '0x7523', '0x0001', '0xea60', '0x6015'],
     productPage: 'https://store.arduino.cc/arduino-uno-rev3',
@@ -14929,7 +14929,7 @@ stk500.prototype.bootload = function (stream, hex, opt, done) {
     this.setOptions.bind(this, stream, parameters, opt.timeout),
     this.enterProgrammingMode.bind(this, stream, opt.timeout),
     this.upload.bind(this, stream, hex, opt.pageSize, opt.timeout),
-    this.verify.bind(this, stream, hex, opt.pageSize, opt.timeout),
+    //this.verify.bind(this, stream, hex, opt.pageSize, opt.timeout),
     this.exitProgrammingMode.bind(this, stream, opt.timeout)
   ], function(error){
        return done(error);

So changed the signature, increased the flash size and disabled the verify. With verification enabled there are errors after flashing. Which i expected because verify does not work with avrdude either.

Any clues why it does not work with the ATmega4809? Any hint greatly appreciated. Thanks!

Expected behaviour

Flash an ATmega4809 like an UNO.

Actual behaviour

Sketch does not start after flashing. So something is not working correctly.

Avrgirl Arduino version

v5.0.1

Using the webserial demo.

Arduino Board being used

Custom PCB with ATmega4809.

Log output, if available

There are no errors in the log after modification of the UNO entry as per description above.