UART Daisy Chain: Depuración Avanzada con el ODROID-C2

UART Daisy Chain

Este artículo explica cómo usar múltiples puertos UART en ODROID-C2 con el sistema operativo Android. Utilizaremos 3 puertos UART y crearemos un flujo de datos llamado Daisy Chain. El flujo de datos básico parte desde TX del UART 1 hacia el RX del UART 2 y luego va a TX UART 2, que enviará los datos a RX del UART 3. Una vez que RX del UART 3 recibe los datos, lo envía desde 7. Para esto, necesitas utilizar la última versión de Android 6.0.1 versión 3.6 o superior y así poder usar 3 puertos UART de forma simultánea.

Figure 1 - Annotated schematic of an ODROID-C2
Figura 1 - Esquema con anotaciones de un ODROID-C2

Hardware

Antes de empezar, tienes que hacerte con algunas cosas. Primero, descarga el diagrama Fritzing desde https://goo.gl/Q1YhP3. Comprueba el diseño de los pines J2 2×20 en  https://goo.gl/44XGpB.

PUERTO

PIN

TX

RX

UART_A (ttyS1) 8 10
UART_B (ttyS2) 3 5
UART_C (ttyS3) 32 26

Software

Necesitas modificar el archivo de Árbol del Dispositivos para habilitar UART_B (ttyS2) y UART_C (ttyS3) ya que Android los usa para otros fines, como GPIO/I2C.

Deshabilitar I2C

 $ diff --git a/arch/arm64/boot/dts/meson64_odroidc2.dts b/arch/arm64/boot/dts/meson64_odroidc2.dts
 index e6a25b0..db09b04 100755
 --- a/arch/arm64/boot/dts/meson64_odroidc2.dts
 +++ b/arch/arm64/boot/dts/meson64_odroidc2.dts
 @@ -813,18 +813,6 @@

};

-&i2c_a {
 - status = "okay";
 -
 - /* Hardkernel I2C RTC */
 - pcf8563: pcf8563@51 {
 - status = "disabled";
 - compatible = "nxp,pcf8563";
 - reg = <0x51>;
 - #clock-cells = <0>;
 - };
 -};
 -
&i2c_b {
 status = "okay";

Añadir las definiciones UART_B y UART_C

El archivo kernel/arch/arm64/boot/dts/meson64_odroidc2.dts se puede descargar desde https://goo.gl/Y7c5Wr, tal y como se muestra a continuación:

$ diff --git a/arch/arm64/boot/dts/meson64_odroidc2.dts b/arch/arm64/boot/dts/meson64_odroidc2.dts
 index e6a25b0..fd41552 100755
 --- a/arch/arm64/boot/dts/meson64_odroidc2.dts
 +++ b/arch/arm64/boot/dts/meson64_odroidc2.dts
 @@ -31,6 +31,8 @@
aliases {
 serial0 = &uart_AO;
 serial1 = &uart_A;
 + serial2 = &uart_B;
 + serial3 = &uart_C;
};

gpu_dvfs_tbl: gpu_dvfs_tbl {
 @@ -459,6 +461,32 @@
 pinctrl-0 = <&a_uart_pins>;
};

+ uart_B: serial@c11084dc {
 + compatible = "amlogic, meson-uart";
 + reg = <0x0 0xc11084dc 0x0 0x18>;
 + interrupts = <0 75 1>;
 + status = "okay";
 + clocks = <&clock CLK_XTAL>;
 + clock-names = "clk_uart";
 + fifosize = < 64 >;
 + pinctrl-names = "default";
 + pinctrl-0 = <&b_uart_pins>;
 + resets = <&clock GCLK_IDX_UART1>;
 + };
 +
 + uart_C: serial@c1108700 {
 + compatible = "amlogic, meson-uart";
 + reg = <0x0 0xc1108700 0x0 0x14>;
 + interrupts = <0 93 1>;
 + status = "okay";
 + clocks = <&clock CLK_XTAL>;
 + clock-names = "clk_uart";
 + fifosize = < 64 >;
 + pinctrl-names = "default";
 + pinctrl-0 = <&c_uart_pins>;
 + resets = <&clock GCLK_IDX_UART2>;
+ };
+
canvas {
 compatible = "amlogic, meson, canvas";
 dev_name = "amlogic-canvas";

Compilar dts hacia dtb

El archivo Meson64_odroidc2.dtd se puede descargar desde https://goo.gl/qha1vx, tal y como se muestra a continuación:

$ make odroidc2_[i2c_]defconfig
 KBUILD_CFLAGS_MODULE:-DMODULE
#
# configuration written to .config
#

#### make completed successfully ####

[~/projects/c2/marshmallow/kernel]$ make dtbs
 KBUILD_CFLAGS_MODULE:-DMODULE
 KBUILD_CFLAGS_MODULE:-DMODULE
 scripts/kconfig/conf --silentoldconfig Kconfig
 KBUILD_CFLAGS_MODULE:-DMODULE
 WRAP arch/arm64/include/generated/asm/bug.h
 WRAP arch/arm64/include/generated/asm/bugs.h
 WRAP arch/arm64/include/generated/asm/checksum.h
 WRAP arch/arm64/include/generated/asm/clkdev.h
 WRAP arch/arm64/include/generated/asm/cputime.h
 WRAP arch/arm64/include/generated/asm/current.h
 WRAP arch/arm64/include/generated/asm/delay.h
 WRAP arch/arm64/include/generated/asm/div64.h
 WRAP arch/arm64/include/generated/asm/dma.h
 WRAP arch/arm64/include/generated/asm/emergency-restart.h
 WRAP arch/arm64/include/generated/asm/early_ioremap.h
 WRAP arch/arm64/include/generated/asm/errno.h
 WRAP arch/arm64/include/generated/asm/ftrace.h
 WRAP arch/arm64/include/generated/asm/hw_irq.h
 WRAP arch/arm64/include/generated/asm/ioctl.h
 WRAP arch/arm64/include/generated/asm/ioctls.h
 WRAP arch/arm64/include/generated/asm/ipcbuf.h
 WRAP arch/arm64/include/generated/asm/irq_regs.h
 WRAP arch/arm64/include/generated/asm/kdebug.h
 WRAP arch/arm64/include/generated/asm/kmap_types.h
 WRAP arch/arm64/include/generated/asm/kvm_para.h
 WRAP arch/arm64/include/generated/asm/local.h
 WRAP arch/arm64/include/generated/asm/local64.h
 WRAP arch/arm64/include/generated/asm/mman.h
 WRAP arch/arm64/include/generated/asm/msgbuf.h
 WRAP arch/arm64/include/generated/asm/mutex.h
 WRAP arch/arm64/include/generated/asm/pci.h
 WRAP arch/arm64/include/generated/asm/poll.h
 WRAP arch/arm64/include/generated/asm/posix_types.h
 WRAP arch/arm64/include/generated/asm/resource.h
 WRAP arch/arm64/include/generated/asm/scatterlist.h
 WRAP arch/arm64/include/generated/asm/sections.h
 WRAP arch/arm64/include/generated/asm/segment.h
 WRAP arch/arm64/include/generated/asm/sembuf.h
 WRAP arch/arm64/include/generated/asm/serial.h
 WRAP arch/arm64/include/generated/asm/shmbuf.h
 WRAP arch/arm64/include/generated/asm/simd.h
 WRAP arch/arm64/include/generated/asm/sizes.h
 WRAP arch/arm64/include/generated/asm/socket.h
 WRAP arch/arm64/include/generated/asm/sockios.h
 WRAP arch/arm64/include/generated/asm/switch_to.h
 WRAP arch/arm64/include/generated/asm/swab.h
 WRAP arch/arm64/include/generated/asm/termbits.h
 WRAP arch/arm64/include/generated/asm/termios.h
 WRAP arch/arm64/include/generated/asm/topology.h
 WRAP arch/arm64/include/generated/asm/trace_clock.h
 WRAP arch/arm64/include/generated/asm/types.h
 WRAP arch/arm64/include/generated/asm/unaligned.h
 WRAP arch/arm64/include/generated/asm/user.h
 WRAP arch/arm64/include/generated/asm/vga.h
 WRAP arch/arm64/include/generated/asm/xor.h
 WRAP arch/arm64/include/generated/asm/preempt.h
 WRAP arch/arm64/include/generated/asm/hash.h
 WRAP arch/arm64/include/generated/uapi/asm/kvm_para.h
 HOSTCC scripts/dtc/checks.o
 HOSTCC scripts/dtc/data.o
 SHIPPED scripts/dtc/dtc-lexer.lex.c
 SHIPPED scripts/dtc/dtc-parser.tab.h
 HOSTCC scripts/dtc/dtc-lexer.lex.o
 SHIPPED scripts/dtc/dtc-parser.tab.c
 HOSTCC scripts/dtc/dtc-parser.tab.o
 HOSTCC scripts/dtc/dtc.o
 HOSTCC scripts/dtc/flattree.o
 HOSTCC scripts/dtc/fstree.o
 HOSTCC scripts/dtc/livetree.o
 HOSTCC scripts/dtc/srcpos.o
 HOSTCC scripts/dtc/treesource.o
 HOSTCC scripts/dtc/util.o
 HOSTLD scripts/dtc/dtc
 CC scripts/mod/empty.o
 HOSTCC scripts/mod/mk_elfconfig
 MKELF scripts/mod/elfconfig.h
 CC scripts/mod/devicetable-offsets.s
 GEN scripts/mod/devicetable-offsets.h
 HOSTCC scripts/mod/file2alias.o
 HOSTCC scripts/mod/modpost.o
 HOSTCC scripts/mod/sumversion.o
 HOSTLD scripts/mod/modpost
 HOSTCC scripts/selinux/genheaders/genheaders
 HOSTCC scripts/selinux/mdp/mdp
 HOSTCC scripts/kallsyms
 HOSTCC scripts/pnmtologo
 HOSTCC scripts/conmakehash
 HOSTCC scripts/bin2c
 HOSTCC scripts/recordmcount
 HOSTCC scripts/sortextable
 DTC arch/arm64/boot/dts/meson64_odroidc2.dtb
 Warning (reg_format): "reg" property in /spi-gpio/spi-gpio@0 has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
 Warning (avoid_default_addr_size): Relying on default #address-cells value for /spi-gpio/spi-gpio@0
 Warning (avoid_default_addr_size): Relying on default #size-cells value for /spi-gpio/spi-gpio@0

#### make completed successfully (4 seconds) ####

 Instalar el archivo dtb modificado

$ sudo fastboot flash dtb \
 out/target/product/odroidc2/obj/KERNEL_OBJ/arch/arm64/boot/dts/meson64_odroidc2.dtb
Tienes que editar el archivo /storage/internal/boot.ini para cargar una imagen alternativa del Kernel. Existe una imagen alternativa del kernel para usar los pines I2C con la función UART.
# movi read boot 0 ${loadaddr}
fatload mmc 0:1 ${loadaddr} Image_android

Editar ueventd.odroidc2.rc

Cambia el permiso de ttyS2 y ttyS3 para el acceso del sistema.

shell@odroidc2:/ $ su
root@odroidc2:/ # mount -o rw,remount /
[ 1243.002784@2] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
root@odroidc2:/ # vi /ueueventd.odroidc2.rc ueventd.rc
root@odroidc2:/ # vi /ueventd.odroidc2.rc

/dev/ttyS* 0666 system system

Configurar el código de ejemplo de la app de Android

Descarga la librería de WiringPi NDK de https://goo.gl/uuDeys, y el código fuente de la aplicación desde GitHub en https://goo.gl/YNXTUn.

$ sudo apt install git
$ git clone https://github.com/codewalkerster/example-wiringPi -b odroid-c_3_uart
Figure 2 - wire connection for three daisy-chained UART ports
Figura 2 - Conexión por cable de tres puertos UART conectados en serie

Figure 3 - Test the daisy-chained UART by typing a string
Figura 3 – Probando el UART conectado en serie escribiendo una cadena de caracteres

Figure 4 - Results of the daisy-chained UART test
Figura 4 - Resultados de la prueba UART conectado en serie

Para comentarios, preguntas y sugerencias, visita el post original en https://goo.gl/jteQuV.

Be the first to comment

Leave a Reply