This driver will create a software-based serial port/UART using any GPIO pin, similiar to
/dev/tty* devices, with some unique features.
- Works with Minicom
- Works with
- 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:
- TX buffer cleared automatically after a write operation (Ex:
- No pooling needed
- Loopback mode
- Runtime changeable parameters (GPIO pins, baudrate and loopback mode)
Export the path location of your toolchain/GCC, Ex:
Makefile to match your kernel source directory and GCC prefix:
KERNEL_SRC_DIR := /root/raspberry/linux GCC_PREFIX := arm-bcm2708-linux-gnueabi-
make and you have the
The driver will be created at
root@raspberrypi:/home/pi# cat /sys/class/softuart/softuart/ baudrate data gpio_rx gpio_tx loopback power/ subsystem/ uevent
- baudrate - Selected baudrate
- data - Used to send and receive data, is the
- gpio_rx - Selected GPIO pin to receive data
- gpio_tx - Selected GPIO pin to transmit data
- loopback - Loopback mode, 1 - on / 0 - off (default)
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:
Loading module specifying all possible parameters:
insmod softuart.ko GPIO_TX=4 GPIO_RX=2 BAUDRATE=4800
minicom -b 4800 -D /sys/class/softuart/softuart/data
Send data with
echo abc > /sys/class/softuart/softuart/data
Receive data with
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
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.
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 =]