rp2: Using machine.freq() changes UART speed and SPI sck. #13679
Replies: 4 comments 13 replies
-
That's what I was referring to. |
Beta Was this translation helpful? Give feedback.
-
Thanks @robert-hh for bringing up this discussion (or issue). I could not understand the impact to I2C and PWM. Can you possibly reword your original explanation please ? I have perceived this issue in a code developed some time ago an fixed the misbehaving with an uart.init(). I would never imagine that could be related to the use of machine.freq() used earlier in the code. After reading your post and doing a search on Pico SDK I found the following entries: Changing system clock sets peripheral clock to 48MHz #841 However the issue has been fixed in the SDK. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the links. I can try the suggested setting. But anyhow seems clocking UART from a fixed peripheral frequency the better choice, only that should be set at startup. Then the UART baud range is 50 to 3M, which is fine, and will not change with MCU freq setting. Being synchronous, a changing baud rate is less critical for I2C and SPI. |
Beta Was this translation helpful? Give feedback.
-
I made a PR #13718, setting the clock to 125MHz at boot and soft reset. As a side effect, this will set the peripheral freq to 48MHz. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Less and issue than an observation:
When using machine.freq() the peripheral clock seems to be changed from 125MHz to 48MHz. That change affects the speed of already created UART, SPI. Is does not matter to which value is used for machine.freq(). It may be the same that is already set. This change is persistent until a hard reset,
For I2C and PWM using machine.freq() causing a scl or freq change relating to the ratio of old/new frequency. Setting the freq to the same value as it was before does not change the I2C scl or PWM frequency.
Setting the device speeds again after changing the frequency is then needed for proper rate. The lower and upper limits will be changed. This behavior is not uncommon to ports. So at least it should be documented.
Maybe related to #8424.
Beta Was this translation helpful? Give feedback.
All reactions