Adding a serial uart tx/rx on D4 and D5 of MKRZERO

Hello,

I'm currently attempting to add an additional serial port to my MKRZERO using pins D4 and D5. These are the only available pins left in my project for this purpose, with D4 serving as TX and D5 as RX. Despite investing hours into multiple unsuccessful attempts, I'm struggling to achieve a successful setup.

I have connected an external terminal on my PC to the D4 and D5 pins of the Arduino. This terminal is configured to operate at 115200 baud rate with an 8N1 configuration. Additionally, I've connected a scope to the D4 pin on the Arduino. Despite my efforts, I'm not observing any activity on the scope or terminal.

I would greatly appreciate any assistance in identifying what might be causing this issue. If anyone could guide me through troubleshooting steps or offer insights into what might be wrong, I would be extremely grateful.
Marc.

Here are my most important lines for that:

.
.
.
Uart mySerial (&sercom4, 5, 4, SERCOM_RX_PAD_3, UART_TX_PAD_2); // Create the new UART instance assigning it to pin 5 and 4 (MKR board pin D5 and D4)
  // Attach the interrupt handler to the SERCOM pour le TDR
  void SERCOM4_Handler()
  {
    mySerial.IrqHandler();
  }


void setup() {

.
.

  // Set up serial pour port série TDR
  mySerial.begin(115200);
  pinPeripheral(5, PIO_SERCOM); //Assign RX function to pin 5
  pinPeripheral(4, PIO_SERCOM); //Assign TX function to pin 4
.
.
.
.
in a fonction called from  loop() I have added this to send t the terminal on my PC:
mySerial.println("Hello dear!");  // transmit data to terminal on PC

I think you need PIO_SERCOM_ALT for those.

If I do that, I loose acces to the SD card.

Where do you have the SD card connected? According to my notes, SPI should be on SerCom 1 or 3, on pins 11/12/13...
(Note that my notes have not been verified/tested on MKRZero, so they might be wrong.)

The SD card on MKRZERO is not something I added by myself. Il's already there. As I said, if adding _ALT, then the card does not initialize.

Here is my complete variant .cpp file followed by some on my lines relating to the SD card. Thanks for your help, I really appreciate.

#include "variant.h"

const PinDescription g_APinDescription[] = {

/*
 +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+
 | Pin number |  MKR  Board pin  |  PIN   | Notes           | Peri.A |     Peripheral B      | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H |
 |            |                  |        |                 |   EIC  | ADC |  AC | PTC | DAC | SERCOMx | SERCOMx |  TCCx  |  TCCx  |    COM   | AC/GLCK  |
 |            |                  |        |                 |(EXTINT)|(AIN)|(AIN)|     |     | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 | 00         | D0               |  PA22  |                 |  *06   |     |     | X10 |     |   3/00  |   5/00  |* TC4/0 | TCC0/4 |          | GCLK_IO6 |
 | 01         | D1               |  PA23  |                 |  *07   |     |     | X11 |     |   3/01  |   5/01  |* TC4/1 | TCC0/5 | USB/SOF  | GCLK_IO7 |
 | 02         | D2               |  PA10  |                 |   10   | *18 |     | X02 |     |   0/02  |   2/02  |*TCC1/0 | TCC0/2 | I2S/SCK0 | GCLK_IO4 |
 | 03         | D3               |  PA11  |                 |   11   | *19 |     | X03 |     |   0/03  |   2/03  |*TCC1/1 | TCC0/3 | I2S/FS0  | GCLK_IO5 |
 | 04         | D4               |  PB10  |                 |  *10   |     |     |     |     |         |   4/02  |* TC5/0 | TCC0/4 | I2S/MCK1 | GCLK_IO4 |
 | 05         | D5               |  PB11  |                 |  *11   |     |     |     |     |         |   4/03  |* TC5/1 | TCC0/5 | I2S/SCK1 | GCLK_IO5 |
 | 06         | D6               |  PA20  |                 |  *04   |     |     | X08 |     |   5/02  |   3/02  |        |*TCC0/6 | I2S/SCK0 | GCLK_IO4 |
 | 07         | D7               |  PA21  |                 |  *05   |     |     | X09 |     |   5/03  |   3/03  |        |*TCC0/7 | I2S/FS0  | GCLK_IO5 |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 */
  { PORTA, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), No_ADC_Channel, PWM4_CH0,   TC4_CH0,      EXTERNAL_INT_6    },
  { PORTA, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), No_ADC_Channel, PWM4_CH1,   TC4_CH1,      EXTERNAL_INT_7    },
  { PORTA, 10, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), ADC_Channel18,  PWM1_CH0,   TCC1_CH0,     EXTERNAL_INT_NONE },
  { PORTA, 11, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), ADC_Channel19,  PWM1_CH1,   TCC1_CH1,     EXTERNAL_INT_NONE },
  { PORTB, 10, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), No_ADC_Channel, PWM5_CH0,   TC5_CH0,      EXTERNAL_INT_10   },
  { PORTB, 11, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), No_ADC_Channel, PWM5_CH1,   TC5_CH1,      EXTERNAL_INT_11   },
  { PORTA, 20, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH6,   TCC0_CH6,     EXTERNAL_INT_4    },
  { PORTA, 21, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH7,   TCC0_CH7,     EXTERNAL_INT_5    },

/*
 +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+
 | Pin number |  MKR  Board pin  |  PIN   | Notes           | Peri.A |     Peripheral B      | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H |
 |            |                  |        |                 |   EIC  | ADC |  AC | PTC | DAC | SERCOMx | SERCOMx |  TCCx  |  TCCx  |    COM   | AC/GLCK  |
 |            |                  |        |                 |(EXTINT)|(AIN)|(AIN)|     |     | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 |            |       SPI        |        |                 |        |     |     |     |     |         |         |        |        |          |          |
 | 08         | MOSI             |  PA16  |                 |  *00   |     |     | X04 |     |  *1/00  |   3/00  |*TCC2/0 | TCC0/6 |          | GCLK_IO2 |
 | 09         | SCK              |  PA17  |                 |  *01   |     |     | X05 |     |  *1/01  |   3/01  | TCC2/1 | TCC0/7 |          | GCLK_IO3 |
 | 10         | MISO             |  PA19  |                 |   03   |     |     | X07 |     |  *1/03  |   3/03  |* TC3/1 | TCC0/3 | I2S/SD0  | AC/CMP1  |
 +------------+------------------+--------+-----------------+--------------------+-----+-----+---------+---------+--------+--------+----------+----------+
 |            |       Wire       |        |                 |        |     |     |     |     |         |         |        |        |          |          |
 | 11         | SDA              |  PA08  |                 |   NMI  | *16 |     | X00 |     |  *0/00  |   2/00  | TCC0/0 | TCC1/2 | I2S/SD1  |          |
 | 12         | SCL              |  PA09  |                 |   09   | *17 |     | X01 |     |  *0/01  |   2/01  | TCC0/1 | TCC1/3 | I2S/MCK0 |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 |            |      Serial1     |        |                 |        |     |     |     |     |         |         |        |        |          |          |
 | 13         | RX               |  PB23  |                 |   07   |     |     |     |     |         |  *5/03  |        |        |          | GCLK_IO1 |
 | 14         | TX               |  PB22  |                 |   06   |     |     |     |     |         |  *5/02  |        |        |          | GCLK_IO0 |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 */
                                                                                                                                               // DIPO=3 DOPO=0
  { PORTA, 16, PIO_SERCOM,  (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), No_ADC_Channel, PWM2_CH0,   TCC2_CH0,     EXTERNAL_INT_0    }, // MOSI: SERCOM1/PAD[0]
  { PORTA, 17, PIO_SERCOM,  (PIN_ATTR_DIGITAL                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1    }, // SCK:  SERCOM1/PAD[1]
  { PORTA, 19, PIO_SERCOM,  (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), No_ADC_Channel, PWM3_CH1,   TC3_CH1,      EXTERNAL_INT_NONE }, // MISO: SERCOM1/PAD[3]

                                                                                                                                               // PINOUT=0
  { PORTA,  8, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL                             ), ADC_Channel16,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NMI  }, // SDA:  SERCOM2/PAD[0]
  { PORTA,  9, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL                             ), ADC_Channel17,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SCL:  SERCOM2/PAD[1]

                                                                                                                                               // RXPO=3 TXPO=1
  { PORTB, 23, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL                             ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // RX:   SERCOM5/PAD[3]
  { PORTB, 22, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL                             ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // TX:   SERCOM5/PAD[2]


/*
 +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+
 | Pin number |  MKR  Board pin  |  PIN   | Notes           | Peri.A |     Peripheral B      | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H |
 |            |                  |        |                 |   EIC  | ADC |  AC | PTC | DAC | SERCOMx | SERCOMx |  TCCx  |  TCCx  |    COM   | AC/GLCK  |
 |            |                  |        |                 |(EXTINT)|(AIN)|(AIN)|     |     | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 | 15         | A0 / DAC0        |  PA02  |                 |   02   | *00 |     | Y00 | OUT |         |         |        |        |          |          |
 | 16         | A1               |  PB02  |                 |  *02   | *10 |     | Y08 |     |         |   5/00  |        |        |          |          |
 | 17         | A2               |  PB03  |                 |  *03   | *11 |     | Y09 |     |         |   5/01  |        |        |          |          |
 | 18         | A3               |  PA04  |                 |   04   | *04 |  00 | Y02 |     |         |   0/00  |*TCC0/0 |        |          |          |
 | 19         | A4               |  PA05  |                 |   05   | *05 |  01 | Y03 |     |         |   0/01  |*TCC0/1 |        |          |          |
 | 20         | A5               |  PA06  |                 |   06   | *06 |  02 | Y04 |     |         |   0/02  | TCC1/0 |        |          |          |
 | 21         | A6               |  PA07  |                 |   07   | *07 |  03 | Y05 |     |         |   0/03  | TCC1/1 |        | I2S/SD0  |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 */
  { PORTA,  2, PIO_ANALOG,  (PIN_ATTR_DIGITAL|PIN_ATTR_ANALOG /*DAC*/        ), ADC_Channel0,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { PORTB,  2, PIO_ANALOG,  (PIN_ATTR_DIGITAL                                ), ADC_Channel10,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    },
  { PORTB,  3, PIO_ANALOG,  (PIN_ATTR_DIGITAL                                ), ADC_Channel11,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3    },
  { PORTA,  4, PIO_ANALOG,  (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), ADC_Channel4,   PWM0_CH0,   TCC0_CH0,     EXTERNAL_INT_NONE },
  { PORTA,  5, PIO_ANALOG,  (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER    ), ADC_Channel5,   PWM0_CH1,   TCC0_CH1,     EXTERNAL_INT_NONE },
  { PORTA,  6, PIO_ANALOG,  (PIN_ATTR_DIGITAL                                ), ADC_Channel6,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { PORTA,  7, PIO_ANALOG,  (PIN_ATTR_DIGITAL                                ), ADC_Channel7,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },

/*
 +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+
 | Pin number |  MKR  Board pin  |  PIN   | Notes           | Peri.A |     Peripheral B      | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H |
 |            |                  |        |                 |   EIC  | ADC |  AC | PTC | DAC | SERCOMx | SERCOMx |  TCCx  |  TCCx  |    COM   | AC/GLCK  |
 |            |                  |        |                 |(EXTINT)|(AIN)|(AIN)|     |     | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 |            |       USB        |        |                 |        |     |     |     |     |         |         |        |        |          |          |
 | 22         |                  |  PA24  | USB N           |   12   |     |     |     |     |   3/02  |   5/02  |  TC5/0 | TCC1/2 | USB/DM   |          |
 | 23         |                  |  PA25  | USB P           |   13   |     |     |     |     |   3/03  |   5/03  |  TC5/1 | TCC1/3 | USB/DP   |          |
 | 24         |                  |  PA18  | USB ID          |   02   |     |     | X06 |     |   1/02  |   3/02  |  TC3/0 | TCC0/2 |          | AC/CMP0  |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 | 25         | AREF             |  PA03  |                 |   03   |  01 |     | Y01 |     |         |         |        |        |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 */
  { PORTA, 24, PIO_COM,     (PIN_ATTR_NONE                                   ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM
  { PORTA, 25, PIO_COM,     (PIN_ATTR_NONE                                   ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DP
  { PORTA, 18, PIO_DIGITAL, (PIN_ATTR_DIGITAL                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },

  { PORTA,  3, PIO_DIGITAL, (PIN_ATTR_DIGITAL                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VREFP

/*
 +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+
 | Pin number |  MKR  Board pin  |  PIN   | Notes           | Peri.A |     Peripheral B      | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H |
 |            |                  |        |                 |   EIC  | ADC |  AC | PTC | DAC | SERCOMx | SERCOMx |  TCCx  |  TCCx  |    COM   | AC/GLCK  |
 |            |                  |        |                 |(EXTINT)|(AIN)|(AIN)|     |     | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 |            | SD SPI           |        |                 |        |     |     |     |     |         |         |        |        |          |          |
 | 26         |                  |  PA12  | SD MOSI         |   12   |     |     |     |     |  *2/00  |   4/00  | TCC2/0 | TCC0/6 |          | AC/CMP0  |
 | 27         |                  |  PA13  | SD SCK          |   13   |     |     |     |     |  *2/01  |   4/01  | TCC2/1 | TCC0/7 |          | AC/CMP1  |
 | 28         |                  |  PA14  | SD SS           |   14   |     |     |     |     |   2/02  |   4/02  |  TC3/0 | TCC0/4 |          | GCLK_IO0 |
 | 29         |                  |  PA15  | SD MISO         |   15   |     |     |     |     |  *2/03  |   4/03  |  TC3/1 | TCC0/5 |          | GCLK_IO1 |
 | 30         |                  |  PA27  | SD CD           |   15   |     |     |     |     |         |         |        |        |          | GCLK_IO0 |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 | 31         |                  |  PA28  | BOTTOM PAD      |   08   |     |     |     |     |         |         |        |        |          | GCLK_IO0 |
 | 32         |                  |  PB08  | LED_BUILTIN     |   08   |  02 |     | Y14 |     |         |   4/00  |  TC4/0 |        |          |          |
 | 33         |                  |  PB09  | ADC_BATTERY     |  *09   |  03 |     | Y15 |     |         |   4/01  |  TC4/1 |        |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 |            | 32768Hz Crystal  |        |                 |        |     |     |     |     |         |         |        |        |          |          |
 | 34         |                  |  PA00  | XIN32           |   00   |     |     |     |     |         |   1/00  | TCC2/0 |        |          |          |
 | 35         |                  |  PA01  | XOUT32          |   01   |     |     |     |     |         |   1/01  | TCC2/1 |        |          |          |
 +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
 */
                                                                                                                                               // DIPO=3 DOPO=0
  { PORTA, 12, PIO_SERCOM_ALT, (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // MOSI: SERCOM4/PAD[0]
  { PORTA, 13, PIO_SERCOM_ALT, (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SCK:  SERCOM4/PAD[1]
  { PORTA, 14, PIO_DIGITAL,    (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SS:   as GPIO
  { PORTA, 15, PIO_SERCOM_ALT, (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // MISO: SERCOM4/PAD[3]
  { PORTA, 27, PIO_DIGITAL,    (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  
  { PORTA, 28, PIO_DIGITAL,    (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { PORTB,  8, PIO_DIGITAL,    (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { PORTB,  9, PIO_ANALOG,     (PIN_ATTR_PWM|PIN_ATTR_TIMER                  ), ADC_Channel3,   PWM4_CH1,   TC4_CH1,      EXTERNAL_INT_9    },

  { PORTA,  0, PIO_DIGITAL,    (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { PORTA,  1, PIO_DIGITAL,    (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
};

extern "C" {
    unsigned int PINCOUNT_fn() {
        return (sizeof(g_APinDescription) / sizeof(g_APinDescription[0]));
    }
}

const void* g_apTCInstances[TCC_INST_NUM + TC_INST_NUM]={ TCC0, TCC1, TCC2, TC3, TC4, TC5 };

// Multi-serial objects instantiation
SERCOM sercom0(SERCOM0);
SERCOM sercom1(SERCOM1);
SERCOM sercom2(SERCOM2);
SERCOM sercom3(SERCOM3);
SERCOM sercom4(SERCOM4);
SERCOM sercom5(SERCOM5);

// Serial1
Uart Serial1(&sercom5, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX);

void SERCOM5_Handler()
{
  Serial1.IrqHandler();
}

Here are some lines of my code to initialize the card:

.
.
#include <SD.h>
.
.
const int pin_cs = 28; // Connaître la broche du Chip Select de la carte SD pour initialisation // Carte SD doit être format FAT16 ou FAT32
.
.
// Démarrer la carte SD
  Serial.println("Initialisation carte SD");
  if (!SD.begin(pin_cs)) {
    Serial.println("Echec d'initialisation carte SD");
    while(true);         }
  Serial.println("Initialisation carte SD reussie");

Hello, I think I clearly showed that I definitly don't understand this mapping matter at all. I though D4 and D5 were usable and the problem was elsewhere. If I would have these pins available:

PA02/A0/D14
PB02/A1/D16
D6/PA20
D10/PA19

would there be a solution for my extra serial and where would you put TX and RX?
Could you correct my line: Uart mySerial (&sercom4, 5, 4, SERCOM_RX_PAD_3, UART_TX_PAD_2);

my previous post was not right a guess.
the SD card uses sercom4
the other pins you listed are no usable. A0 has no sercom capability and other pins are not on the same sercom

1 Like

It's complicated. In theory, you can put Sercom4 on d4/d5, but sercom4 is already used for SPI1 on MkrZero (the SD card.) D4/D5 can ONLY use Sercom4, but in theory the SD card could use SerCom2. But SerCom2 is allocated to the i2C pins...
AFAICT, The SerCom allocation for mkrZero looks like:
Sercom0 - --- available on A3/4/5/6 and d2/3
Sercom1 - SPI on pins 8/9/10
Sercom2 - I2C or 11/12
Sercom3 - --- available on D0/1/6/7
Sercom4 - SD Card.
Sercom5 - Serial1 on 13/14

I've update the spreadsheet to reflect the SD pins for mkrZero, and there is also: SAMD21 Sercoms - Google Sheets (which is less complete, I think.)

Hello all,
I am back on this project today and I was very optimistic that I could make my extra serial port work with the help you provided. But, no, I am still unable to have this port working. I am providing my code in hope you can find the error. Thanks.

.
.
.
.
#define PAD_SERIAL3_TX       (UART_TX_PAD_2)      // SERCOM pad 2
#define PAD_SERIAL3_RX       (SERCOM_RX_PAD_3)    // SERCOM pad 3

//+++++Sercom3 - --- available on D0/1/6/7+++++++
// Create the new UART instance assigning it to MKR board pin D6 (Rx) and D7 (Tx)
Uart myTDRserial (&sercom3, 6, 7, PAD_SERIAL3_RX, PAD_SERIAL3_TX);

  // Attach the interrupt handler to the SERCOM pour le TDR
  void SERCOM3_Handler()
  {
    myTDRserial.IrqHandler();
  }


void setup() {
  
  // Démarrer le port série console intégrée
  Serial.begin(9600);
.
.
.
.
.
  // Set up serial pour port série TDR
  myTDRserial.begin(115200);
  pinPeripheral(6, PIO_SERCOM); //Assign RX function to pin 6
  pinPeripheral(7, PIO_SERCOM); //Assign TX function to pin 7
  
.
.
.
.
.

The code to verify proper operation on the port:
(When run I see the Hello dear! but not what I put on the myTDRserial port.)

.
.
.

// variable contenant le caractère à lire
    char carlu = 0;
    // variable contenant le nombre de caractère disponibles dans le buffer
    int cardispo = 0;

    cardispo = myTDRserial.available();

    while(cardispo > 0) // tant qu'il y a des caractères à lire
    {
        carlu = myTDRserial.read(); // on lit le caractère
        Serial.print(carlu); // puis on le renvoi à l’expéditeur tel quel
        cardispo = myTDRserial.available(); // on relit le nombre de caractères dispo
    }
  Serial.println("Hello dear!");  // transmit data
.
.
.
.

It still needs to be PIO_SERCOM_ALT, I think.

You've determined that pin 6/7 is PA20/PA21 from the variant file, and then in the SAMD21 datasheet "Multiplexing and Considerations" (table 7.2), you can see:


So those pins can run either SERCOM5 or SERCOM3, but Sercom5 is already in use (?) by the Arduino core (I'm not sure what will happen if you try use a sercom twice!), so you need to use the SERCOM_ALT setting to get SERCOM3.

1 Like

Hello,
I am still out of luck. :frowning:

I confirm sercom5 is in use, we can see it from my variant.cpp file:

// Multi-serial objects instantiation
SERCOM sercom0(SERCOM0);
SERCOM sercom1(SERCOM1);
SERCOM sercom2(SERCOM2);
SERCOM sercom3(SERCOM3);
SERCOM sercom4(SERCOM4);
SERCOM sercom5(SERCOM5);

// Serial1
Uart Serial1(&sercom5, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX);

void SERCOM5_Handler()
{
  Serial1.IrqHandler();
}

I have changed myTDRserial speed to 9600 just in case but no luck again.

Also adding _ALT does not help. But I saw somthing that could be a hint toward the solution: I noticed that my terminal on PC (connected to my added serial port) receive some characters but not when it should be...looks like when only other ports are used. The received characters have no meaning. At myTDRserial 115200 it is only dots: ''...................................................................'' At myTDRserial 9600 it is a bit different: see screen capture.

Any more ideas of was this problem is? Thanks!

Hi @marcardui

Here's some code that sets up Serial2 on D6 (Rx) and D7 (Tx). The loop listens for incoming characters at a baud rate of 115200 and echos them back to the console:

#include <wiring_private.h>           // Required for pinPeripheral() function

// Create UART object called Serial2 with 6 as Rx and 7 as Tx
Uart Serial2 (&sercom3, 6, 7, SERCOM_RX_PAD_3, UART_TX_PAD_2);

void SERCOM3_Handler()                // SERCOM3 Interrupt Service Routine (ISR)
{
  Serial2.IrqHandler();
}

void setup() {
  Serial2.begin(115200);              // Open Serial2 at 115200 baud
  pinPeripheral(6, PIO_SERCOM_ALT);   // Assign pins to alternative SERCOM multiplexer switch
  pinPeripheral(7, PIO_SERCOM_ALT);
}
 
void loop() 
{
  if (Serial2.available())            // Check if incoming data is available on D6
  {
    byte byteRead = Serial2.read();   // Read the most recent byte on D6
    Serial2.write(byteRead);          // Echo the byte back out on D7
  }
}

Hello to all,

I have tried very hard: MartinL code do not change anything.

To make sure, I have reverified my connexion from MKRZero to the terminal on my PC.
TX(D7) of MKRZero--->Rx of terminal
Rx(D6) of MKRZero<---Tx of terminal
All setting and speed corrects.
I have my Serial1 used for a bluetooth module Tx pin on D14. So I have connected like this:
TX(D14) used for bluetooth--->Rx of terminal
and the terminal receives the same things as the blutooth module receive.
I have connected a scope on Tx of terminal and I see the data transmitted from the terminal.
So it's not my terminal on PC or speed or any setting in terminal.
It must be that the code do not implement a serial port on D6 and D7. There are no other options.
There must be someting missing or an error in code.
Anyone can suggest any ideas about this problem? Thanks!

Can you provide some details on this "terminal"? It's not an actual "rs232 port", is it?

Hi @marcardui

My mistake, it's not possible to have D7 as Tx. (As the D7 pin is on USART PAD3 which can only be used for receive).

The following code is the same as above, but with the pins swapped. Now D7 is Rx and D6 is Tx. This time I tested the code and it works OK.

#include <wiring_private.h>           // Required for pinPeripheral() function

// Create UART object called Serial2 with 7 as Rx and 6 as Tx
Uart Serial2 (&sercom3, 7, 6, SERCOM_RX_PAD_3, UART_TX_PAD_2);

void SERCOM3_Handler()                // SERCOM3 Interrupt Service Routine (ISR)
{
  Serial2.IrqHandler();
}

void setup() {
  Serial2.begin(115200);              // Open Serial2 at 115200 baud
  pinPeripheral(6, PIO_SERCOM_ALT);   // Assign pins to alternative SERCOM multiplexer switch
  pinPeripheral(7, PIO_SERCOM_ALT);
}
 
void loop() 
{
  if (Serial2.available())            // Check if incoming data is available on D7
  {
    byte byteRead = Serial2.read();   // Read the most recent byte on D7
    Serial2.write(byteRead);          // Echo the byte back out on D6
  }
}

Hello to all,

Again I was very optimistic that this time was the right time and that my extra port would be working....but no, it still doesn't work. I know it sounds like the problem is from me but I hope you will continue helping. But with the change, I noticed a few things that may help. With the new code (which is basically just Tx and Rx reversed) I don't see all these dots or special characters anymore. And if I remove the 2 _ALT, my terminal on PC will receive the exact same thing as my Serial1 port connected to my bluetooth module. In other words, D6 as Tx for my added serial port and D14 as Tx for my Serial1 will send the exact same data. I hope this can help.

There must be one more thing wrong somewhere somehow. Any help again? Thanks.

Hi @marcardui

Have you set the serial port's baud rate on the console/terminal to the same as the sketch?

Do you have any code that sets either D6 or D7 back to GPIO, or repurposes them?

I've tested the revised code by connecting a USB to Serial board with a 5V to 3.3V level-shifter to my SAMD21 target on D7 (Rx) and D6 (Tx). The console on the Arduino IDE is sending character strings to the microcontroller via the USB to Serial. The characters are being successfully received and echoed back.

Hello MartinL,

I have set all the speeds to 9600. So for Serial2 we have 9600 and I set the terminal on PC also to 9600.

// Set up serial pour port série TDR
  Serial2.begin(9600);
  pinPeripheral(6, PIO_SERCOM_ALT); //Assign RX function to pin 6
  pinPeripheral(7, PIO_SERCOM_ALT); //Assign TX function to pin 7
  //pinPeripheral(6, PIO_SERCOM_ALT); //Assign RX function to pin 6

That is the terminal on my PC:

In my design D6 has never been used. D7 was used for activating a buzzer but I changed the line like this to put the buzzer control on D5 instead (which was not used). So the short answer is no I don't have any code that sets either D6 or D7 back to GPIO, or repurposes them.

  int pompe0 = 0;    // Définition de la variable pompe0 sur D0
  int pompe1 = 1;    // Définition de la variable pompe1 sur D1
  int pompe2 = 2;    // Définition de la variable pompe2 sur D2
  int pompe3 = 3;    // Définition de la variable pompe3 sur D3
  int buzzer = 5;    // Définition de la variable buzzer sur D7 +++R9 enlevée et signal déplacé du D5 actuellement inutilisée (pour TDR) (buzzer dans le vide sur D5)
  int led_ihm = 8;    // Définition de la variable led_ihm sur D8
  int bluetooth = 9;    // Définition de la variable bluetooth sur D9
  int osc = 10;    // Définition de la variable osc sur D10

The cable I am using to connect between my added serial port and the terminal on my PC is:

That cable is UART 3.3V.

I just noticed something that could help find the problem. I notice that when I unplug that digikey cable the voltage of data from cable is from 0 to 3.3V but when I connect to Arduino it drops to about from 0 to 1.8V. It seems the Arduino D7 is overloading the tx wire from the digikey cable. This is the same if I try with another Arduino. So it's not a defective Arduino.

Except fot pinPeripheral(7, PIO_SERCOM_ALT);, is there a line missing to tell the Arduino D7 is an input so not to overload the incoming signal?

Hello all and MartinL,

Definitly the loading may be the problem. I have added a line to just send something to the added port:
Serial2.println("Hello dear!"); // transmit data
and it worked! It appeared on the terminal on my PC! So we have half of the added port working. We can transmit from Arduino to PC but not the opposite. There is something wrong with D7 that loads too much the signal it receives .
But how to fix that?

Or is it that I need a pull-up?