pru coding and Debian 13

So I’ve been working on doing some experimenting with the PRU processors on the BBB with the newer 6.19 kernels. However I’ve tried to get libpruio to build without success. The TI tools seem to be a little dated too. I did get FreeBasic installed, and I got am335x_pru_package to build and install pasm. The ti pru-software-support-package is missing for the pro-cookbook-code.

At present what would be the best method to get the PRU coded up and interacting with the main processor? I plan on using C as I have an existing project I would like to switch from libgpiod to using the PRU.

I use gnupru which you can just install on the beagle2. There are example codes in pru-gcc-examples. To run IIR just copy into /lib/firware/am62x-pru0-fw and am62x-pru1-fw then load via the standard process.

1 Like

I tried gnupru and the package doesn’t exist, so then I downloaded the archive and unpacked that. I haven’t been able to get the examples to build from that project though.

I have been able to locate the ti git repo for the pru-software-support-package and I installed that and got the pru-cookbook-code compiling. I updated to the 6.19 kernel, and I did a git clone of git@github.com:beagleboard/BeagleBoard-DeviceTrees.git

Then I added:

/*
 * Configure PRU i/o pins
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/am33xx.h>

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */
&{/chosen} {
        overlays {
                BB-PRU-PIN2-CONFIG.kernel = __TIMESTAMP__;
        };
};

/*
 * Free up the pins used by the cape from the pinmux helpers.
 */
&ocp {
        P9_27_pinmux { status = "disabled"; };  /* mcasp0_fsr */
};

&am33xx_pinmux {
        bb_pru_pins: pinmux_pru_pru_pins {
                pinctrl-single,pins = <
                         AM33XX_PADCONF(AM335X_PIN_MCASP0_FSR, PIN_OUTPUT_PULLDOWN , MUX_MODE5) /* P9_27 PRU0 pr1_pru0_pru_r30_5 output */
                >;
        };
};

&pruss_tm {
        status = "okay";
};

&pruss {
        status = "okay";
        pinctrl-names = "default";
        pinctrl-0 = <&bb_pru_pins>;
};

I then built and and installed these device tree objects, and I modified uEnv.txt to load the BB-PRU-PIN2-CONFIG.dtbo. Then in the pru-cookbook-code I modified the 06io example to:

// This code accesses GPIO without using R30 and R31
#include <stdint.h>
#include <pru_cfg.h>
#include "resource_table_empty.h"
#include "prugpio.h"

#define P9_11   (0x1<<19)                       // Bit position tied to P9_11 on Black
#define P2_05   (0x1<<30)                       // Bit position tied to P2_05 on Pocket

volatile register uint32_t __R30;
volatile register uint32_t __R31;

void main(void)
{
        uint32_t *gpio1 = (uint32_t *)GPIO2;

        while(1) {
                gpio1[GPIO_SETDATAOUT]   = P9_11;
                __delay_cycles(100000000);
                gpio1[GPIO_CLEARDATAOUT] = P9_11;
                __delay_cycles(100000000);
        }
}

I wasn’t sure if the output was on GPIO3 or GPIO2 because it is listed differently in the gpioinfo than the documentation. The code should be toggling P9_27, but it is not working.

I checked the /proc/device-tree/chosen/overlays/, and the contents are:

BB-ADC-00A0.kernel  BB-BONE-eMMC1-01-00A0.kernel  BB-NHDMI-TDA998x-00A0.kernel  BB-PRU-PIN2-CONFIG.kernel  BB-UART4-00A0.kernel  name

My C code was incorrect, but here is a fixed version.

I checked that the pin in the device tree matched what the PRU is programmed for. PRU GPIO3 is the same as GPIO2 in the linux kernel. However I’m still not getting the output to toggle.

// This code accesses GPIO without using R30 and R31
#include <stdint.h>
#include <pru_cfg.h>
#include "resource_table_empty.h"
#include "prugpio.h"

volatile register uint32_t __R30;
volatile register uint32_t __R31;

void main(void)
{
        uint32_t *gpio = (uint32_t *)GPIO3;

        while(1) {
                gpio[GPIO_SETDATAOUT]   = P9_27;
                __delay_cycles(100000000);
                gpio[GPIO_CLEARDATAOUT] = P9_27;
                __delay_cycles(100000000);
        }
}