From 48d73dcb4b28fa4d6602f9f37694df59fe998382 Mon Sep 17 00:00:00 2001 From: Christopher Durand Date: Wed, 16 Sep 2020 22:48:07 +0200 Subject: [PATCH] [stm32] Add support for remapped A11/A12 pins on F0/G0 --- src/modm/platform/gpio/stm32/module.lb | 38 ++++++++++++++++++++++++- src/modm/platform/gpio/stm32/pin.hpp.in | 11 +++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/modm/platform/gpio/stm32/module.lb b/src/modm/platform/gpio/stm32/module.lb index 4f37814201..511d56d230 100644 --- a/src/modm/platform/gpio/stm32/module.lb +++ b/src/modm/platform/gpio/stm32/module.lb @@ -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. # @@ -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 = {} # ----------------------------------------------------------------------------- @@ -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"] @@ -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. diff --git a/src/modm/platform/gpio/stm32/pin.hpp.in b/src/modm/platform/gpio/stm32/pin.hpp.in index b6c58e2ed9..bb9a55d870 100644 --- a/src/modm/platform/gpio/stm32/pin.hpp.in +++ b/src/modm/platform/gpio/stm32/pin.hpp.in @@ -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