firmata / arduino

Firmata firmware for Arduino
GNU Lesser General Public License v2.1
1.53k stars 515 forks source link

Adafruit Metro M4 (SAMD51) support #415

Open Dorme opened 5 years ago

Dorme commented 5 years ago

Hi guys,

Is it possible to implement support for the Adafruit Metro M4 board (https://www.adafruit.com/product/3382)? I'm trying to edit the boards.h file, but I keep on getting the error: "Please edit Boards.h with a hardware abstraction for this board".

#elif defined(ADAFRUIT_METRO_M4__SAMD51_)

soundanalogous commented 5 years ago

Can you provide a link to the pins_arduino.h and variant.h files for this board?

Dorme commented 5 years ago

I was able to solve the error I received: #elif defined(_VARIANT_METRO_M4_)

Tried to complete the rest of the boards.h file:

#elif defined(_VARIANT_METRO_M4_)
#define TOTAL_ANALOG_PINS       NUM_ANALOG_INPUTS // 8
#define TOTAL_PINS              NUM_DIGITAL_PINS // 20
#define VERSION_BLINK_PIN       LED_BUILTIN // 13
#define IS_PIN_DIGITAL(p)       ((p) >= 0 && (p) <= 13) // 0..13 - Digital pins
#define IS_PIN_ANALOG(p)        ((p) >= 14 && (p) < 19) // 14..19 - Analog pins
#define IS_PIN_PWM(p)           (IS_PIN_DIGITAL(p) && digitalPinHasPWM(p))
#define IS_PIN_I2C(p)           ((p) == PIN_WIRE_SDA || (p) == PIN_WIRE_SCL) // SDA=22, SCL=23
#define IS_PIN_SERIAL(p)        ((p) == PIN_SERIAL1_RX || (p) == PIN_SERIAL1_TX) // RX=0, TX=1
#define PIN_TO_DIGITAL(p)       (p)
#define PIN_TO_ANALOG(p)        (p-A0)
#define PIN_TO_PWM(p)           PIN_TO_DIGITAL(p)

But then I get this error:

C:\Program Files (x86)\Arduino\libraries\Servo\src\samd\Servo.cpp:44:60: error: 'volatile struct TC_STATUS_Type::<anonymous>' has no member named 'SYNCBUSY'

 #define WAIT_TC16_REGS_SYNC(x) while(x->COUNT16.STATUS.bit.SYNCBUSY);

Link to the pins_arduino.h and variant.h files: metro_m4.zip

soundanalogous commented 5 years ago

Seems there is an incompatibility in the Servo class. This has happened in the past with a few boards. Try commenting out the Servo functionality in StandardFirmata and see if it then compiles. You can also check if that Servo library is up-to-date.

Dorme commented 5 years ago

I've upgraded the Servo library to the latest version available (1.1.3) but it does not solve the issue.

...\Servo.cpp: In function 'void Servo_Handler(timer16_Sequence_t, Tc*, uint8_t, uint8_t)':
...\Servo.cpp:44:60: error: 'volatile struct TC_STATUS_Type::<anonymous>' has no member named 'SYNCBUSY'
 #define WAIT_TC16_REGS_SYNC(x) while(x->COUNT16.STATUS.bit.SYNCBUSY);

After commenting out the Servo functionality I'm able to compile StandardFirmata and upload it to the Metro M4.

ManOnPajamas commented 4 years ago

Hello @Dorme ! How did you get it work? Which sections did you comment out?

ManOnPajamas commented 4 years ago

Nvm. Got it! :)