Nano Every with MegsCoreX Request 'upload' failed

I'm trying to use MegaCoreX/ATmega4809 to upload to a Nano Every and after compilation completes successfully I get a message that says "Request 'upload' failed". I need to use MegaCoreX because I need one more GPIO pin and from what I've read I have to use this to use the AREF pin as GPIO.

The sketch compiles, uploads, and works fine (except for pin 39/aref) if I select Nano Every.

Get Board info returns correct info for either selection.

IDE is 2.3.3, Linux Mint 20.3 Any assistance greatly appreciated.


FQBN: MegaCoreX:megaavr:4809
Using board '4809' from platform in folder: /home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3
Using core 'coreX-corefiles' from platform in folder: /home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3

Detecting libraries used...
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega4809 -DARDUINO_ARCH_MEGAAVR -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles/api/deprecated -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/variants/48pin-standard /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp -o /dev/null
Alternatives for EEPROM.h: [EEPROM@2.1]
ResolveLibrary(EEPROM.h)
  -> candidates: [EEPROM@2.1]
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega4809 -DARDUINO_ARCH_MEGAAVR -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles/api/deprecated -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/variants/48pin-standard -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/libraries/EEPROM/src /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp -o /dev/null
Alternatives for Bounce2.h: [Bounce2@2.71]
ResolveLibrary(Bounce2.h)
  -> candidates: [Bounce2@2.71]
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega4809 -DARDUINO_ARCH_MEGAAVR -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles/api/deprecated -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/variants/48pin-standard -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/libraries/EEPROM/src -I/home/tdc/Documents/Arduino/libraries/Bounce2/src /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp -o /dev/null
Alternatives for elapse.h: [Elapse@1.1.0]
ResolveLibrary(elapse.h)
  -> candidates: [Elapse@1.1.0]
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega4809 -DARDUINO_ARCH_MEGAAVR -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles/api/deprecated -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/variants/48pin-standard -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/libraries/EEPROM/src -I/home/tdc/Documents/Arduino/libraries/Bounce2/src -I/home/tdc/Documents/Arduino/libraries/elapse /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp -o /dev/null
Using cached library dependencies for file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/Lightlib.cpp
Using cached library dependencies for file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/flash.cpp
Using cached library dependencies for file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/newMainDetection.cpp
Using cached library dependencies for file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/oldMainDetection.cpp
Using cached library dependencies for file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/trackrelay.cpp
Using cached library dependencies for file: /home/tdc/Documents/Arduino/libraries/Bounce2/src/Bounce2.cpp
Using cached library dependencies for file: /home/tdc/Documents/Arduino/libraries/elapse/elapse.cpp
Generating function prototypes...
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega4809 -DARDUINO_ARCH_MEGAAVR -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles/api/deprecated -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/variants/48pin-standard -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/libraries/EEPROM/src -I/home/tdc/Documents/Arduino/libraries/Bounce2/src -I/home/tdc/Documents/Arduino/libraries/elapse /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp -o /tmp/3914730378/sketch_merged.cpp
/home/tdc/.arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/3914730378/sketch_merged.cpp
Compiling sketch...
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mrelax -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega4809 -DARDUINO_ARCH_MEGAAVR -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles/api/deprecated -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/cores/coreX-corefiles -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/variants/48pin-standard -I/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/libraries/EEPROM/src -I/home/tdc/Documents/Arduino/libraries/Bounce2/src -I/home/tdc/Documents/Arduino/libraries/elapse /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp -o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp.o
Using previously compiled file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/Lightlib.cpp.o
Using previously compiled file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/flash.cpp.o
Using previously compiled file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/newMainDetection.cpp.o
Using previously compiled file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/oldMainDetection.cpp.o
Using previously compiled file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/trackrelay.cpp.o
Compiling libraries...
Compiling library "EEPROM"
Compiling library "Bounce2"
Using previously compiled file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/libraries/Bounce2/Bounce2.cpp.o
Compiling library "Elapse"
Using previously compiled file: /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/libraries/elapse/elapse.cpp.o
Compiling core...
Using precompiled core: /tmp/arduino/cores/55d993ceb577e4287f56613c24a6bf50/core.a
Linking everything together...
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -Os -g -flto -fuse-linker-plugin -mrelax -Wl,--gc-sections -Wl,--section-start=.text=0x0 -mmcu=atmega4809 -o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino.elf /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/Lightlib.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/MMRC_depot_grade_xing.ino.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/flash.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/newMainDetection.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/oldMainDetection.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/sketch/trackrelay.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/libraries/Bounce2/Bounce2.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/libraries/elapse/elapse.cpp.o /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/../../cores/55d993ceb577e4287f56613c24a6bf50/core.a -L/tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4 -lm
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino.elf /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino.eep
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -R .eeprom /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino.elf /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino.hex
chmod +x /home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/scripts/create_disassembler_listing.sh
/home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/scripts/create_disassembler_listing.sh /home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objdump "--disassemble --source --line-numbers --demangle --section=.text" /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino.elf /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino_atmega4809_16000000L.lst

Using library EEPROM at version 2.1 in folder: /home/tdc/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.3/libraries/EEPROM 
Using library Bounce2 at version 2.71 in folder: /home/tdc/Documents/Arduino/libraries/Bounce2 
Using library Elapse at version 1.1.0 in folder: /home/tdc/Documents/Arduino/libraries/elapse 
/home/tdc/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-size -A /tmp/arduino/sketches/D4C78EF87516FC519F7207A2CF9E52B4/MMRC_depot_grade_xing.ino.elf
Sketch uses 9133 bytes (18%) of program storage space. Maximum is 49152 bytes.
Global variables use 503 bytes (8%) of dynamic memory, leaving 5641 bytes for local variables. Maximum is 6144 bytes.

I think you misunderstood what you read. This is wrong.

Regarding the Arduino megaavr core file for variants/nona4809/pins_arduino.h you can see that there is no mention of the AREF and Reset pins as GPIO and they are listed as Reserved Pins.

However, in the MegaCoreX variants file variants/nano-every/pins_arduino.h it gives PD7/VREF/AIN7 and PF6/RESET as useable pins. Given this, I'm not certain I understand the compiling issues when selecting Nano Every pin out as opposed to the 48 pin standard for the ATmega4809.

@tdc218 can you provide a minimal example program which demonstrates the issue?

The use of the RESET pin may require some fuse changes from what is standard and there is input capacitance on VREF which will slow down its performance a digital pin. These issues are discussed in Tom Almy's Nano Every Supplement to Far Inside the Arduino.

This code is the standard blink without delay with the aref pin added. The problem is not the code. The problem is that it will upload and run (except no digital output on aref) when board type == Nano Every but won't upload when board type == MegaCoreX/AtMega4809

/*
  Blink without Delay
 (snip)

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay
*/

const int ledPin = LED_BUILTIN;  // the number of the LED pin
const int testPin = 39;   // AREF pin on the Nano Every, requires MegaCoreX package

int ledState = LOW;  // ledState used to set the LED

unsigned long previousMillis = 0;  // will store last time LED was updated

const long interval = 1000;  // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
  pinMode(testPin, OUTPUT);
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    digitalWrite(ledPin, ledState);
    digitalWrite(testPin,ledState);
  }
}

Hi @tdc218.

I'm going to ask you to provide the full verbose output from an upload attempt.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Uncheck the box next to Show verbose output during: compile in the "Preferences" dialog.
  3. Check the box next to Show verbose output during: ☐ upload.
  4. Click the "OK" button.
    The "Preferences" dialog will close.
  5. Attempt an upload, as you did before.
  6. Wait for the upload to fail.
  7. You will see an "Upload error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
  8. Open a forum reply here by clicking the "Reply" button.
  9. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
  10. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the error output from the upload into the code block.
  11. Move the cursor outside of the code block markup before you add any additional text to your reply.
  12. Click the "Reply" button to post the output.

I can not confirm you findings. When I select the board type as Nano Every and I run your sketch with an led connected to the VREF pin and a resistor to ground, I see it blinking in sync with the built in led.

Are you certain the led on the VREF pin is wired correctly?

EDIT:
When using the Arduino megaavr core, the sketch compiles without error even though pin39 is not a valid pin number, but as expected, does not blink the led on VREF.

should be

const int testPin = PIN_PD7;   // AREF pin on the Nano Every, requires MegaCoreX package

With that change, an LED connected to the AREF pin blinks.

It works even without that change.

From MegaCoreX variants/nano-every/pins_arduino.h

#define PIN_PD7 39

When selecting the nano_every pinout that's true. But the OP is selecting the default 48pin_standard pinout, and PIN_PD7 is 29 there. Considering that it appears that they're using an actual Nano Every, I wonder if they've simply chosen the wrong pinout option?

Yes, but as I read this thread, @tdc218 was only doing that because they could not get output on the VREF pin with a Nano Every pinout selected.

I was under the impression that they'd tried FQBNs of arduino:megaavr:nona4809 and MegaCoreX:megaavr:4809 (and the latter defaults to pinout=48pin_standard) but hadn't ever tried MegaCoreX:megaavr:4809:pinout=nano_every. Perhaps I'm mistaken, but I don't find any mention of that searching through the thread.

Edit: anyhow, I was able to upload a "blink LED on the AREF pin of a Nano Every" sketch using the MegaCoreX core and defining the output pin as PIN_PD7 with the following arduino-cli command line:

arduino-cli upload -vtb MegaCoreX:megaavr:4809:pinout=nano_every --input-file=/home/me/tmp/blink.hex --port /dev/ttyACM0

Thank you everyone for trying to figure this out.

The full verbose output was attached to my initial post. There are no errors in it, all I get is "request 'upload' failed" in the box where the "copy error messages" button is.

I am confident that I have the correct pin and led wired up correctly but we haven't even got to that point yet 'cause I can't get the sketch to upload.

Alternatively, if there is some way to use the aref pin as gpio with board type == nano every, I'd be all for that.

Edit:

I don't know what any of this means. I'm using the IDE and selecting board MegaCoreX -> Atmega4809

That is what I found and reported in post #6.

I am using IDE 1.8.19, MegaCoreX Version 1.1.2 and a Windows 10 computer.
Board 4809 PinOut Nano Every

EDIT: Updated MegaCoreX to v1.1.3. Blink code still compiles, loads, and shows ouptut on AREF pin.

Does not work for me.

I have no such selection. Where are you finding this?

Nano Every is one of the pinouts available in the tools pull down with MegaCoreX.

Board Selection

That was it! I had glanced at pinouts but didn't notice the Nano Every setting. Many thanks for all of the assistance.