strange issue where PRU1 is not loaded from boot, but works from terminal when program is ran

Hi,

I have a basic application which use PRU1. program works 100% when executes as “root” from user space (via putty).
I have a bash start up script, which synchronizes with RTC and executes my program.
cat /usr/share/rtc_ds3231/clock_init.sh

#!/bin/bash
sleep 15
echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
hwclock -s -f /dev/rtc1
hwclock -w
/home/myprogram

as a result, the time synch is working, the program executes (ps ax|grep myprogram) shows it running; though no PRU1 activity.
I need to login as root (via putty) kill the process and start is again (as root), and it works just fine. Literally no other actions are taken, killing the program multiple times still results in 100% operation each time.
ps ax|grep myprogram
kill -9 myprogramPID
/home/myprogram &

Kind help would be most appreciated
Thank You

How do you invoke the startupscript? (Maybe it's to early during boot.)

running BeagleBoard.org Debian Image 2015-03-01

startup (from https://learn.adafruit.com/adding-a-real-time-clock-to-beaglebone-black/set-rtc-time) is invoked via;

systemd
bash script has a delay, increased it to 2 min still same non-running of the PRU.

given the large delay; I have logged in and checked, program was not running
I executed it(via putty), and it ran 100% fine.

I killed the program, waited for the start-up script to kick in
the start up script executed the program and its running fine.

kinda not sure where to next?

to recap
I login(via putty)
    ps ax|grep myprogam 
does not show my program running
I execute program
    cd /home
    myprogam & 

I kill the program
   kill -9 myprogramPID

2 minutes pass, and the program executes and runs 100% good.

If I **restart** login(via putty) and wait 2 minutes, the program executed but no PRU activity.

I do get, error below consistently upon boot-up, but does not seem to effect the operation of the PRU.
root@beaglebone:~# dmesg|grep pru
[    8.606803] omap_hwmod: pruss: failed to hardreset
root@beaglebone:~#

if someone who has the time and know how, could quickly test would be appreciated;
I have made a quick program, which uses the user LEDs

same behavior; works great when executed from console, does not work when executed at boot time

main.cpp
//********
#include <stdio.h>
#include <stdlib.h>
#include <prussdrv.h>
#include <pruss_intc_mapping.h>
#include <pthread.h>
#include <unistd.h>

#include
#include
#include

using namespace std;

#define LED0_PATH “/sys/class/leds/beaglebone:green:usr0”
#define LED1_PATH “/sys/class/leds/beaglebone:green:usr1”
#define LED2_PATH “/sys/class/leds/beaglebone:green:usr2”
#define LED3_PATH “/sys/class/leds/beaglebone:green:usr3”

#define PRU_NUM 1

static void *PRU1DataMemory;
static unsigned int *PRU1DataMemory_int;

void removeTrigger(){
// remove the trigger from the LED
std::fstream fs;
fs.open( LED0_PATH “/trigger”, std::fstream::out);
fs << “none”;
fs.close();
fs.open (LED0_PATH “/brightness”, std::fstream::out);
fs << “0”;
fs.close();

fs.open( LED1_PATH “/trigger”, std::fstream::out);
fs << “none”;
fs.close();
fs.open (LED1_PATH “/brightness”, std::fstream::out);
fs << “0”;
fs.close();

fs.open( LED2_PATH “/trigger”, std::fstream::out);
fs << “none”;
fs.close();
fs.open (LED2_PATH “/brightness”, std::fstream::out);
fs << “0”;
fs.close();

fs.open( LED3_PATH “/trigger”, std::fstream::out);
fs << “none”;
fs.close();
fs.open (LED3_PATH “/brightness”, std::fstream::out);
fs << “0”;
fs.close();
}

void *threadFunction(void *value){
do {
std::fstream fs1;
int notimes = prussdrv_pru_wait_event (PRU_EVTOUT_1);
cout << "PRU event 1 " << notimes << endl << flush ;

fs1.open (LED1_PATH “/brightness”, std::fstream::out);
fs1 << “1”;
fs1.close();

sleep(3);
prussdrv_pru_clear_event (PRU_EVTOUT_1, PRU1_ARM_INTERRUPT);
} while (1);
}

int main (void)
{
if(getuid()!=0){
printf(“You must run this program as root. Exiting.\n”);
exit(EXIT_FAILURE);
}
pthread_t thread;
tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

std::fstream fs;

removeTrigger();
cout << “All LED’s off for 3 second” << endl;
sleep(3); //1 sec delay all LEDS off

// select whether it is on, off or flash
fs.open (LED0_PATH “/brightness”, std::fstream::out);
fs << “1”;
fs.close();

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

// Map PRU’s INTC
prussdrv_pruintc_init(&pruss_intc_initdata);

// Copy data to PRU memory - different way
prussdrv_map_prumem(PRUSS0_PRU1_DATARAM, &PRU1DataMemory);
PRU1DataMemory_int = (unsigned int *) PRU1DataMemory;
// Use the first 4 bytes for the number of samples
*PRU1DataMemory_int = 500;
// Use the second 4 bytes for the sample delay in ms
*(PRU1DataMemory_int+1) = 100; // 2 milli seconds between samples

// Load and execute binary on PRU
prussdrv_exec_program (PRU_NUM, “./timedelay.bin”);

fs.open (LED2_PATH “/brightness”, std::fstream::out);
fs << “1”;
fs.close();

if(pthread_create(&thread, NULL, &threadFunction, NULL)){
printf(“Failed to create thread!”);
}
int n = prussdrv_pru_wait_event (PRU_EVTOUT_0);
printf(“PRU program completed, event number %d.\n”, n);

// distance in inches = time (ms) / 148 according to datasheet
/* Disable PRU and close memory mappings */
prussdrv_pru_disable(PRU_NUM);
prussdrv_exit ();
fs.open (LED3_PATH “/brightness”, std::fstream::out);
fs << “1”;
fs.close();

return EXIT_SUCCESS;
}
//****************
timedelay.p → compiled with pasm -b timedelay.p, then chmod +x timedelay.bin ; place at folder /home/

.origin 0 // offset of the start of the code in PRU memory
.entrypoint START // program entry point, used by debugger only

// To signal the host that we’re done, we set bit 5 in our R31
// simultaneously with putting the number of the signal we want
// into R31 bits 0-3. See 5.2.2.2 in AM335x PRU-ICSS Reference Guide.

#define PRU0_R31_VEC_VALID 32;
#define PRU_EVTOUT_0 3
#define PRU_EVTOUT_1 4
#define PRU1_ARM_INTERRUPT 20

#define DELAY_SECONDS 2 // adjust this to experiment
#define CLOCK 200000000 // PRU is always clocked at 200MHz
#define CLOCKS_PER_LOOP 2 // loop contains two instructions, one clock each
#define DELAYCOUNT DELAY_SECONDS * CLOCK / CLOCKS_PER_LOOP

START:

// initialize loop counter
MOV r1, DELAYCOUNT
// wait for specified period of time
DELAY:
SUB r1, r1, 1 // decrement loop counter
QBNE DELAY, r1, 0 // repeat loop unless zero
// tell host we’re done
mov r31.b0, PRU1_ARM_INTERRUPT+16

MOV r1, DELAYCOUNT
// wait for specified period of time
DELAY2:
SUB r1, r1, 1 // decrement loop counter
QBNE DELAY2, r1, 0 // repeat loop unless zero
// tell host we’re done
mov r31.b0, PRU1_ARM_INTERRUPT+16

// initialize loop counter
MOV r1, DELAYCOUNT
// wait for specified period of time
DELAY1:
SUB r1, r1, 1 // decrement loop counter
QBNE DELAY1, r1, 0 // repeat loop unless zero

// tell host we’re done, then halt
mov r31.b0, PRU1_ARM_INTERRUPT+16 //int1
mov r31.b0, PRU1_ARM_INTERRUPT+15 //int0

HALT

executed by bash following instructions https://learn.adafruit.com/adding-a-real-time-clock-to-beaglebone-black/set-rtc-time
bash contents

8.6 s after boot starts seems still to be quite early. You can can
change the boot order in systemd e.g with Type=idle or with After=...
An alternative might be:
echo "@reboot root /pathto/myscript.sh" >> /etc/crontab
HTH

SOLUTION
the pru wasn’t finding the file, because path is not set


1. #!/bin/bash
1. sleep 45
1. **cd /home**

1. /home/main