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

Add support for multiple channel sampling to STM32 ADC driver #19882

Closed
gmarull opened this issue Oct 17, 2019 · 8 comments
Closed

Add support for multiple channel sampling to STM32 ADC driver #19882

gmarull opened this issue Oct 17, 2019 · 8 comments
Assignees
Labels
Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32
Milestone

Comments

@gmarull
Copy link
Member

gmarull commented Oct 17, 2019

Is your enhancement proposal related to a problem? Please describe.

Multiple channels can't be sampled using a single adc_read call. For example,

const struct adc_sequence seq = {
    .channels = BIT(8) | BIT(9),
    .buffer = buffer,
    .buffer_size = sizeof(buffer),
    .resolution = 12,
};

will result in channel 8 being sampled after calling adc_read(dev, &seq), but not channel 9.

The reason for this behavior is that STM32 ADC driver does not support ADC "scan" mode. Only a single acquisition is configured: https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/adc/adc_stm32.c#L273

Describe the solution you'd like

Be able to have all channels in the sequence sampled with a single adc_read call.

Describe alternatives you've considered

Implement scan mode on the STM32 ADC driver. Note that a DMA is required for such mode, not sure how to make the DMA peripheral to be used configurable, Kconfig option?.

Additional context

N/A

@gmarull gmarull added the Enhancement Changes/Updates/Additions to existing features label Oct 17, 2019
@erwango
Copy link
Member

erwango commented Oct 17, 2019

@cybertale, if you're interested: DMA + ADC ;-)

@erwango erwango added the platform: STM32 ST Micro STM32 label Oct 17, 2019
@Oanerer
Copy link

Oanerer commented Oct 17, 2019

Maybe there is an intermediate version possible, similar to what @anangl suggested to me here: #19652 (comment) ? I also wanted to use the scan functionality of the Gecko ADC for multiple channels, but his suggestion works just as well.

@cybertale
Copy link
Collaborator

@gmarull @erwango This is on the to do list, but has to be done after the DMA driver. Here is some explanation: #17375 (comment)
The main reason is that without DMA, zephyr is not fast enough to handle every EOC interrupt signals, which will end up with overrun errors. By the way, the DMA driver is very close to the end in #19712 .

@cybertale
Copy link
Collaborator

Add support for multi-channels conversion is not hard, but it will raise overrun errors on many STM32 SoCs without DMA.

@cybertale cybertale self-assigned this Oct 17, 2019
@gmarull
Copy link
Member Author

gmarull commented Oct 17, 2019

@cybertale Thanks for the update! I can help with the implementation based on DMA support branch, I'd like to have it for a project I'm working on (F100R8). I have F3XX, F4XX and H7XX boards to perform testing.

@cybertale
Copy link
Collaborator

@gmarull Thanks! drivers of f3 and f4 series SoCs have already been implemented, but I don't have a h7 series board, you can have a look into the driver implemented in #19711 and #19712 to add DMA dts support of h7 and driver implementation if you're interested. 😉 :

@windelbouwman
Copy link

Interesting. At least the adc_read function should return some error code to indicate that this is not implemented.

@erwango erwango assigned ABOSTM and unassigned cybertale Jun 7, 2021
@erwango erwango added this to the v2.7.0 milestone Jun 7, 2021
@cfriedt cfriedt added priority: low Low impact/importance bug and removed priority: low Low impact/importance bug labels Jul 12, 2021
@gmarull
Copy link
Member Author

gmarull commented Sep 2, 2021

Closing, there's a newer issue describing the same request. #32288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32
Projects
None yet
Development

No branches or pull requests

7 participants