Adam
November 17, 2023, 8:47am
1
Basic Information:
Printer Model: Customized
MCU : SAMD21
klippy.log (14.4 KB)
I try to set SERCOM4 to 3-wireSPI (MOSI, CLK, CS, without MISO)
according document
https://www.klipper3d.org/Config_Reference.html?h=samd#samd_sercom
rx_pin is optional. but I got “Invalid SERCOM configuration” issue.
while I comment out “rx_pin” (#rx_pin: PA12)
So, How could I set printf.cng to disable MISO at SERCOM4 ?
this pin(PA12) is use for dc_pin at SSD1306.
[samd_sercom sercom4_spi]
sercom: sercom4
clk_pin: PB11
tx_pin: PB10
#rx_pin: PA12
[display]
lcd_type:ssd1306
spi_bus:sercom4
cs_pin:PA13
dc_pin:PA12
reset_pin: PA27
Unfortunately, the Klipper code today does not support 3 wire spi mode. The rx_pin is documented as “optional” only because it is not needed when using i2c mode - it is required in spi mode.
-Kevin
Adam
November 21, 2023, 8:27am
3
I just modify sercom_spi_pins(uint32_t sercom_id)
at /src/atsamd/sercom.c
now, the SAMD21 could support Output Only SPI.
CS, CLK and MOSI. without MISO
For your reference,
#define VALID 0x0f // Dummy for Check Data
struct sercom_pin {
uint8_t pins[3];
uint8_t isvalid[3];
};
uint32_t
sercom_spi_pins(uint32_t sercom_id)
{
if (sercom_id >= ARRAY_SIZE(sercom_pins))
shutdown("Invalid SERCOM bus");
const struct sercom_pad *tx_sp = NULL;
const struct sercom_pad *rx_sp = NULL;
const struct sercom_pad *clk_sp = NULL;
uint8_t tx_pin = 0;
uint8_t clk_pin = 0;
uint8_t rx_pin = 0;
tx_pin = sercom_pins[sercom_id].pins[TX_PIN];
tx_sp = sercom_lookup_pad(sercom_id, tx_pin);
gpio_peripheral(tx_pin, tx_sp->ptype, 0);
clk_pin = sercom_pins[sercom_id].pins[CLK_PIN];
clk_sp = sercom_lookup_pad(sercom_id, clk_pin);
gpio_peripheral(clk_pin, clk_sp->ptype, 0);
if (sercom_pins[sercom_id].isvalid[RX_PIN] == VALID)
{
rx_pin = sercom_pins[sercom_id].pins[RX_PIN];
rx_sp = sercom_lookup_pad(sercom_id, rx_pin);
gpio_peripheral(rx_pin, rx_sp->ptype, 0);
}
uint8_t dopo = sercom_lookup_spi_dopo(tx_sp->pad, clk_sp->pad);
if (sercom_pins[sercom_id].isvalid[RX_PIN] != VALID)
{
if (rx_sp->pad == tx_sp->pad || rx_sp->pad == clk_sp->pad)
shutdown("Sercom RX pad collides with TX or CLK pad");
return SERCOM_SPI_CTRLA_DOPO(dopo);
}
else
{
return SERCOM_SPI_CTRLA_DIPO(rx_sp->pad) | SERCOM_SPI_CTRLA_DOPO(dopo);
}
}