VoCore2: DIY sound record device

It is pretty simple to do this, you only need a VoCore2 Ultimate and a compatible microphone(VoCore2 Ultimate headphone interface is HP_L, HP_R, GND, MIC)

1. Download latest firmware from vocore.io/v2.html, currently I am using https://vonger.cn/misc/vocore2/20190604.bin
2. Upgrade your vocore2, if you do not know how to upgrade, read vocore.io/v2.html first.
3. in VoCore2, run the following commands:

echo '#!/bin/sh' > /usr/bin/record
echo '/usr/bin/arecord -f dat' >> /usr/bin/record
chmod +x /usr/bin/record
echo 'nc -ll -p 9090 -e /usr/bin/record &' > /etc/rc.local 

Now VoCore2 is ready, reboot, it will automatically run.

Note: if you do not want it boot at startup, remove the final command and call nc -ll -p 9090 -e /usr/bin/record

We can use any device able to connect to VoCore2 to read the sound data now 🙂
For example, on my macbook, I connect to VoCore2 AP first, then call nc 192.168.61.1 9090 > test.wav
Ctrl+C to end, then I can play test.wav to get the audio I recorded.

Maybe there is some way you can make the audio live online, do your homework.

PS: I make this only for fun. 🙂 Please do not use it for evil.

VoCore2: Weird Issue of Audio 2

When develop embed device, the hardest part is debug weird issue. It is because the bug is very hard to locate, it might be hardware, kernel, or application. Currently the record audio bug is absolutely a weird bug.

But I finally get it!

Bug and me are good friends, we like to play “hide and seek”, if it wins, it is free to drink my blood; if I win, I kill it!

It is because ES8388 ADC require DAC to work, what the design…It is absolutely a chip bug.

Now it works perfectly, recorded sound is very clear. 🙂
And alsamixer is working fine too.

VoCore2: tinc setting up

Prepare a LINUX computer who has public IP, use it as SERVER, named s0
VoCore2 setting up Station mode or AP+Station mode, make it connect to internet, named s1

My VPN network ip address alloc to 192.168.88.xxx, and my VPN network named vonet.

Server part setting up

1. install tinc: for example, apt-get install tinc
2. prepare folders.

mkdir /etc/tinc
mkdir /etc/tinc/vonet
mkdir /etc/tinc/vonet/hosts
echo vonet >> /etc/tinc/nets.boot

3. prepare scripts.

touch /etc/tinc/vonet/tinc-down

#!/bin/sh
ifconfig $INTERFACE down

touch /etc/tinc/vonet/tinc-up

#!/bin/sh
ifconfig $INTERFACE 192.168.88.1 netmask 255.255.255.0

touch /etc/tinc/vonet/tinc.conf

Name=s0
Interface=tun0
Device=/dev/net/tun
Mode=switch

touch /etc/tinc/vonet/hosts/s0

Address=[your server public ip address]
Subnet=192.168.88.1/32

4. chmod +x /etc/tinc/vonet/tinc-*
5. create keys. tincd -n vonet -K

note: [your server public ip address] replace to your server public ip, format like 11.22.33.44.

Client part, on VoCore2

1. Install tinc:

opkg update
opkg install tinc

2. make folders

mkdir /etc/tinc
mkdir /etc/tinc/vonet
mkdir /etc/tinc/vonet/hosts
echo vonet >> /etc/tinc/nets.boot

3. scripts:

touch /etc/tinc/vonet/tinc-down

#!/bin/sh
ifconfig $INTERFACE down

touch /etc/tinc/vonet/tinc-up

#!/bin/sh
ifconfig $INTERFACE 192.168.88.12 netmask 255.255.255.0

touch /etc/tinc/vonet/tinc.conf

Name=s1
ConnectTo=s0
Interface = tun0
Device = /dev/net/tun
Mode=switch

touch /etc/tinc/vonet/hosts/s1

Subnet=192.168.88.1/32
Address=[your client ip]

4. chmod +x /etc/tinc/vonet/tinc-*
5. make keys: tincd -n vonet -K
note: just press enter, it will create a private rsa-key for your current device and a public rsa-key directly attach to /etc/tinc/vonet/host/s1(which is for current device)

6. setting up firewall:

uci set firewall.@zone[1].device="tun0"
uci commit firewall

note: [your client ip] is your vocore station ip address alloced from your router.

After this, copy s0 from server to client /etc/tinc/vonet/hosts
and same time, copy s1 from client to server /etc/tinc/vonet/hosts

call “tinc -n vonet”, start VPN on both server and client.

vonet is my network name, you can change it to yours.

VoCore2: Ethernet x5 + SD card mode

MT7628AN has a weird design. Ethernet port 1,2,3,4 must be all on or all off, that means if use you only one of them, rest 15 pins you have to use as ethernet but can not work in GPIO mode or SD card mode.
So how can we have SD card mode also have more than one ethernet port.

There is a hidden register, we find in mediatek SDcard driver, and I also hacked a router to get the pins out, pins can be find at vocore.io/v2.html

Here is the patch:

--- a/drivers/mmc/host/mtk-mmc/sd.c
+++ b/drivers/mmc/host/mtk-mmc/sd.c
@@ -2739,7 +2739,7 @@
     struct msdc_host *host;
     struct msdc_hw *hw;
     int ret, irq;
-	u32 reg;
+	u32 reg, reg1;
 
     printk("MTK MSDC device init.\n");
     mtk_sd_device.dev.platform_data = &msdc0_hw;
@@ -2754,8 +2754,11 @@
 	//#elif defined (CONFIG_RALINK_MT7628)
 		/* TODO: maybe omitted when RAether already toggle AGPIO_CFG */
 		reg = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x3c));
-		reg |= 0x1e << 16;
+		reg &= ~(0x1e << 16);
 		sdr_write32((volatile u32*)(RALINK_SYSCTL_BASE + 0x3c), reg);
+		reg = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x60)) & ~(0x3<<0) & ~(0x3<<6) & ~(0x3<<10) & ~(0x1<<15) & ~(0x3<<20) & ~(0x3<<24) | (0x1<<0) | (0x1<<6) | (0x1<<10) | (0x1<<15) | (0x1<<20) | (0x1<<24);
+		reg1 = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x1340)) | (0x1<<11); //Normal mode(AP mode) , SDXC CLK=PAD_GPIO0=GPIO11, driving = 8mA
+		sdr_write32((volatile u32*)(RALINK_SYSCTL_BASE + 0x1340), reg1);
 
- 		reg = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x60)) & ~(0x3<<10);
 #if defined (CONFIG_MTK_MMC_EMMC_8BIT)

VoCore2: Weird Issue of Audio

Just fixed that audio record issue last week, but a new issue comes.

If we play wav before record wav, everything works; if we directly record audio, it will not work, and even worse, it will crash the kernel, cause system reboot.

First, I think it is DMA issue, but when I remove my last patch which set audio chip register 0x2B to 0x80, I can record(but data in file is not correct) and system won’t reboot. So it should not DMA issue.

Second, maybe LRCLK or MCLK or BCLK? Now I am using slave mode(master mode clock do not support FS=272, if we record in 272 it will have noise). It might be such issue, have to do more test and monitor I2S pins.

VoCore2: new firmware 20190422

Now new firmware is ready at http://vonger.cn/misc/vocore2/20190422.bin

new firmware is ready at http://vonger.cn/misc/vocore2/20190422.bin
 
New features for VoCore2 and its screen
 
– add ext4 driver to firmware.
– add librt to firmware.
– default support Qt/GDB debug.
– add framebuffer driver and fbcon for console to firmware.
– add dosbox/libsdl makefile to vocore2 github.
– new vocore2 banner in firmware.
– add vocore2 screen driver support to screen sdk.
– add keyboard support to DOOM demo in screen sdk.
 
Bug Fix:
 
– fix audio record issue in 44.1kHz.
– fix feeds source duplicated.
– fix some spell mistake on github.

VoCore2: Extend Storage and Memory

This tutorial need preinstall kmod-fs-ext4.

Extend Storage

Openwrt is using overlay file system, so we can directly attach sd disk or usb disk to overlay use it as extend storage to store more applications.

Default /etc/config/fstab

config 'global'
option	anon_swap	'0'
option	anon_mount	'0'
option	auto_swap	'1'
option	auto_mount	'1'
option	delay_root	'5'
option	check_fs	'0'

config 'mount'
option device '/dev/sda1'
option enabled '1'

config 'mount'
option device '/dev/mmcblk0p1'
option enabled '1'

This defined VoCore will mount sd disk or usb disk automatically.

If we want to attach SD disk as /overlay to enhance the application storage, we need add one line.

...

 config 'mount'
 option device '/dev/mmcblk0p1'
+option target '/overlay'
 option enabled '1'

Then we will have a much bigger system disk.(call df show list)

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 2816      2816         0 100% /rom
tmpfs                    62616       508     62108   1% /tmp
/dev/mmcblk0p1        29963132     45164  28372856   0% /overlay
overlayfs:/overlay    29963132     45164  28372856   0% /
tmpfs                      512         0       512   0% /dev
/dev/mmcblk0p1        29963132     45164  28372856   0% /mnt/mmcblk0p1

In LuCI it is looks like this:

Note: SD/USB storage file system better to be ext4. Other system should work too but might have some issues.

Extend Memory

This “extend memory” is not real memory, it is a swap buffer in SD disk or USB disk. To use it is very simple, just like we use swap in Linux.

Default firmware we already have necessary tools for swap.

  1. make an empty file(for example 128MB) as swap: dd if=/dev/zero of=/mnt/mmcblk0p1/swap bs=1M count=128
  2. setup it as swap file: mkswap /mnt/mmcblk0p1/swap
  3. add this swap to system: swapon /mnt/mmcblk0p1/swap
  4. check the swap: free
             total       used       free     shared    buffers     cached
Mem:        125232      98940      26292        888       3836      76424
-/+ buffers/cache:      18680     106552
Swap:       131068          0     131068

 

 

Screen: Framebuffer Driver Usage

New SDK comes(download at http://vonger.cn/misc/screen/v2screen.tar.xz). Also new port of DOOM, this time, it reaches its max speed, the app is not laggy anymore.

Now we have two versions. One is VoCore version which is big endian, other is DJN version which is little endian.

Big endian is hardware optimized for 24bit bitmap, so you can display 24bit bitmap directly by memory copy.

Little endian is mainly for 16bit bitmap, we use it for frame buffer, so Qt and SDL such library are easily run on it without modify any code.

The two versions are using same driver board.

How to use fbusb.ko

  1. first your firmware must support frame buffer driver, currently firmware after 20190301 support it already.  If you want to use it in your own firmware, you need to select in openwrt source code “make kernel_menuconfig” > Device Drivers > 

    Graphics support > Frame buffer Devices > Support for frame buffer devices.

  2. now your firmware is ready, use scp copy fbusb driver to your vocore2 /root folder. The driver is in screen SDK(http://vonger.cn/misc/screen/v2screen.tar.xz), lib/vocore2/ folder, its name is fbusb.xxxx.ko (xxxx is your screen type)
  3. final step is insert the ko file to your kernel. Call command insmod /root/fbusb.* , if everything works, after this you will find a frame buffer device at /dev/fb0.
  4. now we can test framebuffer, dd if=/dev/urandom of=/dev/fb0 bs=1000 count=768, then you can find random picture on the screen.

Beginner: OpenWrt 18.06.02 stable version

    1. Download from github,

      git clone https://github.com/openwrt/openwrt.git

    2. Checkout stable version 18.06.02, go to new openwrt folder then

      git checkout v18.06.2

    3. Install and  update LuCI, in openwrt folder,
      1. ./scripts/feeds update luci
      2. ./scripts/feeds install -a -p luci
    4. Install vocore2 patch to package, cd openwrt/package, 

      git clone https://github.com/vonger/vocore2.git

    5. Patch openwrt with VoCore2 addition feature support. in openwrt folder,

      patch -p1 < ./package/vocore2/mt7628/openwrt/000-vocore2-compatible.patch

    6. Patch LuCI with VoCore2 addition feature support. patch -p1 < ./package/vocore2/mt7628/openwrt/luci/*.patch

    7. Copy iwinfo patch to iwinfo folder

      1. mkdir ./package/network/utils/iwinfo/patches
      2. cp ./package/vocore2/mt7628/openwrt/080-iwinfo-compatible-ralink.patch ./package/network/utils/iwinfo/patches/
    8. Patch openwrt with VoCore2 es8388 patch for sound.
      1. patch -p1 < ./package/vocore2/es8388/openwrt/000-openwrt-compatible-sound.patch
      2. cp ./package/vocore2/es8388/openwrt/810-es8388-support.patch ./target/linux/ramips/patches-4.14/
    9. Follow the README.md in ./package/vocore2/README.md: 3. config mt7628 in make menuconfig

VoCore2: Develop on Qt Creator

For the people who do not like Java, now we can use Qt creator to make and debug our application remotely instead of Eclipse.

First, better to use 20190127.bin or later version as your firmware, after the tutorial, once you connect VoCore2 to internet, it is easy for you to download applications from openwrt.

We need to install some packages on VoCore2:

opkg install openssh-sftp-server
opkg install libstdcpp
opkg install gdbserver

Now VoCore has setup.

Let’s setup Qt and openwrt on your PC.

  1. We need to patch gdb, I have submitted the patch to github.com/vonger/vocore2, just do all the compile as Beginner Tutorial, it will be ready.
  2. Install gdb. Ye, it is right, if we do not install gdb there will missing some package.
    1. goto path/to/openwrt/build_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/gdb-8.0.1
    2. call “make install”
  3. Make and install Qt.
    1. in make menuconfig -> Library -> Qt5, you can select qt5-core, and ‘M’ is OK, it is pretty big, so do not select as ‘*’
    2. make everything, takes pretty long time.
    3. goto path/to/build_dir/target-mipsel_24kc_musl/qt-everywhere-opensource-src-5.9.7
    4. call “make install”

Final step, setup Qt creator on your PC(path is just example, use your path of openwrt).

    1. Qt Creator -> Preferences -> Devices -> Devices -> Add -> Generic Linux Device
      • Name: VoCore2
      • Authentcation Type: Password
      • Host name: 192.168.61.1
      • SSH port: 22
      • Username: root
      • Password: vocore
    2. Qt Creator -> Preferences -> Kits -> Compilers -> Add -> GCC -> for both C/C++
      • Name: VoCore2 GCC and VoCore2 G++
      • Compiler path (GCC): openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/mipsel-openwrt-linux-musl-gcc
      • Compiler path (G++): openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/mipsel-openwrt-linux-musl-g++
    3. Qt Creator -> Preferences -> Kits -> Compilers -> Debuggers -> Add
      • Name: VoCore2 GDB
      • Path: path/to/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/mipsel-openwrt-linux-musl-gdb
    4. Qt Creator -> Preferences -> Kits -> Qt Versions -> Add.
      • Version Name: Qt 5.9.7 for VoCore2 mips
      • qmake location: path/to/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/qmake
    5.  Qt Creator -> Preferences -> Kits -> Kits -> Add.
      • Name: VoCore2 Qt 5.9.7 (gcc OpenWrt mips)
      • Device Type: Generic Linux Device
      • Device: Generic Linux Device (default for Generic Linux)
      • Compiler: C, VoCore2 GCC; C++, VoCore2 G++
      • Debugger: VoCore2 GDB
      • Qt version: Qt 5.9.7 for VoCore2 mips

Then create a project, in .pro file, add this lines:

target.path = /tmp
INSTALLS += target

Then you can debug it as your other Qt application.

note: for macos, you need to install texinfo, or gdb will fail to install.