-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Describe the bug
Zephyr Version: 4.1.0
Platform STM32G0B1RE
Utilizing DMA to handle ADC conversion transfers (peripheral to memory)
Sequence of events: ADC conversions complete->DMA is flagged->DMA transfers succesfully (TCI=1)->Transfer complete interrupt->DMA callback (in adc_stm32.c)
What happens:
the DMA channel is passed into the function and compared to the local adc DMA configuration (data->dma.channel) if the channels match ADC conversion completes normally if the channels do not match the function returns taking no action
The channel ID passed into the DMA callback is off by the zephyr offset (+1) when compared to the local adc DMA config (data->dma.channel) resulting in the ADC never finishing a conversion and the calling thread hanging.
Conditional check currently in drivers (adc_stm32.c 790): if (channel == data->dma.channel) this comparison is incorrectly never true resulting in hanging thread
By changing to: if (channel+1 == data->dma.channel)
ADC conversion completes succesfully and thread resumes normal operation
Regression
- This is a regression.
Steps to reproduce
Setup STM32G0 board to utilize DMA and ADC, perform ADC conversion from thread.
Relevant log output
Bad log output prior to fixing off by 1:
[00:00:01.130,000] <dbg> adc: adc_entry: ADC Task started
[00:00:01.130,000] <dbg> adc: adc_entry: Alias: adc_5v, Channel ID: 10
[00:00:01.130,000] <dbg> adc: adc_entry: Alias: adc_ntc, Channel ID: 8
[00:00:01.130,000] <dbg> adc: adc_entry: Alias: adc_ambient, Channel ID: 9
[00:00:01.130,000] <dbg> adc: adc_entry: Alias: adc_24v, Channel ID: 11
[00:00:01.130,000] <dbg> adc: adc_entry: Alias: adc_current_fb, Channel ID: 0
[00:00:01.130,000] <dbg> adc_stm32: adc_stm32_channel_setup: Channel setup succeeded!
[00:00:01.130,000] <dbg> adc_stm32: adc_stm32_channel_setup: Channel setup succeeded!
[00:00:01.130,000] <dbg> adc_stm32: adc_stm32_channel_setup: Channel setup succeeded!
[00:00:01.130,000] <dbg> adc_stm32: adc_stm32_channel_setup: Channel setup succeeded!
[00:00:01.130,000] <dbg> adc_stm32: adc_stm32_channel_setup: Channel setup succeeded!
[00:00:01.130,000] <dbg> adc: adc_entry: ADC controller device ready: adc@40012400
[00:00:01.130,000] <dbg> adc: adc_entry: ADC task loop start
[00:00:01.131,000] <dbg> dma_stm32: dma_stm32_configure: Channel (0) memory inc (80).
[00:00:01.131,000] <dbg> dma_stm32: dma_stm32_configure: Channel (0) peripheral inc (0).
[00:00:01.131,000] <dbg> adc_stm32: adc_stm32_dma_start: DMA started
[00:00:01.131,000] <dbg> adc_stm32: adc_stm32_start_conversion: Starting conversion
[00:00:01.131,000] <dbg> adc_stm32: dma_callback: dma callback
Corrected log output after fixing off by 1:
[00:00:22.148,000] <dbg> dma_stm32: dma_stm32_configure: Channel (0) memory inc (80).
[00:00:22.148,000] <dbg> dma_stm32: dma_stm32_configure: Channel (0) peripheral inc (0).
[00:00:22.148,000] <dbg> adc_stm32: adc_stm32_dma_start: DMA started
[00:00:22.148,000] <dbg> adc_stm32: adc_stm32_start_conversion: Starting conversion
[00:00:22.148,000] <dbg> adc: adc_entry: ADC sequencing
[00:00:22.148,000] <dbg> adc_stm32: dma_callback: dma callback
[00:00:22.148,000] <dbg> adc: adc_callback: ADC Callback: ADC sampling index 0
[00:00:22.148,000] <dbg> adc: adc_callback: ADC Callback: ADC sampling index complete
[00:00:22.148,000] <dbg> adc: adc_entry: ADC poll event signaled
Impact
Functional Limitation – Some features not working as expected, but system usable.
Environment
OS - Linux (Ubuntu)
Toolchain - Zephyr 4.1.0+0, Zephyr SDK 0.16.
remote: zephyrproject
revision: v4.1.0
Additional Context
No response