Hello all,

I am working on a test-setup, which requires at least two pretty fast ADC 
inputs, like 100 kS/s or more. I worked with an Arduino until now, which is 
way to slow. So, I bought a BeagleBoard Green and intend to use libpruio 
for my project. Of course, the first step is to install the library on my 
board, which required a few tweaks to get working. You find my notes on 
what I did attached. I did a few other steps, like installing the 
am33x-pro-package from source, but I re-installed the Debian package after 
I found out the standard one is OK. As far as I can tell, the steps I 
documented should work on a cleanly installed board, but I can't guarantee 
that for the full 100%. 

I am running the shipped Debian image (Debian 7.10) with "Linux beaglebone 
3.8.13-bone71.1 #1 SMP Wed May 20 20:13:27 PDT 2015 armv7l GNU/Linux" on 
which I applied all updates using apt-get update & apt-get upgrade. I 
connected to the board using ssh over ethernet and did everything native on 
the board.

As a final note, I would suggest renaming the patched pasm to fbpasm or 
something, so that one does not need to overwrite the standard pasm in 
/usr/bin.

Best regards and thanks for this nice library!

-- Arend --


-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/65fd2c8c-f777-458a-b714-26e503d2fd78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
get fbc compiler for bootstrapping
    wget https://www.freebasic-portal.de/dlfiles/589/BBB_fbc-1.00.tar.bz2

    bzip2 -dc BBB_fbc-1.00.tar.bz2 | tar xv

    cd BBB_fbc-1.00/usr

    sudo cp -r * /usr

    git clone https://github.com/freebasic/fbc.git

    sudo make install-includes

get am33x-pro-package. Should be already there on BBG.
    sudo apt-get install am335x-pru-package

get prerequisites
    sudo apt-get install gcc libncurses5-dev libffi-dev libgl1-mesa-dev 
libx11-dev libxext-dev libxrender-dev libxrandr-dev libxpm-dev libgpm-dev

    make all

    sudo make install

After this, I did a make clean, make all and make install once again, to
make absolutely sure fbc is correctly built, since the compiler used for
bootstrapping is not the same version as the one we built and it does
not come with header files for the libraries. This might introduce
problems. So, this step should not be necessary, but better safe than
sorry....


---

Install FB prussdrv Kit (BBB)

git clone https://github.com/DTJF/fb_prussdrv.git

>From the Readme.md file:

        When you already installed am335x_pru_package, you can omit the
        libprussdrv part, but must override the pasm binary.

Since I don't like overwriting the pasm binary in /usr/bin, I copied it
to /usr/local/bin, which preceeds /usr/bin in my PATH:

    cd fb_prussdrv/
    sudo su
    cp bin/pasm /usr/local/bin
    mkdir /usr/local/include/freebasic/BBB
    cp include/* /usr/local/include/freebasic/BBB
    exit

Then, copy and test the overlay:

    sudo cp bin/PRUSSDRV-00A0.dtbo /lib/firmware

    sudo echo PRUSSDRV > /sys/devices/bone_capemgr.9/slots

This did not work for me...

Turns out that "ti,beaglebone-green" is not considered compatible with
this overlay, as reported by dmesg. A message like this is included for
all slots:

    bone-capemgr bone_capemgr.9: slot #11: Incompatible with baseboard for 
'PRUSSDRV'
    bone-capemgr bone_capemgr.9: slot #11: Failed verification

The source file for this dtbo is fb_prussdrv/examples/PRUSSDRV.dts
We need to patch this one to include the beaglebone-green by changing line 12 
from:

    compatible = "ti,beaglebone", "ti,beaglebone-black";

to:

    compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";

And then compile with:

    dtc -O dtb -o PRUSSDRV-00A0.dtbo -b 0 -@ PRUSSDRV.dts


We subsequently move the .dtbo to the bin directory and overwrite the
original, after which we install it:

    sudo su
    cp bin/PRUSSDRV-00A0.dtbo /lib/firmware
    echo PRUSSDRV > /sys/devices/bone_capemgr.9/slots
    exit

This works:

    arend@beaglebone:~/src/fb_prussdrv$ cat /sys/devices/bone_capemgr.9/slots 
     0: 54:PF--- 
     1: 55:PF--- 
     2: 56:PF--- 
     3: 57:PF--- 
     4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
     5: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-UART2
    12: ff:P-O-L Override Board Name,00A0,Override Manuf,PRUSSDRV


Now let's try the user_leds example, which must be run as root:

root@beaglebone:/home/arend/src/fb_prussdrv/examples# ./user_leds 

    INFO: Starting ./user_leds example.
    INFO: Executing example.
    INFO: example running, press any key.

It works!


----

Install libpruio

    wget https://www.freebasic-portal.de/dlfiles/592/libpruio-0.2.tar.bz2

    bzip2 -dc libpruio-0.2.tar.bz2 | tar xv

First, we patch pruiotools.bas in libpruio-0.2/src/config to include
"ti,beaglebone-green" platform by changing line 29 from:

    !"\n    compatible = ""ti,beaglebone"", ""ti,beaglebone-black"" ;" _

to:

    !"\n    compatible = ""ti,beaglebone"", ""ti,beaglebone-black"", 
""ti,beaglebone-green"" ;" _

And compile the "dts_universal" tool:

    fbc -w all dts_universal.bas

Which we run:

    ./dts_universal

This generates a "libpruio-00A0.dts", which now includes the
beaglebone-green platform, which we subsequently compile into dtbo
format:

    dtc -O dtb -o  libpruio-0A00.dtbo -b 0 -@ libpruio-00A0.dts


After this, we patch pruio_adc.bas in src/pruio according to:

https://groups.google.com/forum/#!msg/beagleboard/CN5qKSmPIbc/2UdstwjNhHMJ

-:-
So the limiting in the current libpruio-0.2 is too much on the safe
site. If you don't want to wait for the next version, you can adapt the
code by yourself (FreeBASIC compiler required). Replace in file
pruio_adc.bas in function PruIo.configure(...) the lines

      d *= (Conf->ADC_CLKDIV + 1) * 417 '417 = 1000000 / 2400 (= 1 GHz / 2.4 
MHz)
      d += 30 '                             PRU cycles for restart [GHz]
      IF Tmr <= d THEN     .Errr = @"sample rate too big" : RETURN .Errr

by the following code

      d = (d * (Conf->ADC_CLKDIV + 1) * 1000) \ 24
      IF Tmr <= d ORELSE Tmr < 5000 THEN _
                           .Errr = @"sample rate too big" : RETURN .Errr

You may play a bit with the absolute value 5000. On my BBB the timing is
OK up to a frequency of 240 kHz (4165). But this may vary from board to
board.
-:-

Then we use the provided scripts to build the library.

First, we execute "make.sh" in "src/pruio", which compiles the assembler
files. It seems we don't need "build.sh", which compiles the basic
files.

Then, we execute "build.sh" in "src/c_wrapper", which gives us the
"libpruio.so", which should include the above ADC patch. 

Now, we should be able to install the library, as said in:

http://users.freebasic-portal.de/tjf/Projekte/libpruio/doc/html/_cha_preparation.html#SecInstallation


    cd libpruio-0.2
    sudo su
    cp src/c_wrapper/libpruio.so /usr/local/lib
    ldconfig
    cp src/c_wrapper/pruio*.h* /usr/local/include
    cp src/config/libpruio-0A00.dtbo /lib/firmware
    cp src/pruio/pruio*.bi /usr/local/include/freebasic/BBB
    cp src/pruio/pruio.hp /usr/local/include/freebasic/BBB


Now, we should be able to load the overlay, but we get a write error:

    root@beaglebone:/home/arend/src/libpruio-0.2# echo libpruio > 
/sys/devices/bone_capemgr.9/slots
    bash: echo: write error: File exists

According to dmesg, this is due to a conflict with BB-UART2:

    bone-capemgr bone_capemgr.9: slot #9: Requesting firmware 
'libpruio-00A0.dtbo' for board-name 'Override Board Name', version '00A0'
    bone-capemgr bone_capemgr.9: slot #9: dtbo 'libpruio-00A0.dtbo' loaded; 
converting to live tree
    bone-capemgr bone_capemgr.9: slot #9: libpruio conflict P9.22 (#5:BB-UART2)
    bone-capemgr bone_capemgr.9: slot #9: Failed verification


After a reboot, we see that the BB-UART2 is still present and apparently
it's a driver for one of the Green's UART's: 

    arend@beaglebone:~$ cat /sys/devices/bone_capemgr.9/slots
     0: 54:PF--- 
     1: 55:PF--- 
     2: 56:PF--- 
     3: 57:PF--- 
     4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
     5: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-UART2

So, we have to disable BB-UART2, which is the UART for the Green's UART
grove connector. This is done in /boot/uEnv.txt where we change the
line:

    cape_enable=capemgr.enable_partno=BB-UART2

to:

    # AL 16/5/16: BB-UART2, the Grove UART, conflicts with libpruio, so
    # disable it:
    #cape_enable=capemgr.enable_partno=BB-UART2
    cape_disable=capemgr.disable_partno=BB-UART2
 
And reboot.

After reboot, we first load the uio_pruss kernel module:

    sudo modprobe uio_pruss

And load the overlay:

    arend@beaglebone:/boot$ sudo su
    root@beaglebone:/boot# echo libpruio > /sys/devices/bone_capemgr.9/slots
    root@beaglebone:/boot# cat /sys/devices/bone_capemgr.9/slots
     0: 54:PF--- 
     1: 55:PF--- 
     2: 56:PF--- 
     3: 57:PF--- 
     4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
     5: ff:P-O-L Override Board Name,00A0,Override Manuf,libpruio
    root@beaglebone:/boot# 


In order to test this, we build the examples and run some of them:

    arend@beaglebone:~/src/libpruio-0.2/src/examples$ ./_build_all.sh 
    arend@beaglebone:~/src/libpruio-0.2/src/examples$ sudo ./1
     E880 E770 E510 DEA0 D670 D280 D0A0 EF10
     EE80 E850 E630 E020 D8A0 D570 D3A0 EF20
     EEF0 E850 E660 E020 D8F0 D520 D2E0 EF40
     EE60 E780 E5A0 DF30 D740 D3B0 D220 EF40
     EE20 E780 E550 DEF0 D750 D340 D1E0 EF50
     EE30 E7A0 E5A0 DF30 D7B0 D3B0 D1F0 EF60
     EE70 E7B0 E550 DF30 D6E0 D290 D0A0 EF20
     EE20 E720 E480 DE00 D5A0 D1A0 CF80 EF40
     EE30 E700 E490 DE00 D5C0 D200 D060 EF20
     EE70 E740 E4E0 DE90 D620 D260 D0D0 EEF0
     EDD0 E7B0 E4D0 DE70 D680 D270 D0B0 EF10
     EE50 E760 E500 DEA0 D6A0 D280 D0C0 EF50
     EEC0 E7F0 E5B0 DF80 D7F0 D4A0 D320 EF40
    arend@beaglebone:~/src/libpruio-0.2/src/examples$ sudo ./sos
    watch SOS code on user LED 3 (near ethernet connector)

    execute the following command to get rid of mmc1 triggers
      sudo su && echo none > /sys/class/leds/beaglebone:green:usr3/trigger
    && exit

    press any key to quit
       
    arend@beaglebone:~/src/libpruio-0.2/src/examples$ 

It works!

Finally, I deleted the patched pasm from /usr/local/bin, so it won't
interfere with any other project I might do.

Reply via email to