diff options
| author | Damien George <damien@micropython.org> | 2022-03-25 14:29:48 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-03-29 11:44:08 +1100 |
| commit | 2a91c8a888bc56b61876e6d01a2f144aee5686b4 (patch) | |
| tree | 421b465b7ea5d206c763f797ccd31547da0a350a | |
| parent | c90dfba04ca8d6e3eb12732dea2344f393f77531 (diff) | |
stm32/machine_i2s: Allow I2S.deinit to be called multiple times.
In particular, it is called by the constructor if the instance already
exists. So if the previous instance was deinit'd then it will be deinit'd
a second time.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/stm32/machine_i2s.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/ports/stm32/machine_i2s.c b/ports/stm32/machine_i2s.c index 0bb0f3e8f..2120554c3 100644 --- a/ports/stm32/machine_i2s.c +++ b/ports/stm32/machine_i2s.c @@ -887,24 +887,26 @@ STATIC mp_obj_t machine_i2s_init(size_t n_pos_args, const mp_obj_t *pos_args, mp STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_init_obj, 1, machine_i2s_init); STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in) { - machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); - dma_deinit(self->dma_descr_tx); - dma_deinit(self->dma_descr_rx); - HAL_I2S_DeInit(&self->hi2s); - - if (self->hi2s.Instance == I2S1) { - __SPI1_FORCE_RESET(); - __SPI1_RELEASE_RESET(); - __SPI1_CLK_DISABLE(); - } else if (self->hi2s.Instance == I2S2) { - __SPI2_FORCE_RESET(); - __SPI2_RELEASE_RESET(); - __SPI2_CLK_DISABLE(); - } + if (self->ring_buffer_storage != NULL) { + dma_deinit(self->dma_descr_tx); + dma_deinit(self->dma_descr_rx); + HAL_I2S_DeInit(&self->hi2s); + + if (self->hi2s.Instance == I2S1) { + __SPI1_FORCE_RESET(); + __SPI1_RELEASE_RESET(); + __SPI1_CLK_DISABLE(); + } else if (self->hi2s.Instance == I2S2) { + __SPI2_FORCE_RESET(); + __SPI2_RELEASE_RESET(); + __SPI2_CLK_DISABLE(); + } - m_free(self->ring_buffer_storage); + m_free(self->ring_buffer_storage); + self->ring_buffer_storage = NULL; + } return mp_const_none; } |
