From 7aec52dfb3743850935d1080e045339c4a766231 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 27 Jun 2018 11:36:27 -0400 Subject: [PATCH] avr: Don't set SS high on spi_init() The AVR requires that the SS pin be an output pin for correct SPI operation. Some boards use the SS pin to control devices separate from SPI, however. Don't change the output level if the pin is already an output, and prefer setting it low if it is not already an output pin. Signed-off-by: Kevin O'Connor --- src/avr/gpio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/avr/gpio.c b/src/avr/gpio.c index ce89b1be..a6b7aa41 100644 --- a/src/avr/gpio.c +++ b/src/avr/gpio.c @@ -371,7 +371,9 @@ static const uint8_t MOSI = GPIO('B', 2), MISO = GPIO('B', 3); static void spi_init(void) { - gpio_out_setup(SS, 1); + if (!(GPIO2REGS(SS)->mode & GPIO2BIT(SS))) + // The SS pin must be an output pin (but is otherwise unused) + gpio_out_setup(SS, 0); gpio_out_setup(SCK, 0); gpio_out_setup(MOSI, 0); gpio_in_setup(MISO, 0);