Skip to content

Commit

Permalink
[stm32] Add support for remapped A11/A12 pins on F0/G0
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand authored and salkinium committed Sep 17, 2020
1 parent 81265c6 commit 48d73dc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/modm/platform/gpio/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
# Copyright (c) 2020, Christopher Durand
#
# This file is part of the modm project.
#
Expand Down Expand Up @@ -123,6 +124,22 @@ def validate_alternate_functions(driver, env):
if not success:
env.log.debug("Gpio signal validation failed!")

def get_remap_command(family, key):
reg = 'SYSCFG->CFGR1'
mask = {
('f0', 'a9') : 'SYSCFG_CFGR1_PA11_PA12_RMP',
('f0', 'a10'): 'SYSCFG_CFGR1_PA11_PA12_RMP',
('f0', 'a11'): 'SYSCFG_CFGR1_PA11_PA12_RMP',
('f0', 'a12'): 'SYSCFG_CFGR1_PA11_PA12_RMP',
('g0', 'a9') : 'SYSCFG_CFGR1_PA11_RMP',
('g0', 'a10'): 'SYSCFG_CFGR1_PA12_RMP',
('g0', 'a11'): 'SYSCFG_CFGR1_PA11_RMP',
('g0', 'a12'): 'SYSCFG_CFGR1_PA12_RMP',
}.get((family, key))
if mask is None:
raise ValidateException("Unknown Remap for GPIO: 'P{}'".format(key.upper()))
return (reg, mask)

bprops = {}

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -199,6 +216,16 @@ def validate(env):
raise ValidateException("Pin '{}' already in EXTI map!".format(str(num)))
extimap[str(num)] = vec

# Compute the set of remapped pins
remapped_gpios = {}
for p in driver["package"][0]["pin"]:
variant = p.get("variant", "")
if "remap" in variant: # also matches "remap-default"
name = p["name"][1:4].strip().lower()
if len(name) > 2 and not name[2].isdigit():
name = name[:2]
remapped_gpios[name] = (variant == "remap") # "remap-default" -> False

all_signals = {}
for gpio in driver["gpio"]:
key = gpio["port"] + gpio["pin"]
Expand All @@ -215,11 +242,20 @@ def validate(env):
all_signals.update(extracted_signals)
signal_names = sorted(list(set(s["name"] for s in extracted_signals.values())))
extracted_signals = OrderedDict([(name, sorted([s for s in extracted_signals.values() if s["name"] == name], key=lambda si:si["name"])) for name in signal_names])
has_remap = key in remapped_gpios
bprops[key] = {
"gpio": gpio,
"exti_irqn": extimap[gpio["pin"]],
"signals": extracted_signals
"signals": extracted_signals,
"has_remap": has_remap,
}
if has_remap:
reg, mask = get_remap_command(device.identifier.family, key)
bprops[key].update({
"remap_reg": reg,
"remap_mask": mask,
"remap_value": remapped_gpios[key]
})

all_peripherals = [s["driver"] for s in all_signals.values()]
# Signals are not enough, since there are peripherals that don't have signals.
Expand Down
11 changes: 11 additions & 0 deletions src/modm/platform/gpio/stm32/pin.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public:
inline static void setAnalogInput() { PinSet::setAnalogInput(); }
/// @endcond

%% if has_remap
/// Remap this GPIO onto physical pins with selectable GPIO mappings
inline static void remap() {
%% if remap_value
{{remap_reg}} |= {{remap_mask}};
%% else
{{remap_reg}} &= ~{{remap_mask}};
%% endif
};
%% endif

public:
// GpioOutput
// start documentation inherited
Expand Down

0 comments on commit 48d73dc

Please sign in to comment.