mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01: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) {
|
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;
|
volatile HAL_SPI_StateTypeDef *state = &spi->spi->State;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ extern const mp_obj_type_t pyb_spi_type;
|
|||||||
void spi_init0(void);
|
void spi_init0(void);
|
||||||
int spi_init(const spi_t *spi, bool enable_nss_pin);
|
int spi_init(const spi_t *spi, bool enable_nss_pin);
|
||||||
void spi_deinit(const spi_t *spi_obj);
|
void spi_deinit(const spi_t *spi_obj);
|
||||||
|
void spi_deinit_all(void);
|
||||||
int spi_find_index(mp_obj_t id);
|
int spi_find_index(mp_obj_t id);
|
||||||
void spi_set_params(const spi_t *spi_obj, uint32_t prescale, int32_t baudrate,
|
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);
|
int32_t polarity, int32_t phase, int32_t bits, int32_t firstbit);
|
||||||
|
|||||||
Reference in New Issue
Block a user