Skip to content
Snippets Groups Projects
Unverified Commit a1050dae authored by Alexandre Abadie's avatar Alexandre Abadie Committed by GitHub
Browse files

Merge pull request #8819 from Marc-Aurele/i2c_timeout_busy

cpu/stm32l0 : timeout added on waiting loop
parents a04b232c 59b1890e
No related branches found
No related tags found
No related merge requests found
...@@ -403,7 +403,7 @@ int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, const void *data, in ...@@ -403,7 +403,7 @@ int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, const void *data, in
} }
/* Check to see if the bus is busy */ /* Check to see if the bus is busy */
while ((i2c->ISR & I2C_ISR_BUSY) & tick--) { while ((i2c->ISR & I2C_ISR_BUSY) && tick--) {
if ((i2c->ISR & ERROR_FLAG) || !tick) { if ((i2c->ISR & ERROR_FLAG) || !tick) {
return -1; return -1;
} }
...@@ -451,24 +451,28 @@ void i2c_poweron(i2c_t dev) ...@@ -451,24 +451,28 @@ void i2c_poweron(i2c_t dev)
void i2c_poweroff(i2c_t dev) void i2c_poweroff(i2c_t dev)
{ {
#if defined I2C_0_EN || defined I2C_1_EN || defined I2C_2_EN
uint16_t tick = TICK_TIMEOUT;
#endif
switch (dev) { switch (dev) {
#if I2C_0_EN #if I2C_0_EN
case I2C_0: case I2C_0:
while (I2C_0_DEV->ISR & I2C_ISR_BUSY) {} while ((I2C_0_DEV->ISR & I2C_ISR_BUSY) && tick--) {}
I2C_0_CLKDIS(); I2C_0_CLKDIS();
break; break;
#endif #endif
#if I2C_1_EN #if I2C_1_EN
case I2C_1: case I2C_1:
while (I2C_1_DEV->ISR & I2C_ISR_BUSY) {} while ((I2C_1_DEV->ISR & I2C_ISR_BUSY) && tick--) {}
I2C_1_CLKDIS(); I2C_1_CLKDIS();
break; break;
#endif #endif
#if I2C_2_EN #if I2C_2_EN
case I2C_2: case I2C_2:
while (I2C_2_DEV->ISR & I2C_ISR_BUSY) {} while ((I2C_2_DEV->ISR & I2C_ISR_BUSY) && tick--) {}
I2C_2_CLKDIS(); I2C_2_CLKDIS();
break; break;
...@@ -478,6 +482,8 @@ void i2c_poweroff(i2c_t dev) ...@@ -478,6 +482,8 @@ void i2c_poweroff(i2c_t dev)
static void _start(I2C_TypeDef *dev, uint8_t address, uint8_t length, uint8_t rw_flag) static void _start(I2C_TypeDef *dev, uint8_t address, uint8_t length, uint8_t rw_flag)
{ {
uint16_t tick = TICK_TIMEOUT;
dev->CR2 = 0; dev->CR2 = 0;
/* set address mode to 7-bit */ /* set address mode to 7-bit */
dev->CR2 &= ~(I2C_CR2_ADD10); dev->CR2 &= ~(I2C_CR2_ADD10);
...@@ -504,7 +510,7 @@ static void _start(I2C_TypeDef *dev, uint8_t address, uint8_t length, uint8_t rw ...@@ -504,7 +510,7 @@ static void _start(I2C_TypeDef *dev, uint8_t address, uint8_t length, uint8_t rw
dev->CR2 |= I2C_CR2_START; dev->CR2 |= I2C_CR2_START;
/* Wait for the start followed by the address to be sent */ /* Wait for the start followed by the address to be sent */
while (!(dev->CR2 & I2C_CR2_START)) {} while (!(dev->CR2 & I2C_CR2_START) && tick--) {}
} }
static inline int _read(I2C_TypeDef *dev, uint8_t *data, int length) static inline int _read(I2C_TypeDef *dev, uint8_t *data, int length)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment