0

ItsyBitsy M4 - using SERCOM5 for 2nd UART
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ItsyBitsy M4 - using SERCOM5 for 2nd UART

by TheFallen on Wed Nov 07, 2018 7:20 pm

Hi,

I've been using: https://learn.adafruit.com/using-atsamd ... ew-serial# to try and create 2nd hardware serial port on my ItsyBitsy M4. I'm only interested in monitoring incoming serial characters so TX is unconnected.

My code has some extra functions but the basics of it are:
Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>
#include "wiring_private.h"

Uart Serial5 (&sercom5, 10, 12, SERCOM_RX_PAD_2, UART_TX_PAD_0);
void SERCOM5_Handler() { Serial5.IrqHandler(); }

void setup(void) {

  delay(10);

  Serial.begin(115200);

  Serial5.begin(115200);
  pinPeripheral(10, PIO_SERCOM); // compiles, uploads but then hangs
  // or
 //pinPeripheral(10, PIO_SERCOM_ALT); // runs but doesn't see characters

}

void loop() {

  if(Serial5.available() == 10) Serial.println("Got 10 chars!");
  else if(Serial5.available() > 0) Serial.println("Got some chars!");
  else Serial.println("No chars!");

  delay(1000);
}



I'm completely stumped by this and welcome any suggestions. Thanks!
TheFallen
 
Posts: 94
Joined: Mon Feb 08, 2010 1:28 pm
Location: UK

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

by adafruit_support_mike on Thu Nov 08, 2018 5:02 am

The SAMD51's SERCOMs are a bit different from the SAMD21's, and there are some big differences in the pin multiplexer.

The SAMD51 groups SERCOM pins into what the datasheet calls IOSETs, listed in section 6.2.6. Each IOSET has four PADs, and each PAD can do certain things in a SERCOM's configuration. IIRC, only PAD0 can work as a TX pin.

Right now the best reference for working with the SAMD51's SERCOMs is the code in the board support package:

https://github.com/adafruit/ArduinoCore ... es/arduino

You'll want to check the SERCOM and Uart .c and .h files, plus the variant file for one of the M4 boards:

https://github.com/adafruit/ArduinoCore ... ariant.cpp

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

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

by TheFallen on Thu Nov 08, 2018 6:38 pm

I'm not seeing the problem? You say that the SAMD51 SERCOMs are different to the ones on the SAMD21 but list something they have in common? They both use IOSETs, that's a SERCOM feature. I think there's a minor difference on the M4's not having TX on PAD 2 or 3, only PAD 0 but as I'm not interested in TX and am using PAD 0 that shouldn't be a problem.

I thought you might be on to something regarding the pin definitions in 'variant.cpp' as I remembered that some pins have PIO_SERCOM but looking though them again only default SERCOM pins have PIO_SERCOM on them. And comparing the entries between pins below, they look pretty identical.

Arduino Zero 'variant.cpp' :
Code: Select all | TOGGLE FULL SIZE
  { PORTA, 18, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH0, TC3_CH0, EXTERNAL_INT_2 }, // TC3/WO[0]
  { PORTA, 16, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM2_CH0, TCC2_CH0, EXTERNAL_INT_0 }, // TCC2/WO[0]

ItsyBitsy M4 'variant.cpp':
Code: Select all | TOGGLE FULL SIZE
  { PORTA,  20, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM1_CH4, TCC1_CH4, EXTERNAL_INT_4 }, // D10

Looking the Adafruit version of 'SERCOM.cpp' there's only one difference between SAMD21 and SAMD51 chips, it changes where the peripheral clock is coming from. So while it's a bit different I'd hardly say it bears on what I'm trying to do. There is one difference between the ItsyBitsy M4 and Arduino Zero, the Zero uses all of the SERCOMs, could it be that the board variant doesn't initialise all the SERCOMs?
TheFallen
 
Posts: 94
Joined: Mon Feb 08, 2010 1:28 pm
Location: UK

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

by adafruit_support_mike on Fri Nov 09, 2018 3:09 am

The M4 variant defines the SERCOMs, but only initializes the ones it uses for Serial1, SPI, and I2C.

I'd suggest looking through the SAMD21 and SAMD51 datasheets for a more detailed comparison of the two SERCOMs.

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

Please be positive and constructive with your questions and comments.