stm32 NUCLEO boards: pin name conflicts
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:
- Remove the Arduino pin names from pins.csv.
- Prepend the Arduino name with something, eg connector name -
CN8_A2 - Require cpu pins to be entered with a P, eg
pyb.Pin('PA2'). - Require cpu pins to be entered with a
cpu.prefix, egpyb.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?
stm32: Add support for analog-only "_C" pins.
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.pypretty clean) - allow a board to reference these pins in the board's
pins.csvfile by the namePA0_Cetc (so a board can alias them, for example) - these pins (when enabled in
pins.csv) now become available like any othermachine.Pinthrough bothmachine.Pin.boardandmachine.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.ADCto construct the appropriate ADC object, either by passing the string asmachine.ADC("PA0_C")or by passing the object asmachine.ADC(machine.Pin.cpu.PA0_C) - if a board defines both the normal and _C pin (eg both PA0 and PA0_C) in
pins.csvthen 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