I have seen that you added HAL support for the PIO units of the RP2040 and RP2350. Thank you for implementing that.
It took me some time, but I now have a PIO unit working with it. I'm eager to use your PIO HAL functions, because I had function/variable name clashes with PIO when using the pico-sdk in the past. Getting the PIO unit to run with the functions and CMSIS defines was straightforward.
But there was one issue that wasn't obvious to me from reading the datasheet or the code I previously used with the pico-sdk: When you want to output data on a pin, you have to set a PIO-specific output enable flag for the pin you want to output on. Unfortunately there is no register for this you can access from the CPU core, instead you have to execute a SET instruction with the PINDIRS destination for this. The pico-sdk does this for you as part of it's pio_sm_set_consecutive_pindirs() function.
What I now did was:
Code: Select all
pioSmSetExecctrlX(sm_ptr, PIO_SM_EXECCTRL_WRAP(offset+freq_out_wrap_target, offset+freq_out_wrap) | PIO_SM_EXECCTRL_SIDE_EN );
// one side-set output to pin 20, with side-set enable
pioSmSetPinctrlX(sm_ptr, (2U << PIO_SM_PINCTRL_SIDESET_COUNT_Pos) | \
(20U << PIO_SM_PINCTRL_SIDESET_BASE_Pos) | \
(1U << PIO_SM_PINCTRL_SET_COUNT_Pos) | \
(20U << PIO_SM_PINCTRL_SET_BASE_Pos));
#define PIO_INSTRUCTION_SET_CMD 0xe000U
#define PIO_INSTRUCTION_SET_DST_PINDIRS 0x04U
#define PIO_INSTRUCTION_SET_DST_Pos 5
// execute set pindirs once
// required to set the pin direction to output for sideset, this can't be controlled in another way
// this is also why the SET_BASE + SET_COUNT must be set above
pioSmExecX(sm_ptr, PIO_INSTRUCTION_SET_CMD | \
(PIO_INSTRUCTION_SET_DST_PINDIRS << PIO_INSTRUCTION_SET_DST_Pos) | \
1U);
Code: Select all
void pioSmPindirI(const rp_pio_sm_t *smp, uint32_t gpionr, bool output);
Do you think this is a good idea? Or do you have some other way of implementing this in mind?