mirror of
https://github.com/apache/nuttx.git
synced 2025-01-12 22:08:35 +08:00
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:
parent
11d54b34a7
commit
b3120e535b
8 changed files with 38 additions and 52 deletions
|
@ -95,6 +95,14 @@
|
||||||
* Pre-processor Definitions
|
* 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 ************************************************************/
|
/* Configuration ************************************************************/
|
||||||
|
|
||||||
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
/* 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;
|
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 */
|
/* Get I2C private structure */
|
||||||
|
|
||||||
switch (port)
|
switch (port)
|
||||||
|
|
|
@ -118,6 +118,14 @@
|
||||||
* Pre-processor Definitions
|
* 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 ************************************************************/
|
/* Configuration ************************************************************/
|
||||||
|
|
||||||
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
/* 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;
|
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 */
|
/* Get I2C private structure */
|
||||||
|
|
||||||
switch (port)
|
switch (port)
|
||||||
|
|
|
@ -249,6 +249,7 @@
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#warning TODO: check I2C clock source. It must be HSI!
|
||||||
#undef INVALID_CLOCK_SOURCE
|
#undef INVALID_CLOCK_SOURCE
|
||||||
|
|
||||||
#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \
|
#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \
|
||||||
|
@ -264,8 +265,6 @@
|
||||||
# error STM32_I2C: Device not Supported.
|
# error STM32_I2C: Device not Supported.
|
||||||
#endif
|
#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.
|
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
||||||
* Instead, CPU-intensive polling will be used.
|
* Instead, CPU-intensive polling will be used.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -95,6 +95,14 @@
|
||||||
* Pre-processor Definitions
|
* 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 ************************************************************/
|
/* Configuration ************************************************************/
|
||||||
|
|
||||||
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
/* 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;
|
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 */
|
/* Get I2C private structure */
|
||||||
|
|
||||||
switch (port)
|
switch (port)
|
||||||
|
|
|
@ -252,7 +252,7 @@
|
||||||
|
|
||||||
#undef INVALID_CLOCK_SOURCE
|
#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.
|
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
||||||
* Instead, CPU-intensive polling will 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_priv_s *priv = NULL; /* private data of device with multiple instances */
|
||||||
struct stm32_i2c_inst_s *inst = NULL; /* device, single instance */
|
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 */
|
/* Get I2C private structure */
|
||||||
|
|
||||||
switch (port)
|
switch (port)
|
||||||
|
|
|
@ -290,6 +290,10 @@
|
||||||
# endif
|
# endif
|
||||||
#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.
|
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
||||||
* Instead, CPU-intensive polling will 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 */
|
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 */
|
/* Get I2C private structure */
|
||||||
|
|
||||||
switch (port)
|
switch (port)
|
||||||
|
|
|
@ -236,6 +236,10 @@
|
||||||
|
|
||||||
#undef INVALID_CLOCK_SOURCE
|
#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.
|
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
||||||
* Instead, CPU-intensive polling will 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_priv_s *priv = NULL; /* private data of device with multiple instances */
|
||||||
struct stm32_i2c_inst_s *inst = NULL; /* device, single instance */
|
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 */
|
/* Get I2C private structure */
|
||||||
|
|
||||||
switch (port)
|
switch (port)
|
||||||
|
|
|
@ -248,6 +248,10 @@
|
||||||
# endif
|
# endif
|
||||||
#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.
|
/* CONFIG_I2C_POLLED may be set so that I2C interrupts will not be used.
|
||||||
* Instead, CPU-intensive polling will 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_priv_s *priv = NULL; /* private data of device with multiple instances */
|
||||||
struct stm32_i2c_inst_s *inst = NULL; /* device, single instance */
|
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 */
|
/* Get I2C private structure */
|
||||||
|
|
||||||
switch (port)
|
switch (port)
|
||||||
|
|
Loading…
Reference in a new issue