Skip to content
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

SetConfig does not work on STM32 I2C #3914

Closed
agrif opened this issue Feb 24, 2025 · 1 comment · Fixed by #3928
Closed

SetConfig does not work on STM32 I2C #3914

agrif opened this issue Feb 24, 2025 · 1 comment · Fixed by #3928

Comments

@agrif
Copy link
Contributor

agrif commented Feb 24, 2025

I'm using the I2cDeviceWithConfig struct in embassy-embedded-hal, but it does not appear to be actually changing the I2C bus frequency. I'm using the bus with the ssd1306 crate to draw to a small display on an STM32F072CB microcontroller.

If I use a plain I2cDevice with the underlying I2C bus configured to 100kHz, it takes about 120ms to write to the device. If I configure the underlying I2C bus to 200kHz, it takes about 60ms (as expected).

However, if I use an I2cDeviceWithConfig set to 200kHz on top of an underlying I2C bus configured for 100kHz, the flush takes 120ms still. It looks like the configuration override isn't happening at all.

I'm using embassy-embedded-hal 0.3.0 and embassy-stm32 0.2.0. It looks like the implementation of this trait has not changed between 0.2.0 and the latest git.

The embassy docs link to v2 of the I2C peripheral for my MCU, but I must admit I don't know if the STM32F072CB uses v1 or v2.

@agrif
Copy link
Contributor Author

agrif commented Feb 26, 2025

I had some time to look into this today. From STM's RM0091, PDF page 640, in the section describing the I2C timing register:

Caution: Changing the timing configuration is not allowed when the I2C is enabled.

Looks like we need to disable the I2C peripheral before touching the timings register. This is what I2c::init does, earlier in the file, and I should just be able to copy that into SetConfig. I'll give that a shot and open a PR if it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant