Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/efm32: add periph_adc support for Gecko Series 2 #18933

Merged
merged 2 commits into from
Nov 24, 2022

Conversation

jue89
Copy link
Contributor

@jue89 jue89 commented Nov 18, 2022

Contribution description

This is a follow-up of #18780 and adds support for periph_adc

Testing procedure

I added two ADC lines to the xg23-pl6068a board and tested the ADC using tests/periph_adc.

  • ADC_LINE(0) is a single-ended input on PA10. I connected an almost-empty battery to PA10 and GND.
    The battery has a voltage of 147mV. It's multiplied with a gain of 0.5 and compared to the internal bandgap of 1.21V. The test sets a resolution of 10bit.
    Expected result: (147mV * 0.5 / 1,210mV) * (2^10 - 1) = 62.14
    Measured result: 62.
  • ADC_LINE(1) is a differential input between PA5 and PA0. I connected the same battery to these inputs.
    Expected result: The same is true like described for ADC_LINE(0)
    Measured result: 62.

Issues/PRs references

Follow-up of #18780

@jue89 jue89 added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: cpu Area: CPU/MCU ports labels Nov 18, 2022
@github-actions github-actions bot added Area: boards Area: Board ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: tools Area: Supplementary tools Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Nov 18, 2022
@jue89 jue89 requested a review from gschorcht November 18, 2022 16:18
@jue89 jue89 force-pushed the feature/cpu_efm32_series_2_adc branch from 77af3f2 to d759701 Compare November 18, 2022 16:20
@riot-ci
Copy link

riot-ci commented Nov 18, 2022

Murdock results

✔️ PASSED

ab86198 boards/xg23-pk6068a: add ADC lines

Success Failures Total Runtime
117856 0 117858 02h:02m:31s

Artifacts

cpu/efm32/periph/adc_series2.c Outdated Show resolved Hide resolved
cpu/efm32/periph/adc_series2.c Outdated Show resolved Hide resolved

/* wait for the conservation to provide the result in the fifo */
while ((IADC_getStatus(adc_config[dev].dev) & IADC_STATUS_SINGLEFIFODV) == 0);
uint32_t result = IADC_pullSingleFifoData(adc_config[dev].dev);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set a negative input for differential mode, can't the measured voltage be negative?

You'd want a int32_t result then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configs.configs[i].twosComplement = iadcCfgTwosCompUnipolar;

This line makes sure that the result is never negative.

I took this route to be consistent with the adc_sample() interface which uses negative values to indicate errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took this route to be consistent with the adc_sample() interface which uses negative values to indicate errors.

on sam0 I just ignored that interface convention - if there is a wrong config the function should just throw an assert() failure.

adc_sample() just doesn't do this because the test does use this to query supported resolutions, but I think no real-world application will do that.

There should just be a separate interface to check if a resolution is valid (adc_ng does this).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't want to mess around with the defined (and of course very limited) ADC interface.

Otherwise the user can't tell whether something wrong or the ADC just measured -1. Instead, I'd would wait for an ADC interface that's capable of reporting negative values ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does iadcCfgTwosCompUnipolar mean?
Will the application have to deal with this then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a adc_check_res(adc_t line, adc_res_t res) API so that adc_sample() will never need to return error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? There's already an API for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see adc_init(adc_t line) and adc_sample(adc_t line, adc_res_t res) in periph/adc.h

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's an idea for a follow-up? We should have a deeper look into adc_ng - maybe that's a good abstraction to fit this case. Otherwise we have the go through the API change process ...

cpu/efm32/include/periph_cpu.h Show resolved Hide resolved
@jue89 jue89 force-pushed the feature/cpu_efm32_series_2_adc branch from 7f0728e to baed961 Compare November 21, 2022 13:12
@jue89 jue89 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 21, 2022
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash

@jue89 jue89 force-pushed the feature/cpu_efm32_series_2_adc branch from df60c54 to ab86198 Compare November 22, 2022 13:45
@aabadie aabadie removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 23, 2022
@jue89
Copy link
Contributor Author

jue89 commented Nov 23, 2022

Huh? Where's the read for build tag? Is it okay if I re-add it, @aabadie?

@jue89 jue89 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 23, 2022
@jue89 jue89 merged commit a6ff838 into RIOT-OS:master Nov 24, 2022
@jue89 jue89 deleted the feature/cpu_efm32_series_2_adc branch November 24, 2022 10:33
@kaspar030 kaspar030 added this to the Release 2023.01 milestone Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants