Repository navigation
arch/arm/stm32: fix invalid device pointer in adc_sampletime_cfg - #20642
Conversation
|
@raiden00pl I am quite confused by the implementation of ADC driver. You probably have the most experience with STM here, do you know why do we keep two structures, private |
|
Hi @michallenc, To provide some context on the bug this PR fixes:
Regarding the two structures: |
2afbb26 to
14c206a
Compare
|
@michallenc as @Swatantra-66 mentioned, the structural mess is from the fact that some ADC functions can be used to implement dedicated drivers with low-level operations. Once I finish unifying the STM32 code, I’ll try to refactor STM32 ADC and split it into proper upper-half and lower-half components, similar to how it’s done for STM32 timers. The data structure naming in many STM32 drivers is poor (like mentioned |
14c206a to
b9f1126
Compare
b9f1126 to
7204c05
Compare
|
please add Assisted-by: indicating the LLM used according to the community rules |
7204c05 to
4a8ebe0
Compare
In adc_sampletime_cfg() for STM32 M0, the generic upper-half ADC device pointer 'dev' (struct adc_dev_s *) was passed directly to adc_sampletime_set() and adc_sampletime_write(). Both functions expect the driver lower-half pointer and cast it to 'struct stm32_dev_s *'. Since the upper-half and lower-half objects are distinct, this resulted in sample-time configuration values and peripheral register base addresses being written to and read from incorrect offsets. This commit updates adc_sampletime_cfg() to pass 'dev->ad_priv' matching the implementation in sibling drivers (stm32_adc_m3m4_v1v2.c and stm32_adc.c). Fixes: apache#19554 Assisted-by: Google Gemini Signed-off-by: Swatantra Yadav <[email protected]>
4a8ebe0 to
b01cac0
Compare
Summary
Fixes #19554.
In
adc_sampletime_cfg()inarch/arm/src/common/stm32/stm32_adc_m0_v1.c, the generic upper-half ADC device pointerdev(struct adc_dev_s *) was passed directly toadc_sampletime_set()andadc_sampletime_write()underCONFIG_STM32_ADC_CHANGE_SAMPLETIME:Both helper functions internally cast the received pointer back to
struct stm32_dev_s *:Because
struct adc_dev_s(upper-half) andstruct stm32_dev_s(lower-half) are distinct structures with different layouts, castingdevresulted in:priv->baseinadc_putreg()reading garbage instead of the peripheral register base address, writing to incorrect memory locations instead of configuring hardware registers.Changes Made
Updated
adc_sampletime_cfg()instm32_adc_m0_v1.cto passdev->ad_priv(which points tostruct stm32_dev_s), matching the implementation in sibling drivers:arch/arm/src/common/stm32/stm32_adc_m3m4_v1v2.c(line 2621)arch/arm/src/stm32f7/stm32_adc.c(line 1591)#elseblock instm32_adc_m0_v1.c(line 1469)Impact
CONFIG_STM32_ADC_CHANGE_SAMPLETIMEis enabled.CONFIG_STM32_STM32F0/CONFIG_STM32_STM32G0).Testing
stm32_adc_m3m4_v1v2.candstm32_adc.c.struct adc_dev_sandstruct stm32_dev_s.