Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for STM32 F0/G0 remap pins #471

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ git clone --recurse-submodules https://github.com/modm-io/modm.git
## Targets

modm can generate code for <!--avrcount-->506<!--/avrcount--> AVR,
<!--samcount-->163<!--/samcount--> SAM and <!--stmcount-->1959<!--/stmcount-->
<!--samcount-->163<!--/samcount--> SAM and <!--stmcount-->2010<!--/stmcount-->
STM32 devices, however, there are different levels of support and testing.

<center>
Expand Down
2 changes: 1 addition & 1 deletion ext/modm-devices
Submodule modm-devices updated 122 files
14 changes: 12 additions & 2 deletions ext/st/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ def getDefineForDevice(device_id, familyDefines):
if len(deviceDefines) == 1:
return deviceDefines[0]

# now we match for the size-id.
# sort with respecting variants
minlen = min(len(d) for d in deviceDefines)
deviceDefines.sort(key=lambda d: (d[:minlen], d[minlen:]))

# now we match for the size-id (and variant-id if applicable).
devNameMatch = devName + "x{}".format(device_id.size.upper())
if device_id.family == "l1":
# Map STM32L1xxQC and STM32L1xxZC -> STM32L162QCxA variants
if device_id.pin in ["q", "z"] and device_id.size == "c":
devNameMatch += "A"
else:
devNameMatch += device_id.variant.upper()
for define in deviceDefines:
if devNameMatch <= define:
return define
Expand Down Expand Up @@ -70,7 +80,7 @@ def common_rcc_map(env):
define = None

content = Path(localpath(folder, family_header)).read_text(encoding="utf-8", errors="replace")
match = re.findall(r"if defined\((?P<define>STM32[F|L|G].....)\)", content)
match = re.findall(r"if defined\((?P<define>STM32[F|L|G][\w\d]+)\)", content)
define = getDefineForDevice(device.identifier, match)
if define is None or match is None:
raise ValidateException("No device define found for '{}'!".format(device.partname))
Expand Down
2 changes: 1 addition & 1 deletion ext/st/stm32
Submodule stm32 updated 100 files
2 changes: 1 addition & 1 deletion repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def check_submodules():
" git submodule update --init\n")

# Import modm-device tools
sys.path.append(repopath("ext/modm-devices/tools/device"))
sys.path.append(repopath("ext/modm-devices"))
try:
import modm_devices.parser
except ModuleNotFoundError:
Expand Down
2 changes: 0 additions & 2 deletions src/modm/platform/core/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def post_build(env):
target = env[":target"].identifier
properties["with_crashcatcher"] = env.has_module(":crashcatcher")

if target.family in ["l4"]: # FIXME!
properties["regions"].remove("sram2")
if "backup" in properties["regions"]:
properties["regions"].remove("backup")

Expand Down
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
2 changes: 1 addition & 1 deletion tools/scripts/docs_modm_io_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def repopath(path):
def relpath(path):
return os.path.relpath(path, str(repopath(".")))

sys.path.append(str(repopath("ext/modm-devices/tools/device")))
sys.path.append(str(repopath("ext/modm-devices")))
from modm_devices.device_identifier import *


Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/generate_module_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def relpath(path):
return os.path.relpath(path, str(repopath(".")))

sys.path.append(str(repopath("ext/modm-devices/tools/generator")))
sys.path.append(str(repopath("ext/modm-devices/tools/device")))
sys.path.append(str(repopath("ext/modm-devices")))
from dfg.device_tree import DeviceTree
from modm_devices.device_identifier import *
sys.path.append(str(repopath("../lbuild")))
Expand Down