Skip to content

Instantly share code, notes, and snippets.

@gmmoreira
Last active March 6, 2025 14:40
Show Gist options
  • Save gmmoreira/86d7f85ae9b5f737c5f8c5abfa56aef7 to your computer and use it in GitHub Desktop.
Save gmmoreira/86d7f85ae9b5f737c5f8c5abfa56aef7 to your computer and use it in GitHub Desktop.

Revisions

  1. gmmoreira revised this gist Mar 6, 2025. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions commands.sh
    Original file line number Diff line number Diff line change
    @@ -32,12 +32,17 @@ avrdude -c avr109 -p m32u4 -P /dev/ttyACM0 -n
    # -P /dev/ttyACM0 set the serial port. On Windows it would be something like COM1, COM7, etc...
    # -n disables any writes, it's safe option

    # Arduino as ISP
    # Flasing using Arduino as ISP
    # I don't know if my clone Pro Micro had a issue of I bricked it somehow, but I couldn't write to it by just using the reset to bootloader
    # So another solution was flashing it using a ISP programmer. I have a Uno R3 and after some research I discovered that I could use it as ISP.

    # Arduino UNO R3 as ISP
    # You can find more details about wiring and flashing the ISP here: https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP/#use-arduino-as-isp
    # To flash the Pro Micro through the Uno R3 ISP, use this command. caterina.hex is the binary you want to flash.
    avrdude -v -p m32u4 -P /dev/ttyUSB0 -c stk500v1 -b 19200 -U flash:w:caterina.hex:i -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xfb:m

    # Arduino has an autoreset feature which resets the device when a serial connection is opened, so avrdude will fail because Arduino will be reseting and not ready.
    # Arduino UNO R3 has an autoreset feature which resets the device when a serial connection is opened, so avrdude will fail because Arduino will be reseting and not ready.
    # To prevent this, one option to use a capacitor in some pins (google it, dont remember) or cut some traces on the board.
    # In Linux there's a simple option. It's possible to use the following command
    stty -F /dev/ttyUSB0 -hupcl
    # It will prevent the autoreset by not sending the hangup (something like that, I dont understand much about serial connections).
    # It will prevent the autoreset by not sending the hangup (something like that, I dont understand much about serial connections).
    # After this command you can use the avrdude command above.
  2. gmmoreira revised this gist Feb 16, 2023. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion commands.sh
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,14 @@ avrdude -c avr109 -p m32u4 -P /dev/ttyACM0 -n
    # -c avr109 set the programer as avr109. It's the protocol which will be used
    # -p m32u4 set the target, which is an atmega32u4
    # -P /dev/ttyACM0 set the serial port. On Windows it would be something like COM1, COM7, etc...
    # -n disables any writes, it's safe option
    # -n disables any writes, it's safe option

    # Arduino as ISP
    # Flasing using Arduino as ISP
    avrdude -v -p m32u4 -P /dev/ttyUSB0 -c stk500v1 -b 19200 -U flash:w:caterina.hex:i -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xfb:m

    # Arduino has an autoreset feature which resets the device when a serial connection is opened, so avrdude will fail because Arduino will be reseting and not ready.
    # To prevent this, one option to use a capacitor in some pins (google it, dont remember) or cut some traces on the board.
    # In Linux there's a simple option. It's possible to use the following command
    stty -F /dev/ttyUSB0 -hupcl
    # It will prevent the autoreset by not sending the hangup (something like that, I dont understand much about serial connections).
  3. gmmoreira created this gist Apr 8, 2022.
    33 changes: 33 additions & 0 deletions commands.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # Using bootloader
    # To enter bootloader, connect the board to the computer and connect briefly the GND and RST pins.
    # Some boards may require this connection to be done twice.
    # When the bootloader is running, a virtual serial connection is created and so we can read/write to the device

    # Checking connection and fuses
    avrdude -c avr109 -p m32u4 -P /dev/ttyACM0 -n

    # It should write something like the example below
    # Connecting to programmer: .
    # Found programmer: Id = "CATERIN"; type = S
    # Software Version = 1.0; No Hardware Version given.
    # Programmer supports auto addr increment.
    # Programmer supports buffered memory access with buffersize=128 bytes.

    # Programmer supports the following devices:
    # Device code: 0x44

    # avrdude: AVR device initialized and ready to accept instructions

    # Reading | ################################################## | 100% 0.00s

    # avrdude: Device signature = 0x1e9587 (probably m32u4)

    # avrdude: safemode: Fuses OK (E:FB, H:D8, L:FF)

    # avrdude done. Thank you.

    # Explaining the command:
    # -c avr109 set the programer as avr109. It's the protocol which will be used
    # -p m32u4 set the target, which is an atmega32u4
    # -P /dev/ttyACM0 set the serial port. On Windows it would be something like COM1, COM7, etc...
    # -n disables any writes, it's safe option