platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
139 stars 105 forks source link

Build for "micro" board fails #123

Closed YarekTyshchenko closed 5 years ago

YarekTyshchenko commented 9 years ago

Trying to build the blink example for Micro board, Arduino Micro (atmega32u4) fails to compile. Its trying to include a header file for the pins from a folder that wouldn't exist there. I tried to debug it a little myself, i've put in leonardo's pin definitions into the file that its looking for but it spat out some more errors: http://pastie.org/pastes/9797760/text?key=yntqzqdbbyytpepq2gdrxg

MacBook-Pro:Tubeclock yarek$ platformio run
Processing arduino_micro environment:
avr-gcc -o .pioenvs/arduino_micro/src/main.o -c -g -Os -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=158 -DARDUINO_AVR_MICRO -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_PRODUCT=Arduino Micro" -I.pioenvs/arduino_micro/FrameworkArduino -I.pioenvs/arduino_micro/FrameworkArduinoVariant .pioenvs/arduino_micro/src/main.c
In file included from .pioenvs/arduino_micro/FrameworkArduino/Arduino.h:247:0,
                 from .pioenvs/arduino_micro/src/main.c:1:
.pioenvs/arduino_micro/FrameworkArduinoVariant/pins_arduino.h:25:38: fatal error: ../leonardo/pins_arduino.h: No such file or directory
 #include "../leonardo/pins_arduino.h"
                                      ^
compilation terminated.
scons: *** [.pioenvs/arduino_micro/src/main.o] Error 1
ivankravets commented 9 years ago

but it spat out some more errors

Can you look to the issue #35 and read my comment https://github.com/ivankravets/platformio/issues/35#issuecomment-67524943

ivankravets commented 9 years ago

Rename your main.c to main.cpp or to main.ino.

YarekTyshchenko commented 9 years ago

Tried both, same error, its looking for "../leonardo/pins_arduino.h" which isn't anywhere in .pioenvs

ivankravets commented 9 years ago

Give me your platformio.ini. Thanks.

ivankravets commented 9 years ago

Opssss.... Sorry. I see it. Give me a few minutes, I will re-upload new Arduino-Framework package.

YarekTyshchenko commented 9 years ago

I should say that it compiles perfectly well if I switch the board to uno.

[env:arduino_micro]
platform = atmelavr
framework = arduino
board = micro
upload_port = /dev/tty.usbmodem621

using main.* from the platformio blink example

ivankravets commented 9 years ago

It's problem with "relative includes" in the Arduino source code. I've just added to my TODO and will fix it directly in PlatformIO builder later. As for now, I'm going to make a temporary fix for it. I will report here.

ivankravets commented 9 years ago

Please update your packages:

$ platformio update

It should work now.

YarekTyshchenko commented 9 years ago

Almost

MacBook-Pro:Tubeclock yarek$ platformio run
Processing arduino_micro environment:
avr-g++ -o .pioenvs/arduino_micro/FrameworkArduino/USBCore.o -c -fno-exceptions -g -Os -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=158 -DARDUINO_AVR_MICRO -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_PRODUCT=Arduino Micro" -I.pioenvs/arduino_micro/FrameworkArduino -I.pioenvs/arduino_micro/FrameworkArduinoVariant .pioenvs/arduino_micro/FrameworkArduino/USBCore.cpp
<command-line>:0:13: error: 'Arduino' was not declared in this scope
.pioenvs/arduino_micro/FrameworkArduino/USBCore.cpp:55:37: note: in expansion of macro 'USB_PRODUCT'
 const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
                                     ^
.pioenvs/arduino_micro/FrameworkArduino/USBCore.cpp: In function 'bool SendDescriptor(Setup&)':
<command-line>:0:13: error: 'Arduino' was not declared in this scope
.pioenvs/arduino_micro/FrameworkArduino/USBCore.cpp:508:59: note: in expansion of macro 'USB_PRODUCT'
    return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT));
                                                           ^
scons: *** [.pioenvs/arduino_micro/FrameworkArduino/USBCore.o] Error 1

Commenting out the ifndef bit turns it into this: http://pastie.org/pastes/9797825/text?key=mixsg5pawcxhobjpint5sw

Is it wrong to have lines starting with a hash? Maybe the preprocessor gets confused

ivankravets commented 9 years ago

Please share here your main.cpp I will try it tomorrow :sleeping: :smile:

YarekTyshchenko commented 9 years ago
#include <Arduino.h>
#ifndef LED_PIN
// Most Arduino boards already have a LED attached to pin 13 on the board itself
#define LED_PIN 13
#endif

void setup() {
  pinMode(LED_PIN, OUTPUT);     // set pin as output
}

void loop() {
  digitalWrite(LED_PIN, HIGH);  // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(LED_PIN, LOW);   // set the LED off
  delay(1000);                  // wait for a second
}

Thanks for looking into all my complains today, Merry christmas

ivankravets commented 9 years ago

Marry Christmas to you too πŸŽ„πŸŽβ›„οΈ

ivankravets commented 9 years ago

@yarekt Thanks a lot for this report. I fixed critical bug for Arduino USB boards. I'm going to release hot-fix 0.9.3 tomorrow. Please re-test the latest development branch:

$ pip uninstall platformio
$ pip install https://github.com/ivankravets/platformio/archive/develop.zip
YarekTyshchenko commented 9 years ago

Thanks, that looks like it fixes that, however, I can't seem to upload properly. It might be the avrdude options are wrong for the micro. Avrdude has a nasty habit of locking up my USB port. I'll try to dig up the options that worked for me before

ivankravets commented 9 years ago

I see this issue. I know how to fix it. I will work on it tomorrow. Sorry, for the problems and delays :(

YarekTyshchenko commented 9 years ago

No, no worries. I'm amazed how prolific you are at responding to all the issues. Thanks so much. (You should probably take some time off and enjoy the holidays)

ivankravets commented 9 years ago

Thanks :relaxed: I can't relax when PlatformIO has opened the issues with "bug" label :smile:

If you are interested in this problem please look into https://github.com/arduino/Arduino/blob/master/app/src/processing/app/debug/AvrdudeUploader.java#L82

need to do a little dance for Leonardo and derivatives:

Need to implement a specific "reset" logic for Leonardo & similar Arduino USB devices.

YarekTyshchenko commented 9 years ago

I can see that you've already implemented the use_1200bps_touch flag in boards. I'm not very good at python but I found the way that arduino.cc recommend resetting the boards:

#!/usr/bin/python
# usage: reset_arduino <DEVICE>
# where <DEVICE> is typically some /dev/ttyfoobar
import sys
import serial
ser = serial.Serial()
ser.port=sys.argv[1]
ser.baudrate=1200
ser.open(); ser.close()

Works pretty well as an executable script

ivankravets commented 9 years ago

Yes, I added additional information to boards which communicate within avr109 protocol and new boards command. Because your issue depends on issue 11 :)

Your hint isn't 100% solution and will not work in all cases.

I will implement normal device reset with waiting logic. Thins is a main requirement - "waiting" while board will enter in upload mode.

YarekTyshchenko commented 9 years ago

Ah thats true, however, avrdude seems to wait for the right port to be available anyway (for a timeout)

ivankravets commented 9 years ago

I promise you that I will fix this issue tomorrow. Sorry for delay :(

YarekTyshchenko commented 9 years ago

Don't worry mate, theres no rush

ivankravets commented 9 years ago

Can you contact me by email? Because I don't see your email. Thanks :)

YarekTyshchenko commented 9 years ago

It should be public somewhere yarekt@gmail.com

ivankravets commented 9 years ago

Hey @yarekt ,

Can you try the latest dev version?

YarekTyshchenko commented 9 years ago

Works perfectly. Thanks

hpsaturn commented 5 years ago

Hi, I don't know but I have the same error when try to running on a old Microduino MCookie-Core module, it's a Microduino USB like a Leonardo.

I was running the next commands: Select board:

pio boards microduino | grep Microduino | grep USB
32u416m               ATMEGA32U4     16MHz     28KB    2.50KB Microduino Core USB (ATmega32U4@16M,5V)

init project:

platformio init --board 32u416m

error:

pio run
Processing 32u416m (platform: atmelavr; board: 32u416m; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/32u416m.html
PLATFORM: Atmel AVR > Microduino Core USB (ATmega32U4@16M,5V)
HARDWARE: ATMEGA32U4 16MHz 2.50KB RAM (28KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 24 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pioenvs/32u416m/src/main.cpp.o
Compiling .pioenvs/32u416m/FrameworkArduino/CDC.cpp.o
Compiling .pioenvs/32u416m/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pioenvs/32u416m/FrameworkArduino/HardwareSerial0.cpp.o
In file included from src/main.cpp:1:0:
/home/avp/.platformio/packages/framework-arduinoavr/cores/arduino/Arduino.h:257:26: fatal error: pins_arduino.h: No such file or directory

dmesg input:

Dec  2 12:29:34 zenbook kernel: [2042714.805178] usb 2-1: new full-speed USB device number 56 using xhci_hcd
Dec  2 12:29:34 zenbook kernel: [2042714.936045] usb 2-1: New USB device found, idVendor=2341, idProduct=8036
Dec  2 12:29:34 zenbook kernel: [2042714.936053] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Dec  2 12:29:34 zenbook kernel: [2042714.936058] usb 2-1: Product: Arduino Leonardo
Dec  2 12:29:34 zenbook kernel: [2042714.936062] usb 2-1: Manufacturer: Arduino LLC
Dec  2 12:29:34 zenbook kernel: [2042714.936657] cdc_acm 2-1:1.0: ttyACM0: USB ACM device
Dec  2 12:29:34 zenbook kernel: [2042714.939580] input: Arduino LLC Arduino Leonardo as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.2/0003:2341:8036.0003/input/input158
Dec  2 12:29:34 zenbook kernel: [2042714.940024] hid-generic 0003:2341:8036.0003: input,hidraw0: USB HID v1.01 Mouse [Arduino LLC Arduino Leonardo] on usb-0000:00:14.0-1/input
ivankravets commented 5 years ago

Please update you Atmel AVR dev/platform. The new 1.12.1 release is out! https://github.com/platformio/platform-atmelavr/releases/tag/v1.12.1