Issues uploading to HoodLoader2 on Arduino Mega

I have an Arduino Mega 2560 Rev 3 that I have flashed with HoodLoader2 so that I can use the Mega as a HID input device. I have uploaded an example sketch to the arduino using the standard Arduino IDE and verified it works, so now I am attempting to do the same with the PlatformIO IDE, as I don’t want to write my large project with the Arduino IDE. I’m attempting to follow the instructions laid out in this topic but I’m running into a few issues.

Firstly, I was getting errors about USB_PID/USB_VID being undefined preproc symbols, so I copied all of the boards.txt file from the HoodLoader2 repository into .platformio\packages\framework-arduino-avr\boards.txt, thinking that this would define those USB constants, but that did not work. I then added this to my build.extra_flags in the board JSON file: -DUSB_PID=0x484C -DUSB_VID=0x2341. This resolved those errors, but I thought it shouldn’t be necessary.

I’m also noticed that the RAM/Flash usage that the platformio command reports seems to be based on the 16u2 chip on my Mega, and not on the 2560 itself, am I really limited to such little space when using this method?

Finally, when attempting to upload my program firmware, the upload process seems to hang forever, and I can’t figure out why. This is the output that I’m getting:

> Executing task: C:\Users\Nate Mara\.platformio\penv\Scripts\platformio.exe run --target upload <

Processing mega (platform: atmelavr; framework: arduino; board: HoodLoader2atmega16u2)
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Atmel AVR 2.1.0 > HoodLoader2 16u2 Mega
HARDWARE: ATMEGA16U2 16MHz, 512B RAM, 12KB Flash
- framework-arduino-avr 5.0.0
- tool-avrdude 1.60300.200527 (6.3.0)
- toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 6 compatible libraries
Scanning dependencies...    
Dependency Graph       
|-- <HID-Project> 2.6.1
|   |-- <HID> 1.0      
Building in release mode
Checking size .pio\build\mega\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  36.7% (used 188 bytes from 512 bytes)
Flash: [====      ]  44.2% (used 5434 bytes from 12288 bytes)
Configuring upload protocol...
CURRENT: upload_protocol = avr109
Looking for upload port...
Auto-detected: COM7
Waiting for the new upload port...
Uploading .pio\build\mega\firmware.hex

It hangs forever at that Uploading step.

This is my platformio.ini file:

platform = atmelavr
framework = arduino
board = HoodLoader2atmega16u2
; board = megaatmega2560

lib_deps =

And this is my boards/HoodLoader2atmega16u2.json file:

  "build": {
    "core": "arduino",
    "f_cpu": "16000000L",
    "hwids": [["0x2341", "0x484C"]],
    "mcu": "atmega16u2",
    "variant": "HoodLoader2"
  "frameworks": ["arduino", "simba"],
  "fuses": {
    "efuse": "0x05",
    "hfuse": "0xD8",
    "lfuse": "0xFF",
    "lock": "0x3F"
  "name": "HoodLoader2 16u2 Mega",
  "upload": {
    "maximum_ram_size": 512,
    "maximum_size": 12288,
    "protocol": "avr109",
    "disable_flushing": true,
    "require_upload_port": true,
    "wait_for_upload_port": true,
    "speed": 57600
  "url": "",
  "vendor": "Arduino"

Am I missing something about the proper setup for this environment?


the program I’m trying to upload:

#include <Arduino.h>
#include "HID-Project.h"

void setup()

void loop()

just made a account to give the answer

i changed -DMAGIC_KEY_POS=(RAMEND-1)

and now it works most of the times