Skip to content

stm32: Add support for analog-only "_C" pins. #13764

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

Merged
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
18 changes: 10 additions & 8 deletions ports/stm32/boards/make-pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
Expand Down Expand Up @@ -129,11 +135,6 @@ def add_adc(self, adc):
# 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(
Expand Down Expand Up @@ -167,8 +168,9 @@ def definition(self):
)

# 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
Expand Down Expand Up @@ -210,7 +212,7 @@ def print_source(self, out_source):
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))


Expand Down
18 changes: 18 additions & 0 deletions ports/stm32/boards/stm32f4xx_prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,21 @@
.adc_num = p_adc_num, \
.adc_channel = p_adc_channel, \
}

#if MICROPY_HW_ENABLE_ANALOG_ONLY_PINS
#define PIN_ANALOG(p_port, p_pin, p_af, p_adc_num, p_adc_channel) \
{ \
{ &pin_analog_type }, \
.name = MP_QSTR_##p_port##p_pin##_C, \
.port = PORT_##p_port, \
.pin = (p_pin), \
.num_af = (sizeof(p_af) / sizeof(pin_af_obj_t)), \
.pin_mask = (1 << ((p_pin) & 0x0f)), \
.gpio = GPIO##p_port, \
.af = p_af, \
.adc_num = p_adc_num, \
.adc_channel = p_adc_channel, \
}
#else
#define PIN_ANALOG DUAL_PAD_SUPPORT_NOT_ENABLED__CONFIGURE__MICROPY_HW_ANALOG_SWITCH_Pxy
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add an #else here that did something like

#define PIN_ANALOG DUAL_PAD_SUPPORT_NOT_ENABLED__CONFIGURE__MICROPY_HW_ANALOG_SWITCH_PAx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

6 changes: 4 additions & 2 deletions ports/stm32/boards/stm32h723_af.csv
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ PortB,PB14, ,TIM1_CH2N ,TIM12_CH1
PortB,PB15,RTC_REFIN ,TIM1_CH3N ,TIM12_CH2 ,TIM8_CH3N ,USART1_RX ,SPI2_M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