BBBCSIO
A C# I/O Library for the Beaglebone Black
Overview
About BBBCSIO
BBBCSIO is a free and open source .NET v4 library which provides a comprehensive C# input/output solution for the Beaglebone Black Mono environment.
Using BBBCSIO, you can easily read and write to the GPIO pins (and trigger interrupt events from state changes), launch and interact with PRU programs and
control SPI, I2C, PWM, UART and A2D devices. BBBCSIO is intended to be a comprehensive solution for I/O on the Beaglebone Black. At the current time only a few minor OCP devices remain to be implemented. Besides the downloadable
DLL library and
source code
the BBBCSIO contains complete
Help Files
and
Examples
. There is also a
Notes
section which provides more information on numerous topics such
as the Device Tree and the
PinMux.
Note: In order to use the BBBCSIO library, C# and Mono must be installed on the Beaglebone Black. A
separate project
documents that installation procedure.
License, Cost and Disclaimer
The BBBCSIO software is free and open source and is released under the MIT License. Be sure to read the
license text before your use the software. Your use of the BBBCSIO software is entirely at your own risk.
What BBBCSIO Does
- Provides simple and transparent read/write access (including the
triggering of events)
to the GPIO pins of a Beaglebone Black. A maximum output frequency of about 1.8MHz is possible when using a memory mapped port class and about 1.2Khz when using the SYSFS class.
- The SPI ports are fully supported. It is possible to use GPIO pins to provide a large number of SPI device select lines.
- The I2C ports are fully supported.
- The Serial/UART ports are fully supported.
- The Pulse Width Modulation (PWM) devices are fully supported. The PWM duty
cycle can be specified in nano-seconds or as a percentage of the base frequency.
- The Analog to Digital Conversion (A2D) devices are fully supported. A sample rate of about 1000 samples/sec has been observed.
- Full PRU support is included. The BBBCSIO PRU_Driver
class can launch PRU binary code and interact with running PRU programs to
exchange data
or receive interrupt events
etc. The PRU can read from or write to I/O lines at speeds of up to 50Mhz.
- Developed on armhf Debian Linux v3.08 freely available for the Beaglebone Black.
- Tested with the Mono JIT compiler v3.2.8 but is probably also compatible with other versions.
- The software is written in C# and a .NET project is included with the source code.
What BBBCSIO Does Not Do
- The armhf Debian Linux running on the Beaglebone Black is not a real-time operating system. This means, for example, although you might set a port
to output a 100Khz square wave the actual timing of some of the pulses may vary (and there may be gaps) as the process is pre-emptively swapped in and out by the kernel.
If you need extremely accurate timing you can use the BBBCSIO
PRU_Driver class to launch code which will run in the Programmable Realtime Units (PRUs) and this
will be absolutely deterministic in terms of timing (and probably a lot faster as well).
- The SPI, I2C, PWM, A2D, UART and PRU devices are supported as of version 01.05 but relatively little used OCP devices such as the quadrature encoders and McASP system have not yet been implemented in the BBBCSIO library, although they are planned to be added.
- The BBBCSIO Library cannot do much in the way of I/O unless the process it is running in has root privileges. This is enforced by the Linux O/S and means
that any code which incorporates the BBBCSIO Library must run as root.
- The BBBCSIO Library cannot adjust the PinMux
in order to enable specific OCP devices or GPIO pins. This cannot be done from user space and must be done by
setting the Device Tree or by somehow calling a kernel mode device driver to do it for you.
- The InterruptPort functionality is a pseudo interrupt. It operates by monitoring the designated GPIOs out of band in a separate, continuously computable,
thread. In concept, it is not dissimilar to the C
Poll()
call.
- The interrupt events sent by the PRU to a user space C# program are also not true interrupts. The PRU, of course, is completely realtime but by the time
the interrupt filters down the C# program (where it is received as an C# event) the kernel may have swapped that process in and out of memory an arbitrary number of times.
Download
The latest version of the BBBCSIO software can be found on this page. The source
code is also available in browseable form.
Installation and System Requirements
If you download only the BBBCSIO.dll
(rather than the source) you can use it like any other .NET dll library. Either place the BBBCSIO.dll
in the same directory
as the exe file or copy the dll into the /usr/lib
directory where it will be available to all programs that need it. Of course, you will need to
reference it in the .NET solution just as you would any other library.
If you download the source code you can include the BBBCSIO.proj
into your .NET solution in the usual way and the software should compile.
As for system requirements, the BBBCSIO was tested on a Beaglebone Black rev C board with the armhf Debian Linux v3.08 operating system installed. You will also
need Mono and the MCS compiler - testing occurred on Mono 3.2.8.