0

[SOLVED] ItsyBitsy M4 - SERCOM5 as UART
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

[SOLVED] ItsyBitsy M4 - SERCOM5 as UART

by rs2845 on Fri Feb 08, 2019 4:10 pm

Hi,

I've been trying to use `SERCOM5` to provide my projects with an additional hardware UART.

After looking at the [Adafruit schematics](https://cdn-learn.adafruit.com/assets/a ... 1529261754) it mentions that the SERCOM 5 is available on pins D13-D10.

The Microchip [ATSAMD51G19A data sheet ](http://ww1.microchip.com/downloads/en/D ... 01507C.pdf) states that pins `PA21` and `PA20` are available for `SERCOM5`, with `PA21` (D11) using `SERCOM5.3` (first column, so I assume primary) and that `PA20` (D10) is using `SERCOM5.2` (again, first column so assuming primary).

I’ve then looked at the [Adafruit guide](https://learn.adafruit.com/using-atsamd ... new-serial) for the ATSAMD21 (which I’ve used for SERCOMS before on Feather M0), to determine which enums to use for those SERCOM lines as there’s no guide for the SAMD51 without messing around with CircuitPython (please, consider adding some SAMD51 specifics for Arduino users):

Code: Select all | TOGGLE FULL SIZE
The two together let us define the muxing. For example we can define which pin is for RX
* SERCOM_RX_PAD_0 means RX on SERCOMn.0
* SERCOM_RX_PAD_1 means RX on SERCOMn.1
* SERCOM_RX_PAD_2 means RX on SERCOMn.2
* SERCOM_RX_PAD_3 means RX on SERCOMn.3
and then for TX:
* UART_TX_PAD_0 means TX on SERCOMn.0
* UART_TX_PAD_2 means TX on SERCOMn.2


If I’ve interpreted correctly (SERCOM5.3 => SERCOM_RX_PAD_3 and SERCOM5.2 => UART_TX_PAD_2), this is how I should be defining the UART port:
Code: Select all | TOGGLE FULL SIZE
Uart NewSerialPort(&sercom5, 11, 10, SERCOM_RX_PAD_3, UART_TX_PAD_2) ; //[(30)PA21 =>D11 SERCOM5.3][(29)PA20 =>D10 SERCOM5.2]


I’m not sure if I’ve missed something or made a mistake. Have all SERCOMs been fully implemented for the M4 processors? I've got as much out of the datasheets that I can actually understand, so I am now not sure how to proceed.

Below is the test sketch I am running with D11/10 connected to allow a loopback. No data is returned, I don't have an oscilloscope either to check the pins:
Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>   // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function

Uart NewSerialPort(&sercom5, 11, 10, SERCOM_RX_PAD_3, UART_TX_PAD_2); //[(30)PA21 =>D11 SERCOM5.3][(29)PA20 =>D10 SERCOM5.2]

void SERCOM5_0_Handler() {
    NewSerialPort.IrqHandler();
}
void SERCOM5_1_Handler() {
    NewSerialPort.IrqHandler();
}
void SERCOM5_2_Handler() {
    NewSerialPort.IrqHandler();
}
void SERCOM5_3_Handler() {
    NewSerialPort.IrqHandler();
}


void setup() {
  Serial.begin(115200);
  NewSerialPort.begin(115200);
  // Assign pins 10 & 11 SERCOM functionality
  pinPeripheral(10, PIO_SERCOM); // D10 defined as PIO_DIGITAL by default
  pinPeripheral(11, PIO_SERCOM); // D10 defined as PIO_DIGITAL by default
}

uint8_t i=0;
void loop() {
    // Serial.print(i);
    NewSerialPort.write("TEST");
    if (NewSerialPort.available()) {
        Serial.print("\nREAD -> "); Serial.print(NewSerialPort.read());
    }

    delay(10);
}



Note - I opened this issue on the Adafruit/arduinocore-samd GitHub repository, no reply. Hoping someone can help here as I have £100+ worth of these modules for my dissertation.
Last edited by rs2845 on Sat Feb 16, 2019 4:29 pm, edited 1 time in total.

rs2845
 
Posts: 14
Joined: Fri Feb 23, 2018 8:16 pm

Re: ItsyBitsy M4 - SERCOM5 as UART

by adafruit_support_mike on Sat Feb 09, 2019 3:43 am

The SAMD51's SERCOMs work differently than the SAMD21's. Among other things, you can only configure them with specific sets of pins called 'IOSETs', which are listed in section 6.2.8.1 of the SAMD51 datasheet:

http://ww1.microchip.com/downloads/en/D ... 01507C.pdf

Then there are some additional details related to pin selection for a UART. Within an IOSET, only PAD0 will work as the TX pin, for instance. That isn't mentioned explicitly in any of the text, but shows up in the bit-field descriptions for SERCOM UART configuration in section 34.8.1

The SAMD51 board support package defines all five of the available SERCOMs though, and SERCOM 5 is available on the ItsyBitsy.

This thread has more information about configuring SAMD51 SERCOMS for Serial communication, but they cover different pins because SERCOM 5 is already used by some of our other boards.

adafruit_support_mike
 
Posts: 57106
Joined: Thu Feb 11, 2010 2:51 pm

Re: ItsyBitsy M4 - SERCOM5 as UART

by rs2845 on Wed Feb 13, 2019 4:14 am

adafruit_support_mike wrote:The SAMD51's SERCOMs work differently than the SAMD21's. Among other things, you can only configure them with specific sets of pins called 'IOSETs', which are listed in section 6.2.8.1 of the SAMD51 datasheet:

http://ww1.microchip.com/downloads/en/D ... 01507C.pdf

Then there are some additional details related to pin selection for a UART. Within an IOSET, only PAD0 will work as the TX pin, for instance. That isn't mentioned explicitly in any of the text, but shows up in the bit-field descriptions for SERCOM UART configuration in section 34.8.1

The SAMD51 board support package defines all five of the available SERCOMs though, and SERCOM 5 is available on the ItsyBitsy.

This thread has more information about configuring SAMD51 SERCOMS for Serial communication, but they cover different pins because SERCOM 5 is already used by some of our other boards.



Thanks for the response, I’ve closed that Github issue. I see only the sercoms used by default are initialised which makes sense, that threw me off thinking they weren’t implemented.

I’ve spent the last few days reading over the datasheet again (including section 33-34) but haven’t been able to decipher anything new. The sercom pins I identified seemingly match the IOSET pins in table 6.2.8.1 table6-15.
Is the Dotstar using SERCOM5 by any chance on the ItsyBitsy M4? I wonder if there’s a conflict there.

If someone in the production/R&D team at Adafruit could spare some time and try implementing another UART SERCOM, because at this point anything additional I try is guesswork and the last thing I want is to have any of these expensive boards damaged. There’s clearly something I’m missing but I can’t figure out what it is.

I’m happy to juggle around the rest of my project’s IO connections if a different SERCOM is needed. Though I am using SPI, UART and I2C already by the default mapped pins.

Ps - was the last part of your post meant to include a link?

rs2845
 
Posts: 14
Joined: Fri Feb 23, 2018 8:16 pm

Re: ItsyBitsy M4 - SERCOM5 as UART

by westfw on Thu Feb 14, 2019 10:14 pm

SERCOM5.2 => UART_TX_PAD_2
Uart NewSerialPort(&sercom5, 11, 10, SERCOM_RX_PAD_3, UART_TX_PAD_2) ; //[(30)PA21 =>D11 SERCOM5.3][(29)PA20 =>D10 SERCOM5.2]

You can't have TX_PAD_2 on a SAMD51; essentially only PAD0 (pin 13) can be TXD.

The "IO set" thing was a bit of a red herring...
westfw
 
Posts: 1521
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: ItsyBitsy M4 - SERCOM5 as UART

by rs2845 on Fri Feb 15, 2019 1:13 am

Hi,

Thanks for your clarification on this, does it state this anywhere in the datasheet? It’s so damn long I’ve probably missed it

I wonder if i’ll hit any other specific restrictions if I ever changed this SERCOM to use I2C or SPI instead.

rs2845
 
Posts: 14
Joined: Fri Feb 23, 2018 8:16 pm

Re: ItsyBitsy M4 - SERCOM5 as UART

by westfw on Fri Feb 15, 2019 5:06 am

It's in the description of Control A in the SERCOM USART section.
It's DIFFERENT than SAMD21, SAMD1x and SAMC21, which as you said can have TxD on either Pad0 or Pad2.

This is really annoying! (Common Atmel, if you're going to have a common "SERCOM" peripheral in several different chips, it ought to behave the same!)
Attachments
Screen Shot 2019-02-15 at 12.50.34 AM.png
Screen Shot 2019-02-15 at 12.50.34 AM.png (100.68 KiB) Viewed 103 times
westfw
 
Posts: 1521
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: ItsyBitsy M4 - SERCOM5 as UART

by rs2845 on Sat Feb 16, 2019 1:53 am

Finally got some time to try your suggestion to use SERCOM5.0 as TXD. Just a query regarding your reference to pin 13 (Arduino D13) - D13 is SERCOM 5.1, D12 is SERCOM 5.0 so using that as TXD.

So on that logic, I tried:
Code: Select all | TOGGLE FULL SIZE
Uart Serial2(&sercom5, 13, 12, SERCOM_RX_PAD_1, UART_TX_PAD_0); // D13 => 5.1, D12 => 5.0


Still getting no data out though. Been a long day so maybe I’ve made another mistake.

Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>
#include "wiring_private.h" // pinPeripheral() function

Uart Serial2(&sercom5, 13, 12, SERCOM_RX_PAD_1, UART_TX_PAD_0);
void SERCOM5_0_Handler()
{
    Serial2.IrqHandler();
}
void SERCOM5_1_Handler()
{
    Serial2.IrqHandler();
}

void setup() {
  // put your setup code here, to run once:
  pinPeripheral(12, PIO_SERCOM);
  pinPeripheral(13, PIO_SERCOM);
  Serial.begin(115200);
  Serial2.begin(9600);
 
  while (!Serial.available());
 
  Serial.print("\nStarting Serial2 Monitoring...\n");
  while(true) {
    Serial2.write("\n--- TESTING PORT ---");
    while (Serial2.available()) {
      Serial.print("\nREAD: ");Serial.print(char(Serial2.read()));
    }
    delay(1000);
    Serial.write(". ");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}
Last edited by rs2845 on Sat Feb 16, 2019 11:52 am, edited 1 time in total.

rs2845
 
Posts: 14
Joined: Fri Feb 23, 2018 8:16 pm

Re: ItsyBitsy M4 - SERCOM5 as UART

by westfw on Sat Feb 16, 2019 7:21 am

Pins [westfw] refers to don’t match


You're right! And you've found an error in My spreadsheet that I'd been referring to.
Note that Feather m4 and ItsyBitsy M4 have pin12/pin13 "swapped" :-(
Still getting no data out though.
Code: Select all | TOGGLE FULL SIZE
  pinPeripheral(12, PIO_SERCOM);
  pinPeripheral(13, PIO_SERCOM);

I think you need PIO_SERCOM_ALT to get Sercom5 on D12/D13?
PIO_SERCOM will get you SERCOM3.
Attachments
Screen Shot 2019-02-16 at 3.15.32 AM.png
Screen Shot 2019-02-16 at 3.15.32 AM.png (26.55 KiB) Viewed 89 times
westfw
 
Posts: 1521
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: ItsyBitsy M4 - SERCOM5 as UART

by rs2845 on Sat Feb 16, 2019 1:13 pm

westfw wrote:I think you need PIO_SERCOM_ALT to get Sercom5 on D12/D13?


Totally right, D12/D13 are both "PIO_SERCOM_ALT"!

I've got it working, though I did have to include IRQ handlers for Sercom 5.2 and 5.3 as well which is no big deal.

Thank you for your assistance westfw! For anybody else wishing to use the SERCOM5 as a UART, below is a confirmed working implementation for you:

Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>
#include "wiring_private.h" // pinPeripheral() function

Uart Serial2(&sercom5, 13, 12, SERCOM_RX_PAD_1, UART_TX_PAD_0); // 13(D13 =>PA22 => Sercom 5.1) , 12(D12 =>PA23 => Sercom 5.0)

void SERCOM5_0_Handler()
{
    Serial2.IrqHandler();
}
void SERCOM5_1_Handler()
{
    Serial2.IrqHandler();
}

void SERCOM5_2_Handler()
{
    Serial2.IrqHandler();
}

void SERCOM5_3_Handler()
{
    Serial2.IrqHandler();
}

void setup() {
  // put your setup code here, to run once:
  pinPeripheral(12, PIO_SERCOM_ALT);
  pinPeripheral(13, PIO_SERCOM_ALT);
  Serial.begin(115200);
  Serial2.begin(9600);
 
  while (!Serial.available());
 
  Serial.print("\nStarting Serial2 Monitoring...\n");
  while(true) {
    Serial2.write("\n--- TESTING PORT ---");
    while (Serial2.available()) {
      Serial.print("\nREAD: ");Serial.print(char(Serial2.read()));
    }
    delay(1000);
    Serial.write(". ");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

rs2845
 
Posts: 14
Joined: Fri Feb 23, 2018 8:16 pm

Re: ItsyBitsy M4 - SERCOM5 as UART

by westfw on Sat Feb 16, 2019 4:27 pm

excellent! Thanks for posting your working version!
westfw
 
Posts: 1521
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: ItsyBitsy M4 - SERCOM5 as UART

by Nova_Yiot on Sat Feb 23, 2019 4:07 am

Code: Select all | TOGGLE FULL SIZE
rs2845 wrote:
westfw wrote:I think you need PIO_SERCOM_ALT to get Sercom5 on D12/D13?


Totally right, D12/D13 are both "PIO_SERCOM_ALT"!

I've got it working, though I did have to include IRQ handlers for Sercom 5.2 and 5.3 as well which is no big deal.

Thank you for your assistance westfw! For anybody else wishing to use the SERCOM5 as a UART, below is a confirmed working implementation for you:

Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>
#include "wiring_private.h" // pinPeripheral() function

Uart Serial2(&sercom5, 13, 12, SERCOM_RX_PAD_1, UART_TX_PAD_0); // 13(D13 =>PA22 => Sercom 5.1) , 12(D12 =>PA23 => Sercom 5.0)

void SERCOM5_0_Handler()
{
    Serial2.IrqHandler();
}
void SERCOM5_1_Handler()
{
    Serial2.IrqHandler();
}

void SERCOM5_2_Handler()
{
    Serial2.IrqHandler();
}

void SERCOM5_3_Handler()
{
    Serial2.IrqHandler();
}

void setup() {
  // put your setup code here, to run once:
  pinPeripheral(12, PIO_SERCOM_ALT);
  pinPeripheral(13, PIO_SERCOM_ALT);
  Serial.begin(115200);
  Serial2.begin(9600);
 
  while (!Serial.available());
 
  Serial.print("\nStarting Serial2 Monitoring...\n");
  while(true) {
    Serial2.write("\n--- TESTING PORT ---");
    while (Serial2.available()) {
      Serial.print("\nREAD: ");Serial.print(char(Serial2.read()));
    }
    delay(1000);
    Serial.write(". ");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}


hai,
am using adafruit feather m0 board. i want to try serial event for serial1. how can i use it?as a inteerput

Nova_Yiot
 
Posts: 6
Joined: Mon Apr 23, 2018 7:23 am

Please be positive and constructive with your questions and comments.