Skip to content

[F4] I2C broken since last STM32F4 HAL update #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
charlie1024 opened this issue Feb 28, 2019 · 9 comments
Closed

[F4] I2C broken since last STM32F4 HAL update #463

charlie1024 opened this issue Feb 28, 2019 · 9 comments
Assignees
Labels
bug 🐛 Something isn't working
Milestone

Comments

@charlie1024
Copy link

charlie1024 commented Feb 28, 2019

[Edit: transferred from stm32duino/STM32RTC]

Hello,
I recently seen the board library was updated some days ago and the HAL feature was newly implemented.
I thought that with the new master branch board platform the new library will work, so with my Nucleo-F411RE I tried to operate the new library.

It worked without I2C. I use D14/D15(I2C1) and if I connect any I2C device, then the MCU goes to forever sleep(all codes are stopped).

This code shows:

#include <Wire.h>
#include <STM32RTC.h>
STM32RTC& rtc = STM32RTC::getInstance();

void setup() {
  // put your setup code here, to run once:
  rtc.setClockSource(STM32RTC::LSE_CLOCK);
  rtc.begin(false); // initialize RTC 24H format

  if (!rtc.isTimeSet()) {
    rtc.setTime(0, 0, 0);
    rtc.setDate(1, 1, 19); // fallback
  }
  pinMode(LED_BUILTIN, OUTPUT);

  Wire.begin();

  Wire.beginTransmission(0x50);
  Wire.write(0);
  Wire.endTransmission();
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(500);
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

0x50 means the EEPROM device and I just wrote a waste data to the line, so there must be no problem.
However If I use this code with any I2C device connected, F411RE just halts and not respond for anything(interrupts are all stopped too).

Couldn't be the new library used yet? Or is this a bug?

Thank you.

@fpistm fpistm self-assigned this Feb 28, 2019
@charlie1024
Copy link
Author

Additionally confirmed that the source caused halt only with Wire library, without STM32RTC and all related codes. It's so confusing. Initially I thought the RTC library has an issue with the master branch board platform but it seems that the core has another problem.

@fpistm
Copy link
Member

fpistm commented Feb 28, 2019

Hi @charlie1024
Thanks for report.
Could you give me more detail about your setup.
Which core version (master repo? official 1.5.0?..) STM32RTC version (I guess this is the master)? Board exact reference (MBxxxxx)? Arduino IDE version?

@charlie1024
Copy link
Author

charlie1024 commented Feb 28, 2019

Hello,
I have MB1136-C-04(It has a 32.768kHz crystal).
Used core was directly got from the master branch. Official 1.5.0 seems doesn't support the new library so It will be out of the problem. STM32RTC version is from the master branch as well.
Finally, I'm using Arduino 1.8.8, which is the latest and before changing the core, the Arduino didn't make any problems.

@fpistm
Copy link
Member

fpistm commented Feb 28, 2019

Ok thanks. I will test on my side when possible.

@fpistm fpistm transferred this issue from stm32duino/STM32RTC Feb 28, 2019
@fpistm fpistm changed the title With i2c new library doesn't work [F4] I2C broken since last STM32 HAL update Feb 28, 2019
@fpistm fpistm added the bug 🐛 Something isn't working label Feb 28, 2019
@fpistm fpistm added this to the 1.5.1/1.6.0 milestone Feb 28, 2019
@fpistm
Copy link
Member

fpistm commented Feb 28, 2019

@charlie1024,
I confirm this is a bug in the core since the last HAL update for F4.

@fpistm fpistm changed the title [F4] I2C broken since last STM32 HAL update [F4] I2C broken since last STM32F4 HAL update Feb 28, 2019
@fpistm
Copy link
Member

fpistm commented Feb 28, 2019

As a workaround you can revert those 2 commits:
df49661
0e8722f

@charlie1024
Copy link
Author

charlie1024 commented Mar 1, 2019

I tried to implement new RTC feature with [RTC] Avoid reset time after low power mode #442 and that did work in 1.5.0 release platform. I hope the bug could be resolved. Thank you for assistance.

@fpistm
Copy link
Member

fpistm commented Mar 1, 2019

Of course this will be resolved ;)
Moreover there is a workaround to not block user who want use the master.

@fpistm fpistm closed this as completed in de68692 Mar 5, 2019
@fpistm
Copy link
Member

fpistm commented Mar 5, 2019

Issue found and fixed.

benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this issue Apr 10, 2019
In function:
static HAL_StatusTypeDef I2C_Master_SB(I2C_HandleTypeDef *hi2c)

This check has been added:
      if ((hi2c->hdmatx->XferCpltCallback != NULL) || (hi2c->hdmarx->XferCpltCallback != NULL))
      {
        /* Enable DMA Request */
        SET_BIT(hi2c->Instance->CR2, I2C_CR2_DMAEN);
      }

But, in case of the DMA is not used, hi2c->hdmatx and hi2c->hdmarx are NULL.
In this case, hi2c->hdma(rx|tx)->XferCpltCallback can be not NULL
then I2C_CR2_DMAEN is set while it should not.
As this bit is checked several time to know if DMA is used or not this
raised an exception handler.

Fix stm32duino#463

Signed-off-by: Frederic.Pillon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants