From e6bf33ea055ada265522a1043c021a592b3da41f Mon Sep 17 00:00:00 2001 From: crasbe Date: Fri, 8 Nov 2024 21:23:10 +0100 Subject: [PATCH 1/2] cpu/stm32: make ADC resolution uniform --- cpu/stm32/include/periph/c0/periph_cpu.h | 15 +++++++++++++++ cpu/stm32/include/periph/f0/periph_cpu.h | 12 ++++++------ cpu/stm32/include/periph/f2/periph_cpu.h | 12 ++++++------ cpu/stm32/include/periph/f3/periph_cpu.h | 12 ++++++------ cpu/stm32/include/periph/f4/periph_cpu.h | 14 +++++++------- cpu/stm32/include/periph/f7/periph_cpu.h | 14 +++++++------- cpu/stm32/include/periph/g0/periph_cpu.h | 15 +++++++++++++++ cpu/stm32/include/periph/l0/periph_cpu.h | 12 ++++++------ cpu/stm32/include/periph/l1/periph_cpu.h | 12 ++++++------ cpu/stm32/include/periph/l4/periph_cpu.h | 12 ++++++------ cpu/stm32/include/periph/wb/periph_cpu.h | 12 ++++++------ cpu/stm32/include/periph/wl/periph_cpu.h | 12 ++++++------ cpu/stm32/periph/adc_f0_g0_c0.c | 2 +- cpu/stm32/periph/adc_f2.c | 2 +- cpu/stm32/periph/adc_f3.c | 2 +- cpu/stm32/periph/adc_f4_f7.c | 2 +- cpu/stm32/periph/adc_l0.c | 5 +---- cpu/stm32/periph/adc_l1.c | 5 +---- cpu/stm32/periph/adc_l4_wb.c | 2 +- cpu/stm32/periph/adc_wl.c | 2 +- 20 files changed, 100 insertions(+), 76 deletions(-) diff --git a/cpu/stm32/include/periph/c0/periph_cpu.h b/cpu/stm32/include/periph/c0/periph_cpu.h index 81408b034902..ab6e7cf69b04 100644 --- a/cpu/stm32/include/periph/c0/periph_cpu.h +++ b/cpu/stm32/include/periph/c0/periph_cpu.h @@ -31,6 +31,21 @@ extern "C" { */ #define STM32_BOOTLOADER_ADDR (0x1FFF0000) +/** + * @brief Override ADC resolution values + * @{ + */ +#define HAVE_ADC_RES_T +typedef enum { + ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ +} adc_res_t; +/** @} */ + /** * @name Constants for internal VBAT ADC line * @{ diff --git a/cpu/stm32/include/periph/f0/periph_cpu.h b/cpu/stm32/include/periph/f0/periph_cpu.h index f8202c1798a8..9323084b3adf 100644 --- a/cpu/stm32/include/periph/f0/periph_cpu.h +++ b/cpu/stm32/include/periph/f0/periph_cpu.h @@ -53,12 +53,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = (0x3 << 3), /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = (0x2 << 3), /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = (0x1 << 3), /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = (0x0 << 3), /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = (0xfe), /**< not applicable */ - ADC_RES_16BIT = (0xff) /**< not applicable */ + ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ } adc_res_t; /** @} */ diff --git a/cpu/stm32/include/periph/f2/periph_cpu.h b/cpu/stm32/include/periph/f2/periph_cpu.h index f16d4f5f3571..a43eebeb9628 100644 --- a/cpu/stm32/include/periph/f2/periph_cpu.h +++ b/cpu/stm32/include/periph/f2/periph_cpu.h @@ -54,12 +54,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */ - ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/ + ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/ } adc_res_t; /** @} */ diff --git a/cpu/stm32/include/periph/f3/periph_cpu.h b/cpu/stm32/include/periph/f3/periph_cpu.h index 01ccf69573e0..03afd1fa4b8f 100644 --- a/cpu/stm32/include/periph/f3/periph_cpu.h +++ b/cpu/stm32/include/periph/f3/periph_cpu.h @@ -61,12 +61,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = (0x1), /**< not applicable */ - ADC_RES_16BIT = (0x2) /**< not applicable */ + ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ } adc_res_t; /** @} */ diff --git a/cpu/stm32/include/periph/f4/periph_cpu.h b/cpu/stm32/include/periph/f4/periph_cpu.h index 231e2461619b..d57130610e68 100644 --- a/cpu/stm32/include/periph/f4/periph_cpu.h +++ b/cpu/stm32/include/periph/f4/periph_cpu.h @@ -56,17 +56,17 @@ extern "C" { #define GET_RDP(x) ((x & 0xFF00) >> 8) /** - * @brief Override the ADC resolution configuration + * @brief Override ADC resolution values * @{ */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */ - ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/ + ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ } adc_res_t; /** @} */ diff --git a/cpu/stm32/include/periph/f7/periph_cpu.h b/cpu/stm32/include/periph/f7/periph_cpu.h index 1e3ea495b6fc..043a3906ad05 100644 --- a/cpu/stm32/include/periph/f7/periph_cpu.h +++ b/cpu/stm32/include/periph/f7/periph_cpu.h @@ -44,17 +44,17 @@ extern "C" { #define ADC_DEVS (3U) /** - * @brief Override the ADC resolution configuration + * @brief Override ADC resolution values * @{ */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */ - ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/ + ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ } adc_res_t; /** @} */ diff --git a/cpu/stm32/include/periph/g0/periph_cpu.h b/cpu/stm32/include/periph/g0/periph_cpu.h index c325e36f9028..ce04edd5c4f8 100644 --- a/cpu/stm32/include/periph/g0/periph_cpu.h +++ b/cpu/stm32/include/periph/g0/periph_cpu.h @@ -32,6 +32,21 @@ extern "C" { */ #define STM32_BOOTLOADER_ADDR (0x1FFF0000) +/** + * @brief Override ADC resolution values + * @{ + */ +#define HAVE_ADC_RES_T +typedef enum { + ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ +} adc_res_t; +/** @} */ + /** * @name Constants for internal VBAT ADC line * @{ diff --git a/cpu/stm32/include/periph/l0/periph_cpu.h b/cpu/stm32/include/periph/l0/periph_cpu.h index 09024937dade..8dd8510cbfb0 100644 --- a/cpu/stm32/include/periph/l0/periph_cpu.h +++ b/cpu/stm32/include/periph/l0/periph_cpu.h @@ -40,12 +40,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = (0x3 << 3), /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = (0x2 << 3), /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = (0x1 << 3), /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = (0x0 << 3), /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = (0xfe), /**< not applicable */ - ADC_RES_16BIT = (0xff) /**< not applicable */ + ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported)*/ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/ } adc_res_t; /** @} */ #endif /* ndef DOXYGEN */ diff --git a/cpu/stm32/include/periph/l1/periph_cpu.h b/cpu/stm32/include/periph/l1/periph_cpu.h index b5155300fea1..3893860340c9 100644 --- a/cpu/stm32/include/periph/l1/periph_cpu.h +++ b/cpu/stm32/include/periph/l1/periph_cpu.h @@ -45,12 +45,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = (ADC_CR1_RES_0 | ADC_CR1_RES_1), /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = (0xfe), /**< not applicable */ - ADC_RES_16BIT = (0xff) /**< not applicable */ + ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported)*/ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/ } adc_res_t; /** @} */ #endif /* ndef DOXYGEN */ diff --git a/cpu/stm32/include/periph/l4/periph_cpu.h b/cpu/stm32/include/periph/l4/periph_cpu.h index 692e12d1c849..768952f283f5 100644 --- a/cpu/stm32/include/periph/l4/periph_cpu.h +++ b/cpu/stm32/include/periph/l4/periph_cpu.h @@ -61,12 +61,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = (0x1), /**< not applicable */ - ADC_RES_16BIT = (0x2) /**< not applicable */ + ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ } adc_res_t; /** @} */ diff --git a/cpu/stm32/include/periph/wb/periph_cpu.h b/cpu/stm32/include/periph/wb/periph_cpu.h index ab9194e15d18..636262b9f397 100644 --- a/cpu/stm32/include/periph/wb/periph_cpu.h +++ b/cpu/stm32/include/periph/wb/periph_cpu.h @@ -58,12 +58,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = (0x1), /**< not applicable */ - ADC_RES_16BIT = (0x2) /**< not applicable */ + ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ } adc_res_t; /** @} */ diff --git a/cpu/stm32/include/periph/wl/periph_cpu.h b/cpu/stm32/include/periph/wl/periph_cpu.h index 8edf765fbbec..646bbc1f09b2 100644 --- a/cpu/stm32/include/periph/wl/periph_cpu.h +++ b/cpu/stm32/include/periph/wl/periph_cpu.h @@ -42,12 +42,12 @@ extern "C" { */ #define HAVE_ADC_RES_T typedef enum { - ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */ - ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = (0x1), /**< not applicable */ - ADC_RES_16BIT = (0x2) /**< not applicable */ + ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */ + ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */ + ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */ + ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */ } adc_res_t; /** @} */ diff --git a/cpu/stm32/periph/adc_f0_g0_c0.c b/cpu/stm32/periph/adc_f0_g0_c0.c index 89e6c19c134f..53b29e1bf103 100644 --- a/cpu/stm32/periph/adc_f0_g0_c0.c +++ b/cpu/stm32/periph/adc_f0_g0_c0.c @@ -101,7 +101,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if (res > 0xf0) { + if ((res & ADC_CFGR_RES_Msk) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_f2.c b/cpu/stm32/periph/adc_f2.c index 48a7bb1b6e52..c66a9ad1e5ea 100644 --- a/cpu/stm32/periph/adc_f2.c +++ b/cpu/stm32/periph/adc_f2.c @@ -109,7 +109,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if (res < 0xff) { + if ((res & ADC_CR1_RES_Msk) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_f3.c b/cpu/stm32/periph/adc_f3.c index dc022524ba3e..9460cf3e6a49 100644 --- a/cpu/stm32/periph/adc_f3.c +++ b/cpu/stm32/periph/adc_f3.c @@ -194,7 +194,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* Check if resolution is applicable */ - if (res & 0x3) { + if ((res & ADC_CFGR_RES_Msk) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_f4_f7.c b/cpu/stm32/periph/adc_f4_f7.c index e946c1e2a760..cb83f95adac3 100644 --- a/cpu/stm32/periph/adc_f4_f7.c +++ b/cpu/stm32/periph/adc_f4_f7.c @@ -129,7 +129,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if (res & 0xff) { + if ((res & ADC_CR1_RES_Msk) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_l0.c b/cpu/stm32/periph/adc_l0.c index e56d953f8774..4b675c7b42c8 100644 --- a/cpu/stm32/periph/adc_l0.c +++ b/cpu/stm32/periph/adc_l0.c @@ -118,10 +118,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ( (res != ADC_RES_6BIT) && - (res != ADC_RES_8BIT) && - (res != ADC_RES_10BIT) && - (res != ADC_RES_12BIT)) { + if ((res & ADC_CFGR1_RES_Msk) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_l1.c b/cpu/stm32/periph/adc_l1.c index d7c97003c4d8..8753e2e0dbe9 100644 --- a/cpu/stm32/periph/adc_l1.c +++ b/cpu/stm32/periph/adc_l1.c @@ -147,10 +147,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ( (res != ADC_RES_6BIT) && - (res != ADC_RES_8BIT) && - (res != ADC_RES_10BIT) && - (res != ADC_RES_12BIT)) { + if ((res & ADC_CR1_RES_Msk) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_l4_wb.c b/cpu/stm32/periph/adc_l4_wb.c index 03b2746873e3..26e16b2075eb 100644 --- a/cpu/stm32/periph/adc_l4_wb.c +++ b/cpu/stm32/periph/adc_l4_wb.c @@ -218,7 +218,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if (res & 0x3) { + if ((res & ADC_CFGR_RES_Msk) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_wl.c b/cpu/stm32/periph/adc_wl.c index 7a895d613e21..5f162cd16c82 100644 --- a/cpu/stm32/periph/adc_wl.c +++ b/cpu/stm32/periph/adc_wl.c @@ -119,7 +119,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if (res & 0x3) { + if ((res & ADC_CFGR_RES_Msk) != res) { return -1; } From 62d0e08218bc6c0884d41b13a87836e487047fb5 Mon Sep 17 00:00:00 2001 From: crasbe Date: Wed, 11 Dec 2024 15:58:59 +0100 Subject: [PATCH 2/2] fixup! cpu/stm32: make ADC resolution uniform --- cpu/stm32/periph/adc_f0_g0_c0.c | 2 +- cpu/stm32/periph/adc_f2.c | 2 +- cpu/stm32/periph/adc_f3.c | 2 +- cpu/stm32/periph/adc_f4_f7.c | 2 +- cpu/stm32/periph/adc_l0.c | 2 +- cpu/stm32/periph/adc_l1.c | 2 +- cpu/stm32/periph/adc_l4_wb.c | 2 +- cpu/stm32/periph/adc_wl.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cpu/stm32/periph/adc_f0_g0_c0.c b/cpu/stm32/periph/adc_f0_g0_c0.c index 53b29e1bf103..6d8297dab438 100644 --- a/cpu/stm32/periph/adc_f0_g0_c0.c +++ b/cpu/stm32/periph/adc_f0_g0_c0.c @@ -101,7 +101,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ((res & ADC_CFGR_RES_Msk) != res) { + if ((res & ADC_CFGR_RES) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_f2.c b/cpu/stm32/periph/adc_f2.c index c66a9ad1e5ea..49f030f30be5 100644 --- a/cpu/stm32/periph/adc_f2.c +++ b/cpu/stm32/periph/adc_f2.c @@ -109,7 +109,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ((res & ADC_CR1_RES_Msk) != res) { + if ((res & ADC_CR1_RES) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_f3.c b/cpu/stm32/periph/adc_f3.c index 9460cf3e6a49..7a9818ae17eb 100644 --- a/cpu/stm32/periph/adc_f3.c +++ b/cpu/stm32/periph/adc_f3.c @@ -194,7 +194,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* Check if resolution is applicable */ - if ((res & ADC_CFGR_RES_Msk) != res) { + if ((res & ADC_CFGR_RES) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_f4_f7.c b/cpu/stm32/periph/adc_f4_f7.c index cb83f95adac3..947bd0f6f772 100644 --- a/cpu/stm32/periph/adc_f4_f7.c +++ b/cpu/stm32/periph/adc_f4_f7.c @@ -129,7 +129,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ((res & ADC_CR1_RES_Msk) != res) { + if ((res & ADC_CR1_RES) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_l0.c b/cpu/stm32/periph/adc_l0.c index 4b675c7b42c8..087e5e3ce9e1 100644 --- a/cpu/stm32/periph/adc_l0.c +++ b/cpu/stm32/periph/adc_l0.c @@ -118,7 +118,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ((res & ADC_CFGR1_RES_Msk) != res) { + if ((res & ADC_CFGR1_RES) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_l1.c b/cpu/stm32/periph/adc_l1.c index 8753e2e0dbe9..9519714159c6 100644 --- a/cpu/stm32/periph/adc_l1.c +++ b/cpu/stm32/periph/adc_l1.c @@ -147,7 +147,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ((res & ADC_CR1_RES_Msk) != res) { + if ((res & ADC_CR1_RES) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_l4_wb.c b/cpu/stm32/periph/adc_l4_wb.c index 26e16b2075eb..b057ae64ffd4 100644 --- a/cpu/stm32/periph/adc_l4_wb.c +++ b/cpu/stm32/periph/adc_l4_wb.c @@ -218,7 +218,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ((res & ADC_CFGR_RES_Msk) != res) { + if ((res & ADC_CFGR_RES) != res) { return -1; } diff --git a/cpu/stm32/periph/adc_wl.c b/cpu/stm32/periph/adc_wl.c index 5f162cd16c82..a0bedbde2251 100644 --- a/cpu/stm32/periph/adc_wl.c +++ b/cpu/stm32/periph/adc_wl.c @@ -119,7 +119,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) int sample; /* check if resolution is applicable */ - if ((res & ADC_CFGR_RES_Msk) != res) { + if ((res & ADC_CFGR_RES) != res) { return -1; }