Skip to content

How to use the peripherals on 40 Pin Header

Daniele Cleri edited this page Jun 5, 2024 · 5 revisions

LEDs

The UP Platforms includes 3 or 4 LEDs, depending on the board (yellow, green, red, and blue), which are controlled by the pin control FPGA on the board.
As root, you can use the following commands to control the LEDs:

 # Turn on the Green LED
 echo 1 > /sys/class/leds/upboard\:green\:/brightness
 # Turn off the Green LED
 echo 0 > /sys/class/leds/upboard\:green\:/brightness

For other LEDs, replace "green" with "red", "blue" or "yellow" in the commands above.

GPIO

On UP platforms, at the system start, all the pins in the hat connector are configured in function mode.

So for example the hat pin 3 associated with I2C_SDA function at the start is configured as an I2C channel

You can switch the function after booting accessing the GPIO RPi numbering so for example we can have done the same example with

 $ sudo -i
 $ cd /sys/class/gpio
 $ echo 27 > export
 $ cd gpio27
 $ echo "out" > direction
 $ watch -n 0.5 'echo 1 > value; sleep 0.5 ; echo 0 > value'
 $ echo "in" > direction
 $ cd ..
 $ echo 27 > unexport

Warning: The current pinctrl driver implementation does not allow to restore a pin in function mode (e.g. UART) once it has been already switched to GPIO mode until the operating system is rebooted.

Warning: When a pin is unexported it retains the last value/direction. So if you don't intend to use the GPIO again better set it to input to protect it from short/electrical problems.


Interrupts

Currently interrupts are only supported using the Linux GPIO numbering scheme (e.g. use 432 GPIO number instead of Rpi GPIO number 27).

The most simple way to use interrupts from userspace is to use a userspace software library like mraa

Example IRQ test using Python Periphery

  1. Download this file and extract it on the board
  2. install python3-pip

sudo apt update && sudo apt install python3-pip

  1. install periphery from pip

sudo -H pip3 install python-periphery

  1. launch the script

sudo python3 irqtest.py

PWM

The PWM output can be controlled via /sys/class/pwm/pwmchip0

(/sys/class/pwm/pwmchip1 on some platfortms)

PWM channel HAT PIN
pwm0 32: PWM0
pwm1 33: PWM1
pwm2 Not Available
pwm3 16: PWM3

If you don't see the above directory double-check that in the bios the option

Main > CRB Setup > CRB Chipset > South Bridge > OS Selection

is set to: Intel Linux


Warning: Add information about maximum pwm frequency/duty cycle


Example: Generate PWM signal on PWM0

Download the PWM Test script from here.

Extract and from the terminal, run the following command:

$ sudo ./pwmset.sh 0 1000 50

Usage:

  • The first argument is channel
  • The second argument is frequency
  • The 3rd argument is duty_cycle

UART

To identify the TTY device node number in Linux corresponding to a particular hardware UART open a terminal and execute the following command

 $ ls /sys/bus/pci/devices/0000\:00\:18.?/dw-apb-uart.*/tty/ | grep tty
 
 /sys/bus/pci/devices/0000:00:18.0/dw-apb-uart.8/tty/:
 ttyS4
 /sys/bus/pci/devices/0000:00:18.1/dw-apb-uart.9/tty/:
 ttyS5

The first UART (associated to dw-apb-uart.8) is the uart on the M10 connector, and the one associated with dw-apb-uart.9 is the one on the HAT.

So to access the UART on the HAT you have to open the device file '''/dev/ttyS5'''

sudo screen /dev/ttyS5 115200

I2C ports

Similar to UART ports above, I2C device nodes in Linux can be identified as follows:

  • i2c_designware.0 -> I2C channel 0 on hat (ID_SD ID_SCL)
 ls /sys/bus/pci/devices/*/i2c_designware.0/ | grep i2c
 i2c-0
  • i2c_designware.1 -> I2C channel 0 on hat (pin 3,5 on HAT)
 ls /sys/bus/pci/devices/*/i2c_designware.1/ | grep i2c
 i2c-1

So the Linux device node for the first i2c channel is /dev/i2c-0

To detect all the peripherals on the first i2c bus do the following

 $ sudo apt install i2c-tools
 $ sudo i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
 00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 70: -- -- -- -- -- -- -- --

Change I2C clock speed

Reboot the board and enter the BIOS settings menu.

You should now see the I2C configuration menu.

 LPSS I2C #1 refers to I2C0 on HAT pins 27,28
 LPSS I2C #2 refers to I2C1 on HAT pins 3,5
  • To change the speed on I2C1, select Set LPSS I2C #2 Speed and press Enter.

  • The 4 speeds listed are:

    • Standard Mode = 100kHz
    • Fast Mode = 400kHz
    • Fast Plus Mode = 1MHz
    • High Speed Mode = 3MHz
  • Select the desired speed and press Enter.

  • Press F4 to save changes and reboot.

SPI Ports

SPI device nodes in Linux can be identified as follows:

 $ ls /sys/bus/pci/devices/0000\:00\:19.*/pxa2xx-spi.*/spi_master/ | grep spi
/sys/bus/pci/devices/0000:00:19.0/pxa2xx-spi.4/spi_master/:
spi1
/sys/bus/pci/devices/0000:00:19.1/pxa2xx-spi.5/spi_master/:
spi2
/sys/bus/pci/devices/0000:00:19.2/pxa2xx-spi.6/spi_master/:
spi3

ACPI overrides to enable SPI in userspace

To enable access to SPI from userspace ACPI overrides are added to the kernel when installing the DKMS pinctrl driver

You should see the SPI devices under /dev

 $ ls /dev/spi*
 /dev/spidev1.0  /dev/spidev1.1
Clone this wiki locally