mbed-ce / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
88 stars 17 forks source link

Add AnalogIn and AnalogOut APIs support for STM32H5 #314

Closed JohnK1987 closed 3 months ago

JohnK1987 commented 3 months ago

Summary of changes

This PR brings AnalogIn and AnalogOut APIs for STM32H5 family.

Impact of changes

On Nucleo-H503RB there is a conflict between DAC's pins and other equipments (LED and STDIO console). So because of that the AnalogOut was removed for Nucleo-H503RB but not for the MCU it self.

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

AnalogIn and AnalogOut were tested just by a poti and a multimetr.

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[x] Tests / results supplied as part of this PR

multiplemonomials commented 3 months ago

Passing CI shield ADC test:

10: [1722709830.99][CONN][RXD] Based on target.default-adc-vref of 3.30V, the digital IO voltage of this target is 3.30V.
10: [1722709831.00][CONN][RXD] >>> Running case #2: 'Test reading analog values with the ADC'...
10: [1722709831.00][CONN][INF] found KV pair in stream: {{__testcase_start;Test reading analog values with the ADC}}, queued...
10: [1722709831.04][CONN][RXD] PWM duty cycle of 0.0% produced an ADC reading of 0.0% (expected 0.0%)
10: [1722709831.09][CONN][RXD] PWM duty cycle of 10.0% produced an ADC reading of 9.8% (expected 10.0%)
10: [1722709831.14][CONN][RXD] PWM duty cycle of 20.0% produced an ADC reading of 19.7% (expected 20.0%)
10: [1722709831.19][CONN][RXD] PWM duty cycle of 30.0% produced an ADC reading of 29.5% (expected 30.0%)
10: [1722709831.24][CONN][RXD] PWM duty cycle of 40.0% produced an ADC reading of 39.5% (expected 40.0%)
10: [1722709831.29][CONN][RXD] PWM duty cycle of 50.0% produced an ADC reading of 49.5% (expected 50.0%)
10: [1722709831.34][CONN][RXD] PWM duty cycle of 60.0% produced an ADC reading of 59.7% (expected 60.0%)
10: [1722709831.39][CONN][RXD] PWM duty cycle of 70.0% produced an ADC reading of 69.8% (expected 70.0%)
10: [1722709831.44][CONN][RXD] PWM duty cycle of 80.0% produced an ADC reading of 80.2% (expected 80.0%)
10: [1722709831.49][CONN][RXD] PWM duty cycle of 90.0% produced an ADC reading of 90.3% (expected 90.0%)
10: [1722709831.50][CONN][RXD] >>> 'Test reading analog values with the ADC': 1 passed, 0 failed
10: [1722709831.50][CONN][RXD] <greentea test suite>:0::PASS
JohnK1987 commented 3 months ago

Ok, I made few changes to make DAC working also with ADC because a bug was found during CI test (ADC and DAC were work separately but not together). Positive result of DAC test is below. @multiplemonomials can you please repeat the ADC/DAC tests for sure?

Result of test - testshield-dac-to-adc ``` C:\MbedCE\mbed-ce-test-tools\CI-Shield-Tests\mbed-os>ctest -V -R test-testshield-dac-to-adc UpdateCTestConfiguration from :C:/MbedCE/mbed-ce-test-tools/CI-Shield-Tests/mbed-os/DartConfiguration.tcl UpdateCTestConfiguration from :C:/MbedCE/mbed-ce-test-tools/CI-Shield-Tests/mbed-os/DartConfiguration.tcl Test project C:/MbedCE/mbed-ce-test-tools/CI-Shield-Tests/mbed-os Constructing a list of tests Done constructing a list of tests Updating test list for fixtures Added 0 tests to meet fixture requirements Checking test dependency graph... Checking test dependency graph end test 6 Start 6: test-testshield-dac-to-adc 6: Test command: "C:\Program Files\CMake\bin\cmake.exe" "-P" "mbed-run-greentea-test-testshield-dac-to-adc.cmake" 6: Working Directory: C:/MbedCE/mbed-ce-test-tools/CI-Shield-Tests/mbed-os 6: Test timeout computed to be: 10000000 6: [1/1] Flashing test-testshield-dac-to-adc with STM32CubeProg... 6: ------------------------------------------------------------------- 6: STM32CubeProgrammer v2.15.0 6: ------------------------------------------------------------------- 6: 6: ST-LINK SN : 0033002C3232510139353236 6: ST-LINK FW : V3J12M3 6: Board : NUCLEO-H563ZI 6: Voltage : 3.28V 6: Warning: Connection to AP 0 requested and failed, Connection established with AP 1 6: 6: SWD freq : 8000 KHz 6: Connect mode: Under Reset 6: Reset mode : Hardware reset 6: Device ID : 0x484 6: Revision ID : Rev Z 6: Device name : STM32H5xx 6: Flash size : 2 MBytes 6: Device type : MCU 6: Device CPU : Cortex-M33 6: BL Version : 0xE3 6: SFSP Version: v2.2.0 6: Debug in Low Power mode enabled 6: 6: 6: 6: Memory Programming ... 6: Opening and parsing file: test-testshield-dac-to-adc.elf 6: File : test-testshield-dac-to-adc.elf 6: Size : 70.25 KB 6: Address : 0x08000000 6: 6: 6: Erasing memory corresponding to segment 0: 6: Erasing internal memory sectors [0 8] 6: Download in Progress: ██████████████████████████████████████████████████ 100%% 6: 6: File download complete 6: Time elapsed during download operation: 00:00:00.899 6: 6: MCU Reset 6: 6: Software reset is performed 6: Executing: C:/MbedCE/mbed-ce-test-tools/CI-Shield-Tests/mbed-os/venv/Scripts/python.exe -m mbed_host_tests.mbedhtrun --skip-flashing -p COM11 --skip-reset -m NUCLEO_H563ZI --baud-rate=115200 6: [1723406374.54][HTST][INF] host test executor ver. 0.0.16 6: [1723406374.54][HTST][INF] copy image onto target... SKIPPED! 6: [1723406374.54][HTST][INF] starting host test process... 6: [1723406375.29][CONN][INF] starting connection process... 6: [1723406375.29][CONN][INF] notify event queue about extra 60 sec timeout for serial port pooling 6: [1723406375.29][CONN][INF] initializing serial port listener... 6: [1723406375.29][SERI][INF] using specified port 'COM11' 6: [1723406375.29][HTST][INF] setting timeout to: 60 sec 6: [1723406375.29][SERI][INF] serial(port=COM11, baudrate=115200, read_timeout=0.01, write_timeout=5) 6: [1723406375.30][SERI][TXD] mbedmbedmbedmbedmbedmbedmbedmbedmbedmbed 6: [1723406375.30][CONN][INF] sending up to 2 __sync packets (specified with --sync=2) 6: [1723406375.30][CONN][INF] sending preamble '294e0cd3-dc95-45f8-87c3-263d79cacf8a' 6: [1723406375.30][SERI][TXD] {{__sync;294e0cd3-dc95-45f8-87c3-263d79cacf8a}} 6: [1723406375.31][CONN][RXD] mbedmbedmbedmbedmbedmbedmbedmbed 6: [1723406375.32][CONN][INF] found SYNC in stream: {{__sync;294e0cd3-dc95-45f8-87c3-263d79cacf8a}} it is #0 sent, queued... 6: [1723406375.32][CONN][INF] found KV pair in stream: {{__version;1.3.0}}, queued... 6: [1723406375.32][HTST][INF] sync KV found, uuid=294e0cd3-dc95-45f8-87c3-263d79cacf8a, timestamp=1723406375.320641 6: [1723406375.32][HTST][INF] DUT greentea-client version: 1.3.0 6: [1723406375.32][CONN][INF] found KV pair in stream: {{__timeout;30}}, queued... 6: [1723406375.32][HTST][INF] setting timeout to: 30 sec 6: [1723406375.32][CONN][INF] found KV pair in stream: {{__host_test_name;default_auto}}, queued... 6: [1723406375.32][HTST][INF] host test class: '' 6: [1723406375.32][HTST][INF] host test setup() call... 6: [1723406375.32][HTST][INF] CALLBACKs updated 6: [1723406375.32][HTST][INF] host test detected: default_auto 6: [1723406375.33][CONN][RXD] >>> Running 1 test cases... 6: [1723406375.33][CONN][RXD] 6: [1723406375.33][CONN][RXD] >>> Running case #1: 'DAC to ADC'... 6: [1723406375.33][CONN][INF] found KV pair in stream: {{__testcase_name;DAC to ADC}}, queued... 6: [1723406375.33][CONN][INF] found KV pair in stream: {{__testcase_start;DAC to ADC}}, queued... 6: [1723406375.36][CONN][RXD] DAC output of 0.0% produced an ADC reading of 0.5% 6: [1723406375.42][CONN][RXD] DAC output of 10.0% produced an ADC reading of 9.9% 6: [1723406375.47][CONN][RXD] DAC output of 20.0% produced an ADC reading of 20.0% 6: [1723406375.52][CONN][RXD] DAC output of 30.0% produced an ADC reading of 29.9% 6: [1723406375.56][CONN][RXD] DAC output of 40.0% produced an ADC reading of 39.9% 6: [1723406375.62][CONN][RXD] DAC output of 50.0% produced an ADC reading of 49.7% 6: [1723406375.67][CONN][RXD] DAC output of 60.0% produced an ADC reading of 59.7% 6: [1723406375.72][CONN][RXD] DAC output of 70.0% produced an ADC reading of 69.9% 6: [1723406375.76][CONN][RXD] DAC output of 80.0% produced an ADC reading of 80.1% 6: [1723406375.82][CONN][RXD] DAC output of 90.0% produced an ADC reading of 90.0% 6: [1723406375.87][CONN][RXD] DAC output of 100.0% produced an ADC reading of 98.7% 6: [1723406375.87][CONN][INF] found KV pair in stream: {{__testcase_finish;DAC to ADC;1;0}}, queued... 6: [1723406375.88][CONN][RXD] >>> 'DAC to ADC': 1 passed, 0 failed 6: [1723406375.88][CONN][RXD] :0::PASS 6: [1723406375.88][CONN][RXD] 6: [1723406375.88][CONN][RXD] >>> Test cases: 1 passed, 0 failed 6: [1723406375.88][CONN][RXD] 6: [1723406375.88][CONN][RXD] ----------------------- 6: [1723406375.89][CONN][RXD] 0 Tests 0 Failures 0 Ignored 6: [1723406375.89][CONN][RXD] OK 6: [1723406375.89][CONN][INF] found KV pair in stream: {{__testcase_summary;1;0}}, queued... 6: [1723406375.89][CONN][INF] found KV pair in stream: {{end;success}}, queued... 6: [1723406375.89][CONN][INF] found KV pair in stream: {{__exit;0}}, queued... 6: [1723406375.89][HTST][INF] __exit(0) 6: [1723406375.89][HTST][INF] __notify_complete(True) 6: [1723406375.89][HTST][INF] __exit_event_queue received 6: [1723406375.89][HTST][INF] test suite run finished after 0.57 sec... 6: [1723406375.90][CONN][INF] received special event '__host_test_finished' value='True', finishing 6: [1723406375.95][HTST][INF] CONN exited with code: 0 6: [1723406375.95][HTST][INF] Some events in queue 6: [1723406375.95][HTST][INF] stopped consuming events 6: [1723406375.95][HTST][INF] host test result() call skipped, received: True 6: [1723406375.95][HTST][INF] calling blocking teardown() 6: [1723406375.95][HTST][INF] teardown() finished 6: [1723406375.95][HTST][INF] {{result;success}} 1/1 Test #6: test-testshield-dac-to-adc ....... Passed 4.73 sec The following tests passed: test-testshield-dac-to-adc 100% tests passed, 0 tests failed out of 1 Total Test time (real) = 4.73 sec ```
multiplemonomials commented 3 months ago

PWM to ADC and DAC to ADC tests are now passing!