EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: ledtester on June 09, 2019, 06:33:55 am

Title: Reinstall bootloader for an Arduino Pro Micro?
Post by: ledtester on June 09, 2019, 06:33:55 am

Using the Arduino IDE I accidentally uploaded the Blink sketch to an Arduino Pro Micro with the Board set to "Arduino Leonardo". It uploaded, but now the Pro Micro doesn't register its USB serial port when you plug it in.

Can I reset the device back to its standard bootloader? I have a USBASP and an STK-500, and I've comfortable using avrdude.

Thanks!

And another question... what board setting should I use within the Arduino IDE for this device? In the Port menu it shows up as "/dev/ttyACM (Arduino/Genuino Micro)" so I guess I should select "Arduino/Genuino Micro", right?
Title: Re: Reinstall bootloader for an Arduino Pro Micro?
Post by: ebastler on June 09, 2019, 06:44:10 am
Have you tried the "reset twice" procedure already?

https://arduino.stackexchange.com/questions/6702/arduino-pro-micro-clone-not-recognized-flickering-rx-led
https://arduino.stackexchange.com/questions/57651/arduino-pro-micro-bricked
Title: Re: Reinstall bootloader for an Arduino Pro Micro?
Post by: lollandster on June 09, 2019, 07:58:37 am
The pro micro doesn't have a ISP header so that makes it a bit trickier. But once you have successfully connected the ISP, use Arduino IDE to burn the bootloader (In Tools, select correct board, select correct programmer and press Burn Bootloader.)

For avrdude you'll find the bootloaders in Arduino\hardware\arduino\avr\bootloaders

(http://www.coreforge.com/blog/media/2014/09/updfrm_1pro_micro_pins-450x317.png)
Image source: https://www.coreforge.com/blog/2014/09/recovering-arduino-pro-micro-atmega32u4/ (https://www.coreforge.com/blog/2014/09/recovering-arduino-pro-micro-atmega32u4/)

EDIT: Yes, Arduino/Genuino Micro is the correct one for Pro Micro. The Pro Micro is essentially a Arduino Micro with fewer pins.
Title: Re: Reinstall bootloader for an Arduino Pro Micro?
Post by: cv007 on June 09, 2019, 11:35:35 am
I would go to the bootloader source to figure out what is happening, as no bootloader (correctly done) would make you reflash the firmware just because you made a programming/coding mistake-
https://github.com/arduino/ArduinoCore-avr/blob/7a2e1cd815266fef3012a5c9b48f88d78551f838/bootloaders/caterina/Caterina.c#L124

Now, your board may be a variation of his bootloader, but I would bet most are at least similar and getting the source for it should be easy enough.

If using the above 'original' bootloader, it only requires a setting of the external reset flag to make the bootloader run. To set the external reset flag of course, you pull the reset pin low. Then it looks like you have 8 seconds before the bootloader tries to run the app (this version simply jumps to 0 without checking if location 0 is an erased word).

Others variations may do something different (press reset twice, etc.), but when you figure it out you will not have to get out the programmer to flash the bootloader every time you make a mistake.
Title: Re: Reinstall bootloader for an Arduino Pro Micro?
Post by: ledtester on June 09, 2019, 04:01:35 pm
Thanks everyone I finally got it working.

The double reset trick worked - how it works on the Pro Micro is described here:

https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/troubleshooting-and-faq#faq-reinstall

But then I had to fight Ubuntu's ModemManager which would grab the Pro MIcro's serial port and prevent the Arduino IDE from using it for the 8 seconds that it existed.

I then found and tried the solution described in:  https://defproc.co.uk/blog/sparkfun-pro-micro-device-busy/

but couldn't get it to work. (Note you need to look at your syslog because the vendor id I was seeing was different (2341) from Spark Fun's vendor id 1b4f.) So I just ended up killing the ModemManager process and then I was able to upload the blink sketch.

For the Board setting I used "Arduino/Genuino Micro". I did install the Spark Fun board library through the Board Manager preferences, but setting the Board to "Spark Fun Pro Micro" did not work.
Title: Re: Reinstall bootloader for an Arduino Pro Micro?
Post by: cv007 on June 09, 2019, 04:19:11 pm
systemctl stop ModemManager.service
systemctl disable ModemManager.service

I doubt many need to put up with ModemManager's lengthy interrogation each time a serial device is plugged in. Took me a while to figure out what was happening when I wrote my usb driver, and makes for some confusing usb troubleshooting.
Title: Re: Reinstall bootloader for an Arduino Pro Micro?
Post by: Nominal Animal on June 10, 2019, 09:53:33 pm
Create 49-pro-micro.rules using your favourite text editor.  In Ubuntu, you can use e.g. gedit (in the Accessories menu) or nano (on the command line):
Code: [Select]
ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="920[3456]", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{ID_MM_PORT_IGNORE}="1", ENV{MTP_NO_PROBE}="1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="920[3456]", GROUP:="lp", MODE:="0660"
KERNEL=="ttyACM*", ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="920[3456]", GROUP:="lp", MODE:="0660"

ATTRS{idVendor}=="2341", ATTRS{idProduct}=="920[3456]", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{ID_MM_PORT_IGNORE}="1", ENV{MTP_NO_PROBE}="1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="920[3456]", GROUP:="lp", MODE:="0660"
KERNEL=="ttyACM*", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="920[3456]", GROUP:="lp", MODE:="0660"
You can replace lp with any other group name that should have full access to the microcontroller.  The ENV{} parts tell ModemManager to keep its mitts off these devices.

Install the rules file using
Code: [Select]
sudo install -o root -g root -m 0664 49-pro-micro.rules /lib/udev/rules.d/
sudo udevadm control -R
The first command copies it to the /lib/udev/rules.d/ directory, setting proper ownership and mode, and the second command tells udev to reload the rules.  Existing devices are not affected; the new settings are only applied when a device is connected.