diff options
| author | iabdalkader <i.abdalkader@gmail.com> | 2024-12-02 08:09:25 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-12-10 10:53:24 +1100 |
| commit | d42e39d87d37f20d74456222e603d0b6b409a556 (patch) | |
| tree | 2068787134828ab2e3b5823624553470474680a3 /ports/stm32/spi.c | |
| parent | 17808e7b749b269b58dcee67df599a0c61d455bd (diff) | |
stm32/spi: Add spi_deinit_all function.
SPI objects can remain active after a soft-reboot because they are
statically allocated and lack a finalizer to collect and deinitialize them.
This commit adds a `spi_deinit_all()` functions for SPI, similar to other
peripherals such as UART, DAC, etc.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Diffstat (limited to 'ports/stm32/spi.c')
| -rw-r--r-- | ports/stm32/spi.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c index 607b3fe68..aa459119c 100644 --- a/ports/stm32/spi.c +++ b/ports/stm32/spi.c @@ -545,6 +545,15 @@ void spi_deinit(const spi_t *spi_obj) { } } +void spi_deinit_all(void) { + for (int i = 0; i < MP_ARRAY_SIZE(spi_obj); i++) { + const spi_t *spi = &spi_obj[i]; + if (spi->spi != NULL) { + spi_deinit(spi); + } + } +} + static HAL_StatusTypeDef spi_wait_dma_finished(const spi_t *spi, uint32_t t_start, uint32_t timeout) { volatile HAL_SPI_StateTypeDef *state = &spi->spi->State; for (;;) { |
