如何在Sparkfun Pro Micro上使用Arduino-Makefile?

时间:2015-10-15 20:43:03

标签: linux build makefile arduino cross-compiling

所以,我正在使用Arduino-Makefile(https://github.com/sudar/Arduino-Makefile)并尝试编程5V 16MHz Sparkfun Pro Micro(https://www.sparkfun.com/products/12640)。

我在我正在使用的Linux发行版的存储库中使用Arduino库和Arduino-Makefile的版本(Linux Mint 17.2)。这些版本分别为1.0.5和1.3.1。

我的文件结构如下:

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

我的test.ino直接来自这里:https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide#example-1-blinkies,看起来像这样:

/* 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
}

我的Makefile,非常短暂但令人尴尬的混乱,看起来像这样:

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

一切都很好,但程序员在我尝试make upload时抱怨。 Pro Micro是/dev/ttyACM0,我已经确认ls /dev/tty*设备已插入但没有插入并比较输出。

这是直线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)

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

现在,由于这个错误,我认为我的引导加载程序配置有问题,但我不确定。也许程序员设置错了?我将不胜感激任何帮助! :)

1 个答案:

答案 0 :(得分:2)

这对我有用。

首先,转到Arduino sketchbook中的hardware文件夹,或者如果它不存在则创建它。然后将sparkfun addon files提取到硬件文件夹中。您的目录结构应如下所示:$SKETCHBOOK_DIR/hardware/sparkfun/avr/

然后在你的项目目录中使用这个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

然后您应该能够运行makemake upload。但是,如果您的代码执行禁用或覆盖pro-micro上默认USB行为的内容,则Arduino-mk将无法通过USB将pro-micro重置为引导加载程序模式。而是将GNDRESET针脚缩短两次至get into bootloader mode。然后make upload2闪现pro-micro(注意:pro-micro仅在引导加载程序模式下保持8秒)。