I2C v.1.0 discrepancy RM Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

I2C v.1.0 discrepancy RM

Post 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;
...
User avatar
Giovanni
Site Admin
Posts: 14894
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C v.1.0 discrepancy RM

Post by Giovanni »

Hi,

Moving in bug reports.

Giovanni
User avatar
Edoardo1982
Posts: 24
Joined: Thu Aug 03, 2017 8:39 am
Has thanked: 10 times
Been thanked: 20 times

Re: I2C v.1.0 discrepancy RM

Post 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
User avatar
Giovanni
Site Admin
Posts: 14894
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C v.1.0 discrepancy RM

Post by Giovanni »

Hi,

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

Giovanni
Post Reply