Saturday, June 18, 2022

DIY Mini Chess Clock

DIY rechargeable mini-chess-clock using SAMD21 mini board and 0.91" 128x32 OLED display.


 demo:


 Arduino code: chess-clock.ino





Monday, May 2, 2022

Cheap CMSIS-DAP/DAPLink Debugger+Serial Port Module

Cheap CMSIS-DAP/DAPLink SWD module based on NS32F103CBT6 (an STM32-clone?). It has both a debugger and a serial/UART port on a single USB device just like the J-Link OB v2 debugger (based on STM32F072) - better than those ST-Link debugger clones.

MCU interface:

  • SWD (with pull-up resistors to 3V3)
    • PB10 - CLK
    • PB11 - DAT
  • CDC-UART (UART1)
    • PA9 - TXD
    • PA10 - RXD
  • LEDs (active high)
    • PA2 - running status
    • PA3 - connected status
  • USB:
    • PA11
    • PA12 (with fixed pull-up resistor)

 


Firmwares:
(*should work also on chips with smaller ROM STM32F103C8 (like the BluePill C8)

Tested only on Ubuntu host.
sample kernel logs if using original FW:

usb 1-1: new full-speed USB device number 44 using xhci_hcd
usb 1-1: New USB device found, idVendor=c251, idProduct=f001, bcdDevice= 1.00
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: CMSIS_DAP
usb 1-1: Manufacturer: CMSIS-DAP by ARM
usb 1-1: SerialNumber: 202108120001
cdc_acm 1-1:1.0: ttyACM0: USB ACM device
hid-generic 0003:C251:F001.0015: hiddev0,hidraw2: USB HID v1.00 Device [CMSIS-DAP by ARM CMSIS_DAP] on usb-0000:00:14.0-1/input2

Sample kernel logs if using the modified FW:

usb 1-1: new full-speed USB device number 52 using xhci_hcd
usb 1-1: device descriptor read/64, error -71
usb 1-1: new full-speed USB device number 53 using xhci_hcd
usb 1-1: New USB device found, idVendor=0d28, idProduct=0204, bcdDevice= 1.00
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: DAPLink CMSIS-DAP
usb 1-1: Manufacturer: ARM
usb 1-1: SerialNumber: 20220218979699080605210b3030153632303030
cdc_acm 1-1:1.0: ttyACM0: USB ACM device
usbcore: registered new interface driver cdc_acm
usbhid 1-1:1.2: couldn't find an input interrupt endpoint
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver

Sample openocd configuration:

source [find interface/cmsis-dap.cfg]
transport select swd
source [find target/stm32f4x.cfg]
adapter speed 4000
init
targets
reset halt
If using the original FW, need to add these on the configuration:
cmsis_dap_vid_pid 0xc251 0xf001
cmsis_dap_backend hid

Not tested:

  • UDisk drag-n-drop (looks like not working)
  • WebUSB

 

size comparison (from left to right) :
  1. Blue Pill STM32F103C8
  2. WCH-Link (based on 8051 mcu) - cheaper
  3. NS32F103CB module
  4. J-Link OB v2 clone (STM32F072CB)

 

Reference:

 

Monday, October 5, 2020

STM32 LED Color Matching For Kids

Fun activity for kids with simple LED circuit! The LEDs will light up when the corresponding connectors of the same color are matching.
STM32 Blue Pill (STM32F103C8T6-development-board) circuit connections:
STM32CubeIDE Project: main.c:

Tuesday, April 14, 2020

TVplus Go on Windows 10 PC

Part 2 of TVplus Go on Laptop

Using VirtualBox running Android-x86 guest OS on a Windows 10 PC.
Guides:
1. Android-x86 via VirtualBox
2. Adjust screen resolution. TVplusgo app runs better on 16:9 resolutions (e.g. 1280x720).
3. Enable native bridge (ARM translation layer)
4. Disable root or hide root via Magisk (note: install only v1.0.28 or older of the TVplusgo app).
5. VirtualBox USB pass-through (the official android emulator for Windows, or the Qemu itself, currently does not support USB pass-through).

Tuesday, January 7, 2020

TVplus Go Teardown

Teardown of ABS-CBN TVplus Go USB dongle. This dongle looks like ADTH DGI 1011 (*although the PCB indicates "DGI1012_RevD" instead).



dmesg log when plugged:
[ 2555.447630] usb 1-1: new high-speed USB device number 13 using xhci_hcd
[ 2555.601320] usb 1-1: New USB device found, idVendor=048d, idProduct=9308, bcdDevice= 1.00
[ 2555.601325] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2555.601329] usb 1-1: Product: DGI1011
[ 2555.601331] usb 1-1: Manufacturer: Atlanta DTH, Inc.
[ 2555.601333] usb 1-1: SerialNumber: 000000



The USB chip has a marking of "Tolka101" - most probably developed by Tolka Taiwan Inc. - same company who develops the tvplus go app (?). Beside this chip looks like an external EEPROM chip. (*there are no markings on the RF frontend chip).



For simple modification, I replaced the micro-USB connector with an "older" (but more reliable) type-A USB connector+cable - more suitable since I'm using the dongle on laptop or PC more often than my android phone.

Sunday, December 29, 2019

TVplus Go on Laptop

Watch free ISDB-T digital TV on laptop (or any x86_64 computer) using the ABS-CBN TVplus Go USB dongle.



As of this writing, the TVplus Go dongle only works on Android operating system. So the way to make it work on an x86 platform is either install the Android-x86 or simply use an Android emulator. This demo will use the official emulator running on Ubuntu 18.04 64-bit host OS. Other OS types, like Windows 10, might also work but will still initially require *nix-based tools for modifying the virtual device's ramdisk cpio archive and system ext4 image file.

The TVplus Go Android app, as of version 1.0.28, only works on ARM CPUs (armeabi-v7a and arm64-v8a only). Running the ARM emulator is not advisable because it's too slow and unusable. So the only option now is to install libhoudini (ARM translator) on the x86 emulator.



Guide:
1. Download the Android command line tools (installing the whole Android studio is only optional).
https://developer.android.com/studio, e.g. extract sdk-tools-linux-4333796.zip to ~/android/sdk.

2. Open a terminal, change directory to ~/android/sdk, and set the following environment variables:
$ export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
$ export ANDROID_HOME=$HOME/android/sdk
$ export ANDROID_SDK_ROOT=$ANDROID_HOME

3. Download the emulator, platform-tools, and the system-image. Android Nougat (API-25) is selected because easier to modify compared to with the recent versions.
$ ./tools/bin/sdkmanager "platform-tools" "platforms;android-25" "emulator"
$ ./tools/bin/sdkmanager --install "system-images;android-25;google_apis;x86_64"


4. Go to $ANDROID_SDK_ROOT/system-images/android-25/google_apis/x86_64 and increase the size of the system.img (create a backup first!). Allocate at least 128MB for the additional files.
$ cd $ANDROID_SDK_ROOT/system-images/android-25/google_apis/x86_64
$ dd if=/dev/zero bs=1M count=512 >> ./system.img
$ e2fsck -f system.img
$ resize2fs system.img


5. Copy libhoudini binaries. Mount first the system.img before extracting the files.
$ wget http://dl.android-x86.org/houdini/7_y/houdini.sfs -O houdini_7_y.sfs
$ mkdir -p systemfs
$ sudo mount -o loop -t ext4 system.img systemfs
$ sudo unsquashfs -d systemfs/lib/arm houdini_7_y.sfs
$ sudo cp systemfs/lib/arm/libhoudini.so systemfs/lib/
$ sudo cp systemfs/lib/arm/houdini systemfs/bin/

Either set the selinux to permissive (add -selinux permissive option on the emulator) or set the security context of the libhoudini files.
$ sudo setfattr -n security.selinux -v u:object_r:system_file:s0 systemfs/bin/houdini
$ sudo setfattr -n security.selinux -v u:object_r:system_file:s0 systemfs/lib/libhoudini.so
$ sudo setfattr -n security.selinux -v u:object_r:system_file:s0 systemfs/lib/arm
$ sudo setfattr -n security.selinux -v u:object_r:system_file:s0 systemfs/lib/arm/*
$ sudo setfattr -n security.selinux -v u:object_r:system_file:s0 systemfs/lib/arm/nb/*

6. Allows ARM executable file formats
$ sudo mkdir -p systemfs/etc/binfmt_misc
$ echo ":arm_dyn:M::\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x28::/system/bin/houdini:" | sudo tee systemfs/etc/binfmt_misc/arm_dyn
$ echo ":arm_exe:M::\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28::/system/bin/houdini:" | sudo tee systemfs/etc/binfmt_misc/arm_exe

$ sudo nano systemfs/build.prop
add the following properties to the build.prop (overwrite if existing):
ro.enable.native.bridge.exec=1

ro.product.cpu.abilist=x86_64,x86,armeabi-v7a,armeabi
ro.product.cpu.abilist32=x86,armeabi-v7a,armeabi


7. Enable access to the TVPlus Go USB dongle (vendor id 0x048d, product id 0x9308)
$ echo '<permissions><feature name="android.hardware.usb.host"/></permissions>' | sudo tee systemfs/etc/permissions/android.hardware.usb.host.xml
$ echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="048d", ATTRS{idProduct}=="9308", GROUP="kvm"' | sudo tee /etc/udev/rules.d/89-usb-android.rules
$ sudo udevadm control --reload-rules

8. Hide from "root-detection" and "running-on-emulator-detection"
i. rename the su executable
$ sudo mv systemfs/xbin/su systemfs/xbin/_s_u
ii. edit again build.prop, check these answers on which properties to be modified. Replace, at least, the "generic" string from ro.product.device and ro.build.fingerprint. (not the actual workaround)

iii. (optional) Install Google Play, if you want to watch the encrypted channels - need to pay P20 for the registration (in-app purchase). Copy "Phonesky.apk" from opengapps.org to systemfs/priv-app/Phonesky

iv. finally, unmount the image.
$ sync
$ sudo umount systemfs

9. Extract ramdisk, and edit default.prop
$ mkdir -p ramdiskfs
$ cd ramdiskfs
$ gzip -dc ../ramdisk.img | cpio -i

$ nano default.prop


Replace ro.dalvik.vm.native.bridge=0 with ro.dalvik.vm.native.bridge=libhoudini.so

10. Edit an init configuration file (e.g. init.ranchu.rc) to register the libhoudini by adding these lines:
# Enable native bridge for target executables
on early-init
    mount binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc

on property:ro.enable.native.bridge.exec=1
    copy /system/etc/binfmt_misc/arm_exe /proc/sys/fs/binfmt_misc/register
    copy /system/etc/binfmt_misc/arm_dyn /proc/sys/fs/binfmt_misc/register

11. Repack the new ramdisk
$ cd ..
$ wget https://github.com/xiaolu/mkbootimg_tools/raw/master/mkbootfs
$ chmod +x mkbootfs
$ ./mkbootfs ./ramdiskfs | gzip > ramdisk.img

12. Create the AVD named "avd_7_1_x86_64" based on "Android TV (720p)" device.
$ ./tools/bin/avdmanager --verbose create avd --force --name "avd_7_1_x86_64" --device "tv_720p" \
  --package "system-images;android-25;google_apis;x86_64" --tag "google_apis" --abi "x86_64"


13. Now launch the emulator.
$ ./tools/emulator @avd_7_1_x86_64 -show-kernel -verbose -memory 2048 \
  -qemu -usb -device usb-host,vendorid=0x048d,productid=0x9308

14. Install the TVplus Go Android app, either via the Google Play or via adb install
$ adb install ../apks/TVplus\ GO_v1.0.28_apkpure.com.apk


15. Finally, plugin the TVplus Go dongle to a USB port and then launch now the app on the emulator




Tuesday, September 24, 2019

Alexa Local FM Radio


Alexa Echo Dot playing local FM radio radio stations using ESP8266 WiFi module, RDA5807 FM receiver module and audio Bluetooth transmitter.


source code (Arduino):
https://github.com/julznc/alexa_esp_fmradio


suggestion for improvement:
use ESP32, instead of ESP8266, since it already has built-in bluetooth functionality.

references:
https://bitbucket.org/xoseperez/fauxmoesp
https://github.com/me-no-dev/ESPAsyncWebServer
https://github.com/mathertel/Radio