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.

BEAGLEBK: Segmentation fault in a C program with function prussdrv_pruintc_init

Part Number: BEAGLEBK

Hello i require some assistance in solving a segmentation fault error. I am currently running debian 10.3 buster with the kernel 4.19.94-ti-r42. I have a c program that calls a PRU(programmable real time unit) program on my beaglebone black. The c program is and was compiled with:
gcc ledbutton.c -g ‐lpthread ‐lprussdrv

c program:

#include <stdio.h>
#include <stdlib.h>
#include <prussdrv.h>
#include <pruss_intc_mapping.h>
#include <unistd.h>

#define PRU_NUM 0   // using PRU0 for these examples

int main (void)
{
   if(getuid()!=0){
      printf("You must run this program as root. Exiting.\n");
      exit(EXIT_FAILURE);
   }
   // Initialize structure used by prussdrv_pruintc_intc
   // PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h
   tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

   // Allocate and initialize memory
   prussdrv_init ();
   prussdrv_open (PRU_EVTOUT_0);

   // Map PRU's interrupts
   prussdrv_pruintc_init(&pruss_intc_initdata);

   // Load and execute the PRU program on the PRU
   prussdrv_exec_program (PRU_NUM, "./ledButton.bin");

   // Wait for event completion from PRU, returns the PRU_EVTOUT_0 number
   int n = prussdrv_pru_wait_event (PRU_EVTOUT_0);
   printf("EBB PRU program completed, event number %d.\n", n);

   // Disable PRU and close memory mappings
   prussdrv_pru_disable(PRU_NUM);
   prussdrv_exit ();
   return EXIT_SUCCESS;
}

After compiling i receive a segmentation fault error. So i installed a gdb compiler to debug it and determine a possible source of error. using gdb ./a.out provides:

(gdb) run
Starting program: /home/debian/EBB_CH13/ledbutton/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0xb6f9f470 in prussdrv_pruintc_init () from /usr/lib/libprussdrv.so
(gdb) backtrace
#0  0xb6f9f470 in prussdrv_pruintc_init () from /usr/lib/libprussdrv.so
#1  0x00400880 in main () at ledbutton.c:30

The contents of libprussdrv.so is encrypted so i cant view it. The pru program (ledbutton.bin) is in the same directory and is the result of compiling a assembly program (ledbutton.p) that blinks a led. Here is the

texas instruments API reference: https://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader_API_Guide

I have ran each function individually and the segmentation faults is due to prussdrv_pruintc_init. I cant seems to find info on what return value would signify an error for the prussdrv_init and prussdrv_open but they compiled without error individually. The segmentation fault occurs when i run the executable with the command ./ledbutton 

Any help will be appreciated. Thank you 

  • Running the executable with the command ./ledbutton is what produces the segmentation fault not compiling. I have tried to run these functions individually: 
    prussdrv_init ();
    prussdrv_open (PRU_EVTOUT_0);

    an i got a segmentation fault when i ran the executable with ./ledbutton 

  • Hello Franklin,

    The prussdrv APIs were developed for PRU on OMAP-L138 (think of it like the grandfather of the PRU-ICSS in your AM335x). I am not sure whether they were ever tested on AM335x, but I can tell you that TI no longer supports those APIs.

    RemoteProc is a different method you can use to load and initialize the PRU cores from Linux. TI's RemoteProc documentation is here. You can find an example of using RemoteProc from a userspace program in the PRU Software Support Package under examples/am335x/PRU_ADC_onChip/pru_adc_userspace .

    Regards,

    Nick