Hi,
I'm working on a small board with samd21e micro controller. I want to use the smaller samd21e with less pins. Uploading boot loader shall be done by the help of an Arduino Zero. Once Uploaded I want to use the Arduino M0 Board Variant.
The samd21 has several SERCOM modules and I want to use almost all of them. Problem is, that UART, SPI and WIRE are predefined in variant.cpp and sometimes called from librarys.
Here is my pin mapping code, this is all I made so far. The PCB Board is not made yet, I needed to be sure on Pin connection first.
//NUR ARDUINO M0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include
#include
#include
#include // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function
/*
XTAL
====================
PA00 = XTAL0
PA01 = XTAL1
UART Serial2 Dam1021
=====================
04 PA14 = TX dam1021 SERCOM_ALT4.2
05 PA15 = RX dam1021 SERCOM_ALT4.3
UART Serial1 RPi
=====================
00 PA10 = TX RPi SERCOM0.2
01 PA11 = RX RPi SERCOM0.3
SPI Ethernet W5500
=====================
40 PA16 = MOSI SERCOM1.0
42 PA17 = SCK SERCOM1.1
41 PA18 = SS SERCOM1.2
39 PA19 = MISO SERCOM1.3
I2C Display
====================
16 PA22 = SDA muss Pad[0] SERCOM_ALT5.0
17 PA23 = SCL muss Pad[1] SERCOM_ALT5.1
SPI SN74hc595 daisy chained
=====================
27 PA04 = MOSI SERCOM3.0
28 PA05 = SS SERCOM3.1
45 PA06 = MISO SERCOM3.2
46 PA07 = SCK SERCOM3.3
?Serial? USB
====================
PA24 = D-
PA25 = D+
One Wire programming Port
====================
PA30 = CLK
PA31 = DIO
*/
Uart Serial2 (&sercom4, 5, 4, SERCOM_RX_PAD_3, UART_TX_PAD_2);
void SERCOM4_Handler(){
Serial2.IrqHandler();
}
SPIClass SN74SPI (&sercom3, 45, 46, 27, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2);
void setup() {
Serial.begin(115200); //SerialUSB
Serial1.begin(115200); //PA10 & PA11 SERCOM0
Serial2.begin(115200); //PA14 & PA15 SERCOM4
// do this first, for Reasons
SPI.begin(); //PA16-PA19 SERCOM1
SN74SPI.begin();
pinPeripheral(5, PIO_SERCOM_ALT); //RX
pinPeripheral(4, PIO_SERCOM_ALT); //TX
pinPeripheral(16, PIO_SERCOM_ALT); //RX
pinPeripheral(17, PIO_SERCOM_ALT); //TX
pinPeripheral(27, PIO_SERCOM);
pinPeripheral(45, PIO_SERCOM);
pinPeripheral(46, PIO_SERCOM);
}
void loop() {
// put your main code here, to run repeatedly:
}
Original M0 Variant.cpp snipped from the end:
Uart Serial1( &sercom0, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;
Uart Serial( &sercom5, PIN_SERIAL_RX, PIN_SERIAL_TX, PAD_SERIAL_RX, PAD_SERIAL_TX ) ;
void SERCOM0_Handler()
{
Serial1.IrqHandler();
}
void SERCOM5_Handler()
{
Serial.IrqHandler();
}
Original M0 Variant.h snipped:
/*
* Serial interfaces
*/
// Serial (EDBG)
#define PIN_SERIAL_RX (36ul)
#define PIN_SERIAL_TX (35ul)
#define PAD_SERIAL_TX (UART_TX_PAD_2)
#define PAD_SERIAL_RX (SERCOM_RX_PAD_3)
// Serial1
#define PIN_SERIAL1_RX (0ul)
#define PIN_SERIAL1_TX (1ul)
#define PAD_SERIAL1_TX (UART_TX_PAD_2)
#define PAD_SERIAL1_RX (SERCOM_RX_PAD_3)
/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (18u)
#define PIN_SPI_MOSI (21u)
#define PIN_SPI_SCK (20u)
#define PERIPH_SPI sercom4
#define PAD_SPI_TX SPI_PAD_2_SCK_3
#define PAD_SPI_RX SERCOM_RX_PAD_0
static const uint8_t SS = 14; //GND
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
/*
* Wire Interfaces
*/
#define WIRE_INTERFACES_COUNT 1
#define PIN_WIRE_SDA (16u)
#define PIN_WIRE_SCL (17u)
#define PERIPH_WIRE sercom3
#define WIRE_IT_HANDLER SERCOM3_Handler
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
In order to make all the SERCOMs work as I want them to, I changed these Variant.cpp and Varian.h files to the according:
modified Variant.cpp:
Uart Serial1( &sercom0, 1, 0, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;
void SERCOM0_Handler()
{
Serial1.IrqHandler();
}
Modified Variant.h:
/*
* Serial interfaces
*/
// Serial1
#define PIN_SERIAL1_RX (0ul)
#define PIN_SERIAL1_TX (1ul)
#define PAD_SERIAL1_TX (UART_TX_PAD_2)
#define PAD_SERIAL1_RX (SERCOM_RX_PAD_3)
//SERCOM0
/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (39u)
#define PIN_SPI_MOSI (40u)
#define PIN_SPI_SCK (42u)
#define PERIPH_SPI sercom1
#define PAD_SPI_TX SPI_PAD_0_SCK_1
#define PAD_SPI_RX SERCOM_RX_PAD_3
static const uint8_t SS = 41;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
/*
* Wire Interfaces
*/
#define WIRE_INTERFACES_COUNT 1
#define PIN_WIRE_SDA (16u)
#define PIN_WIRE_SCL (17u)
#define PERIPH_WIRE sercom5
#define WIRE_IT_HANDLER SERCOM5_Handler
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
Is this gonna work? Do I have to do anything else? Is there an obvious mistake I missed? I get no error messages whatsoever, but I want to be sure.
Thank you very much, with friendly regards, Jan