Problems uploading to Blend Micro via direct invocation of avrdude


#1

My apologies if I missed a relevant thread. I referred to the Blend Micro’s boards.txt to build the command line below. However, connectivity is intermittent and despite properly detecting the chip programming does not start:

avrdude -p m32u4 -P /dev/ttyACM0 -b 57600 -c avr109 -F -U flash:w:main.hex:i

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding

avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = ""; type = 
    Software Version = .; Hardware Version = .
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x08db09
avrdude: Expected signature for ATmega32U4 is 1E 95 87
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader

avrdude done.  Thank you.

Each invocation is essentially the same.


#2

I remembered there’s a reset button and I was able to get it to upload properly after messing with it a few times, and now it reliably uploads after pressing the reset button. However, my program that is “while (1);” disables the CDC ACM endpoint - is this intentional? How do I keep it active so that I can reset the device from software?


#3

Where did you find the while(1); Forgive me I have no impress about this and have never tried the command line instruction.


#4

No problem, it’s attached below. It doesn’t make use of Arduino or its libraries. I’ve since discovered the behavior where the CDC ACM endpoint disappears is intentional.

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

int
main(void)
{
	while (1);
}

Makefile:

MCU=atmega32u4
F_CPU=16000000
F_USB=
PORT=/dev/ttyACM0
BAUD=57600

CC=avr-gcc
CF=-mmcu=${MCU} -DF_CPU=${F_CPU} -Os -std=c99 -Wall -pedantic
OC=avr-objcopy

SRC=$(wildcard *.c)
OBJ=${SRC:.c=.o}
BIN=main

.phony: all clean

${BIN}.hex: ${BIN}.elf *.h
	${OC} -O ihex $< [email protected]

${BIN}.elf: ${OBJ}
	${CC} -o [email protected] $^

%.o: %.c
	${CC} ${CF} -c -o [email protected] $<

program:
	avrdude -p m32u4 -P ${PORT} -b 57600 -c avr109 -D -U flash:w:${BIN}.hex:i

clean:
	rm ${OBJ} ${BIN}.elf ${BIN}.hex

#5

I see. The Arduino sketch is the most top layer of a program. Actually, the Arduino code execute as below:

int main(void)
{
    init();

    initVariant();

#if defined(USBCON)
    USBDevice.attach();
#endif
	
    setup(); // The setup() function implemented in your sketch
    
    for (;;) {
        loop(); // The loop() function implemented in your sketch

        if (serialEventRun) serialEventRun();
    }
        
    return 0;
}

View the Arduino core source code here. You should have seen that the USB CDC is initialized before the setup() function is executed. But your code did nothing to initialize the USB stack.

Besides, to use the avrdude, you must implement the corresponding protocol on the BlendMicro side. Since the Arduino sketch can detect the avrdude initial command and then it makes itself enter the bootloader, so that the bootloader can communicate with the avrdude to exchange data and command to deploy the application.