Skip to content

Commit 0a507aa

Browse files
committed
[platform] DMA: Enable for many more stm32-channel(-request) devices
1 parent 6562f17 commit 0a507aa

File tree

8 files changed

+163
-34
lines changed

8 files changed

+163
-34
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,16 @@ Please [discover modm's peripheral drivers for your specific device][discover].
185185
<td align="center">✗</td>
186186
</tr><tr>
187187
<td align="left">DMA</td>
188+
<td align="center">✅</td>
189+
<td align="center">✅</td>
188190
<td align="center">○</td>
191+
<td align="center">✅</td>
189192
<td align="center">○</td>
190193
<td align="center">○</td>
191194
<td align="center">○</td>
192195
<td align="center">○</td>
193-
<td align="center">○</td>
194-
<td align="center">○</td>
195-
<td align="center">○</td>
196-
<td align="center">○</td>
197-
<td align="center">○</td>
196+
<td align="center">✅</td>
197+
<td align="center">✅</td>
198198
<td align="center">✅</td>
199199
<td align="center">○</td>
200200
<td align="center">✗</td>

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111

1212
#include "dma.hpp"
1313

14-
%% for channels in dma["channels"]
14+
using namespace modm::platform;
15+
16+
%% for instance, irqs in irqList.items()
1517
/*
16-
* IRQ handler for DMA{{ channels.instance }}
18+
* IRQ handler for DMA{{ instance }}
1719
*/
18-
%% for channel in channels.channel
20+
%% for channels in irqs
1921

20-
MODM_ISR(DMA{{ channels.instance }}_Channel{{ channel.position }})
22+
MODM_ISR(DMA{{ instance }}_Channel{{ channels | join("_") }})
2123
{
22-
using namespace modm::platform;
23-
Dma{{ channels.instance }}::Channel<DmaBase::Channel::Channel{{ channel.position }}>::interruptHandler();
24+
%% for channel in channels
25+
Dma{{ instance }}::Channel<DmaBase::Channel::Channel{{ channel }}>::interruptHandler();
26+
%% endfor
2427
}
2528

2629
%% endfor

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2014, Kevin Läufer
33
* Copyright (c) 2014-2017, Niklas Hauser
44
* Copyright (c) 2020, Mike Wolfram
5+
* Copyright (c) 2021, Raphael Lehmann
56
*
67
* This file is part of the modm project.
78
*
@@ -46,8 +47,10 @@ public:
4647
{
4748
if constexpr (ID == 1)
4849
Rcc::enable<Peripheral::Dma1>();
50+
%% if (dma.instance | length) > 1
4951
else
5052
Rcc::enable<Peripheral::Dma2>();
53+
%% endif
5154
}
5255
/**
5356
* Disable the DMA controller in the RCC
@@ -57,8 +60,10 @@ public:
5760
{
5861
if constexpr (ID == 1)
5962
Rcc::disable<Peripheral::Dma1>();
63+
%% if (dma.instance | length) > 1
6064
else
6165
Rcc::disable<Peripheral::Dma2>();
66+
%% endif
6267
}
6368

6469
/**
@@ -225,16 +230,22 @@ public:
225230
{
226231
transferComplete = irqHandler;
227232
}
233+
228234
/**
229235
* Set the peripheral that operates the channel
230236
*/
231237
template <DmaBase::Request dmaRequest>
232238
static void
233239
setPeripheralRequest()
234240
{
241+
%% if dmaType in ["stm32-channel-request"]
235242
DMA_Request_TypeDef *DMA_REQ = reinterpret_cast<DMA_Request_TypeDef *>(ControlHal::DMA_CSEL);
236243
DMA_REQ->CSELR &= ~(0x0f << (uint32_t(ChannelID) * 4));
237244
DMA_REQ->CSELR |= uint32_t(dmaRequest) << (uint32_t(ChannelID) * 4);
245+
%% else
246+
// Nothing to see here. This controller has no request mux, instead
247+
// all requests are or-ed together.
248+
%% endif
238249
}
239250

240251
/**
@@ -349,6 +360,7 @@ public:
349360
* ...
350361
* };
351362
*/
363+
%% if dmaType in ["stm32-channel-request"]
352364
%% for channels in dma["channels"]
353365
%% for channel in channels.channel
354366
%% for request in channel.request
@@ -357,7 +369,7 @@ public:
357369
%% if signal.instance is defined
358370
%% set peripheral = peripheral ~ signal.instance
359371
%% else
360-
%% if peripheral not in ["Quadspi", "Aes", "Dcmi"]
372+
%% if peripheral in ["Dac", "Lpuart", "Swpmi"] and target["family"] not in ["f1", "f3", "l0", "l1"]
361373
%% set peripheral = peripheral ~ 1
362374
%% endif
363375
%% endif
@@ -375,6 +387,32 @@ struct DmaController<{{ channels.instance }}>::Channel<DmaBase::Channel::Channel
375387
%% endfor
376388
%% endfor
377389

390+
%%else
391+
%% for channels in dma["channels"]
392+
%% for channel in channels.channel
393+
%% for signal in channel.signal
394+
%% set peripheral = signal.driver.capitalize()
395+
%% if signal.instance is defined
396+
%% set peripheral = peripheral ~ signal.instance
397+
%% else
398+
%% if peripheral in ["Dac", "Lpuart", "Swpmi"] and target["family"] not in ["f1", "f3", "l0", "l1"]
399+
%% set peripheral = peripheral ~ 1
400+
%% endif
401+
%% endif
402+
template <>
403+
template <>
404+
template <>
405+
struct DmaController<{{ channels.instance }}>::Channel<DmaBase::Channel::Channel{{ channel.position }}>::RequestMapping<Peripheral::{{ peripheral }}{% if signal.name is defined %}, DmaBase::Signal::{{ signal.name.capitalize() }}{% endif %}>
406+
{
407+
using Channel = DmaController<{{ channels.instance }}>::Channel<DmaBase::Channel::Channel{{ channel.position }}>;
408+
static constexpr DmaBase::Request Request = DmaBase::Request::Any;
409+
};
410+
411+
%% endfor
412+
%% endfor
413+
%% endfor
414+
415+
%%endif
378416
} // namespace platform
379417

380418
} // namespace modm

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2014, Kevin Läufer
33
* Copyright (c) 2014-2017, Niklas Hauser
44
* Copyright (c) 2020, Mike Wolfram
5+
* Copyright (c) 2021, Raphael Lehmann
56
*
67
* This file is part of the modm project.
78
*
@@ -15,6 +16,8 @@
1516
#define MODM_STM32_DMA_BASE_HPP
1617

1718
#include <stdint.h>
19+
#include <cstddef>
20+
1821
#include "../device.hpp"
1922

2023
#include <modm/architecture/interface/assert.hpp>
@@ -23,7 +26,7 @@
2326

2427
%% if target["family"] == "f4"
2528
%% set reg_prefix = "DMA_SxCR"
26-
%% elif target["family"] in ["f3", "l4"]
29+
%% elif dmaType in ["stm32-channel-request", "stm32-channel"]
2730
%% set reg_prefix = "DMA_CCR"
2831
%% endif
2932

@@ -81,7 +84,7 @@ public:
8184
Dma = 0,
8285
Peripheral = DMA_SxCR_PFCTRL, ///< the peripheral is the flow controller
8386
};
84-
%% elif target["family"] in ["f3", "l4"]
87+
%% elif dmaType in ["stm32-channel-request", "stm32-channel"]
8588
%% set channel_count = namespace(max_channels = 0)
8689
%% for controller in dmaController
8790
%% if channel_count.max_channels < controller.channels
@@ -96,7 +99,7 @@ public:
9699
%% endfor
97100
};
98101

99-
%% if target["family"] == "l4"
102+
%% if dmaType in ["stm32-channel-request"]
100103
%% set request_count = namespace(max_requests = 0)
101104
%% for channels in dma["channels"]
102105
%% for channel in channels.channel
@@ -114,6 +117,14 @@ public:
114117
Request{{ request }}{% if request == 0 %} = 0{% endif %},
115118
%% endfor
116119
};
120+
%% else
121+
enum class
122+
Request
123+
{
124+
// Nothing to see here. This controller has no request mux, instead
125+
// all requests are OR-ed together.
126+
Any
127+
};
117128
%% endif
118129
%% endif
119130

@@ -181,7 +192,7 @@ public:
181192
MemoryToPeripheral = DMA_SxCR_DIR_0,
182193
/// Source: DMA_SxPAR; Sink: DMA_SxM0AR
183194
MemoryToMemory = DMA_SxCR_DIR_1,
184-
%% elif target["family"] in ["f3", "l4"]
195+
%% elif dmaType in ["stm32-channel-request", "stm32-channel"]
185196
/// Source: DMA_CPARx; Sink: DMA_CMARx
186197
PeripheralToMemory = 0,
187198
/// Source: DMA_CMARx; Sink: DMA_CPARx
@@ -219,7 +230,7 @@ protected:
219230
DMA_SxCR_PL_1 | DMA_SxCR_PL_0 | // Priority
220231
DMA_SxCR_CIRC | // CircularMode
221232
DMA_SxCR_PFCTRL; // FlowControl
222-
%% elif target["family"] in ["f3", "l4"]
233+
%% elif dmaType in ["stm32-channel-request", "stm32-channel"]
223234
static constexpr uint32_t memoryMask =
224235
DMA_CCR_MSIZE_0 | DMA_CCR_MSIZE_1 | // MemoryDataSize
225236
DMA_CCR_MINC | // MemoryIncrementMode
@@ -248,13 +259,15 @@ protected:
248259
struct Nvic;
249260
};
250261

251-
%% for channels in dma["channels"]
262+
%% for instance, irqs in irqList.items()
252263
template <>
253-
struct DmaBase::Nvic<{{ channels.instance }}>
264+
struct DmaBase::Nvic<{{ instance }}>
254265
{
255266
static constexpr IRQn_Type DmaIrqs[] {
256-
%% for channel in channels.channel
257-
DMA{{ channels.instance }}_Channel{{ channel.position }}_IRQn,
267+
%% for channels in irqs
268+
%% for i in range(channels | length)
269+
DMA{{ instance }}_Channel{{ channels | join("_") }}_IRQn,
270+
%% endfor
258271
%% endfor
259272
};
260273
};

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2020, Mike Wolfram
3+
* Copyright (c) 2021, Raphael Lehmann
34
*
45
* This file is part of the modm project.
56
*
@@ -22,6 +23,7 @@ namespace modm
2223
namespace platform
2324
{
2425

26+
2527
/**
2628
* Hardware abstraction of DMA controller
2729
*
@@ -45,20 +47,24 @@ class DmaHal : public DmaBase
4547
static constexpr uint32_t getBaseAddress() {
4648
if (id == 1)
4749
return DMA1_BASE;
50+
%% if (dma.instance | length) > 1
4851
else
4952
return DMA2_BASE;
53+
%% endif
5054
}
5155
/**
52-
* Get the base address of the DMA channel reigsters
56+
* Get the base address of the DMA channel registers
5357
*
5458
* @tparam id The number of the DMA channel
5559
*/
5660
template <uint32_t id>
5761
static constexpr uint32_t getChannelBaseAddress() {
5862
if (id == 1)
5963
return DMA1_Channel1_BASE;
64+
%% if (dma.instance | length) > 1
6065
else
6166
return DMA2_Channel1_BASE;
67+
%% endif
6268
}
6369
/**
6470
* Get the address of the channel selection register
@@ -67,10 +73,18 @@ class DmaHal : public DmaBase
6773
*/
6874
template <uint32_t id>
6975
static constexpr uint32_t getCselAddress() {
76+
%% if dmaType in ["stm32-channel-request"]
7077
if (id == 1)
7178
return DMA1_CSELR_BASE;
79+
%% if (dma.instance | length) > 1
7280
else
7381
return DMA2_CSELR_BASE;
82+
%%endif
83+
%% else
84+
// Nothing to see here. This controller has no request mux, instead
85+
// all requests are OR-ed together.
86+
return 0;
87+
%% endif
7488
}
7589

7690
public:

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2020, Mike Wolfram
3+
* Copyright (c) 2021, Raphael Lehmann
34
*
45
* This file is part of the modm project.
56
*
@@ -23,7 +24,7 @@ modm::platform::DmaChannelHal<ChannelID, CHANNEL_BASE>::start()
2324

2425
%% if target["family"] == "f4"
2526
Base->CR |= DMA_SxCR_EN;
26-
%% else
27+
%% elif dmaType in ["stm32-channel-request", "stm32-channel"]
2728
Base->CCR |= DMA_CCR_EN;
2829
%% endif
2930
}
@@ -37,7 +38,7 @@ modm::platform::DmaChannelHal<ChannelID, CHANNEL_BASE>::stop()
3738
%% if target["family"] == "f4"
3839
Base->CR &= ~DMA_SxCR_EN;
3940
while (Base->SCR & DMA_SxCR_EN); // wait for stream to be stopped
40-
%% else
41+
%% elif dmaType in ["stm32-channel-request", "stm32-channel"]
4142
Base->CCR &= ~DMA_CCR_EN;
4243
while (Base->CCR & DMA_CCR_EN); // wait for stream to be stopped
4344
%% endif
@@ -52,7 +53,7 @@ modm::platform::DmaChannelHal<ChannelID, CHANNEL_BASE>::getDataTransferDirection
5253
return static_cast<DataTransferDirection>(
5354
%% if target["family"] == "f4"
5455
Base->CR & (DMA_SxCR_DIR_0 | DMA_SxCR_DIR_1));
55-
%% else
56+
%% elif dmaType in ["stm32-channel-request", "stm32-channel"]
5657
Base->CCR & (DMA_CCR_MEM2MEM | DMA_CCR_DIR));
5758
%% endif
5859
}

0 commit comments

Comments
 (0)