Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8374

Interfacing (DSI, CSI, I2C, etc.) • RPI5 PIO. Two calls of pio_sm_set_consecutive_pindirs.

$
0
0
I have a problem with a simple PIO program on RPI5 (RP1).
It was working before, but sometimes it was unstable. That means some runs were error-free (in console), but there were no signals on the GPIO pins.
I suspect that I'm configuring the pins incorrectly. I have tried many versions without success. Currently, I have a version that is permanently not working.

Code:

// -------------------------------------------------- //// This file is autogenerated by pioasm; do not edit! //// -------------------------------------------------- //#pragma once#if !PICO_NO_HARDWARE#include "hardware/pio.h"#endif// --------- //// pio_test_2 //// --------- //#define pio_test_2_wrap_target 0#define pio_test_2_wrap 4static const uint16_t pio_test_2_program_instructions[] = {            //     .wrap_target    0x80a0, //  0: pull   block           side 0         0xe03f, //  1: set    x, 31           side 0         0x6002, //  2: out    pins, 2         side 0         0x1042, //  3: jmp    x--, 2          side 1         0x0000, //  4: jmp    0               side 0                 //     .wrap};#if !PICO_NO_HARDWAREstatic const struct pio_program pio_test_2_program = {    .instructions = pio_test_2_program_instructions,    .length = 5,    .origin = -1,};static inline pio_sm_config pio_test_2_program_get_default_config(uint offset) {    pio_sm_config c = pio_get_default_sm_config();    sm_config_set_wrap(&c, offset + pio_test_2_wrap_target, offset + pio_test_2_wrap);    sm_config_set_sideset(&c, 1, false, false);    return c;}static inline void pio_test_2_program_init(PIO pio, uint sm, uint offset, uint pin) {    pio_sm_config c = pio_test_2_program_get_default_config(offset);    // Map the state machine's OUT pin group to one pin, namely the `pin`    // parameter to this function.    sm_config_set_out_pins(&c, pin, 2);     sm_config_set_sideset_pins(&c, 6);    sm_config_set_out_pins(&c, 6, 1);    // Set this pin's GPIO function (connect PIO to the pad)    pio_gpio_init(pio, pin+0);    pio_gpio_init(pio, pin+1);    pio_gpio_init(pio, 6);    // Set the pin direction to output at the PIO    pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, true);    pio_sm_set_consecutive_pindirs(pio, sm, 6, 1, true);    //pio_sm_set_pindirs_with_mask(pio, sm, (1u << pin) | (1u << 3), 0);    sm_config_set_out_shift(&c, false, true, 32);    sm_config_set_in_shift(&c, false, true, 32);    sm_config_set_clkdiv(&c, 14);      // Load our configuration, and jump to the start of the program    pio_sm_init(pio, sm, offset, &c);    // Set the state machine running    pio_sm_set_enabled(pio, sm, true);}#endif
My main.c initialization is this:

Code:

    pio_0 = pio0;    sm_0 = pio_claim_unused_sm(pio_0, true);    pio_sm_config_xfer(pio_0, sm_0, PIO_DIR_TO_SM, 1024, 1);    pio_sm_set_enabled(pio_0, sm_0, false);    pio_sm_clear_fifos(pio_0, sm_0);    pio_sm_restart(pio_0, sm_0);    offset = pio_add_program(pio_0, &pio_test_2_program);        gpio = 2;    if (argc == 2)        gpio = (uint)strtoul(argv[1], NULL, 0);    printf("PIO Test, using pin %d\n", gpio);    printf("Loaded program at %d, using sm %d\n", offset, sm_0);    pio_test_2_program_init(pio_0, sm_0, offset, gpio);
And in while loop:

Code:

    pio_buffer_0[0] = 0x55556789;    pio_buffer_0[1] = 0xA5556789;    pio_buffer_0[2] = 0xB5556789;    pio_buffer_0[3] = 0xC5556789;    pio_sm_xfer_data(pio_0, sm_0, PIO_DIR_TO_SM, 64, pio_buffer_0);
The goal is to get data on GPIO2 and GPIO3, and a clock signal on GPIO6. The clock signal is present, but the data is not.
I have the GPIO6 pin number hardcoded, and I pass the GPIO2/3 pins as parameters.
I have tried swapping the pins (e.g., CLK on GPIO2, and data on 3 and 4), and the clock signal is always present, so the GPIO2, 3, 4, and 6 pins are electrically functional. The only problem is in the PIO configuration.
My main suspicion is as follows:
1. Is it possible to use the function sm_config_set_out_pins twice? I need this because GPIO6 is further away than pins 2 and 3 (there is no continuity).
So I use:
sm_config_set_out_pins(&c, pin, 2);
sm_config_set_sideset_pins(&c, 6);
sm_config_set_out_pins(&c, 6, 1);
2. Is it possible to use pio_sm_set_consecutive_pindirs twice? For the same reason?
3. is sm_config_set_out_pins(&c, 6, 1); necessary for sideset CLK pin?
4. Or maybe there is some other problem? Can someone do an idiot check by looking at this program?
Thank you in advance!

Statistics: Posted by uc_man — Sat Dec 13, 2025 11:18 am



Viewing all articles
Browse latest Browse all 8374

Trending Articles