Skip to content

Commit b26526f

Browse files
fix DMA resource tracking by properly masking off the channel index
1 parent ea0dcb3 commit b26526f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

system/libstm32l4_dragonfly/stm32l4_dma.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,19 @@ static void stm32l4_dma_track(uint32_t channel, uint32_t address)
8989
{
9090
if (address < 0x40000000)
9191
{
92+
uint32_t mask = (1ul << (channel & 15));
93+
9294
if (address >= 0x20000000)
9395
{
94-
stm32l4_system_periph_cond_wake(SYSTEM_PERIPH_SRAM1, &stm32l4_dma_driver.sram1, (1ul << channel));
96+
stm32l4_system_periph_cond_wake(SYSTEM_PERIPH_SRAM1, &stm32l4_dma_driver.sram1, mask);
9597
}
9698
else if (address >= 0x10000000)
9799
{
98-
stm32l4_system_periph_cond_wake(SYSTEM_PERIPH_SRAM2, &stm32l4_dma_driver.sram2, (1ul << channel));
100+
stm32l4_system_periph_cond_wake(SYSTEM_PERIPH_SRAM2, &stm32l4_dma_driver.sram2, mask);
99101
}
100102
else
101103
{
102-
stm32l4_system_periph_cond_wake(SYSTEM_PERIPH_FLASH, &stm32l4_dma_driver.flash, (1ul << channel));
104+
stm32l4_system_periph_cond_wake(SYSTEM_PERIPH_FLASH, &stm32l4_dma_driver.flash, mask);
103105
}
104106
}
105107
}
@@ -108,17 +110,19 @@ static void stm32l4_dma_untrack(uint32_t channel, uint32_t address)
108110
{
109111
if (address < 0x40000000)
110112
{
113+
uint32_t mask = (1ul << (channel & 15));
114+
111115
if (address >= 0x20000000)
112116
{
113-
stm32l4_system_periph_cond_sleep(SYSTEM_PERIPH_SRAM1, &stm32l4_dma_driver.sram1, (1ul << channel));
117+
stm32l4_system_periph_cond_sleep(SYSTEM_PERIPH_SRAM1, &stm32l4_dma_driver.sram1, mask);
114118
}
115119
else if (address >= 0x10000000)
116120
{
117-
stm32l4_system_periph_cond_sleep(SYSTEM_PERIPH_SRAM2, &stm32l4_dma_driver.sram2, (1ul << channel));
121+
stm32l4_system_periph_cond_sleep(SYSTEM_PERIPH_SRAM2, &stm32l4_dma_driver.sram2, mask);
118122
}
119123
else
120124
{
121-
stm32l4_system_periph_cond_sleep(SYSTEM_PERIPH_FLASH, &stm32l4_dma_driver.flash, (1ul << channel));
125+
stm32l4_system_periph_cond_sleep(SYSTEM_PERIPH_FLASH, &stm32l4_dma_driver.flash, mask);
122126
}
123127
}
124128
}
196 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)