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

archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new b3120e535b arch/arm/stm32{|f0l0g0|f7|h5|h7}/i2c: raise compilation 
error when configuration is invalid
b3120e535b is described below

commit b3120e535baad2a46914a5bb6cd856ed038aa820
Author: raiden00pl <raide...@railab.me>
AuthorDate: Wed Jan 8 17:10:23 2025 +0100

    arch/arm/stm32{|f0l0g0|f7|h5|h7}/i2c: raise compilation error when 
configuration is invalid
    
    Raise compilation error when I2C configuration is invalid.
    It's better to catch invalid clock configuration during compilation instead 
of
    producing binary that doesn't work as expected anyway.
    
    Signed-off-by: raiden00pl <raide...@railab.me>
---
 arch/arm/src/stm32/stm32_i2c.c       | 17 ++++++++---------
 arch/arm/src/stm32/stm32_i2c_alt.c   | 17 ++++++++---------
 arch/arm/src/stm32/stm32_i2c_v2.c    |  3 +--
 arch/arm/src/stm32/stm32f40xxx_i2c.c | 17 ++++++++---------
 arch/arm/src/stm32f0l0g0/stm32_i2c.c |  9 +--------
 arch/arm/src/stm32f7/stm32_i2c.c     |  9 ++++-----
 arch/arm/src/stm32h5/stm32_i2c.c     |  9 ++++-----
 arch/arm/src/stm32h7/stm32_i2c.c     |  9 ++++-----
 8 files changed, 38 insertions(+), 52 deletions(-)

diff --git a/arch/arm/src/stm32/stm32_i2c.c b/arch/arm/src/stm32/stm32_i2c.c
index 0c7f26676f..a8fd44c269 100644
--- a/arch/arm/src/stm32/stm32_i2c.c
+++ b/arch/arm/src/stm32/stm32_i2c.c
@@ -95,6 +95,14 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#if STM32_PCLK1_FREQUENCY < 4000000
+#  warning STM32_I2C: Peripheral clock must be at least 4 MHz to support 400 
kHz operation.
+#endif
+
+#if STM32_PCLK1_FREQUENCY < 2000000
+#  error STM32_I2C: Peripheral clock must be at least 2 MHz to support 100 kHz 
operation.
+#endif
+
 /* Configuration ************************************************************/
 
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
@@ -1859,15 +1867,6 @@ struct i2c_master_s *stm32_i2cbus_initialize(int port)
 {
   struct stm32_i2c_priv_s *priv = NULL;
 
-#if STM32_PCLK1_FREQUENCY < 4000000
-#   warning STM32_I2C_INIT: Peripheral clock must be at least 4 MHz to support 
400 kHz operation.
-#endif
-
-#if STM32_PCLK1_FREQUENCY < 2000000
-#   warning STM32_I2C_INIT: Peripheral clock must be at least 2 MHz to support 
100 kHz operation.
-  return NULL;
-#endif
-
   /* Get I2C private structure */
 
   switch (port)
diff --git a/arch/arm/src/stm32/stm32_i2c_alt.c 
b/arch/arm/src/stm32/stm32_i2c_alt.c
index 0a003dd752..a23a66ec62 100644
--- a/arch/arm/src/stm32/stm32_i2c_alt.c
+++ b/arch/arm/src/stm32/stm32_i2c_alt.c
@@ -118,6 +118,14 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#if STM32_PCLK1_FREQUENCY < 4000000
+#  warning STM32_I2C: Peripheral clock must be at least 4 MHz to support 400 
kHz operation.
+#endif
+
+#if STM32_PCLK1_FREQUENCY < 2000000
+#  error STM32_I2C: Peripheral clock must be at least 2 MHz to support 100 kHz 
operation.
+#endif
+
 /* Configuration ************************************************************/
 
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
@@ -2366,15 +2374,6 @@ struct i2c_master_s *stm32_i2cbus_initialize(int port)
 {
   struct stm32_i2c_priv_s *priv = NULL;
 
-#if STM32_PCLK1_FREQUENCY < 4000000
-#   warning STM32_I2C_INIT: Peripheral clock must be at least 4 MHz to support 
400 kHz operation.
-#endif
-
-#if STM32_PCLK1_FREQUENCY < 2000000
-#   warning STM32_I2C_INIT: Peripheral clock must be at least 2 MHz to support 
100 kHz operation.
-  return NULL;
-#endif
-
   /* Get I2C private structure */
 
   switch (port)
diff --git a/arch/arm/src/stm32/stm32_i2c_v2.c 
b/arch/arm/src/stm32/stm32_i2c_v2.c
index 0f88986feb..3ddf200be7 100644
--- a/arch/arm/src/stm32/stm32_i2c_v2.c
+++ b/arch/arm/src/stm32/stm32_i2c_v2.c
@@ -249,6 +249,7 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#warning TODO: check I2C clock source. It must be HSI!
 #undef INVALID_CLOCK_SOURCE
 
 #if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \
@@ -264,8 +265,6 @@
 #  error STM32_I2C: Device not Supported.
 #endif
 
-#warning TODO: check I2C clock source. It must be HSI!
-
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
  * Instead, CPU-intensive polling will be used.
  */
diff --git a/arch/arm/src/stm32/stm32f40xxx_i2c.c 
b/arch/arm/src/stm32/stm32f40xxx_i2c.c
index 6331210c64..fac079150c 100644
--- a/arch/arm/src/stm32/stm32f40xxx_i2c.c
+++ b/arch/arm/src/stm32/stm32f40xxx_i2c.c
@@ -95,6 +95,14 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#if STM32_PCLK1_FREQUENCY < 4000000
+#  warning STM32_I2C: Peripheral clock must be at least 4 MHz to support 400 
kHz operation.
+#endif
+
+#if STM32_PCLK1_FREQUENCY < 2000000
+#  error STM32_I2C: Peripheral clock must be at least 2 MHz to support 100 kHz 
operation.
+#endif
+
 /* Configuration ************************************************************/
 
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
@@ -2587,15 +2595,6 @@ struct i2c_master_s *stm32_i2cbus_initialize(int port)
 {
   struct stm32_i2c_priv_s *priv = NULL;
 
-#if STM32_PCLK1_FREQUENCY < 4000000
-#   warning STM32_I2C_INIT: Peripheral clock must be at least 4 MHz to support 
400 kHz operation.
-#endif
-
-#if STM32_PCLK1_FREQUENCY < 2000000
-#   warning STM32_I2C_INIT: Peripheral clock must be at least 2 MHz to support 
100 kHz operation.
-  return NULL;
-#endif
-
   /* Get I2C private structure */
 
   switch (port)
diff --git a/arch/arm/src/stm32f0l0g0/stm32_i2c.c 
b/arch/arm/src/stm32f0l0g0/stm32_i2c.c
index 070d425054..93ba0f2f4c 100644
--- a/arch/arm/src/stm32f0l0g0/stm32_i2c.c
+++ b/arch/arm/src/stm32f0l0g0/stm32_i2c.c
@@ -252,7 +252,7 @@
 
 #undef INVALID_CLOCK_SOURCE
 
-#warning TODO: check I2C clock source. It must be HSI!
+#warning TODO: check I2C clock source and clock frequency. It must be HSI!
 
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
  * Instead, CPU-intensive polling will be used.
@@ -2702,13 +2702,6 @@ struct i2c_master_s *stm32_i2cbus_initialize(int port)
   struct stm32_i2c_priv_s *priv = NULL;  /* private data of device with 
multiple instances */
   struct stm32_i2c_inst_s *inst = NULL;  /* device, single instance */
 
-#if 0                           /* REVISIT: this is not true for all STM32 M0 
*/
-#if STM32_HSI_FREQUENCY != 8000000 || defined(INVALID_CLOCK_SOURCE)
-#  warning STM32_I2C_INIT: Peripheral clock is HSI and it must be 16mHz or the 
speed/timing calculations need to be redone.
-  return NULL;
-#endif
-#endif
-
   /* Get I2C private structure */
 
   switch (port)
diff --git a/arch/arm/src/stm32f7/stm32_i2c.c b/arch/arm/src/stm32f7/stm32_i2c.c
index b5fba286de..ca4b3b2e9d 100644
--- a/arch/arm/src/stm32f7/stm32_i2c.c
+++ b/arch/arm/src/stm32f7/stm32_i2c.c
@@ -290,6 +290,10 @@
 #  endif
 #endif
 
+#if STM32_HSI_FREQUENCY != 16000000 || defined(INVALID_CLOCK_SOURCE)
+#  error STM32_I2C: Peripheral clock is HSI and it must be 16mHz or the 
speed/timing calculations need to be redone.
+#endif
+
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
  * Instead, CPU-intensive polling will be used.
  */
@@ -2731,11 +2735,6 @@ struct i2c_master_s *stm32_i2cbus_initialize(int port)
 {
   struct stm32_i2c_priv_s *priv = NULL;  /* private data of device with 
multiple instances */
 
-#if STM32_HSI_FREQUENCY != 16000000 || defined(INVALID_CLOCK_SOURCE)
-# warning STM32_I2C_INIT: Peripheral clock is HSI and it must be 16mHz or the 
speed/timing calculations need to be redone.
-  return NULL;
-#endif
-
   /* Get I2C private structure */
 
   switch (port)
diff --git a/arch/arm/src/stm32h5/stm32_i2c.c b/arch/arm/src/stm32h5/stm32_i2c.c
index 6f299beda8..91698c16da 100644
--- a/arch/arm/src/stm32h5/stm32_i2c.c
+++ b/arch/arm/src/stm32h5/stm32_i2c.c
@@ -236,6 +236,10 @@
 
 #undef INVALID_CLOCK_SOURCE
 
+#if defined(INVALID_CLOCK_SOURCE)
+#   error STM32_I2C: Peripheral input clock must be HSI or the speed/timing 
calculations need to be redone.
+#endif
+
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
  * Instead, CPU-intensive polling will be used.
  */
@@ -3005,11 +3009,6 @@ struct i2c_master_s *stm32_i2cbus_initialize(int port)
   struct stm32_i2c_priv_s *priv = NULL;  /* private data of device with 
multiple instances */
   struct stm32_i2c_inst_s *inst = NULL;  /* device, single instance */
 
-#if defined(INVALID_CLOCK_SOURCE)
-#   warning STM32_I2C_INIT: Peripheral input clock must be HSI or the 
speed/timing calculations need to be redone.
-  return NULL;
-#endif
-
   /* Get I2C private structure */
 
   switch (port)
diff --git a/arch/arm/src/stm32h7/stm32_i2c.c b/arch/arm/src/stm32h7/stm32_i2c.c
index 99ace3cbf0..9f96a33e53 100644
--- a/arch/arm/src/stm32h7/stm32_i2c.c
+++ b/arch/arm/src/stm32h7/stm32_i2c.c
@@ -248,6 +248,10 @@
 #  endif
 #endif
 
+#if STM32_HSI_FREQUENCY != 16000000 || defined(INVALID_CLOCK_SOURCE)
+#   error STM32_I2C: Peripheral clock is HSI and it must be 16mHz or the 
speed/timing calculations need to be redone.
+#endif
+
 /* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
  * Instead, CPU-intensive polling will be used.
  */
@@ -2706,11 +2710,6 @@ struct i2c_master_s *stm32_i2cbus_initialize(int port)
   struct stm32_i2c_priv_s *priv = NULL;  /* private data of device with 
multiple instances */
   struct stm32_i2c_inst_s *inst = NULL;  /* device, single instance */
 
-#if STM32_HSI_FREQUENCY != 16000000 || defined(INVALID_CLOCK_SOURCE)
-#   warning STM32_I2C_INIT: Peripheral clock is HSI and it must be 16mHz or 
the speed/timing calculations need to be redone.
-  return NULL;
-#endif
-
   /* Get I2C private structure */
 
   switch (port)

Reply via email to