Hi,
I'm trying to figure out how sideset works.
I created a super simple example, which uses sideset feature to blink the default LED, but I can't figure out why it doesn't work ...
These are the source code:
led.piomain.cppIn the console log I can see the right values, but the LED remains always ON ....
I'm trying to figure out how sideset works.
I created a super simple example, which uses sideset feature to blink the default LED, but I can't figure out why it doesn't work ...
These are the source code:
led.pio
Code:
.program led.side_set 1.wrap_target out x, 32 side 1 // led on, while it waits for pio_sm_put_blocking ? in x, 32 side 0 // led off, while it waits for pio_sm_get_blocking ?.wrapCode:
#include <hardware/pio.h>#include <hardware/timer.h>#include <tusb.h>#include <cstdio>#include "led.pio.h"namespace {#define pio pio0int sm;void setup_led_pio() { sm = pio_claim_unused_sm(pio, true); auto offset = pio_add_program(pio, &led_program); pio_sm_config c = led_program_get_default_config(offset); sm_config_set_clkdiv(&c, 1); sm_config_set_sideset_pins(&c, PICO_DEFAULT_LED_PIN); pio_gpio_init(pio, PICO_DEFAULT_LED_PIN); pio_sm_set_consecutive_pindirs(pio, sm, PICO_DEFAULT_LED_PIN, 1, true); // Auto pull/push sm_config_set_in_shift(&c, true, true, 32); sm_config_set_out_shift(&c, true, true, 32); pio_sm_init(pio, sm, offset, &c); pio_sm_set_enabled(pio, sm, true); pio_sm_drain_tx_fifo(pio, sm);}} // namespace {void main(){ stdio_init_all(); while (!tud_cdc_connected()) sleep_ms(100); setup_led_pio(); uint32_t data = 0; while(true) { pio_sm_put_blocking(pio, sm, data++); busy_wait_ms(500); uint32_t dat = pio_sm_get_blocking(pio, sm); printf("%lx\n", dat); busy_wait_ms(500); }}Statistics: Posted by bog_dan_ro — Sun Jun 22, 2025 4:08 pm — Replies 1 — Views 55