platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
78 stars 105 forks source link

Custom board SAMD21 E18A pin definitions #137

Closed xsrf closed 3 years ago

xsrf commented 3 years ago

Hi, I've got a custom board with a SAMD21 E18A on it. I want to program it using Platform IO (VS Code) and want to be able to use Arduino libraries. Since I couldn't find a custom board board, I went with adafruit_trinket_m0. Now I wan't to toggle IOs PA05 to PA07 but I can't find their names. How do I refer to an IO like PA05?!

This is my platformio.ini:

[env:adafruit_trinket_m0]
platform = atmelsam
board = adafruit_trinket_m0
framework = arduino
board_build.mcu = samd21e18a

This is my code:

#include <Arduino.h>

#define LED_R PIN_PA06 // actually toggles PA09 by measurement
#define LED_G PIN_PA05 // actually toggles PA08 by measurement
#define LED_B PIN_PA07 // actually toggles PA00 by measurement

void setup() {
  pinMode(LED_R, OUTPUT);
  pinMode(LED_G, OUTPUT);
  pinMode(LED_B, OUTPUT);
}

uint8_t cnt = 0;
void loop() {
  cnt++;
  digitalWrite(LED_R,cnt&0x01);
  digitalWrite(LED_G,cnt&0x02);
  digitalWrite(LED_B,cnt&0x04);
  delay(10);
}

Actually PA08 is toggled instead of PA05. The pin definitions from samd21e18a.h are not very helpful:

...
#define PIN_PA05                           5  /**< \brief Pin Number for PA05 */
#define PORT_PA05                 (1ul <<  5) /**< \brief PORT Mask  for PA05 */
#define PIN_PA06                           6  /**< \brief Pin Number for PA06 */
#define PORT_PA06                 (1ul <<  6) /**< \brief PORT Mask  for PA06 */
#define PIN_PA07                           7  /**< \brief Pin Number for PA07 */
#define PORT_PA07                 (1ul <<  7) /**< \brief PORT Mask  for PA07 */

Guess these are just the bit positions in the actual port register and are not meant to be used as pin names in the Arduino world. When I use this:

#define LED_R 4 // actually PA06 by measurement
#define LED_G PIN_PA05 // actually PA08 by measurement
#define LED_B 3 // actually PA07 by measurement

It actually works. 3/4 are the pin labels used by the adafruit trinket M0. But the problem is, the trinket only has 5 IOs and PA05 isn't one of them.

All the SAMD21 E18A boards available only have a hand full of IOs broken out. Isn't there a way to use the SAMD21 without writing my own board definition?

valeros commented 3 years ago

Hi @xsrf ! This repository is not the right place to ask such questions. Please forward your question to the community forum https://community.platformio.org/c/development-platforms/17