Yes, "variant.cpp"/"variant.h" are the places to look.
If it's not there, it's possible to get Serial2 working on D12 (Rx) and D10 (Tx) without modification to the "variant" files, using the following code in your Arduino sketch. This code example simply echos back characters sent from the Arduino IDE console:
// Serial2 pin and pad definitions (in Arduino files Variant.h & Variant.cpp)
#define PIN_SERIAL2_RX (34ul) // Pin description number for PIO_SERCOM on D12
#define PIN_SERIAL2_TX (36ul) // Pin description number for PIO_SERCOM on D10
#define PAD_SERIAL2_TX (UART_TX_PAD_2) // SERCOM pad 2
#define PAD_SERIAL2_RX (SERCOM_RX_PAD_3) // SERCOM pad 3
// Instantiate the Serial2 class
Uart Serial2(&sercom1, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
void setup()
{
Serial2.begin(115200); // Begin Serial2
}
void loop()
{
if (Serial2.available()) // Check if incoming data is available
{
byte byteRead = Serial2.read(); // Read the most recent byte
Serial2.write(byteRead); // Echo the byte back out on the serial port
}
}
void SERCOM1_Handler() // Interrupt handler for SERCOM1
{
Serial2.IrqHandler();
}
Implementing Serial3 however, requires a modification to the "variant.cpp" file. Just dd the two following lines to the end of the "g_APinDescription" array in the file ..Computer\AppData\Roaming\Arduino15\packages\arduino\hardware\samd\1.6.1\variants\arduino_zero\variant.cpp:
// 44..45 - SERCOM2
{ PORTA, 14, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SERCOM2/PAD[2]
{ PORTA, 15, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SERCOM2/PAD[3]
Then to get Serial3 working on D5 (Rx) and D2 (Tx) on the Zero (or D5 (Rx) and D4 (Tx) on the M0 Pro), use the following code:
// Serial3 pin and pad definitions (in Arduino files Variant.h & modified Variant.cpp)
#define PIN_SERIAL3_RX (45ul) // Pin description number for PIO_SERCOM on D5
#define PIN_SERIAL3_TX (44ul) // Pin description number for PIO_SERCOM on D2
#define PAD_SERIAL3_TX (UART_TX_PAD_2) // SERCOM pad 2
#define PAD_SERIAL3_RX (SERCOM_RX_PAD_3) // SERCOM pad 3
// Instantiate the Serial3 class
Uart Serial3(&sercom2, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
void setup()
{
Serial3.begin(115200); // Begin Serial3
}
void loop()
{
if (Serial3.available()) // Check if incoming data is available
{
byte byteRead = Serial3.read(); // Read the most recent byte
Serial3.write(byteRead); // Echo the byte back out on the serial port
}
}
void SERCOM2_Handler() // Interrupt handler for SERCOM2
{
Serial3.IrqHandler();
}
Or alternatively, just replace your "variant.cpp" and "variant.h" files (in the directory specified above) with these modified ones (attached). This allows you to call on Serial2 and Serial3 in your Arduino sketch directly without any additional code:
variant.h (6.88 KB)
variant.cpp (18.9 KB)