pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

Should we add pio_sm_set_pins_with_mask64 and pio_sm_set_pindirs_with_mask64?

Open peterharperuk opened this issue 1 year ago • 5 comments

If you try calling pio_sm_set_pins_with_mask or pio_sm_set_pindirs_with_mask with a gpio >= 32 you'll get a build error. You have to know to use pio_get_gpio_base when constructing the mask. Just wondering if it would be more obvious to add a 64bit version of these functions? We'd have to assert it was valid for the gpiobase?

peterharperuk avatar Aug 16 '24 11:08 peterharperuk

ha, yes, and indeed the existing (non-mask) functions are just plain broken it seems

kilograham avatar Aug 17 '24 00:08 kilograham

You mean pio_sm_set_pins? I hadn't noticed that. Might have to write some test code

peterharperuk avatar Aug 19 '24 09:08 peterharperuk

Hmm - I've just been hit with this one on a board I constructed. If any code needs to be tested I can run it here.

StijnKuipers avatar Sep 24 '24 14:09 StijnKuipers

Which function are you trying to use?

peterharperuk avatar Sep 24 '24 16:09 peterharperuk

I was trying to get this bit of code to output, ported from a RP2040 product ->

pio_sm_config c = toggleprog_program_get_default_config(offset);
pio_set_gpio_base(pio, 16);
    
pio_gpio_init(pio, LEDCLK);
pio_gpio_init(pio, LEDDAT);
pio_gpio_init(pio, LEDLAT);

#define ADJUST(x) ((x+16)%32) 
sm_config_set_out_pin_base(&c, ADJUST(LEDDAT));
sm_config_set_set_pin_base(&c, ADJUST(LEDDAT));
pio_sm_set_consecutive_pindirs(pio, sm, ADJUST(LEDDAT), 1, true);
pio_sm_set_consecutive_pindirs(pio, sm, ADJUST(LEDCLK), 2, true);

sm_config_set_sideset(&c, 2, false, false);

sm_config_set_sideset_pins(&c, ADJUST(LEDCLK));
sm_config_set_out_pins(&c, ADJUST(LEDDAT), 1);

sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
sm_config_set_clkdiv(&c, clk_div);
sm_config_set_out_shift(&c, false, true, 32);

 pio_sm_init(pio, sm, offset, &c);
 pio_sm_set_enabled(pio, sm,true);
    ```

StijnKuipers avatar Sep 25 '24 00:09 StijnKuipers

@StijnKuipers Just looked at your code again. The code looks correct on develop.

The following functions handle pins >= 32, do not adjust your pin numbers when calling them. sm_config_set_out_pin_base pio_sm_set_consecutive_pindirs sm_config_set_sideset_pins sm_config_set_out_pins

peterharperuk avatar Nov 19 '24 17:11 peterharperuk

The following functions handle pins >= 32, do not adjust your pin numbers when calling them. sm_config_set_out_pin_base

Doxygen at https://github.com/raspberrypi/pico-sdk/blob/develop/src/rp2_common/hardware_pio/include/hardware/pio.h#L263 says \param out_base 0-31 First pin to set as output so I guess that might need updating to avoid confusion?

Also, would you get a compile-time error if you tried doing both sm_config_set_out_pin_base(&c, 10) and sm_config_set_in_pin_base(&c, 40) ?

lurch avatar Nov 20 '24 01:11 lurch

see also #2085

kilograham avatar Nov 22 '24 03:11 kilograham

merged into develop

kilograham avatar Nov 22 '24 19:11 kilograham