STM32H7: PA0 and PA1 ADC returning incorrect values
Hello community,
I have a custom stm32H7 board running v1.17 of micropython.
I have noticed that PA0 and PA1 return incorrect ADC values:
from machine import ADC, Pin
adc = ADC(Pin.cpu.A0)
adc.read_u16()
The return value is 5763 (we are expecting ~61722 with a 3.3Vref) the first time "adc.read_u16()" is called. Calling "adc.read_u16()" will then consistently return ~800 after the first call. PA3 and PA4 are working as expected. Are these two pins reserved for a specific function?
stmhal: ADC class only uses ADC1 hardware
This issue appears not to be very minor for the pyboard or any board using 64- or 100-pin versions of the STM32F405, so it could be low-priority or 'won't fix'. However, I encountered this running MicroPython on an Olimex STM32-E407 dev board, which uses a 144-pin STM32F407. On this board, much of the GPIO from ports A, B, and C are connected to / utilized by on-board peripherals (like an Ethernet PHY). Most of the ADC input pins that are broken out to headers are on Port F, but those ADC pins are only connected internally to ADC3, so not accessible via the current ADC class:
>>> pf6 = pyb.ADC('PF6')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: pin F6 does not have ADC capabilities
>>>
Since I am already customizing the firmware a bit to get it running on the Olimex board, I think that I can solve my immediate problem by hacking a few lines in adc.c to use ADC3 instead of ADC1. I don't have a more generic solution yet, so I just wanted to raise the issue before I forgot about it.
The biggest potential benefit that I could see in enabling the ADC2 and ADC3 hardware for lower pin-count chips would be to enable high-speed interleaved ADC reads on those pins connected to all three instances, but it would take some serious recoding to allow this, for an application that may see relatively little use.