mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 21:11:12 +02:00
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>
This commit is contained in:
committed by
Damien George
parent
17808e7b74
commit
d42e39d87d
@@ -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 (;;) {
|
||||
|
@@ -67,6 +67,7 @@ extern const mp_obj_type_t pyb_spi_type;
|
||||
void spi_init0(void);
|
||||
int spi_init(const spi_t *spi, bool enable_nss_pin);
|
||||
void spi_deinit(const spi_t *spi_obj);
|
||||
void spi_deinit_all(void);
|
||||
int spi_find_index(mp_obj_t id);
|
||||
void spi_set_params(const spi_t *spi_obj, uint32_t prescale, int32_t baudrate,
|
||||
int32_t polarity, int32_t phase, int32_t bits, int32_t firstbit);
|
||||
|
Reference in New Issue
Block a user