Coder Social home page Coder Social logo

sohanmane / rpisoft-uart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from themrleon/rpisoft-uart

0.0 1.0 0.0 14 KB

A Raspberry Pi / BCM2835 Software-based UART Linux device driver

License: GNU General Public License v2.0

Makefile 2.37% C 97.63%

rpisoft-uart's Introduction

RpiSoft-UART

This driver will create a software-based serial port/UART using any GPIO pin, similiar to /dev/tty* devices, with some unique features.

Features

  • Works with Minicom
  • Works with cat and echo commands
  • 256 bytes RX buffer (read the data whenever you want, no data lost!)
  • 256 bytes TX buffer (no need to send each byte separately, send the whole array once!)
  • RX buffer cleared automatically after a read operation (Ex: cat)
  • TX buffer cleared automatically after a write operation (Ex: echo)
  • No pooling needed
  • Loopback mode
  • Runtime changeable parameters (GPIO pins, baudrate and loopback mode)

Compiling

Export the path location of your toolchain/GCC, Ex:

export PATH=$PATH:/root/raspberry/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin

Edit Makefile to match your kernel source directory and GCC prefix:

KERNEL_SRC_DIR := /root/raspberry/linux
GCC_PREFIX := arm-bcm2708-linux-gnueabi-

Now type make and you have the softuart.ko driver.

Structure

The driver will be created at /sys/class/softuart/softuart/:

root@raspberrypi:/home/pi# cat /sys/class/softuart/softuart/
baudrate   data       gpio_rx    gpio_tx    loopback   power/     subsystem/ uevent

Where:

  • baudrate - Selected baudrate
  • data - Used to send and receive data, is the /dev/tty* like file
  • gpio_rx - Selected GPIO pin to receive data
  • gpio_tx - Selected GPIO pin to transmit data
  • loopback - Loopback mode, 1 - on / 0 - off (default)

Usage

Driver parameters:

root@raspberrypi:/home/pi# modinfo softuart.ko 
...
parm:           BAUDRATE: Baudrate value [default = 4800] (min=1200, max=19200) (int)
parm:           GPIO_TX: GPIO TX pin [default = 4] (int)
parm:           GPIO_RX: GPIO RX pin [default = 2] (int)

Loading module with default parameters:

insmod softuart.ko

Loading module specifying all possible parameters:

insmod softuart.ko GPIO_TX=4 GPIO_RX=2 BAUDRATE=4800

Examples

Minicom:

minicom -b 4800 -D /sys/class/softuart/softuart/data

Send data with echo:

echo abc > /sys/class/softuart/softuart/data

Receive data with cat:

cat /sys/class/softuart/softuart/data

Loopback mode:

echo 1 > /sys/class/softuart/softuart/loopback
echo abc > /sys/class/softuart/softuart/data
cat /sys/class/softuart/softuart/data
abc

Change baudrate to 9600 kbps:

echo 9600 > /sys/class/softuart/softuart/baudrate

Advanced

Just don't send more than 256 bytes at once and all must be ok, 256 is enough for most applications, but if you need more just change in the source code.

Understanding the RX buffer

The driver have a 256 bytes RX buffer. This mean you can receive up to 256 bytes at once and they will be stored, without loss, if more bytes are received the buffer will be cleared and start store again. Any read operation at 'data' entry, will clear the buffer (Ex: cat). The buffer have only effect without the use of a software like minicom (because have it's own buffer, and due the pooling, keep the buffer clear).

Understanding the TX buffer

The driver have a 256 bytes TX buffer. This mean you can send up to 256 bytes at once and they will be stored and transmitted until the last byte, clearing the buffer automatically. If more bytes than the buffer capacity is written, the buffer will clear and start store again. Any write operation at 'data' entry, will start the transmission (Ex: echo). The buffer have only effect without the use of a software like minicom (because transmit each byte separately, using just one byte of the TX buffer at time).

Remember, this is a software-based UART, subject to preemption, not a piece of dedicated hardware. Details, limitations and a user-space version can be found HERE.

License

GPLv2 License, details HERE.

Updated (june 2016)

Tag 1.0 released and a pull request was accept on the Master branch, seems to be that the new raspberry pi toolchain can't understand some of the old symbols, so they were hardcoded.

Updated (july 2017)

Accepted pull request that adds support for the rpi version 2 and 3, however, I can't test any pull requests because I haven't the rpi hardware anymore, so if you are having problems with the master branch version (which contains all the pull requests), try the tag 1.0 that was fully developed and tested by me, using the rpi model B. A BIG thanks for all the contributors that keep updating the driver with the newer rpi models =]

rpisoft-uart's People

Contributors

themrleon avatar volodink avatar grlks avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.