-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix AnalogIn implementation on STM32G4 series #13601
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
Conversation
@jeromecoutant Should the Nucleo G474 be using Lines 2441 to 2445 in 356effa
|
@AGlass0fMilk, thank you for your changes. |
@jeromecoutant Also, since the clock speed on this target is so high by default I am seeing small offsets in my ADC readings due to the short accumulation time. Setting the ADC prescaler to divide by 4 and setting the sampling time to 640.5 cycles greatly improves the offset but maybe there's a way to get make it so I'm not maxing out the settings? |
@ARMmbed/team-st-mcd Please review |
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Set back to review, waiting for @jeromecoutant to review |
@jeromecoutant Can you review? this can go in if approved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi
I have tested ci-test-shield, results are OK :-)
But...
- it seems there are too many TODO in comments?
- it works but I couldn't see any __HAL_RCC_ADC12_CLK_ENABLE()) call for ex... Need to check...
- internal channels to check
@@ -153,11 +163,15 @@ uint16_t adc_read(analogin_t *obj) | |||
|
|||
// Configure ADC channel | |||
sConfig.Rank = ADC_REGULAR_RANK_1; | |||
sConfig.SamplingTime = ADC_SAMPLETIME_24CYCLES_5; | |||
sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really need so much time ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If my math is correct, with the PCLK @ 180MHz and the ADC prescaler set to DIV2, a sample time of 24.5 clock cycles is only ~272 nanoseconds... I think this is quite short for most of the slow signals Mbed users will be trying to read with the simple AnalogIn
API.
My comment from before:
Also, since the clock speed on this target is so high by default I am seeing small offsets in my ADC readings due to the short accumulation time.
Setting the ADC prescaler to divide by 4 and setting the sampling time to 640.5 cycles greatly improves the offset but maybe there's a way to get make it so I'm not maxing out the settings?
Perhaps we could increase the ADC prescaler?
The TODOs are mostly for future reference. I'm not sure where (or if) the ADC is deinitialized. We should deinitialize the clock at the same time to save power. Regardless I think this is an improvement over the current target support. |
Are TODO's required there? I would rather keep TODO as an issue rather than in the code. |
Here is my branch: 885aca7 |
Note that |
356effa
to
bbc15f6
Compare
Pull request has been modified.
@jeromecoutant I implemented @0xc0170 I removed the TODOs. |
Co-authored-by: jeromecoutant <[email protected]>
@jeromecoutant I merged your internal ADC channel changes: bbc7355 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe only 2 counters are needed ? adc12 and adc345 ?
@@ -158,6 +204,10 @@ uint16_t adc_read(analogin_t *obj) | |||
sConfig.OffsetNumber = ADC_OFFSET_NONE; | |||
sConfig.Offset = 0; | |||
|
|||
/** | |||
* TODO - what about internal channels? VBAT, VREF, Temperature? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove in the next commit ?
@@ -163,7 +199,7 @@ uint16_t adc_read(analogin_t *obj) | |||
|
|||
// Configure ADC channel | |||
sConfig.Rank = ADC_REGULAR_RANK_1; | |||
sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5; | |||
sConfig.SamplingTime = ADC_SAMPLETIME_24CYCLES_5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should keep 247 cycles value,
some tests are failing with 24 value...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I should increase the ADC clock prescaler?
That was my initial implementation but then I figured having a counter for each ADC would allow us to deinitialize each ADC individually as well. |
@jeromecoutant Please review |
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Summary of changes
This PR reintroduces AnalogIn on the STM32G4 series based targets (eg: NUCLEO_G474RE). It also introduces fixes to the AnalogIn HAL API implementation.
Fixes in this PR include:
@jeromecoutant Please review and possibly update this PR at your discretion... I am not as familiar with how to handle the internal ADC channels (ie: Temperature, VREF, OPAMP, etc). This PR removes all support for internal ADC channels as it stands right now. It seems ADC2 has more inputs than on the F3 series upon which this analog in implementation was based. I tried to use the pin
A2
as an analog input on my NUCLEO G474 and the current analog in implementation routed it to an internal OP amp channel instead of thePA4/A2
.Impact of changes
Migration actions required
Documentation
None
Pull request type
Test results
Reviewers
@jeromecoutant