diff options
| author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-12-17 12:45:50 +0000 | 
|---|---|---|
| committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-12-17 12:45:50 +0000 | 
| commit | 27a7716a3b4218c5edfa2e226febfb38aa94e1d7 (patch) | |
| tree | cd246f0918aa476aeee376ae41cb2c42c6b6c751 /os/hal/platforms | |
| parent | 3ff51b09a448a0986cdfd388b40a790bf5033a32 (diff) | |
| download | ChibiOS-27a7716a3b4218c5edfa2e226febfb38aa94e1d7.tar.gz ChibiOS-27a7716a3b4218c5edfa2e226febfb38aa94e1d7.tar.bz2 ChibiOS-27a7716a3b4218c5edfa2e226febfb38aa94e1d7.zip  | |
I2C. Added safety checks for different STM32 platforms in frequency settings routine.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3624 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms')
| -rw-r--r-- | os/hal/platforms/STM32/i2c_lld.c | 21 | 
1 files changed, 18 insertions, 3 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c index 84decd64f..cd040b6d1 100644 --- a/os/hal/platforms/STM32/i2c_lld.c +++ b/os/hal/platforms/STM32/i2c_lld.c @@ -587,13 +587,28 @@ void i2c_lld_set_clock(I2CDriver *i2cp) {    regCR2 = i2cp->id_i2c->CR2;                   /* Get the I2Cx CR2 value */    regCR2 &= (uint16_t)~I2C_CR2_FREQ;            /* Clear frequency FREQ[5:0] bits */    freq = (uint16_t)(STM32_PCLK1 / 1000000);     /* Set frequency bits depending on pclk1 value */ -#ifdef STM32F4XX +#if   defined(STM32F4XX)    chDbgCheck((freq >= 2) && (freq <= 42),                  "i2c_lld_set_clock() : Peripheral clock freq. out of range"); -#else +#elif defined(STM32L1XX_MD) +  chDbgCheck((freq >= 2) && (freq <= 32), +                "i2c_lld_set_clock() : Peripheral clock freq. out of range"); +#elif defined(STM32F2XX) +  chDbgCheck((freq >= 2) && (freq <= 30), +                "i2c_lld_set_clock() : Peripheral clock freq. out of range"); + +#elif defined(STM32F10X_LD_VL) || defined(STM32F10X_MD_VL) || \ +      defined(STM32F10X_HD_VL) +  chDbgCheck((freq >= 2) && (freq <= 24), +                  "i2c_lld_set_clock() : Peripheral clock freq. out of range"); +#elif defined(STM32F10X_LD) || defined(STM32F10X_MD) ||                     \ +      defined(STM32F10X_HD) || defined(STM32F10X_XL) ||                     \ +      defined(STM32F10X_CL)    chDbgCheck((freq >= 2) && (freq <= 36),                "i2c_lld_set_clock() : Peripheral clock freq. out of range"); -#endif /* define STM32F4XX */ +#else +#error "unspecified, unsupported or invalid STM32 platform" +#endif    regCR2 |= freq;    i2cp->id_i2c->CR2 = regCR2;  | 
