adafruit / ArduinoCore-samd

116 stars 119 forks source link

Grand Central M4 MOSI and SCLK Pins Swapped #284

Open Rymar-Eng opened 3 years ago

Rymar-Eng commented 3 years ago

It appears that these 2 pins are reversed, in variants/grand_central_m4/variant.h (line 180)

#define PIN_SPI_MOSI        (66)
#define PIN_SPI_SCK         (65)

From variant.cpp, in the rows for pins 65 and 66:

  { PORTD, 8, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3 },   // MOSI
  { PORTD, 9, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 },   // SCK

Looking at the Grand Central M4 schematic, PORTD pin 8 is actually connected to MOSI, and PORTD pin 9 is actually connected to SCK; in other words variant.cpp is correct. However, in variant.h, PIN_SPI_MOSI should be for row 65 in g_APinDescription, and PIN_SPI_SCK should be for row 66. This doesn't cause any problems with the SERCOM controlled SPI port, because both pins have the same initialization parameter from g_APinDescription, and the SPI SERCOM controls both signals directly. I guess if someone tried to use the symbols MOSI and SCK to as inputs to the simple digital pin controls this would create a problem.