1

I have a hand-wired keyboard that uses a Pro Micro board, with an ATmega32u4 chip. I can't seem to flash firmware on it. The commands I've been trying are variations of:

avrdude -p m32U4 -P /dev/ttyACM0 -c avr109 -U flash:w:atreus62.hex

The errors I've been getting begin:

Writing | #######avrdude: error: programmer did not respond to command: set addr
####avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: write block
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  

And end:

#avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
#avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
# | 100% 0.16s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x0d != 0x0c
avrdude: verification error; content mismatch
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: error: programmer did not respond to command: exit bootloader

I'm on Arch Linux. Any ideas?

Jonathan
  • 111
  • 1
  • 5
  • Enable verbose mode, program it once with the IDE, and copy the command line it uses. – Chris Stratton Jun 16 '18 at 01:30
  • What is the IDE? – Jonathan Jun 16 '18 at 01:53
  • And what do you mean by "program it"? Could you just tell me what the avrdude command is? I don't have any IDE installed. – Jonathan Jun 16 '18 at 01:58
  • Also verbose modes -v, -vv, -vvv, and -vvvv don't really seem to affect anything. – Jonathan Jun 16 '18 at 02:02
  • 1
    You are asking a question on the Arduino site, presumably you are familiar with the Arduino tools? If not, give that a try first to validate your hardware and tools setup (before you try to do things the hard way. Use the avrdude and configuration file for it that ships with a modern Arduino IDE version, and let the IDE drive it the first time, with verbose mode selected in the dropdown menu, so you see the suitable command. – Chris Stratton Jun 16 '18 at 02:04
  • I have no idea what the Arduino IDE is all about, but I installed it, and can't really make heads or tails of it. How can I open a hex file with it? If I could get the IDE to program the board, that'd be fine, too, but I have no idea what's going on in this program. – Jonathan Jun 16 '18 at 02:28
  • Also the IDE doesn't seem to have my board listed (pro micro). – Jonathan Jun 16 '18 at 02:30
  • @Jon, how did you create the hex file? ... it is odd that you would not know what an IDE is. – jsotola Jun 16 '18 at 05:01
  • Using QMK. I know what an IDE is, just not what the Arduino IDE is supposed to do with .hex files, or how it's supposed to work. – Jonathan Jun 16 '18 at 12:38

2 Answers2

2

There's two stages to uploading a hex file to a USB-based Arduino - and you're only doing the second stage.

The first stage is to reset the board into the bootloader so it can accept the instructions from the second stage. The IDE normally does that manually for you when you hit the UPLOAD button.

The way these boards are reset is to first open the CDC/ACM port and set the baud rate to 1200, then close the port again. That triggers the code to reset the board into the bootloader.

You can probably do it using the stty tool in Linux:

$ stty -F /dev/ttyACM0 speed 1200
$ stty -F /dev/ttyACM0 speed 115200
$ avrdude -p m32U4 -P /dev/ttyACM0 -c avr109 -U flash:w:atreus62.hex

The second stty may not actually be needed, but it's good to reset the baud rate to a normal value ready for uploading. I don't have a board to hand right now to test it though.

Majenko
  • 105,095
  • 5
  • 79
  • 137
  • Those commands don't seem to help, sadly. They both return 9600, if that's at all helpful. I'm still getting "programmer did not respond" errors. – Jonathan Jun 16 '18 at 13:41
  • 1
    The return value is the value it was before changing it. The second should return 1200 not 9600. You can try using stty -F /dev/ttyACM0 ospeed 1200 ispeed 1200 instead. – Majenko Jun 16 '18 at 13:42
  • That doesn't seem to help either, I'm afraid. – Jonathan Jun 16 '18 at 20:09
  • 1
    Have you had it working in the IDE at all? – Majenko Jun 16 '18 at 20:10
  • I'm at a loss for how to upload .hex files to a chip using the IDE. (And furthermore the IDE is almost totally useless to me, since the UI isn't HiDPI-friendly.) – Jonathan Jun 17 '18 at 15:22
  • You don't upload hex files with the IDE. You write code, compile it, and upload that. Try the Blink example. – Majenko Jun 17 '18 at 15:22
  • @Jon The point of the IDE and the reason we're all harping on it is that success in using the IDE's automation to upload trivial example code you aren't interested in shows you the commands you can then use to upload your custom hex file. It lets you benefit from the work someone else put into figuring out how to do this, rather than having to figure it out again from scratch. There's more wrong than right with the Arduino IDE when it comes to actual software development, but what it is good at is getting trivial code into a chip without spending a day reading documentation. – Chris Stratton Jun 17 '18 at 18:44
  • Also it confirms that your board is actually working and able to accept code. Some cheap chinese clones come without a bootloader. – Majenko Jun 17 '18 at 18:45
  • If I can't upload hex files with the IDE, though, how can I use it? The codebase that generates my hex files is fairly complex, and scattered in a bunch of files across QMK. There's a real network of includes, env vars, and makefile instructions that I, as a non-C programmer, can't make sense of. Trying to put this all together in a way that the IDE will understand seems incredibly complicated. So I think everyone's advice to use the IDE is well-intentioned, but it won't help me just get this already-compiled hex file onto my board, which should be a simple task. – Jonathan Jun 18 '18 at 15:57
  • We're not telling you to use the IDE to complete your task. We are telling you to use the IDE to test that the board and everything is functional. Once that is confirmed we can then move on to more low-level things. – Majenko Jun 18 '18 at 16:03
  • @Majenko you just saved my day, thank you! Couldn't get QMK to flash to my pro micro using any of the normal tooling, but setting ospeed and ispeed explicitly caused it to magically work. For the record I'm on OSX. – RobertMcReed Aug 14 '21 at 23:24
2

I had the same issue, and it was caused by udev, I found the answer here

It's some obscure bug

Tweaking udev rules solved the problem for me, now all is good, here is the procedure: https://learn.adafruit.com/adafruit-arduino-ide-setup/linux-setup#udev-rules

  • Had the same issue, and this fixed it for me! (mostly - I still had to use the stty commands from Majenko's answer, and run the upload a couple of times in order to get it working... but it worked!) It's a bit difficult to find this answer... – codermonkeyfuel Feb 24 '19 at 03:25