This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch releases/13.1
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/releases/13.1 by this push:
     new 4215db102da arch/arm/stm32: fix invalid device pointer in 
adc_sampletime_cfg
4215db102da is described below

commit 4215db102da8e0efee1185c3cb6f5a610a37c6c2
Author: Swatantra Yadav <[email protected]>
AuthorDate: Tue Oct 13 23:06:46 2026 +0530

    arch/arm/stm32: fix invalid device pointer in adc_sampletime_cfg
    
    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: #19554
    Assisted-by: Google Gemini
    Signed-off-by: Swatantra Yadav <[email protected]>
---
 arch/arm/src/common/stm32/stm32_adc_m0_v1.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/arm/src/common/stm32/stm32_adc_m0_v1.c 
b/arch/arm/src/common/stm32/stm32_adc_m0_v1.c
index 09e199b8dd3..7c6088f31cd 100644
--- a/arch/arm/src/common/stm32/stm32_adc_m0_v1.c
+++ b/arch/arm/src/common/stm32/stm32_adc_m0_v1.c
@@ -685,6 +685,7 @@ static void tim_modifyreg32(struct stm32_dev_s *priv, int 
offset,
                             uint32_t clrbits, uint32_t setbits)
 {
   uint32_t addr = priv->tbase + offset;
+
   putreg32((getreg32(addr) & ~clrbits) | setbits, addr);
 }
 
@@ -1438,7 +1439,8 @@ static void adc_sampletime_cfg(struct adc_dev_s *dev)
    * During sample cycles channel selection bits must remain unchanged.
    */
 #ifdef CONFIG_STM32_ADC_CHANGE_SAMPLETIME
-  struct adc_sample_time_s time_samples = {
+  struct adc_sample_time_s time_samples =
+  {
 #  ifdef STM32_ADC1_SMPR_SMP1
       .smp1    = STM32_ADC1_SMPR_SMP1,
 #  else
@@ -1463,8 +1465,8 @@ static void adc_sampletime_cfg(struct adc_dev_s *dev)
 #  endif
   };
 
-  adc_sampletime_set((struct stm32_adc_dev_s *)dev, &time_samples);
-  adc_sampletime_write((struct stm32_adc_dev_s *)dev);
+  adc_sampletime_set((struct stm32_adc_dev_s *)dev->ad_priv, &time_samples);
+  adc_sampletime_write((struct stm32_adc_dev_s *)dev->ad_priv);
 #else
   struct stm32_dev_s *priv = (struct stm32_dev_s *)dev->ad_priv;
   uint32_t setbits = 0;

Reply via email to