David-OConnor / stm32-hal

This library provides access to STM32 peripherals in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timing prescaler (PREC) assertion is panicking on 170Mhz

egimbernat opened this issue · comments

The timing prescaler is out of bounds even on 400_000 Fast i2c. I think they should be match-case for the correct dividers instead of a hardcoded 2 bit one, but not sure.

image

I'm testing it on real hardware, based on SM32G474RE

Are you on the Github version, or the latest release? I fixed a bug related to this a few days ago that hasn't made it into the release.

I wish ST provided examples for higher APB frequencies. All the RMs copy+paste the same ones that only go up to 64MHz, even on H7s where a 200Mhz APB isn't uncommon!

If Presc ends up maxxed in the latest update, it's just pegged at max value. As you've noticed, setting a higher I2C speed can help, but it can still max the prescaler even at 400kHz.

Yes, I'm using 1.2.1 release, I'll try Github version and keep you posted.

I did some research and I found a loop that seems to manage the correct values on Arduino SMT32 port https://github.com/stm32duino/Arduino_Core_STM32/blob/main/libraries/Wire/src/utility/twi.c#L504 hope it helps!

Of note:

  • I plan to do a new release within the next few days with this and other fixes
  • I think the default APB speed set for G4 here is 170Mhz... which would definitely trigger this!
  • Setting a high I2C speed works better with high APB speeds, but some I2C devices can't handle 1MHz, and perhaps even 400KHz.
  • Another workaround is lowering the APB speed using its scaler.

Released as 1.3.0.

Awesome! Now works

Sweet.

Btw, this is one of the trickier things to configure on STM32, remarkably. The RM section is detailed, and concludes with something to the effect of "Use Cube to configure it". It has tables for a few settings, which I extrapolated from, but they don't cover higher APB speeds.