Skip to content

Commit

Permalink
[stm32] Add DMA support for F030xC, F091 and F098
Browse files Browse the repository at this point in the history
Now all F0, F1, F3, L0, L1, L4, G0 and G4 are supported.
  • Loading branch information
chris-durand committed Jun 6, 2021
1 parent 4e3d374 commit 8896b5b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/modm/platform/dma/stm32/dma.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ public:
setPeripheralRequest()
{
%% if dmaType in ["stm32-channel-request"]
DMA_Request_TypeDef *DMA_REQ = reinterpret_cast<DMA_Request_TypeDef *>(ControlHal::DMA_CSEL);
%% if target["family"] == "f0"
auto* DMA_REQ = reinterpret_cast<DMA_TypeDef *>(ControlHal::DMA_BASE);
%% else
auto* DMA_REQ = reinterpret_cast<DMA_Request_TypeDef *>(ControlHal::DMA_CSEL);
%% endif
DMA_REQ->CSELR &= ~(0x0f << (uint32_t(ChannelID) * 4));
DMA_REQ->CSELR |= uint32_t(dmaRequest) << (uint32_t(ChannelID) * 4);
%% elif dmaType in ["stm32-mux"]
Expand Down
4 changes: 2 additions & 2 deletions src/modm/platform/dma/stm32/dma_hal.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DmaHal : public DmaBase
%% endif
}

%% if dmaType in ["stm32-channel-request"]
%% if dmaType in ["stm32-channel-request"] and target["family"] != "f0"
/**
* Get the address of the channel selection register
*
Expand All @@ -87,7 +87,7 @@ class DmaHal : public DmaBase
public:
/// DMA base register address
static constexpr uint32_t DMA_BASE { getBaseAddress<ID>() };
%% if dmaType in ["stm32-channel-request"]
%% if dmaType in ["stm32-channel-request"] and target["family"] != "f0"
/// DMA channel selection register address
static constexpr uint32_t DMA_CSEL { getCselAddress<ID>() };
%% endif
Expand Down
27 changes: 18 additions & 9 deletions src/modm/platform/dma/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ def prepare(module, options):

did = device.identifier

# Enable DMA for all but some devices...

if did["family"] in ["f0"]:
if did["name"] in ["91", "98"] or (did["name"] == "30" and did["size"] == "c"):
# type "stm32-channel-request" incompatible to driver
return False
return True

if did["family"] in ["f1", "f3", "l0", "l1", "l4", "g0", "g4"]:
if did["family"] in ["f0", "f1", "f3", "l0", "l1", "l4", "g0", "g4"]:
return True

return False
Expand Down Expand Up @@ -95,11 +87,28 @@ def build(env):
for channel in channels["channel"]:
max_channels = channel["position"]
if dma["type"] in ["stm32-channel-request"]:
# Some F0 allow to use multiple requests for the same peripheral signal
# on the same channel. This is not supported with the current api.
# Therefore, signals are deduplicated.
signal_set = set()
duplicates = []
for request in channel["request"]:
for signal in request["signal"]:
signal_data = (signal.get("driver"),
signal.get("instance"),
signal.get("name"))
if signal_data in signal_set:
duplicates.append((channel, request, signal))
else:
signal_set.add(signal_data)
if "name" in signal:
signal_name = signal["name"].capitalize()
signal_names[signal_name] = 1
for duplicate in duplicates:
(channel, request, signal) = duplicate
request["signal"].remove(signal)
if len(request["signal"]) == 0:
channel["request"].remove(request)
else:
for signal in channel["signal"]:
if "name" in signal:
Expand Down

0 comments on commit 8896b5b

Please sign in to comment.