Skip to content

stm32/adc: Add STM32H5 support.#12119

Closed
renestraub wants to merge 3 commits intomicropython:masterfrom
renestraub:master
Closed

stm32/adc: Add STM32H5 support.#12119
renestraub wants to merge 3 commits intomicropython:masterfrom
renestraub:master

Conversation

@renestraub
Copy link
Copy Markdown
Contributor

@renestraub renestraub commented Jul 29, 2023

Description

Add STM32H5 ADC support to pyb.ADC by correcting existing code.

Changes are:

  • Run ADC on PCLK/16
  • Use STM32 ADC library channel literals (__HAL_ADC_DECIMAL_NB_TO_CHANNEL)
  • Use correct temperature conversion for H5 (30°C, 130°C calibration points)
  • Add support for ADC2 input channels
  • Optimize sample time for external inputs

Thanks to @yn386 for discussions.

Environment

  • NUCLEO-H563ZI
  • Using STM32H573I-DK board with minor modifications (input clock, on-chip flash)
  • First ADC Input (PF12) connected externally to GPIO PF14
MicroPython v1.20.0-283-g7d66ae603-dirty on 2023-07-29; STM32H573I-DK with STM32H573IIK3Q

Tests

from pyb import Pin, ADC, ADCAll

io = Pin('F14', Pin.OUT_PP)
io.high()

adc=ADC(Pin('F12'))
adc.read()
# Result: 4095 -> Ok, 3.30 V

io.low()
adc.read()
# Result: 4 --> Ok, ~2 mV
adc.read()
# Result: 2 --> Ok, ~1 mV

# Pin F13 is only available on ADC2, for test connect ADC Input PF13 to GPIO PF14
adc2=ADC(Pin('F13'))
print(adc2)
<ADC2 on Pin(Pin.cpu.F13, mode=Pin.ANALOG) channel=2>

io.high()
adc2.read()
# Result: 4087 --> Ok
io.low()
adc2.read()
# Result: 2 --> Ok


all=ADCAll(12,0x70000)
all.read_core_temp()
# Result: 28.2205 -> Ok 

all.read_core_vref()
# Result: 1.207985 -> Ok, nominal 1.21 V

Fixed the preliminary STM32H5 ADC support for pyb.ADC.

Signed-off-by: Rene Straub <rene@see5.ch>
Select ADC instance based on pin information to support ADC2 inputs.
Display ADC instance number similar to machine_adc (STM32H5 only).
<ADC2 on Pin(Pin.cpu.F14, mode=Pin.ANALOG) channel=6>

Signed-off-by: Rene Straub <rene@see5.ch>
Signed-off-by: Rene Straub <rene@see5.ch>
@renestraub
Copy link
Copy Markdown
Contributor Author

@yn386 I enhanced the PR to support ADC2 channels on STM32H5 in pyb.adc. Would you mind to have a look at the changes? Together with my other PR ADC support should be complete for the H5.

@dpgeorge
Copy link
Copy Markdown
Member

Thank you for these fixes. I have tested them and they work.

Merged in 13cc280 through 64d24fc

@dpgeorge dpgeorge closed this Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants