Tag Archives: Raspberry

Are you lucky? No USB to serial converter needed!

All model B-V2 (and model A) owners can set-up their svxlink system without the need of an external USB-2-serial converter. All raspi versions offer a built-in serial port, but only the data signals (RXD/TXD) are available on the GPIO header (see http://elinux.org/RPi_Low-level_peripherals). With the arrival of the version 2 boards things improved. A new connector P5 was introduced. It is right next to the extension header P1, but as shipped there are no pins equipped.

Details on the P5 header can be found at http://www.raspberrypi-spy.co.uk/2012/09/raspberry-pi-p5-header/

Of interest to us are the pins 5+6 (GPIO30+GPIO31). The chip on the raspi allows different mappings as can be found at http://elinux.org/RPi_BCM2835_GPIOs . As can be seen there, GPIO30+GPIO31 can be switch to be RTS0/CTS0 in mode “ALT3”.

To use the IO pins we first need to “free” the serial port for our usage. The default configuration of the linux image uses the built in serial port to dump kernel messages and as a way to log into your raspi.

From /boot/cmdline.txt we need to remove the following options:

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

We also need to stop the system to spin up a terminal on the serial port. For this we put the following statement in /etc/inittab into comment (add # in front of the line):

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200

OK, the serial port is ours, but we still need a tool to switch the GPIO assignment.

# as pi user, 
cd /home/pi
mkdir rpi-tools
cd rpi-tools/
# if you have not yet installed git, this must be done upfront
# see comments section below on how to do this
git clone https://github.com/rewolff/bw_rpi_tools.git
cd bw_rpi_tools/gpio
# depending on the version or status of the tools you might need to fix the Makefile
# see comments section below
make
sudo make install

We can now check the current pin assignment:

sudo gpio_list

To reassign the pins to the RTS/CTS function we use the following command:

sudo gpio_setfunc 31 ALT3
sudo gpio_setfunc 30 ALT3

To make this restart safe, we put the command into /etc/rc.local:

# enable CTS+RTS on P5 header for onboard serial
/usr/local/bin/gpio_setfunc 31 ALT3
/usr/local/bin/gpio_setfunc 30 ALT3

Bingo. We can now use the built-in serial port in the svxlink configuration by referring to the device: /dev/ttyAMA0 . In svxlink.conf we use:

SERIAL_PORT=/dev/ttyAMA0

Until the advent of direct raspi GPIO support in svxlink above few lines will be of help.

WARNING: When connecting external circuitry to the raspi GPIO pins, please be reminded that the Raspberry Pi only support 3.3V signal level. So in the best interest of your raspi keep this in mind!

Advertisements

Are you up for a challenge… USB and raspi

Unfortunately, there is a variety of problems surrounding the USB ports on the Raspberry Pi.

First there are power related problems, especially on the Model-B-V1 boards. The build-in fuses seem to cause problems with some USB periherals (http://elinux.org/RPi_Hardware#Power_Supply_Problems).

Even after all the improvements that happened in the firmware over last months, there are still problems with various devices and their drivers.

I had problems with a FTDI USB-2-serial converter used for the svxlink TRX interface. It would lock up the raspberry after a few hours 😦   Similar converters based on other chips (using other drivers) appear to be more well behaved.

I will have to add a dedicated post for USB audio, but a similar situation exists with such devices. Many provide choppy audio.

For all above problems there seems to be solution, even though with some limitations…

The USB port speed can be restricted to USB1.1 speeds by adding a kernel command line option. To do this, edit /boot/cmdline.txt and add the following option INTO THE SAME LINE as all the existing options you will find there:

dwc_otg.speed=1

The downside seems to be with USB keyboards. If connected they seem to lock up. This was no issue for me, as I only connect to the system over the network… talking of which – the Ethernet network will also be limited by this change. The 12 Mpbs still provide enough bandwidth for full-duplex audio and an echolink connection 😉

Updating kernel and the firmware

Once the initial OS set-up is completed, we want to update the kernel and firmware. A description can be found at https://github.com/Hexxeh/rpi-update

First we need to install a tool to help us with the update :

sudo apt-get install git-core
mkdir ~/software
cd ~/software
sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update

As next step we run the update:

sudo rpi-update

A reboot will be required to activate the newly downloaded kernel & firmware.

sysinfo.sh

I haven’t posted any details on overclocking and firmware update yet, and before I do it is possibly a good idea to recommend adding the following script to your system (as can be found e.g. at http://youresuchageek.blogspot.de/2012/09/howto-raspberry-pi-openelec-on.html):

sudo bash
vi /usr/local/bin/sysinfo.sh
#!/bin/sh
echo "\n###############################################"
echo "# RASPBERRY PI SYSTEM INFORMATIONS #"
echo "###############################################"

echo "\nCPU current Frequency: `vcgencmd measure_clock arm`"
echo "CORE current Frequency: `vcgencmd measure_clock core`"
echo "CORE current Voltage: `vcgencmd measure_volts core`"
echo "CPU current Temperature: `vcgencmd measure_temp`"

echo "\nFirmware Version: `vcgencmd version`\n"

echo "Codecs Status:"
echo "`vcgencmd codec_enabled H264`"
echo "`vcgencmd codec_enabled MPG2`"
echo "`vcgencmd codec_enabled WVC1`"

echo

I will use “vi” as editor. Please replace with your favourite linux editor.

We now mark the script as executable:

chmod +x /usr/local/bin/sysinfo.sh

Executing the script will give us information on the system:

oot@raspberrypi:/home/pi# sysinfo.sh

###############################################
# RASPBERRY PI SYSTEM INFORMATIONS #
###############################################

CPU current Frequency: frequency(45)=700000000
CORE current Frequency: frequency(1)=250000000
CORE current Voltage: volt=1.20V
CPU current Temperature: temp=41.2'C

Firmware Version: Oct 25 2012 16:36:25
Copyright (c) 2012 Broadcom
version 346337 (release)

Codecs Status:
H264=enabled
MPG2=disabled
WVC1=disabled

One might add info on the running kernel version using the following command:

uname -a

The output will look like this:

Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l

My raspi hardware

Just posting the initial OS install info, I thought it might be helpful to point out that there are three different hardware version of Raspberri Pi:

  • Model B, Version 1: This is the initial version. Several hundred thousand units got shipped. Model B is the better equipped version with an Ethernet port and 2 USB ports. This version was shipped with 256MB of RAM.
  • Model B Version 2: Improved version that replaced Version 1 in autumn 2012.  A few shortcomings of the initial board got improved, e.g .USB port power fuses. It now comes with 512MB RAM. It also gained an additional IO connector called P5.
  • Model A: released in January 2013, this model comes without Ethernet and only has 1 USB port. The memory is 256MB. Main advantage is a significantly reduced power consumption (I haven’t checked, but some say about 1/3 of model B)

For my svxlink activities I started with the model B-V1, swiftly to be replaced with a model B-V2.

Initial Linux Install

I used the “official” Rapspberri Pi Linux Distribution based on Debian, as can be downloaded at http://www.raspberrypi.org/downloads – look for the “Raspian wheezy” section.

A stripped down, RAM only, svxlink optimised OS image would be great, but to start with I decided to go for the best supported distribution. You’ll be able to find a nice description on how to get started on http://www.raspberrypi.org/archives/2892 – just click on the Quich Start Guide link to download the PDF.

I did all my setup without any keyboard or monitor installed. The image is pre-configured to start up a DHCP client to get an IP address automatically and it will also start an SSH server. So connectibg it to your home network and connecting power will be all you need to get started. You will need to know the IP address that was assigned to you raspi. A good place to search could be in your home router. Many routers allow on their configuration pages to check for the IP addresses that where handed out by the router. Use your favourite SSH client to log into the raspi. A good SSH client for windows is putty.

Below you can find my steps to setup the OS after the downloaded OS image was copied onto an SD card, the raspberry pi booted and login (some basic linux skills are required 😉 :

sudo raspi-config
boot_behaviour: straight to desktop = NO
memory_split: GPU memory=16
change_locale: en_US.UTF-8 , en_US.UTF-8
change_timezone: Europe/Berlin
reboot
sudo raspi-config
expand_rootfs: yes
change_pass: xxx
reboot

sudo apt-get update
sudo apt-get upgrade
sudo reboot

vi /home/pi/.bashrc
uncomment alias (ll, ...)
sudo bash
edit /root/.bashrc
uncomment alias (ll, ...)