Variant.cpp needs to be updated for the remaining pins of the SAM D21

I use the SAM D21 stand alone and want to use all the extra pins:

pin19 PB10
pin20 PB11
pin21 PA12
pin22 PA13
pin37 PB22
pin38 PB23
pin39 PA27
pin41 PA28
pin45 PA30
pin46 PA31
pin48 PB3

Unfortunately, variant.cpp doesn’t describe the remaining pins on the SAM D21, which are not connected to the pin headers at the Arduino Zero. Therefore, these extra pins can't be controlled as usual, for example, with digital write (13, 0):

Can we make a new project about this?

See my website here about this topic

http://www.avdweb.nl/arduino/sam-d21.html

Those pins are described in the variant.cpp :

pin19 PB10 = digital pin 23
pin20 PB11 = digital pin 24
pin21 PA12 = digital pin 21
pin22 PA13 = digital pin 38
pin37 PB22 = digital pin 30
pin38 PB23 = digital pin 31
pin39 PA27 = digital pin 26
pin41 PA28 = digital pin 27
pin45 PA30 x not defined, used for SWD programming/debug
pin46 PA31 x not defined, used for SWD programming/debug
pin48 PB3 = digital pin 25

variant.cpp doesn't describe the remaining pins on the SAM D21

I'm curious as to how you arrived at this conclusion. The SAMD variant.cpp looks unusually well documented...

westfw:
I'm curious as to how you arrived at this conclusion. The SAMD variant.cpp looks unusually well documented...

+1
There is in the comments a lot of information about the pin muxing and peripheral mapping.

You can find some information here:

I must obviously doing something wrong trying to use sercom5 with a custom board:

#include <Arduino.h>   // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function

Uart Serial4( &sercom5, 30, 31, SERCOM_RX_PAD_3, UART_TX_PAD_0 ) ;

void setup() {   
  Serial4.begin(9600);
}

void loop() {
  Serial4.println("Hi there!");
  delay(2000);
}

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

I don't get any output on the serial at all. (Serial2 is on 3 / 4 and works fine).

If you use the default variant file (default Arduino Samd Core), Sercom5 is already used as an Uart port on pin 30 and 31. It is the Serial instance. You can rename it Serial4 if you want by modifying the variant.cpp file.

I have solved this issue, see here:
How to use all SAMD21G pins

Please don't go away guys because this is the thread I have been looking for for weeks.
Little did I know that the answer to the question I had, "How to use more pins", was under my nose all the time. I have been hunting for this information on the internet without any great success and, as a newby still learning about MCUs and Arduino, this seems to be the "golden" thread and I bet many others feel that way to.

I built a custom board, probably a bit hasty for a newby, but I did it. It is not much of a stretch from the basic Zero but I needed a few extra pins added and to re-route the use of others. If you can confirm I understand what you are saying here I am on my way.

a. I have a direct connection on the board to an LED from PA07. When I write the sketch I simply refer to the LED driver pin as pin 9, ie digitalWrite(9, HIGH) --- correct?

b. I use PA10 and PA11 for on-board serial use so I made sure the use of these pins was not changed.

c. I need three new connections for digital use to PB22, PB23 and PB27 (this was mainly to ease PCB trace layout). So, I simply refer to these as pins 20, 21 and 26 in the sketch, define them as digital pins with pinmode and the IDE will accept this even though these are not defined as Arduino Zero pins. Is this correct?

Do I need to do anything else to make this work?

Obviously I could just try these ideas on the board to see if they work but I am not sure yet that the board itself is perfect yet so it would be a great help if I could know that what I am trying is correct before I experiment.

Thanks, Brian

When you create your own board, you can reassign "pin numbers" to the actual chip pins in any way you like, by re-writing the variant.h and perhaps variant.cpp. In theory, anyway. In reality, departing too far from the existing mappings will cause you all sorts of grief with existing libraries that assume things like "digital pin 0/1 are the Serial port", which wouldn't necessarily be true any more. That's why it's more common for a variant to keep the same pin mappings for the pins that are common, and assign new "high-numbered" pins any added pins...

Thanks westfw,

I was careful to disturb as few pins as possible in the standard Zero range but we did move pin 13 functions to pin 9 to simplify the trace layout. Do you see anything wrong with that? The LED driver layout was copied straight from the Zero schematic except this is a direct connection to the LED with no exterior pin breakout.

I think I have other problems with my board because simply using the "blink" sketch and substituting pin 9 and PA07 for pin 13 and PA17 does not work (but this should be the subject for another post).

Thanks

Using the variant file values my circuit operated correctly using the extended pin allocations.

The only item I noted is that the pins 2 and 4 connections are reversed on the Arduino Zero schematic.

The variant files shows Arduino pin2 going to PA14 and Arduino pin4 going to PA08. The Arduino schematic shows these connections reversed.

It depends on which schematic you look at... Those two pins are rolled between the Ardiuino.cc Zero and Arduino.org M0 Pro. I've seen a few different versions of the schematics floating around out there.

dlabun
I am comparing the variant.cpp file in my computer with the schematic on the Arduino website. You would think that these two would match since they are both from the same source. A typo somewhere no doubt but I suppose for the routine Zero user this does not matter but when you are designing your own board with custom pin-outs it could be a problem.

.

Is this the schematic you are looking at? It matches the Zero core as you described above.

The schematic has a signal name "PA08...", but it's connected to a pin labeled "PA14..." (and vis versa.)
Screen Shot 2016-11-15 at 8.18.24 PM.jpg

Attached is the PDF of the original (and correct) Atmel schematic for the Arduino.cc Zero.

Arduino-Zero-schematic.pdf (779 KB)

Thanks for the updated schematic Martini, I think I like this layout more than the old one.

I suppose the pinouts being wrong on the old schematic don't really matter if you are only using the Zero on a dev. board basis because one I/O is the same as another. This would only be a problem for someone making a custom board who did not check the schematic closely enough and somehow built the error into their project.

.