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

我正在使用的Linux版本(Linux Mint 17.2)的存储库中使用Arduino库和Arduino-Makefile的版本。这些版本分别是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

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

最佳答案

这对我有用。

首先,转到Arduino素描簿中的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重置为Bootloader模式。而是将GNDRESET引脚短接到get into bootloader mode两次。然后make upload2闪烁pro-micro(注意:pro-micro仅停留在 bootstrap 模式下8秒钟)。

关于linux - 如何在Sparkfun Pro Micro中使用Arduino-Makefile?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33158180/

10-13 06:59