summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'stmhal/spi.c')
-rw-r--r--stmhal/spi.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/stmhal/spi.c b/stmhal/spi.c
index 6285321a8b..387fc174c4 100644
--- a/stmhal/spi.c
+++ b/stmhal/spi.c
@@ -78,10 +78,8 @@
typedef struct _pyb_spi_obj_t {
mp_obj_base_t base;
SPI_HandleTypeDef *spi;
- DMA_Stream_TypeDef *tx_dma_stream;
- uint32_t tx_dma_channel;
- DMA_Stream_TypeDef *rx_dma_stream;
- uint32_t rx_dma_channel;
+ const dma_descr_t *tx_dma_descr;
+ const dma_descr_t *rx_dma_descr;
} pyb_spi_obj_t;
#if defined(MICROPY_HW_SPI1_SCK)
@@ -105,34 +103,34 @@ SPI_HandleTypeDef SPIHandle6 = {.Instance = NULL};
STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
#if defined(MICROPY_HW_SPI1_SCK)
- {{&pyb_spi_type}, &SPIHandle1, DMA_STREAM_SPI1_TX, DMA_CHANNEL_SPI1_TX, DMA_STREAM_SPI1_RX, DMA_CHANNEL_SPI1_RX},
+ {{&pyb_spi_type}, &SPIHandle1, &dma_SPI_1_TX, &dma_SPI_1_RX},
#else
- {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0},
+ {{&pyb_spi_type}, NULL, NULL, NULL},
#endif
#if defined(MICROPY_HW_SPI2_SCK)
- {{&pyb_spi_type}, &SPIHandle2, DMA_STREAM_SPI2_TX, DMA_CHANNEL_SPI2_TX, DMA_STREAM_SPI2_RX, DMA_CHANNEL_SPI2_RX},
+ {{&pyb_spi_type}, &SPIHandle2, &dma_SPI_2_TX, &dma_SPI_2_RX},
#else
- {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0},
+ {{&pyb_spi_type}, NULL, NULL, NULL},
#endif
#if defined(MICROPY_HW_SPI3_SCK)
- {{&pyb_spi_type}, &SPIHandle3, DMA_STREAM_SPI3_TX, DMA_CHANNEL_SPI3_TX, DMA_STREAM_SPI3_RX, DMA_CHANNEL_SPI3_RX},
+ {{&pyb_spi_type}, &SPIHandle3, &dma_SPI_3_TX, &dma_SPI_3_RX},
#else
- {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0},
+ {{&pyb_spi_type}, NULL, NULL, NULL},
#endif
#if defined(MICROPY_HW_SPI4_SCK)
- {{&pyb_spi_type}, &SPIHandle4, DMA_STREAM_SPI4_TX, DMA_CHANNEL_SPI4_TX, DMA_STREAM_SPI4_RX, DMA_CHANNEL_SPI4_RX},
+ {{&pyb_spi_type}, &SPIHandle4, &dma_SPI_4_TX, &dma_SPI_4_RX},
#else
- {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0},
+ {{&pyb_spi_type}, NULL, NULL, NULL},
#endif
#if defined(MICROPY_HW_SPI5_SCK)
- {{&pyb_spi_type}, &SPIHandle5, DMA_STREAM_SPI5_TX, DMA_CHANNEL_SPI5_TX, DMA_STREAM_SPI5_RX, DMA_CHANNEL_SPI5_RX},
+ {{&pyb_spi_type}, &SPIHandle5, &dma_SPI_5_TX, &dma_SPI_5_RX},
#else
- {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0},
+ {{&pyb_spi_type}, NULL, NULL, NULL},
#endif
#if defined(MICROPY_HW_SPI6_SCK)
- {{&pyb_spi_type}, &SPIHandle6, DMA_STREAM_SPI6_TX, DMA_CHANNEL_SPI6_TX, DMA_STREAM_SPI6_RX, DMA_CHANNEL_SPI6_RX},
+ {{&pyb_spi_type}, &SPIHandle6, &dma_SPI_6_TX, &dma_SPI_6_RX},
#else
- {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0},
+ {{&pyb_spi_type}, NULL, NULL, NULL},
#endif
};
@@ -257,8 +255,8 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
// After calling HAL_SPI_Init() it seems that the DMA gets disconnected if
// it was previously configured. So we invalidate the DMA channel to force
// an initialisation the next time we use it.
- dma_invalidate_channel(self->tx_dma_stream, self->tx_dma_channel);
- dma_invalidate_channel(self->rx_dma_stream, self->rx_dma_channel);
+ dma_invalidate_channel(self->tx_dma_descr);
+ dma_invalidate_channel(self->rx_dma_descr);
}
void spi_deinit(SPI_HandleTypeDef *spi) {
@@ -553,14 +551,14 @@ STATIC mp_obj_t pyb_spi_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
status = HAL_SPI_Transmit(self->spi, bufinfo.buf, bufinfo.len, args[1].u_int);
} else {
DMA_HandleTypeDef tx_dma;
- dma_init(&tx_dma, self->tx_dma_stream, &dma_init_struct_spi_i2c, self->tx_dma_channel, DMA_MEMORY_TO_PERIPH, self->spi);
+ dma_init(&tx_dma, self->tx_dma_descr, self->spi);
self->spi->hdmatx = &tx_dma;
self->spi->hdmarx = NULL;
status = HAL_SPI_Transmit_DMA(self->spi, bufinfo.buf, bufinfo.len);
if (status == HAL_OK) {
status = spi_wait_dma_finished(self->spi, args[1].u_int);
}
- dma_deinit(&tx_dma);
+ dma_deinit(self->tx_dma_descr);
}
if (status != HAL_OK) {
@@ -606,12 +604,12 @@ STATIC mp_obj_t pyb_spi_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
DMA_HandleTypeDef tx_dma, rx_dma;
if (self->spi->Init.Mode == SPI_MODE_MASTER) {
// in master mode the HAL actually does a TransmitReceive call
- dma_init(&tx_dma, self->tx_dma_stream, &dma_init_struct_spi_i2c, self->tx_dma_channel, DMA_MEMORY_TO_PERIPH, self->spi);
+ dma_init(&tx_dma, self->tx_dma_descr, self->spi);
self->spi->hdmatx = &tx_dma;
} else {
self->spi->hdmatx = NULL;
}
- dma_init(&rx_dma, self->rx_dma_stream, &dma_init_struct_spi_i2c, self->rx_dma_channel, DMA_PERIPH_TO_MEMORY, self->spi);
+ dma_init(&rx_dma, self->rx_dma_descr, self->spi);
self->spi->hdmarx = &rx_dma;
status = HAL_SPI_Receive_DMA(self->spi, (uint8_t*)vstr.buf, vstr.len);
@@ -619,9 +617,9 @@ STATIC mp_obj_t pyb_spi_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
status = spi_wait_dma_finished(self->spi, args[1].u_int);
}
if (self->spi->hdmatx != NULL) {
- dma_deinit(&tx_dma);
+ dma_deinit(self->tx_dma_descr);
}
- dma_deinit(&rx_dma);
+ dma_deinit(self->rx_dma_descr);
}
if (status != HAL_OK) {
@@ -701,16 +699,16 @@ STATIC mp_obj_t pyb_spi_send_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp
status = HAL_SPI_TransmitReceive(self->spi, bufinfo_send.buf, bufinfo_recv.buf, bufinfo_send.len, args[2].u_int);
} else {
DMA_HandleTypeDef tx_dma, rx_dma;
- dma_init(&tx_dma, self->tx_dma_stream, &dma_init_struct_spi_i2c, self->tx_dma_channel, DMA_MEMORY_TO_PERIPH, self->spi);
+ dma_init(&tx_dma, self->tx_dma_descr, self->spi);
self->spi->hdmatx = &tx_dma;
- dma_init(&rx_dma, self->rx_dma_stream, &dma_init_struct_spi_i2c, self->rx_dma_channel, DMA_PERIPH_TO_MEMORY, self->spi);
+ dma_init(&rx_dma, self->rx_dma_descr, self->spi);
self->spi->hdmarx = &rx_dma;
status = HAL_SPI_TransmitReceive_DMA(self->spi, bufinfo_send.buf, bufinfo_recv.buf, bufinfo_send.len);
if (status == HAL_OK) {
status = spi_wait_dma_finished(self->spi, args[2].u_int);
}
- dma_deinit(&tx_dma);
- dma_deinit(&rx_dma);
+ dma_deinit(self->tx_dma_descr);
+ dma_deinit(self->rx_dma_descr);
}
if (status != HAL_OK) {