summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-09-11 17:19:55 +1000
committerDamien George <damien.p.george@gmail.com>2018-09-11 17:19:55 +1000
commitd7e2ac4a6ae8d11f108a526c7ad356154d0d2a43 (patch)
treeccf47883f42f9445e9a5e36956dcde57537e3dae
parentb0c8a94b4146ff2266fca76e1c08172ea6e3aeb7 (diff)
stm32/dma: Reinitialise the DMA if the direction changed on the channel.
-rw-r--r--ports/stm32/dma.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ports/stm32/dma.c b/ports/stm32/dma.c
index 54e1c15be..f5bdd5a38 100644
--- a/ports/stm32/dma.c
+++ b/ports/stm32/dma.c
@@ -551,9 +551,9 @@ void dma_init(DMA_HandleTypeDef *dma, const dma_descr_t *dma_descr, uint32_t dir
HAL_DMA_Init(dma);
NVIC_SetPriority(IRQn_NONNEG(dma_irqn[dma_id]), IRQ_PRI_DMA);
#else
- // if this stream was previously configured for this channel/request then we
+ // if this stream was previously configured for this channel/request and direction then we
// can skip most of the initialisation
- uint8_t sub_inst = DMA_SUB_INSTANCE_AS_UINT8(dma_descr->sub_instance);
+ uint8_t sub_inst = DMA_SUB_INSTANCE_AS_UINT8(dma_descr->sub_instance) | (dir == DMA_PERIPH_TO_MEMORY) << 7;
if (dma_last_sub_instance[dma_id] != sub_inst) {
dma_last_sub_instance[dma_id] = sub_inst;
@@ -596,7 +596,8 @@ void dma_deinit(const dma_descr_t *dma_descr) {
void dma_invalidate_channel(const dma_descr_t *dma_descr) {
if (dma_descr != NULL) {
dma_id_t dma_id = dma_descr->id;
- if (dma_last_sub_instance[dma_id] == DMA_SUB_INSTANCE_AS_UINT8(dma_descr->sub_instance) ) {
+ // Only compare the sub-instance, not the direction bit (MSB)
+ if ((dma_last_sub_instance[dma_id] & 0x7f) == DMA_SUB_INSTANCE_AS_UINT8(dma_descr->sub_instance) ) {
dma_last_sub_instance[dma_id] = DMA_INVALID_CHANNEL;
}
}