STMicroelectronics / STM32CubeL0

STM32Cube MCU Full Package for the STM32L0 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
103 stars 57 forks source link

i2c slave mode gets stuck #26

Closed mfiumara closed 1 year ago

mfiumara commented 2 years ago

Describe the set-up

Describe the bug Trying to respond to a read request from a master (configuring the STM32 as slave device) as per https://st.force.com/community/s/article/how-to-create-an-i2c-slave-device-using-the-stm32cube-library. This simply does not work, the only way to get it to work kind of is to reset the I2C peripheral in the transfer complete callback, but this results in loss of data.

Not sure how this is supposed to work, I have enabled interrupts and they are being triggered, but the problem is my SCL line goes down and does not recover. The address is correctly matched but I can't get any further:

image

How To Reproduce

  1. Set-up the project as per https://st.force.com/community/s/article/how-to-create-an-i2c-slave-device-using-the-stm32cube-library.
  2. Use the latest version of this repo as the HAL
  3. The problem must be somewhere in the stm32l0xx_hal_i2c.c file
  4. Use case is I2C slave device

Additional context I do not have any proposal for a patch, trying to figure out how to resolve it but I don't fully understand the slave HAL.

kjsdf7wr3 commented 2 years ago

Is this related to https://github.com/STMicroelectronics/STM32CubeG0/issues/31 ?

HBOSTM commented 2 years ago

Hello mfiumara,

Thank you for this report. The point you reported is actually related to the How to create an I2C slave device using the STM32Cube Library article and not to the firmware published in this repository (may be a hardware pull-up is missing on I2C pins). Unfortunately, we don't treat aspect related to articles in our GitHub repositories. They are rather treated at the STM32-MCUs dedicated page of the ST Community . Since this issue is not directly related to the STM32Cube firmware but rather to specific application (Aardvark module + STM32CubeMx + article), please allow me then to close this thread.

Thank you for your comprehension.

With regards, Houssine

mfiumara commented 2 years ago

Hello mfiumara,

Thank you for this report. The point you reported is actually related to the How to create an I2C slave device using the STM32Cube Library article and not to the firmware published in this repository (may be a hardware pull-up is missing on I2C pins).

Unfortunately, we don't treat aspect related to articles in our GitHub repositories. They are rather treated at the STM32-MCUs dedicated page of the ST Community .

Since this issue is not directly related to the STM32Cube firmware but rather to specific application (Aardvark module + STM32CubeMx + article), please allow me then to close this thread.

Thank you for your comprehension.

With regards,

Houssine

Hi Houssine,

I am 100% sure that this is a bug in the HAL which I have now resolved by implementing the i2c slave mode myself following the stm32 0 series reference manual (writing registers directly).

I hope you can take this issue more seriously than just waving it off as an article inaccuracy or a hardware setup problem (pull up missing, really?). I would advise to leave this ticket open until it is actually resolved in case someone else spends weeks on figuring out what's going on in their implementation.

If you're low on resources I'd gladly help by sharing the basis of a working implementation.

Best regards,

Mattia

etheory commented 2 years ago

@mfiumara I have been struggling for AGES with the G0 I2C implementation. I know 100% there is no issue with my hardware setup. What is happening is that the first HAL_I2C_Slave_Transmit_IT call works, and the second one never completes. It's definitely a bug with the HAL code itself, and all my attempts to report this issue have gone ignored by ST. If you have any tips about how to fix it I'd love to know, thanks!

etheory commented 2 years ago

This also seems related potentially: https://github.com/STMicroelectronics/STM32CubeF4/issues/76

HBOSTM commented 2 years ago

Hello @Mfiumara We have followed the steps you have described to reproduce the issue and we did not get the same behavior you are having. The salve is correctly responding as shown in the following results :

image

MicrosoftTeams-image (1)

MicrosoftTeams-image

For a better analysis of the problem would you please provide us with the project you have used to reproduce the issue. Would you also confirm that you are using the latest version of the STM32CubeL0 (V1.12.1).

With regards,

mfiumara commented 1 year ago

Hey as reported in the original ticket I used stm32Cube Version 1.9.0. I imagine it was fixed in the newer stm32cube release then?