From fe6b92f8b700db5310164339e71110953a59e110 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 2 Mar 2025 13:38:44 -0700 Subject: libhw: w5500: Re-add SPI validation This reverts commit 063f263f84d517c6497e7ca37f503956bad7075a. --- libhw/w5500.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libhw/w5500.c') diff --git a/libhw/w5500.c b/libhw/w5500.c index b4ad86b..fafc846 100644 --- a/libhw/w5500.c +++ b/libhw/w5500.c @@ -312,6 +312,15 @@ void _w5500_init(struct w5500 *chip, }; } + /* Validate that SPI works correctly. */ + for (uint16_t a = 0; a < 0x100; a++) { + w5500ll_write_sock_reg(chip->spidev, 0, mode, a); + uint8_t b = w5500ll_read_sock_reg(chip->spidev, 0, mode); + if (b != a) + errorf("SPI to W5500 does not appear to be functional: wrote:%d != read:%d", a, b); + } + w5500ll_write_sock_reg(chip->spidev, 0, mode, 0); + /* Initialize the hardware. */ gpioirq_set_and_enable_exclusive_handler(pin_intr, GPIO_IRQ_EDGE_FALL, w5500_intrhandler, chip); gpio_set_dir(chip->pin_reset, GPIO_OUT); -- cgit v1.2.3-2-g168b From c63584e6bcb934d84ef277cdc4619763a41f1bbe Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 2 Mar 2025 13:43:36 -0700 Subject: libhw: w5500: Add a VALIDATE_SPI toggle --- libhw/w5500.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'libhw/w5500.c') diff --git a/libhw/w5500.c b/libhw/w5500.c index fafc846..0f15785 100644 --- a/libhw/w5500.c +++ b/libhw/w5500.c @@ -96,6 +96,9 @@ #ifndef CONFIG_W5500_LOCAL_PORT_MAX #error config.h must define CONFIG_W5500_LOCAL_PORT_MAX #endif +#ifndef CONFIG_W5500_VALIDATE_SPI + #error config.h must define CONFIG_W5500_VALIDATE_SPI +#endif #ifndef CONFIG_W5500_DEBUG #error config.h must define CONFIG_W5500_DEBUG #endif @@ -312,14 +315,21 @@ void _w5500_init(struct w5500 *chip, }; } +#if CONFIG_W5500_VALIDATE_SPI /* Validate that SPI works correctly. */ + bool spi_ok = true; for (uint16_t a = 0; a < 0x100; a++) { w5500ll_write_sock_reg(chip->spidev, 0, mode, a); uint8_t b = w5500ll_read_sock_reg(chip->spidev, 0, mode); - if (b != a) - errorf("SPI to W5500 does not appear to be functional: wrote:%d != read:%d", a, b); + if (b != a) { + errorf("SPI to W5500 does not appear to be functional: wrote:0x%02"PRIx16" != read:0x%02"PRIx8, a, b); + spi_ok = false; + } } + if (!spi_ok) + __lm_abort(); w5500ll_write_sock_reg(chip->spidev, 0, mode, 0); +#endif /* Initialize the hardware. */ gpioirq_set_and_enable_exclusive_handler(pin_intr, GPIO_IRQ_EDGE_FALL, w5500_intrhandler, chip); -- cgit v1.2.3-2-g168b From 6354a440b24d9a0b157c8c5571403f09dd04c245 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 2 Mar 2025 21:16:35 -0700 Subject: libhw: Update comments and asserts about clock rate --- libhw/w5500.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libhw/w5500.c') diff --git a/libhw/w5500.c b/libhw/w5500.c index 0f15785..c4d36f3 100644 --- a/libhw/w5500.c +++ b/libhw/w5500.c @@ -348,9 +348,9 @@ static void w5500_post_reset(struct w5500 *chip) { w5500ll_write_common_reg(chip->spidev, eth_addr, chip->hwaddr); /* The RP2040 needs a 1/sys_clk hysteresis between interrupts - * for us to notice them. At the maximum-rated clock-rate of - * 133MHz, that means 7.5ns (but the sbc-harness overclocks - * the RP2040, so we could get away with even shorter). + * for us to notice them. At the default clock-rate of + * 125MHz, that means 8ns; and at the maximum-rated clock-rate + * of 200MHz, that means 5ns. * * If intlevel is non-zero, then the hysteresis is * (intlevel+1)*4/(150MHz), or (intlevel+1)*26.7ns; so even -- cgit v1.2.3-2-g168b