libpruio (BB D/A - I/O fast and easy)

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
thegame
Posts: 4
Joined: May 25, 2021 9:27

Re: libpruio (BB D/A - I/O fast and easy)

Post by thegame »

In the build tree you can add option -R to the compiler flags. Then fbc will create a C source file from the FreeBASIC code. Just #include that file in to your LKM code. Once working, you can drop the bloat.
I will try that.
Did you consider using the second PRUSS for IRQ handling? This should work up to ~1 MHz without losses.
But that would still leave me with the UDP part. But you are right, that would probably eliminate the IRQ loss if implemented properly.
maybe I look into this once the ADC part is working ........

Thanks!
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

Hi TJF,
i found your great libpruio and started testing it for a project i'd like to implement in my BBB (an ATA Cape disk emulator), but since i'm not familiar with Linux nor BBB (since now i used only arduino's hw), i can't even start using your library!
The first difficult i found is in setting the overlays, i'm on 4.19.94-ti-r42 and i can't found capemgr and other uEnv.txt setting working with the info i get here or in the online documentation.
Anyway, i can compile and run some examples, but don't work: 1.bas run fine with showing values, SOS start and write to console the chars but i've no usr led blinking!
i made some test adding both universal.bas and custom.bas dtbo files to /firmware folder and adapting uEnv.txt, but with no success.
So, i wonder if you (or some other users) can reupload a working uSD image (the one you posted some pages ago is no more available) to start with a stable base.
Thank you in advance!
TJF
Posts: 3764
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Hi aotta, welcome to the forum!
aotta wrote: Apr 09, 2022 11:201.bas run fine with showing values, SOS start and write to console the chars but i've no usr led blinking!
It seems that you have the uio_pruss driver working (in /boot/uEnv.txt), but no pinmuxing capability.

I recommend to install the LKM (loadable kernel module) solution, in order to get unlimited pinmuxing features from user space (for single source development). Did you try this yet? Any issues? If so, how did you install?
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

Thank you TJF,
i installed LKM and a custom dtbo made with dts_custom.bas and made SOS working for an external GPIO (P8_11)!!

Then, added P8_24 to custom dts (and just disabled emmc overlay in uEnv.txt, never know...) for defining USR3 led as GPIO too, but still doesn't work with USRx leds.
I'll made further test, but if you have some hints to try, il'll happy to try them!

I'd like to ask you some further help: my goal is to have 16 pin (from the pin used by hdmi that's not needed) in Input/Output mode, and assign them direction by software (for sharing data with an ATA controller, via two 27lvc245 level shifter).
It's possible realize that with libpruio and custom_dts? i'll have to use the pri assembler (that i don't know)?
Thank you in advance for helping!
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

solved the USRx led not working in SOS.bas!
added this lines to pruio_pins.bi:

Code: Select all

'* CPU ball number for USR0
#DEFINE USR0 &h15
'* CPU ball number for USR1
#DEFINE USR1 &h16
'* CPU ball number for USR2
#DEFINE USR2 &h17
'* CPU ball number for USR3
#DEFINE USR3 &h18
and added USR3 to dts_custom.bas for claiming the pin!

Now sos works fine with user leds too! :D
TJF
Posts: 3764
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

aotta wrote: Apr 10, 2022 9:21... i installed LKM and a custom dtbo made with dts_custom.bas ...
Once you have the LKM working, you wont need a custom dtbo. You can do any pinmuxing without dtbo. But finally, when the used pins are defined and you designed your PCB, you should generate and install a custom dtbo just claiming the pins (in order to inform the kernel about the used pins).
aotta wrote: Apr 10, 2022 9:21... my goal is to have 16 pin (from the pin used by hdmi that's not needed) in Input/Output mode, and assign them direction by software (for sharing data with an ATA controller, via two 27lvc245 level shifter).
It's possible realize that with libpruio and custom_dts?
You can configure those pins either as input or output as normal GPIO (with L3 latency).
aotta wrote: Apr 10, 2022 9:21i'll have to use the pri assembler (that i don't know)?
What's pri assembler?

If you need fast GPIO (1 PRU cycle latency) you'll need the PRU assembler (named PASM) code. Find a list of the pins at
https://users.freebasic-portal.de/tjf/P ... SecPruGpio
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

TJF wrote: Apr 10, 2022 15:23
aotta wrote: Apr 10, 2022 9:21... i installed LKM and a custom dtbo made with dts_custom.bas ...
Once you have the LKM working, you wont need a custom dtbo. You can do any pinmuxing without dtbo. But finally, when the used pins are defined and you designed your PCB, you should generate and install a custom dtbo just claiming the pins (in order to inform the kernel about the used pins).
i had LKM service working, but i had to use custom dtbo for pinmuxing the usr3 led. So, with LKM there's a different way to pinmuxing? i didn't find any example using this module, so i'll have to study more...
TJF wrote: Apr 10, 2022 15:23
aotta wrote: Apr 10, 2022 9:21... my goal is to have 16 pin (from the pin used by hdmi that's not needed) in Input/Output mode, and assign them direction by software (for sharing data with an ATA controller, via two 27lvc245 level shifter).
It's possible realize that with libpruio and custom_dts?
You can configure those pins either as input or output as normal GPIO (with L3 latency).
Thank you, so i could change direction at runtime? with LKM, i presume?
TJF wrote: Apr 10, 2022 15:23
aotta wrote: Apr 10, 2022 9:21i'll have to use the pri assembler (that i don't know)?
What's pri assembler?
If you need fast GPIO (1 PRU cycle latency) you'll need the PRU assembler (named PASM) code. Find a list of the pins at
https://users.freebasic-portal.de/tjf/P ... SecPruGpio
sorry, my typo, i was talking about PRU assembler, of course! :lol:
TJF
Posts: 3764
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

aotta wrote: Apr 10, 2022 15:42i had LKM service working, but i had to use custom dtbo for pinmuxing the usr3 led. So, with LKM there's a different way to pinmuxing? i didn't find any example using this module, so i'll have to study more...
Just remove the custom dtbo file from the /boot/uEnv.txt file. When the LKM is realy working, nothing should change. (Test with button2 example, there's a GPIO.config missing in sos example.)
aotta wrote: Apr 10, 2022 15:42 Thank you, so i could change direction at runtime? with LKM, i presume?
Yes, but changing direction is slow (the ARM has to call the LKM). For fast PRU-GPIO this means the PRU has to stop and wait for the ARM finishing the task.

BTW: changing direction also work with universal dtbo, but is slower than LKM.
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

TJF wrote: Apr 10, 2022 16:14
aotta wrote: Apr 10, 2022 15:42i had LKM service working, but i had to use custom dtbo for pinmuxing the usr3 led. So, with LKM there's a different way to pinmuxing? i didn't find any example using this module, so i'll have to study more...
Just remove the custom dtbo file from the /boot/uEnv.txt file. When the LKM is realy working, nothing should change. (Test with button2 example, there's a GPIO.config missing in sos example.)
No luck: removing the custom dtbo file from uEnv.txt i got "initialisation failed (parsing kernel claims)" error when launching sos (with or without sudo).
So my LKM seems not working... i had to reinstall it (i wget it from your debian jessie site and installed with dpkg -i), since it first didn't found header kernel. Sencond time installer seemed to worked fine and generate new kernel module (and showing as last message the warning about it may avoid system to boot).
With systemctl command i found the module as "loaded active exited".
Some other test to check what's wrong with LKM? sorry to boring you, but i've no others ideas to try.
TJF
Posts: 3764
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

aotta wrote: Apr 10, 2022 17:03(i wget it from your debian jessie site and installed with dpkg -i)
That's not the latest version. It isn't prepared for the 4.19 kernel, in which a sysfs path changed.

As a work-around you can create a symlink in folder /sys/kernel/debug/pinctrl/ named
44e10800.pinmux
pointing to folder
44e10800.pinmux-pinctrl-single

Or compile from latest source at https://github.com/DTJF/libpruio.
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

TJF wrote: Apr 11, 2022 3:53
aotta wrote: Apr 10, 2022 17:03(i wget it from your debian jessie site and installed with dpkg -i)
That's not the latest version. It isn't prepared for the 4.19 kernel, in which a sysfs path changed.

As a work-around you can create a symlink in folder /sys/kernel/debug/pinctrl/ named
44e10800.pinmux
pointing to folder
44e10800.pinmux-pinctrl-single

Or compile from latest source at https://github.com/DTJF/libpruio.
made dozens of try, but no way to have lkm working.. i downgraded to 4.14 kernel (the bone 9.5 deb found on beaglebone site) and used your script in previous page (but added an install to linux headers, becouse the dependencies add and install a 4.4 header!), also compiled from source tree...
Always no error, but usr led (and gpio) works only if loaded a dtbo custom cape.
I'd like to test with the 9.6 you used for test, but it's no more available on the net.
Please, someone could upload a working image with lkm working, for testing if it's something wrong on my bbbw?
[edited]
Just an update, after further test: LMK is working fine! i made some changes to SOS.bas code to configure new pin "on the fly" using io->setPin(io, PIN, 7) and changed setValue(PIN,1) to power on led and setValue(PIN,0) to turn it off.
I don't know why the "original" sos.bas doesn't work with usr3 led, but now it seems to me a minor issue... i'll go through new test, thank you TJF for all support until now!
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

Final update for who may follow my step in testing LKM environment: get finally SOS.bas working, uncommenting the code as in github:
from

Code: Select all

'* Create a PruIo instance, wakeup only GPIO-1 subsystem, ignore kernel claims.
'VAR io = NEW PruIo(PRUIO_ACT_FREMUX OR PRUIO_ACT_GPIO1)
VAR io = NEW PruIo()
to

Code: Select all

'* Create a PruIo instance, wakeup only GPIO-1 subsystem, ignore kernel claims.
VAR io = NEW PruIo(PRUIO_ACT_FREMUX OR PRUIO_ACT_GPIO1)
'VAR io = NEW PruIo()
at first it was not clear to me i had to change the source for claiming the pin to system.... :D
Well, now i can study more this great library and start develop my project!
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

Hi TJF,
i'm trying to use "simultaneos GPIO" tips for reading, writing and redirectory pins on GPIO2 subsystem, following the suggestione in your Wiki but can't get it work as expected and didn't find any example about OE register usage.
I tried to get some help from chapter 25, but with no luck.. so you could give us some more info.

First of all, for having some result, i had to use Cleardataout inverted from Setdataout, so i wrote:

Code: Select all

     Io->Gpio->Conf(2)->SETDATAOUT AND= mask
     Io->Gpio->Conf(2)->CLEARDATAOUT OR= NOT mask

instead of your:

Code: Select all

Io->Gpio->Conf(2)->SETDATAOUT    OR= mask
Io->Gpio->Conf(2)->CLEARDATAOUT AND= NOT mask
Second question: OE seems work when GPIO set as input and after changed by OE register, but doesn't work for me if GPIO first set as output.
So, in general, how i should define the GPIO Pin before change direction with OE? how can i set the pullup-pullout options?
Last stupid question, is why you suggest to use Mix register for reading multiple pins and not the DATAIN register? since i get an "inverted" reading from the IDE port i connected to my cape in my project, i wonder if i missed somethings...

Thank you in advance if you can give some advice!
TJF
Posts: 3764
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Hi aotta!
aotta wrote: May 14, 2022 12:30 First of all, for having some result, i had to use Cleardataout inverted from Setdataout, so i wrote:

Code: Select all

     Io->Gpio->Conf(2)->SETDATAOUT AND= mask
     Io->Gpio->Conf(2)->CLEARDATAOUT OR= NOT mask

...
Second question: OE seems work when GPIO set as input and after changed by OE register, but doesn't work for me if GPIO first set as output.
The Io->Gpio->Conf([0-3])->xxx member variables are used only once in the Io->Config() call. Later, when running in the main loop, they have no effect unless you update the registers by performing a GPIO command on the PRU. Therefor use a code fragment similar as in the source of function GpioUdt::setGpioSs() (where Indx is the number of your GPIO subsystem):

Code: Select all

   WITH *Top
     PruReady(1) ' wait, if PRU is busy (should never happen)
     .DRam[5] = Conf(Indx)->OE
     .DRam[4] = Conf(Indx)->SETDATAOUT
     .DRam[3] = Conf(Indx)->CLEARDATAOUT
     .DRam[2] = Conf(Indx)->DeAd + &h100
     .DRam[1] = PRUIO_COM_GPIO_CONF SHL 24
     END WITH
aotta wrote: May 14, 2022 12:30 So, in general, how i should define the GPIO Pin before change direction with OE? how can i set the pullup-pullout options?
Set your start configuration as usual by Io->Gpio->SetValue() for an output pin and Io->Gpio->Config() for an input pin, before the call to Io->Config().

In order to change pullup/pulldown resistors when running in the main loop, use Io->setPin_save() function.

Regards
aotta
Posts: 10
Joined: Apr 07, 2022 18:07

Re: libpruio (BB D/A - I/O fast and easy)

Post by aotta »

Thank you TJF,
i missed a lot of info, and this one in particular:
TJF wrote: May 16, 2022 17:48 The Io->Gpio->Conf([0-3])->xxx member variables are used only once in the Io->Config() call. Later, when running in the main loop, they have no effect unless you update the registers by performing a GPIO command on the PRU.
But i showed in my post only the 2 line where coding the Set and clear dataout registers, and i used them in a sequence DRam[5] to DRam[1] like in your example, so it's not clear for me: the GPIO command to give for update registers, is the PRUIO_COM_GPIO_CONF SHL24 ones (and for me seems to work in this way), or i have to give a further command to PRU for having registers update?
Again, thank for your work and your help to all users!
Post Reply