← index #4814PR #13764
Off-topic · high · value 3.801
QUERY · ISSUE

stm32 NUCLEO boards: pin name conflicts

openby chrismas9opened 2019-05-26updated 2019-05-29
port-stm32

On pyboard:
>>> import pyb
>>> pin = pyb.Pin('A2')
>>> pin
Pin(Pin.cpu.A2, mode=Pin.ALT, pull=Pin.PULL_UP, af=Pin.AF7_USART2)

On many NUCLEO boards:
>>> import pyb
>>> pin = pyb.Pin('A2')
>>> pin
Pin(Pin.cpu.A4, mode=Pin.ANALOG)

On NUCLEO boards (eg NUCLEO_F091RC or L476RG) 'A2' maps to cpu pin A4.

This is because pins.csv has a board pin entry 'A2' for the Arduino analog pin name. Quite a few of the Arduino pin names are the same as the STM32 port names.

I can think of 4 solutions:

  1. Remove the Arduino pin names from pins.csv.
  2. Prepend the Arduino name with something, eg connector name - CN8_A2
  3. Require cpu pins to be entered with a P, eg pyb.Pin('PA2').
  4. Require cpu pins to be entered with a cpu. prefix, eg pyb.Pin('cpu.A2').

Options 3 & 4 are most likely to break existing code, although this could be avoided by mapping the short names in the csv file, eg A2,PA2 or A2,cpu.A2, for non NUCLEO ports.

Option 3 may not work for all MCUs as some MCUs don't have a P, just A2, etc.

I am currently using option 2, ie make board pin names unique.

Any suggestions on the best fix?

CANDIDATE · PULL REQUEST

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

mergedby dpgeorgeopened 2024-02-27updated 2024-03-08
port-stm32

This PR adds support for the analog-only pads/pins 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 PR 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 (this seems logical to me, since they are going to be 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)

To show how this works, the ARDUINO_PORTENTA_H7 board is updated to define its analog pins, using these new _C pins. The code is also tested on this board to work correctly.

TODO:

  • update all relevant af.csv files with separate _C rows

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied