IOT-GATE-iMX8 and SBC-IOT-iMX8: Debian Linux: How-To Guide

From Compulab Mediawiki
Jump to: navigation, search

Overview

Linux filesystem image for the CompuLab IOT-GATE-iMX8 / SBC-IOT-iMX8 is based on Debian GNU/Linux stretch.

The default Debian Linux image includes more than 350 software packages. Among them:

  • Core system
  • Debian package management system
  • SSH server and client
  • PulseAudio configuration and usage utilities
  • NetworkManager
  • ModemManager
  • Bluez5 Bluetooth tools and daemons
  • Docker

Serial Console

IOT-GATE-IMX8 / SBC-IOT-IMX8 provides a serial console on the front panel micro-USB Console connector.

Connecting to a host PC

  1. Use a micro-USB cable to connect the Console connector to a USB port on your host PC.
  2. Make sure the CP2104 driver is available with your operating system, otherwise install CP2104 driver onto the host PC from https://www.silabs.com/documents/public/software/CP210x_Windows_Drivers_with_Serial_Enumeration.zip
  3. Identify the host PC interface and port number that will be used for communication with the device:
    • In most Linux PCs, the serial port will be denoted as one of the following (where n is a positive integer): /dev/ttyUSB0, /dev/ttyUSB1 ... /dev/ttyUSBn
    • In Windows PCs, the serial port usually will be denoted as one of the following (where n is a positive integer): COM1, COM2 ... COMn
  4. Start a terminal emulation program (such as PuTTY on Windows or minicom on Linux).
  5. In the port configuration section of the terminal emulation program select the port identified in previous step and set the following serial port parameters:
Baud Rate Data Bits Stop Bits Parity Flow Control
115200 8 1 none none

Connection and Login

To login into the Linux system, you may use a terminal emulator as described here, or connect through the network (ssh).
On this Debian rootfs root account is disabled; a user may enable it by means of passw utility:

sudo passwd root
Admolition important.png The following examples assume root user.

Package Management

The IOT-GATE-iMX8 / SBC-IOT-iMX8 Debian Linux image includes everything required to use the Debian package management utilities. You can use apt-get and dpkg out of the box.

Device Serial Number and Configuration

Product information is stored in on-board EEPROM.

  • To read the product serial number, issue the folowing command:
root@iot-gate-imx8:~# cat /proc/device-tree/baseboard-sn
  • To read the product configuration part number, issue the following command:
root@iot-gate-imx8:~# cat /proc/device-tree/baseboard-options

Docker

The Docker Engine is preinstalled.

  • The following command downloads a test image and runs it in a container. The container sample prints a message and exits.
root@iot-gate-imx8:~# docker run hello-world
  • Verify that the following message is generated (among other messages):
Hello from Docker!
This message shows that your installation appears to be working correctly.

Networking

To configure networking, edit /etc/network/interfaces, /etc/resolv.conf, /etc/hostname and /etc/hosts. For more information about Debian Linux network configuration read:

The majority of network setup can be done via the interfaces configuration file at /etc/network/interfaces.

Admolition note.png auto line is required for interfaces that have to be brought up at boot time.
  • Using DHCP to automatically configure the interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
  • Configuring the interface manually
auto eth0
    iface eth0 inet static
        address 192.168.1.170
        netmask 255.255.0.0
        gateway 192.0.0.1

WiFi

IOT-GATE-iMX8 / SBC-IOT-iMX8 features an optional 802.11ac WiFi interface, implemented with the Intel WiFi 6 AX200 module.

Simple Scanning

  • Sample WiFi scanning:
root@iot-gate-imx8:~# nmcli dev wifi list

The output will show the list of Access Points and Ad-Hoc cells in range. For more information about tuning WiFi interfaces refer to the “wireless-tools” man pages.

Connecting to an Access Point

The NetworkManager can be used to connect to an access point.
Access point connection command example.

Replace SSID with the wireless network name.
Replace PASSWORD with the wireless network password.
Replace Connection-Name with the new connection name.
root@iot-gate-imx8:~# nmcli radio wifi on
root@iot-gate-imx8:~# nmcli dev wifi con "SSID" password "PASSWORD" name "Connection-Name"

Creating an Access Point

The hostapd can be used to create an access point.

Access point creation example

Access point network mask 50.150.250.0/24 is used.
Replace the mask with the desired network mask.

  • Install the required utilities
root@iot-gate-imx8:~# apt-get update
root@iot-gate-imx8:~# DEBIAN_FRONTEND=noninteractive apt-get install --yes hostapd iptables-persistent
  • Create the configuration file.
Replace SSID with the wireless network name.
Replace PASSWORD with the wireless network password.
root@iot-gate-imx8:~# cat > /etc/hostapd/hostapd.conf << EOF
interface=wlan0
ssid=SSID
wpa_key_mgmt=WPA-PSK
wpa_passphrase=PASSWORD
driver=nl80211
hw_mode=g
channel=7
wpa=1
auth_algs=1
wpa_pairwise=CCMP
EOF
  • Update the network interfaces configuration to force the WiFi interface to only run in the access point mode.
root@iot-gate-imx8:~# cat >> /etc/network/interfaces << EOF

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
hostapd /etc/hostapd/hostapd.conf
address 50.150.250.1
netmask 255.255.255.0
EOF
  • Update the dnsmasq configuration file for DNS relay and DHCP server on our WiFi interface.
root@iot-gate-imx8:~# cat > /etc/NetworkManager/dnsmasq.d/dnsmasq.conf << EOF
interface=lo,wlan0
no-dhcp-interface=lo
dhcp-range=50.150.250.2,50.150.250.254,255.255.255.0,12h
EOF
  • Use iptables for NAT configuration
root@iot-gate-imx8:~# iptables -t nat -I POSTROUTING 1 -s 50.150.250.0/24 ! -d 50.150.250.0/24  -j MASQUERADE
root@iot-gate-imx8:~# iptables -I FORWARD 1 -s 50.150.250.0/24 -j ACCEPT
root@iot-gate-imx8:~# iptables -I FORWARD 1 -d 50.150.250.0/24 -j ACCEPT
root@iot-gate-imx8:~# iptables-save > /etc/iptables/rules.v4
  • Prevent Network Manager from interfering with hostapd.
root@iot-gate-imx8:~# sed -i "/^plugins=/c\plugins=ifupdown,keyfile,ofono" /etc/NetworkManager/NetworkManager.conf
  • Restart the system.
root@iot-gate-imx8:~# reboot

Bluetooth

IOT-GATE-iMX8 / SBC-IOT-iMX8 features an optional Bluetooth 5.1 BLE interface, implemented with the Intel WiFi 6 AX200 module.

Host Controller Interface (HCI) Initialization

  • HCI requires no user interaction for being configured. The driver gets loaded automatically unless this option has been disabled by putting a black list rule for this device.
  • HCI device configuration utility can be run to retrieve detailed information about the Bluetooth interfaces:
root@iot-gate-imx8:~# hciconfig hci0 -a
hci0:   Type: Primary  Bus: USB
        BD Address: 38:00:25:AF:FF:59  ACL MTU: 1021:4  SCO MTU: 96:6
        UP RUNNING
        RX bytes:751 acl:0 sco:0 events:52 errors:0
        TX bytes:2676 acl:0 sco:0 commands:52 errors:0
        Features: 0xbf 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'iot-gate-imx8'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version: 5.0 (0x9)  Revision: 0x100
        LMP Version: 5.0 (0x9)  Subversion: 0x100
        Manufacturer: Intel Corp. (2)
  • If the HCI device is not running, use the below command to enable the HCI device:
root@iot-gate-imx8:~#  hciconfig hci0 up
  • HCI Inquire remote devices.
root@iot-gate-imx8:~# hcitool scan
Scanning ...

Cellular Modem

The IOT-GATE-iMX8 / SBC-IOT-iMX8 features an optional cellular modem implemented with a mini-PCIe module. On-board micro-SIM card socket is available.

ModemManager

The ModemManager can be used to log into almost any Internet Service Provider with simple configuration setup.

In the following example:

  • Replace ISP-APN with the APN name of the cellular provider.
root@iot-gate-imx8:~# nmcli connection add type gsm ifname '*' con-name CellularCon apn ISP-APN
  • Connect to the cellular network.
root@iot-gate-imx8:~# nmcli connection up CellularCon
  • Disconnect from the cellular network.
root@iot-gate-imx8:~# nmcli connection down CellularCon

GPS

Optional GPS interface is implemented with the cellular modem module.
The cgps client can be used to display the GPS information. The cgps client utility depends on the gpsd daemon (starts automatically).

  • Select the GPS interface:
root@iot-gate-imx8:~# sed -i "/^DEVICES=.*/c\DEVICES=\"/dev/ttyUSB1\"" /etc/default/gpsd
  • Enable the GPS with the following AT commands:
root@iot-gate-imx8:~# echo AT+CGPS=0,1 | socat - /dev/ttyUSB3,crnl
root@iot-gate-imx8:~# echo AT+CGPS=1,1 | socat - /dev/ttyUSB3,crnl
  • Start the cgps client to display GPS information.

The synchronization process might take a few minutes.

root@iot-gate-imx8:~# cgps
┌───────────────────────────────────────────┐┌─────────────────────────────────┐
│    Time:       2020-05-04T14:13:30.000Z   ││PRN:   Elev:  Azim:  SNR:  Used: │
│    Latitude:    32.65985123 N             ││  71    29    123    22      Y   │
│    Longitude:   35.10027205 E             ││  85    27    047    22      Y   │
│    Altitude:   102.700 m                  ││                                 │
│    Speed:      0.00 kph                   ││                                 │
│    Heading:    128.7 deg (true)           ││                                 │
│    Climb:      6.00 m/min                 ││                                 │
│    Status:     3D FIX (53 secs)           ││                                 │
│    Longitude Err:   n/a                   ││                                 │
│    Latitude Err:    n/a                   ││                                 │
│    Altitude Err:    +/- 18 m              ││                                 │
│    Course Err:      n/a                   ││                                 │
│    Speed Err:       n/a                   ││                                 │
│    Time offset:     -3.682                ││                                 │
│    Grid Square:     KM72np                ││                                 │
└───────────────────────────────────────────┘└─────────────────────────────────┘

Back panel RS485 / RS232 port

IOT-GATE-iMX8 / SBC-IOT-iMX8 features a RS485 / RS232 port. Only half-duplex mode is supported for the RS485.
The RS485 / RS232 interface is routed to rear panel terminal block connector see drawing.
RS485 / RS232 connector pin-out:

Pin Number RS485 Functionality RS232 Functionality
1 NEG A/- TXD
2 NEG B/+ RTS
3 Ground Ground
4 NC CTS
5 NC RXD
6 Ground Ground

RS485 / RS232 Mode Selection

The UART mode is stored in the U-Boot environment.
U-Boot environment commands are used to set/get the UART mode.

Set RS485 mode

root@iot-gate-imx8:~# fw_setenv uart_mode rs485
root@iot-gate-imx8:~# reboot

Set RS232 mode

root@iot-gate-imx8:~# fw_setenv uart_mode rs232
root@iot-gate-imx8:~# reboot

Get UART mode

root@iot-gate-imx8:~# fw_printenv uart_mode

Note: The default port mode is RS485. The port operates in this mode in case of the variable uart_mode is assigned to an incorrect value or unset.

Example

Serial terminal emulator application can be used to test the RS485 port.

  • Use the following command to start Minicom with the user space device of the RS485 (/dev/ttymxc0).
root@iot-gate-imx8:~# minicom -D /dev/ttymxc0
  • Follow the following steps to disable hardware flow control
    • Open the menu "Configure Minicom" with CTRL-a followed by the letter 'o'.
    • Select "Serial port setup"
    • Press the letter 'f'.
    • Press the letter 'h'.
    • Press the letter 'i'.
    • Press the Esc key twice.
  • The characters that are typed in the terminal are transmitted to the RS485 port.
  • The characters that are received from the RS485 port are displayed in the terminal.
  • Press CTRL-a followed by the letter 'x' to exit from Minicom

ModBus

Modbus is a standard communication protocol and is a commonly available means of connecting industrial electronic devices. IOT-GATE-iMX8 RS485 ports can be used to implement the Modbus protocol.
It is recommended to use the modpoll - a command line based Modbus master simulator and test utility. Download and install the modpoll utility:

compulab@iot-gate-imx8:~$ wget -P /tmp https://www.modbusdriver.com/downloads/modpoll.tgz
...
compulab@iot-gate-imx8:~$ sudo tar -xvf /tmp/modpoll.tgz -C /opt/
...

Modbus Communication Example

[XY-MD02] is a high-precision temperature and humidity sensor. XY-MD02 uses the RS485 hardware interface and protocol layer compatible with standard industrial Modbus RTU protocol.

  • Connect the XY-MD02 sensor to the IOT-GATE-iMX8, RS485 port:
    • Connect power lines to a DC power supply 5V-30V
    • Connect RS485 lines
--------------------                                   
|                  |                                   
|                  *--(+)---< <------------- 5V-30V    
|                  |                                   
|                  *--(-)---< <-------------- GND     ------------------------  
| XY-MD02 (RS485)  |                                  |                      |
|                  *--(A+)--< <---...---> >--(P7/2)---*-----                 |
|                  |                                  | P7 |  IOT-GATE-iMX8  |
|                  *--(B-)--< <---...---> >--(P7/1)---*-----                 |
|                  |                                  |                      |
--------------------                                  ------------------------ 
  • Read temperature once:
root@iot-gate-imx8:~# /opt/modpoll/arm-linux-gnueabihf/modpoll -b 9600 -p none -t 3 -c 1 -r 2 -1 /dev/ttymxc0
-- Polling slave...
[2]: 284
  • Read humidity once:
root@iot-gate-imx8:~# /opt/modpoll/arm-linux-gnueabihf/modpoll -b 9600 -p none -t 3 -c 1 -r 3 -1 /dev/ttymxc0

-- Polling slave...
[3]: 453

Industrial I/O add-on

IOT-GATE-iMX8 / SBC-IOT-iMX8 can be optionally assembled with the industrial I/O add-on board.
The industrial I/O add-on features up-to three separate I/O modules which allow to implement different combinations of isolated CAN, RS485, RS232, digital outputs and inputs.

CAN

CAN bus modules can be installed in I/O add-on slots A or B.
CAN bus modules support both CAN 2.0B and CAN FD standards. Maximum supported data rate is 8Mbps (in CAN FD mode).

CAN interface configuration

  • Configure the CAN interface bit-rate to 1 Mbits/sec:
root@iot-gate-imx8:~# ip link set can0 type can bitrate 1000000
  • Enable the CAN interface:
root@iot-gate-imx8:~# ip link set can0 up

Send/Receive packets

Use cansend and candump utilities to send and receive packets via CAN interface.

  • Send standard CAN frame (on the first device):
root@iot-gate-imx8:~# cansend can0 111#1122334455667788
  • Send extended CAN frame (on the first device):
root@iot-gate-imx8:~# cansend can0 11111111#1122334455667788
  • CAN frames (extended mode) generator, random payload, interval between two successive flames 50 msec:
root@iot-gate-imx8:~# cangen -g 50 -e -D r -v can0
can: raw protocol (rev 20170425)
...
  can0  03FF0983#D7.61.FF.03.C1.F7.C1.34
  can0  19C34D32#F7.5A.C2.73.AD.0E.3F.0B
  can0  0675E391#2B.2D.D3.49
  can0  13091C55#99.32.EC.77.27.81.49.0B
  can0  098D67CF#22.50.AB.48.AD.7F.F4.26
  can0  05263FEC#1B.4C.02.45.6E
  can0  12B30E20#
  can0  1F193DF9#C5
  can0  1EB0B18F#3E.3F.DA.57.C2.FE.73.58
  can0  1E5C64D9#6F.0D.B3.63.6A
  can0  1E1DE3F9#96.48.AC.79.4E.00.27.71
  can0  0E1A11B7#75.81.70.7C.86.79.A7.77
  can0  05F8FD8B#33.F9.9B.1E.77.3D.1F
  can0  1E155FCD#E6.BA.F8.58.ED.6D.C8.10
  can0  1D91DF9E#5D.29.82.7B.97.1D.AB.5C
  can0  11FB3CDA#14.65.C3
  can0  091352C0#2C.ED
...
  • Dump all received data frames as well as error frames (on the second device):
root@iot-gate-imx8:~# candump any,0:0,#FFFFFFFF
  can0  111   [8]  11 22 33 44 55 66 77 88
  can0  11111111   [8]  11 22 33 44 55 66 77 88
...
  can0  03FF0983   [8]  D7 61 FF 03 C1 F7 C1 34
  can0  19C34D32   [8]  F7 5A C2 73 AD 0E 3F 0B
  can0  0675E391   [4]  2B 2D D3 49
  can0  13091C55   [8]  99 32 EC 77 27 81 49 0B
  can0  098D67CF   [8]  22 50 AB 48 AD 7F F4 26
  can0  05263FEC   [5]  1B 4C 02 45 6E
  can0  12B30E20   [0] 
  can0  1F193DF9   [1]  C5
  can0  1EB0B18F   [8]  3E 3F DA 57 C2 FE 73 58
  can0  1E5C64D9   [5]  6F 0D B3 63 6A
  can0  1E1DE3F9   [8]  96 48 AC 79 4E 00 27 71
  can0  0E1A11B7   [8]  75 81 70 7C 86 79 A7 77
  can0  05F8FD8B   [7]  33 F9 9B 1E 77 3D 1F
  can0  1E155FCD   [8]  E6 BA F8 58 ED 6D C8 10
  can0  1D91DF9E   [8]  5D 29 82 7B 97 1D AB 5C
  can0  11FB3CDA   [3]  14 65 C3
  can0  091352C0   [2]  2C ED
...

RS232

RS232 modules can be installed in I/O slots A or B.
The module implements RS232 interface without hardware flow control.
The interface device in Linux:

  • I/O module A: /dev/ttymxc1
  • I/O module B: /dev/ttymxc3

RS485

RS485 I/O modules can be installed in I/O slots A or B.
The module implements a half-duplex RS485 interface.
The interface device in Linux:

  • I/O module A: /dev/ttymxc1
  • I/O module B: /dev/ttymxc3


The RS485 I/O module includes an optional software-enabled termination. Please note that the termination is disabled each time the device goes through power-cycle.
Linux commands to switch termination state:

SLOT Enable termination Disable termination
A GPIOSET 4 12=1 GPIOSET 4 12=0
B GPIOSET 4 24=1 GPIOSET 4 24=0

Digital I/O

The digital I/O module can be installed in industrial I/O add-on slot C. The module implements 4 digital input and 4 digital output signals.
Make sure that the digital I/O module is present in your device.

Admolition note.png in order to operate digital output or input signals, it is mandatory to connect external voltage source between pin 19 (24V_IN) and pin 20 (ISO_GND_C) of the industrial I/O add-on connector.

Read Digital Input

Use the following commands to read the value of the input signals.
Command format:

root@iot-gate-imx8:~# gpioget 2 0
Signal Name Pin number on the
I/O add-on connector
Read input
IN0 15 gpioget 2 0
IN2 16 gpioget 2 6
IN1 17 gpioget 2 1
IN3 18 gpioget 2 7

Set Digital Output

Use the following commands to set the value of the output signals.
Command format:

root@iot-gate-imx8:~# gpioset 2 8=1
Signal Name Pin number on the
I/O add-on connector
Set HIGH Set LOW
OUT0 11 gpioset 2 8=1 gpioset 2 8=0
OUT2 12 gpioset 5 9=1 gpioset 5 9=0
OUT1 13 gpioset 2 9=1 gpioset 2 9=0
OUT3 14 gpioset 5 10=1 gpioset 5 10=0

Analog Input

Analog 4–20mA input modules can be installed in I/O slots A or B.
The module detects the current level between 4 to 20 mA with 12-bit resolution.

Use the following command to load the kernel object:

root@iot-gate-imx8:~# modprobe max11108

Read the Detected Value

Use the following command to read the current detected value:

root@iot-gate-imx8:~# cat /sys/bus/iio/devices/iio:device0/in_current_raw

Values range from 0 to 4095 (12-bit resolution).
Values can be transposed to actual mA current in the loop by the formula: Current(mA)= Value * 0.00684

  • Current 4mA equals the digital value of 585
  • Current 20mA equals the digital value of 2,924

Power Button

IOT-GATE-iMX8 power button triggers two types of events, depending on the time interval the button was pressed for:

  • less than 50 mS -- considered as an electrical bounce/glitch. Ignored.
  • short press: 50 ms < T < 5 s -- a pair of events (press/release) will be triggered on the input device /dev/input/event0. By default, the press event is handled by the systemd-logind daemon (runs on Linux); once the event is raised, the OS starts normal shutdown process.
  • long press: more than 5 s -- triggers immediate hardware shutdown. This event is handled by SNVS sub-system of the i.MX8M-Mini SoC.

To disable the handling of short press by systemd-logind add (or uncomment) the line HandlePowerKey=ignore to the file /etc/systemd/logind.conf. See man logind.conf(5) for details.

To disable the hardware shutdown event triggered by long press, execute the following snippet on the boot loader (e.g., add it to startup script)

setenv lpcr_addr 30370038
setenv off_long_press 30000
setexpr lpcr_val *$lpcr_addr \| $off_long_press
mw.l $lpcr_addr $lpcr_val 1

To learn more, please refer to ch. 9.7.16 of Security Reference Manual for i.MX 8M Mini Applications Processor

User LED (DS4)

The user LED is controlled by the following SoC GPIOs:

  • GPIO3_19, pin number 83
  • GPIO3_25, pin number 89

Set LED Color

Use the following commands to set the LED state:

  • Off
root@iot-gate-imx8:~# gpioset 2 25=0; gpioset 2 19=0
  • Green
root@iot-gate-imx8:~# gpioset 2 25=1; gpioset 2 19=0
  • Yellow
root@iot-gate-imx8:~# gpioset 2 25=0; gpioset 2 19=1
  • Orange
root@iot-gate-imx8:~# gpioset 2 25=1; gpioset 2 19=1

TPM

Basic Functionality

  • Load the TPM kernel object:
root@iot-gate-imx8:~# modprobe tpm_tis_spi
  • Verify that the TPM device was created:
root@iot-gate-imx8:~# ls -lh /dev/tpm*
  • Install the tpm2-tools package
root@iot-gate-imx8:~# apt-get update
root@iot-gate-imx8:~# apt-get install tpm2-tools
  • Validate basic functionality
root@iot-gate-imx8:~# tpm2_getrandom 16

Watchdog

IOT-GATE-IMX8 / SBC-IOT-IMX8 watchdog function is implemented with the i.MX8M-Mini SoC watchdog.
By default, the watchdog is not configured.

$ systemctl show | grep RuntimeWatchdog
RuntimeWatchdogUSec=0

The value RuntimeWatchdogUSec=0 means watchdog logic is disabled: no watchdog device is opened, configured, or pinged

Watchdog configuration

  • Edit /etc/systemd/system.conf file to configure watchdog related parameters, in particular RuntimeWatchdogSec and ShutdownWatchdogSec.
RuntimeWatchdogSec - specifies the watchdog timeout for runtime services, meaning services that are actively running during normal system operation. The value is in seconds and should be set to a positive integer.
ShutdownWatchdogSec - specifies the watchdog timeout for the shutdown process, ensuring the system doesn't hang indefinitely during the shutdown. The value is in seconds and should be set to a positive integer.
  • Reboot the device
  • Verify watchdog configuration
$ systemctl show | grep RuntimeWatchdog
RuntimeWatchdogUSec=10s

Watchdog testing

  • Run the following command to simulate kernel panic:
# echo "c" > /proc/sysrq-trigger
  • As a result, the watchdog is not fed and the system reboots after 10 sec.

RTC

IOT-GATE-IMX8 / SBC-IOT-IMX8 RTC is implemented with the AM1805 real-time clock (RTC) chip.
The backup battery keeps the RTC running to maintain clock and time information whenever the main power supply is not present.

Accessing and setting the RTC

  • To access the RTC time and date run:
$ sudo hwclock -r
2022-08-04 12:38:10.577874+00:00
  • To set the date and write it into the RTC do the following:
$ sudo date -s "31 Dec 2021 10:00:00"
Fri Dec 31 10:00:00 IST 2021
$ sudo hwclock -w
$ sudo hwclock -r
2021-12-31 10:00:08.317403+02:00

See also