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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-06-27 11:36:27 -04:00
parent d651851567
commit 7aec52dfb3
1 changed files with 3 additions and 1 deletions

View File

@ -371,7 +371,9 @@ static const uint8_t MOSI = GPIO('B', 2), MISO = GPIO('B', 3);
static void static void
spi_init(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(SCK, 0);
gpio_out_setup(MOSI, 0); gpio_out_setup(MOSI, 0);
gpio_in_setup(MISO, 0); gpio_in_setup(MISO, 0);