From 410e55d912e2b79037ae839b8c34f767c8f457b2 Mon Sep 17 00:00:00 2001 From: Joshua DeWeese Date: Fri, 10 May 2024 21:40:47 -0400 Subject: [PATCH] cpu/{gd32v,stm32}/periph/adc: ensure max ADC speed is honored This patch ensures that the ADC's max clock speed is not exceded. --- cpu/gd32v/periph/adc.c | 2 ++ cpu/stm32/periph/adc_f1.c | 2 ++ cpu/stm32/periph/adc_f2.c | 2 ++ cpu/stm32/periph/adc_f4_f7.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/cpu/gd32v/periph/adc.c b/cpu/gd32v/periph/adc.c index a1868bf72f..88b15a1c32 100644 --- a/cpu/gd32v/periph/adc.c +++ b/cpu/gd32v/periph/adc.c @@ -22,6 +22,7 @@ * @} */ +#include "compiler_hints.h" #include "cpu.h" #include "macros/units.h" #include "mutex.h" @@ -128,6 +129,7 @@ int adc_init(adc_t line) break; } } + assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX); RCU->CFG0 &= ~(RCU_CFG0_ADCPSC_2_Msk); RCU->CFG0 |= ((clk_div / 2) - 1) << RCU_CFG0_ADCPSC_2_Pos; diff --git a/cpu/stm32/periph/adc_f1.c b/cpu/stm32/periph/adc_f1.c index 5753eeda90..4382f72aee 100644 --- a/cpu/stm32/periph/adc_f1.c +++ b/cpu/stm32/periph/adc_f1.c @@ -20,6 +20,7 @@ * @} */ +#include "compiler_hints.h" #include "cpu.h" #include "mutex.h" #include "periph/adc.h" @@ -99,6 +100,7 @@ int adc_init(adc_t line) break; } } + assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX); RCC->CFGR &= ~(RCC_CFGR_ADCPRE); RCC->CFGR |= ((clk_div / 2) - 1) << 14; diff --git a/cpu/stm32/periph/adc_f2.c b/cpu/stm32/periph/adc_f2.c index dd8b6b1f5c..48a7bb1b6e 100644 --- a/cpu/stm32/periph/adc_f2.c +++ b/cpu/stm32/periph/adc_f2.c @@ -20,6 +20,7 @@ * @} */ +#include "compiler_hints.h" #include "cpu.h" #include "mutex.h" #include "periph/adc.h" @@ -92,6 +93,7 @@ int adc_init(adc_t line) break; } } + assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX); ADC->CCR = ((clk_div / 2) - 1) << 16; /* enable the ADC module */ diff --git a/cpu/stm32/periph/adc_f4_f7.c b/cpu/stm32/periph/adc_f4_f7.c index ef707b3b47..e946c1e2a7 100644 --- a/cpu/stm32/periph/adc_f4_f7.c +++ b/cpu/stm32/periph/adc_f4_f7.c @@ -19,6 +19,7 @@ * @} */ +#include "compiler_hints.h" #include "cpu.h" #include "irq.h" #include "mutex.h" @@ -101,6 +102,7 @@ int adc_init(adc_t line) break; } } + assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX); ADC->CCR = ((clk_div / 2) - 1) << 16; /* set sampling time to the maximum */ unsigned irq_state = irq_disable();