Hi, the atsamd51/21 MCU’s need to have sercom configured for SPI. I’m trying to setup a itsybitsy M4 (atsam51) with Klipper.
If I configured the SPI per what I’m fairly sure is the correct config for this board I get ‘Invalid SERCOM configuration’.
sercom: sercom1
tx_pin: samd:PA0 #MOSI
rx_pin: samd:PB23 #MISO
clk_pin: samd:PA1 #CLK
Reading the source in src/atsamd/sercom.c, I see that for sercom1 PB23 is not allows (this is actually allowed, as the MISO pin can be on any valid pad on the atsam51.
So I changed the pins to a valid set, as below but I still get the same error.
sercom: sercom1
tx_pin: samd:PA0 #MOSI
rx_pin: samd:PA31 #MISO (have tried PA30 also)
clk_pin: samd:PA1 #CLK
If I use the following I do not get an error
sercom: sercom0
tx_pin: samd:PA4 #MOSI
rx_pin: samd:PA7 #MISO
clk_pin: samd:PA5 #CLK
The SPI does not work because these pins are incorrect for the board but at least the errors stopped.
At this point I decided I need to check if the data was getting to the function which was causing the message and shutdown.
I changed sercom_lookup_pad to the following
static const struct sercom_pad *
sercom_lookup_pad(uint32_t sercom_id, uint8_t pin)
{
const struct sercom_pad *sp = sercom_pads;
char strpin[2] = "r";
uint8_t h = sercom_id % 0xff;
strpin[0] = h+64;
output("error: %s", strpin);
strpin[0] = pin+64;
output("error: %s", strpin);
for (; ; sp++) {
if (sp >= &sercom_pads[ARRAY_SIZE(sercom_pads)]) {
shutdown("Invalid SERCOM configuration");
}
if (sp->sercom_id == sercom_id && sp->gpio == pin)
return sp;
}
}
I then tried the working config again
[samd_sercom samd_spi]
sercom: sercom0
tx_pin: samd:PA4 #MOSI
rx_pin: samd:PA7 #MISO
clk_pin: samd:PA5 #CLK
This results in
mcu ‘samd’: #output: error: ‘@’ ← is sercom0
mcu ‘samd’: #output: error: ‘D’
mcu ‘samd’: #output: error: ‘@’
mcu ‘samd’: #output: error: ‘G’
mcu ‘samd’: #output: error: ‘@’
mcu ‘samd’: #output: error: ‘E’
Now I try which is a valid config for sercom1 but still not valid for the board.
sercom: sercom1
tx_pin: samd:PA0 #MOSI
rx_pin: samd:PA31 #MISO (have tried PA30 also)
clk_pin: samd:PA1 #CLK
This results in
Receive: 75 224034.722536 224034.721611 8: seq: 11, #output error: ‘@’ < sercom0 but should be 1
Receive: 76 224034.722558 224034.721611 8: seq: 11, #output error: ‘@’ ← tx_pin
From this I see that the code does not correctly set the sercom to 1 so the table in the source code does not match anything.
Finally the issue is that the table in sercom.c does not allow for the fact that PB23 is a valid pin for MISO.
IE
sercom: sercom1
tx_pin: samd:PA0 #MOSI
rx_pin: samd:PB23 #MISO
clk_pin: samd:PA1 #CLK
As a result I think there is a bug which is not correctly processing the sercom port and then there is an issue with the allowed pins in the table.
klipper_m4_bad_goodline.zip (29.1 KB)
klipper_m4_ok.zip (26.8 KB)
Cheers
Mike