Skip to content
Advertisement

How to use Arduino-Makefile with Sparkfun Pro Micro?

So, I am using Arduino-Makefile (https://github.com/sudar/Arduino-Makefile) and trying to program a 5V 16MHz Sparkfun Pro Micro (https://www.sparkfun.com/products/12640).

I am using the versions of the Arduino libraries and Arduino-Makefile in the repository of the Linux distro I am using (Linux Mint 17.2). These versions are 1.0.5 and 1.3.1 respectively.

My file structure looks like this:

<project-root>/
    sparkfun/
        ... Sparkfun Arduino Addon Files (https://github.com/sparkfun/SF32u4_boards/)
    src/
        Makefile
        test.ino

My test.ino is taken directly from here: https://learn.sparkfun.com/tutorials/pro-micro–fio-v3-hookup-guide#example-1-blinkies and looks like this:

/* Pro Micro Test Code
   by: Nathan Seidle
   modified by: Jim Lindblom
   SparkFun Electronics
   date: September 16, 2013
   license: Public Domain - please use this code however you'd like.
   It's provided as a learning tool.

   This code is provided to show how to control the SparkFun
   ProMicro's TX and RX LEDs within a sketch. It also serves
   to explain the difference between Serial.print() and
   Serial1.print().
*/

int RXLED = 17;  // The RX LED has a defined Arduino pin
// The TX LED was not so lucky, we'll need to use pre-defined
// macros (TXLED1, TXLED0) to control that.
// (We could use the same macros for the RX LED too -- RXLED1,
//  and RXLED0.)

void setup()
{
 pinMode(RXLED, OUTPUT);  // Set RX LED as an output
 // TX LED is set as an output behind the scenes

 Serial.begin(9600); //This pipes to the serial monitor
 Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
}

void loop()
{
 Serial.println("Hello world");  // Print "Hello World" to the Serial Monitor
 Serial1.println("Hello!");  // Print "Hello!" over hardware UART

 digitalWrite(RXLED, LOW);   // set the LED on
 TXLED0; //TX LED is not tied to a normally controlled pin
 delay(1000);              // wait for a second
 digitalWrite(RXLED, HIGH);    // set the LED off
 TXLED1;
 delay(1000);              // wait for a second
}

My Makefile, which is very short yet embarrassingly messy, looks like this:

MONITOR_PORT = /dev/ttyACM0

CPPFLAGS += -std=c++11 -I$(realpath ../sparkfun/avr/variants/promicro) -w -DUSB_VID=6991 -DUSB_PID=37381

# --- sparkfun pro micro
BOARD_TAG         = promicro16
ALTERNATE_CORE    = $(realpath ../sparkfun/avr)
ARDUINO_VAR_PATH = $(realpath ../sparkfun/avr/bootloaders)
BOARDS_TXT        = $(realpath ../sparkfun/avr/boards.txt)
BOOTLOADER_PARENT = $(realpath ../sparkfun/avr/bootloaders)
BOOTLOADER_PATH   = caterina
BOOTLOADER_FILE   = Caterina-promicro16.hex
ISP_PROG           = usbasp


USER_LIB_PATH := $(realpath ../lib)
include /usr/share/arduino/Arduino.mk

Everything builds fine, but the programmer complains when I try a make upload. The Pro Micro is /dev/ttyACM0, which I have confirmed by doing an ls /dev/tty* with the device both plugged in and not plugged in and comparing the outputs.

Here is the result of a straight up make:

-------------------------
Arduino.mk Configuration:
- [AUTODETECTED]       CURRENT_OS = LINUX 
- [COMPUTED]           ARDMK_DIR = /usr/share/arduino (relative to Common.mk)
- [AUTODETECTED]       ARDUINO_DIR = /usr/share/arduino 
- [AUTODETECTED]       ARDUINO_VERSION = 105 
- [DEFAULT]            ARDUINO_SKETCHBOOK = /home/kota/sketchbook 
- [BUNDLED]            AVR_TOOLS_DIR = /usr/share/arduino/hardware/tools/avr (in Arduino distribution)
- [COMPUTED]           ARDUINO_LIB_PATH = /usr/share/arduino/libraries (from ARDUINO_DIR)
- [DEFAULT]            ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/cores/arduino 
- [USER]               ALTERNATE_CORE = /home/kota/Projects/tinyIMU/arduino/sparkfun/avr 
- [COMPUTED]           ALTERNATE_CORE_PATH = /home/kota/sketchbook/hardware//home/kota/Projects/tinyIMU/arduino/sparkfun/avr  (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE)
- [DEFAULT]            USER_LIB_PATH = /home/kota/sketchbook/libraries (in user sketchbook)
- [USER]               BOARD_TAG = promicro16 
- [COMPUTED]           OBJDIR = build-promicro16 (from BOARD_TAG)
- [ASSUMED]            MONITOR_BAUDRATE = 9600 
- [DEFAULT]            OPTIMIZATION_LEVEL = s 
- [DEFAULT]            MCU_FLAG_NAME = mmcu 
- [DEFAULT]            CFLAGS_STD = -std=gnu99 
- [AUTODETECTED]       Size utility: AVR-aware for enhanced output
- [USER]               BOOTLOADER_PARENT = /home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders 
-------------------------
mkdir -p build-promicro16
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -x c++ -include Arduino.h -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   tinyimu.ino -o build-promicro16/tinyimu.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os   /usr/share/arduino/hardware/arduino/cores/arduino/WInterrupts.c -o build-promicro16/WInterrupts.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os   /usr/share/arduino/hardware/arduino/cores/arduino/wiring_analog.c -o build-promicro16/wiring_analog.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os   /usr/share/arduino/hardware/arduino/cores/arduino/wiring.c -o build-promicro16/wiring.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os   /usr/share/arduino/hardware/arduino/cores/arduino/wiring_digital.c -o build-promicro16/wiring_digital.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os   /usr/share/arduino/hardware/arduino/cores/arduino/wiring_pulse.c -o build-promicro16/wiring_pulse.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os   /usr/share/arduino/hardware/arduino/cores/arduino/wiring_shift.c -o build-promicro16/wiring_shift.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/CDC.cpp -o build-promicro16/CDC.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp -o build-promicro16/HardwareSerial.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/HID.cpp -o build-promicro16/HID.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/IPAddress.cpp -o build-promicro16/IPAddress.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/main.cpp -o build-promicro16/main.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/new.cpp -o build-promicro16/new.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/Print.cpp -o build-promicro16/Print.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/Stream.cpp -o build-promicro16/Stream.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/Tone.cpp -o build-promicro16/Tone.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/USBCore.cpp -o build-promicro16/USBCore.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/WMath.cpp -o build-promicro16/WMath.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -std=c++11 -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/variants/promicro -w -DUSB_VID=6991 -DUSB_PID=37381 -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders/promicro   -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions   /usr/share/arduino/hardware/arduino/cores/arduino/WString.cpp -o build-promicro16/WString.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs build-promicro16/libcore.a  build-promicro16/WInterrupts.o  build-promicro16/wiring_analog.o  build-promicro16/wiring.o  build-promicro16/wiring_digital.o  build-promicro16/wiring_pulse.o  build-promicro16/wiring_shift.o  build-promicro16/CDC.o  build-promicro16/HardwareSerial.o  build-promicro16/HID.o  build-promicro16/IPAddress.o  build-promicro16/main.o  build-promicro16/new.o  build-promicro16/Print.o  build-promicro16/Stream.o  build-promicro16/Tone.o  build-promicro16/USBCore.o  build-promicro16/WMath.o  build-promicro16/WString.o    
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -mmcu=atmega32u4 -Wl,--gc-sections -Os    -o build-promicro16/src.elf build-promicro16/tinyimu.o build-promicro16/libcore.a  -lc -lm
/usr/share/arduino/hardware/tools/avr/bin/avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" 
                --change-section-lma .eeprom=0 -O ihex build-promicro16/src.elf build-promicro16/src.eep
/usr/share/arduino/hardware/tools/avr/bin/avr-objcopy: --change-section-lma .eeprom=0x0000000000000000 never used
/usr/share/arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom build-promicro16/src.elf build-promicro16/src.hex

/usr/share/arduino/hardware/tools/avr/bin/avr-size --mcu=atmega32u4 -C --format=avr build-promicro16/src.elf
AVR Memory Usage
----------------
Device: atmega32u4

Program:    4808 bytes (14.7% Full)
(.text + .data + .bootloader)

Data:        163 bytes (6.4% Full)
(.data + .bss + .noinit)

and the output of make upload:

-------------------------
Arduino.mk Configuration:
- [AUTODETECTED]       CURRENT_OS = LINUX 
- [COMPUTED]           ARDMK_DIR = /usr/share/arduino (relative to Common.mk)
- [AUTODETECTED]       ARDUINO_DIR = /usr/share/arduino 
- [AUTODETECTED]       ARDUINO_VERSION = 105 
- [DEFAULT]            ARDUINO_SKETCHBOOK = /home/kota/sketchbook 
- [BUNDLED]            AVR_TOOLS_DIR = /usr/share/arduino/hardware/tools/avr (in Arduino distribution)
- [COMPUTED]           ARDUINO_LIB_PATH = /usr/share/arduino/libraries (from ARDUINO_DIR)
- [DEFAULT]            ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/cores/arduino 
- [USER]               ALTERNATE_CORE = /home/kota/Projects/tinyIMU/arduino/sparkfun/avr 
- [COMPUTED]           ALTERNATE_CORE_PATH = /home/kota/sketchbook/hardware//home/kota/Projects/tinyIMU/arduino/sparkfun/avr  (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE)
- [DEFAULT]            USER_LIB_PATH = /home/kota/sketchbook/libraries (in user sketchbook)
- [USER]               BOARD_TAG = promicro16 
- [COMPUTED]           OBJDIR = build-promicro16 (from BOARD_TAG)
- [ASSUMED]            MONITOR_BAUDRATE = 9600 
- [DEFAULT]            OPTIMIZATION_LEVEL = s 
- [DEFAULT]            MCU_FLAG_NAME = mmcu 
- [DEFAULT]            CFLAGS_STD = -std=gnu99 
- [AUTODETECTED]       Size utility: AVR-aware for enhanced output
- [USER]               BOOTLOADER_PARENT = /home/kota/Projects/tinyIMU/arduino/sparkfun/avr/bootloaders 
-------------------------
make reset
make[1]: Entering directory `/home/kota/Projects/tinyIMU/arduino/src'
/usr/bin/ard-reset-arduino  /dev/ttyACM0
make[1]: Leaving directory `/home/kota/Projects/tinyIMU/arduino/src'
make do_upload
make[1]: Entering directory `/home/kota/Projects/tinyIMU/arduino/src'
/usr/share/arduino/hardware/tools/avr/../avrdude -q -V -D -p atmega32u4 -C /usr/share/arduino/hardware/tools/avr/../avrdude.conf -c avr109 -b 57600 -P /dev/ttyACM0 
                        -U flash:w:build-promicro16/src.hex:i

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding
make[1]: *** [do_upload] Error 1
make[1]: Leaving directory `/home/kota/Projects/tinyIMU/arduino/src'
make: *** [upload] Error 2

Now, because of the error, I figure it’s something wrong with my configuration of the bootloader, but I am unsure. Maybe the programmer setting is wrong? I would appreciate any help! 🙂

Advertisement

Answer

Here’s what worked for me.

First, go to the hardware folder in your Arduino sketchbook or create it if it does not exist. Then extract the sparkfun addon files into the hardware folder. Your directory structure should look something like this:$SKETCHBOOK_DIR/hardware/sparkfun/avr/.

Then in your project directory use this makefile:

BOARD_TAG         = promicro16
ALTERNATE_CORE    = sparkfun

ARDUINO_DIR       = /usr/share/arduino

include $(ARDUINO_DIR)/Arduino.mk

upload2:
    avrdude -p atmega32u4 -P /dev/ttyACM0 -c avr109 -U flash:w:build-$(BOARD_TAG)/$(TARGET).hex

Then you should be able to run make and make upload. However, if your code does something that disables or overrides the default USB behaviour on the pro-micro, then Arduino-mk will not be able to reset the pro-micro into bootloader mode over USB. Instead short the GND and RESET pins twice to get into bootloader mode. Then make upload2 flash the pro-micro (Note: the pro-micro only stays in bootloader mode for 8 seconds).

Advertisement