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.

arm335x PRU GPI example: reading input

Hi,

I've recently started using the PRUs on my beaglebone. To start with, I want to write to the PRU GPOs and read from PRU GPIs which are pinned out to the p8 and P9 headers on the beaglebone. So far, I managed to get the writing to the GPOs part working. It's the reading from the GPIs, I'm having trouble with.

For example, say I want to read from P8 header pin #46 to which I input a square wave with a function generator. This corresponds to the signal GPIO_2_7.

I set the multiplexing of this signal to use the signal: pr1_pru1_pru_r31_1 which corresponds to multiplex mode 6. Then, in my PRU code, I try to read R31 and write it into PRU1 local DRAM as follows:

MOV r0, R31
SBCO r0, CONST_PRUDRAM, 0, 4

I expect to see the value at the memory location in the memory browser to toggle between 0x00000000 and 0x00000002 (toggling of bit 1). But, this is not happening and the value at the memory location stays at 0x00000000. There is no toggling as apparently I'm not reading the signal which is coming to that pin.

Can anyone point out if I'm missing something crucial ? I really don't see why this is not working. I did a very similar thing the other way around to toggle the GPO of the PRUs and measured it with an oscilloscope...

Thanks

  • Hi,

    As a starting point I would recommend the https://github.com/rjw245/am335x_pru_package repo. The 'inputtest' folder contains a snippet in which the state of a GPIO pin set as input is mirrored on another GPIO pin set as output. I have not tested the code myself, but it should be a good starting point.

    Regards.

  • OK, thanks. I'll check it out.. 

  • For reading the input, I'm setting up the multiplexing (mode 6) and reading the appropriate bit from r31 ? The reference code you mentioned seems to be doing just that.. (although I don't see in the code where they do the multiplexing to set up the PRU GP input and output pins) 

    As I mentioned, I managed to get the GPOs working. Are there any additional configurations to make the PRU GPIs to work ? Am I missing something here ? 

  • Setting the correct mux mode (mode 6) is all that is required.  

    As a quick test, you could eliminate any software and write directly to the Control Module and PRU registers manually in CCS.  For example, you can create a simple loopback test by connecting a pin supporting a PRU GPO (R30) signal to another pin supporting a PRU GPI (R31) signal.  After connecting to the device, manually set your pin mux.  After running the set-up PRU gel script included in the AM335x PRU package (see corresponding PRU debugger training slides also included in the package), you should be able to toggle the PRU GPO R30 signal and see the PRU GPI R31 signal change.

    Regards,

    Melissa

  • Hi Melissa, Thanks for the reply. I had to set the enable reception field along with the pin multiplexing and it's working now..

  • Hi locke14 - I'm having the same problem. Do you set this in the device tree, or somewhere else?  Could you post the code you needed to do that?

  • Hi,

    I used the GpioPinMuxSetup (unsigned int offsetAddr, unsigned int padConfValue) function in the starterware kit for doing the GPIO pin mux. It's defined in the file gpio.c of the starterware kit.

    To set GPIO_3_18  pin as an output pin for the PRU: 

    GpioPinMuxSetup(GPIO_3_18, CONTROL_CONF_MUXMODE(5));

    To set it as an input PRU pin: 

    GpioPinMuxSetup(GPIO_3_18, PAD_FS_RXE_NA_PUPDD(6));

    Hope that helps..

  • Hey - thanks for the response.  I'm not actually using the starterware, but trying to setup pins using the device tree to do the pin muxing, following this great post:

    http://www.element14.com/community/community/knode/single-board_computers/next-gen_beaglebone/blog/2013/05/22/bbb--working-with-the-pru-icssprussv2

    So I figured out how to do what you did - it turns out you need to Rx enable by setting bit 5.  See BBB ref. manual p88.

  • Could you share the simply program you describe here :

    MOV r0, R31
    SBCO r0, CONST_PRUDRAM, 0, 4

     

    I was starting with PRUS and I don't know how to start with ASM.

     

    Thank you