Minified Adafruit Bluefruit 32u4: Uploading firmware to 32u4 and nRF58122

Hello Arduino forum,

learnt a lot here and thanks for all the contribution. :slight_smile:

Wanted to further minify my wearable project and used Adafruit Bluefruit 32u4 Adafruit Feather 32u4 Bluefruit LE with Headers - Assembled : ID 3379 : $31.95 : Adafruit Industries, Unique & fun DIY electronics and kits as a basis for a custom PCB. It has the Atmega 32u4 chip and nRF51822 MDBT40 Raytec module.

The PCBs arrived, assembled them and now I am trying to upload firmware to the 32u4 chip, so I can develop in Arduino IDE (and share with community). Found this link to the BluefruitLE Firmwares. GitHub - adafruit/Adafruit_BluefruitLE_Firmware: Firmware images for Adafruit's Bluefruit LE Modules (Bluefruit LE Friend, etc.)

I assume these are for the nRF51822 module. When trying to upload blespifriend 0.8.0 to atmega32u4 (using dfu-programmer https://dfu-programmer.github.io/), it shows error:

$ sudo dfu-programmer atmega32u4 flash ~/Downloads/Adafruit_BluefruitLE_Firmware-master/0.8.0/blespifriend/blespifriend_s110_xxac_0_8_0_170925_blespifriend.hex --debug 100
Password:
     target: atmega32u4
    chip_id: 0x2ff4
  vendor_id: 0x03eb
    command: flash
      quiet: false
      debug: 100
device_type: AVR
------ command specific below ------
   validate: true
   hex file: ~/Downloads/Adafruit_BluefruitLE_Firmware-master/0.8.0/blespifriend/blespifriend_s110_xxac_0_8_0_170925_blespifriend.hex

intel_hex.c:342: Address offset set to 0x10000.
intel_hex.c:254: Address 0x18000 is outside valid range 0x0 to 0x7FFF.
intel_hex.c:227: Valid address region from 0x0 to 0x7FFF.
WARNING (line 3): 0x18000 address outside valid region,
 suppressing additional address error messages.
intel_hex.c:254: Address 0x18001 is outside valid range 0x0 to 0x7FFF.
...
...
...
intel_hex.c:254: Address 0x297EF is outside valid range 0x0 to 0x7FFF.
Total of 0x117F0 bytes in invalid addressed.
commands.c:410: WARNING: File contains 0x117F0 bytes outside target memory.
commands.c:413: There may be data in the user page (offset 0X80800000).
commands.c:414: Inspect the hex file or try flash-user.
WARNING: 0x117F0 bytes are outside target memory,
 and will not be written.
atmel.c:1153: atmel_flash( 0x7ffeef6b6920, 0x7ffeef6b6810, false, false )
intel_hex.c:673: intel_flash_prep_buffer( 0x7ffeef6b6810 )
atmel.c:1193: Flash available from 0x0 to 0x6FFF (64kB p. 0 to 0), 0x7000 bytes.
atmel.c:1197: Data start @ 0xFFFFFFFF: 64kB p 65535; 128B p 0x1FFFFFF + 0x7F offset.
atmel.c:1201: Data end @ 0x0: 64kB p 0; 128B p 0x0 + 0x0 offset.
atmel.c:1206: Totals: 0x2 bytes, 4261412866 128B pages, 4294901762 64kB byte pages.
atmel.c:1216: ERROR: No valid data to flash.
Hex file error, use debug for more info.
commands.c:514: Error writing memory data. (err -1)

Current status notes:

  • The atmega32u4 is recognised by a computer when connected via USB.
  • dfu-programmer recognizes atmega32u4 chip connected.
  • The BLE module does not appear (might be invisible - not sure).

Three questions:
(1) I assume the atmega32u4 has an DFU bootloader that allows USB programming from factory, as per avr - Custom Atmega32u4 board first boot - Electrical Engineering Stack Exchange. If I burn an Arduino bootloader on it, will it replace this DFU bootloader and subsequently work in Arduino IDE? Or the DFU bootloader will still be there and using dfu-programmer I will only upload an Arduino firmware as mentioned here: https://www.arduino.cc/en/Hacking/DFUProgramming8U2 For a circuit to work with Arduino, do I need Arduino firmware or Arduino bootloader?

(2) I found firmwares for other Arduinos using 32u4 such as Leonardo. Can this be used in my case or do you know a source for the atmega32u4 firmware in Adafruit Bluefruit 32u4?

(3) How would you proceed to upload the firmware to nRF51822, if I cannot see the module? What could be a possible problem other than wrong connections?

I am a complete beginner regarding bootloaders/custom PCBs, trying to learn how it all works.

//posted same question to adafruit forum, will share insights.

Answer from adafruit forum:

1) You can't change the BLE module's firmware through the USB cable. That only connects to the ATmega32u4, and trying to upload firmware for the nRF51822 into the ATmega32u4 will fail in every way possible.
2) We use a Caterina-based dootloader for the 32u4, and it lives in the board support package:
Adafruit_Arduino_Boards/bootloaders at master · adafruit/Adafruit_Arduino_Boards · GitHub
If you have an in-circuit programmer, you can flash the bootloader to the 32u4 from the Arduino IDE with the Tools->Burn Bootloader menu option. Just select the correct board type and programmer type, and the IDE will find the correct bootloader on its own.
3) You update the nRF51822's firmware from our BLE Connect app. It's an over-the-air update.


When trying to upload the Caterina-Feather32u4.hex using dfu-programmer, I get bootloader and code overlap. (I have erased the memory before flashing)

$ sudo dfu-programmer atmega32u4 flash Caterina-Feather32u4.hex --debug 100
Password:
     target: atmega32u4
    chip_id: 0x2ff4
  vendor_id: 0x03eb
    command: flash
      quiet: false
      debug: 100
device_type: AVR
------ command specific below ------
   validate: true
   hex file: Caterina-Feather32u4.hex

Bootloader and code overlap.
Use --suppress-bootloader-mem to ignore

Adding --suppress-bootlaoder-mem - Data outside of valide target flash region ERROR occurs:

$ sudo dfu-programmer atmega32u4 flash Caterina-Feather32u4.hex --suppress-bootloader-mem --debug 100
     target: atmega32u4
    chip_id: 0x2ff4
  vendor_id: 0x03eb
    command: flash
      quiet: false
      debug: 100
device_type: AVR
------ command specific below ------
   validate: true
   hex file: Caterina-Feather32u4.hex

atmel.c:1153: atmel_flash( 0x7ffee380c9b0, 0x7ffee380c8a0, false, false )
intel_hex.c:673: intel_flash_prep_buffer( 0x7ffee380c8a0 )
atmel.c:1193: Flash available from 0x0 to 0x6FFF (64kB p. 0 to 0), 0x7000 bytes.
atmel.c:1197: Data start @ 0xFFFFFFFF: 64kB p 65535; 128B p 0x1FFFFFF + 0x7F offset.
atmel.c:1201: Data end @ 0x7FC7: 64kB p 0; 128B p 0xFF + 0x47 offset.
atmel.c:1206: Totals: 0x7FC9 bytes, 4261413121 128B pages, 4294901762 64kB byte pages.
atmel.c:1211: ERROR: Data exists outside of the valid target flash region.
Hex file error, use debug for more info.
commands.c:514: Error writing memory data. (err -1)

Tried Atmega32u4.hex as well from Adafruit github mentioned above. Same results.

Two question:

  • Is the issue that I am using dfu-programmer instead of Arduino IDE?
  • Anyone knows how to fix this?