0

SAMD51 - PINS CONFIGURATION
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SAMD51 - PINS CONFIGURATION

by YoheiStitch on Fri Mar 27, 2020 11:44 am

Hello everyone,

I've been playing with the SAMD51 CI and it's variant files. Everything is going really smoothly with the pins programming and when using the Arduino IDE to code. However, I've got a question that I could not find the answer and would appreciate if someone could help me understand the problem.

When dealing with the varian.cpp, we have the PinDescription array that basically tells us what is the function assigned to each pin, like the code below.
Code: Select all | TOGGLE FULL SIZE
[...]some code here[...]
{ PORTA, 6, PIO_DIGITAL, PIN_ATTR_PWM_E, No_ADC_Channel, TC1_CH0, TC1_CH0, EXTERNAL_INT_6 },
 { PORTA,  15, PIO_TIMER_ALT, PIN_ATTR_PWM_F, No_ADC_Channel, TCC2_CH1, TC3_CH1, EXTERNAL_INT_2  },

[...]some code here[...]
  { NOT_A_PORT, 0,  PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },

 [...]some code here[...]
{ PORTB,  2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },
[...]some code here[...]


My questions are, when do I know if I should use PIO_DIGITAL instead of PIO_TIMER_ALT and why not PIO_TIMER?
I know that _ALT, al least for the SERCOM, means the second column (of the two with SERCOM) in the datasheet. However I don't know a TIMER column.
Also, why would anyone use NOT_A_PORT instead of just leaving without this line?

YoheiStitch
 
Posts: 10
Joined: Fri Mar 27, 2020 10:39 am

Re: SAMD51 - PINS CONFIGURATION

by adafruit_support_mike on Sun Mar 29, 2020 4:29 am

YoheiStitch wrote:My questions are, when do I know if I should use PIO_DIGITAL instead of PIO_TIMER_ALT and why not PIO_TIMER?

For that, you have to look at the SAMD51's pin multiplexer. Reading the code in the 'cores' folders will also help, since that shows how the different fields are used.

PIO_TIMER means the pin is a primary output channel for a TC or TCC timer-counter peripheral, and can do hardware PWM. PIO_TIMER_ALT means the pin can connect to a TC or TCC peripheral, but that it isn't a default connection.

PIO_DIGITAL means the pin can connect to a PORT peripheral, but not to a TC or TCC peripheral.. it can do digital IO, but not hardware PWM.

YoheiStitch wrote:Also, why would anyone use NOT_A_PORT instead of just leaving without this line?

Without an entry in the table, functions like pinMode() or analogWrite() will crash if you call them with the number for that pin.

All of the convenience functions like pinMode() and analogWrite() start by checking the array to see if the pin number they've been given can do what you've asked it to. If you call analogWrite() for a pin that doesn't have any connection to a TC or TCC peripheral, the function will bascially say, "nope, can't do that" and fail gracefully instead of trying to configure something that can't possibly work.

If the table doesn't have an entry for some pin, the code that does the lookup will crash because you're asking it to look for information in a data structure that doesn't exist.

adafruit_support_mike
 
Posts: 63701
Joined: Thu Feb 11, 2010 2:51 pm

Re: SAMD51 - PINS CONFIGURATION

by YoheiStitch on Mon Mar 30, 2020 3:05 pm

@adafruit_support_mike,

Thank you very much for your answer!

YoheiStitch
 
Posts: 10
Joined: Fri Mar 27, 2020 10:39 am

Re: SAMD51 - PINS CONFIGURATION

by YoheiStitch on Tue Jul 27, 2021 1:23 pm

Dears,

Sorry to resurrect this post, but is the same subject and the same author.

In the SAMD51 Datasheet(https://www.mouser.com/datasheet/2/268/60001507E-1660031.pdf), 6.2.8 IOSET Configurations, we have this sentence:
The SAM D5x/E5x has multiple peripheral instances, mapped to different IO locations. Each peripheral IO
location is called IOSET and for a given peripheral, signals from different IOSET cannot be mixed.

For a given peripheral with two pads PAD0 and PAD1:
    Valid: PAD0 and PAD1 in the same IOSETn.
    Invalid: PAD0 in IOSETx and PAD1 in IOSETy.


So I assumed that differents IOSETs cannot be used for the same TC/TCC, for example: If I use TCC0/WO[0] with PA20 (IOSET 6 on Table 6-28. TCC0 IO SET Configuration) I wouldn't be able to use TCC0/WO[1] with PA09 (IOSET 1 on Table 6-28. TCC0 IO SET Configuration) because they are from different IOSETS and we can only use the same IOSET,, meaning that for TCC0/WO[1] we should go for PA21 that is on IOSET6.

The same goes for the TC: If I use TC2/WO[0] with PA16 I shouldn't use TC2/WO[0] anymore because it will go for different IOSET, and TC2/WO[1] should only go for PA17.

If my understanding is wrong, then why can't I enable PWM and TIMER on all pins that have it on columns E, F and G from Table 6-1. Multiplexed Peripheral Signals, or can I?

And if I'm right, why does adafruit do it on the itsybitsy_m4 variant files? Here we can see they using multiple IOSET from TC2.
Code: Select all | TOGGLE FULL SIZE
  // 0/1 - SERCOM/UART (Serial1)
  { PORTA,  16, PIO_SERCOM_ALT, PIN_ATTR_PWM_F, No_ADC_Channel, TCC1_CH0, TC2_CH0, EXTERNAL_INT_0 }, // SERCOM 3.1
  { PORTA,  17, PIO_SERCOM_ALT, PIN_ATTR_PWM_F, No_ADC_Channel, TCC1_CH1, TC2_CH1, EXTERNAL_INT_1 }, // SERCOM 3.0
...
  // 21..22 I2C pins (SDA/SCL)
  // ----------------------
  { PORTA,  12, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, TC2_CH0, EXTERNAL_INT_12 }, // SERCOM 2.0
  { PORTA,  13, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, TC2_CH1, EXTERNAL_INT_13 }, // SERCOM 2.1
...
  // 23..25 - SPI pins (ICSP:MISO,SCK,MOSI)
  // ----------------------
  { PORTB, 23, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 },     // MISO SERCOM 1.3
  { PORTA,  1, PIO_SERCOM_ALT, PIN_ATTR_PWM_E, No_ADC_Channel, TC2_CH1, TC2_CH1, EXTERNAL_INT_1 }, // SCK  SERCOM 1.1
  { PORTA,  0, PIO_SERCOM_ALT, PIN_ATTR_PWM_E, No_ADC_Channel, TC2_CH0, TC2_CH0, EXTERNAL_INT_0 }, // MOSI SERCOM 1.0

YoheiStitch
 
Posts: 10
Joined: Fri Mar 27, 2020 10:39 am

Re: SAMD51 - PINS CONFIGURATION

by adafruit_support_mike on Sun Aug 01, 2021 1:43 am

The IOSETs are related to the SERCOMs, which handle SPI, I2C, and Serial.

The TC/TCC instances can use more pins than exist in an IOSET, so just stick to the signal names and where those signals can be mapped by the multiplexer.

The pin options for TC/TCC outputs do have some overlap.. if:

pin-1 can get TC1[w0] or TCC2[w6]
pin-2 can get TC1[w0] or TC2[w1]
pin-3 can get TC2[w1] or TCC2[w6]

doing

pin-1 = TCC2[w6]
pin-2 to TC2[w1]

makes it impossible to have PWM output on pin-3.. the only two signals pin-3 can use have already been assigned to the other pins.

On the other hand, you can get PWM on all three pins with:

pin-1 = TC1[w0]
pin-2 = TC2[w1]
pin-3 = TCC2[w6]

so mapping signals to the pins isn’t trivial. You have to compare the options.

adafruit_support_mike
 
Posts: 63701
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.