-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex J Lennon <[email protected]>
- Loading branch information
0 parents
commit 7d519ef
Showing
10 changed files
with
824 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,349 @@ | ||
## Edge AI | ||
|
||
AI audio STT and TTS development platform | ||
|
||
# Sound Support | ||
|
||
## TAS2563 audio playback | ||
|
||
The TAS2563 audio codec is used for output. Currently we've back ported an older TI driver as a kernel module. In future we plan to migrate to a backport of the newer TAS2781 driver. | ||
|
||
The driver downloads a pre-built audio firmware binary to the TAS2563 (`/lib/firmware/tas2563_uCDSP.bin`). There is also a calibration file which is not currently supported. | ||
|
||
The firmware can be built with the TI graphical tool for Windows which can be found [here](https://www.ti.com/tool/PUREPATHCONSOLE). | ||
|
||
Further resources can be found [here](https://www.ti.com/product/TAS2563?keyMatch=TAS2563). | ||
|
||
The driver for this is a module which loads as `snd_soc_tas2563` (use `lsmod` to view) | ||
|
||
We blacklist automatic loading of audio drivers in `/etc/modprobe.d/blacklist.conf` as otherwise card IDs can change depending on load order. Instead a systemd service `audio-driver` runs on startup and executes `/usr/bin/load-audio-drivers.sh` to load in the relevant drivers | ||
|
||
### ALSA | ||
|
||
When loaded `aplay -l` can be executed to show device details | ||
|
||
``` | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:/var/rootdirs/home/fio# aplay -l | ||
**** List of PLAYBACK Hardware Devices **** | ||
card 1: tas2563audio [tas2563-audio], device 0: 30030000.sai-tas2563 ASI1 tas2563 ASI1-0 [30030000.sai-tas2563 ASI1 tas2563 ASI1-0] | ||
Subdevices: 1/1 | ||
Subdevice #0: subdevice #0 | ||
``` | ||
|
||
To play a sample wav file the following command can be used | ||
|
||
``` | ||
aplay -Dhw:1,0 -r 48000 -c 2 sample.wav | ||
``` | ||
|
||
NOTE: Currently when using the hardware device directly only 2 channnels of 48kHz audio are supported. | ||
|
||
### PulseAudio | ||
|
||
We need to be running audio within docker containers. We seem to be able to use ALSA but some .NET code fails with ALSA. So we've added PulseAudio to the host OS mage and can use this instead of ALSA. | ||
|
||
There are PulseAudio equivalents to ALSA record and playback utilities. For example | ||
|
||
``` | ||
parecord file.wav | ||
paplay file.wav | ||
``` | ||
|
||
There is also a command line control utility, for example | ||
|
||
``` | ||
pactl list sources | ||
pactl list sinks | ||
pactl list modules | ||
``` | ||
|
||
NOTE: That the pulseaudio server runs as non-root `fio` user. It's not possible to interact with the server as the root user and this will fail. | ||
|
||
The docker container needs to have access to the host os pulse audio socket and dbus. An example `docker-compose.yml` configuration to achieve this looks something like this | ||
|
||
``` | ||
version: '2' | ||
services: | ||
Example: | ||
build: . | ||
image: hub.foundries.io/dynamic-devices/example:latest | ||
devices: | ||
- /dev/snd:/dev/snd | ||
environment: | ||
- PULSE_SERVER=unix:/tmp/pulseaudio.socket | ||
- PULSE_COOKIE=/tmp/pulseaudio.cookie | ||
volumes: | ||
- "/tmp:/tmp" | ||
- "/run/dbus/system_bus_socket:/run/dbus/system_bus_socket" | ||
restart: always | ||
privileged: true | ||
``` | ||
|
||
TODO: We should support cookies for authentication but this is not yet implemented. Instead we allow unauthenticated to the host pulseaudio server | ||
|
||
To provide the socket in a known place, `/tmp/pulseaudio.socket` we have a script that runs the following command on start-up | ||
|
||
``` | ||
pactl load-module module-native-protocol-unix socket=/tmp/pulseaudio.socket auth-anonymous=true | ||
``` | ||
|
||
Then you can enter a docker container configured as above and run the `paplay` commands or similar | ||
|
||
SECURITY NOTE: That usually PulseAudio would run within a user session. This makes sense for desktop/laptop systems but is non-ideal for embedded systems. Instead we run PulseAudio in the systemwide configuration so we don't have to worry about user login. There are potentially some security and other issues with running in this configuration. These should be noted and can be found [here](https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/). | ||
|
||
# Networking / Radio Support | ||
|
||
## WiFi | ||
|
||
To see current IW612 firmware version use | ||
|
||
``` | ||
cat /proc/mwlan/adapter0/wlan0/info | grep version | ||
driver_version = SDIW612---18.99.2.p66.10-MM6X18423.p6-GPL-(FP92) | ||
firmware_major_version=18.99.2 | ||
``` | ||
Run `ifconfig` to view the wlan0 device (there is no wired ethernet) | ||
|
||
Run the following to add a WiFi connection | ||
|
||
``` | ||
nmcli con add type wifi con-name $CONNECTIONAME ssid "$SSID" 802-11-wireless-security.key-mgmt WPA-PSK 802-11-wireless-security.psk "$PASSWORD" ifname wlan0 | ||
``` | ||
|
||
To see connection status use: | ||
|
||
``` | ||
nmcli | ||
``` | ||
|
||
## Cellular | ||
|
||
If a Quectel modem module is installed it is posssible to see the modem ID with: | ||
|
||
``` | ||
mmcli -L | ||
``` | ||
|
||
Then use this to get the modem status | ||
|
||
``` | ||
mmcli -m $MODEM_ID | ||
``` | ||
|
||
## Bluetooth / BLE | ||
|
||
To test bluetooth is working turn on the device and perform a scan | ||
|
||
``` | ||
bluetoothctl power on | ||
bluetoothctl scan on | ||
``` | ||
or | ||
``` | ||
bluetoothctl scan le | ||
``` | ||
|
||
## 802.15.4 | ||
|
||
### Zigbee | ||
|
||
TBD | ||
|
||
### Thread / Matter | ||
|
||
TBD | ||
|
||
# Power Management | ||
|
||
## STUSB4500 | ||
|
||
We use a STUSB4500 to manage USB-C power. This allows us automatically to switch a PSU between different voltages e.g. 5V, 9V, 20V. | ||
|
||
The datasheet is [here](https://www.st.com/resource/en/datasheet/stusb4500.pdf) | ||
|
||
And the register map is [here](https://www.st.com/resource/en/user_manual/um2650-the-stusb4500-software-programing-guide-stmicroelectronics.pdf) | ||
|
||
We have a tool that allows us to program the NVM in this part to control which settings should be used, the "PDOS". For details on this tool see the repository [here](https://github.com/DynamicDevices/stusb4500-rs/blob/main/examples/stusb4500.rs). | ||
|
||
To write a binary file of 40 bytes of NVM settings | ||
|
||
``` | ||
stusb4500 write --file $input_filename | ||
``` | ||
We also have own own current NVM setting binary in the `/firmware` tree so to program this use | ||
|
||
``` | ||
stusb4500 write --file /lib/firmware/stusb4500.dat | ||
``` | ||
|
||
To display the current settings: | ||
|
||
``` | ||
stusb4500 read | ||
``` | ||
|
||
To store the current settings: | ||
|
||
``` | ||
stusb4500 read --file $output_file | ||
``` | ||
|
||
This tool can also be used to show the current voltage, current consumption and related information. Example usage: | ||
|
||
``` | ||
stusb4500 status | ||
``` | ||
|
||
# Sensors | ||
|
||
## Button | ||
|
||
The button interrupt is not currently implemented but to test via polling use | ||
|
||
``` | ||
echo 102 > /sys/class/gpio/export | ||
cat /sys/class/gpio/gpio102/value | ||
``` | ||
|
||
State is `1` when not depressed and goes to `0` when depressed. | ||
|
||
## BGT 60TR13C Radar | ||
|
||
We've integrated the Infineon `spi-lib` driver which talks to the part [here](https://github.com/dynamicdevices/spi-lib) | ||
|
||
You can run this for test and it will generate a log file with copious numbers of data-points | ||
|
||
``` | ||
seamless_dev_spi spi.mode=landscape rec.file=test.dat | ||
``` | ||
|
||
The RADAR-SDK analysis library implements core protocols and we have this build for aarch64 [here](https://github.com/DynamicDevices/radar-sdk). The SDK talks to Infineon microcontroller firmware using a protocol which seems to be named "stratula" or similar. It can use USB/Serial and other transports. | ||
|
||
As we don't have a microcontroller on our boards we need to interface the SDK to the code that accesses the part over SPI. We have been provided with `spi-lib` which we have [here](https://github.com/DynamicDevices/spi-lib) | ||
|
||
We've then made changes to `spi-lib` to implement the needed protocol to communicate with the SDK code and we do this via a virtual serial port implementation. | ||
|
||
Currently `spi-lib` expects to open a `/dev/ttySpiLib` device which can be linked to a virtual serial port. | ||
|
||
A way of creating a virtual serial port pair is to use | ||
|
||
``` | ||
sudo socat -d -d pty,raw,echo=0,link=/dev/ttyAMA0 pty,raw,echo=0,link=/tmp/ttySpiLib | ||
``` | ||
|
||
This will give two /dev/pts/X devices which you than then create symlinks to. | ||
|
||
NOTE: The RADAR-SDK automatically searches on `/dev/ttyUSB*`, `/dev/ttyAMA*` so we can create a `/dev/ttyAMA0` and the `spi-lib` is currently hard-coded to use `/tmp/ttySpiLib` | ||
|
||
## SHT40-AD1F-R2 Temperature & Humidity | ||
|
||
This is implemented as an I2C device using the SHT4X IIO driver. The `lm-sensors` framework is installed to the image. To see sensor details use `sensors`. | ||
|
||
``` | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# sensors | ||
sht4x-i2c-2-44 | ||
Adapter: 30a40000.i2c | ||
temp1: +32.0 C | ||
humidity1: 33.0 %RH | ||
``` | ||
|
||
## LIS2DH12 Accelerometer | ||
|
||
``` | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# cat /sys/bus/iio/devices/iio\:device0/name | ||
lis2dh12_accel | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# echo 400 > /sys/bus/iio/devices/iio\:device0/sampling_frequency | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# cat /sys/bus/iio/devices/iio\:device0/in_accel_x_raw | ||
336 | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# cat /sys/bus/iio/devices/iio\:device0/in_accel_x_raw | ||
-8 | ||
``` | ||
|
||
## STTS22H Temperature | ||
|
||
The STT22H driver is implemented within the IIO subsystem. To check the temperature you can use: | ||
|
||
``` | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# cat /sys/bus/iio/devices/iio\:device1/name | ||
stts22h | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# cat /sys/bus/iio/devices/iio\:device1/in_temp_ambient_raw | ||
3073 | ||
root@imx8mm-jaguar-sentai-7130a09dab86563:~# cat /sys/bus/iio/devices/iio\:device1/in_temp_ambient_scale | ||
10.000000000 | ||
``` | ||
# Testing | ||
|
||
## LED Testing | ||
|
||
- Pulse RGBW LED intensity "heartbeat" `test-leds-hb.sh` | ||
- Rotate R, G, B, W in ring `test-leds-rc.sh` | ||
|
||
## CE Mark Testing | ||
|
||
This requires a specific image `lmp-factory-image-ce` to be programmed onto the test board. | ||
|
||
### Systemd services | ||
|
||
Individual tests are implemented as `systemd` services which automatically start and can also be stopped and/or disabled. | ||
|
||
| Test | Description | | ||
| ---- | ----------- | | ||
| ce-audio-test.service | Plays a tune on loop via PulseAudio| | ||
| ce-led-test.service | Sets LEDs to 50% green | | ||
| ce-mic-test.service | Records via PulseAudio to /dev/null | | ||
| ce-wifi-bt-test.service | TBD | | ||
| ce-radar-test.service | Runs seamless_dev_spi outputting data to /dev/null | | ||
|
||
To view status of a service | ||
|
||
``` | ||
systemctl status ce-foo-test | ||
``` | ||
To stop a service when running | ||
``` | ||
sudo systemctl stop ce-foo-test | ||
``` | ||
To disable a service from running automatically | ||
|
||
``` | ||
sudo systemctl disable ce-foo-test | ||
``` | ||
To look at output from a service (and "follow" output) | ||
|
||
``` | ||
sudo journalctl -u ce-foo-test -f | ||
``` | ||
|
||
### Manual scripts | ||
|
||
There are also some scripts which can be run manually as needed | ||
|
||
To turn off the modem use | ||
|
||
``` | ||
sudo ce-modem-pwrdown.sh | ||
``` | ||
|
||
Note that this will turn off the modem and it will disconnect from the USB bus but it then powers up and re-enumerates. This issue is addressed in the latest revision of boards. | ||
|
||
To turn off the WiFi/BT | ||
|
||
``` | ||
ifconfig wlan0 down | ||
gpioset gpiochip2 7=0 | ||
``` | ||
|
||
### Running iperf3 | ||
|
||
On the AI board run | ||
|
||
``` | ||
iperf3 -s | ||
``` | ||
|
||
On the monitoring device run | ||
|
||
``` | ||
iperf3 -c $BOARD_IP_ADDRESS -V -b 10M -t 50 | ||
``` |
Oops, something went wrong.