Skip to content

Commit 0a1bb00

Browse files
Disable FLASH in sleep mode, unless a DMA from/to FLASH is active (remove SVCALL usage)
1 parent 5b7b348 commit 0a1bb00

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

system/libstm32l4_dragonfly/stm32l4_dma.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,26 @@ static void stm32l4_dma_track(uint32_t address)
114114

115115
static void stm32l4_dma_untrack(uint32_t address)
116116
{
117+
uint32_t o_flash, n_flash;
118+
117119
if (address < 0x10000000)
118120
{
119-
if (stm32l4_dma_driver.flash == 1)
121+
o_flash = stm32l4_dma_driver.flash;
122+
123+
do
120124
{
121-
if (__get_IPSR() == 0)
125+
n_flash = o_flash - 1;
126+
127+
if (n_flash == 0)
122128
{
123-
armv7m_svcall_0((uint32_t)&stm32l4_dma_flash_sleep);
129+
armv7m_atomic_and(&RCC->AHB1SMENR, ~RCC_AHB1SMENR_FLASHSMEN);
124130
}
125131
else
126132
{
127-
stm32l4_dma_flash_sleep();
133+
armv7m_atomic_or(&RCC->AHB1SMENR, RCC_AHB1SMENR_FLASHSMEN);
128134
}
129135
}
136+
while (!armv7m_atomic_compare_exchange(&stm32l4_dma_driver.flash, &o_flash, n_flash));
130137
}
131138
}
132139

-2 KB
Binary file not shown.

0 commit comments

Comments
 (0)