tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

nucleo-l432kc, nucleo-l031k6, nucleo-f722ze seemingly lack the ability to change I2C frequency

Open rayozzie opened this issue 4 years ago • 4 comments

For both of these boards there are consts for TWI_FREQ, however the I2CConfig type has no Frequency field and thus it is not apparent how to configure bus speed for I2C.

https://tinygo.org/docs/reference/microcontrollers/machine/nucleo-l432kc/ https://tinygo.org/docs/reference/microcontrollers/machine/nucleo-l031k6/ https://tinygo.org/docs/reference/microcontrollers/machine/nucleo-f722ze

Thank you for your consideration of this fix/enhancement.

rayozzie avatar Nov 24 '21 16:11 rayozzie

@kenbell I was looking at this briefly, and saw that we are using some constant values based on clock speed generated by STM32CubeMX. We could keep doing this as an interim solution if we can also generate those 4 values for the typical standard and fast mode speeds for each of the boards this is currently being used for.

I was looking at STM32CubeMX but it was not immediately obvious how to regenerate those values. Could you show me how you did that and/or help out to generate values for the various getFreqRange() functions?

deadprogram avatar May 06 '24 10:05 deadprogram

@deadprogram you first have to set the peripheral clock to the correct MHz in the 'Clock Configuration' tab. For L432, it's this (80MHz on PCLK1): image

Resolve the clock configuration.

Then enable I2C1 peripheral, you'll now see in gray the magic value in the 'timing' setting (0x10909CEC in this case for 100kHz standard mode): image

kenbell avatar May 06 '24 10:05 kenbell

Thanks @kenbell that is exactly what I was looking for. PR coming later.

deadprogram avatar May 06 '24 13:05 deadprogram

Merged into dev, tagged to close on next release. Thanks @rayozzie for report and to @kenbell for helping me out.

deadprogram avatar May 08 '24 08:05 deadprogram

This was released with v0.32.0 so now closing. Thank you everyone!

deadprogram avatar Jun 23 '24 17:06 deadprogram