Armadilloフォーラム

USBシリアル通信について

yasuda0108

2022年2月16日 13時26分

お世話になります。
Armadillo-G4 CN4のUSBポートを使用して、シリアル通信データを受信しようと考えております。
マニュアル「9.1.4.7. USB を扱う」を参考にコンテナを作成しようとしているのですが、
/devディレクトリ下に/ttyUSBNが存在しません。
こちらはどのように対応すればよろしいでしょうか。

armadillo:~# ls /dev
autofs           loop-control        ptyp3     tty17  tty51    ttypf
block            loop0               ptyp4     tty18  tty52    ubi_ctrl
bsg              loop1               ptyp5     tty19  tty53    uhid
btrfs-control    loop2               ptyp6     tty2   tty54    urandom
bus              loop3               ptyp7     tty20  tty55    v4l
caam-keygen      loop4               ptyp8     tty21  tty56    vcs
cec0             loop5               ptyp9     tty22  tty57    vcs1
char             loop6               ptypa     tty23  tty58    vcs2
console          loop7               ptypb     tty24  tty59    vcs3
core             mapper              ptypc     tty25  tty6     vcs4
cpu_dma_latency  mem                 ptypd     tty26  tty60    vcs5
cuse             mmcblk2             ptype     tty27  tty61    vcs6
disk             mmcblk2boot0        ptypf     tty28  tty62    vcsa
dlm-control      mmcblk2boot1        random    tty29  tty63    vcsa1
dlm-monitor      mmcblk2gp0          rfkill    tty3   tty7     vcsa2
dlm_plock        mmcblk2gp1          rtc       tty30  tty8     vcsa3
dri              mmcblk2gp2          rtc0      tty31  tty9     vcsa4
fb0              mmcblk2gp3          rtc1      tty32  ttyS0    vcsa5
fd               mmcblk2p1           sda       tty33  ttyS1    vcsa6
full             mmcblk2p2           sda1      tty34  ttyS2    vcsu
fuse             mmcblk2p3           shm       tty35  ttyS3    vcsu1
galcore          mmcblk2p4           snapshot  tty36  ttymxc0  vcsu2
gpiochip0        mmcblk2p5           snd       tty37  ttymxc1  vcsu3
gpiochip1        mmcblk2rpmb         stderr    tty38  ttyp0    vcsu4
gpiochip2        mqueue              stdin     tty39  ttyp1    vcsu5
gpiochip3        mxc_hantro          stdout    tty4   ttyp2    vcsu6
gpiochip4        mxc_hantro_vc8000e  tee0      tty40  ttyp3    vfio
gpiochip5        net                 teepriv0  tty41  ttyp4    vga_arbiter
hwrng            null                tty       tty42  ttyp5    vhci
i2c-0            port                tty0      tty43  ttyp6    video0
i2c-1            pps0                tty1      tty44  ttyp7    video1
i2c-2            ptmx                tty10     tty45  ttyp8    video2
i2c-3            ptp0                tty11     tty46  ttyp9    vsi_daemon_ctrl
i2c-6            ptp1                tty12     tty47  ttypa    watchdog
input            pts                 tty13     tty48  ttypb    watchdog0
ion              ptyp0               tty14     tty49  ttypc    zero
kmsg             ptyp1               tty15     tty5   ttypd    zram0
log              ptyp2               tty16     tty50  ttype
コメント

at_akihito.irie

2022年2月16日 14時39分

入江です。

> マニュアル「9.1.4.7. USB を扱う」を参考にコンテナを作成しようとしているのですが、
> /devディレクトリ下に/ttyUSBNが存在しません。

いくつか確認させてください。

1. USBデバイスはArmadilloに正しく接続されておりますでしょうか。

2. USBデバイスをArmadilloに接続した時の出力されるログをいただけますでしょうか。

3. 可能であればご使用されるUSBデバイスの詳細を教えていただけますでしょうか。

以上、よろしくお願いいたします。

yasuda0108

2022年2月16日 15時09分

回答致します。

1. USBデバイスはArmadilloに正しく接続されておりますでしょうか。
2. USBデバイスをArmadilloに接続した時の出力されるログをいただけますでしょうか。
→接続時にUSBを認識しているようですので、接続はされていると考えられます。
 以下接続時ログです。

armadillo:~# [   65.836479] usb 1-1: new full-speed USB device number 2 using xhci-hcd

3. 可能であればご使用されるUSBデバイスの詳細を教えていただけますでしょうか。
→RS-422通信をUSBに変換するアダプターになります。
 製品:MOXA Uport 1130
 回答をしていて思いましたが、この製品のドライバはインストールが必要ですよね。。
 https://moxa.com/en/support/product-support/software-and-documentation/…
 ドライバをインストールする際は、armadilloのどこかのディレクトリにて.tgzを解凍しmake→make installの手順でよろしいでしょうか?

> 入江です。
>
> > マニュアル「9.1.4.7. USB を扱う」を参考にコンテナを作成しようとしているのですが、
> > /devディレクトリ下に/ttyUSBNが存在しません。
>
> いくつか確認させてください。
>
> 1. USBデバイスはArmadilloに正しく接続されておりますでしょうか。
>
> 2. USBデバイスをArmadilloに接続した時の出力されるログをいただけますでしょうか。
>
> 3. 可能であればご使用されるUSBデバイスの詳細を教えていただけますでしょうか。
>
> 以上、よろしくお願いいたします。
>

at_akihito.irie

2022年2月16日 16時06分

入江です。

>  ドライバをインストールする際は、armadilloのどこかのディレクトリにて.tgzを解凍しmake→make installの手順でよろしいでしょうか?

arm64向けにビルドするには少し違う手順が必要かもしれません。

ご自身でドライバをビルドしても良いですが、Linuxカーネル内に用意されて
いるドライバも使えるかもしれません。
つきましては当該USBデバイスを接続した状態で、lsusbを実行した際の出力をい
ただけますでしょうか。

以上、よろしくお願いいたします。

yasuda0108

2022年2月16日 16時19分

CN4に接続し、lsusb実行の結果、出力は下記になります。

armadillo:~# [   33.160212] usb 1-1: new full-speed USB device number 2 using xhci-hcd
armadillo:~# lsusb
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 110a:1131
Bus 004 Device 001: ID 1d6b:0003
Bus 002 Device 001: ID 1d6b:0003
Bus 003 Device 002: ID 0424:2422

> 入江です。
>
> >  ドライバをインストールする際は、armadilloのどこかのディレクトリにて.tgzを解凍しmake→make installの手順でよろしいでしょうか?
>
> arm64向けにビルドするには少し違う手順が必要かもしれません。
>
> ご自身でドライバをビルドしても良いですが、Linuxカーネル内に用意されて
> いるドライバも使えるかもしれません。
> つきましては当該USBデバイスを接続した状態で、lsusbを実行した際の出力をい
> ただけますでしょうか。
>
> 以上、よろしくお願いいたします。
>

at_akihito.irie

2022年2月16日 18時38分

入江です。

情報ありがとうございます。

少々長くなりますが、以下の手順を試していただけますでしょうか。

まず、以下のマニュアルを参考にLinuxカーネルをビルドできる環境を整えま
す。すでにカーネルがビルドできる状態にあるのであれば実行する必要はあり
ません。
https://manual.atmark-techno.com/armadillo-iot-g4/armadillo-iotg-g4_pro…

次にカーネルコンフィギュレーションを変更し、当該USBデバイスのドライバ
を有効にします。

[ATDE]$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig

menuconfigでは以下を有効にしてください。

Device Drivers  --->
  [*] USB support  --->
    <*>   USB Serial Converter support  --->
      <*>   USB TI 3410/5052 Serial Driver  <- これを有効化(スペースキー押下で<*>にする)

コンフィギュレーションの変更後、カーネルをビルドしてください。

[ATDE]$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j5

次に、生成したカーネルイメージのArmadilloへの書込みと、当該デバイスを
使用するのに必要なファームウェアをArmadilloにインストールするために、
SWUpdateを使用するのでswuイメージを作成します。

別スレッドのご質問にて既にinitial_setupは完了しているようですので、
SWUpdateは使用できる前提で説明します。

まず、ホームディレクトリにあるmkswuディレクトリに移動し、カーネルとファー
ムウェアのアップデート用ディレクトリとdescファイルを作成します。
以下の例ではviを用いていますがお好きなエディタでdescファイルを編集して
ください。

[ATDE]$ cd /home/atmark/mkswu
[ATDE]$ mkdir for-moxa-uport1130
[ATDE]$ vi for-moxa-uport1130/kernel_firmware_update.desc // 編集
[ATDE]$ cat for-moxa-uport1130/kernel_firmware_update.desc // 編集後のdescファイルの内容
swdesc_files --version extra_os.kernel 5.10.82-1 \
	--install-if different --dest /boot \
	"Image"
 
swdesc_command "apk add linux-firmware-moxa" --version extra_os.firmware-moxa 1
 
install_if=different
swdesc_command --version extra_os.kernel 5.10.82-1 \
        'grep -qE "^POST /boot" /etc/swupdate_preserve_files || echo -e "POST /boot\nPOST /lib/modules" >> /etc/swupdate_preserve_files'

次に、先程生成したカーネルイメージ(Image)ファイルをfor-moxa-uport1130/
の下に配置し、mkswuを実行します。
カーネルイメージへのパスは適宜読み替えてください。

[ATDE]$ cp /home/atmark/linux-5.10-at/arch/arm64/boot/Image ./for-moxa-uport1130/
[ATDE]$ mkswu for-moxa-uport1130/kernel_firmware_update.desc
[ATDE]$ ls for-moxa-uport1130/kernel_firmware_update.swu
for-moxa-uport1130/kernel_firmware_update.swu // swuパッケージが生成されていることを確認

上記手順で生成されたkernel_firmware_update.swuをUSBメモリに書き込み、
Armadilloに挿入してSWUpdateを実行してください。
正常にSWUpdateが実行されると、Armadilloが再起動します。

以下のコマンドで、正しくカーネルがアップデートされ、ファームウェアが書
き込まれていることが確認できます。

[armadillo]# zcat /proc/config.gz | grep CONFIG_USB_SERIAL_TI
CONFIG_USB_SERIAL_TI=y  <- =yになっている
 
[armadillo]# ls /lib/firmware/moxa/ <- ファームウェアが存在している
moxa-1110.fw  moxa-1150.fw  moxa-1251.fw  moxa-1451.fw  moxa-1653.fw
moxa-1130.fw  moxa-1151.fw  moxa-1410.fw  moxa-1613.fw  moxa-1658.fw
moxa-1131.fw  moxa-1250.fw  moxa-1450.fw  moxa-1618.fw

この状態で、当該USBデバイスをArmadilloに接続して正しく認識されるか確認
していただけますでしょうか。

以上、よろしくお願いいたします。

yasuda0108

2022年2月17日 13時42分

ご丁寧にご対応ありがとうございます。
記載いただいた内容通りに試してみます。

質問が2点ございます。
①新規の.descファイルはどのように作成するのでしょうか
 前回のものをコピーしrenameしようとしましたがエラ-が出力されます。

ご回答内容から抜粋
[ATDE]$ vi for-moxa-uport1130/kernel_firmware_update.desc ←こちらの作成方法
 
リネームエラー
atmark@atde9:~/mkswu$ rename kernel_update_plain.desc kernel_firmware_plain.desc
Bareword "kernel_update_plain" not allowed while "strict subs" in use at (user-supplied code) line 3.

②今回作成するkernel_firmware_update.descを使用してG4をアップデートした際、
 以前実施したデバイスツリーのSWupdate更新内容(GPIOの設定)は、G4に残ったままアップデートされるのでしょうか

yasuda0108

2022年2月17日 16時15分

先ほどの質問内容ですが、①については、下記の方法で名前を変更し解決しました。

atmark@atde9:~/mkswu$ cp update-dtb/kernel_update_plain.desc for-moxa-uport1130/kernel_firmware_update.desc

mkswuを実行しましたが、エラ-が出力されますので、ご確認をお願いします。

atmark@atde9:~/mkswu$ cat for-moxa-uport1130/kernel_firmware_update.desc
# We expose `--install-if different` here in two different ways for
# demonstration purpose (either using the switch or setting the variable)
# Anything below the variable being set will have the switch automatically
# set unless they specify --install-if higher manually
# Note that if a component is installed in both modes, the swu generation
# will fail.
 
 
swdesc_files --version extra_os.kernel 5.10.82-1 \
	--install-if different --dest /boot \
	"Image"
 
swdesc_command "apk add linux-firmware-moxa" --version extra_os.firmware-moxa 1
 
swdesc_command --version extra_os.kernel 5.10.82-1 \
        'grep -qE "^POST /boot" /etc/swupdate_preserve_files || echo -e "POST /boot\nPOST /lib/modules" >> /etc/swupdate_preserve_files'
 
atmark@atde9:~/mkswu$ mkswu for-moxa-uport1130/kernel_firmware_update.desc
sort: -:3: 順序が不規則: extra_os.kernel 5.10.82-1 higher *
ERROR: 上記のcomponentが別のバージョンかinstall-ifで使われました。

また、②についてもご回答お待ちしております。

yasuda0108

2022年2月17日 16時20分

失礼いたしました。
install_if=differentが抜けておりました。無事.swu作成が完了しました。

> 先ほどの質問内容ですが、①については、下記の方法で名前を変更し解決しました。
>

> atmark@atde9:~/mkswu$ cp update-dtb/kernel_update_plain.desc for-moxa-uport1130/kernel_firmware_update.desc
> 

>
> mkswuを実行しましたが、エラ-が出力されますので、ご確認をお願いします。
>

> atmark@atde9:~/mkswu$ cat for-moxa-uport1130/kernel_firmware_update.desc
> # We expose `--install-if different` here in two different ways for
> # demonstration purpose (either using the switch or setting the variable)
> # Anything below the variable being set will have the switch automatically
> # set unless they specify --install-if higher manually
> # Note that if a component is installed in both modes, the swu generation
> # will fail.
> 
> 
> swdesc_files --version extra_os.kernel 5.10.82-1 \
> 	--install-if different --dest /boot \
> 	"Image"
> 
> swdesc_command "apk add linux-firmware-moxa" --version extra_os.firmware-moxa 1
> 
> swdesc_command --version extra_os.kernel 5.10.82-1 \
>         'grep -qE "^POST /boot" /etc/swupdate_preserve_files || echo -e "POST /boot\nPOST /lib/modules" >> /etc/swupdate_preserve_files'
> 
> atmark@atde9:~/mkswu$ mkswu for-moxa-uport1130/kernel_firmware_update.desc
> sort: -:3: 順序が不規則: extra_os.kernel 5.10.82-1 higher *
> ERROR: 上記のcomponentが別のバージョンかinstall-ifで使われました。
> 
> 

>
> また、②についてもご回答お待ちしております。

yasuda0108

2022年2月18日 9時04分

お世話になります。

ご回答頂いた通り、USBドライバを有効にした.swuにてアップデートを実施しました。
G4が再起動されたのち、RS422↔USB変換ケーブルを差し、下記の通り確認しましたが、以下のように表示されます。
ご対応方法のご教示お願い致します。

USB接続
armadillo:~# [   26.564529] usb 1-1: new full-speed USB device number 2 using xhci-hcd
 
★ =y と表示されない
armadillo:~# zcat /proc/config.gz | grep CONFIG_USB_SERIAL_TI
# CONFIG_USB_SERIAL_TI is not set
 
ファームウェア確認
armadillo:~# ls /lib/firmware/moxa
moxa-1110.fw  moxa-1150.fw  moxa-1251.fw  moxa-1451.fw  moxa-1653.fw
moxa-1130.fw  moxa-1151.fw  moxa-1410.fw  moxa-1613.fw  moxa-1658.fw
moxa-1131.fw  moxa-1250.fw  moxa-1450.fw  moxa-1618.fw

at_akihito.irie

2022年2月21日 11時19分

入江です。

以下のコマンドをArmadillo上で実行し、その結果を送っていただけますでしょうか。

[armadillo]# ls -l /boot

また、ATDEにて、ビルドしたLinuxカーネルソースコードのディレクトリ内で
以下を実行し、その結果を送っていただけますでしょうか。
(linux-5.10-atへのパスは適宜読み替えてください。)

[ATDE]$ cd /path/to/linux-5.10-at
[ATDE]$ cat .config | grep CONFIG_USB_SERIAL_TI

以上、よろしくお願いいたします。

yasuda0108

2022年2月22日 9時32分

実行結果は下記になります。
ご回答宜しくお願い致します。

Armadillo-G4

armadillo:~# ls -l /boot
total 30617
-rw-r--r-- 1 root root 31051784 Dec  2  2021 Image
lrwxrwxrwx 1 root root       30 Jan  1  1970 armadillo.dtb -> armadillo_iotg_g4-at-dtweb.dtb
-rw-r--r-- 1 root root    59915 Jan  1  1970 armadillo_iotg_g4-at-dtweb.dtb
-rw-r--r-- 1 root root    59796 Dec  2  2021 armadillo_iotg_g4-nousb.dtb
-rw-r--r-- 1 root root    60012 Dec  2  2021 armadillo_iotg_g4.dtb
-rw-r--r-- 1 root root    63003 Dec  2  2021 imx8mp-evk.dtb
-rw-r--r-- 1 root root    53982 Dec  2  2021 yakushima-eva.dtb

ATDE

atmark@atde9:~$ ls /home/atmark
Qt                 kernel_update_plain.swu  mkswu         デスクトップ  音楽
drv                linux-5.10-5.10.93-r0    ダウンロード  ドキュメント  画像
initial_setup.swu  linux-at-5.10.93-r0      テンプレート  ビデオ        公開
atmark@atde9:~$ cd linux-5.10-5.10.93-r0
atmark@atde9:~/linux-5.10-5.10.93-r0$ cat .config | grep CONFIG_USB_SERIAL_TI
CONFIG_USB_SERIAL_TI=y

at_akihito.irie

2022年2月22日 12時58分

入江です。

> -rw-r--r-- 1 root root 31051784 Dec 2 2021 Image

日付から察するに、Imageファイルの書き換えができていないように見えます。

開発時以外は非推奨ですが、以下の手順を実行し、swuを使用しないでImageファ
イルの書き換えを試してみていただけますでしょうか。

まず、CONFIG_USB_SERIAL_TIを有効にして生成したImageファイルをArmadillo
に送ってください。

その後、/boot/Image(既存のカーネルイメージ)のバックアップをとりつつ、
新たなImageファイルを/boot以下にコピーします。
persist_file(ファイルの永続化)も忘れずに行ってください。

[armadillo]# ls Image
Image //CONFIG_USB_SERIAL_TIを有効にしたImage
[armadillo]# ls /boot/Image
/boot/Image //既存のカーネルイメージ
[armadillo]# cp --backup=numbered Image /boot/Image //元のImageのバックアップをとりつつcp
[armadillo]# persist_file /boot/Image /boot/Image.~1~ //コピーしたファイルとバックアップの永続化

その後、rebootコマンドでArmadilloを再起動し、以下のコマンドの出力をご
確認ください。

[armadillo]# zcat /proc/config.gz | grep CONFIG_USB_SERIAL_TI
CONFIG_USB_SERIAL_TI=y  <- =yになっている

以上、よろしくお願いいたします。

yasuda0108

2022年2月28日 15時50分

ご回答ありがとうございます。

cpコマンド実施時に、/以下がReadOnlyである旨表示されました。

armadillo:~# cp --backup=numbered /mnt/Image /boot/Image
cp: cannot backup '/boot/Image': Read-only file system

こちらについては、以下のリンク先を参考に「新Imageをコピー」「初期Imageはリネームしてバックアップ保存」
すればよいかなと考えられますが、persist_fileにて初期Imageをリネームすることは可能なのでしょうか。
https://manual.atmark-techno.com/armadillo-iot-g4/armadillo-iotg-g4_pro…

また、その他解決方法ありましたらご教示お願い致します。

at_akihito.irie

2022年3月1日 11時42分

入江です。

以下の手順でルートファイルシステムを読み書き可能でremountしてから、
Imageの書き換えを行ってみてください。

[armadillo]# mount -o remount,rw /
[armadillo]# cp --backup=numbered /mnt/Image /boot/Image
[armadillo]# persist_file /boot/Image /boot/Image.~1~

その後、rebootコマンドで再起動して、CONFIG_USB_SERIAL_TI=yになっている
か確認してください。

以上、よろしくお願いいたします。

yasuda0108

2022年3月1日 13時35分

ご回答ありがとうございます。
persist_fileを実行すると、下記のように表示されます。
この場合正しく永続化が出来ていないのでしょうか。

armadillo:~# mount -o remount,rw /
armadillo:~# cp --backup=numbered /mnt/Image /boot/Image
armadillo:~# ls /boot
Image          armadillo_iotg_g4-at-dtweb.dtb  imx8mp-evk.dtb
Image.~1~      armadillo_iotg_g4-nousb.dtb     yakushima-eva.dtb
armadillo.dtb  armadillo_iotg_g4.dtb
 
armadillo:~# persist_file /boot/Image /boot/Image.~1~
Could not find what filesystem /boot/Image belongs to

at_akihito.irie

2022年3月1日 13時42分

入江です。

> persist_fileを実行すると、下記のように表示されます。
> この場合正しく永続化が出来ていないのでしょうか。

失礼いたしました。
今回の手順においてpersist_fileは必要ありませんでした。

そのままrebootして動作確認を行ってください。

以上、よろしくお願いいたします。

yasuda0108

2022年3月1日 14時10分

無事ttyUSB0として、RS422→USB変換機が認識されました。
ご丁寧にご対応頂き、誠にありがとうございました。