Gpio + uart (not the debug-port)

seems that in kernel 4.14 the fallback-driver mt6577 is used, which can only control 2 uarts

if i disable uart0 then uart1 is found

[14:37] root@bpi-r2:~# dmesg | grep tty
[    0.000000] Kernel command line: board=bpi-r2 console=earlyprintk fbcon=map:0 console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait service0
[    0.230738] console [ttyS0] disabled
[    0.250928] 11004000.serial: ttyS0 at MMIO 0x11004000 (irq = 195, base_baud = 1625000) is a ST16650V2
[    0.918903] console [ttyS0] enabled
[    0.943324] 11003000.serial: ttyS1 at MMIO 0x11003000 (irq = 196, base_baud = 1625000) is a ST16650V2

nice now here is 11003000 aka uart1

here the /sys-tree if all uart are enabled in dts:

[14:30] root@bpi-r2:~# find /sys -name '*serial*'
/sys/devices/platform/11003000.serial
/sys/devices/platform/11230000.mmc/mmc_host/mmc1/mmc1:0001/serial
/sys/devices/platform/11240000.mmc/mmc_host/mmc0/mmc0:0007/serial
/sys/devices/platform/1a240000.usb/usb3/serial
/sys/devices/platform/1a240000.usb/usb4/serial
/sys/devices/platform/11004000.serial
/sys/devices/platform/1a1c0000.usb/usb1/serial
/sys/devices/platform/1a1c0000.usb/usb2/serial
/sys/devices/platform/11002000.serial
/sys/devices/platform/serial8250
/sys/devices/platform/11005000.serial
/sys/firmware/devicetree/base/serial@11004000
/sys/firmware/devicetree/base/aliases/serial2
/sys/firmware/devicetree/base/serial@11003000
/sys/firmware/devicetree/base/serial@11005000
/sys/firmware/devicetree/base/serial@11002000
/sys/fs/cgroup/systemd/system.slice/setserial.service
/sys/fs/cgroup/systemd/system.slice/system-serial\x2dgetty.slice
/sys/fs/cgroup/systemd/system.slice/system-serial\x2dgetty.slice/[email protected]
/sys/fs/cgroup/systemd/system.slice/etc-setserial.service
/sys/bus/platform/devices/11003000.serial
/sys/bus/platform/devices/11004000.serial
/sys/bus/platform/devices/11002000.serial
/sys/bus/platform/devices/serial8250
/sys/bus/platform/devices/11005000.serial
/sys/bus/platform/drivers/mt6577-uart/11004000.serial
/sys/bus/platform/drivers/mt6577-uart/11002000.serial
/sys/bus/platform/drivers/serial8250
/sys/bus/platform/drivers/serial8250/serial8250
/sys/bus/pci/drivers/exar_serial
/sys/bus/pci/drivers/serial

4.4.x seems to use mt2712

Linux bpi-r2 4.4.107-BPI-R2-Kernel #13 SMP Thu Dec 21 13:36:53 CET 2017 armv7l
[14:53] root@bpi-r2:~# find /sys -name '*serial*'
/sys/fs/cgroup/systemd/system.slice/etc-setserial.service
/sys/fs/cgroup/systemd/system.slice/setserial.service
/sys/fs/cgroup/systemd/system.slice/system-serial\x2dgetty.slice
/sys/fs/cgroup/systemd/system.slice/system-serial\x2dgetty.slice/[email protected]
/sys/bus/pci/drivers/serial
/sys/bus/platform/devices/11004000.serial
/sys/bus/platform/devices/11003000.serial
/sys/bus/platform/devices/serial8250
/sys/bus/platform/devices/11002000.serial
/sys/bus/platform/drivers/serial8250
/sys/bus/platform/drivers/serial8250/serial8250
/sys/bus/platform/drivers/mt2712-uart/11004000.serial
/sys/bus/platform/drivers/mt2712-uart/11003000.serial
/sys/bus/platform/drivers/mt2712-uart/11002000.serial
/sys/devices/platform/11230000.mmc/mmc_host/mmc1/mmc1:0001/serial
/sys/devices/platform/11004000.serial
/sys/devices/platform/11003000.serial
/sys/devices/platform/1a1c0000.usb/usb1/serial
/sys/devices/platform/1a1c0000.usb/usb2/serial
/sys/devices/platform/serial8250
/sys/devices/platform/1a240000.usb/usb3/serial
/sys/devices/platform/1a240000.usb/usb4/serial
/sys/devices/platform/11002000.serial
/sys/devices/platform/11240000.mmc/mmc_host/mmc0/mmc0:0007/serial
/sys/firmware/devicetree/base/serial@11002000
/sys/firmware/devicetree/base/serial@11003000
/sys/firmware/devicetree/base/serial@11004000

@garywang can you explain, where mt2712 is loaded for uart?

maybe here

../BPI-R2-4.4/linux-mt/drivers/tty/serial/8250/8250_mtk.c:796:	{ .compatible = "mediatek,mt2712-uart" },
../BPI-R2-4.4/linux-mt/drivers/tty/serial/8250/8250_mtk.c:804:		.name		= "mt2712-uart",

but i’ve not found 8250 in the related dts(i) for bpi-r2

The cause for you guys only can let 2 uarts enabled is I guessed you only allow 2 ports for 8250 driver. You have to configure again with menuconfig.

1 Like
  │ Symbol: SERIAL_8250_NR_UARTS [=2]                                                                             │  
  │ Type  : integer                                                                                               │  
  │ Prompt: Maximum number of 8250/16550 serial ports                                                             │  
  │   Location:                                                                                                   │  
  │     -> Device Drivers                                                                                         │  
  │       -> Character devices                                                                                    │  
  │         -> Serial drivers                                                                                     │  
  │ (6)       -> 8250/16550 and compatible serial support (SERIAL_8250 [=y])                                      │  
  │   Defined at drivers/tty/serial/8250/Kconfig:169                                                              │  
  │   Depends on: TTY [=y] && HAS_IOMEM [=y] && SERIAL_8250 [=y]                                                  │  

:wink: good to know its configurable…

-CONFIG_SERIAL_8250_NR_UARTS=2
-CONFIG_SERIAL_8250_RUNTIME_UARTS=2
+CONFIG_SERIAL_8250_NR_UARTS=4
+CONFIG_SERIAL_8250_RUNTIME_UARTS=4


Linux bpi-r2 4.14.8-00022-gb3e6160-dirty #47 SMP Thu Dec 21 15:53:13 CET 2017 armv7l
[15:56] root@bpi-r2:~# find /sys -name '*serial*'
[15:56] root@bpi-r2:~# dmesg | grep tty
[    0.000000] Kernel command line: board=bpi-r2 console=earlyprintk fbcon=map:0 console=ttyS0,115200 root=/dev/mmcbl0
[    0.231181] console [ttyS0] disabled
[    0.251356] 11004000.serial: ttyS0 at MMIO 0x11004000 (irq = 195, base_baud = 1625000) is a ST16650V2
[    0.919335] console [ttyS0] enabled
[    0.943721] 11002000.serial: ttyS1 at MMIO 0x11002000 (irq = 196, base_baud = 1625000) is a ST16650V2
[    0.973765] 11003000.serial: ttyS2 at MMIO 0x11003000 (irq = 197, base_baud = 1625000) is a ST16650V2
[    4.306955] systemd[1]: Expecting device dev-ttyS0.device...

kernel 4.14.8 with uarts enabled: https://drive.google.com/drive/folders/1EGN1TvqCpDHdOAS-mjRg9ipi0kahnOUV?usp=sharing

Yes, you got the points.

@linkerosa can you explain how in 4.14 gpio-read and pwm works?

tried uart again:

running that on one terminal:

#!/bin/bash
DEV=/dev/ttyS2
stty -F ${DEV} 9600 cs8 -cstopb -parenb
while read line; do
    echo "["$(date "+%Y-%m-%d %H:%M:%S")"] Arduino: "$line
done < <(cat $DEV)

and on the other

[17:20] root@bpi-r2:~# stty -F /dev/ttyS2 sane
[17:20] root@bpi-r2:~# stty -F /dev/ttyS2 9600 cs8 -cstopb -parenb
[17:20] root@bpi-r2:~# echo "blahblubb">/dev/ttyS2

and got some weired chars…same config (9600b 8N1) on raspberry works, also tried with minicom, seems also work…but not with the cat-loop

i think i have got it working:

stty -F ${DEV} 9600 cs8 -cstopb -parenb raw -echo 

should be the right setting. full config, if anyone have problems:

root@bpi-r2:~# stty -F /dev/ttyS2 -a
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

Gpio read is described here: GPIO Python or shell and of. Course in my wiki http://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:gpio

Hello,

Is there a way to get serial working from the box (in compiled image)? I understand everyone here is a linux engineer but how people without this kind of background can get it working?

Thanks in advance,

You can use debian/ubuntu-images and installing one my compiled kernels (4.4 or 4.14). I have activated the uart-nodes.

The configuration of the serial-port itself depends on your device. Basicly you can use raw-mode with 8n1 and desired speed (documentation of your device)

1 Like

Hello Frank,

Thanks a lot for your response. Can you please share a url to your kernel? Do you have debian emmc image with your compiled kernel by any chance? I really appreciate your feedback, thanks a lot again.

Thank you,

Here you find my compiled kernels:

https://drive.google.com/drive/folders/15Y5Y3NAOwg_IMmN3k6hdb7pAQj9oTVTl?usp=sharing

You’ll find that link also on startpage of my wiki. The archive-file contains folders boot and root,which contents have to be copied to the partitions bpi-root/bpi-boot of sd-card.

Currently i have no emmc-image,i’m building currently a clean debian on my emmc. Install on emmc is a bit more tricky because of the partition-change and burning preloader to boot-device

1 Like

Thanks for your help. I have tried to replace boot and root (lib folder) files but received kernel panic on boot. I will try more but wanted to confirm: Files in lib folder should be replaced or merged?

Files I used:

4.4.112-BPI-R2-Kernel-BPI-BOOT-bpi-r2.tgz

4.4.112-BPI-R2-Kernel.tgz

Image: 2017-09-13-debian-9-stretch-mate-desktop-preview-bpi-r2-sd-emmc.img.zip

Thank you,

I think I’ve made it working (I will try tomorrow with real UART to USB converter when I receive my level shifter). Thanks a lot. Do you think Its possible to write everything from SD to EMMC? Or it will work only from SD?

root@bpi-iot-ros-ai:/home/pi# stty -F /dev/ttyS2 -a
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc
root@bpi-iot-ros-ai:/home/pi# stty -F /dev/ttyS1 -a
speed 115200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread clocal crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt
-echoctl -echoke -flusho -extproc
root@bpi-iot-ros-ai:/home/pi#    

Thank you,

Basicly an OS on sd will also work on emmc. You can copy image also via dd to emmc,but you have do some extra steps.

  • First change partition-config in uboot to “48”
  • enable write-access to boot0
  • flash preloader to boot0

Now you have to modify uEnv.txt (config for uboot) on boot-partition and fstab to mount the right root-partition.

You’ll find the most steps in my wiki

http://www.fw-web.de/dokuwiki/doku.php?id=en/bpi-r2/storage

I created my sd/emmc with debootstrap: http://www.fw-web.de/dokuwiki/doku.php?id=en/bpi-r2/debian

1 Like

I will try to do like this and share my results. Thanks

copy kernel (p1) and modules (p2, if you not want to copy full rootfs from SD card)
mkdir -p /mnt/emmc/boot/bananapi/bpi-r2/linux
cp /boot/bananapi/bpi-r2/linux/uImage /mnt/emmc/boot/bananapi/bpi-r2/linux
mkdir -p /mnt/emmc/root/lib/modules/
cp -r /lib/modules/$(uname -r) /mnt/emmc/root/lib/modules/
uboot auf die richtige Partition konfigurieren
sed 's/mmcblk0/mmcblk1/' /boot/bananapi/bpi-r2/linux/uEnv.txt > /mnt/emmc/boot/bananapi/bpi-r2/linux/uEnv.txt

I have manually copied uImage and kernel to eemc on my already preinstalled debian9 and its working fine. Now its booting from emmc using your kernel. Thank a lot Frank, you are the best :slight_smile:

Do you happen to know if I can move rootfs to SATA hdd using your kernel? I read somewhere that it should be custom kernel so sata will be available on boot.

Thank you,

you can only copy rootfs to hdd/ssd (boot-partition must be on emmc/SD)

you just need to change uenv.txt (on sd/emmc) to point to you hdd/ssd-partition (root=/dev/sdax) and change /etc/fstab in your rootfs so that the right / is mounted

but now it’s leaving the topic…please make a new topic if you have more questions

You are right. Thanks for your help and wiki you created (it helped a lot), hope this discussion will be valuable for other people as well.

Thank you,

@frank-w May I know how many UARTs are available in BPI-R2. I would like to use 3 UARTs.

TIA.

Uart 0 and 1 are on 40pin-header,uart2 is the debug-uart (maybe can used in another way) and uart3 are only 2 dots on circuitboard near debug-pins

@garywang: i have some 4 solder-pods next to debug-uarts rx-pin…are these connected to the TPxx-pins of uart3?

Thanks for the quick response. Can we use UART 3 on GPIO?. I dont think the 2 dots of near by debug-pins can soldered.

Also like to know if there is any way to disable the debug-UART and can be used for our purpose.

TIA.