summaryrefslogtreecommitdiffstatshomepage
path: root/ports/stm32/boards/make-pins.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-02-27 16:57:18 +1100
committerDamien George <damien@micropython.org>2024-03-08 12:38:00 +1100
commita9efffca96d321a09829bbba4de558f1ca718800 (patch)
tree9054dea7e38c86b9824d19a4e85cd8c18d819eb6 /ports/stm32/boards/make-pins.py
parent7fd8a6d4bced2fcad11b30189e1fba4c32eaafc5 (diff)
downloadmicropython-a9efffca96d321a09829bbba4de558f1ca718800.tar.gz
micropython-a9efffca96d321a09829bbba4de558f1ca718800.zip
stm32: Add support for dual-analog-pad "_C" pins on H7 MCUs.
This commit adds support for the dual-analog-pads on STM32H7 parts. These pads/pins are called PA0_C/PA1_C/PC2_C/PC3_C in the datasheet. They each have an analog switch that can optionally connect them to their normal pin (eg PA0). When the switch is open, the normal and _C pin are independent pins/pads. The approach taken in this commit to make these _C pins available to Python is: - put them in their own, independent row in the stm32h7_af.csv definition file, with only the ADC column defined (they are separate machine.Pin entities, and doing it this way keeps make-pins.py pretty clean) - allow a board to reference these pins in the board's pins.csv file by the name PA0_C etc (so a board can alias them, for example) - these pins (when enabled in pins.csv) now become available like any other machine.Pin through both machine.Pin.board and machine.Pin.cpu - BUT these _C pins have a separate pin type which doesn't have any methods, because they don't have any functionality - these _C pins can be used with machine.ADC to construct the appropriate ADC object, either by passing the string as machine.ADC("PA0_C") or by passing the object as machine.ADC(machine.Pin.cpu.PA0_C) - if a board defines both the normal and _C pin (eg both PA0 and PA0_C) in pins.csv then it must not define the analog switch to be closed (this is a sanity check for the build, because it doesn't make sense to close the switch and have two separate pins) Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/stm32/boards/make-pins.py')
-rwxr-xr-xports/stm32/boards/make-pins.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/ports/stm32/boards/make-pins.py b/ports/stm32/boards/make-pins.py
index bfa22d7974..8fb442153f 100755
--- a/ports/stm32/boards/make-pins.py
+++ b/ports/stm32/boards/make-pins.py
@@ -59,6 +59,12 @@ class Stm32Pin(boardgen.Pin):
def __init__(self, cpu_pin_name):
super().__init__(cpu_pin_name)
+ # Pins ending in "_C" correspond to the analog-only pad of a pair
+ # of dual (analog) pads found on H7 MCUs (eg PA0 and PA0_C pair).
+ self._analog_only = cpu_pin_name.endswith("_C")
+ if self._analog_only:
+ cpu_pin_name = cpu_pin_name[:-2]
+
# P<port><num> (already verified by validate_cpu_pin_name).
self._port = cpu_pin_name[1]
self._pin = int(cpu_pin_name[2:])
@@ -129,11 +135,6 @@ class Stm32Pin(boardgen.Pin):
# be the P for one channel, and the N for a different channel.
# e.g. "ADC123_INP12/ADC123_INN11".
for adc_name in adc.split("/"):
- if adc_name.startswith("C_"):
- # Currently unsupported, H7 dual-pad. The C_ADC entries should
- # only be available directly from machine.ADC (not via the pin
- # object).
- continue
m = re.match("ADC([1-5]+)_(IN[NP]?)([0-9]+)$", adc_name)
if not m:
raise boardgen.PinGeneratorError(
@@ -167,8 +168,9 @@ class Stm32Pin(boardgen.Pin):
)
# PIN(p_port, p_pin, p_af, p_adc_num, p_adc_channel)
- return "PIN({:s}, {:d}, pin_{:s}_af, {:s}, {:d})".format(
- self._port, self._pin, self.name(), adc_units_bitfield, self._adc_channel
+ pin_macro = "PIN_ANALOG" if self._analog_only else "PIN"
+ return "{:s}({:s}, {:d}, pin_{:s}_af, {:s}, {:d})".format(
+ pin_macro, self._port, self._pin, self.name(), adc_units_bitfield, self._adc_channel
)
# This will be called at the start of the output (after the prefix). Use
@@ -210,7 +212,7 @@ class Stm32Pin(boardgen.Pin):
def validate_cpu_pin_name(cpu_pin_name):
boardgen.Pin.validate_cpu_pin_name(cpu_pin_name)
- if not re.match("P[A-K][0-9]+$", cpu_pin_name):
+ if not re.match("P[A-K][0-9]+(_C)?$", cpu_pin_name):
raise boardgen.PinGeneratorError("Invalid cpu pin name '{}'".format(cpu_pin_name))