Long, long time ago I had flashed the bootloader of my Funduino UNO.
When listing my USB devices it would appear as follows:
Bus 002 Device 017: ID 03eb:2042 Atmel Corp. LUFA Keyboard Demo Application
I had flashed a firmware to get an alternative to the makeymakey board with my own shield (basically with high-imedance resistors only). So I could not flash the ATmega328P microcontroller (in the socket) via the serial interface which is usually provided via the USB of the ATmega16U2. And unfortunately I didn’t have the old shield available anymore and the controller was constantly putting out data on the HID keyboard device which was quite annoying!
This page on sparkfun explains what a bootloader is, what it does and how it basically works: https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader
Burning the bootloader via the Arduino IDE failed:
I wasn’t too sure if my AVRISP mkII was working correctly. I remembered that I’d has issues with it before – and I hadn’t used it for a long, long time!
Same error when trying to talk to avrdude directly via command line:
avrdude -c avrispmkII -p m16u2 avrdude: stk500v2_command(): command failed avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: Target not detected avrdude: initialization failed, rc=-1 Double check connections and try again, or use -F to override this check. avrdude done. Thank you.
Similar error for the ATmega328P with the other connector (using “avrdude -c avrispmkII -p m328p”). How about adding the port and verbose options?
$ avrdude -c avrispmkII -p m328p -P usb -v avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch System wide configuration file is "/etc/avrdude.conf" User configuration file is "/home/maehw/.avrduderc" User configuration file does not exist or is not a regular file, skipping Using Port : usb Using Programmer : avrispmkII avrdude: usbdev_open(): Found AVRISP mkII, serno: 1337DEADBEEF AVR Part : ATmega328P Chip Erase delay : 9000 us PAGEL : PD7 BS2 : PC2 RESET disposition : dedicated RETRY pulse : SCK serial program mode : yes parallel program mode : yes Timeout : 200 StabDelay : 100 CmdexeDelay : 25 SyncLoops : 32 ByteDelay : 0 PollIndex : 3 PollValue : 0x53 Memory Detail : Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00 signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00 Programmer Type : STK500V2 Description : Atmel AVR ISP mkII Programmer Model: AVRISP mkII Hardware Version: 1 Firmware Version Master : 1.12 Vtarget : 0.0 V SCK period : 4.00 us (...)
Relevant info: “-vvvv” gives a very verbose mode. Let’s assume my AVRISP mkII is broken. How to proceed? I’ve still got a working Arduino Leonardo lying around – let’s try to use it as an ISP: ArduinoISP – https://www.arduino.cc/en/Tutorial/ArduinoISP
Before loading the ArduinoISP sketch and resetting the board:
Bus 002 Device 023: ID 2341:8036 Arduino SA Leonardo (CDC ACM, HID)
Bus 002 Device 024: ID 2341:0036 Arduino SA
The two Arduino board are connected with the following pins:
- power supply 5V and GND from the programmer to the target Arduino
- SPI interface (MOSI on target pin 11, MISO on target pin 12, CLK on target pin 13)
- reset pin of the target Arduino with a controlling GPIO of the programmer Arduino
Checkout the following diagram:
If pins with the same numbers were connected with each other – like those SPI pins – wouldn’t this conflict? If MISO was connected to MISO and MOSI was connected to MOSI? Both controllers might drive the same line?
It probably would! I have stumbled across the logic in the ArduinoISP sketch and had to define:
[Comment: “Uncomment following line to use the old Uno style wiring (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due…”]
Avrdude didn’t complain about any wrong signatures anymore. I used:
$ avrdude -P /dev/ttyACM0 -c stk500v1 -b 19200 -F -v -v -p m328p
Back to the Arduino IDE, finally:
In a next step I compiled and downloaded the simple Blink example, that worked as well. Let’s try to unplug the Arduino Leonardo (the Arduino functioning as a programmer) and replug the USB connector to the Funduino/Arduino UNO. The LED still blinks after startup, however the UNO is still not available as a serial device to be programmed, but still the HID keyboard. The bootloader/firmware of the ATmega16U2 still needs to be flashed. The ATmega16U2 acts as a USB-serial bridge between the PC and the ATmega328P microcontroller.
Resetting the Arduino UNO connects the device in a different mode:
Bus 002 Device 062: ID 03eb:2fef Atmel Corp.
Then the dfu-programmer needs to be executed:
$ sudo dfu-programmer atmega16u2 erase $ sudo dfu-programmer atmega16u2 flash Arduino-usbserial-atmega16u2-Uno-Rev3.hex Validating... 4034 bytes used (32.83%) $ sudo dfu-programmer atmega16u2 reset
… and power-cycling the board finally did the trick for me: the device is back available as serial interface:
Bus 002 Device 064: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
And now it can also be programmed via the Arduino IDE back again! 🙂