Skip to content

Commit d0972e2

Browse files
committed
[stm32] Add support for remapped A11/A12 pins on F0/G0
1 parent 64c98f8 commit d0972e2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
# Copyright (c) 2016-2018, Niklas Hauser
55
# Copyright (c) 2017, Fabian Greif
6+
# Copyright (c) 2020, Christopher Durand
67
#
78
# This file is part of the modm project.
89
#
@@ -123,6 +124,44 @@ def validate_alternate_functions(driver, env):
123124
if not success:
124125
env.log.debug("Gpio signal validation failed!")
125126

127+
def is_remap_pin(driver, pin, port):
128+
"""
129+
For the STM32F0/G0 series
130+
-------------------------
131+
Some chips exist where gpios can be multiplexed on some package pins
132+
"""
133+
package_pins = driver["package"][0]["pin"]
134+
pin_name = 'P{}{}'.format(port.upper(), pin)
135+
package_pin = next(pin for pin in package_pins if pin['name'].startswith(pin_name))
136+
variant = package_pin.get('variant', None)
137+
if variant is not None and 'remap' in variant:
138+
return True
139+
else:
140+
position = package_pin["position"]
141+
def is_other_mapping(p):
142+
variant = p.get('variant', None)
143+
return (p['position'] == position) and variant is not None and 'remap' in variant
144+
return any(pin for pin in package_pins if is_other_mapping(pin))
145+
146+
def get_remap_command(family, pin, port):
147+
if family not in ["f0", "g0"]:
148+
raise ValidateException("Remapped package pins only supported for F0 and G0")
149+
if (port != 'a' or pin not in ["9","10","11","12"]):
150+
raise ValidateException("Only Pins PA9/PA10/PA11/PA12 can be remapped")
151+
152+
reg = 'SYSCFG->CFGR1'
153+
value = {
154+
('f0', '9') : ('SYSCFG_CFGR1_PA11_PA12_RMP', False),
155+
('f0', '10') : ('SYSCFG_CFGR1_PA11_PA12_RMP', False),
156+
('f0', '11') : ('SYSCFG_CFGR1_PA11_PA12_RMP', True),
157+
('f0', '12') : ('SYSCFG_CFGR1_PA11_PA12_RMP', True),
158+
('g0', '9') : ('SYSCFG_CFGR1_PA11_RMP', True),
159+
('g0', '10') : ('SYSCFG_CFGR1_PA12_RMP', True),
160+
('g0', '11') : ('SYSCFG_CFGR1_PA11_RMP', False),
161+
('g0', '12') : ('SYSCFG_CFGR1_PA12_RMP', False)
162+
}
163+
return (reg,) + value[(family, pin)]
164+
126165
bprops = {}
127166

128167
# -----------------------------------------------------------------------------
@@ -257,6 +296,10 @@ def build(env):
257296

258297
for gpio in driver["gpio"]:
259298
po, pi = gpio["port"], gpio["pin"]
299+
properties["remap_pin"] = is_remap_pin(driver, pi, po)
300+
if properties["remap_pin"]:
301+
family = device.identifier["family"]
302+
(properties["remap_reg"],properties["remap_value"],properties["remap_set"]) = get_remap_command(family, pi, po)
260303
properties.update(bprops[po + pi])
261304
header_name = "gpio_{}{}.hpp".format(po.upper(), pi)
262305
env.template(gpio_source, header_name, filters={ "to_adc_channel" : lambda name : "".join(filter(str.isdigit, name)) })

src/modm/platform/gpio/stm32/pin.hpp.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ public:
7474
inline static void setAnalogInput() { PinSet::setAnalogInput(); }
7575
/// @endcond
7676

77+
%% if remap_pin
78+
/// Remap this GPIO onto physical pins with selectable GPIO mappings
79+
inline static void remap() {
80+
%% if remap_set
81+
{{remap_reg}} |= {{remap_value}};
82+
%% else
83+
{{remap_reg}} &= ~{{remap_value}};
84+
%% endif
85+
};
86+
%% endif
87+
7788
public:
7889
// GpioOutput
7990
// start documentation inherited

0 commit comments

Comments
 (0)