Page 1 of 1

I2C v.1.0 discrepancy RM

Posted: Tue Jun 14, 2022 12:52 pm
by alexblack
Hi.
In current stable branch (21.11.2) there is I2C v.1 driver and it has discrepancy with Reference Manual:

Code: Select all

"ChibiOS\os\hal\ports\STM32\LLD\I2Cv1\hal_i2c_lld.c"
...
252 static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
253   I2C_TypeDef *dp = i2cp->i2c;
254   uint32_t regSR2 = dp->SR2;
255   uint32_t event = dp->SR1;
...

But the Reference Manual for STM32F407 (for example) says:

Code: Select all

"Page 858 <27.6.6> DM00031020_RM0090_STM32F4xx.pdf
Bit 1 ADDR: Address sent (master mode)/matched (slave mode)
This bit is cleared by software reading SR1 register followed reading SR2, or by hardware
when PE=0.

Thus, you must first read status register 1, then 2:

Code: Select all

252 static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
253   I2C_TypeDef *dp = i2cp->i2c;
254   uint32_t event = dp->SR1;
255   uint32_t regSR2 = dp->SR2;
...

Re: I2C v.1.0 discrepancy RM

Posted: Tue Jun 14, 2022 1:08 pm
by Giovanni
Hi,

Moving in bug reports.

Giovanni

Re: I2C v.1.0 discrepancy RM

Posted: Mon Sep 19, 2022 5:17 pm
by Edoardo1982
alexblack wrote:Hi.
In current stable branch (21.11.2) there is I2C v.1 driver and it has discrepancy with Reference Manual:

Code: Select all

"ChibiOS\os\hal\ports\STM32\LLD\I2Cv1\hal_i2c_lld.c"
...
252 static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
253   I2C_TypeDef *dp = i2cp->i2c;
254   uint32_t regSR2 = dp->SR2;
255   uint32_t event = dp->SR1;
...

But the Reference Manual for STM32F407 (for example) says:

Code: Select all

"Page 858 <27.6.6> DM00031020_RM0090_STM32F4xx.pdf
Bit 1 ADDR: Address sent (master mode)/matched (slave mode)
This bit is cleared by software reading SR1 register followed reading SR2, or by hardware
when PE=0.

Thus, you must first read status register 1, then 2:

Code: Select all

252 static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
253   I2C_TypeDef *dp = i2cp->i2c;
254   uint32_t event = dp->SR1;
255   uint32_t regSR2 = dp->SR2;
...

SR1 is cleared reading SR2 at the end of event handler

Code: Select all

  /* Clear ADDR flag. */
  if (event & (I2C_SR1_ADDR | I2C_SR1_ADD10))
    (void)dp->SR2;

There is no discrepancy with RM.
Edoardo

Re: I2C v.1.0 discrepancy RM

Posted: Wed Sep 21, 2022 5:28 pm
by Giovanni
Hi,

Is this agreed? if so I will close the ticket.

Giovanni