NanoPi M4

From FriendlyARM WiKi
Jump to: navigation, search

查看中文

Contents

Introduction

Overview
Front
Back
  • The NanoPi M4 is a RK3399 SoC based ARM board. It has the same form of factor as the RPi B3+ and has ports and interfaces compatible with RPi B3+ too. On a 85 x 56 mm compact board there are rich hardware resources. These features make it a good platform for rapid product prototyping and various applications.
  • The NanoPi M4 has an onboard 2.4G & 5G dual-band WiFi + Bluetooth 4.1 combo wireless module, four USB3.0 Type A host ports, one Gbps Ethernet port, one HDMI 2.0 Type A port, one 3.5mm audio jack and one Type-C port. In addition it has a RPi compatible 40-pin connector, dual MIPI-CSI camera interface, PCIe x2, USB2.0 x2, eMMC socket, RTC port and etc.
  • The NanoPi M4 has two RAM options: 4GB LPDDR3 and 2GB DDR3. Both can be booted from either a TF card or an external eMMC module.
  • The NanoPi M4 supports Ubuntu Desktop 18.04(64-bit), Lubuntu 16.04(32-bit), Ubuntu Core 18.04(64-bit), Android 7.1 and Lubuntu Desktop with GPU and VPU acceleration. With these rich resources and powerful performance it can be widely used in applications of machine learning, AI, deep learning, robots, industrial control, industrial cameras, advertisement machines, game machines, blockchain and etc.

Hardware Spec

  • SoC: Rockchip RK3399
    • CPU: big.LITTLE,Dual-Core Cortex-A72(up to 2.0GHz) + Quad-Core Cortex-A53(up to 1.5GHz)
    • GPU: Mali-T864 GPU,supports OpenGL ES1.1/2.0/3.0/3.1, OpenVG1.1, OpenCL, DX11, and AFBC
    • VPU: 4K VP9 and 4K 10bits H265/H264 60fps decoding, Dual VOP, etc
  • PMU: RK808-D PMIC, cooperated with independent DC/DC, enabling DVFS, solfware power-down, RTC wake-up, system sleep mode
  • RAM: Dual-Channel 4GB LPDDR3-1866, or Dual-Channel 2GB DDR3-1866
  • Flash: no Onboard eMMC, but has a eMMC socket
  • Ethernet: Native Gigabit Ethernet
  • Wi-Fi/BT: 802.11a/b/g/n/ac, Bluetooth 4.1, Wi-Fi and Bluetooth combo module, dual antenna interface
  • Video Input: one or two 4-Lane MIPI-CSI, dual ISP, up to 13MPix/s,supports simultaneous input of dual camera data
  • Video output
    • HDMI: HDMI 2.0a, supports 4K@60Hz,HDCP 1.4/2.2
    • one 4-Lane MIPI-DSI
  • Audio Out: 3.5mm Dual channel headphone jack, or HDMI
  • Audio In: one microphone input interface
  • USB 3.0: four USB 3.0 Type-A ports
  • USB Type-C: Supports USB2.0 OTG and Power input
  • microSD Slot x 1
  • 40Pin GPIO Extension ports:
    • 3 X 3V/1.8V I2C, up to 1 x 3V UART, 1 X 3V SPI, 1 x SPDIF_TX, up to 8 x 3V GPIOs
    • 1 x 1.8V 8 channels I2S
  • 24Pin Extension ports:
    • 2 independent native USB 2.0 Host
    • PCIe x2
    • PWM x1, PowerKey
  • Debug: one Debug UART, 4 Pin 2.54mm header, 3V level, 1500000bps
  • LED: 1 x power LED and 1 x GPIO Controlled LED
  • RTC Battery: 2 Pin 1.27/1.25mm RTC battery input connector
  • Power supply: DC 5V/3A
  • PCB: 8 Layer, 85 mm x 56 mm
  • Ambient Operating Temperature: -20℃ to 70℃

Diagram, Layout and Dimension

Layout

NanoPi M4 Layout
NanoPi M4 Layout
  • 40-Pin GPIO1 Pin Spec
Pin# Assignment Pin# Assignment
1 VCC3V3_SYS 2 VDD_5V
3 I2C2_SDA(3V) 4 VDD_5V
5 I2C2_SCL(3V) 6 GND
7 GPIO1_A0(3V) 8 GPIO4_C1/I2C3_SCL(3V)
9 GND 10 GPIO4_C0/I2C3_SDA(3V)
11 GPIO1_A1(3V) 12 GPIO1_C2(3V)
13 GPIO1_A3(3V) 14 GND
15 GPIO1_A4(3V) 16 GPIO1_C6(3V)
17 VCC3V3_SYS 18 GPIO1_C7(3V)
19 SPI1_TXD/UART4_TX(3V) 20 GND
21 SPI1_RXD/UART4_RX(3V) 22 GPIO1_D0(3V)
23 SPI1_CLK(3V) 24 SPI1_CSn0(3V)
25 GND 26 GPIO4_C5/SPDIF_TX(3V)
27 I2C2_SDA(1.8V) 28 I2C2_SCL(1.8V)
29 I2S0_LRCK_RX(1.8V) 30 GND
31 I2S0_LRCK_TX(1.8V) 32 I2S_CLK(1.8V)
33 I2S0_SCLK(1.8V) 34 GND
35 I2S0_SDI0(1.8V) 36 I2S0_SDO0(1.8V)
37 I2S0_SDI1SDO3(1.8V) 38 I2S0_SDI2SDO2(1.8V)
39 GND 40 I2S0_SDI3SDO1(1.8V)
  • 24-Pin GPIO2 Pin Spec
Pin# Assignment Pin# Assignment
1 VCC5V0_SYS 2 VCC5V0_SYS
3 PCIE_RX1_P 4 PCIE_TX1P
5 PCIE_RX1_N 6 PCIE_TX1N
7 GND 8 GND
9 PCIE_RX0_P 10 PCIE_TX0P
11 PCIE_RX0_N 12 PCIE_TX0N
13 GND 14 GND
15 PCIE_REF_CLKP 16 HOST0_DM
17 PCIE_REF_CLKN 18 HOST0_DP
19 GND 20 GND
21 PWR_KEY 22 HOST1_DM
23 GPIO4_C6/PWM1(3V) 24 HOST1_DP
  • MIPI-CSI Interface Pin Spec
0.5mm FPC Connector
MIPI-CSI2 can be configured to MIPI-DSI
Pin# MIPI-CSI1 MIPI-CSI2 Description
1 VCC5V0_SYS VCC5V0_SYS 5V Power ouput
2 VCC5V0_SYS VCC5V0_SYS 5V Power ouput
3 GND GND Return current path
4 VCC_CSI_AF2.8V VCC_CSI_AF2.8V 2.8V Power for VCM
5 VCC_CSI_1.2V VCC_CSI_1.2V 1.2V Power for image sensor core circuit
6 VCC1V8_CAM VCC1V8_CAM 1.8V power for I/O circuit
7 VCC_CSI_2.8V VCC_CSI_2.8V 2.8V power for image sensor analog circuit
8 VCC_CSI_1.0V VCC_CSI_1.0V 1.0V Power for image sensor core circuit
9 I2C1_SCL I2C2_SCL 1.8V I2C clock signal
10 I2C1_SDA I2C2_SDA 1.8V I2C data signal
11 MIPI_CSI0_RST MIPI_CSI1_RST reset camera module
12 MIPI_CSI0_PWN MIPI_CSI1_PWN Power down camera module
13 GND GND Return current path
14 GPIO2_B3_CIF_CLKOUTA GPIO2_B3_CIF_CLKOUTA MCLK to camera module
15 GND GND Return current path
16 MIPI_RX0_D3P MIPI_TX1/RX1_D3P MIPI CSI positive differential data line transceiver output
17 MIPI_RX0_D3N MIPI_TX1/RX1_D3N MIPI CSI negative differential data line transceiver output
18 GND GND Return current path
19 MIPI_RX0_D2P MIPI_TX1/RX1_D2P MIPI CSI positive differential data line transceiver output
20 MIPI_RX0_D2N MIPI_TX1/RX1_D2N MIPI CSI negative differential data line transceiver output
21 GND GND Return current path
22 MIPI_RX0_D1P MIPI_TX1/RX1_D1P MIPI CSI positive differential data line transceiver output
23 MIPI_RX0_D1N MIPI_TX1/RX1_D1N MIPI CSI negative differential data line transceiver output
24 GND GND Return current path
25 MIPI_RX0_CLKP MIPI_TX1/RX1_CLKP MIPI CSI positive differential clock line transceiver output
26 MIPI_RX0_CLKN MIPI_TX1/RX1_CLKN MIPI CSI negative differential clock line transceiver output
27 GND GND Return current path
28 MIPI_RX0_D0P MIPI_TX1/RX1_D0P MIPI CSI positive differential data line transceiver output
29 MIPI_RX0_D0N MIPI_TX1/RX1_D0N MIPI CSI negative differential data line transceiver output
30 GND GND Return current path
  • eMMC Socket Pin Spec
Pin# Assignment Pin# Assignment
1 EMMC_D0 2 EMMC_D1
3 EMMC_D2 4 EMMC_D3
5 EMMC_D4 6 EMMC_D5
7 EMMC_D6 8 EMMC_D7
9 EMMC_STRB 10 GND
11 EMMC_CMD 12 EMMC_CLKO
13 N/C 14 GND
15 N/C 16 VCC1V8_S3
17 eMMC_RST 18 VCC3V3_S3
19 GND 20 GND
  • Debug UART Pin Spec
3V level signals, 1500000bps
Pin# Assignment Description
1 GND 0V
2 VCC5V0_SYS 5V power output
3 UART2DBG_TX output
4 UART2DBG_RX intput
  • USB Port
USB 3.0 port has 2A overcurrent protection.
  • RTC
RTC backup current is 27uA.
Connector P/N: Molex 53398-0271
Notes
  1. Power Input : 5V/3A, via USB Type-C or Pin2&Pin4 of the 40-pin GPIO1 header
  2. For more details refer to the Schematic: NanoPi-M4-2GB-1807-Schematic.pdf NanoPi-M4-4GB-1807-Schematic.pdf

Board Dimension

NanoPi M4 Dimensions

For more details refer to the CAD document: NanoPi-M4-1807-Drawing(dxf).zip

Get Started

Essentials You Need

Before starting to use your NanoPi-M4 get the following items ready

  • NanoPi-M4
  • Type-C cable
  • TF Card: Class 10 or Above, minimum 8GB SDHC
  • USB to serial adapter(optinal, for debugging or access from PC host)
  • 5V/3A Power adapter
  • HDMI monitor or LCD
  • USB keyboard, mouse and possible a USB hub(or a TTL to serial board)
  • A host computer running Ubuntu 18.04 64-bit system

Boot from SD Card

Get the following files from here download link:

  • Get an 8G SDHC card and backup its data if necessary.
Image Files
rk3399-sd-friendlydesktop-bionic-4.4-arm64-YYYYMMDD.img.zip FriendlyDesktop image file with X Window (base on Ubuntu 18.04 64bit)
rk3399-sd-friendlycore-bionic-4.4-arm64-YYYYMMDD.img.zip FriendlyCore with Qt 5.10.0 (base on Ubuntu core) image file
rk3399-sd-lubuntu-desktop-xenial-4.4-armhf-YYYYMMDD.img.zip LUbuntu Desktop image file with X Window
Flash Utility:
win32diskimager.rar Windows utility. Under Linux users can use "dd"
  • Extract these files. Insert an SD card(at least 8G) into a Windows PC and run the win32diskimager utility as administrator. On the utility's main window select your SD card's drive, the wanted image file and click on "write" to start flashing the SD card.
  • Insert this card into your board's boot slot and power on, If the PWR LED is on and LED1 is blinking this indicates your board has successfully booted.
  • The Android system does not support starting from the SD card. If you need to run the Android system, please buy the eMMC module, and then burn the Android system to the eMMC to run, referring to the following section.


Access hardware

Access Serial Interface

For now only UART4 is available for users:

Serial Interface Serial Device
UART0 Used by Bluetooth
UART1 Used by Gbps Ethernet
UART2 Used by Serial Debug Port
UART3 Used by Gbps Ethernet
UART4 Available, device name is /dev/ttyS4 (note: this is only applicable for ROM released after 20180618)

Work with FriendlyDesktop

Friendlydesktop-home.png

Arduino
Firefox
Scratch

FriendlyDesktop is a light-weighted Ubuntu desktop system. It is based on LXDE and has the following features:
    Latest Version - Based on Ubuntu 18.04 64
    Various Development Utilities - It is compatible with FriendlyCore and has integrated an optimized Qt5.10, QtCreator and Arduino IDE.
    Light-weighted - it consumes relatively less CPU resources than a common desktop system. When a system's RAM is sufficient it can achieve much better performance.
    Less Power Consumption - it consumes relatively less power or resources than a common desktop system to achieve the same performance.
    Compact and Neat - its desktop is based on GTK+ 2 and it supports multiple languages.
    Easy to Use - its GUI looks similar to MS Windows'.
    Customizable - Users can customize LXDE's GUI.
    Compatible - it is compatible with freedesktop.org.
FriendlyELEC has optimized support for Mali GPU and VPU in FriendlyDesktop for RK3399 and integrated drivers for X.org. FriendlyDesktop supports Hardware Cursor, OpenGL graphic acceleration, 4K video playing with hardware decoding.

Account & Password

Regular Account:

   User Name: pi
   Password: pi

Root:

   User Name: root
   Password: fa

WiFi Connection

Click on the icon on the top right in the FriendlyDesktop's main window, select your wanted WiFi hotspot and proceed with prompts

HDMI/DP LCD Resolution

Open the system's menu and go to Perferences -> Monitor Settings to customize your settings.
Recommended resolution: 1920x1080@60Hz

eDP LCD Display Rotation

If you want to rotate an eDP LCD's display you can do it by commanding "xrotate.sh" to rotate its display to 90/180/270 degrees. You can rotate display clockwise by 90 degrees by running the following command as root. This command calls lightdm to make your change effective immediately:

sudo xrotate.sh -m CW -r

For more details about its options you can run "xrotate -h".
Note: this command doesn't support HDMI display's rotation. If you want to rorate an HDMI's display you need to refer to X11's tech documents and make changes in "/etc/X11/xorg.conf".

Note: when you play a video with hardware decoding your player's display window doesn't rotate with your LCD's display

Test OpenGL ES

You can test it by clicking on the Terminator icon to start a commandline utility in the System Tools and run the following commands:

taskset -c 4-5 glmark2-es2

Friendlydesktop-glmark-es.png
Friendlydesktop-glmark-es2-score.jpg

4K Video Playing

Play with Qt Player with Hardware Decoding

FriendlyDesktop has integrated a Qt5-VideoPlayer utility. This utility has support for Rockchip's gstreamer plug-in and supports 4K video playing with hardware decoding. You can start it by following the steps below: On FriendlyDesktop's main window open "Sound & Video" and click on "Qt5-VideoPlayer".

On the player's main window click on the bottom left's "Open" button to load a video file and double-click on its name on the file list to start video playing. Here is how it looks like. You can set the display window to full screen and adjust the volume:
Friendlydesktop-player.jpg

Play with Linux Command

You can play it by running the following command in a commandline utility:

gst-player.sh

By default its voice will be output to audio jack. You can locate this script by commanding "which gst-player.sh". You can customize its behavior by making changes in this script.

Work with USB Camera

Connect a USB camera e.g. Logitech C270/C920 to a board that runs FriendlyDesktop. After your system is booted click on the "Other" menu option in the main window to start "xawtv" and you will be able to preview with this camera.

File Transfer with Bluetooth

Click on the "Preferences" in the main window's menu to start Bluetooth Manager and click on "Search" to search surrounding Bluetooth devices. Click on your wanted device, pair the device with your board and you will be able to do file transfer, here is how it looks like:
Friendlydesktop-ble-sendfile.jpg

Install OpenCV

On FriendlyDesktop's main window click on System Tools -> Terminator to open a commandline utility and run the following commands to install OpenCV 3.4:

su -
cd /root/
git clone https://github.com/friendlyarm/install-opencv-on-friendlycore
cd install-opencv-on-friendlycore
./install-opencv.sh
cp examples/cv-env.sh /usr/bin/

After installation is done compile it and test it by running a facial recognition test case:

su -
cd /usr/local/share/OpenCV/samples/cpp
g++ -ggdb facedetect.cpp -o facedetect `pkg-config --cflags --libs /usr/local/lib/pkgconfig/opencv.pc`
. setqt5env
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.3 /usr/local/share/OpenCV/samples/data/data/lena.jpg

Here is how it looks like:
Friendlydesktop-opencv.png

Develop Qt Applications

FriendlyDesktop has a Qt 5.10.0 which supports RK3399's OpenGL ES and Gstreamer 1.0 hardware acceleration and a QtCreator IDE which is ready and can be used to compile and run applications. Here is how it looks like:
Friendlydesktop-qtcreator.png

WiringPi and Python Wrapper


Work with MIPI Camera OV13850 Under Linux

Hardware Setting: The present Linux kernel only supports MIPI-CSI1 so a camera module can only be connected to a MIPI-CSI1 port and here is the hardware setting:
M4-mipi-single-camera.jpg


FriendlyELEC provides a test script "gst-camera.sh" to test a camera's functions. You can run it in a commandline to test picture taking and video recording. You can install the script by running the following command:

sudo wget http://112.124.9.243:8888/rk3399/gst-camera.sh -O `which gst-camera.sh`

Options in "gst-camera.sh"

Options Comment
--index or -i Camera's index, it can be either 0 or 1. When two cameras are connected to a board you need to specify 1 to access the second camera.
--mode or -m Camera's resolution. For example if a camera's resolution is 720P 30FPS you can set width=1280, height=720 and framerate=30/1
--action or -a Specify an action, it can be "preview" to preview, "photo" to take a picture or "video" to record video
--output or -o Specify an output file to save a picture when taking a picture or video file when recording video
--verbose or -v If it is specified as "yes" it will output the complete command when "gst-launch-1.0" is called

Usage of gst-camera.sh

  • Preview
gst-camera.sh --action preview
  • Picture Taking

You can run the following command to take a picture and save it as a "1.jpg" file,

gst-camera.sh --action photo -output 1.jpg
  • Preview and Record

You can run the following command to preview and record video and save your video to a "1.ts" file. Hardware encoding is activated when it is recording video.

gst-camera.sh --action video -output 1.ts


  • Show Complete Command

If you add the "--verbose yes" option it will show a complete gsteamer command.

gst-camera.sh --action video --output 1.ts --verbose yes

Here is the complete gsteamer command you will see:

gst-launch-1.0 rkisp num-buffers=512 io-mode=4 path-iqf=/etc/cam_iq/ov13850.xml \
    ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 \
    ! tee name=t t. ! queue ! kmssink t. ! queue ! mpph264enc \
    ! queue ! h264parse ! mpegtsmux ! filesink location=1.ts

Work with FriendlyCore

Introduction

FriendlyCore is a Ubuntu core based OS which doesn't have X Desktop. Its current version is 18.04

FriendlyCore targets enterprise users and is customized for industrial applications. FriendlyCore and Ubuntu base target different users. FriendlyCore has both a commandline utility and a two GUI utilities:
1)Qt 5.10.0 cuustomized for ROCKCHIP3399. It supports GPU and VPU acceleration and has modules like: QtQuick/QtWebEngine/QtMultimedia/WebGL and three display plug-ins:KMS, EGLFS and XCB;
2) Xorg system. It can run X11 applications and supports hardware acceleration;

FriendlyCore for RK3399 has the following features:

  • supports FriendlyElec's 7"LCD with capacitive touch - HD702. If a board is connected to both an LCD and an HDMI monitor the LCD and the HDMI monitor can be set to display either differently or the same;
  • supports Gstreamer 1.0 multi-media framework;
  • supports hard encoding video playing with either commandline utility or Qt player;
  • supports Qt5 WebGL;
  • supports Qt5 VNC and runs a Qt application as a VNC Server allowing remote control;
  • supports bluetooth. It has preinstalled bluez packages;

FriendlyCore's User Accounts

  • If your board is connected to an HDMI monitor you need to use a USB mouse and keyboard.
  • If you want to do kernel development you need to use a serial communication board, ie a PSU-ONECOM board, which will

You can use a USB to Serial on NanoPi-M4:
T4usb2serialport.jpg

  • FriendlyCore User Accounts:

Non-root User:

   User Name: pi
   Password: pi

Root:

   User Name: root
   Password: fa

The system is automatically logged in as "pi". You can do "sudo npi-config" to disable auto login.

  • Update packages
$ sudo apt-get update

Configure System with npi-config

The npi-config is a commandline utility which can be used to initialize system configurations such as user password, system language, time zone, Hostname, SSH switch , Auto login and etc. Type the following command to run this utility.

$ sudo npi-config

Here is how npi-config's GUI looks like:
npi-config

Develop Qt Application

The Qt 5.10.0 FriendlyELEC ported for RK3399 supports the following plug-ins:KMS, EGLFS and XCB. All these three plug-ins support OpenGL ES and GPU hardware acceleration but in different ways:

  • KMS - it calls Linux kernel's DRM interface to display
  • EGLFS - it calls OpenGL ES interface to display
  • XCB - it runs on X11 server and is integrated in X11 windows system


Three plug-ins support different Qt features and here is a table:

Plug-in OpenGL ES QtWebEngine QtMultimedia Video Playing with Hardware Decoding Different Display
KMS Yes No Yes No Yes
EGLFS Yes No Yes No No
XCB Yes Yes Yes Yes Yes

We recommend to use KMS or XCB.

FriendlyCore has four scripts for setting Qt environmental variables for users and here is a table:

Script Comment
/usr/bin/setqt5env-kms set kms' environmental variables
/usr/bin/setqt5env-eglfs set eglfs' environmental variables
/usr/bin/setqt5env-xcb set xcb's environmental variables
/usr/bin/setqt5env-nogui set environmental variables for a system without a Qt GUI

For instance, if you want to use KMS to display you can run the following commands:

. setqt5env-kms
./apps

(Note:there is a space between '.' and 's')

Setup Qt Development Envronment

FriendlyELEC developed two methods for RK3399 to cross-compile a Qt program:

Qt Demo

FriendlyCore has several Qt demo programs:

  • Qt QML: CinematicExperience

CinematicExperience is a utility for selecting a video file and it is developed with Qt QML.
This demo uses Qt QML's various features and runs very smoothly on RK3399. This performance is achieved by hardware and software optimization.
You can start it in a commandline utility by running the following commands:

cd /opt/Qt5_CinematicExperience
./run.sh

Here is what it looks like:
Cinematicsexperience.jpg

  • QQt WebEngine: web browser

Qt WebEngine uses Chromium and supports HTML5.
You can start it by running the following commands:

cd /opt/qt5-brower
./run.sh

Here is what it looks like:
Qt5-brower.jpg

Note:Qt WebEngine depends on the Xcb plug-in.

  • Qt Different Display

This demo shows that when a board is connected to an HDMI monitor and an eDP LCD these two devices display differently. You can start it by running the following commands:

cd /opt/qt5-multi-screen-demo
./run.sh

Here is what it looks like:
Qt5-multi-screen.jpg

  • Qt Multimedia: qt5-player with hard decoding

The qt5-player works with Rockchip's gstreamer plug-in and supports 4K video playing. Since Rockchip's plug-in only supports output images to an X11 window the qt5-player needs to use XCB for display.
You can start the demo by running the following commands:

cd /opt/qt5-player
./run.sh

Here is what it looks like. You can set it to display in full-screen and adjust the voice's volume:
Qt5-player.gif

  • Qt WebGL demo: nmapper

Qt WebGL allows you to remotely access a Qt program running on your board.
Before you run the demo you need to connect your board to the internet and run the following commands:

cd /opt/qt5-nmapper
./run-with-webgl.sh

You can open a browser on another device, type the IP address of your board on the browser's address bar, enter and you will be able to see a Qt GUI. Here is what it looks like:
Qtwebgl.gif

  • Qt VNC demo: Smart home applicance GUI

Qt VNC allows you to run a program as a VNC Server on your board and you can access the program from a VNC client on another device. This program can be developed with either QtWidgets or QML.
You can start it by running the following commands:

cd /opt/qt5-smarthome
./run-with-vnc.sh

Start a VNC viewer on a smart phone or mobile device and type your board's IP address and port number 5900. For instance if your board's IP address is 192.168.1.100 you can type "192.168.1.100:5900", enter and you will see the following GUI:
Qt5smarthomevnc.png

Play with Dual Cameras under Qt

This sample shows how to connect dual cameras to the board and play with them. Before run the sample make sure you connect dual cameras and an LCD to your board. In general popular UVC cameras should work however we suggest users use the following modules which we have tested:

Index Model
1 Logitech C270
2 Logitech C270i
3 Logitech C922 Pro

Run the following commands:

cd /opt/dual-camera
./run.sh

Here is what you expect to observe:
Qt5dualcamera.jpg

Setup Program to AutoRun

You can setup a program to autorun on system boot with npi-config:

sudo npi-config

Go to Boot Options -> Autologin -> Qt/Embedded, select Enable and reboot.

Extend TF Card's Section

When FriendlyCore is loaded the TF card's section will be automatically extended.You can check the section's size by running the following command:

$ df -h

WiFi

For either an SD WiFi or a USB WiFi you can connect it to your board in the same way. The APXX series WiFi chips are SD WiFi chips. By default FriendlyElec's system supports most popular USB WiFi modules. Here is a list of the USB WiFi modules we tested:

Index Model
1 RTL8188CUS/8188EU 802.11n WLAN Adapter
2 RT2070 Wireless Adapter
3 RT2870/RT3070 Wireless Adapter
4 RTL8192CU Wireless Adapter
5 mi WiFi mt7601

You can use the NetworkManager utility to manage network. You can run "nmcli" in the commandline utility to start it. Here are the commands to start a WiFi connection:

  • Change to root
$ su root
  • Check device list
$ nmcli dev

Note: if the status of a device is "unmanaged" it means that device cannot be accessed by NetworkManager. To make it accessed you need to clear the settings under "/etc/network/interfaces" and reboot your system.

  • Start WiFi
$ nmcli r wifi on
  • Scan Surrounding WiFi Sources
$ nmcli dev wifi
  • Connect to a WiFi Source
$ nmcli dev wifi connect "SSID" password "PASSWORD" ifname wlan0

The "SSID" and "PASSWORD" need to be replaced with your actual SSID and password.If you have multiple WiFi devices you need to specify the one you want to connect to a WiFi source with iface
If a connection succeeds it will be automatically setup on next system reboot.

For more details about NetworkManager refer to this link: Use NetworkManager to configure network settings

If your USB WiFi module doesn't work most likely your system doesn't have its driver. For a Debian system you can get a driver from Debian-WiFi and install it on your system. For a Ubuntu system you can install a driver by running the following commands:

$ apt-get install linux-firmware

In general all WiFi drivers are located at the "/lib/firmware" directory.


Ethernet Connection

If a board is connected to a network via Ethernet before it is powered on it will automatically obtain an IP with DHCP activated after it is powered up. If you want to set up a static IP refer to: Use NetworkManager to configure network settings

WiringPi and Python Wrapper

Set Audio Device

If your system has multiple audio devices such as HDMI-Audio, 3.5mm audio jack and I2S-Codec you can set system's default audio device by running the following commands.

  • After your board is booted run the following commands to install alsa packages:
$ apt-get update
$ apt-get install libasound2
$ apt-get install alsa-base
$ apt-get install alsa-utils
  • After installation is done you can list all the audio devices by running the following command. Here is a similar list you may see after you run the command:
$ aplay -l
card 0: HDMI
card 1: 3.5mm codec
card 2: I2S codec

"card 0" is HDMI-Audio, "card 1" is 3.5mm audio jack and "card 2" is I2S-Codec. You can set default audio device to HDMI-Audio by changing the "/etc/asound.conf" file as follows:

pcm.!default {
    type hw
    card 0
    device 0
}
 
ctl.!default {
    type hw
    card 0
}

If you change "card 0" to "card 1" the 3.5mm audio jack will be set to the default device.
Copy a .wav file to your board and test it by running the following command:

$ aplay /root/Music/test.wav

You will hear sounds from system's default audio device.
If you are using H3/H5/H2+ series board with mainline kernel, the easier way is using npi-config

Run the X11 application

FriendlyCore system built-in lightweight Xorg,although there is no window manager, you can still run a single X-Windows application,For example, the program to run is ~/YourX11App,use the following command:

. /usr/bin/setqt5env-xcb
startx ~/YourX11App -geometry 1280x800

Note that there is a space between "." and /usr/bin/setqt5env-xcb. In addition, the resolution after -geometry should be changed to the actual resolution of your screen.

Work with MIPI Camera OV13850 Under Linux

Hardware Setting: The present Linux kernel only supports MIPI-CSI1 so a camera module can only be connected to a MIPI-CSI1 port and here is the hardware setting:
M4-mipi-single-camera.jpg


FriendlyELEC provides a test script "gst-camera.sh" to test a camera's functions. You can run it in a commandline to test picture taking and video recording. You can install the script by running the following command:

sudo wget http://112.124.9.243:8888/rk3399/gst-camera.sh -O `which gst-camera.sh`

Options in "gst-camera.sh"

Options Comment
--index or -i Camera's index, it can be either 0 or 1. When two cameras are connected to a board you need to specify 1 to access the second camera.
--mode or -m Camera's resolution. For example if a camera's resolution is 720P 30FPS you can set width=1280, height=720 and framerate=30/1
--action or -a Specify an action, it can be "preview" to preview, "photo" to take a picture or "video" to record video
--output or -o Specify an output file to save a picture when taking a picture or video file when recording video
--verbose or -v If it is specified as "yes" it will output the complete command when "gst-launch-1.0" is called

Usage of gst-camera.sh

  • Preview
gst-camera.sh --action preview
  • Picture Taking

You can run the following command to take a picture and save it as a "1.jpg" file,

gst-camera.sh --action photo -output 1.jpg
  • Preview and Record

You can run the following command to preview and record video and save your video to a "1.ts" file. Hardware encoding is activated when it is recording video.

gst-camera.sh --action video -output 1.ts


  • Show Complete Command

If you add the "--verbose yes" option it will show a complete gsteamer command.

gst-camera.sh --action video --output 1.ts --verbose yes

Here is the complete gsteamer command you will see:

gst-launch-1.0 rkisp num-buffers=512 io-mode=4 path-iqf=/etc/cam_iq/ov13850.xml \
    ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 \
    ! tee name=t t. ! queue ! kmssink t. ! queue ! mpph264enc \
    ! queue ! h264parse ! mpegtsmux ! filesink location=1.ts

Work with Lubuntu

See here: Lubuntu-RK3399

Work with Android 8.1

FriendlyElec provides a full Android8.1 BSP for NanoPi-M4. The source code is hosted at gitlab.com and is open source. The BSP supports GPU and VPU hardware acceleration.

Connect MIPI Camera to T4

FriendlyElec developed a MIPI camera CAM1320 for NanoPi-M4 and it works under Android. You can use this camera to take pictures and record video. The operation is straightforward. You just need to connect the camera at your NanoPi-M4's MIPI interface, boot your T4 to Android and start Android's camera app.

The NanoPi-M4 has two MIPI interfaces: one front camera and the other rear camera:

Interface Camera Type(front or rear)
MIPI-CSI1 Android rear camera
MIPI-CSI2 Android front camera

How to connect:
M4-mipi-dual-camera.jpg

Android8.1 hardware access

You can use the FriendlyThings SDK to access and control hardware resources on the motherboard in the Android App, such as Uart, SPI, I2C, GPIO and other interfaces. For details, please refer to the following two documents.:

Android Neural Networks SDK Sample

Android8.1 BSP预装了Rockchip为Android8.1提供的Android NN SDK,支持GPU加速。
我们提供的Android8固件中预装了Android NN的示例程序:TfLiteCameraDemo,这是一个使用Rockchip AndroidNN GPU加速的MobileNet分类器Demo,运行时需要主板连接有摄像头模块,USB摄像头和CSI摄像头都是支持的,示例程序通过点击首页的 “TfLiteCameraDemo”图标进入,运行效果如下所示:

TfLiteCameraDemo.png
关于Android NN SDK的详细描述,可以参考原厂的这份文档:[RK3399_Android8.1_AndroidNN_SDK_V1.0_20180605发布说明.pdf]
TfLiteCameraDemo示例源代码下载地址:[TfLiteCameraDemo源代码]

Work with USB Camera to Take Pictures and Record Video

FriendlyELEC's Android system supports picture taking and video recording with a USB camera, Android's camera app has these functions. When you use the app to take pictures or record video you need to be aware of the following two things:
1) Make sure your camera's resolution works. We suggest you try a camera with a lower CIF resolution first. If it works you may switch to a camera with a higher resolution:
Android8-usbcamera-setting.png;
2)A USB camera cannot work simultaneously with a MIPI camera. Plug and play is not supporter for camera modules. After you connect a camera to a board you need to reboot your board to enable the camera.

Here are the camera modules we tested: Logitech C270 and LogitechC922 PRO
In our test the resolution was 1080P when we used a Logitech C922 PRO to take pictures or record video.

Android下使用4G模块EC20

连接方法

连接时,需要通过USB to miniPCIe转接板转接EC20,再连接到主板的USB Host端口,如下图所示:
M4-4g-ec20.jpg
连接后无需额外的配置,启动Android后就可以使用4G上网了,跟Android手机类拟。

启用EC20的GPS功能

默认情况下,Android的GPS功能是关闭的 (原因是Android在没有找到任何GPS模块的情况下,会不停的打印LOG信息),在你连接了EC20模块后,就可以开启GPS了。
开启方法是修改Android源代码下的 vendor/quectel/ec20/BoardConfigPartial.mk 文件,将下面这行:

BOARD_HAS_GPS := false

改为

BOARD_HAS_GPS := true

然后重新编译 Android。

Work with Android7.1

See here: Android7

Make Your Own OS Image

Setup Development Environment

In order to compile an Android image we suggest you do it on a 64 bit Ubuntu 16.04 system and install the following packages:

sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
sudo apt-get install flex curl libncurses5-dev libssl-dev zlib1g-dev gawk minicom
sudo apt-get install openjdk-8-jdk
sudo apt-get install exfat-fuse exfat-utils device-tree-compiler liblz4-tool

For more details refer to https://source.android.com/source/initializing.html;
Or you can do it in Docker: friendlyelec-android-docker

Install Cross Compiler

Install aarch64-linux-gcc 6.4

This compiler can be used to compile a Linux kernel and u-boot. You can do it by running the following commands:

git clone https://github.com/friendlyarm/prebuilts.git
sudo mkdir -p /opt/FriendlyARM/toolchain
sudo tar xf prebuilts/gcc-x64/aarch64-cortexa53-linux-gnu-6.4.tar.xz -C /opt/FriendlyARM/toolchain/

Add the compiler's directory to the PATH variable by appending the following lines to the ~/.bashrc file:

export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin:$PATH
export GCC_COLORS=auto

Run the ~/.bashrc script to make it effective in the current commandline. Note: there is a space after ".":

. ~/.bashrc

This is a 64 bit compiler and cannot work on a 32 bit Linux system. You can test if your compiler is installed correctly by running the following commands:

aarch64-linux-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/6.4-aarch64/libexec/gcc/aarch64-cortexa53-linux-gnu/6.4.0/lto-wrapper
Target: aarch64-cortexa53-linux-gnu
Configured with: /work/toolchain/build/aarch64-cortexa53-linux-gnu/build/src/gcc/configure --build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=aarch64-cortexa53-linux-gnu --prefix=/opt/FriendlyARM/toolchain/6.4-aarch64
--with-sysroot=/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot --enable-languages=c,c++
--enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-cpu=cortex-a53
...
Thread model: posix
gcc version 6.4.0 (ctng-1.23.0-150g-FA)

Compile Android8.1 Source Code

Download Android8.1 Source Code

NanoPi-M4 source code is maintained in gitlab, You can download it by running the following command:

git clone https://gitlab.com/friendlyelec/rk3399-android-8.1 --depth 1 -b master

Generate Image File

You can compile an Android7 source code and generate an image file:

cd rk3399-android-8.1
./build-nanopc-t4.sh -F -M

Update System with New Image

After compilation is done a new image file will be generated in the "rockdev/Image-nanopc_t4/" directory under Android 8.1's source code directory. You can follow the steps below to update the OS in NanoPi-M4:
1) Insert an SD card which is processed with EFlasher to an SD card reader and insert this reader to a PC running Ubuntu. The SD card's partitions will be automatically mounted;
2) Copy all the files under the "rockdev/Image-nanopc_t4/" directory to the SD card's android8 directory in the "FRIENDLYARM" partition;
3) Insert this SD card to NanoPi-M4 and reflash Android
Here is an alternative guide to update OS: sd-fuse_rk3399

Compile Android7 Source Code

Download Android7 Source Code

NanoPi-M4 source code is maintained in gitlab. You can download it by running the following command:

git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat

Generate Image File

You can compile an Android7 source code and generate an image file:

cd rk3399-nougat
./build-nanopc-t4.sh -F -M

Update System with New Image

After compilation is done a new image file will be generated in the "rockdev/Image-nanopc_t4/" directory under Android7's source code directory. You can follow the steps below to update the OS in NanoPi-M4:
1) Insert an SD card which is processed with EFlasher to an SD card reader and insert this reader to a PC running Ubuntu. The SD card's partitions will be automatically mounted;
2) Copy all the files under the "rockdev/Image-nanopc_t4/" directory to the SD card's android8 directory in the "FRIENDLYARM" partition;
3) Insert this SD card to NanoPi-M4 and reflash Android
Here is an alternative guide to update OS: sd-fuse_rk3399

Compile FriendlyCore/FriendlyDesktop/Lubuntu's Kernel

git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
cd kernel-rockchip
make ARCH=arm64 nanopi4_linux_defconfig
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
make ARCH=arm64 nanopi4-images

After compilation is done a kernel.img and a resource.img will be generated. You can simply copy them to replace the existing files in your eflasher SD card. We assume your SD card's FRIENDLYARM partition is mounted at the FRIENDLYARM directory and you can run the following commands to update system:

# for Lubuntu
cp kernel.img resource.img /media/FRIENDLYARM/lubuntu/
 
# for FriendlyCore
cp kernel.img resource.img /media/FRIENDLYARM/friendlycore-arm64/
 
# for FriendlyDesktop
cp kernel.img resource.img /media/FRIENDLYARM/friendlydesktop-arm64/

Or you can use a USB Type-C cable and the Linux_Upgrade_Tool utility to update system.

Compile FriendlyCore/FriendlyDesktop/Lubuntu U-boot Source Code

git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat
cd rk3399-nougat/u-boot
make CROSS_COMPILE=aarch64-linux- rk3399_defconfig
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
make CROSS_COMPILE=aarch64-linux-

After compilation is done a uboot.img, a trust.img and a rk3399_loader_v1.12.109.bin will be generated. You need to rename the rk3399_loader_v1.12.109.bin to "MiniLoaderAll.bin" and copy it to replace the existing file in your eflasher SD card. We assume your SD card's FRIENDLYARM partition is mounted at the FRIENDLYARM directory. You can run the following commands to update system:

# for Lubuntu
cp uboot.img trust.img /media/FRIENDLYARM/lubuntu
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/lubuntu/MiniLoaderAll.bin
 
# for FriendlyCore
cp uboot.img trust.img /media/FRIENDLYARM/friendlycore-arm64
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/friendlycore-arm64/MiniLoaderAll.bin
 
# for FriendlyDesktop
cp uboot.img trust.img /media/FRIENDLYARM/friendlydesktop-arm64
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/friendlydesktop-arm64/MiniLoaderAll.bin

Or you can use a USB Type-C cable and the Linux_Upgrade_Tool utility to update system.

Make Bootable SD Card for Mass Production

If you need to make a bootable SD card for mass production you can refer to this github link:sd-fuse_rk3399

The usage of eMMC module

Nanopim4emmc.jpg

Flash Image to eMMC


Download Image and Utilities

Visit download link to download image files and utilities.

Image Files
rk3399-eflasher-android8-YYYYMMDD.img.zip Android 8.1 image file
rk3399-eflasher-android7-YYYYMMDD.img.zip Android 7.1.2 image file
rk3399-eflasher-friendlydesktop-bionic-4.4-arm64-YYYYMMDD.img.zip 64-bit FriendlyDesktop image file based on Ubuntu desktop 18.04 64bit
rk3399-eflasher-friendlycore-bionic-4.4-arm64-YYYYMMDD.img.zip 64-bit FriendlyCore image file(Qt 5.10.0) based on Ubuntu core 18.04 64bit
rk3399-eflasher-lubuntu-desktop-xenial-4.4-armhf-YYYYMMDD.img.zip Lubuntu Desktop(with Qt 5.10.0)
Flash Utility:
win32diskimager.rar Windows utility. Under Linux users can use "dd"

Flash Image to eMMC with eflasher and SD card

  • Get an 8G SDHC card and backup its data if necessary;
  • Download and extract the rk3399-eflasher-OSNAME-YYYYMMDD.img.zip and win32diskimager;
  • Run the win32diskimager utility under Windows as administrator. On the utility's main window select your SD card's drive, the wanted image file EFlasher and click on "write" to start flashing the SD card. Under Linux run "dd" to flash the rk3399-eflasher-OSNAME-YYYYMMDD.img file to your SD card;
  • Take out the SD and insert it to NanoPi-M4's microSD card slot;
  • Power on NanoPi-M4 and it will be booted from your SD card and the EFlasher utility will be automatically launched. You can work with the EFlasher in multiple ways:

1: Connect an HDMI monitor and a USB mouse to your board and work with EFlasher's GUI;
2: Connect your board to a LAN, login onto the board with SSH and type "eflasher" in a commandline utility and proceed with prompts;(Note: when you login with SSH the username is root and the password is fa. Your board's IP address can be found by checking the router's system)
3: Login onto your board via a serial terminal and type "eflasher" to proceed;
4: Connect a lcd2usb to NanoPi-M4, press the K1 button on the LCD2USB board to select your wanted OS and press the K2 button to confirm. The installation process will be shown on lcd2usb;

  • After installation is done turn off the board and take out the SD card from NanoPi-M4, power on the board and it will be booted from eMMC;

Access hardware

Access Serial Interface

For now only UART4 is available for users:

Serial Interface Serial Device
UART0 Used by Bluetooth
UART1 Used by Gbps Ethernet
UART2 Used by Serial Debug Port
UART3 Used by Gbps Ethernet
UART4 Available, device name is /dev/ttyS4 (note: this is only applicable for ROM released after 20180618)

Source code repositories

NanoPi-M4's source code repositories
Android 8.1 Uboot

https://gitlab.com/friendlyelec/rk3399-android-8.1/tree/master/u-boot

Android 8.1 Linux-4.4.y Kernel

https://gitlab.com/friendlyelec/rk3399-android-8.1/tree/master/kernel

Android 8.1 BSP

https://gitlab.com/friendlyelec/rk3399-android-8.1

Android 7.1.2 Uboot

https://gitlab.com/friendlyelec/rk3399-nougat/tree/nanopc-t4-nougat/u-boot

Android 7.1.2 Linux-4.4.y Kernel

https://gitlab.com/friendlyelec/rk3399-nougat/tree/nanopc-t4-nougat/kernel

Android 7.1.2 BSP

https://gitlab.com/friendlyelec/rk3399-nougat

FriendlyCore/FriendlyDesktop/Lubuntu Uboot

https://gitlab.com/friendlyelec/rk3399-nougat/tree/nanopc-t4-nougat/u-boot

FriendlyCore/FriendlyDesktop/Lubuntu Linux-4.4.y Kernel

https://github.com/friendlyarm/kernel-rockchip

Link to Rockchip Resources

Schematic, PCB CAD File

Update Log