Author Topic: ATMega32U4 - can't stay in bootloader mode  (Read 1177 times)

0 Members and 1 Guest are viewing this topic.

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
ATMega32U4 - can't stay in bootloader mode
« on: Thu, 17 June 2021, 09:14:46 »
Hi! I've got a keyboard PCB with ATMega32U4, and it almost does what it should. I can flash it, the firmware evokes letters, except that shorting the RST pin jumps to bootloader mode and immediatey back to application mode. What could be the problem there? And how to debug that?I attached the wiring scheme and the fuse settings.
« Last Edit: Thu, 17 June 2021, 09:16:54 by Eszett »

Offline fpazos

  • Posts: 139
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #1 on: Thu, 17 June 2021, 09:17:19 »
Pushing it twice should keep the bootloader mode some seconds
 

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #2 on: Thu, 17 June 2021, 09:32:54 »
I wish it would ... After shorting the RST pin, the "disconnect" Windows sound is followed immediately by the "connect" Windows sound, so my guess, that it doesn't stay in bootloader mode.

Offline nevin

  • Posts: 1455
  • Location: US
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #3 on: Thu, 17 June 2021, 09:42:50 »
the bootloader for a promicro 32u4 (if reset twice quickly in succession) will give you a max of 8 seconds (if my memory serves.... Catalina, AVR).
DFU on the other hand will stay in bootloader mode until it's power is cycled.

so it's probably not the chip but the bootloader you are using.
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #4 on: Thu, 17 June 2021, 09:48:21 »
Hi Nevin, beeing unsure whether the chip came with a bootloader or not, I flashed the official bootloader by hand with the command
avrdude -c usbasp -p m32u4 -e -U flash:w:ATMega32U4-usbdevice_dfu-1_0_0.hex
I hope this was correct? With flashing I've got no errors. But maybe I should double check if everything turned out well? How do I?
« Last Edit: Thu, 17 June 2021, 09:50:03 by Eszett »

Offline nevin

  • Posts: 1455
  • Location: US
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #5 on: Thu, 17 June 2021, 10:11:20 »
ok. avr.... yep. that's what it's going to be. and it's fine. just have a small window to catch it.
this might help catch it, it's the way i do it. (copy/pasted from my response on another thread)

- promicros can be tricky to flash, even with resetting twice in a row you only get 8 seconds to catch the bootloader
so, - edit & download the firmware
- open QMK toolbox and get it ready, select the correct firmware
- reset it twice quickly
- as soon as you see the port open up in the window, click flash.
270785-0
- wait for the confirmation message that flashing was successful
270787-1

other notes:  used VIA and keymap you just flashed is not the keymap the board is using?, try clearing the EEPROM.
- reset twice quickly
- soon as the port is found click "Clear EEPROM"
(i've run into this myself with flashing new firmware while there was a previous keymap sitting in the EEPROM from VIA, so my revised keymap in the firmware was being overridden by the keymap in the EEPROM from VIA.)
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #6 on: Thu, 17 June 2021, 10:39:59 »
I tinkered abit with the qmk_toolbox.exe You mentioned, and confirmed "Yes, install the driver", and it seems this tool flashed the chip with my custom firmware even though the chip was not in bootloader mode! Not sure what kind of magic this is, but yes it worked. Still, why is the chip not staying in bootloader mode when shorting RST?
« Last Edit: Thu, 17 June 2021, 10:42:46 by Eszett »

Offline nevin

  • Posts: 1455
  • Location: US
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #7 on: Thu, 17 June 2021, 11:02:46 »
that's the dfu programmer, which acts a little different. that will stay in bootloader mode until power is cycled.
- it does go into bootloader mode for a second when it powers up (boots) but quickly jumps to it's running program.
- hold the boot button/key when you plug it in and it will go into bootloader mode, power cycle it and it will be back to the normal running program.
- this version is definitely nicer than the caterina one i was referring to.

the 8 seconds is all the window you get to flash for the caterina bootloader which is common with promicros and other 32u4's
- was figuring it was this one because you were using the avrdude flasher which is the tool used for the caterina bootloader.
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #8 on: Thu, 17 June 2021, 11:29:21 »
Not sure I can follow you, but I pulled the USB cable of the circuit and pressed and held down RST while replugging the cable. Now it seems I'm stuck with beeing in bootloader mode. ATMEL Flip can flash the chip, but even with "start application" the chip remains in bootloader mode. I'm really confused. What I did do the last hour was to resolder the 10k pullup on RST, and the 10K pulldown on HWB.
« Last Edit: Thu, 17 June 2021, 11:41:23 by Eszett »

Offline nevin

  • Posts: 1455
  • Location: US
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #9 on: Thu, 17 June 2021, 11:39:45 »
unplug & replug, but don't hold the reset. (to power cycle the keyboard)
now it is running should be able to type.

to flash again
unplug, hold reset while plugging in, flash, unplug, replug - back to using it.

and put a reset key in your keymap
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #10 on: Thu, 17 June 2021, 12:35:37 »
Yes, I've tried all those methods, the PCB stays in bootloader mode, or at least I think so. My gut feeling is that there is a hardware issue, maybe faulty soldering, so I discard this PCB and solder together another one. I will compare the behaviour of both PCBs just to rule out a hardware issue.
« Last Edit: Thu, 17 June 2021, 12:37:22 by Eszett »

Offline nevin

  • Posts: 1455
  • Location: US
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #11 on: Thu, 17 June 2021, 12:59:48 »
ok. check the pinout of the 32u4 and make sure you don't have a solder bridge at the controller. or somewhere else around the controller.

- do a continuity test for the reset button... it should not be making contact when not depressed.
... there are two types of switches... NO and NC. NO is normally open, NC is normally closed. more common in limit switches & such, but they exist and has tripped me up once on a project (not keyboards).. i just wasn't paying attention when i ordered the parts.

... and if you have a reset key in your keymap, you really don't need the physical button on the pcb.

if you do have a bridge, the easiest way to separate them is warm up the solder and pull something between the pins. i usually use an dull exact-o blade, but anything that won't melt will work. be gentile.
« Last Edit: Thu, 17 June 2021, 13:01:27 by nevin »
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #12 on: Thu, 17 June 2021, 13:16:03 »
Yes, I omitted the reset button, so it's blank pads there, no issue. Possible issues are
- the crystal. How can I check if it's running at 16MHz? Don't think my multimeter can measure Mhz?
- the ATMega32U4, but I soldered it with utmost case, with the flux reflow method and good soldere paste. So i think this one is ok.
- the USB-C-receptable. I can't measure for shorts with my multimeter as the pin pitch is too small. Under my magnifiers it looks fine.
- the 10k pullup on RST and 10k pulldown on HWB, I've used crappy solder wire for it.
- the USB cable

What I experience, and that makes me feel it's hardware related, is that the circuit now and then, seemingly random, connects and disconnects, as is indicated by the Windows sounds. It happens without any mechanical movement. So I guess electronically there are some pins floating that shouldn't?
« Last Edit: Thu, 17 June 2021, 13:19:38 by Eszett »

Offline nevin

  • Posts: 1455
  • Location: US
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #13 on: Thu, 17 June 2021, 13:23:41 »
if it's intermittent with non repetitive timing... it usually is a hardware issue.

have you tried a different usb cable? maybe usb cable is on it's way out?
....or different port on the computer for that matter.

sent pm as well
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #14 on: Thu, 17 June 2021, 13:37:42 »
Yes, the cable might be iffy, tomorrow I will connect with a different one. I'm glad you helped so far, and will continue tomorrow.

Offline nevin

  • Posts: 1455
  • Location: US
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #15 on: Thu, 17 June 2021, 13:38:37 »
ok. good luck. hopefully, that's all it is.
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Eszett

  • Thread Starter
  • Posts: 531
  • Supporting the communities Geekhack & Deskthority
Re: ATMega32U4 - can't stay in bootloader mode
« Reply #16 on: Fri, 18 June 2021, 04:21:45 »
I've got the problem solved, and for the records I post it here. I flashed the bootloader with a command, forgetting the parameter "i" at the end
Code: [Select]
avrdude -c usbasp -p m32u4 -U flash:w:ATMega32U4-usbdevice_dfu-1_0_0.hex (wrong)
Code: [Select]
avrdude -c usbasp -p m32u4 -U flash:w:ATMega32U4-usbdevice_dfu-1_0_0.hex:i (correct)The parameter basically tells that the *.hex file is a hex file, which is kinda obvious, but not for this dumb Avrdude. Even without this parameter Avrdude didn't complain, there was no error message given, which is kind of evil, as I thought everything was fine. But the thing is the bootloader gets written to a wrong address. When pressing Reset the chip jumps to a void address and jumps immediately back to application mode.
« Last Edit: Fri, 18 June 2021, 10:07:49 by Eszett »