Go Down

Topic: Avrdude not working with Arduino Micro (Read 825 times) previous topic - next topic

dynasample

Hi, I have been using Avrdude for uploading the Arduino software to Duemilanoves and Nanos before.
Now I'm trying to upload using a shell (inside of Pd) but I can't get it to upload to the arduino micro.
What am I doing wrong?

Here's the code:

avrdude -p m32u4 -P /dev/xp/arduremote2-0 -c arduino -b 57600 -D -U flash:w:/"path to file"/arduremote4_micro.ino.hex:i

/dev/xp/arduremote2-0 is the name and location that I have created with a UDEV rule. It is working fine with the Nano using     "avrdude -p atmega328p -P /dev/xp/ardu.... "

The files always come from the temp directory after uploading from the Arduino software which works perfectly fine. "arduremote4_micro" is the name after renaming it.

Thanks for any hints!
Ingo

tf68

#1
Jul 14, 2019, 09:07 pm Last Edit: Jul 14, 2019, 09:13 pm by tf68
You need to start the bootloader by pressing the reset button. If that doesn't work try pressing the button
and using -P/dev/ttyACM0 or whatever it is on your system.
edit: try -cavr109

dynasample

Thanks, tf68!

I had tried the reset button before with no success.
Using /dev/ACM0 doesn't make any difference (with or without reset).
The Arduino actually responds to either address by flasing the LED once when starting the transmission but doesn't actually upload.

Pushing the reset button has not been necessary on any of the other boards or when transmitting to the Micro from the Arduino software.

I'm going to create the file once more even though I had done this before several times.
Maybe something in the programming is wrong that causes it to work from the Arduino but not from avrdude directly? But I had used the same programming for the other boards as well ...


What is -cavr109 and where does it go in the command line?
Does it replace anything else in there?

sterretje

Non-32U4 boards are reset via the DTR line. 32U4 based boards are reset by opening and closing the serial port with a baudrate of 1200 baud.

The IDE does this for you. Below the output of the verbose output during upload

Code: [Select]
Sketch uses 4002 bytes (13%) of program storage space. Maximum is 28672 bytes.
Global variables use 165 bytes (6%) of dynamic memory, leaving 2395 bytes for local variables. Maximum is 2560 bytes.
Forcing reset using 1200bps open/close on port COM6
PORTS {COM1, COM6, } / {COM1, } => {}
PORTS {COM1, } / {COM1, COM7, } => {COM7, }
Found upload port: COM7
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

tf68

Press and release reset.

avrdude -cavr109 -pm32u4 -b57600 -P/dev/ttyACM?

/dev/ttyACM? use the /dev/ttyACM that shows when the bootloader is running, typically will be /dev/ttyACM0


dynasample

#5
Jul 18, 2019, 04:58 pm Last Edit: Jul 18, 2019, 05:06 pm by dynasample
Thanks a lot guys!

Setting the baud rate to 1200 first and then sending to my original message while adding  "-cavr109" did the trick.

It's working perfectly as expected now.   :-)


Ingo

sterretje

Can you post your bash file (or whatever you are using). Both for my learning and for others to learn.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

dynasample

The command is exactly what I had used before with the addition of the "-cavr109". The command is being sent from Pd within something like a hardware box. There is no feedback during programming.

dynasample

OK,

this is getting very strange now:

If I reupload the sketch everything works fine.
The Arduino will restart and go through the programmed startup screen, etc.

However, if I put on the blink program first and then upload it will not upload to the Arduino!
I see the Arduino LEDs receiving something but after a few seconds it goes back to the Blink sketch.
No restarting is happening.

Programming with the Arduino IDE software works fine, though.
I can upload my programming and go beack to blink as many times as I want.

Not so with the command line from the Pd shell.

Something is still wrong.
As mentioned earlier, with my upload I cannot get any feedack.
Even if I add a print command the Arduino seems to be connected exclusively to Avrdude.
The Pd console reports during uploading "[comport]: serial port is not open".
After transmitting it will connect to Pd again normally and work again.

As of now I cannot tell if the sketch was uploaded or not.
I will have to make some change in the startup message to see if it did.

dynasample

#9
Jul 18, 2019, 11:37 pm Last Edit: Jul 18, 2019, 11:51 pm by dynasample
Now I tried a similar sketch with another startup message.
After uploading I got the old startup message.

So it is not uploading!

Eliminated "-D" in the command. No change!

It is doing something and restarting the Arduino but does not accept the code which is working perfectly fine when uploading from the Arduino IDE software.

I'm using 1.82 Arduino software and version 6.3 of avrdude.

When inputting the command into a Debian Bash Console I get this error:

avrdude: stk500_getsync () attempt 1 of 10 not in sync: resp=0x fd
avrdude: stk500_getsync () attempt 2 of 10 not in sync: resp=0x 05
avrdude: stk500_getsync () attempt 3 of 10 not in syn ...
...
...avrdude: stk500_getsync () attempt 10 of 10 not in sync: resp=0x 05

Here's what I'm doing:

avrdude -p m3u24 -P /dev/ttyACM0 -c arduino -b 1200

then wait for a second or two and input:

avrdude -cavr109 -p m32u4 -P /dev/ttyACM0 -c arduino -b 57600 -U flash:w:/"path_to_file"/arduremote_XO.ino.hex:i

tf68

Press and release the reset button.
Then run:
avrdude -cavr109 -pm32u4 -b57600 -P/dev/ttyACM0

This works 100% of the time on my system.
You do not have to fool around with the serial port, pushing the reset starts the booloader.
DO NOT include -carduino in your avrdude command line.

dynasample

#11
Jul 19, 2019, 11:52 am Last Edit: Jul 19, 2019, 11:52 am by dynasample
Thanks, tf68!

It works!
I can get it to upload reliably now by using /dev/ttyACM0 and pressing the reset button beforehand.
The (UDEV) link in the subfolder does indeed not work. However, I can get the ttyACM number. This is important since I have one MICRO and two LEONARDO boards that need to be identified correctly before uploading. The UDEV rule does this as it should. Then I use the number for the ttyACM.


However my problem is that the Micro is inside of a closed box with no access to the reset button.
I cannot add a hardware button on the reset pin because the units and pcbs are already built.

So, I somehow need a command line reset.

Using   avrdude -c arduino -p m32u4 -P /dev/ADM0 -b 1200
seems to work at first glance when looking ar the board but gives me this error:
ioctl ("TIOCMGET"): Input/output error

Using   avrdude -c avr109 -p m32u4 -P /dev/ADM0 -b 1200   returns:

Connecting to programmer
avrdude: butterfly recv(): programmer is not responding
Found programmer: Id = "?"; type =
   Software Version = ?.? Hardware Version = ?.?
avrdude: error: buffered memory access not supported.
Maybe it isn't a butterly/AVR109 but a AVR910 device?
avrdude: initialisation failed, rc=-1
            Double check connections and try again, or use -F to override this check.

avrdude: error: programmer did not respond to command: leave prog mode
avrdude: error: programmer did not respond to command: exit bootloader

avrdude done. Thank you.

(the "?" characters are som unreadable korean looking characters)


I was doing a search for "avrdude command line reset" but only found suggestions for Windows but not Linux.
There must be something since I don't have to push the reset button when uploading from the IDE software.

dynasample

#12
Jul 19, 2019, 03:12 pm Last Edit: Jul 19, 2019, 03:24 pm by dynasample
I have to correct myself for saying "I can get it to upload reliably now by using /dev/ttyACM0 and pressing the reset button beforehand."

It's very sproadic. Sometimes it works - sometomes it doesn't.
Now I can't get it to work anymore at all with the same command that was working earlier.


I press the reset button and send to a shell:

avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/"path_2_file"/"filename".ino.hex:i

This is the exact command that my Arduino IDE software uses for uploading. I used it before and it was working. Now all the sudden it's not working anymore! I tried two Arduinos and the number for the ttyACM0 is corrcect.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

But it won't matter anyway because I cannot do a software reset.
What does the IDE software do to make it work? And why is it a secret that the verbose output doesn't tell you everything that it does during uploading?


OK, this is what it does during compilation:
"Forcing reset using 1200bps open/close on port /dev/ttyACM0"

I tried:   avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -B1200
and       avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -b1200

How do you set 1200bps and open/close?
Is tis the baudrate or the bitclock?

Sterretje had mentioned this already in the beginning.
However, there is no mention about how this is done or what the command is ...

What kind of a manual or help system is this?
Ardunino can do it but doesn't let the users know how to do it?

dynasample

#13
Jul 19, 2019, 05:23 pm Last Edit: Jul 19, 2019, 06:00 pm by dynasample
Here's why it keeps failing:

As soon as I press the reset button the number of the ttyACM changes. Usually it goes up by one but it might also go back and forth between two numbers.

So I'm looking at ttyACM0 and as soon as I send the reset command (see below) I would have to send the programming command to ttyACM1. I havn't tested what happens exactly if this number exists. I'm assuming it takes the next unused number.

So if I see ttyACM0 I need to do a reset with
avrdude -patmega32u4 -carduino -P/dev/ttyACM0 -b1200

Then I can program the Micro with
avrdude -patmega32u4 -cavr109 -P/dev/ttyACM1 -b57600 -D -Uflash:w:/"path_2_file"/"filename".ino.hex:i

Resetting only works with -c arduino while programming works only with -c avr109.


Now it actually works for the first time (with one sinle board)!
At this point I only have to figure out what exactly happens with the numbering if I have 3 boards.

sterretje

1)
To my knowledge, it's your operating system that is responsible for the enumeration of the serial ports.
2)
If you look at the output that I gave in reply #3, the IDE does a scan by talking to every port. It first tried COM1 (and failed) and next COM7 (and succeeded). I do not know where it it's exactly done; maybe successive calls to avrdude or maybe to something else till it succeeds.

PS
You have access to the source code of the IDE ;)
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up