Skip to content

Commit 458d4ea

Browse files
committed
[dma] Support double buffer (stm32-stream-channel)
1 parent 0ed4457 commit 458d4ea

File tree

5 files changed

+118
-12
lines changed

5 files changed

+118
-12
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ Please [discover modm's peripheral drivers for your specific device][discover].
206206
<td align="left">DMA</td>
207207
<td align="center">✅</td>
208208
<td align="center">✅</td>
209-
<td align="center">○</td>
210209
<td align="center">✅</td>
211210
<td align="center">✅</td>
212211
<td align="center">✅</td>
213212
<td align="center">✅</td>
214213
<td align="center">✅</td>
215-
<td align="center">○</td>
214+
<td align="center">✅</td>
215+
<td align="center">✅</td>
216216
<td align="center">✅</td>
217217
<td align="center">✅</td>
218218
<td align="center">✅</td>
@@ -303,6 +303,26 @@ Please [discover modm's peripheral drivers for your specific device][discover].
303303
<td align="center">✅</td>
304304
<td align="center">✅</td>
305305
</tr><tr>
306+
<td align="left">I2S</td>
307+
<td align="center">✅</td>
308+
<td align="center">✅</td>
309+
<td align="center">✅</td>
310+
<td align="center">✅</td>
311+
<td align="center">✅</td>
312+
<td align="center">✅</td>
313+
<td align="center">✅</td>
314+
<td align="center">✅</td>
315+
<td align="center">✅</td>
316+
<td align="center">✅</td>
317+
<td align="center">✅</td>
318+
<td align="center">✕</td>
319+
<td align="center">○</td>
320+
<td align="center">✕</td>
321+
<td align="center">✕</td>
322+
<td align="center">✕</td>
323+
<td align="center">✕</td>
324+
<td align="center">✕</td>
325+
</tr><tr>
306326
<td align="left">I<sup>2</sup>C</td>
307327
<td align="center">✅</td>
308328
<td align="center">✅</td>

src/modm/platform/dma/stm32/dma.hpp.in

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,18 @@ public:
131131
MemoryIncrementMode memoryIncrement,
132132
PeripheralIncrementMode peripheralIncrement,
133133
Priority priority = Priority::Medium,
134-
CircularMode circularMode = CircularMode::Disabled)
134+
CircularMode circularMode = CircularMode::Disabled
135+
%% if doubleBuffer
136+
,DoubleBufferMode doubleBufferMode = DoubleBufferMode::Disabled
137+
%% endif
138+
)
135139
{
136-
ChannelHal::configure(direction, memoryDataSize, peripheralDataSize,
137-
memoryIncrement, peripheralIncrement, priority, circularMode);
140+
ChannelHal::configure(direction, memoryDataSize, peripheralDataSize, memoryIncrement,
141+
peripheralIncrement, priority, circularMode
142+
%% if doubleBuffer
143+
, doubleBufferMode
144+
%% endif
145+
);
138146
}
139147

140148
/**
@@ -177,6 +185,33 @@ public:
177185
{
178186
ChannelHal::setMemoryAddress(address);
179187
}
188+
189+
%% if doubleBuffer
190+
/**
191+
* Set the secondary memory address of the DMA channel
192+
*
193+
* Only used in double buffer mode
194+
*
195+
* @param[in] address Source address
196+
*/
197+
static void
198+
setMemoryAddress2(uintptr_t address)
199+
{
200+
ChannelHal::setMemoryAddress2(address);
201+
}
202+
203+
/**
204+
* Detect which buffer is currently in use
205+
*
206+
* Only meaningful in double buffer mode
207+
*/
208+
static bool
209+
isPrimaryBufferActive()
210+
{
211+
return ChannelHal::isPrimaryBufferActive();
212+
}
213+
%% endif
214+
180215
/**
181216
* Set the peripheral address of the DMA channel
182217
*

src/modm/platform/dma/stm32/dma_base.hpp.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ public:
189189
Enabled = {{ reg_prefix }}_CIRC, ///< circular mode
190190
};
191191

192+
%% if doubleBuffer
193+
enum class
194+
DoubleBufferMode : uint32_t
195+
{
196+
Disabled = 0,
197+
Enabled = {{ reg_prefix }}_DBM, ///< double buffer mode
198+
};
199+
%% endif
200+
192201
enum class
193202
DataTransferDirection : uint32_t
194203
{

src/modm/platform/dma/stm32/dma_hal.hpp.in

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,29 @@ public:
181181
* @param[in] circularMode Transfer data in circular mode?
182182
*/
183183
static void
184-
configure(DataTransferDirection direction, MemoryDataSize memoryDataSize,
185-
PeripheralDataSize peripheralDataSize,
186-
MemoryIncrementMode memoryIncrement,
187-
PeripheralIncrementMode peripheralIncrement,
188-
Priority priority = Priority::Medium,
189-
CircularMode circularMode = CircularMode::Disabled)
184+
configure(DataTransferDirection direction,
185+
MemoryDataSize memoryDataSize,
186+
PeripheralDataSize peripheralDataSize,
187+
MemoryIncrementMode memoryIncrement,
188+
PeripheralIncrementMode peripheralIncrement,
189+
Priority priority = Priority::Medium,
190+
CircularMode circularMode = CircularMode::Disabled
191+
%% if doubleBuffer
192+
, DoubleBufferMode doubleBufferMode = DoubleBufferMode::Disabled
193+
%% endif
194+
)
190195
{
191196
stop();
192197

193198
DMA_Channel_TypeDef *Base = (DMA_Channel_TypeDef *) CHANNEL_BASE;
194199
Base->{{ cr }} = uint32_t(direction) | uint32_t(memoryDataSize) |
195200
uint32_t(peripheralDataSize) | uint32_t(memoryIncrement) |
196201
uint32_t(peripheralIncrement) | uint32_t(priority) |
197-
uint32_t(circularMode);
202+
uint32_t(circularMode)
203+
%% if doubleBuffer
204+
| uint32_t(doubleBufferMode)
205+
%% endif
206+
;
198207
}
199208

200209
/**
@@ -232,6 +241,38 @@ public:
232241
%% endif
233242
}
234243

244+
%% if doubleBuffer
245+
/**
246+
* Set the secondary memory address of the DMA channel
247+
*
248+
* Only used in double buffer mode
249+
*
250+
* @param[in] address Source address
251+
*/
252+
static void
253+
setMemoryAddress2(uintptr_t address)
254+
{
255+
DMA_Channel_TypeDef *Base = (DMA_Channel_TypeDef *) CHANNEL_BASE;
256+
%% if dmaType in ["stm32-stream-channel"]
257+
Base->M1AR = address;
258+
%% endif
259+
}
260+
261+
/**
262+
* Detect which buffer is currently in use
263+
*
264+
* Only meaningful in double buffer mode
265+
*/
266+
static bool
267+
isPrimaryBufferActive()
268+
{
269+
DMA_Channel_TypeDef *Base = (DMA_Channel_TypeDef *) CHANNEL_BASE;
270+
%% if dmaType in ["stm32-stream-channel"]
271+
return (Base->CR & DMA_SxCR_CT);
272+
%% endif
273+
}
274+
%% endif
275+
235276
/**
236277
* Set the peripheral address of the DMA channel
237278
*

src/modm/platform/dma/stm32/module.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def build(env):
192192
properties["dmaType"] = dma["type"]
193193
properties["dmaSignals"] = signal_names
194194
properties["dmaController"] = controller
195+
properties["doubleBuffer"] = (dma["type"] in ["stm32-stream-channel"]) ## TODO: which other types support double buffer mode?
195196

196197
properties['channel_count'] = {
197198
"min" : min(controller, key=lambda c: c["min_channel"])["min_channel"],

0 commit comments

Comments
 (0)