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 <raiden00@railab.me>
This commit is contained in:
raiden00pl 2025-01-08 17:10:23 +01:00 committed by archer
parent 11d54b34a7
commit b3120e535b
8 changed files with 38 additions and 52 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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.
*/

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)