This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM6546: Writing to GPO from PRU

Part Number: AM6546

We were trying to write to a GPO from a PRU core on our AM6546 SoC to drive data acquisition & conversion on an ADC. We found sample code on how to do this for other TI SoCs but did not find the same for the AM6546.

Could you point us to a good starting point to do the same.

  • Hello Dhruva,

    The AM65x GPO functionality using R30 should work like GPO on AM335x/AM437x/etc. We do not currently have a GPO example specifically for the AM65x, but you should be able to get it working by taking a look at current resources and at the AM65x Technical Reference Manual PRU Chapter, section "General-Purpose Outputs (R30): Enhanced PRU GP Module".

    example current resources include the PRU Software support package (in your Linux Processor SDK under example-applications/pru-icss-x.x.x or at the git repo) examples/am335x/PRU_gpioToggle, and the PRU Hands-on Labs.

    If you cannot get it working, feel free to post follow-up questions.

    Regards,

    Nick

  • Hi Nick,

    So would I be right in saying, that without any changes in the device-tree we should be able to write to the GPO register and get an output?

  • Dhruva,

    To help us better assist you, please provide us some details:

    • Which ICSSG?
    • Which PRU?
    • Which GPO?
    • What values have been written to what registers?
    • How are you checking the result, i.e. what pin are you looking at?
    • What is the pinmux value for that pin?

    Thanks,
    Brad

  • Brad,

    We were working with "PRG0_PRU0_GPO18" design signal pad name. Ball number 25. 

    We also tried to configure it as a GPIO (Muxmode 7 - GPIO1_47 <default> ) without our additional ADC circuitry.

    We added the following to &main_pmx0

    mygpio1_pins_default: mygpio1_pins_default {
    pinctrl-single,pins = <
    AM65X_IOPAD(0x023c, PIN_INPUT, 7) /* (V25) PRG0_PRU0_GPO18.GPIO1_47 */
    >;
    };

    We were hoping to get this working and then change the pinmux value.

    However after exposing the GPIO pin from the sysfs, we were unable to successfully write to it.  We were trying to echo 1 to the value-file of the gpio.

  • Dhruva Krishnadas said:
    We were working with "PRG0_PRU0_GPO18" design signal pad name. Ball number 25. 

    I assume you're talking about V25.

    Dhruva Krishnadas said:
    mygpio1_pins_default: mygpio1_pins_default {
    pinctrl-single,pins = <
    AM65X_IOPAD(0x023c, PIN_INPUT, 7) /* (V25) PRG0_PRU0_GPO18.GPIO1_47 */
    >;
    };

    You might be used to AM3/4/5 where there was only an input enable bit.  On AM6 there are enable bits related to both input and output.  In order to output on that pin you need PIN_OUTPUT, and if you wish to be able to see what's on the pin you also need the input, i.e. PIN_INPUT | PIN_OUTPUT.

    Please directly check the register value.  I see the following using the SDK 6.01 binaries:

    root@am65xx-evm:~# devmem2 0x0011c23c
    /dev/mem opened.
    Memory mapped at address 0xffffb2830000.
    Read at address 0x0011C23C (0xffffb283c23c): 0x08210007

    That value corresponds to neither the input nor output being enabled.  I made a quick update using devmem2:

    root@am65xx-evm:~# devmem2 0x0011c23c w 0x08050007
    /dev/mem opened.
    Memory mapped at address 0xffff893b0000.
    Read at address 0x0011C23C (0xffff893bc23c): 0x08010007
    Write at address 0x0011C23C (0xffff893bc23c): 0x08050007, readback 0x08050007

    This new value enables both input and output.  Now you can modify the GPIO from user space.  Some quick notes regarding the GPIO:

    • /sys/class/gpio/gpiochip0 -> Controls WKUP_GPIO[0-55]
    • /sys/class/gpio/gpiochip56 -> Controls GPIO0[0-95]
    • /sys/class/gpio/gpiochip152 -> Controls GPIO1[0-89]

    In your case you are trying to control gpio1_47.  So in terms of the Linux GPIO's, gpio152 corresponds to gpio1_0.  Therefore gpio1_47 is Linux gpio199.  Here's how I write it:

    root@am65xx-evm:~# cd /sys/class/gpio/
    root@am65xx-evm:/sys/class/gpio# echo 199 > export

    root@am65xx-evm:/sys/class/gpio# cd gpio199
    root@am65xx-evm:/sys/class/gpio/gpio199# ls
    active_low device direction edge power subsystem uevent value
    root@am65xx-evm:/sys/class/gpio/gpio199# cat direction
    in
    root@am65xx-evm:/sys/class/gpio/gpio199# echo out > direction
    root@am65xx-evm:/sys/class/gpio/gpio199# cat direction
    out
    root@am65xx-evm:/sys/class/gpio/gpio199# cat value
    0
    root@am65xx-evm:/sys/class/gpio/gpio199# echo 1 > value
    root@am65xx-evm:/sys/class/gpio/gpio199# cat value
    1

    Best regards,
    Brad

  • Thanks Brad. We were able to have reasonable success by modifying the pad configuration register (0x0011C23C) for ball number V25. We were able to output to the pin after setting muxmode as PRG0_PRU0_GPO18 (muxmode 0) and GPIO1_47 (muxmode 7) by setting pad configuration register using devmem2 program.

    However, we were hoping to set the pad configuration register by simply having the dtb file changed. However using an updated dtb ( with  mode set to PIN_OUTPUT|PIN_INPUT ) did not change the value of the pad configuration register.

    We also tried hard coding (without macros) 0x08010000 to the pad configuration register from the dts file but that did not work either.

    Also, are the .h and .c files generated by the pinmux tool of any use?

  • Dhruva Krishnadas said:
    However, we were hoping to set the pad configuration register by simply having the dtb file changed. However using an updated dtb ( with  mode set to PIN_OUTPUT|PIN_INPUT ) did not change the value of the pad configuration register.

    That's not sufficient.  Typically your pin array is passed in the dts as a phandle to some other driver.  It is that other driver that actually performs the pinmux update.  If you don't pass your phandle to any drivers, then nothing gets configured.

    That said, there's something called "gpio-hog" which allows for you to do what you want.  Please have a look at the device tree documentation of "gpio-hog" and look at some of the other dts files for an example.

    Dhruva Krishnadas said:
    Also, are the .h and .c files generated by the pinmux tool of any use?

    Those are for RTOS.

  • Thanks a lot Brad. We'll give that a try.