summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-29 14:37:32 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-30 10:33:27 -0700
commit45f349d41588b732aa5118d8da890ce35a5e86ba (patch)
treeddf69800ee22ba66b61216eafaf1aecdd9556fcb
parenta2b1479a791fffa48d9ead914501562082bcdd95 (diff)
w5500: Validate SPI *before* initializing the hardware
-rw-r--r--libhw/w5500.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/libhw/w5500.c b/libhw/w5500.c
index c039226..563fd8b 100644
--- a/libhw/w5500.c
+++ b/libhw/w5500.c
@@ -331,11 +331,6 @@ void _w5500_init(struct w5500 *chip,
};
}
- /* Initialize the hardware. */
- gpio_set_irq_enabled_with_callback(pin_intr, GPIO_IRQ_EDGE_FALL, true, w5500_intrhandler);
- gpio_set_dir(chip->pin_reset, GPIO_OUT);
- w5500_hard_reset(chip);
-
/* Validate that SPI works correctly. */
for (uint16_t a = 0; a < 0x100; a++) {
w5500ll_write_sock_reg(chip->spidev, 0, mode, a);
@@ -345,6 +340,11 @@ void _w5500_init(struct w5500 *chip,
}
w5500ll_write_sock_reg(chip->spidev, 0, mode, 0);
+ /* Initialize the hardware. */
+ gpio_set_irq_enabled_with_callback(pin_intr, GPIO_IRQ_EDGE_FALL, true, w5500_intrhandler);
+ gpio_set_dir(chip->pin_reset, GPIO_OUT);
+ w5500_hard_reset(chip);
+
/* Finally, wire in the interrupt handler. */
bool saved = cr_save_and_disable_interrupts();
for (size_t i = 0; i < ARRAY_LEN(w5500_chips); i++) {