Skip to content

Conversation

@giansta
Copy link
Contributor

@giansta giansta commented Apr 20, 2021

According to the ST Errata sheet ES0389 - Rev 5, section 2.5.2, the
workaround to the issue of "Wrong ADC result if conversion done late
after calibration or previous conversion" is to perform two consecutive
ADC conversions.
We found also that the same objective is achieved enabling and disabling
it at every read. Moreover, this approach solves another issue found on
several STM32L462VE samples, where the reads were stuck, giving always
the same wrong value, that was 0 or the last calibration value.

Additional clearing of ADRDY flag has been added to avoid finding it
already set before next enabling.

Signed-off-by: Giancarlo Stasi [email protected]

@giansta giansta requested a review from cybertale as a code owner April 20, 2021 16:18
@github-actions github-actions bot added area: ADC Analog-to-Digital Converter (ADC) platform: STM32 ST Micro STM32 labels Apr 20, 2021
@giansta giansta marked this pull request as draft April 21, 2021 09:36
@giansta giansta marked this pull request as ready for review April 21, 2021 09:37
@giansta giansta marked this pull request as draft April 21, 2021 09:42
@giansta giansta marked this pull request as ready for review April 21, 2021 09:43
@giansta
Copy link
Contributor Author

giansta commented Apr 21, 2021

It looks like buildkite had errors on tests that don't seems to be related to this PR changes (e.g. tests/kernel/workq/work/kernel.work.api).
The "convert to draft - put in ready state" trick used in similar past cases doesn't help.

@github-actions
Copy link

Unit Test Results

     10 files    41 suites   12m 16s ⏱️
1 279 tests 394 ✔️ 885 💤 0 ❌

Results for commit 46ab4548.

@erwango
Copy link
Member

erwango commented Apr 26, 2021

I would like other ADC users could review

Copy link
Contributor

@ABOSTM ABOSTM left a comment

Choose a reason for hiding this comment

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

@giansta, thanks for this PullRequest.
LGTM

Copy link
Contributor

@str4t0m str4t0m left a comment

Choose a reason for hiding this comment

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

I am not an extensive adc user, but would like to raise the following two concerns:

  • After this change the ADC has to be enabled twice for a single read on G0 series, because of the errata that the ADC_cfgr1 can't be changed while the ADEN bit is set(needed for LL_ADC_SetResolution in start_read()).
    It would be great if this could be avoided.
  • Am I right that the issue is present for the async api?

Could moving the disabling and enabling of the adc into the start_read() function solve both these problems, or do you see any problem that is introduced with such a move.

@erwango erwango added this to the v2.7.0 milestone May 12, 2021
@giansta
Copy link
Contributor Author

giansta commented May 21, 2021

@str4t0m, thanks for your suggestions. I tried to apply the changes you proposed.

I could test them with some limitations on our L462VE platform, as we're using an older branch without G0 family support, I'll try to test it more when possible. Unfortunately I don't have any G0 family board to test it.

giansta added 2 commits July 16, 2021 21:44
According to the ST Errata sheet ES0389 - Rev 5, section 2.5.2, the
workaround to the issue of "Wrong ADC result if conversion done late
after calibration or previous conversion" is to perform two consecutive
ADC conversions.
We found also that the same objective is achieved enabling and disabling
it at every read. Moreover, this approach solves another issue found on
several STM32L462VE samples, where the reads were stuck, giving always
the same wrong value, that was 0 or the last calibration value.

Additional clearing of ADRDY flag has been added to avoid finding it
already set before next enabling.

Signed-off-by: Giancarlo Stasi <[email protected]>
Apply workaround for both L462xE errata 2.5.2 and G081xB errata 2.6.2,
avoiding to have double enabling for a single read on G0 series.
Make workaround for L462xE valid also for the async api.

Signed-off-by: Giancarlo Stasi <[email protected]>
@giansta giansta force-pushed the fix/adc-stm32-read-stuck branch from 4839cdc to e346a72 Compare July 16, 2021 20:05
@cfriedt cfriedt requested a review from str4t0m July 22, 2021 09:36
@cfriedt
Copy link
Member

cfriedt commented Jul 23, 2021

@giansta - is this one moving forward still?

@cfriedt
Copy link
Member

cfriedt commented Jul 27, 2021

@str4t0m - can you please re-review?

@cfriedt
Copy link
Member

cfriedt commented Jul 29, 2021

@anangl - could you also please review?

@erwango erwango dismissed their stale review July 29, 2021 07:22

Dismiss my review as I missed the second commit. I'm gonna review again

Copy link
Contributor

@str4t0m str4t0m left a comment

Choose a reason for hiding this comment

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

I'm not sure if disabling of the ADC after each read should be configurable, but as applications which continuously sample adc values likely use a custom dma based driver doing it always should be fine. (The time it takes until the ADC is ready is equal to 1-2 conversion cycles on series I am familiar with.)

Assuming the ADC is disabled unconditionally after each read, special handling of stm32g0 in lines 412-425 is no longer needed.
However I'd prefer to add a short note to the driver about the special cases on stm32g0 and stm32l462xe. Otherwise these requirements are likely to be overlooked in future driver changes.

Additionally the ADC should also be in disabled state after adc_stm32_init, otherwise the behavior will differ between the first and subsequent reads.
The same applies to start_read: In case calibration fails you should not return immediately, but also disable the ADC.

While the ADC is disabled unconditionally at the end of start_read it is never enabled for CONFIG_SOC_SERIES_STM32F1X and STM32F3X_ADC_V2_5. Could you please make sure that it is also enabled again on these series.

Could you eventually stash the two commits as the 2nd one reverts many changes of the first.

* still not stabilized, this will wait for a short time to ensure ADC
* modules are properly enabled.
*/
uint32_t countTimeout = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: don't use camel case.

Comment on lines +462 to +467
if (LL_ADC_IsEnabled(adc) == 0) {
err = adc_stm32_enable_and_wait_stabilisation(adc);
if (err) {
return err;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please move this after LL_ADC_SetResolution(), such that no special handling of STM32G0 is necessary.
I don't know of any Series which needs ADC to be enabled to set the resolution so this should be fine.
The HAL includes the following note regarding the LL_ADC_SetResolution macro:

ADC must be disabled or enabled without conversion on going...

@cfriedt
Copy link
Member

cfriedt commented Sep 2, 2021

@giansta , @str4t0m - can we move this forward?

@cfriedt
Copy link
Member

cfriedt commented Sep 20, 2021

@giansta - please address comments from @str4t0m

@nashif nashif modified the milestones: v2.7.0, v2.7.1 Oct 20, 2021
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Dec 20, 2021
@github-actions github-actions bot closed this Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ADC Analog-to-Digital Converter (ADC) platform: STM32 ST Micro STM32 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants