Custom SAMD51 Board (Add pins in variant files) Issue

I have created a custom SAMD51 board everything is working good so far.....

Now I connected some of the unused pins to test points to see if I could get them up and running

The pins PB04,5,6,7 (Attached). MCU is ATSAMD51J20A-AU

To start with I was trying to connect PB04 first

Manual reference

PB04 VDDANA EXTINT[4] AIN[12] AIN[0]

I copied the 1.6.2 variant files from the Arduino51 area to work with. I want to bring these pins on as simple analog pins. I will us the PB04 pin to read battery voltage. The other are simple High/Low to turn on power sources etc.

So I opened the variant.h file and the variant.ccp files. THese are the changes I made

Variant.h

// Number of pins defined in PinDescription array
#define PINS_COUNT (37u) //Changed from 36 to 37
#define NUM_DIGITAL_PINS (20u)
#define NUM_ANALOG_INPUTS (7u) // Changed from 6 to 7
#define NUM_ANALOG_OUTPUTS (1u)
#define analogInputToDigitalPin(p) ((p < 7u) ? (p) + 14u : -1) //change from 6u to 7u

  • Analog pins
    */
    #define PIN_A0 (14ul)
    #define PIN_A1 (PIN_A0 + 1)
    #define PIN_A2 (PIN_A0 + 2)
    #define PIN_A3 (PIN_A0 + 3)
    #define PIN_A4 (PIN_A0 + 4)
    #define PIN_A5 (PIN_A0 + 5)
    #define PIN_A6 (PIN_A0 + 6) //added

#define PIN_DAC0 (14ul)
#define PIN_DAC1 PIN_A1

static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6; //added this line

variant.ccp

// 14..19 - Analog pins
// --------------------
{ PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 },
{ PORTB, 4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line
{ PORTB, 8, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8 },
{ PORTB, 9, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel3, TC4_CH1, TC4_CH1, EXTERNAL_INT_9 },
{ PORTA, 4, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel4, TC0_CH0, TC0_CH0, EXTERNAL_INT_6 },
{ PORTA, 5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
{ PORTB, 2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },

After I load these new files and run the blink code everything compiles correct but A6/PB4 never blinks the led....

Anyone have a bit more experience in this area and could shed some light on why this does not work?

Thanks.
T

pins.png

The Arduino pin number is the index of the g_APinDescription array. Since A6 is Arduino pin number 20 (14 + 6), you should have added that line to variant.cpp as the 20th element of the array definition. But you added it at the 15th position. So right now if you blink Arduino pin 15 then PB04 should blink. If you want it to work as A6/20 then you need to move the line to the correct position in the array definition.

Ok Im with you...

Where do I find this mapping "Since A6 is Arduino pin number 20 (14 + 6)"

Ok so under the const PinDescription g_APinDescription[]=

I have made the changes.

// 14..20 - Analog pins changed 19 to 20
// --------------------
{ PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 },
{ PORTB, 8, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8 },
{ PORTB, 9, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel3, TC4_CH1, TC4_CH1, EXTERNAL_INT_9 },
{ PORTA, 4, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel4, TC0_CH0, TC0_CH0, EXTERNAL_INT_6 },
{ PORTA, 5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
{ PORTB, 2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },
{ PORTB, 4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20

I will do some testing but I'm worried this will alter my I2C pins

When I make these changes all locations pin mapping with change no? I Did notice "23" in the pin array is not here

// 20..21 I2C pins (SDA/SCL) // These pins in the array will no change no?
// ----------------------
{ PORTA, 22, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH0, TC4_CH0, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
{ PORTA, 23, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH1, TC4_CH1, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]

// 22..24 - SPI pins (MISO,MOSI,SCK)
// ----------------------
{ PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // MISO: SERCOM4/PAD[3]
{ PORTB, 12, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // MOSI: SERCOM4/PAD[0]
{ PORTB, 13, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13 }, // SCK: SERCOM4/PAD[1]

Testing:

when I put the code like this my SCL pin blinks (Expected)

// 20..21 I2C pins (SDA/SCL) // These will change as will all the below pins
// ----------------------
{ PORTA, 22, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH0, TC4_CH0, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
{ PORTB, 4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20
{ PORTA, 23, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH1, TC4_CH1, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]

When I put the code to this my A5 Blinks (Expected)

// 14..20 - Analog pins changed 19 to 20
// --------------------
{ PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 },
{ PORTB, 8, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8 },
{ PORTB, 9, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel3, TC4_CH1, TC4_CH1, EXTERNAL_INT_9 },
{ PORTA, 4, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel4, TC0_CH0, TC0_CH0, EXTERNAL_INT_6 },
{ PORTA, 5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
{ PORTB, 4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20
{ PORTB, 2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },

But when I place the line at exactly line 20 nothing happens

Its like its not accepting this pin...

Now This part of the board is custom. I'm using the template from SAMD51 Thing Plus. Its the same MCU but I'm trying to use all the pins. I'm guessing if I want to use these pins there is one or two other files I need to edit. I'm I correct?

S1buell:
Where do I find this mapping "Since A6 is Arduino pin number 20 (14 + 6)"

Here:

S1buell:

#define PIN_A0               (14ul)

...

S1buell:

#define PIN_A6               (PIN_A0 + 6) //added

...

S1buell:

static const uint8_t A6  = PIN_A6; //added this line

Hi S1buell,

Please find attached the "variant.h" and "variant.cpp" files for my custom SAMD51J20A board.

The "variant" files for my custom board more closely resemble the pin allocations of the Arduno Zero than Adafruit's boards.

In addition, I also added the SAMD51J20A build flag to the "boards.txt" file. This allows the compiler to access the CMSIS pin definitions for the "J" variant:

adafruit_metro_m4.build.extra_flags=-D__SAMD51J20A__ -D__SAMD51__ {build.usb_flags} -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16

variant.h (7.77 KB)

variant.cpp (20.4 KB)

@ pert

Thanks that helps a ton. I will have a look at this and get back to you.... Need a little time to sit down and look at this in detail. But I understand the connection now. Thanks for the help its been amazing. I will post the details if/when I get this working for others to view.

@martinL

Wow.... Bam there it is..... lol
Let me have a look at this. I`m really loving this SAMD51 project. I will have a look at what you have done and see how It can add some clarity to my issue.

Question did you uses all the pins on the MCU?

Ok had a little time today...

Here`s what I have

Boards.txt has access the CMSIS pin definitions for the "J" variant:
samd51_thing_plus.build.extra_flags=-D__SAMD51J20A__ -D__SAMD51__ {build.usb_flags} -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16

Variant.h (mods)

// Number of pins defined in PinDescription array
#define PINS_COUNT (37u) //added one, 36 to 37
#define NUM_DIGITAL_PINS (20u)
#define NUM_ANALOG_INPUTS (7u) //added 1, 6 to 7
#define NUM_ANALOG_OUTPUTS (1u)
#define analogInputToDigitalPin(p) ((p < 7u) ? (p) + 14u : -1) //change 6u to 7u

  • Analog pins
    */
    #define PIN_A0 (14ul)
    #define PIN_A1 (PIN_A0 + 1)
    #define PIN_A2 (PIN_A0 + 2)
    #define PIN_A3 (PIN_A0 + 3)
    #define PIN_A4 (PIN_A0 + 4)
    #define PIN_A5 (PIN_A0 + 5)
    #define PIN_A6 (37ul) //added this line

Also tried
#define PIN_A6 (PIN_A6 + 23) //added this line 37

#define PIN_DAC0 (14ul)
#define PIN_DAC1 PIN_A1

static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6; // Added this line

Variant.ccp

// 33..36 SPI for Flash (SCK, CS, MISO, MOSI)
{ PORTA, 9, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //SCK
{ PORTA, 10, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //CS
{ PORTA, 11, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MISO
{ PORTA, 8, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MOSI

// SAMD21J18A Pins...##################### //Added these lines ######################3

// 37..40 - Analog pins
{ PORTB, 4, PIO_ANALOG, 0, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC/AIN[12]
// { PORTB, 5, PIO_ANALOG, 0, ADC_Channel13, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC/AIN[13]
// { PORTB, 6, PIO_ANALOG, 0, ADC_Channel14, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC/AIN[14]
// { PORTB, 7, PIO_ANALOG, 0, ADC_Channel15, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC/AIN[15]

Let me know if that looks right. I will test tonight.

BTW I`m just working on the PB4 pin for now.

Well.... That didn't work as I planed the new changes did not give me access to A6 / PB04

hemmmm

@MartinL

Are these Variant files correct they don`t seems to match. Also I found this in the variant.ccp line 199

// SAMD21J18A Pins...

e.g

Variant.h
/*

  • Analog pins
    */
    #define PIN_A0 (14ul)
    #define PIN_A1 (PIN_A0 + 1)
    #define PIN_A2 (PIN_A0 + 2)
    #define PIN_A3 (PIN_A0 + 3)
    #define PIN_A4 (PIN_A0 + 4)
    #define PIN_A5 (PIN_A0 + 5)
    #define PIN_A6 (PIN_A0 + 6)
    #define PIN_A7 (PIN_A0 + 7)
    #define PIN_A8 (PIN_A0 + 8)
    #define PIN_A9 (PIN_A0 + 9)
    #define PIN_DAC0 (14ul)
    #define PIN_DAC1 PIN_A1

Variant.ccp
// 14..19 - Analog pins
// --------------------
{ PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // ADC/AIN[0]
{ PORTB, 8, PIO_ANALOG, 0, ADC_Channel2, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_8 }, // ADC/AIN[2]
{ PORTB, 9, PIO_ANALOG, 0, ADC_Channel3, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9 }, // ADC/AIN[3]
{ PORTA, 4, PIO_ANALOG, 0, ADC_Channel4, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC/AIN[4]
{ PORTA, 5, PIO_ANALOG, 0, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC/AIN[5]
{ PORTB, 2, PIO_ANALOG, 0, ADC_Channel10, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // ADC/AIN[10]

// 20..21 I2C pins (SDA/SCL and also EDBG:SDA/SCL)
// ----------------------
{ PORTA, 22, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
{ PORTA, 23, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]

I really like to fill out a spreadsheet like SAMD51-pmux - Google Sheets
It gives me a good sense of what's there, what's connected, what's left over...
In combination with the ability to sort the spreadsheet by (chip pin number, port/pin number, arduino pin number, or any of the functions... It can be very clarifying.)

// SAMD21J18A Pins...##################### //Added these lines ######################3

Since the g_APinDescription array is just an array, exactly WHERE you added those lines is as important as what was in them... Post the whole thing.

Hi S1buell,

You're right, my apologies. The variant files that I provided aren't able to activate the analog input on PB04. This is because as the comment suggests, they've been cut 'n' pasted from the SAMD21J18A. This works for digital IO on both the SAMD21/SAMD51, but not for analog inputs on the SAMD51.

There are two issues. The first is that the "variant.h" file needs to be corrected to address the right analog pin:

/*
 * Analog pins
 */
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (44ul)
#define PIN_A7               (PIN_A6 + 1)
#define PIN_A8               (PIN_A6 + 2)
#define PIN_A9               (PIN_A6 + 3)
#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

The second is that PB04 uses the SAMD51's ADC1 rather than ADC0, this requires selection of the alternative analog pin attribute: PIN_ATTR_ANALOG_ALT.

Just replace the pin entries for 44 to 47 in the "variant.cpp" file with:

// 44..47 - Analog pins
{ PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC1/AIN[6]
{ PORTB,  5, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel7, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC1/AIN[7]
{ PORTB,  6, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel8, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC1/AIN[8]
{ PORTB,  7, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel9, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC1/AIN[9]

It should then be possible to activate the analog input on PB04 with:

int result = analogRead(A6);

Ok here are my changes I will test tonight.

@westfw

I attached the complete files to review. I will look at the document you sent tonight... I was thinking last night...... Man I need something to help organize these pins.... I`m guessing this sheet is exactly what I need. Thanks again!

@martin

Ok top part of variant.h is as follows:

/*----------------------------------------------------------------------------
*        Pins
*----------------------------------------------------------------------------*/

// Number of pins defined in PinDescription array
// Modified only for PB4 test
#define PINS_COUNT           (37u) //added one, 36 to 37
#define NUM_DIGITAL_PINS     (20u) 
#define NUM_ANALOG_INPUTS    (7u) //added 1, 6 to 7
#define NUM_ANALOG_OUTPUTS   (1u)
#define analogInputToDigitalPin(p)  ((p < 7u) ? (p) + 14u : -1)  //change 6u to 7u

#define digitalPinToPort(P)        ( &(PORT->Group[g_APinDescription[P].ulPort]) )
#define digitalPinToBitMask(P)     ( 1 << g_APinDescription[P].ulPin )
//#define analogInPinToBit(P)        ( )
#define portOutputRegister(port)   ( &(port->OUT.reg) )
#define portInputRegister(port)    ( &(port->IN.reg) )
#define portModeRegister(port)     ( &(port->DIR.reg) )
#define digitalPinHasPWM(P)        ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER )

/*
* digitalPinToTimer(..) is AVR-specific and is not defined for SAMD
* architecture. If you need to check if a pin supports PWM you must
* use digitalPinHasPWM(..).
*
* https://github.com/arduino/Arduino/issues/1833
*/
// #define digitalPinToTimer(P)

// LEDs
#define PIN_LED_13           (13u)
#define PIN_LED_RXL          (25u)
#define PIN_LED_TXL          (26u)
#define PIN_LED              PIN_LED_13
#define PIN_LED2             PIN_LED_RXL
#define PIN_LED3             PIN_LED_TXL
#define LED_BUILTIN          PIN_LED_13

/*
* Analog pins
*/
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (37ul) //added this line A5 is pin 37
//#define PIN_A7               (PIN_A6 + 1)
//#define PIN_A8               (PIN_A6 + 2)
//#define PIN_A9               (PIN_A6 + 3)


#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

static const uint8_t A0  = PIN_A0;
static const uint8_t A1  = PIN_A1;
static const uint8_t A2  = PIN_A2;
static const uint8_t A3  = PIN_A3;
static const uint8_t A4  = PIN_A4;
static const uint8_t A5  = PIN_A5;
static const uint8_t A6  = PIN_A6;  // Added this line
//static const uint8_t A7  = PIN_A6;  // Added this line
//static const uint8_t A8  = PIN_A6;  // Added this line
//static const uint8_t A9  = PIN_A6;  // Added this line

static const uint8_t DAC0 = PIN_DAC0;
static const uint8_t DAC1 = PIN_DAC1;

#define ADC_RESOLUTION 12
Variant.ccp (feom line 31 on...

// ----------------------
// 31..32 - Alternate use of A0/A4 (DAC output)
{ PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VOUT0
{ PORTA,  5, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel1, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VOUT1

// ----------------------
// 33..36 SPI for Flash (SCK, CS, MISO, MOSI)
{ PORTA, 9, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //SCK
{ PORTA, 10, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //CS
{ PORTA, 11, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MISO
{ PORTA, 8, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MOSI

// SAMD21J18A Pins...#####################  //Added these lines ######################3


// 37..40 - Analog pins (Test PB4 first, Then the rest)
{ PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC1/AIN[6] 
//{ PORTB,  5, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel7, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC1/AIN[7]
//{ PORTB,  6, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel8, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC1/AIN[8]
//{ PORTB,  7, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel9, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC1/AIN[9]

variant.cpp (9.52 KB)

variant.h (8.37 KB)

Hopefully this should work. Using the PIN_ATTR_ANALOG_ALT pin attribute should get the analogRead() funtion to switch over to ADC1, which is what you require for port pin PB04:

Inside the analogRead() funtion:

#if defined(__SAMD51__)
  Adc *adc;
  if(g_APinDescription[pin].ulPinAttribute & PIN_ATTR_ANALOG) adc = ADC0;
  else if(g_APinDescription[pin].ulPinAttribute & PIN_ATTR_ANALOG_ALT) adc = ADC1;
  else return 0;

Ok, tried the first changes and nothing. I will look at what you send me.

Hi S1buell,

As westfw stated: where the entries appear in the g_APinDescription array is important.

In your "variant.cpp" file, by inserting an additional line for PB04 at position 20:

{ PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20

...effectively shunts all the subsequent entries down by 1, so your entry at position 37 is now at 38. However your "variant.h" file still defines A6 as position 37:

#define PIN_A6               (37ul) //added this line A5 is pin 37

Does it work if you comment out additional entry for position 20?

I'm unable to test port pin PB04 myself, as unfortunately neither my custom or Adafruit M4 boards breakout this pin.

@MartinL, thanks for you help!

Here is what i changed and the full code:

  1. Minnor changes
#define PINS_COUNT           (37u) // from 36u
#define NUM_ANALOG_INPUTS    (7u) //was 6u
  1. Changed this to it can point to 37 instead of just p+14 (would be correct if it was ate position 21)
#define analogInputToDigitalPin(p)  ((p < 6u) ? (p) + 14u : ( (p == 7u) ? 37u : -1)) //((p < 7u) ? (p) + 14u : -1)
  1. Added pinA06
#define PIN_A6               (37ul) //added this line A6 is pin 37
static const uint8_t A6  = PIN_A6;
  1. Added line 37 in g_APinDescription
 { PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 37

With all those changes, i can still read all my analog pins until A5, but stil cant read A6. =/ It is located in PB04 of 64pin SAMD51J21 (http://ww1.microchip.com/downloads/en/DeviceDoc/60001507E.pdf)

Variant.h

#ifndef _VARIANT_SAMD51_THING_PLUS_
#define _VARIANT_SAMD51_THING_PLUS_

// The definitions here needs a SAMD core >=1.6.10
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10610

/*----------------------------------------------------------------------------
 *        Definitions
 *----------------------------------------------------------------------------*/

/** Frequency of the board main oscillator */
#define VARIANT_MAINOSC (32768ul)

/** Master clock frequency */
#define VARIANT_MCK  (120000000ul)

#define VARIANT_GCLK0_FREQ (120000000UL)
#define VARIANT_GCLK1_FREQ (48000000UL)
#define VARIANT_GCLK2_FREQ (100000000UL)

/*----------------------------------------------------------------------------
 *        Headers
 *----------------------------------------------------------------------------*/

#include "WVariant.h"

#ifdef __cplusplus
#include "SERCOM.h"
#include "Uart.h"
#endif // __cplusplus

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

/*----------------------------------------------------------------------------
 *        Pins
 *----------------------------------------------------------------------------*/

// Number of pins defined in PinDescription array
#define PINS_COUNT           (37u)
#define NUM_DIGITAL_PINS     (20u)
#define NUM_ANALOG_INPUTS    (7u)
#define NUM_ANALOG_OUTPUTS   (1u)
#define analogInputToDigitalPin(p)  ((p < 6u) ? (p) + 14u : ( (p == 7u) ? 37u : -1)) //((p < 7u) ? (p) + 14u : -1)

#define digitalPinToPort(P)        ( &(PORT->Group[g_APinDescription[P].ulPort]) )
#define digitalPinToBitMask(P)     ( 1 << g_APinDescription[P].ulPin )
//#define analogInPinToBit(P)        ( )
#define portOutputRegister(port)   ( &(port->OUT.reg) )
#define portInputRegister(port)    ( &(port->IN.reg) )
#define portModeRegister(port)     ( &(port->DIR.reg) )
#define digitalPinHasPWM(P)        ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER )

/*
 * digitalPinToTimer(..) is AVR-specific and is not defined for SAMD
 * architecture. If you need to check if a pin supports PWM you must
 * use digitalPinHasPWM(..).
 *
 * https://github.com/arduino/Arduino/issues/1833
 */
// #define digitalPinToTimer(P)

// LEDs
#define PIN_LED_13           (13u)
#define PIN_LED_RXL          (25u)
#define PIN_LED_TXL          (26u)
#define PIN_LED              PIN_LED_13
#define PIN_LED2             PIN_LED_RXL
#define PIN_LED3             PIN_LED_TXL
#define LED_BUILTIN          PIN_LED_13

/*
 * Analog pins
 */
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (37ul) //added this line A6 is pin 37


#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

static const uint8_t A0  = PIN_A0;
static const uint8_t A1  = PIN_A1;
static const uint8_t A2  = PIN_A2;
static const uint8_t A3  = PIN_A3;
static const uint8_t A4  = PIN_A4;
static const uint8_t A5  = PIN_A5;
static const uint8_t A6  = PIN_A6;

static const uint8_t DAC0 = PIN_DAC0;
static const uint8_t DAC1 = PIN_DAC1;

#define ADC_RESOLUTION 12

// Other pins
#define PIN_ATN              (30ul)
static const uint8_t ATN = PIN_ATN;

/*
 * Serial interfaces
 */

// Serial1
#define PIN_SERIAL1_RX       (0ul)
#define PIN_SERIAL1_TX       (1ul)
#define PAD_SERIAL1_RX       SERCOM_RX_PAD_1
#define PAD_SERIAL1_TX       UART_TX_PAD_0

/*
 * SPI Interfaces
 */
#define SPI_INTERFACES_COUNT 2
  
#define PIN_SPI_MISO         (22u)
#define PIN_SPI_MOSI         (23u)
#define PIN_SPI_SCK          (24u)
#define PERIPH_SPI           sercom4
#define PAD_SPI_TX           SPI_PAD_0_SCK_1
#define PAD_SPI_RX           SERCOM_RX_PAD_3

static const uint8_t SS  = 9 ; // SERCOM4 last PAD is present on d9 but HW SS isn't used. Set here only for reference.
static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t MISO = PIN_SPI_MISO ;
static const uint8_t SCK  = PIN_SPI_SCK ;  

#define PIN_SPI1_MISO         (35u)
#define PIN_SPI1_MOSI         (36u)
#define PIN_SPI1_SCK          (33u)
#define PERIPH_SPI1           sercom0
#define PAD_SPI1_TX           SPI_PAD_0_SCK_1
#define PAD_SPI1_RX           SERCOM_RX_PAD_3

static const uint8_t FLASH_SS = 34 ; // SERCOM0 last PAD is present on 34 but HW SS isn't used. Set here only for reference.
static const uint8_t FLASH_MOSI = PIN_SPI1_MOSI ;
static const uint8_t FLASH_MISO = PIN_SPI1_MISO ;
static const uint8_t FLASH_SCK  = PIN_SPI1_SCK ;

/*
 * Wire Interfaces
 */
#define WIRE_INTERFACES_COUNT 1

#define PIN_WIRE_SDA         (20u)
#define PIN_WIRE_SCL         (21u)
#define PERIPH_WIRE          sercom3
#define WIRE_IT_HANDLER      SERCOM3_Handler
#define WIRE_IT_HANDLER_0    SERCOM3_0_Handler
#define WIRE_IT_HANDLER_1    SERCOM3_1_Handler
#define WIRE_IT_HANDLER_2    SERCOM3_2_Handler
#define WIRE_IT_HANDLER_3    SERCOM3_3_Handler

static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;

/*
 * USB
 */
#define PIN_USB_HOST_ENABLE (27ul)
#define PIN_USB_DM          (28ul)
#define PIN_USB_DP          (29ul)

/*
 * I2S Interfaces
 */
#define I2S_INTERFACES_COUNT 1

#define I2S_DEVICE          0
#define I2S_CLOCK_GENERATOR 3

#define PIN_I2S_SDO          (11u)
#define PIN_I2S_SDI          (12u)
#define PIN_I2S_SCK          PIN_SERIAL1_TX
#define PIN_I2S_FS           (10u)
#define PIN_I2S_MCK          PIN_SERIAL1_RX

//QSPI Pins
//#define PIN_QSPI_SCK    (34u)
//#define PIN_QSPI_CS     (35u)
//#define PIN_QSPI_IO0    (36u)
//#define PIN_QSPI_IO1    (37u)
//#define PIN_QSPI_IO2    (38u)
//#define PIN_QSPI_IO3    (39u)

//TODO: meaningful value for this
//#define VARIANT_QSPI_BAUD_DEFAULT 5000000

#ifdef __cplusplus
}
#endif

/*----------------------------------------------------------------------------
 *        Arduino objects - C++ only
 *----------------------------------------------------------------------------*/

#ifdef __cplusplus

/* =========================
 * ===== SERCOM DEFINITION
 * =========================
*/
extern SERCOM sercom0;
extern SERCOM sercom1;
extern SERCOM sercom2;
extern SERCOM sercom3;
extern SERCOM sercom4;
extern SERCOM sercom5;

extern Uart Serial1;

#endif

// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use.  For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR        Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL     Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE    Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE       Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN  Hardware serial ports which are open for use.  Their RX & TX
//                            pins are NOT connected to anything by default.
#define SERIAL_PORT_USBVIRTUAL      Serial
#define SERIAL_PORT_MONITOR         Serial
// Serial has no physical pins broken out, so it's not listed as HARDWARE port
#define SERIAL_PORT_HARDWARE        Serial1
#define SERIAL_PORT_HARDWARE_OPEN   Serial1

#endif /* _VARIANT_FEATHER_M4_ */

Variant.cpp

#include "variant.h"

/*
 * Pins descriptions
 */

//TCC0 IOSET 6
//TCC1 IOSET 1
//TC0 IOSET 1
//TC1 IOSET 1
//TC2 IOSET 2
//TC3 IOSET 1
//TC4 IOSET 1
const PinDescription g_APinDescription[]=
{
  // 0..13 - Digital pins
  // ----------------------
  // 0/1 - SERCOM/UART (Serial1)
  { PORTA, 13, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC2_CH1, NOT_ON_TIMER, EXTERNAL_INT_13 }, // RX: SERCOM2/PAD[1]
  { PORTA, 12, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC2_CH0, NOT_ON_TIMER, EXTERNAL_INT_12 }, // TX: SERCOM2/PAD[2]

  // 2..12
  // Digital
  { NOT_A_PORT, 0,  PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { NOT_A_PORT, 0,  PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { 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  },
  { PORTA,  20, PIO_TIMER_ALT, PIN_ATTR_PWM_F, No_ADC_Channel, TCC0_CH0, TC7_CH0, EXTERNAL_INT_4 },
  { NOT_A_PORT, 0,  PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { NOT_A_PORT, 0,  PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },

  { PORTA,  7,  PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //pin 9
  { PORTA,  18, PIO_TIMER_ALT, PIN_ATTR_PWM_F, No_ADC_Channel, TCC1_CH2, TC3_CH0, EXTERNAL_INT_2 },
  { PORTA,  16, PIO_TIMER_ALT, PIN_ATTR_PWM_G, No_ADC_Channel, TCC1_CH0, NOT_ON_TIMER, EXTERNAL_INT_0 },
  { PORTA,  19, PIO_TIMER_ALT, PIN_ATTR_PWM_F, No_ADC_Channel, TCC1_CH3, TC3_CH1, EXTERNAL_INT_3 },

  // 13 (LED)
  { PORTA, 17, PIO_DIGITAL, PIN_ATTR_PWM_G, No_ADC_Channel, TCC0_CH3, TC4_CH1, EXTERNAL_INT_1 }, // TCC2/WO[1]

  // 14..19 - Analog pins
  // --------------------
  { PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 },
  { PORTB,  8, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8 },
  { PORTB,  9, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel3, TC4_CH1, TC4_CH1, EXTERNAL_INT_9 },
  { PORTA,  4, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel4, TC0_CH0, TC0_CH0, EXTERNAL_INT_6 },
  { PORTA,  5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
  { PORTB,  2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },

  // 20..21 I2C pins (SDA/SCL)
  // ----------------------
  { PORTA, 22, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH0, TC4_CH0, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
  { PORTA, 23, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH1, TC4_CH1, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]

  // 22..24 - SPI pins (MISO,MOSI,SCK)
  // ----------------------
  { PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // MISO: SERCOM4/PAD[3]
  { PORTB, 12, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // MOSI: SERCOM4/PAD[0]
  { PORTB, 13, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13 }, // SCK: SERCOM4/PAD[1]

  // 25..26 - RX/TX LEDS  -- unused
  // --------------------
  { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
  { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },

  // 27..29 - USB
  // --------------------
  { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB Host enable DOES NOT EXIST ON THIS BOARD
  { PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM
  { PORTA, 27, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DP

  // 30 (AREF)
  { PORTA, 3, PIO_ANALOG, PIN_ATTR_ANALOG, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VREFP

  // ----------------------
  // 31..32 - Alternate use of A0/A4 (DAC output)
  { PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VOUT0
  { PORTA,  5, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel1, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VOUT1

  // ----------------------
  // 33..36 SPI for Flash (SCK, CS, MISO, MOSI)
  { PORTA, 9, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //SCK
  { PORTA, 10, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //CS
  { PORTA, 11, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MISO
  { PORTA, 8, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MOSIZ

  { PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20

} ;

const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM]={ TCC0, TCC1, TCC2, TCC3, TCC4, TC0, TC1, TC2, TC3, TC4, TC5 } ;
const uint32_t GCLK_CLKCTRL_IDs[TCC_INST_NUM+TC_INST_NUM] = { TCC0_GCLK_ID, TCC1_GCLK_ID, TCC2_GCLK_ID, TCC3_GCLK_ID, TCC4_GCLK_ID, TC0_GCLK_ID, TC1_GCLK_ID, TC2_GCLK_ID, TC3_GCLK_ID, TC4_GCLK_ID, TC5_GCLK_ID } ;

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

Uart Serial1( &sercom2, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;

void SERCOM2_0_Handler()
{
  Serial1.IrqHandler();
}
void SERCOM2_1_Handler()
{
  Serial1.IrqHandler();
}
void SERCOM2_2_Handler()
{
  Serial1.IrqHandler();
}
void SERCOM2_3_Handler()
{
  Serial1.IrqHandler();
}

Hi S1buell,

Position 37 requires the PIN_ATTR_ANALOG_ALT attribute:

{ PORTB, 4, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC1/AIN[6]

It's the same as the PB04 port pin in Adafruit's Grand Central Metro M4 "variant.cpp" file:

{ PORTB, 4, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 },

Hello MartinL!

I really apreciate your help! With this i could read PB04, PB05, PB30, PB31. Thank you very much for your support!

I'm currently trying to read PB00 and PB01, and without success.

I've tried using the following combinations:

PIN_ATTR_ANALOG_ALT
(PIN_ATTR_ANALOG_ALT|PIN_ATTR_PWM_E)
PIN_ATTR_ANALOG

Maybe it has something to do with the code bellow, but not so shure...

// Number of pins defined in PinDescription array
#define PINS_COUNT           (42u)
#define NUM_DIGITAL_PINS     (22u)
#define NUM_ANALOG_INPUTS    (10u)
#define NUM_ANALOG_OUTPUTS   (1u)
#define analogInputToDigitalPin(p)  ((p < 6u) ? (p) + 14u : ((p < 10u) ? (p) + 37u : -1)) //((p < 7u) ? (p) + 14u : -1)
  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // %%%%%%%%%%%%%%%%%%%%%%%      ADDED LINES BELLOW      %%%%%%%%%%%%%%%%%%%%%%%%%%%
  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  // 37..40 - Analog pins
  { PORTB,  5, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel7, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, //A6 - OK
  { PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // A7 - OK
  { PORTB,  0, PIO_ANALOG, (PIN_ATTR_ANALOG_ALT|PIN_ATTR_PWM_E), ADC_Channel3, TC7_CH0, TC7_CH0, EXTERNAL_INT_0 }, // A8
  { PORTB,  1, PIO_ANALOG, (PIN_ATTR_ANALOG_ALT|PIN_ATTR_PWM_E), ADC_Channel4, TC7_CH1, TC7_CH1, EXTERNAL_INT_1 }, // A9
  
  // 41..42 - Digital pins
  { PORTB,  30, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, TCC4_CH0, TC0_CH0, EXTERNAL_INT_14 }, // D41
  { PORTB,  31, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, TCC4_CH1, TC0_CH1, EXTERNAL_INT_15 }, // D42

variant.cpp (7.46 KB)

variant.h (8.34 KB)