# Getting Started with R64 - Banana Pi Wiki

## Introduction

```
  The Banana Pi R64 is a router based development board, which can run on a variety of open source operating systems including OpenWrt,Linux. It has 4 Gigabit LAN ports, 1 Gigabit WAN, and AC wifi AP function. use 64 bit chip design.
```

Read more: [Banana Pi BPI-R64](http://wiki.banana-pi.org/Banana_Pi_BPI-R64)

### Key Features

* &#x20;MediaTek MT7622,1.35GHZ 64 bit dual-core ARM Cortex-A53
* &#x20;1G DDR3 SDRAM
* &#x20;Mini PCIE interface support 4G module
* &#x20;Built-in 4x4n 802.11n/Bluetooth 5.0 system-on-chip
* &#x20;MTK7615 4x4ac wifi on board
* &#x20;Support 1 SATA interface
* &#x20;MicroSD slot supports up to 256GB expansion
* &#x20;8G eMMC flash (option 16/32/64G)
* &#x20;5 port 10/100/1000 Mb Ethernet port
* &#x20;1 Port USB 3.0
* &#x20;Slow I/O:ADC, Audio Amplifier, GPIO, I2C, I2S, IR, PMIC I/F, PWM, RTC, SPI, UART
* &#x20;POE function support

## Development

### Basic Development

#### Prepare to develop

```
 * Prepare 8G/above TF card, USB-Serial interface, Ubuntu System
 * Using your USB-Serial Connect debug console on R64
```

```
 
```

#### How to burn image to SD card

```
 1.You could download latest image from our forum
 * Here is the example image link: 
 
 2.Install bpi-tools on your Ubuntu. If you can't access this URL or any other problems, please go to bpi-tools repo and install this tools manually.
 * apt-get install pv
 * curl -sL https://github.com/BPI-SINOVOIP/bpi-tools/raw/master/bpi-tools | sudo -E bash
 
 3.After you download the image, insert your TF card into your Ubuntu
 * Execute "bpi-copy xxx.img /dev/sdx" to install image on your TF card
 
 4.After step 3, then you can insert your TF card into R64, and press power button to setup R64
```

**How to burn image to onboard eMMC**

```
 Before burning image to eMMC, please prepare a SD card with flashed bootable image and a USB disk. Let's take OpenWrt image (mtk-bpi-r64-preloader-emmc.bin,2020-04-09-OpenWRT-mtk-bpi-r64-EMMC.img) for example, the steps are below:
```

```
 1. Insert the flashed SD card and power on to start the board.(the image on the SD card can be OpenWrt or other linux OS like ubuntu...)
```

```
 2. Copy eMMC bootable OpenWrt image(mtk-bpi-r64-preloader-emmc.bin,2020-04-09-OpenWRT-mtk-bpi-r64-EMMC.img) to USB disk, if the image is compressed please uncompress it before copying to USB disk.
```

```
 3. Plug in USB disk to the board, and mount the USB to /mnt or other directory as follows: (you can skip mounting if it is mounted automatically)
    * mount -t vfat /dev/sda1 /mnt 
    * change your directory to the mounting point, here is : cd /mnt
```

```
 4. Execute following command to enable and copy image to eMMC:
    * echo 0 > /sys/block/mmcblk0boot0/force_ro
    * dd if=2020-04-09-OpenWRT-mtk-bpi-r64-EMMC.img of=/dev/mmcblk0
    * dd if=mtk-bpi-r64-preloader-emmc.bin of=/dev/mmcblk0boot0
    * mmc bootpart enable 1 1   /dev/mmcblk0
```

```
 5. Shutdown, remove SD card and USB disk, and restart the board from eMMC.
```

#### Network-Configuration

* Network-Configuration : <http://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:network:start>

### Advanced Development

#### GPIO

**40 Pins Definition**

**GPIO Control**

* &#x20;echo xxx > /sys/class/gpio/export
* &#x20;echo in/out > /sys/class/gpio/gpioxxx/direction
* &#x20;echo 0/1 > /sys/class/gpio/gpioxxx/value

Check the base gpio, you could see mine is 409

For example: if you want to change gpio 22 as out highlevel, you need input commands like this：

* &#x20;echo 431（22+409） > /sys/class/gpio/export
* &#x20;echo out > /sys/class/gpio/gpio431/direction
* &#x20;echo 1 > /sys/class/gpio/gpio431/value

**PWM Control**

* &#x20;echo x >/sys/class/pwm/pwmchip0/export
* &#x20;echo 200000 >/sys/class/pwm/pwmchip0/pwmx/period
* &#x20;echo 100000 >/sys/class/pwm/pwmchip0/pwmx/duty\_cycle
* &#x20;echo 1 >/sys/class/pwm/pwmchip0/pwmx/enable

**SPI touch panel**

SPI Panel module:

2.4" Touch Screen TFT LCD with SPI Interface, 240x320 (ILI9341 + ADS7843/XPT2046/HR2046)

SPI Panel <–> BPIR64

```
T_DO, T_DIN, T_CLK <–> SPIC_0: MOSI / MISO / CLK
T_CS <–> SPI-CE0
T_IRQ <–> IO-37
SDO, SCK, SDI <–> SPIC_1: MOSI / MISO / CLK
LED <–> PIN-31
DC <–> PIN-11
RESET <–> PIN-13
CS <–> SPI-CE1
GND <–> GND-9
VCC <–> 3.3V-1
```

DTS Modification:

```
/ {
       backlight: backlight {
               compatible = "gpio-backlight";
               gpios = <&pio 82 GPIO_ACTIVE_HIGH>;        //PIN31 IO-31 : GPIO82
               default-on;
       };
};
```

```
&pio {
       spic0_pins: spic0-pins {
               mux {
                       function = "spi";
                       groups = "spic0_0";
               };
       };

       spic1_pins: spic1-pins {
               mux {
                       function = "spi";
                       groups = "spic1_0";
               };
       };
}
```

```
&spi0 {
       pinctrl-names = "default";
       pinctrl-0 = <&spic0_pins>;
       status = "okay";
       touch@0 {
               reg = <0>;                                 //CE0
               compatible = "ti,ads7843";
               interrupt-parent = <&pio>;
               interrupts = <86 0>;                       //PIN37: IO-37 == GPIO86
               pendown-gpio = <&pio 86 0>;
               spi-max-frequency = <1000000>;
               vcc-supply = <®_3p3v>;
               wakeup-source;
       };
};
```

```
&spi1 {
       pinctrl-names = "default";
       pinctrl-0 = <&spic1_pins>;
       status = "okay";
       display@0{
               compatible = "ilitek,ili9341";
               reg = <0>;                                 //CE0
               spi-max-frequency = <32000000>;
               dc-gpios = <&pio 51 GPIO_ACTIVE_HIGH>;     //PIN11 UART1-TXD : GPIO51
               reset-gpios = <&pio 52 GPIO_ACTIVE_HIGH>;  //PIN13 UART1-RXD : GPIO52
               backlight = <&backlight>;
       };
};
```

Kernel config:

```
+CONFIG_FB_TFT_ILI9341
+CONFIG_FB_TFT
+CONFIG_FB
+CONFIG_BACKLIGHT_LCD_SUPPORT
+CONFIG_BACKLIGHT_CLASS_DEVICE
+CONFIG_BACKLIGHT_GPIO
+CONFIG_INPUT
+CONFIG_INPUT_TOUCHSCREEN
+CONFIG_TOUCHSCREEN_ADS7846
```

Application:

input-event-daemon config that show image by touch area: (I don't know why are the coordinates so strange, but the result of my actual touch and print out that it is like this)

```
[Global]
listen = /dev/input/event0
listen = /dev/input/event1
[TouchTEST]
340,400,3440,1860 = cat /dev/zero > /dev/fb0; fbv -f /root/bpi_608x429.jpg -s 1
340,2260,3440,1860 = cat /dev/zero > /dev/fb0; fbv -f /root/openwrt_449x449.png -s 1
```

Banana Pi BPI-R64 SPI touch panel test: <https://www.youtube.com/watch?v=ikag-D_TI0g&feature=youtu.be>

#### Sata

* &#x20;**If you want to use Sata interface on R64, you need to give GPIO90 low level**
  * &#x20;echo 499 > /sys/class/gpio/export
  * &#x20;echo out > /sys/class/gpio/gpio499/direction
  * &#x20;echo 0 > /sys/class/gpio/gpio499/value
* Test a TOSHIBA HDD DISK, the Read/Write performance are below:

Read from disk: 50MB/s command: dd if=/dev/sda of=/dev/null bs=1M count=1024Write to disk: 38MB/s command: dd if=/dev/zero of=/dev/sda bs=1M count=1024

* Test a SAMSUNG SSD DISK, the Read/Write performance are below:

Read from disk: 360MB/s command: dd if=/dev/sda of=/dev/null bs=1M count=1024Write to disk: 200MB/s command: dd if=/dev/zero of=/dev/sda bs=1M count=1024

#### PCIe

* &#x20;**If you want to use PCIe interface on R64, you need to give GPIO90 high level**
  * &#x20;echo 499 > /sys/class/gpio/export
  * &#x20;echo out > /sys/class/gpio/gpio499/direction
  * &#x20;echo 1 > /sys/class/gpio/gpio499/value
* &#x20;PCIe supports EC-25 4G module.

#### GMAC

Use iperf3 to test gmac

1\. On PC Terminal:

* &#x20;Execute "iperf3 -s"

2\. On R64 console:

* &#x20;TCP test: "iperf3 -c serverIP"
* &#x20;UDP test: "iperf3 -u -c serverIP"

#### BT & BLE on R64

**R64 BT Architectural**

* &#x20;BLE on R64
* &#x20;Input Command "btmw-test", you will enter to "btmw\_test\_cli" command line
* &#x20;Here are some example commands：
  * &#x20;MW\_GAP name 7622\_BT /\*rename bt device\*/
  * &#x20;MW\_GAP info /\*check local BT device info\*/
  * &#x20;MW\_GATTC scan /\* start ble scan\*/
  * &#x20;MW\_GATTC stop\_scan /\* stop ble scan\*/

#### R64 LAN Function

* &#x20;LAN eth interface is eth2, use "ifconfig eth2 up" to enable it.
* &#x20;Config the ip, "ifconfig eth2 192.168.1.1".

```
 
```

* &#x20;Config your dhcp server, "vim /etc/dhcp/dhcpd.conf", add these configurations.

```
 
```

* &#x20;Start dhcp server, "dhcpd eth2".

```
 
```

* &#x20;then config iptables and set package forward.
  * &#x20;Add "net.ipv4.ip\_forward=1" to "/etc/sysctl.conf"
  * &#x20;"/sbin/sysctl -p" to make forward work
  * &#x20;"iptables -t nat -A POSTROUTING -s 192.168.1.1/24 -o eth3 -j MASQUERADE"

#### Ap mode on R64

* &#x20;Find "mt\_wifi.ko" and insmod it.
  * &#x20;insmod ./lib/modules/4.4.92-BPI-R64-Kernel/extra/mt\_wifi.ko
* &#x20;Then you will see ra0 and rai0.

```
 
```

* &#x20;ra0 is MT7622 2.4G wifi
* &#x20;rai0 is MT7615 5G wifi

**2.4G WiFi**

* &#x20;Use "ifconfig ra0 up" to enable it.
* &#x20;Config the ip, "ifconfig ra0 192.168.1.1".
* &#x20;Config your dhcp server, "vim /etc/dhcp/dhcpd.conf", add these configurations.

```
 
```

* &#x20;Start dhcp server, "dhcpd ra0".
* &#x20;then config iptables and set package forward.
  * &#x20;Add "net.ipv4.ip\_forward=1" to "/etc/sysctl.conf"
  * &#x20;"/sbin/sysctl -p" to make forward work
  * &#x20;"iptables -t nat -A POSTROUTING -s 192.168.1.1/24 -o eth3 -j MASQUERADE"

**5G WiFi**

* &#x20;Use "ifconfig rai0 up" to enable it.
* &#x20;Config the ip, "ifconfig rai0 192.168.1.1".
* &#x20;Config your dhcp server, "vim /etc/dhcp/dhcpd.conf", add these configurations.

```
 
```

* &#x20;Start dhcp server, "dhcpd rai0".
* &#x20;then config iptables and set package forward.
  * &#x20;Add "net.ipv4.ip\_forward=1" to "/etc/sysctl.conf"
  * &#x20;"/sbin/sysctl -p" to make forward work
  * &#x20;"iptables -t nat -A POSTROUTING -s 192.168.1.1/24 -o eth3 -j MASQUERADE"

### FAQ

* MT7622 Reference Manual for Develope Board(BPi)

Google Drive：<https://drive.google.com/open?id=1UhaIM9ork1O9cNO-t6ENMVVamB75AThV>BaiDu Drive：<https://pan.baidu.com/s/1KduFT2MUvMs2FhOF4A8kQQ>

## **Reference Link**

<http://forum.banana-pi.org/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bananapi.gitbook.io/banana-pi-bpi-r64-open-source-router-board/untitled.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
