Example request: show how to use pio_sm_set_clkdiv()
I am trying to use the pio_sm_set_clkdiv() call in my code and had some questions about it. I had hoped to find an example of its use in the examples, but currently there are none. It might be useful to add it, perhaps as an option to the squarewave example, just to show how it works and how it is intended to be used.
There are examples of sm_config_set_clkdiv, and AIUI the difference is largely that you'd use sm_config_set_clkdiv to configure the StateMachine before starting it, whereas pio_sm_set_clkdiv would be used to modify the clock divider (see section 3.5.5 of https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf ) of a StateMachine that's already running?
Some clear delineation of the difference between sm_config_set_clkdiv and pio_sm_set_clkdiv and why one would use one versus the other would be helpful, both in the examples and in the SDK documentation.
Off the top of my head, I can't really think of a reason why you'd want to change the clock-divider on an already-running StateMachine, which is probably why all of the examples use sm_config_set_clkdiv.
Is there a specific reason why you want/need to use pio_sm_set_clkdiv?
I searched for a way to change the clock divider and happened upon pio_sm_set_clkdiv first and thought I could use it. The problem is that the documentation doesn't say anything about that only being useful after the state machine is running.
For what it's worth, I am currently using both in my program. I use sm_config_set_clkdiv to establish an initial reasonable value, but then I have a user menu in which the user can bump up the clock speed to see if the device under test (attached to the Pico) can still work at higher speeds; that one uses pio_sm_set_clkdiv because the state machine is already running.
Sorry for the inaccuracy in my earlier statement; pio_sm_set_clkdiv isn't only useful after the state-machine is running, it's just that the common usage-model in pico-sdk is to use the sm_config methods to set up the state-machines before you start them running (which IIRC is more efficient than using the pio_sm methods).
And that's just about the limit of my knowledge on this subject, so any further clarifications will have to come from @kilograham