UART Integration Guide*
The main control chip/host communicates with GX8002 via UART to exchange events and data. The main control chip/host acts as a Master device, while GX8002 acts as a Slave device.
There are two ways to interface via UART:
- GX8002 actively reports wake-up events via UART every time it wakes up.
- GX8002 reports the wake-up event through an interrupt and waits for the main control chip/host to query and retrieve the wake-up event via UART.
The distinction between these two methods is based on low-power scenarios, where the main control chip/host may be in a sleep state and requires an interrupt from GX8002 to wake up and then query the current wake-up event. If the main control chip/host supports UART wake-up or does not enter a sleep state, it is recommended to use GX8002's UART active sending mode.
1. Message Protocol*
1.1 Message Protocol*
Messages are divided into three types: Request (REQ), Response (RSP), and Notification (NTF).
1.2 Default UART Parameters*
- Baud rate: 115200
- Data bits: 8
- Parity: None
- Stop bits: 1
1.3 Message Format*
A message consists of a message header and a message body.
1.3.1 Message Header*
Field | Length (Bytes) | Description |
---|---|---|
magic | 4 | Magic number |
cmd | 2 | Command |
seq | 1 | Message sequence number |
flags | 1 | Message flags |
length | 2 | Length of the message body |
crc32 | 4 | CRC32 checksum of the header |
- Magic number (
magic
):0x42 0x55 0x58 0x58
-
Command (
cmd
):Bit Name Description 0 ~ 7 NR Command number (see Command Description) 8 ~ 15 TYPE Message type: REQ (0x01), RSP (0x02), NTF (0x03) REQ
: Host sends a request to the Slave, and the Slave should respond with RSP.
RSP
: Slave responds to the Host's request.
NTF
: Host or Slave sends a notification to the other party without requiring a response. -
Message sequence number (
seq
): Used to indicate the sequence of the current message. Managed internally by the protocol. -
Message flags (
flags
):Bit Name Description 0 B_CHECK Indicates whether the message body has a CRC32 checksum 1 ~ 7 Reserve Reserved -
Message body length (
length
): Iflength
is 0, it means the message has no body. IfB_CHECK
is 1, it includes the length of the CRC32 checksum in the body. -
Message header CRC32 (
crc32
): Checksum for the message header to ensure its integrity.
1.3.2 Message Body*
The message body is used to carry user data and is determined by the length
and B_CHECK
fields in the message header.
Field | Length (Bytes) | Description |
---|---|---|
content | Determined by length and B_CHECK fields |
User data |
crc32 | 4 | CRC32 checksum of the message body (specified by B_CHECK ) |
2. Command Description*
2.1 Voice Events*
- Magic number (
magic
):0x42 0x55 0x58 0x58
-
Message:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x0C REQ (0x01) 0 0 N/A Slave 0x0C RSP (0x02) 1 6 (2 bytes ID + 4 bytes crc) EventID Slave 0x0C NTF (0x03) 1 6 (2 bytes ID + 4 bytes crc) EventID -
EventID (Same as GX8002 Short Command ID):
ID Event 100 Main wake-up word 102 Pause playback 103 Stop playback 104 Play music 105 Increase volume 106 Decrease volume 112 Play previous track 113 Play next track 114 Answer call 115 Hang up call
Note
The values of the EventID may vary depending on the firmware. Please confirm them with the corresponding engineer according to the actual situation.
-
Host reads slave events:
Host: 42 55 58 58 0c 01 00 00 00 00 ba 1d 5b 9d Slave: 42 55 58 58 0c 02 00 01 06 00 db aa 63 8d 64 00 5c bc 48 40
In the specific implementation, polling or responding to external GPIO interrupts can be used to read events.
-
Slave reports events:
Slave: 42 55 58 58 0c 03 00 01 06 00 6b 83 03 b0 64 00 5c bc 48 40
-
Message structure example:
2.2 Microphone Status*
- Magic number (
magic
):0x42 0x55 0x58 0x58
-
Message:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x70 REQ (0x01) 0 0 N/A Slave 0x70 RSP (0x02) 1 6 (2 bytes status code + 4 bytes crc) Status code -
Status code:
Value Description 0 Abnormal 1 Normal -
Query example:
Host: 42 55 58 58 70 01 01 00 00 00 65 b7 07 59 Slave: 42 55 58 58 70 02 00 01 06 00 61 67 83 f1 01 00 be 23 c2 58
2.3 G-Sensor Status*
- Magic number (
magic
):0x42 0x55 0x58 0x58
-
Message:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x71 REQ (0x01) 0 0 N/A Slave 0x71 RSP (0x02) 1 6 (2 bytes status code + 4 bytes crc) Status code -
Status code:
Value Description 0 Abnormal 1 Stationary 2 Motion detected -
Query example:
Host: 42 55 58 58 71 01 01 00 00 00 c0 64 5b 92 Slave: 42 55 58 58 71 02 00 01 06 00 c4 b4 df 3a 02 00 7d 70 ef 73
2.4 Firmware Version Number*
- Magic number (
magic
):0x42 0x55 0x58 0x58
-
Message:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x02 REQ (0x01) 0 0 N/A Slave 0x02 RSP (0x02) 1 8 (4 bytes version number + 4 bytes crc) Version number -
Version number:
4 bytes, e.g., 0x01 0x02 0x03 0x04, representing version V1.2.3.4
-
Query example:
Host: 42 55 58 58 02 01 01 00 00 00 af 1b ed 1f Slave: 42 55 58 58 02 02 00 01 08 00 25 e6 ea 29 01 00 00 00 79 b8 f8 99
2.5 open and close Dmic function*
-
Magic number (
magic
):0x42 0x55 0x58 0x58
-
Message:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x72/0x73 REQ (0x01) 0 0 N/A Slave 0x72/0x73 RSP (0x02) 1 6 (2 bytes status code + 4 bytes crc) Status code -
Query example:
open Dmic example:
Host: 42 55 58 58 72 01 00 00 00 00 0B 71 73 AC
Slave:42 55 58 58 72 02 00 01 06 00 6A C6 4B BC 01 00 BE 23 C2 58
close Dmic example:
Host: 42 55 58 58 73 01 00 00 00 00 AE A2 2F 67
Slave: 42 55 58 58 73 02 00 01 06 00 CF 15 17 77 01 00 BE 23 C2 58
2.6 UART Recording*
- Recording baud rate: 500000
- Magic number (
magic
):0x58 0x58 0x55 0x42
-
Start recording:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x0307 NTF (0x03) 0 16 Recording configuration: UART_RECORD_CONFIG Slave 0x0381 NTF (0x03) 0 16 Recording configuration: UART_RECORD_CONFIG typedef struct { unsigned int baudrate; // 0: default; others: Limited support unsigned int channel_num; // 0 or 1: one channel; 2: two channels; others: Not support; unsigned int channel; // bit_0: mic0; bit_1: mic1; bit_2: fft; bit_3: logfbank; bit_4: G-sensor unsigned int flow_ctrl_enable; // 1: enable flow control; 0: disable flow control } UART_RECORD_CONFIG;
-
When the host sends the recording configuration to GX8002, GX8002 checks the configuration. If it is valid, it will return the configuration back to the host to indicate that recording can start; otherwise, it will ignore the message.
-
Example (mic0):
Host:
58 58 55 42 07 03 00 00 10 00 6f 8c f6 5e 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
Slave:58 58 55 42 81 03 00 00 10 00 aa 7b 1f 96 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
-
Example (G-sensor):
Host:
58 58 55 42 07 03 00 00 10 00 6f 8c f6 5e 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00
Slave:58 58 55 42 81 03 00 00 10 00 aa 7b 1f 96 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00
-
Flow control:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x0384 NTF (0x03) 0 0 N/A -
If flow control is enabled in the start recording message, it is considered that it is accompanied by flow control. After the GX8002 checks the recording configuration and switches the working mode, it starts sending data.
Flow control cannot be used when recording G-sensor data.
Example:
58 58 55 42 84 03 01 00 00 00 2d 9f ac 34
-
Recording data:
Role Command Message Type B_CHECK Message Body Length Message Body Content Slave 0x0382 NTF (0x03) 0 Length of data for one recording period Data for one recording period (context) Each flow control sends data for one recording period, which corresponds to the data in one context.
The recording period varies depending on the amount of sensor data.
For these 4 channels (mic0, mic1, fft, logfbank), if multiple channels are enabled, they will be sent in sequence.
G-sensor channel cannot be used together with other channels for recording.
mic0 and mic1 channels are PCM data with a sample rate of 16000 and a bit depth of 16 bits. mic1 is not supported in single mic mode.
G-sensor channel data is 3-dimensional, with a sample rate of 1600 and a bit depth of 16 bits, resulting in 6 bytes for each sample point.
-
Stop recording:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x0308 NTF (0x03) 0 0 N/A Upon receiving the stop recording message, GX8002 stops sending data.
Example:
58 58 55 42 08 03 01 00 00 00 8e 4b de 5d
2.7 FEED Mode*
- FEED mode is used for GX8002 to receive logfbank data sent by the host through UART for kws.
- When the host is in wakeup mode, GX8002 uses the data sent by the host for kws.
- When the host is in sleep mode, GX8002 uses mic data for kws.
- Baud rate: 500000
-
Magic number (
magic
):0x58 0x58 0x55 0x42
-
Host sends sleep state:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x0312 NTF (0x03) 0 0 N/A -
The host sends this message to GX8002 before entering sleep state. Upon receiving it, GX8002 switches its working mode to use mic data for kws.
-
GX8002 sends stop data transmission:
Role Command Message Type B_CHECK Message Body Length Message Body Content Slave 0x0316 NTF (0x03) 0 16 Feature configuration: UART_RECORD_CONFIG -
After receiving the sleep state message sent by the host, GX8002 switches its working mode and then sends this message to the host.
-
Host sends wakeup state:
Role Command Message Type B_CHECK Message Body Length Message Body Content Host 0x0313 NTF (0x03) 0 0 N/A -
The host sends this message to GX8002 after waking up. Upon receiving it, GX8002 switches its working mode to use logfbank data sent by the host for kws.
-
Start data transmission:
Role Command Message Type B_CHECK Message Body Length Message Body Content Slave 0x0314 NTF (0x03) 0 16 Feature configuration: UART_RECORD_CONFIG Host 0x0317 NTF (0x03) 0 16 Feature configuration: Configuration: UART_RECORD_CONFIG typedef struct { unsigned int frame_length; // ms unsigned int sample_rate; // default: 16000 unsigned int frame_num_per_pack; // default: 4 unsigned int version; // 0x1 } UART_FEATURE_CONFIG;
-
GX8002 sends the feature configuration to the host, and the host checks the configuration. If it is valid, the host returns the feature configuration back to GX8002 to indicate that data transmission can begin; otherwise, it will ignore the message.