Reading GPIO input from mem in PRU (BBB)

Hi

I found the following code and although it compiles the example app
never exits while waiting for HALT. And after that all other example
apps no longer work.

#define GPIO0 0x44e07000
#define GPIO1 0x4804c000
#define GPIO2 0x481ac000
#define GPIO_OE 0x134
#define GPIO_DATAIN 0x138

MOV r3, GPIO1 | GPIO_OE

LBBO r2, r3, 0, 4

SET r2, 12 // set bit 12

SBBO r2, r3, 0, 4

MOV r3, GPIO1 | GPIO_DATAIN

LBBO r2, r3, 0, 4 // Store register contents into r2

     // r2 contains of all GPIO1, so now you can inspect the value of
bit 12 as desired

HALT

can anyone tell what’s wrong or another way of doing this?
/Jacob

Looks like to me you just halted the PRU.

the comment: " // r2 contains of all GPIO1, so now you can inspect the value of
bit 12 as desired ", I think is a hint you need to do something (write some code) to look at the value of r2.

your say “I found the following code and although it compiles the example app
never exits while waiting for HALT” This sounds like you are referring to the program that loads and starts the Pru. Why don’t you show
all the code involved.

If you follow the examples in the am335x_pru_package, you will see the App-loader C program. The App-loader initializes a linux interrupt and the PRU INTC (interrupt controler) so the PRU can send an interrrupt to the linux program.

Are you doing something like this? if so, you are not sending the interrupt back to linix.

You can look at some PRU programs in the examples of the am335x_pru_package. For example, There is the “PRU_memAccessPRUDataRam” which shows the linux
program reading from the PRU data memory. Just put r2 from the example above into the PRU data memory and read in linux.

I modified the "PRU_memAccessPRUDataRam.p" with the interrupt code and
without the HALT command and now the code (and C program) exits
successfully.

But how do I send an interrupt the other way? Say I want the PRU to
run a loop until the C code reads a key input?

Or should I just do that using shared mem?

Thanks
/Jacob

You can look at some of the examples (the C program based on App-loader) at
https://github.com/jstampfl

The example PRU_memAccessPRUDataRam should exit with the halt, it is sending the interrupt “mov r31.t30” that sends the interrupt to the linux program.
You can program the loops and exits anyway you want. In fact you can start the p prpgram and exit the c program leaving the p running.