bus busy timeout, errata

This commit is contained in:
Lok Tep 2016-06-05 11:43:06 +02:00
parent 82cd44dbc5
commit 88b51683bb
2 changed files with 84 additions and 68 deletions

View File

@ -402,6 +402,7 @@ struct stm32_i2c_priv_s
uint8_t msgc; /* Message count */
struct i2c_msg_s *msgv; /* Message list */
uint8_t *ptr; /* Current message buffer */
uint32_t frequency; /* Current I2C frequency */
int dcnt; /* Current message bytes remaining to transfer */
uint16_t flags; /* Current message flags */
bool astart; /* START sent */
@ -426,10 +427,6 @@ struct stm32_i2c_inst_s
{
struct i2c_ops_s *ops; /* Standard I2C operations */
struct stm32_i2c_priv_s *priv; /* Common driver private data structure */
uint32_t frequency; /* Frequency used in this instantiation */
int address; /* Address used in this instantiation */
uint16_t flags; /* Flags used in this instantiation */
};
/************************************************************************************
@ -516,6 +513,7 @@ struct stm32_i2c_priv_s stm32_i2c1_priv =
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.frequency = 0,
.dcnt = 0,
.flags = 0,
.status = 0
@ -545,6 +543,7 @@ struct stm32_i2c_priv_s stm32_i2c2_priv =
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.frequency = 0,
.dcnt = 0,
.flags = 0,
.status = 0
@ -574,6 +573,7 @@ struct stm32_i2c_priv_s stm32_i2c3_priv =
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.frequency = 0,
.dcnt = 0,
.flags = 0,
.status = 0
@ -1242,6 +1242,8 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ
uint8_t scl_h_period;
uint8_t scl_l_period;
if (frequency != priv->frequency)
{
/* I2C peripheral must be disabled to update clocking configuration */
pe = (stm32_i2c_getreg32(priv, STM32F7_I2C_CR1_OFFSET) & I2C_CR1_PE);
@ -1292,6 +1294,8 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ
{
stm32_i2c_modifyreg32(priv, STM32F7_I2C_CR1_OFFSET, 0, I2C_CR1_PE);
}
priv->frequency = frequency;
}
}
/************************************************************************************
@ -2352,10 +2356,11 @@ static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s
if (status & I2C_INT_BERR)
{
/* Bus Error */
/* Bus Error, ignore it because of errata (revision A,Z) */
i2cdbg("I2C: Bus Error\n");
errval = EIO;
/* errval = EIO; */
}
else if (status & I2C_INT_ARLO)
{
@ -2427,8 +2432,22 @@ static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s
* fails above; Otherwise it is cleared by the hardware when the ISR
* wraps up the transfer with a STOP condition.
*/
uint32_t start = clock_systimer();
uint32_t timeout = USEC2TICK(USEC_PER_SEC/priv->frequency) + 1;
status = stm32_i2c_getstatus(priv);
while(status & I2C_ISR_BUSY)
{
if((clock_systimer() - start) > timeout)
{
i2cdbg("I2C: Bus busy");
errval = EBUSY;
break;
}
status = stm32_i2c_getstatus(priv);
}
}
/* Dump the trace result */
@ -2515,9 +2534,6 @@ FAR struct i2c_master_s *stm32f7_i2cbus_initialize(int port)
inst->ops = &stm32_i2c_ops;
inst->priv = priv;
inst->frequency = 0;
inst->address = 0;
inst->flags = 0;
/* Init private data for the first time, increment refs count,
* power-up hardware and configure GPIOs.

View File

@ -333,7 +333,7 @@ CONFIG_DISABLE_OS_API=y
#
# Clocks and Timers
#
CONFIG_USEC_PER_TICK=10000
CONFIG_USEC_PER_TICK=1000
# CONFIG_SYSTEM_TIME64 is not set
# CONFIG_CLOCK_MONOTONIC is not set
# CONFIG_JULIAN_TIME is not set