Upload fails when almost finished

I am trying to upload Marlin 1.9 to an Anet A6 3D printer. When the upload appears to be nearly finished it fails saying (repeatedly) the “the programmer is not responding”.I wonder if the problem is that my hex file is too big for the available memory, as the reason I am trying to upload it, is to add a feature to the standard setup. The Anet A6 control board uses an ATMega 1284p processor which should, I think, have just enough memory if the Optiboot bootloader is installed, but I don’t know which bootloader the A6 uses. Another reason that I think this is the problem is that, after this failure, the A6 will not boot up, so I suspect the bootloader has gone. I am reluctant to just try to reflash the bootloader, as I have already tried all this on another board, which is now completely bricked after tryin to reflash Optiboot.

Here is the output from the Marlin compilation. Unfortunately I did not copy the output from the upload, though I took a screenshot, but there doesn’t seem to be any way to attach the image file.

Processing sanguino_atmega1284p (platform: atmelavr; board: sanguino_atmega1284p; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR > Sanguino ATmega1284p (16MHz)
HARDWARE: ATMEGA1284P 16MHz 16KB RAM (127KB Flash)
Converting Marlin.ino
Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 16 compatible libraries
Scanning dependencies…
Dependency Graph
|-- 0.4
| |-- 1.0
| |-- 1.0
|-- <LiquidCrystal_I2C>
| |-- 1.0
|-- 2.5.1
| |-- 1.0
|-- 0.1.1
|-- 1.1.3
|-- <30aa480>
| |-- 1.0
|-- 0.7.0
|--
| |-- 1.0
|-- 1.0
|-- 1.0
|-- 1.0
Compiling .pioenvs/sanguino_atmega1284p/src/Marlin.ino.cpp.o
Linking .pioenvs/sanguino_atmega1284p/firmware.elf
Checking size .pioenvs/sanguino_atmega1284p/firmware.elf
Memory Usage → Redirecting...
DATA: [=== ] 28.7% (used 4708 bytes from 16384 bytes)
PROGRAM: [==========] 98.6% (used 128248 bytes from 130048 bytes)
======================================== [SUCCESS] Took 5.30 seconds
======================================== [SUMMARY]
Environment megaatmega2560 [SKIP]
Environment megaatmega1280 [SKIP]
Environment at90USB1286_CDC [SKIP]
Environment at90USB1286_DFU [SKIP]
Environment melzi [SKIP]
Environment melzi_optiboot [SKIP]
Environment rambo [SKIP]
Environment sanguino_atmega644p [SKIP]
Environment sanguino_atmega1284p [SUCCESS]
Environment teensy20 [SKIP]

Further to my post, here is a transcription of the output from avrdude when it tries to upload the firmware, which I hope will help diagnose the problem. It appears that avrdude outputs 50 #s when reading the file but fails after outputing 49#s when writing it.

Configuring upload profile…
AVAILABLE: arduino
CURRENT: upload_protoco; = arduino
Looking for upload port…
Use manually specified: /dev/cu.wchusbserial1410
Uploading .pioenvs/sanguino_atmega1284p/firmware.hex

avrdude: AVR device initialised and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9705 (probably m1284p)
avrdude:reading input file “.pioenvs/sanguino_atmega1284p/firmware.hex”
avrdude: writing flash (128248 bytes):

Writing | #################################################avrdude:stk500_rec(): programmer is not responding
avrdude:stk500_rec(): programmer is not responding
avrdude:stk500_rec(): programmer is not responding
etc.

We’d need to know with which exact settings you’ve flashed the bootloader. The chip should always be reprogrammable with an AVR programmer.

Can you upload via the pio run -t program command? It should not write a bootloader, just the bare firmware. Otherwise if you want to make sure the size of the firmware is the problem, can you reduce the size by disabling some features and uploading?

Thanks for your response.
I would try your suggestion, but I don’t know how to use the “pio run -t program” command. Could you tell me how to do this or give a link to a description?
Hugh McIntyre

Open a “PIO Terminal” (here) from the lower status bar and type the command in there. As I said, be aware that if you program it like this, it won’t have a normal USB bootloader anymore, but you can re-programm the bootloader anytime again using e.g. the Arduino IDE.

Thanks again. I tried this, first with “pio run -t program” , just to check that wouldn’t work, and then with “pio run -t .pioenvs/sanguino_atmega1284p/firmware.hex” which I thought might. I got the output below. I had my board connected to my Mac by its USB port when I did this. However the board still doesn’t work when connected to the printer, but I wasn’t surprised by this, as the output doesn’t give any indication that anything was uploaded. What am I doing wrong? Should I have connected the board through an ISP? Sorry to be so clueless, but I am completely new to this sort of thing and don’t know the basics.

iMac:Marlin-1.1.x 2 HAJM$ pio run -t program

Processing sanguino_atmega1284p (platform: atmelavr; board: sanguino_atmega1284p; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR > Sanguino ATmega1284p (16MHz)
HARDWARE: ATMEGA1284P 16MHz 16KB RAM (127KB Flash)
Converting Marlin.ino
Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 16 compatible libraries
Scanning dependencies…
Dependency Graph
|-- 0.4
| |-- 1.0
| |-- 1.0
|-- <LiquidCrystal_I2C>
| |-- 1.0
|-- 2.5.1
| |-- 1.0
|-- 0.1.1
|-- 1.1.3
|-- <30aa480>
| |-- 1.0
|-- 0.7.0
|--
| |-- 1.0
|-- 1.0
|-- 1.0
|-- 1.0
Compiling .pioenvs/sanguino_atmega1284p/src/Marlin.ino.cpp.o
Linking .pioenvs/sanguino_atmega1284p/firmware.elf
Checking size .pioenvs/sanguino_atmega1284p/firmware.elf
Memory Usage → Redirecting...
DATA: [=== ] 28.7% (used 4708 bytes from 16384 bytes)
PROGRAM: [==========] 98.6% (used 128248 bytes from 130048 bytes)
Configuring upload protocol…
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port…
Use manually specified: /dev/cu.wchusbserial1410
Programming .pioenvs/sanguino_atmega1284p/firmware.hex
dyld: Library not loaded: /usr/local/opt/libftdi/lib/libftdi1.2.dylib
Referenced from: /Users/HAJM/.platformio/packages/tool-avrdude/bin/avrdude
Reason: image not found
*** [program] Error -6
===================================================================================== [ERROR] Took 5.86 seconds =====================================================================================

============================================================================================= [SUMMARY] =============================================================================================
Environment megaatmega2560 [SKIP]
Environment megaatmega1280 [SKIP]
Environment at90USB1286_CDC [SKIP]
Environment at90USB1286_DFU [SKIP]
Environment melzi [SKIP]
Environment melzi_optiboot [SKIP]
Environment rambo [SKIP]
Environment sanguino_atmega644p [SKIP]
Environment sanguino_atmega1284p [ERROR]
Environment teensy20 [SKIP]
===================================================================================== [ERROR] Took 5.86 seconds =====================================================================================
iMac:Marlin-1.1.x 2 HAJM$
iMac:Marlin-1.1.x 2 HAJM$
iMac:Marlin-1.1.x 2 HAJM$
iMac:Marlin-1.1.x 2 HAJM$
iMac:Marlin-1.1.x 2 HAJM$
iMac:Marlin-1.1.x 2 HAJM$
iMac:Marlin-1.1.x 2 HAJM$
iMac:Marlin-1.1.x 2 HAJM$ pio run -t .pioenvs/sanguino_atmega1284p/firmware.hex

Processing sanguino_atmega1284p (platform: atmelavr; board: sanguino_atmega1284p; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR > Sanguino ATmega1284p (16MHz)
HARDWARE: ATMEGA1284P 16MHz 16KB RAM (127KB Flash)
Converting Marlin.ino
Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 16 compatible libraries
Scanning dependencies…
Dependency Graph
|-- 0.4
| |-- 1.0
| |-- 1.0
|-- <LiquidCrystal_I2C>
| |-- 1.0
|-- 2.5.1
| |-- 1.0
|-- 0.1.1
|-- 1.1.3
|-- <30aa480>
| |-- 1.0
|-- 0.7.0
|--
| |-- 1.0
|-- 1.0
|-- 1.0
|-- 1.0
Compiling .pioenvs/sanguino_atmega1284p/src/Marlin.ino.cpp.o
Linking .pioenvs/sanguino_atmega1284p/firmware.elf
`.pioenvs/sanguino_atmega1284p/firmware.hex’ is up to date.
==================================================================================== [SUCCESS] Took 5.17 seconds ====================================================================================

============================================================================================= [SUMMARY] =============================================================================================
Environment megaatmega2560 [SKIP]
Environment megaatmega1280 [SKIP]
Environment at90USB1286_CDC [SKIP]
Environment at90USB1286_DFU [SKIP]
Environment melzi [SKIP]
Environment melzi_optiboot [SKIP]
Environment rambo [SKIP]
Environment sanguino_atmega644p [SKIP]
Environment sanguino_atmega1284p [SUCCESS]
Environment teensy20 [SKIP]
==================================================================================== [SUCCESS] Took 5.17 seconds ====================================================================================
iMac:Marlin-1.1.x 2 HAJM$

Seems like current installations of openocd don’t install the needed dynamic libraries for MacOS. Can you try to install brew (https://brew.sh/, Installation — Homebrew Documentation) and then brew install openocd? Its dependeny should install the missing library for pio run -t program to go through.

1 Like

Thanks again for your help. I don’t have access to my printer for the next two weeks, but when I do, I will try to install the missing library and post what happens. I take it, from your comment, that I should use the word “program”, not the file name, but I am still not sure whether to connect to my board by USB or through an ISP programmer.

Right the command is just pio run -t program, no filename needed

This. You may attempt also flash the board via USB as you have tried before, but you’ll just run into the problem of out-of-space due to the bootloader again. So I’d try via the ISP programmer. (SPI + RESET + GND)

1 Like

Thanks. I’ll let you know how I get on.

HI Max. I could not get PlatformIO to recognise the port for my USBasp so I could not flash Marlin over the ISP link, but I finally got Marlin to compile and upload to my Anet A6 by using the Arduino IDE + USBasp to upload the Optiboot boot loader to the printer and then uploading Marlin from PlatformIO using the boot loader over the USB link. This final step is what I originally tried and I think it failed because my printer originally had a larger bootloader which didn’t leave enough room for Marlin.

Thanks again for all your help. I’m closing this topic now.