Skip to content

cpu/gd32v: add periph_adc support #19188

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

Merged
merged 4 commits into from
Feb 2, 2023
Merged

Conversation

gschorcht
Copy link
Contributor

Contribution description

This PR provides the periph_adc support and is one of a bunch of follow up PRs that complete the peripheral drivers for GD32VF103.

This PR depends on PR #19170 and includes this PR to be compilable since includes the ADC configuration also for Sipeed Longan Nano board.

Testing procedure

tests/periph_adc should work on any GD32VF103 board.

Issues/PRs references

Depends on PR #19170

@github-actions github-actions bot added 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 labels Jan 22, 2023
@gschorcht gschorcht 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 Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms labels Jan 22, 2023
@gschorcht gschorcht requested a review from bergzand January 22, 2023 17:46
@riot-ci
Copy link

riot-ci commented Jan 22, 2023

Murdock results

✔️ PASSED

57463cb dist/tools/dockcheck: add ADC config as generic exclude pattern

Success Failures Total Runtime
6807 0 6807 09m:19s

Artifacts

@github-actions github-actions bot removed the Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms label Jan 22, 2023
@gschorcht gschorcht force-pushed the cpu/gd32v/periph_adc branch from 858c53d to 38055cb Compare January 22, 2023 22:38
@benpicco benpicco requested a review from maribu January 23, 2023 01:12
@benpicco
Copy link
Contributor

This needs a rebase

@gschorcht gschorcht force-pushed the cpu/gd32v/periph_adc branch from 38055cb to 15fd668 Compare January 28, 2023 17:28
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.

looks good, please squash directly

/**
* @brief Maximum allowed ADC clock speed
*/
#define MAX_ADC_SPEED (MHZ(14))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#define MAX_ADC_SPEED (MHZ(14))
#define MAX_ADC_SPEED MHZ(14)

Copy link
Contributor Author

@gschorcht gschorcht Jan 29, 2023

Choose a reason for hiding this comment

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

That's just a leftover from code for STM32F1 which was (14000000U).


static inline ADC0_Type *dev(adc_t line)
{
return (ADC0_Type *)(ADC0_BASE + (adc_config[line].dev << 10));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's a bit optimistic if more family members are added, there is no grantee the ADCs will all be continuous in memory.

Suggested change
return (ADC0_Type *)(ADC0_BASE + (adc_config[line].dev << 10));
switch (adc_config[line].dev) {
case 0:
return ADC0_BASE;
#if ADC_DEVS > 1
case 1:
return ADC1_BASE;
#endif
#if ADC_DEVS > 2
case 2:
return ADC2_BASE;
#endif
default:
assert(0);
return NULL;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the way how STM32F1 dealt with it. The question is whether there will ever be more families for which this code could be used. It is more likely that other families will need their own ADC low level drivers like for STM32. At the moment I wouldn't allow the case ADC_DEVS > 2.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is more likely that other families will need their own ADC low level drivers like for STM32

The STM32 families don't all need their own ADC driver, they pretty much all use the same ADC IP. The ADC driver mess on STM32 is due to a lack of cleanup - and that has been always postponed with the new ADC API on the horizon.

Comment on lines 145 to 147
if (dev(line) != ADC0) {
return -3;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (dev(line) != ADC0) {
return -3;
}
assert(dev(line) == ADC0);

since that'd be an error in the board config, let this fail loudly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just the code from STM32F1. Using assert here makes perfect sense, especially since the API does not define -3 as a possible return value. In fact, I had already thought about an assert.

@gschorcht gschorcht force-pushed the cpu/gd32v/periph_adc branch 2 times, most recently from 3fa77ab to 5448969 Compare January 29, 2023 11:01
@benpicco
Copy link
Contributor

bors merge

@gschorcht
Copy link
Contributor Author

Merge failed due tue conflicts with PR #19201. Before I rebase it to resolve the conflicts, I would prefere to merge PR #19214 since it will produce further conflicts.

@gschorcht gschorcht force-pushed the cpu/gd32v/periph_adc branch from 5448969 to e6bf881 Compare February 1, 2023 13:39
@gschorcht gschorcht added the Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms label Feb 1, 2023
@gschorcht gschorcht force-pushed the cpu/gd32v/periph_adc branch from e6bf881 to 31e778b Compare February 1, 2023 18:31
@github-actions github-actions bot removed the Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms label Feb 1, 2023
@gschorcht gschorcht force-pushed the cpu/gd32v/periph_adc branch from 31e778b to 3be68cb Compare February 1, 2023 18:56
@gschorcht
Copy link
Contributor Author

After the failed last run due to the tools/backport_pr, we could try the merge again.

@gschorcht
Copy link
Contributor Author

bors merge

@bors
Copy link
Contributor

bors bot commented Feb 1, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

bors bot added a commit that referenced this pull request Feb 1, 2023
19188: cpu/gd32v: add periph_adc support r=gschorcht a=gschorcht

### Contribution description

This PR provides the `periph_adc` support and is one of a bunch of follow up PRs that complete the peripheral drivers for GD32VF103.

This PR depends on PR #19170 and includes this PR to be compilable since includes the ADC configuration also for Sipeed Longan Nano board.

### Testing procedure

`tests/periph_adc` should work on any GD32VF103 board.

### Issues/PRs references

Depends on PR #19170 

Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@bors
Copy link
Contributor

bors bot commented Feb 1, 2023

Build failed:

@gschorcht gschorcht force-pushed the cpu/gd32v/periph_adc branch from 3be68cb to 57463cb Compare February 1, 2023 22:11
@benpicco
Copy link
Contributor

benpicco commented Feb 2, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Feb 2, 2023

Build succeeded:

@bors bors bot merged commit a9dbf8b into RIOT-OS:master Feb 2, 2023
@gschorcht gschorcht deleted the cpu/gd32v/periph_adc branch February 4, 2023 12:15
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.04 milestone Apr 25, 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 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.

4 participants