0

Adafruit M4 Express: Add'l Serial Communication
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit M4 Express: Add'l Serial Communication

by cjs on Thu Feb 07, 2019 10:12 am

Bought an M4 express for the huge improvements in processing and memory over the Arduino and found out (too late) that it doesn't support the SoftwareSerial library. I tried to follow this tutorial https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-serial but just don't understand what I need to change in what files and why. I don't know why I'm so dense.

I also tried to follow this post https://forums.adafruit.com/viewtopic.php?f=63&t=137941#p682497 but again, I don't understand.

From what I can see I need to do four things:

1. Modify variant.cpp
2. Modify variant.h
3. Add some declarations and definitions in my sketch
4. Move my wires from pins 5 (RX) and 6 (TX) to whatever the newly defined pins are

I'm really not a fan of making changes to libraries in the IDE; I'm afraid I'll screw something up (I did create backups) and I'm concerned that someday an update will break everything because my customized files were over-written.

Can someone just share with me the files that work (variant.cpp and variant.h) and verify that this is what needs to go in my sketch (if I'm using pins 10 & 11, of course)?

Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>   // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function
 
Uart Serial2 (&sercom1, 11, 10, SERCOM_RX_PAD_0, UART_TX_PAD_2);
void SERCOM1_Handler()
{
  Serial2.IrqHandler();
}
 
void setup() {
  Serial.begin(115200);
 
  Serial2.begin(115200);
 
  // Assign pins 10 & 11 SERCOM functionality
  pinPeripheral(10, PIO_SERCOM);
  pinPeripheral(11, PIO_SERCOM);
}
 
uint8_t i=0;
void loop() {
  Serial.print(i);
  Serial2.write(i++);
  if (Serial2.available()) {
    Serial.print(" -> 0x"); Serial.print(Serial2.read(), HEX);
  }
  Serial.println();
 
  delay(10);
}


Sorry if I'm being bitchy, it's been a long week already and I really need this board to work so I can get back to writing code and making robots move stuff and thereby making everyone happy.

Because nothing makes people happier than robots moving stuff.

Thanks for your time.

cjs
 
Posts: 12
Joined: Sun Feb 22, 2009 3:49 pm

Re: Adafruit M4 Express: Add'l Serial Communication

by roborich on Thu Feb 07, 2019 11:55 pm

I had your exact problem.

So here's the bad news. With the sercom you're using only pin D13 can be used as the TX output. The M4 is not as flexible as the M0 in this regard. It only allows you to place the Tx output on mux 0 which feeds out to D13. And just so your aware, D13 will be active on boot doing stuff not necessarily useful for serial transmission.

The good thing about the M4 is that TX1 and RX1 on D0 and D1 are decoupled from the USB port. so you may have to rewire your shield, but you wont get junk on your serial I/O when you downloading or talking to your board using the serial monitor.

roborich
 
Posts: 10
Joined: Sun Mar 31, 2013 8:55 pm

Re: Adafruit M4 Express: Add'l Serial Communication

by westfw on Fri Feb 08, 2019 3:06 am

With the sercom you're using only pin D13 can be used as the TX output.

Yes, the D51 SerCom peripherals seem to be quite restricted WRT where the TX output can happen (on SAMD21 you had two choices.)
SerCom1 can only transmit on Pin13.

SerCom2 is used for SPI, and SerCom5 is used for I2C. In theory, these could be re-configured as serial ports if you're not using them for their normal function. I'm not sure how well that would interact with the rest of Arduino or CircuitPython.

This leaves SerCom0, which has its TX pin on A3 (Rx on A1 or A2), Sercom3 on D0/D1 (already implements "Serial1"), SerCom4 on A4/A5 or D7/D4, and I guess (more theory) SerCom7 on the debug connector (seems like a bad idea, though!)
westfw
 
Posts: 1522
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Adafruit M4 Express: Add'l Serial Communication

by cjs on Sun Feb 10, 2019 8:33 pm

roborich wrote:I had your exact problem.

So here's the bad news. With the sercom you're using only pin D13 can be used as the TX output. The M4 is not as flexible as the M0 in this regard. It only allows you to place the Tx output on mux 0 which feeds out to D13. And just so your aware, D13 will be active on boot doing stuff not necessarily useful for serial transmission.

The good thing about the M4 is that TX1 and RX1 on D0 and D1 are decoupled from the USB port. so you may have to rewire your shield, but you wont get junk on your serial I/O when you downloading or talking to your board using the serial monitor.


Thank you for replying, I appreciate it. So are you saying that on this board I can use the USB port for all my debug messaging (Serial.read(), Serial.println(), etc) but ALSO use D0 and D1 as another pair of serial TX/RX? This was not possible in the past as they were the same bus on Arduino. If this is the case how do I address that port (D0 & D1) instead of the USB serial port (serial monitor)?

I don't see anything about it in the documentation for the board but maybe I'm overlooking something. On my Mega at home I use Serial1, Serial2, and Serial3, is it similar to that?

I have no problem with re-wiring anything, I'll do whatever it takes to make this work.

Thanks again for replying.

cjs
 
Posts: 12
Joined: Sun Feb 22, 2009 3:49 pm

Re: Adafruit M4 Express: Add'l Serial Communication

by westfw on Tue Feb 12, 2019 4:50 am

The USB port will be "Serial", and pin0/1 are "Serial1".
(This is compatible with the 32u4-based boards like Leonardo and Micro, BTW.)

It's documented in the pinout section https://learn.adafruit.com/adafruit-met ... 51/pinouts
But I guess it's not really singled out for attention.

The Metro M4 SPI pins (on the "ISP connector") and I2C pins (SDA/SCL, to the left of AREF) are also distinct pins on the Metro M4, rather than "sharing" functionality with other pins like they do on the Uno. The NeoPixel, QSPI flash, and debug interface are also independent. (the chip itself has 60 IO pins, so it would have been a bit depressing to only have 20 of those made useful.)
westfw
 
Posts: 1522
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Adafruit M4 Express: Add'l Serial Communication

by cjs on Tue Feb 12, 2019 11:18 am

westfw wrote:The USB port will be "Serial", and pin0/1 are "Serial1".
(This is compatible with the 32u4-based boards like Leonardo and Micro, BTW.)

It's documented in the pinout section https://learn.adafruit.com/adafruit-met ... 51/pinouts
But I guess it's not really singled out for attention.

The Metro M4 SPI pins (on the "ISP connector") and I2C pins (SDA/SCL, to the left of AREF) are also distinct pins on the Metro M4, rather than "sharing" functionality with other pins like they do on the Uno. The NeoPixel, QSPI flash, and debug interface are also independent. (the chip itself has 60 IO pins, so it would have been a bit depressing to only have 20 of those made useful.)


Understood, D0 and D1 are Serial1, thank you for the clarification. I'll give it a shot this afternoon and post back here.

I really should have picked up on that from the documentation.

cjs
 
Posts: 12
Joined: Sun Feb 22, 2009 3:49 pm

Please be positive and constructive with your questions and comments.