update zh-en
This commit is contained in:
@@ -0,0 +1,286 @@
|
||||
---
|
||||
title: XU316 and MCU Communication Protocol Command Macro Definitions
|
||||
description: This document provides command macro definitions related to the XU316 and MCU communication protocol, including frame format, command length, communication protocol, etc., to help developers implement XU316-MCU communication functionality.
|
||||
keywords: XU316 communication protocol, MCU command macro definitions, audio format definitions, communication frame format, command data structures, audio type definitions
|
||||
---
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
# XU316 and MCU Communication Protocol Command Macro Definitions
|
||||
|
||||
## Document Description
|
||||
|
||||
This document provides command macro definitions related to the XU316 and MCU communication protocol, mainly including the following content:
|
||||
|
||||
1. Communication frame format definitions
|
||||
2. MCU command data length definitions
|
||||
3. Communication protocol command word enumerations
|
||||
4. Audio format and type definitions
|
||||
5. Command data structure definitions
|
||||
|
||||
These macro definitions and data structures are the foundation of XU316-MCU communication. Developers need to correctly understand and use these definitions to implement communication functionality.
|
||||
|
||||
## Communication Frame Format
|
||||
|
||||
### Basic Frame Format Definitions
|
||||
```c
|
||||
#define FRAME_HEADER_H 0x55
|
||||
#define FRAME_HEADER_L 0xAA
|
||||
#define PROTOCOL_VERSION 0x01
|
||||
#define PROTOCOL_VERSION_RX 0x03
|
||||
```
|
||||
|
||||
## Command Data Length Definitions
|
||||
|
||||
### XU316 Command Data Length
|
||||
```c
|
||||
#define CMD00_XU316_DATA_LEN 0x11 // 0x00 Command: Start boot (boot options)
|
||||
#define CMD01_XU316_DATA_LEN 0x00 // 0x01 Command: Read product information (60-byte firmware info)
|
||||
#define CMD02_XU316_DATA_LEN 0x00 // 0x02 Command: Read power-on configuration (14-byte config parameters)
|
||||
#define CMD03_XU316_DATA_LEN 0x00 // 0x03 Command: Get audio mode (5-byte mode parameters)
|
||||
#define CMD04_XU316_DATA_LEN 0x00 // 0x04 Command: Get user configuration (14-byte user settings)
|
||||
#define CMD05_XU316_DATA_LEN 0x15 // 0x05 Command: Boot complete (no data field)
|
||||
|
||||
#define CMDF1_XU316_DATA_LEN 0x03 // 0xF1 Command: Version query (3-byte version info)
|
||||
|
||||
#define CMD20_XU316_DATA_LEN 0x14 // 0x20 Command: Set volume
|
||||
#define CMD21_XU316_DATA_LEN 0x00 // 0x21 Command: Audio effect mode
|
||||
#define CMD22_XU316_DATA_LEN 0x02 // 0x22 Command: Device status query
|
||||
#define CMD23_XU316_DATA_LEN 0x00 // 0x23 Command: Bluetooth control
|
||||
#define CMD24_XU316_DATA_LEN 0x02 // 0x24 Command: Send playback volume
|
||||
#define CMD25_XU316_DATA_LEN 0x01 // 0x25 Command: Send recording volume
|
||||
#define CMD27_XU316_DATA_LEN 0x00 // 0x27 Command: Special unmute (no data field)
|
||||
#define CMD28_XU316_DATA_LEN 0x01 // 0x28 Command: Audio format delay setting (1-byte parameter)
|
||||
|
||||
#define CMD_HID_TRANSPARENT_DATA_LEN 0x39 // 0xEE Command: HID transparent/OTA upgrade (57 bytes)
|
||||
```
|
||||
|
||||
### MCU Command Data Length
|
||||
```c
|
||||
#define CMD00_MCU_DATA_LEN 0x01 // 0x00 Command: Start boot (boot options)
|
||||
#define CMD01_MCU_DATA_LEN 0x3C // 0x01 Command: Read product information (60-byte firmware info)
|
||||
#define CMD02_MCU_DATA_LEN 0x0E // 0x02 Command: Read power-on configuration (14-byte config parameters)
|
||||
#define CMD03_MCU_DATA_LEN 0x05 // 0x03 Command: Get audio mode (5-byte mode parameters)
|
||||
#define CMD04_MCU_DATA_LEN 0x0E // 0x04 Command: Get user configuration (14-byte user settings)
|
||||
#define CMD05_MCU_DATA_LEN 0x00 // 0x05 Command: Boot complete (no data field)
|
||||
|
||||
#define CMDF1_MCU_DATA_LEN 0x00 // 0xF1 Command: Version query (no data field)
|
||||
|
||||
#define CMD20_MCU_DATA_LEN 0x00 // 0x20 Command: Set volume
|
||||
#define CMD21_MCU_DATA_LEN 0x01 // 0x21 Command: Audio effect mode
|
||||
#define CMD22_MCU_DATA_LEN 0x00 // 0x22 Command: Device status query
|
||||
#define CMD23_MCU_DATA_LEN 0x05 // 0x23 Command: Set audio mode
|
||||
#define CMD24_MCU_DATA_LEN 0x00 // 0x24 Command: Send playback volume
|
||||
#define CMD25_MCU_DATA_LEN 0x00 // 0x25 Command: Send recording volume
|
||||
#define CMD27_MCU_DATA_LEN 0x00 // 0x27 Command: Special unmute (no data field)
|
||||
#define CMD28_MCU_DATA_LEN 0x00 // 0x28 Command: Audio format delay setting (no data field)
|
||||
|
||||
#define CMD_HID_TRANSPARENT_MCU_DATA_LEN 0x39 // 0xEE Command: HID transparent/OTA upgrade (57 bytes)
|
||||
```
|
||||
|
||||
## Communication Protocol Command Definitions
|
||||
|
||||
### Command Word Enumeration
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
/****** Basic Control Commands (0x00-0x05) ******/
|
||||
CMD_STARTUP = 0x00, // System startup
|
||||
CMD_GET_PRODUCT_INFO = 0x01, // Product information query
|
||||
CMD_GET_BOOT_CFG = 0x02, // Power-on configuration read
|
||||
CMD_GET_AUD_MODE = 0x03, // Audio mode get
|
||||
CMD_GET_USER_CFG = 0x04, // User configuration get
|
||||
CMD_STARTUP_COMPLETE = 0x05, // Boot complete notification
|
||||
|
||||
CMD_GET_VERSION = 0xF1, // Version query
|
||||
|
||||
/****** Business Control Commands (0x20-0x2F) ******/
|
||||
CMD_REPORT_STATUS = 0x20, // Status report
|
||||
CMD_MEDIA_CONTROL = 0x21, // Media control
|
||||
CMD_SET_PLAY_FORMAT = 0x22, // Audio format setting
|
||||
CMD_SET_AUDIO_MODE = 0x23, // Audio mode setting
|
||||
CMD_SET_PLAY_VOL = 0x24, // Playback volume setting
|
||||
CMD_SET_REC_VOL = 0x25, // Recording volume setting
|
||||
CMD_SPECIAL_UNMUTE = 0x27, // Special unmute
|
||||
CMD_SET_AUDIO_FORMAT_DELAY = 0x28, // Audio format delay setting
|
||||
|
||||
CMD_HID_TRANSPARENT = 0xEE, // HID transparent/OTA upgrade command
|
||||
|
||||
CMD_COUNT = CMD_SET_REC_VOL + 1 // Total number of currently supported commands
|
||||
|
||||
} mcu_command_t;
|
||||
```
|
||||
|
||||
### Boot Option Enumeration (Bitmask Mode)
|
||||
|
||||
!!! note
|
||||
**Boot Option Enumeration (Bitmask Mode)**
|
||||
**Uses uint8_t to ensure single-byte storage, supports multiple option combinations**
|
||||
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
BOOT_OPTION_USE_DEFAULTS = 0x00, // Use all default configurations
|
||||
BOOT_OPTION_UPDATE_BASIC_INFO = 0x01, // Update basic product information (bit0)
|
||||
BOOT_OPTION_UPDATE_POWER_CFG = 0x02, // Update power-on configuration information (bit1)
|
||||
BOOT_OPTION_UPDATE_OTHER_CFG = 0x04 // Reserved configuration, currently unused (bit2)
|
||||
} boot_option_t;
|
||||
```
|
||||
|
||||
### Media Control Enumeration
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
MEDIA_KEY_VOLUME_UP = 0x00, // Volume increase
|
||||
MEDIA_KEY_VOLUME_DOWN = 0x01, // Volume decrease
|
||||
MEDIA_KEY_PLAY_PAUSE = 0x02, // Play/Pause
|
||||
MEDIA_KEY_NEXT_TRACK = 0x03, // Next track
|
||||
MEDIA_KEY_PREV_TRACK = 0x04, // Previous track
|
||||
MEDIA_KEY_FAST_FORWARD = 0x05, // Fast forward
|
||||
MEDIA_KEY_REWIND = 0x06, // Rewind
|
||||
MEDIA_KEY_MUTE = 0x07 // Mute toggle
|
||||
|
||||
// Reserved for expansion (0x08-0xFF reserved for protocol)
|
||||
|
||||
} media_control_t;
|
||||
```
|
||||
|
||||
## Audio Format Definitions
|
||||
|
||||
!!! note
|
||||
**Audio Stream Format Enumeration (Compatible with AES67-2020 Standard)**
|
||||
**Explicitly specifies underlying type as uint8_t to ensure 1-byte storage**
|
||||
|
||||
### Audio Stream Format Enumeration
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
// PCM Sample Rate Formats (0x00-0x10)
|
||||
AUDIO_PCM_44100 = 0x00,
|
||||
AUDIO_PCM_48000 = 0x01,
|
||||
AUDIO_PCM_88200 = 0x02,
|
||||
AUDIO_PCM_96000 = 0x03,
|
||||
AUDIO_PCM_176400 = 0x04,
|
||||
AUDIO_PCM_192000 = 0x05,
|
||||
AUDIO_PCM_352800 = 0x06,
|
||||
AUDIO_PCM_384000 = 0x07,
|
||||
AUDIO_PCM_705600 = 0x08,
|
||||
AUDIO_PCM_768000 = 0x09,
|
||||
AUDIO_PCM_1441200 = 0x0A,
|
||||
AUDIO_PCM_1536000 = 0x0B,
|
||||
AUDIO_PCM_32000 = 0x0C,
|
||||
AUDIO_PCM_64000 = 0x0D,
|
||||
AUDIO_PCM_128000 = 0x0E,
|
||||
AUDIO_PCM_256000 = 0x0F,
|
||||
AUDIO_PCM_512000 = 0x10,
|
||||
|
||||
// DSD Formats (0x11-0x15)
|
||||
AUDIO_DSD_64 = 0x11,
|
||||
AUDIO_DSD_128 = 0x12,
|
||||
AUDIO_DSD_256 = 0x13,
|
||||
AUDIO_DSD_512 = 0x14,
|
||||
AUDIO_DSD_1024 = 0x15,
|
||||
|
||||
// MQA Formats (0x16-0x2D)
|
||||
AUDIO_MQA_44100 = 0x16,
|
||||
AUDIO_MQA_88200 = 0x17,
|
||||
AUDIO_MQA_176400 = 0x18,
|
||||
AUDIO_MQA_352800 = 0x19,
|
||||
AUDIO_MQA_705600 = 0x1A,
|
||||
AUDIO_MQA_1411200 = 0x1B,
|
||||
AUDIO_MQA_2822400 = 0x1C,
|
||||
AUDIO_MQA_5644800 = 0x1D,
|
||||
|
||||
// -- 48kHz Base Series --
|
||||
AUDIO_MQA_48000 = 0x1E,
|
||||
AUDIO_MQA_96000 = 0x1F,
|
||||
AUDIO_MQA_192000 = 0x20,
|
||||
AUDIO_MQA_384000 = 0x21,
|
||||
AUDIO_MQA_768000 = 0x22,
|
||||
AUDIO_MQA_1536000 = 0x23,
|
||||
AUDIO_MQA_3072000 = 0x24,
|
||||
AUDIO_MQA_6144000 = 0x25,
|
||||
|
||||
// -- Other Base Frequency Series --
|
||||
AUDIO_MQA_64000 = 0x26,
|
||||
AUDIO_MQA_128000 = 0x27,
|
||||
AUDIO_MQA_256000 = 0x28,
|
||||
AUDIO_MQA_512000 = 0x29,
|
||||
AUDIO_MQA_1024000 = 0x2A,
|
||||
AUDIO_MQA_2048000 = 0x2B,
|
||||
AUDIO_MQA_4096000 = 0x2C,
|
||||
AUDIO_MQA_8192000 = 0x2D,
|
||||
|
||||
// Special Reserved Value
|
||||
AUDIO_NO_USED = 0xFF
|
||||
|
||||
} audio_format_t;
|
||||
```
|
||||
|
||||
### Audio Type Enumeration
|
||||
!!! note
|
||||
**Audio Type Enumeration (Compatible with AES67-2020 Standard)**
|
||||
**Explicitly specifies underlying type as uint8_t to ensure 1-byte storage**
|
||||
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_TYPE_PCM = 0x00, // PCM standard audio
|
||||
AUDIO_TYPE_RESERVE = 0x01, // Protocol reserved field
|
||||
AUDIO_TYPE_MQA = 0x02, // MQA encoded audio
|
||||
AUDIO_TYPE_MQB = 0x03, // MQB encoded audio (secondary extension)
|
||||
AUDIO_TYPE_MQA_STUDIO = 0x04, // MQA Studio master quality
|
||||
AUDIO_TYPE_DSD = 0x05 // Direct Stream Digital
|
||||
|
||||
// 0x06-0xFF reserved for future expansion
|
||||
|
||||
} audio_type_t;
|
||||
```
|
||||
|
||||
## Command Data Structures
|
||||
|
||||
### Data Structure Definitions
|
||||
```c
|
||||
typedef uint8_t byte_pair[2];
|
||||
// Command data structure
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint8_t boot_option; // 0x00: Boot option data
|
||||
// Product basic information
|
||||
uint8_t vid_uac1[2]; // UAC1.0 vendor ID
|
||||
uint8_t pid_uac1[2]; // UAC1.0 product ID
|
||||
uint8_t vid_uac2[2]; // UAC2.0 vendor ID
|
||||
uint8_t pid_uac2[2]; // UAC2.0 product ID
|
||||
uint8_t product_manufacturer[16]; // Manufacturer name
|
||||
uint8_t product_name[16]; // Product name
|
||||
uint8_t product_serial[16]; // Serial number
|
||||
uint8_t basic_info_crc[4]; // Basic information CRC32
|
||||
// User configuration is power-on configuration information and also application runtime parameters
|
||||
uint8_t startup_status; // Startup status
|
||||
uint8_t audio_mode[5];
|
||||
uint8_t mute_duration[2]; // Mute duration (ms)
|
||||
uint8_t mic_volume; // Microphone volume, also recording volume
|
||||
uint8_t dac_l_volume; // Left channel volume (0-255)
|
||||
uint8_t dac_r_volume; // Right channel volume (0-255)
|
||||
uint8_t power_cfg_crc[4]; // Power-on configuration CRC32
|
||||
// Application runtime parameters
|
||||
uint8_t media_control; // Media control command
|
||||
uint8_t audio_format; // Audio format code
|
||||
uint8_t audio_type; // Audio type code
|
||||
} mcu_data_t;
|
||||
```
|
||||
|
||||
<!-- Structured Data Markup -->
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"headline": "XU316 and MCU Communication Protocol Command Macro Definitions",
|
||||
"description": "This document provides command macro definitions related to the XU316 and MCU communication protocol, including frame format, command length, communication protocol, etc., to help developers implement XU316-MCU communication functionality.",
|
||||
"keywords": "XU316 communication protocol, MCU command macro definitions, audio format definitions, communication frame format, command data structures, audio type definitions",
|
||||
"author": {
|
||||
"@type": "Organization",
|
||||
"name": "Phaten Audio"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,407 @@
|
||||
---
|
||||
title: XU316 and MCU Communication Protocol Reference
|
||||
description: Detailed description of the communication protocol between XU316 and MCU, including data structures, command formats, and processing flows
|
||||
keywords: XU316, MCU, communication protocol, command reference
|
||||
hide:
|
||||
-toc
|
||||
---
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
# XU316 and MCU Communication Protocol Reference
|
||||
|
||||
## 1. Basic Data Structures
|
||||
|
||||
### 1.1 Ring Buffer
|
||||
```c
|
||||
#define RING_BUFFER_SIZE 256 // Ring buffer size, used for UART communication buffering
|
||||
|
||||
typedef struct {
|
||||
uint8_t buffer[RING_BUFFER_SIZE]; // Data storage area
|
||||
volatile uint16_t head; // Write position pointer
|
||||
volatile uint16_t tail; // Read position pointer
|
||||
volatile uint16_t count; // Current data count
|
||||
} ring_buffer_t;
|
||||
```
|
||||
|
||||
### 1.2 Audio Mode Definitions
|
||||
```c
|
||||
// Audio mode configuration array, each mode contains 5-byte configuration data
|
||||
static const uint8_t audio_modes[][5] = {
|
||||
{0x00, 0x80, 0xa9, 0x00, 0x01}, // USB-no-mqa mode
|
||||
{0x00, 0x80, 0x01, 0x00, 0x02}, // UAC1 mode
|
||||
{0x10, 0x80, 0x65, 0x10, 0x03}, // COAX mode
|
||||
{0x00, 0x80, 0x65, 0x10, 0x04}, // OPT mode
|
||||
{0x00, 0x80, 0xc5, 0x08, 0x05}, // SPDIF OUT mode
|
||||
{0x00, 0x82, 0xd5, 0x81, 0x06}, // I2S IN mode
|
||||
{0x20, 0x80, 0x65, 0x10, 0x07} // HDMI mode
|
||||
};
|
||||
|
||||
// Corresponding mode name array
|
||||
static const char *mode_names[] = {
|
||||
"USB-no-mqa",
|
||||
"UAC1",
|
||||
"COAX",
|
||||
"OPT",
|
||||
"SPDIF OUT",
|
||||
"I2S IN",
|
||||
"HDMI"
|
||||
};
|
||||
```
|
||||
|
||||
## 2. Initialization and Configuration
|
||||
|
||||
### 2.1 Device Initialization Information Print
|
||||
```c
|
||||
#define AUDIO_MODE_COUNT (sizeof(audio_modes) / sizeof(audio_modes[0]))
|
||||
|
||||
void print_init_info(void)
|
||||
{
|
||||
log_data(LOG_USER, "----------Device initialized----------\n");
|
||||
// Print UAC1.0 device information
|
||||
log_data(LOG_USER, "VID1: %02X%02X", mcu_data.vid_uac1[0], mcu_data.vid_uac1[1]);
|
||||
log_data(LOG_USER, "PID1: %02X%02X", mcu_data.pid_uac1[0], mcu_data.pid_uac1[1]);
|
||||
// Print UAC2.0 device information
|
||||
log_data(LOG_USER, "VID2: %02X%02X", mcu_data.vid_uac2[0], mcu_data.vid_uac2[1]);
|
||||
log_data(LOG_USER, "PID2: %02X%02X", mcu_data.pid_uac2[0], mcu_data.pid_uac2[1]);
|
||||
// Print product information
|
||||
log_data(LOG_USER, "Manufacturer: %s", mcu_data.product_manufacturer);
|
||||
log_data(LOG_USER, "Name: %s", mcu_data.product_name);
|
||||
log_data(LOG_USER, "Serial: %s", mcu_data.product_serial);
|
||||
// Print CRC verification information
|
||||
log_data(LOG_USER, "Basic Info CRC: %02X%02X%02X%02X",
|
||||
mcu_data.basic_info_crc[0], mcu_data.basic_info_crc[1],
|
||||
mcu_data.basic_info_crc[2], mcu_data.basic_info_crc[3]);
|
||||
log_data(LOG_USER, "Power Config CRC: %02X%02X%02X%02X",
|
||||
mcu_data.power_cfg_crc[0], mcu_data.power_cfg_crc[1],
|
||||
mcu_data.power_cfg_crc[2], mcu_data.power_cfg_crc[3]);
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 Ring Buffer Initialization
|
||||
```c
|
||||
void ring_buffer_init(void) {
|
||||
uart_ring_buffer.head = 0; // Initialize write position
|
||||
uart_ring_buffer.tail = 0; // Initialize read position
|
||||
uart_ring_buffer.count = 0; // Initialize data count
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3 Product Information Initialization
|
||||
```c
|
||||
void xu316_init(void)
|
||||
{
|
||||
// Default audio mode configuration (USB UAC2.0)
|
||||
uint8_t audio_mode[5] = {0x00, 0x80, 0xa9, 0x00, 0x01};
|
||||
|
||||
// Configure UAC1.0 device information
|
||||
mcu_data.vid_uac1[0] = 0x20;
|
||||
mcu_data.vid_uac1[1] = 0xB1; // VID = 0x20B1
|
||||
mcu_data.pid_uac1[0] = 0x00;
|
||||
mcu_data.pid_uac1[1] = 0x17; // PID = 0x0017
|
||||
|
||||
// Configure UAC2.0 device information
|
||||
mcu_data.vid_uac2[0] = 0x20;
|
||||
mcu_data.vid_uac2[1] = 0xB1; // VID = 0x20B1
|
||||
mcu_data.pid_uac2[0] = 0x00;
|
||||
mcu_data.pid_uac2[1] = 0x16; // PID = 0x0016
|
||||
|
||||
// Configure product information
|
||||
memcpy(mcu_data.product_manufacturer, "Phaten", 6);
|
||||
// Set product name
|
||||
memcpy(mcu_data.product_name, "XMOS XU316", 11);
|
||||
// Set product serial number
|
||||
memcpy(mcu_data.product_serial, "123456789ABCDEF", 15);
|
||||
|
||||
// Calculate and store basic information CRC32 checksum (56 bytes)
|
||||
crc = calculate_crc32(mcu_data.vid_uac1, 56);
|
||||
mcu_data.basic_info_crc[0] = (crc >> 24) & 0xFF;
|
||||
mcu_data.basic_info_crc[1] = (crc >> 16) & 0xFF;
|
||||
mcu_data.basic_info_crc[2] = (crc >> 8) & 0xFF;
|
||||
mcu_data.basic_info_crc[3] = crc & 0xFF;
|
||||
|
||||
// Initialize device status and audio configuration
|
||||
mcu_data.startup_status = 0x00;
|
||||
memcpy(&mcu_data.audio_mode, audio_mode, 5);
|
||||
|
||||
// Configure mute duration (400ms)
|
||||
mcu_data.mute_duration[0] = MUTE_DURATION_CONFIG >> 8;
|
||||
mcu_data.mute_duration[1] = MUTE_DURATION_CONFIG;
|
||||
|
||||
// Initialize volume settings
|
||||
mcu_data.mic_volume = MIC_VOLUME_CONFIG;
|
||||
// Initialize left and right channel DAC volume
|
||||
mcu_data.dac_l_volume = DAC_L_VOLUME_CONFIG;
|
||||
mcu_data.dac_r_volume = DAC_R_VOLUME_CONFIG;
|
||||
|
||||
// Calculate and store power configuration CRC32 checksum (10 bytes)
|
||||
crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 0x0a);
|
||||
mcu_data.power_cfg_crc[0] = (crc >> 24) & 0xFF;
|
||||
mcu_data.power_cfg_crc[1] = (crc >> 16) & 0xFF;
|
||||
mcu_data.power_cfg_crc[2] = (crc >> 8) & 0xFF;
|
||||
mcu_data.power_cfg_crc[3] = crc & 0xFF;
|
||||
|
||||
// Initialize communication buffer
|
||||
ring_buffer_init();
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Communication Buffer Operations
|
||||
|
||||
### 3.1 Ring Buffer Operation Functions
|
||||
```c
|
||||
// Write data to ring buffer
|
||||
uint8_t ring_buffer_write(uint8_t *data, uint16_t len) {
|
||||
uint16_t i;
|
||||
for(i = 0; i < len; i++) {
|
||||
if(uart_ring_buffer.count >= RING_BUFFER_SIZE) {
|
||||
return 0; // Buffer full, write failed
|
||||
}
|
||||
uart_ring_buffer.buffer[uart_ring_buffer.head] = data[i];
|
||||
uart_ring_buffer.head = (uart_ring_buffer.head + 1) % RING_BUFFER_SIZE;
|
||||
uart_ring_buffer.count++;
|
||||
}
|
||||
return 1; // Write successful
|
||||
}
|
||||
|
||||
// Read data from ring buffer
|
||||
uint8_t ring_buffer_read(uint8_t *data, uint16_t len) {
|
||||
uint16_t i;
|
||||
if(uart_ring_buffer.count < len) {
|
||||
return 0; // Insufficient data
|
||||
}
|
||||
for(i = 0; i < len; i++) {
|
||||
data[i] = uart_ring_buffer.buffer[uart_ring_buffer.tail];
|
||||
uart_ring_buffer.tail = (uart_ring_buffer.tail + 1) % RING_BUFFER_SIZE;
|
||||
uart_ring_buffer.count--;
|
||||
}
|
||||
return 1; // Read successful
|
||||
}
|
||||
|
||||
// Peek data (without moving read pointer)
|
||||
uint8_t ring_buffer_peek(uint8_t *data, uint16_t len) {
|
||||
uint16_t i;
|
||||
uint16_t temp_tail = uart_ring_buffer.tail;
|
||||
for(i = 0; i < len; i++) {
|
||||
data[i] = uart_ring_buffer.buffer[temp_tail];
|
||||
temp_tail = (temp_tail + 1) % RING_BUFFER_SIZE;
|
||||
}
|
||||
return 0; // Peek successful
|
||||
}
|
||||
```
|
||||
|
||||
## 4. Checksum Calculation
|
||||
|
||||
### 4.1 CRC32 Calculation
|
||||
```c
|
||||
uint32_t calculate_crc32(const uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
uint32_t crc = 0xFFFFFFFF;
|
||||
const uint32_t poly = 0xEDB88320; // CRC32 polynomial
|
||||
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
crc ^= buffer[i];
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if (crc & 1) {
|
||||
crc = (crc >> 1) ^ poly;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ~crc; // Return CRC32 checksum
|
||||
}
|
||||
|
||||
// Calculate simple checksum
|
||||
uint8_t xu316_calc_checksum(uint8_t *data, uint8_t len)
|
||||
{
|
||||
uint8_t sum = 0;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
sum += data[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Communication Protocol Processing
|
||||
|
||||
### 5.1 Frame Verification
|
||||
```c
|
||||
// Verify frame data integrity
|
||||
uint8_t uart_frame_check(uint8_t *buf, uint8_t len)
|
||||
{
|
||||
// Check minimum length requirement
|
||||
if (len < 6) { // Header(2) + Version(1) + Command(1) + Length(2) + Checksum(1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Verify frame header
|
||||
if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get data length (big-endian mode)
|
||||
uint16_t data_len = buf[4];
|
||||
|
||||
// Verify data length validity
|
||||
if (data_len > 256 || len < (data_len + 6)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Calculate and verify checksum
|
||||
uint8_t sum = xu316_calc_checksum(buf, data_len + 5);
|
||||
if (sum != buf[data_len + 5]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_TEMP(LOG_RECV, "", buf, len);
|
||||
return 1;
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 Data Frame Encapsulation
|
||||
```c
|
||||
int xu316_pack_frame(uint8_t cmd, uint8_t *data, uint8_t len)
|
||||
{
|
||||
uint8_t tx_data[256] = {0};
|
||||
if (len >= 255) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Build frame header
|
||||
tx_data[0] = FRAME_HEADER_H;
|
||||
tx_data[1] = FRAME_HEADER_L;
|
||||
tx_data[2] = PROTOCOL_VERSION_RX;
|
||||
tx_data[3] = cmd;
|
||||
tx_data[4] = len;
|
||||
|
||||
// Copy data payload
|
||||
if (data && len > 0) {
|
||||
memcpy(tx_data + 5, data, len);
|
||||
}
|
||||
|
||||
// Calculate and add checksum
|
||||
tx_data[len + 5] = xu316_calc_checksum(tx_data, len + 5);
|
||||
len += 6;
|
||||
|
||||
// Send data
|
||||
usart_dma_send(tx_data, len);
|
||||
LOG_INFO("Sending frame: cmd=0x%02X, len=%d", cmd, len);
|
||||
LOG_TEMP(LOG_SEND, "", tx_data, len);
|
||||
return len;
|
||||
}
|
||||
```
|
||||
|
||||
### 5.3 Frame Length Check
|
||||
```c
|
||||
int check_frame_length(uint8_t *buf, uint16_t len) {
|
||||
// Verify frame header
|
||||
if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
|
||||
LOG_DEBUG("Frame header check failed %02x %02x", buf[0], buf[1]);
|
||||
return -1;
|
||||
}
|
||||
// Get data length (big-endian mode)
|
||||
int data_len = buf[4];
|
||||
// Return complete frame length
|
||||
return data_len + 6;
|
||||
}
|
||||
```
|
||||
|
||||
### 5.4 Data Reception Processing
|
||||
```c
|
||||
void uart_data_process(void)
|
||||
{
|
||||
uint8_t peek_buffer[8]; // Peek buffer
|
||||
uint8_t process_buffer[256]; // Processing buffer
|
||||
int frame_length;
|
||||
|
||||
while(uart_ring_buffer.count >= 6) { // At least 6 bytes needed to start checking
|
||||
// Peek frame header information
|
||||
ring_buffer_peek(peek_buffer, 6);
|
||||
|
||||
// Debug output
|
||||
for(int i = 0; i < 6; i++) {
|
||||
LOG_DEBUG("peek_buffer[%d]: %02x", i, peek_buffer[i]);
|
||||
}
|
||||
|
||||
// Check frame length
|
||||
frame_length = check_frame_length(peek_buffer, 6);
|
||||
if(frame_length < 0) {
|
||||
// Invalid frame, discard one byte
|
||||
uint8_t dummy;
|
||||
ring_buffer_read(&dummy, 1);
|
||||
LOG_ERROR("Frame length check failed %02x", dummy);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if there is enough data
|
||||
if(uart_ring_buffer.count < frame_length) {
|
||||
LOG_ERROR("Not enough data");
|
||||
break; // Wait for more data
|
||||
}
|
||||
|
||||
// Read and process complete frame
|
||||
if(ring_buffer_read(process_buffer, frame_length)) {
|
||||
uart_data_parse();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.5 Data Parsing Processing
|
||||
```c
|
||||
int uart_data_parse(void)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t cmd = 0;
|
||||
uint16_t data_len = 0;
|
||||
uint16_t rx_len = 0;
|
||||
uint8_t tmp;
|
||||
static uint8_t buffer[256] = {0};
|
||||
rx_len = g_rx_count;
|
||||
|
||||
// Verify frame integrity
|
||||
ret = uart_frame_check((uint8_t *)g_rx_data, rx_len);
|
||||
if (ret == 0) {
|
||||
LOG_ERROR("Frame check failed %d", rx_len);
|
||||
LOG_TEMP(LOG_RECV, "", g_rx_data, rx_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Parse frame information
|
||||
data_len = rx_len - 6;
|
||||
cmd = g_rx_data[3];
|
||||
if (g_rx_data[4] != data_len) {
|
||||
LOG_ERROR("Data length mismatch: expected %d, got %d", g_rx_data[4], data_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_DEBUG("Received frame: cmd=0x%02X, len=%d", cmd, data_len);
|
||||
LOG_VERBOSE("--------------------------------");
|
||||
LOG_VERBOSE("cmd : %02X", cmd);
|
||||
memcpy(buffer, g_rx_data + 5, data_len);
|
||||
|
||||
// Process data according to command type
|
||||
switch (cmd) {
|
||||
case 0x00: // Startup information
|
||||
// ... Process startup information ...
|
||||
break;
|
||||
|
||||
case 0x01: // Basic information
|
||||
// ... Process basic information ...
|
||||
break;
|
||||
|
||||
case 0x02: // Power configuration
|
||||
// ... Process power configuration ...
|
||||
break;
|
||||
|
||||
// ... Other command processing ...
|
||||
|
||||
default:
|
||||
LOG_ERROR("Unknown command: 0x%02X", cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
@@ -1,31 +1,31 @@
|
||||
---
|
||||
title: Code Examples for XU316 Audio Interface Control
|
||||
description: This document provides code examples related to the control of the XU316 audio interface, including serial communication protocols, audio interface configurations, etc., to help developers quickly implement the communication function between XU316 and MCU.
|
||||
title: XU316 Audio Interface Control Code Examples
|
||||
description: This document provides code examples for XU316 audio interface control, including serial communication protocol, audio interface configuration, etc., to help developers quickly implement XU316-MCU communication functionality.
|
||||
keywords: XU316 development, audio interface control, MCU communication, I2S configuration, serial protocol, audio sampling rate, DSD configuration
|
||||
---
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
# Code Examples for XU316 Audio Interface Control
|
||||
# XU316 Audio Interface Control Code Examples
|
||||
|
||||
## Document Instructions
|
||||
## Document Description
|
||||
|
||||
This document provides code examples related to the control of the XU316 audio interface, mainly including the following contents:
|
||||
This document provides code examples for XU316 audio interface control, mainly including the following content:
|
||||
|
||||
1. Definition of serial communication protocol
|
||||
2. Configuration parameters of audio interface
|
||||
3. Configuration of audio sampling rate and channels
|
||||
4. Setting of volume control parameters
|
||||
1. Serial communication protocol definitions
|
||||
2. Audio interface configuration parameters
|
||||
3. Audio sampling rate and channel configuration
|
||||
4. Volume control parameter settings
|
||||
|
||||
These code examples can assist developers in rapidly achieving the communication between XU316 and MCU and configuring various audio interface parameters.
|
||||
These code examples can help developers quickly implement XU316-MCU communication functionality and configure various audio interface parameters.
|
||||
|
||||
## Serial Communication Protocol
|
||||
|
||||
### Protocol Definition
|
||||
### Protocol Definitions
|
||||
```c
|
||||
#define SWAP16(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00))
|
||||
#define SWAP32(x) ((((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000))
|
||||
/*Protocol analysis*/
|
||||
/* Protocol parsing */
|
||||
#define UART_FRAME_HEAD 0xAA
|
||||
#define UART_FRAME_TAIL 0x55
|
||||
#define HEX_UPPERCASE 0
|
||||
@@ -45,11 +45,11 @@ typedef struct
|
||||
|
||||
### Serial Buffer Management
|
||||
```c
|
||||
/*Serial port*/
|
||||
/* Serial */
|
||||
/* buffer sizes */
|
||||
#define RX_BUFFER_SIZE 256
|
||||
#define TX_BUFFER_SIZE 256
|
||||
#define TX_BUFFER_NUM 2 // Double buffer
|
||||
#define TX_BUFFER_NUM 2 // Double buffering
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -78,21 +78,21 @@ typedef enum
|
||||
|
||||
### Interface Mode Configuration
|
||||
```c
|
||||
// I2S master - slave mode configuration
|
||||
#define I2S_MODE I2S_MODE_MASTER // I2S master mode, XU316 as the I2S master device
|
||||
// I2S master/slave mode configuration
|
||||
#define I2S_MODE I2S_MODE_MASTER // I2S master mode, XU316 acts as I2S master device
|
||||
// Synchronization mode configuration
|
||||
#define SYNC_MODE SYNC // Synchronization mode, used for audio clock synchronization
|
||||
#define SYNC_MODE SYNC // Synchronous mode, used for audio clock synchronization
|
||||
// MIDI interface configuration
|
||||
#define MIDI_MODE MIDI_MODE_ENABLE // MIDI function enabled
|
||||
// SPDIF input interface configuration
|
||||
#define SPDIF_IN_MODE SPDIF_IN_MODE_ENABLE // SPDIF input function enabled
|
||||
// SPDIF output interface configuration
|
||||
#define SPDIF_OUT_MODE SPDIF_OUT_MODE_ENABLE // SPDIF output function enabled
|
||||
// ADAT input interface configuration (ADAT is an 8 - channel digital audio transmission format)
|
||||
// ADAT input interface configuration (ADAT is an 8-channel digital audio transmission format)
|
||||
#define ADAT_IN_MODE ADAT_IN_MODE_ENABLE // ADAT input function enabled
|
||||
// ADAT output interface configuration
|
||||
#define ADAT_OUT_MODE ADAT_OUT_MODE_ENABLE // ADAT output function enabled
|
||||
// DSD output interface configuration (DSD is Direct Stream Digital, used for high - resolution audio)
|
||||
// DSD output interface configuration (DSD is Direct Stream Digital, used for high-resolution audio)
|
||||
#define DSD_OUT_MODE DSD_OUT_MODE_ENABLE // DSD output function enabled
|
||||
```
|
||||
|
||||
@@ -108,23 +108,23 @@ typedef enum
|
||||
#define AUDIO_OUTPUT_CHANNEL 3
|
||||
// Initialize audio type
|
||||
#define AUDIO_MODE USB_MODE
|
||||
// Mute time 2 0 - 65535 (ms)
|
||||
// Mute duration 2 0-65535 (ms)
|
||||
#define MUTE_DURATION 100
|
||||
// Default microphone volume
|
||||
// Microphone default volume
|
||||
#define MIC_VOLUME 10
|
||||
// Default DAC left - channel volume 1 See DAC volume field description
|
||||
// DAC left channel default volume 1 See DAC volume field description
|
||||
#define DAC_L_VOLUME 30
|
||||
// Default DAC right - channel volume 1 See DAC volume field description
|
||||
// DAC right channel default volume 1 See DAC volume field description
|
||||
#define DAC_R_VOLUME 20
|
||||
```
|
||||
|
||||
<!-- Structured data markup -->
|
||||
<!-- Structured Data Markup -->
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"headline": "Code Examples for XU316 Audio Interface Control",
|
||||
"description": "This document provides code examples related to the control of the XU316 audio interface, including serial communication protocols, audio interface configurations, etc., to help developers quickly implement the communication function between XU316 and MCU.",
|
||||
"headline": "XU316 Audio Interface Control Code Examples",
|
||||
"description": "This document provides code examples for XU316 audio interface control, including serial communication protocol, audio interface configuration, etc., to help developers quickly implement XU316-MCU communication functionality.",
|
||||
"keywords": "XU316 development, audio interface control, MCU communication, I2S configuration, serial protocol, audio sampling rate, DSD configuration",
|
||||
"author": {
|
||||
"@type": "Organization",
|
||||
@@ -133,11 +133,4 @@ typedef enum
|
||||
}
|
||||
</script>
|
||||
|
||||
## Consultation and Feedback
|
||||
|
||||
<details>
|
||||
<summary>Click to expand consultation feedback form</summary>
|
||||
|
||||
--8<-- "common/customer_form.md"
|
||||
|
||||
</details>
|
||||
```
|
||||
@@ -0,0 +1,198 @@
|
||||
---
|
||||
title: A316 Firmware-Free MCU Development Guide
|
||||
description: This document provides comprehensive guidance for XU316 and MCU communication development, including development steps, reference documentation, and FAQs to help developers quickly implement XU316-MCU communication functionality.
|
||||
keywords: XU316 development, MCU communication development, audio interface control, communication protocol, development guide, FAQ
|
||||
---
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
# A316 Firmware-Free MCU Development Guide
|
||||
|
||||
## Development Overview
|
||||
|
||||
This document provides comprehensive guidance for XU316 and MCU communication development, helping developers implement XU316-MCU communication functionality in the correct sequence. The development process is divided into several main steps, each with corresponding reference documentation and detailed instructions.
|
||||
|
||||
## Development Steps
|
||||
|
||||
<div class="grid" markdown>
|
||||
|
||||
=== "Step 1: Understanding Basic Concepts and Protocol Structure"
|
||||
**Objective**: Understand the basic concepts and protocol structure of XU316-MCU communication
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: XU316 and MCU Communication Protocol Command Macro Definitions](Command_Macros.md)
|
||||
|
||||
**Key Learning Points**:
|
||||
|
||||
- Master the basic structure of frame format (frame header, command, data length, checksum, frame tail)
|
||||
- Understand data length definitions for various commands
|
||||
- Familiarize with audio format enumerations and type definitions
|
||||
- Learn the composition of command data structures
|
||||
|
||||
=== "Step 2: Implementing Basic Communication Functions"
|
||||
**Objective**: Implement basic communication functions between XU316 and MCU
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: XU316 and MCU Communication Protocol Reference](Command_Reference.md)
|
||||
|
||||
**Development Tasks**:
|
||||
|
||||
- Implement ring buffer initialization and management
|
||||
- Implement data frame encapsulation and transmission
|
||||
- Implement data frame reception and parsing
|
||||
- Implement CRC32 and simple checksum calculation
|
||||
- Implement basic communication protocol processing flow
|
||||
|
||||
=== "Step 3: Configuring Audio Interfaces and Parameters"
|
||||
**Objective**: Configure XU316 audio interfaces and related parameters
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: XU316 Audio Interface Control Code Examples](Product_Content.md)
|
||||
|
||||
**Development Tasks**:
|
||||
|
||||
- Configure I2S master/slave mode
|
||||
- Set audio sampling rate and bit depth
|
||||
- Configure audio channel count
|
||||
- Set volume control parameters
|
||||
- Configure various audio interfaces (SPDIF, ADAT, DSD, etc.)
|
||||
|
||||
<!-- === "Step 4: Integration and Testing"
|
||||
**Objective**: Integrate all modules and perform functional testing
|
||||
|
||||
**Development Tasks**:
|
||||
- Integrate all communication function modules
|
||||
- Implement complete command processing flow
|
||||
- Perform functional testing and debugging
|
||||
- Optimize performance and stability -->
|
||||
|
||||
</div>
|
||||
|
||||
## Consultation and Feedback
|
||||
|
||||
<details>
|
||||
<summary>Click to expand consultation and feedback form</summary>
|
||||
|
||||
--8<-- "common/customer_form.md"
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
<!-- ## Frequently Asked Questions
|
||||
|
||||
### Communication Issues
|
||||
|
||||
!!! question "Q1: XU316 cannot send/receive data when connected to PC via serial port"
|
||||
**Problem Description**: XU316 cannot send or receive data when connected to PC via serial port, and logic analyzer cannot capture any data
|
||||
|
||||
**Solutions**:
|
||||
1. Check MCU response speed and configure XU316 with priority
|
||||
2. Verify if MCU is supplying power to XU316
|
||||
3. Ensure initialization is completed before XU316 sends power-on command
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: Firmware-Free Development Issues Guide](../../faq/technical_faq/a316_firmware_dev_faq.md)
|
||||
|
||||
!!! question "Q2: Device recognized normally on PC but not recognized by phone"
|
||||
**Problem Description**: Device can be recognized and play normally on PC, but cannot be recognized when connected to phone
|
||||
|
||||
**Solutions**:
|
||||
1. Check device power supply mode design
|
||||
2. Modify device power supply and discharge sections
|
||||
3. Ensure device can receive power correctly when connected to phone
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: Firmware-Free Development Issues Guide](../../faq/technical_faq/a316_firmware_dev_faq.md)
|
||||
|
||||
!!! question "Q3: IIS in command ineffective when WiFi is in slave mode"
|
||||
**Problem Description**: Sending IIS in command has no effect when WiFi is set to slave mode
|
||||
|
||||
**Solutions**:
|
||||
1. Check if firmware supports WiFi slave mode to XMOS master mode conversion
|
||||
2. Mount WiFi module to Bluetooth module
|
||||
3. Implement mode switching through Bluetooth module
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: Firmware-Free Development Issues Guide](../../faq/technical_faq/a316_firmware_dev_faq.md)
|
||||
|
||||
### Configuration Issues
|
||||
|
||||
!!! question "Q4: Incorrect audio parameter configuration"
|
||||
**Problem Description**: Audio playback has noise or no sound
|
||||
|
||||
**Solutions**:
|
||||
1. Check if audio sampling rate configuration is correct
|
||||
2. Verify audio channel count settings
|
||||
3. Confirm volume parameter range
|
||||
4. Check I2S mode configuration
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: XU316 Audio Interface Control Code Examples](Product_Content.md)
|
||||
|
||||
!!! question "Q5: Communication protocol parsing error"
|
||||
**Problem Description**: Received data is not parsed correctly
|
||||
|
||||
**Solutions**:
|
||||
1. Check if frame format definition is correct
|
||||
2. Verify checksum calculation method
|
||||
3. Confirm data length definition
|
||||
4. Check command word enumeration definition
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: XU316 and MCU Communication Protocol Command Macro Definitions](Command_Macros.md) -->
|
||||
|
||||
<!-- ### Performance Issues
|
||||
|
||||
#### Q6: Slow communication speed or packet loss
|
||||
**Problem Description**: Data transmission is slow or data loss occurs
|
||||
|
||||
**Solutions**:
|
||||
1. Optimize ring buffer size
|
||||
2. Check DMA configuration
|
||||
3. Optimize data processing flow
|
||||
4. Add error retransmission mechanism
|
||||
|
||||
**Reference Documentation**: [:material-file-document-outline: XU316 and MCU Communication Protocol Reference](Command_Reference.md)
|
||||
|
||||
#### Q7: System stability issues
|
||||
**Problem Description**: System encounters exceptions after running for a period of time
|
||||
|
||||
**Solutions**:
|
||||
1. Add watchdog mechanism
|
||||
2. Optimize memory management
|
||||
3. Add exception handling
|
||||
4. Perform stress testing
|
||||
|
||||
## Development Recommendations
|
||||
|
||||
### Development Environment Preparation
|
||||
1. Ensure development environment is configured correctly
|
||||
2. Prepare necessary debugging tools
|
||||
3. Familiarize with relevant documentation and APIs
|
||||
|
||||
### Development Process Recommendations
|
||||
1. Follow the step-by-step development sequence
|
||||
2. Perform thorough testing after each step is completed
|
||||
3. Record and resolve encountered issues promptly
|
||||
4. Maintain clean and maintainable code
|
||||
|
||||
### Debugging Tips
|
||||
1. Use log output for debugging
|
||||
2. Use logic analyzer to analyze communication waveforms
|
||||
3. Test module by module
|
||||
4. Build comprehensive test cases
|
||||
|
||||
## Technical Support
|
||||
|
||||
If you encounter problems during development, you can obtain technical support through the following methods:
|
||||
|
||||
- **Documentation Reference**: Consult relevant technical documentation
|
||||
- **FAQ**: Refer to frequently asked questions
|
||||
- **Technical Support**: Contact technical support team -->
|
||||
|
||||
<!-- Structured Data Markup -->
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"headline": "XU316 and MCU Communication Development Guide",
|
||||
"description": "This document provides comprehensive guidance for XU316 and MCU communication development, including development steps, reference documentation, and frequently asked questions.",
|
||||
"keywords": "XU316 development, MCU communication development, audio interface control, communication protocol, development guide, FAQ",
|
||||
"author": {
|
||||
"@type": "Organization",
|
||||
"name": "Phaten Audio"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1,188 +0,0 @@
|
||||
---
|
||||
title: A316免开发固件MCU开发指南
|
||||
description: 本文档提供了XU316与MCU通信开发的完整指导,包括开发步骤、参考文档和常见问题解答,帮助开发者快速实现XU316与MCU的通信功能。
|
||||
keywords: XU316开发, MCU通信开发, 音频接口控制, 通信协议, 开发指导, 常见问题解答
|
||||
---
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
# A316免开发固件MCU开发指南
|
||||
|
||||
## 开发概述
|
||||
|
||||
本文档提供了XU316与MCU通信开发的完整指导,帮助开发者按照正确的顺序实现XU316与MCU的通信功能。开发过程分为以下几个主要步骤,每个步骤都有对应的参考文档和详细说明。
|
||||
|
||||
## 开发步骤
|
||||
|
||||
<div class="grid" markdown>
|
||||
|
||||
=== "第一步:了解基础概念和协议结构"
|
||||
**目标**:理解XU316与MCU通信的基本概念和协议结构
|
||||
|
||||
**参考文档**:[:material-file-document-outline: XU316与MCU通信协议命令宏定义](命令的相关宏.md)
|
||||
|
||||
**学习要点**:
|
||||
|
||||
- 掌握帧格式的基本结构(帧头、命令、数据长度、校验和、帧尾)
|
||||
- 理解各种命令的数据长度定义
|
||||
- 熟悉音频格式枚举和类型定义
|
||||
- 了解命令数据结构体的组成
|
||||
|
||||
=== "第二步:实现基础通信功能"
|
||||
**目标**:实现XU316与MCU的基础通信功能
|
||||
|
||||
**参考文档**:[:material-file-document-outline: XU316与MCU通信协议参考](命令相关.md)
|
||||
|
||||
**开发任务**:
|
||||
|
||||
- 实现环形缓冲区初始化和管理
|
||||
- 实现数据帧的封装和发送
|
||||
- 实现数据帧的接收和解析
|
||||
- 实现CRC32和简单校验和计算
|
||||
- 实现基本的通信协议处理流程
|
||||
|
||||
=== "第三步:配置音频接口和参数"
|
||||
**目标**:配置XU316的音频接口和相关参数
|
||||
|
||||
**参考文档**:[:material-file-document-outline: XU316音频接口控制代码示例](产品内容相关.md)
|
||||
|
||||
**开发任务**:
|
||||
|
||||
- 配置I2S主从模式
|
||||
- 设置音频采样率和位深度
|
||||
- 配置音频通道数量
|
||||
- 设置音量控制参数
|
||||
- 配置各种音频接口(SPDIF、ADAT、DSD等)
|
||||
|
||||
<!-- === "第四步:集成和测试"
|
||||
**目标**:将各个模块集成并进行功能测试
|
||||
|
||||
**开发任务**:
|
||||
- 集成所有通信功能模块
|
||||
- 实现完整的命令处理流程
|
||||
- 进行功能测试和调试
|
||||
- 优化性能和稳定性 -->
|
||||
|
||||
</div>
|
||||
|
||||
## 常见问题解答
|
||||
|
||||
### 通信问题
|
||||
|
||||
!!! question "Q1: XU316通过串口连接PC时无法收发数据"
|
||||
**问题现象**:XU316通过串口连接PC时无法收发数据,逻辑分析仪也抓不到数据
|
||||
|
||||
**解决方案**:
|
||||
1. 检查MCU响应速度,优先配置XU316
|
||||
2. 检查MCU是否给XU316供电
|
||||
3. 确保在XU316发送上电命令前完成初始化
|
||||
|
||||
**参考文档**:[:material-file-document-outline: 免开发固件开发问题指南](../../faq/technical_faq/a316_firmware_dev_faq.md)
|
||||
|
||||
!!! question "Q2: 设备在PC上正常识别,但手机无法识别"
|
||||
**问题现象**:设备在PC上可以正常识别和播放,但连接手机后无法识别设备
|
||||
|
||||
**解决方案**:
|
||||
1. 检查设备供电模式设计
|
||||
2. 修改设备供电部分和放电部分
|
||||
3. 确保设备在手机连接时能正确接收供电
|
||||
|
||||
**参考文档**:[:material-file-document-outline: 免开发固件开发问题指南](../../faq/technical_faq/a316_firmware_dev_faq.md)
|
||||
|
||||
!!! question "Q3: WiFi做从模式时,发送IIS in指令无效"
|
||||
**问题现象**:WiFi设置为从模式,发送IIS in指令后无效果
|
||||
|
||||
**解决方案**:
|
||||
1. 检查固件是否支持WiFi从模式到XMOS主模式的转换
|
||||
2. 将WiFi模块挂载到蓝牙模块上
|
||||
3. 通过蓝牙模块实现模式切换功能
|
||||
|
||||
**参考文档**:[:material-file-document-outline: 免开发固件开发问题指南](../../faq/technical_faq/a316_firmware_dev_faq.md)
|
||||
|
||||
### 配置问题
|
||||
|
||||
!!! question "Q4: 音频参数配置不正确"
|
||||
**问题现象**:音频播放出现杂音或无声
|
||||
|
||||
**解决方案**:
|
||||
1. 检查音频采样率配置是否正确
|
||||
2. 验证音频通道数量设置
|
||||
3. 确认音量参数范围
|
||||
4. 检查I2S模式配置
|
||||
|
||||
**参考文档**:[:material-file-document-outline: XU316音频接口控制代码示例](产品内容相关.md)
|
||||
|
||||
!!! question "Q5: 通信协议解析错误"
|
||||
**问题现象**:接收到的数据解析不正确
|
||||
|
||||
**解决方案**:
|
||||
1. 检查帧格式定义是否正确
|
||||
2. 验证校验和计算方法
|
||||
3. 确认数据长度定义
|
||||
4. 检查命令字枚举定义
|
||||
|
||||
**参考文档**:[:material-file-document-outline: XU316与MCU通信协议命令宏定义](命令的相关宏.md)
|
||||
|
||||
<!-- ### 性能问题
|
||||
|
||||
#### Q6: 通信速度慢或丢包
|
||||
**问题现象**:数据传输速度慢或出现数据丢失
|
||||
|
||||
**解决方案**:
|
||||
1. 优化环形缓冲区大小
|
||||
2. 检查DMA配置
|
||||
3. 优化数据处理流程
|
||||
4. 增加错误重传机制
|
||||
|
||||
**参考文档**:[:material-file-document-outline: XU316与MCU通信协议参考](命令相关.md)
|
||||
|
||||
#### Q7: 系统稳定性问题
|
||||
**问题现象**:系统运行一段时间后出现异常
|
||||
|
||||
**解决方案**:
|
||||
1. 增加看门狗机制
|
||||
2. 优化内存管理
|
||||
3. 增加异常处理
|
||||
4. 进行压力测试
|
||||
|
||||
## 开发建议
|
||||
|
||||
### 开发环境准备
|
||||
1. 确保开发环境配置正确
|
||||
2. 准备必要的调试工具
|
||||
3. 熟悉相关文档和API
|
||||
|
||||
### 开发流程建议
|
||||
1. 按照步骤顺序进行开发
|
||||
2. 每个步骤完成后进行充分测试
|
||||
3. 及时记录和解决遇到的问题
|
||||
4. 保持代码的整洁和可维护性
|
||||
|
||||
### 调试技巧
|
||||
1. 使用日志输出进行调试
|
||||
2. 利用逻辑分析仪分析通信波形
|
||||
3. 分模块进行测试
|
||||
4. 建立完整的测试用例
|
||||
|
||||
## 技术支持
|
||||
|
||||
如果在开发过程中遇到问题,可以通过以下方式获取技术支持:
|
||||
|
||||
- **文档参考**:查看相关技术文档
|
||||
- **常见问题**:参考常见问题解答
|
||||
- **技术支持**:联系技术支持团队 -->
|
||||
|
||||
<!-- 结构化数据标记 -->
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"headline": "XU316与MCU通信开发指导",
|
||||
"description": "本文档提供了XU316与MCU通信开发的完整指导,包括开发步骤、参考文档和常见问题解答。",
|
||||
"keywords": "XU316开发, MCU通信开发, 音频接口控制, 通信协议, 开发指导, 常见问题解答",
|
||||
"author": {
|
||||
"@type": "Organization",
|
||||
"name": "Phaten Audio"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1,295 +0,0 @@
|
||||
---
|
||||
title: Command Macro Definitions for XU316 and MCU Communication Protocol
|
||||
description: This document provides the command macro definitions related to the communication protocol between XU316 and MCU, including frame format, command length, communication protocol, etc., to help developers implement the communication function between XU316 and MCU.
|
||||
keywords: XU316 communication protocol, MCU command macro definitions, audio format definitions, communication frame format, command data structure, audio type definitions
|
||||
---
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
# Command Macro Definitions for XU316 and MCU Communication Protocol
|
||||
|
||||
## Document Instructions
|
||||
|
||||
This document provides the command macro definitions related to the communication protocol between XU316 and MCU, mainly including the following contents:
|
||||
|
||||
1. Definition of communication frame format
|
||||
2. Definition of MCU command data length
|
||||
3. Enumeration of communication protocol command words
|
||||
4. Definitions of audio formats and types
|
||||
5. Definition of command data structure
|
||||
|
||||
These macro definitions and data structures are the basis for the communication between XU316 and MCU. Developers need to correctly understand and use these definitions to implement the communication function.
|
||||
|
||||
## Communication Frame Format
|
||||
|
||||
### Definition of Basic Frame Format
|
||||
```c
|
||||
#define FRAME_HEADER_H 0x55
|
||||
#define FRAME_HEADER_L 0xAA
|
||||
#define PROTOCOL_VERSION 0x01
|
||||
#define PROTOCOL_VERSION_RX 0x03
|
||||
```
|
||||
|
||||
## Definition of Command Data Length
|
||||
|
||||
### XU316 Command Data Length
|
||||
```c
|
||||
#define CMD00_XU316_DATA_LEN 0x11 // Command 0x00: Start-up (Startup options)
|
||||
#define CMD01_XU316_DATA_LEN 0x00 // Command 0x01: Read product information (60-byte firmware information)
|
||||
#define CMD02_XU316_DATA_LEN 0x00 // Command 0x02: Read power-on configuration (14-byte configuration parameters)
|
||||
#define CMD03_XU316_DATA_LEN 0x00 // Command 0x03: Get audio mode (5-byte mode parameters)
|
||||
#define CMD04_XU316_DATA_LEN 0x00 // Command 0x04: Get user configuration (14-byte user settings)
|
||||
#define CMD05_XU316_DATA_LEN 0x15 // Command 0x05: Startup completed (No data field)
|
||||
|
||||
#define CMDF1_XU316_DATA_LEN 0x03 // Command 0xF1: Version number query (3-byte version information)
|
||||
|
||||
#define CMD20_XU316_DATA_LEN 0x14 // Command 0x20: Set volume
|
||||
#define CMD21_XU316_DATA_LEN 0x00 // Command 0x21: Sound effect mode
|
||||
#define CMD22_XU316_DATA_LEN 0x02 // Command 0x22: Device status query
|
||||
#define CMD23_XU316_DATA_LEN 0x00 // Command 0x23: Bluetooth control
|
||||
#define CMD24_XU316_DATA_LEN 0x02 // Command 0x24: Send playback volume
|
||||
#define CMD25_XU316_DATA_LEN 0x01 // Command 0x25: Send recording volume
|
||||
#define CMD27_XU316_DATA_LEN 0x00 // Command 0x27: Special unmute (No data field)
|
||||
#define CMD28_XU316_DATA_LEN 0x01 // Command 0x28: Audio format delay setting (1-byte parameter)
|
||||
|
||||
#define CMD_HID_TRANSPARENT_DATA_LEN 0x39 // Command 0xEE: HID passthrough/OTA upgrade (57 bytes)
|
||||
```
|
||||
|
||||
### MCU Command Data Length
|
||||
```c
|
||||
#define CMD00_MCU_DATA_LEN 0x01 // Command 0x00: Start-up (Startup options)
|
||||
#define CMD01_MCU_DATA_LEN 0x3C // Command 0x01: Read product information (60-byte firmware information)
|
||||
#define CMD02_MCU_DATA_LEN 0x0E // Command 0x02: Read power-on configuration (14-byte configuration parameters)
|
||||
#define CMD03_MCU_DATA_LEN 0x05 // Command 0x03: Get audio mode (5-byte mode parameters)
|
||||
#define CMD04_MCU_DATA_LEN 0x0E // Command 0x04: Get user configuration (14-byte user settings)
|
||||
#define CMD05_MCU_DATA_LEN 0x00 // Command 0x05: Startup completed (No data field)
|
||||
|
||||
#define CMDF1_MCU_DATA_LEN 0x00 // Command 0xF1: Version number query (No data field)
|
||||
|
||||
#define CMD20_MCU_DATA_LEN 0x00 // Command 0x20: Set volume
|
||||
#define CMD21_MCU_DATA_LEN 0x01 // Command 0x21: Sound effect mode
|
||||
#define CMD22_MCU_DATA_LEN 0x00 // Command 0x22: Device status query
|
||||
#define CMD23_MCU_DATA_LEN 0x05 // Command 0x23: Set audio mode
|
||||
#define CMD24_MCU_DATA_LEN 0x00 // Command 0x24: Send playback volume
|
||||
#define CMD25_MCU_DATA_LEN 0x00 // Command 0x25: Send recording volume
|
||||
#define CMD27_MCU_DATA_LEN 0x00 // Command 0x27: Special unmute (No data field)
|
||||
#define CMD28_MCU_DATA_LEN 0x00 // Command 0x28: Audio format delay setting (No data field)
|
||||
|
||||
#define CMD_HID_TRANSPARENT_MCU_DATA_LEN 0x39 // Command 0xEE: HID passthrough/OTA upgrade (57 bytes)
|
||||
```
|
||||
|
||||
## Definition of Communication Protocol Commands
|
||||
|
||||
### Enumeration of Command Words
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
/****** Basic control commands (0x00 - 0x05) ******/
|
||||
CMD_STARTUP = 0x00, // System startup
|
||||
CMD_GET_PRODUCT_INFO = 0x01, // Product information query
|
||||
CMD_GET_BOOT_CFG = 0x02, // Read power-on configuration
|
||||
CMD_GET_AUD_MODE = 0x03, // Get audio mode
|
||||
CMD_GET_USER_CFG = 0x04, // Get user configuration
|
||||
CMD_STARTUP_COMPLETE = 0x05, // Startup completion notification
|
||||
|
||||
CMD_GET_VERSION = 0xF1, // Version number query
|
||||
|
||||
/****** Service control commands (0x20 - 0x2F) ******/
|
||||
CMD_REPORT_STATUS = 0x20, // Status report
|
||||
CMD_MEDIA_CONTROL = 0x21, // Media control
|
||||
CMD_SET_PLAY_FORMAT = 0x22, // Set audio format
|
||||
CMD_SET_AUDIO_MODE = 0x23, // Set audio mode
|
||||
CMD_SET_PLAY_VOL = 0x24, // Set playback volume
|
||||
CMD_SET_REC_VOL = 0x25, // Set recording volume
|
||||
CMD_SPECIAL_UNMUTE = 0x27, // Special unmute
|
||||
CMD_SET_AUDIO_FORMAT_DELAY = 0x28, // Set audio format delay
|
||||
|
||||
CMD_HID_TRANSPARENT = 0xEE, // HID passthrough/OTA upgrade command
|
||||
|
||||
CMD_COUNT = CMD_SET_REC_VOL + 1 // Total number of currently supported commands
|
||||
|
||||
} mcu_command_t;
|
||||
```
|
||||
|
||||
### Enumeration of Startup Options (Bitmask mode)
|
||||
|
||||
!!! note
|
||||
**Enumeration of Startup Options (Bitmask mode)**
|
||||
**Use uint8_t to ensure single-byte storage and support multiple option combinations**
|
||||
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
BOOT_OPTION_USE_DEFAULTS = 0x00, // Use all default configurations
|
||||
BOOT_OPTION_UPDATE_BASIC_INFO = 0x01, // Update basic product information (bit0)
|
||||
BOOT_OPTION_UPDATE_POWER_CFG = 0x02, // Update power-on configuration information (bit1)
|
||||
BOOT_OPTION_UPDATE_OTHER_CFG = 0x04 // Reserved configuration, currently unused (bit2)
|
||||
} boot_option_t;
|
||||
```
|
||||
|
||||
### Enumeration of Media Control
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
MEDIA_KEY_VOLUME_UP = 0x00, // Volume up
|
||||
MEDIA_KEY_VOLUME_DOWN = 0x01, // Volume down
|
||||
MEDIA_KEY_PLAY_PAUSE = 0x02, // Play/Pause
|
||||
MEDIA_KEY_NEXT_TRACK = 0x03, // Next track
|
||||
MEDIA_KEY_PREV_TRACK = 0x04, // Previous track
|
||||
MEDIA_KEY_FAST_FORWARD = 0x05, // Fast forward
|
||||
MEDIA_KEY_REWIND = 0x06, // Rewind
|
||||
MEDIA_KEY_MUTE = 0x07 // Mute toggle
|
||||
|
||||
// Reserved extension bits (0x08 - 0xFF is the reserved area for the protocol)
|
||||
|
||||
} media_control_t;
|
||||
```
|
||||
|
||||
## Definition of Audio Formats
|
||||
|
||||
!!! note
|
||||
**Enumeration of Audio Stream Formats (Compatible with AES67 - 2020 Standard)**
|
||||
**Explicitly specify the underlying type as uint8_t to ensure 1-byte storage**
|
||||
|
||||
### Enumeration of Audio Stream Formats
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
// PCM sampling rate formats (0x00 - 0x10)
|
||||
AUDIO_PCM_44100 = 0x00,
|
||||
AUDIO_PCM_48000 = 0x01,
|
||||
AUDIO_PCM_88200 = 0x02,
|
||||
AUDIO_PCM_96000 = 0x03,
|
||||
AUDIO_PCM_176400 = 0x04,
|
||||
AUDIO_PCM_192000 = 0x05,
|
||||
AUDIO_PCM_352800 = 0x06,
|
||||
AUDIO_PCM_384000 = 0x07,
|
||||
AUDIO_PCM_705600 = 0x08,
|
||||
AUDIO_PCM_768000 = 0x09,
|
||||
AUDIO_PCM_1441200 = 0x0A,
|
||||
AUDIO_PCM_1536000 = 0x0B,
|
||||
AUDIO_PCM_32000 = 0x0C,
|
||||
AUDIO_PCM_64000 = 0x0D,
|
||||
AUDIO_PCM_128000 = 0x0E,
|
||||
AUDIO_PCM_256000 = 0x0F,
|
||||
AUDIO_PCM_512000 = 0x10,
|
||||
|
||||
// DSD formats (0x11 - 0x15)
|
||||
AUDIO_DSD_64 = 0x11,
|
||||
AUDIO_DSD_128 = 0x12,
|
||||
AUDIO_DSD_256 = 0x13,
|
||||
AUDIO_DSD_512 = 0x14,
|
||||
AUDIO_DSD_1024 = 0x15,
|
||||
|
||||
// MQA formats (0x16 - 0x2D)
|
||||
AUDIO_MQA_44100 = 0x16,
|
||||
AUDIO_MQA_88200 = 0x17,
|
||||
AUDIO_MQA_176400 = 0x18,
|
||||
AUDIO_MQA_352800 = 0x19,
|
||||
AUDIO_MQA_705600 = 0x1A,
|
||||
AUDIO_MQA_1411200 = 0x1B,
|
||||
AUDIO_MQA_2822400 = 0x1C,
|
||||
AUDIO_MQA_5644800 = 0x1D,
|
||||
|
||||
// -- Based on 48kHz series --
|
||||
AUDIO_MQA_48000 = 0x1E,
|
||||
AUDIO_MQA_96000 = 0x1F,
|
||||
AUDIO_MQA_192000 = 0x20,
|
||||
AUDIO_MQA_384000 = 0x21,
|
||||
AUDIO_MQA_768000 = 0x22,
|
||||
AUDIO_MQA_1536000 = 0x23,
|
||||
AUDIO_MQA_3072000 = 0x24,
|
||||
AUDIO_MQA_6144000 = 0x25,
|
||||
|
||||
// -- Other base frequency series --
|
||||
AUDIO_MQA_64000 = 0x26,
|
||||
AUDIO_MQA_128000 = 0x27,
|
||||
AUDIO_MQA_256000 = 0x28,
|
||||
AUDIO_MQA_512000 = 0x29,
|
||||
AUDIO_MQA_1024000 = 0x2A,
|
||||
AUDIO_MQA_2048000 = 0x2B,
|
||||
AUDIO_MQA_4096000 = 0x2C,
|
||||
AUDIO_MQA_8192000 = 0x2D,
|
||||
|
||||
// Special reserved value
|
||||
AUDIO_NO_USED = 0xFF
|
||||
|
||||
} audio_format_t;
|
||||
```
|
||||
|
||||
### Enumeration of Audio Types
|
||||
!!! note
|
||||
**Enumeration of Audio Types (Compatible with AES67 - 2020 Standard)**
|
||||
**Explicitly specify the underlying type as uint8_t to ensure 1-byte storage**
|
||||
|
||||
```c
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_TYPE_PCM = 0x00, // PCM standard audio
|
||||
AUDIO_TYPE_RESERVE = 0x01, // Protocol reserved field
|
||||
AUDIO_TYPE_MQA = 0x02, // MQA encoded audio
|
||||
AUDIO_TYPE_MQB = 0x03, // MQB encoded audio (secondary extension)
|
||||
AUDIO_TYPE_MQA_STUDIO = 0x04, // MQA Studio master level
|
||||
AUDIO_TYPE_DSD = 0x05 // Direct Stream Digital
|
||||
|
||||
// 0x06 - 0xFF is reserved for future expansion
|
||||
|
||||
} audio_type_t;
|
||||
```
|
||||
|
||||
## Command Data Structure
|
||||
|
||||
### Definition of Data Structure
|
||||
```c
|
||||
typedef uint8_t byte_pair[2];
|
||||
// Command data structure
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint8_t boot_option; // 0x00: Startup option data
|
||||
// Basic product information
|
||||
uint8_t vid_uac1[2]; // UAC1.0 vendor ID
|
||||
uint8_t pid_uac1[2]; // UAC1.0 product ID
|
||||
uint8_t vid_uac2[2]; // UAC2.0 vendor ID
|
||||
uint8_t pid_uac2[2]; // UAC2.0 product ID
|
||||
uint8_t product_manufacturer[16]; // Manufacturer name
|
||||
uint8_t product_name[16]; // Product name
|
||||
uint8_t product_serial[16]; // Serial number
|
||||
uint8_t basic_info_crc[4]; // CRC32 of basic information
|
||||
// User configuration is the power-on configuration information and also the application running parameters
|
||||
uint8_t startup_status; // Startup status
|
||||
uint8_t audio_mode[5];
|
||||
uint8_t mute_duration[2]; // Mute time (ms)
|
||||
uint8_t mic_volume; // Microphone volume is also the recording volume
|
||||
uint8_t dac_l_volume; // Left channel volume (0 - 255)
|
||||
uint8_t dac_r_volume; // Right channel volume (0 - 255)
|
||||
uint8_t power_cfg_crc[4]; // CRC32 of power-on configuration
|
||||
// Application running parameters
|
||||
uint8_t media_control; // Media control command
|
||||
uint8_t audio_format; // Audio format code
|
||||
uint8_t audio_type; // Audio type code
|
||||
} mcu_data_t;
|
||||
```
|
||||
|
||||
<!-- Structured data markup -->
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"headline": "Command Macro Definitions for XU316 and MCU Communication Protocol",
|
||||
"description": "This document provides the command macro definitions related to the communication protocol between XU316 and MCU, including frame format, command length, communication protocol, etc., to help developers implement the communication function between XU316 and MCU.",
|
||||
"keywords": "XU316 communication protocol, MCU command macro definitions, audio format definitions, communication frame format, command data structure, audio type definitions",
|
||||
"author": {
|
||||
"@type": "Organization",
|
||||
"name": "Phaten Audio"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
## Consultation and Feedback
|
||||
|
||||
<details>
|
||||
<summary>Click to expand consultation feedback form</summary>
|
||||
|
||||
--8<-- "common/customer_form.md"
|
||||
|
||||
</details>
|
||||
@@ -1,423 +0,0 @@
|
||||
---
|
||||
title: XU316 and MCU Communication Protocol Reference
|
||||
description: Detailed description of the communication protocol between XU316 and MCU, including data structures, command formats, and processing flows.
|
||||
keywords: XU316, MCU, communication protocol, command reference
|
||||
hide:
|
||||
-toc
|
||||
---
|
||||
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
|
||||
# XU316 and MCU Communication Protocol Reference
|
||||
|
||||
|
||||
## 1. Basic Data Structures
|
||||
|
||||
|
||||
### 1.1 Ring Buffer
|
||||
|
||||
```c
|
||||
define RINGBUFFERSIZE 256 // Size of the ring buffer used for UART communication caching
|
||||
typedef struct {
|
||||
uint8t buffer[RINGBUFFERSIZE]; // Data storage area
|
||||
volatile uint16t head; // Write position pointer
|
||||
volatile uint16t tail; // Read position pointer
|
||||
volatile uint16t count; // Current data count
|
||||
} ringbuffert;
|
||||
```
|
||||
### 1.2 Audio Mode Definitions
|
||||
|
||||
```c
|
||||
// Audio mode configuration array, each mode contains 5 bytes of configuration data
|
||||
static const uint8t audiomodes[][5] = {
|
||||
{0x00, 0x80, 0xa9, 0x00, 0x01}, // USB-no-mqa mode
|
||||
{0x00, 0x80, 0x01, 0x00, 0x02}, // UAC1 mode
|
||||
{0x10, 0x80, 0x65, 0x10, 0x03}, // COAX mode
|
||||
{0x00, 0x80, 0x65, 0x10, 0x04}, // OPT mode
|
||||
{0x00, 0x80, 0xc5, 0x08, 0x05}, // SPDIF OUT mode
|
||||
{0x00, 0x82, 0xd5, 0x81, 0x06}, // I2S IN mode
|
||||
{0x20, 0x80, 0x65, 0x10, 0x07} // HDMI mode
|
||||
};
|
||||
// Corresponding mode names array
|
||||
static const char *mode_names[] = {
|
||||
"USB-no-mqa",
|
||||
"UAC1",
|
||||
"COAX",
|
||||
"OPT",
|
||||
"SPDIF OUT",
|
||||
"I2S IN",
|
||||
"HDMI"
|
||||
};
|
||||
```
|
||||
## 2. Initialization and Configuration
|
||||
|
||||
|
||||
### 2.1 Device Initialization Information Print
|
||||
|
||||
```c
|
||||
define AUDIOMODECOUNT (sizeof(audiomodes) / sizeof(audiomodes[0]))
|
||||
void printinitinfo(void)
|
||||
{
|
||||
logdata(LOGUSER, "----------Device initialized----------\n");
|
||||
// Print UAC1.0 device information
|
||||
logdata(LOGUSER, "VID1: %02X%02X", mcudata.viduac1[0], mcudata.viduac1[1]);
|
||||
logdata(LOGUSER, "PID1: %02X%02X", mcudata.piduac1[0], mcudata.piduac1[1]);
|
||||
// Print UAC2.0 device information
|
||||
logdata(LOGUSER, "VID2: %02X%02X", mcudata.viduac2[0], mcudata.viduac2[1]);
|
||||
logdata(LOGUSER, "PID2: %02X%02X", mcudata.piduac2[0], mcudata.piduac2[1]);
|
||||
// Print product information
|
||||
logdata(LOGUSER, "Manufacturer: %s", mcudata.productmanufacturer);
|
||||
logdata(LOGUSER, "Name: %s", mcudata.productname);
|
||||
logdata(LOGUSER, "Serial: %s", mcudata.productserial);
|
||||
// Print CRC check information
|
||||
logdata(LOGUSER, "Basic Info CRC: %02X%02X%02X%02X",
|
||||
mcudata.basicinfocrc[0], mcudata.basicinfocrc[1],
|
||||
mcudata.basicinfocrc[2], mcudata.basicinfocrc[3]);
|
||||
logdata(LOGUSER, "Power Config CRC: %02X%02X%02X%02X",
|
||||
mcudata.powercfgcrc[0], mcudata.powercfgcrc[1],
|
||||
mcudata.powercfgcrc[2], mcudata.powercfgcrc[3]);
|
||||
}
|
||||
```
|
||||
### 2.2 Ring Buffer Initialization
|
||||
|
||||
```c
|
||||
void ringbufferinit(void) {
|
||||
uartringbuffer.head = 0; // Initialize write position
|
||||
uartringbuffer.tail = 0; // Initialize read position
|
||||
uartringbuffer.count = 0; // Initialize data count
|
||||
}
|
||||
```
|
||||
### 2.3 Product Information Initialization
|
||||
|
||||
```c
|
||||
void xu316init(void)
|
||||
{
|
||||
// Default audio mode configuration (USB UAC2.0)
|
||||
uint8t audio_mode[5] = {0x00, 0x80, 0xa9, 0x00, 0x01};
|
||||
// Configure UAC1.0 device information
|
||||
mcu_data.vid_uac1[0] = 0x20;
|
||||
mcu_data.vid_uac1[1] = 0xB1; // VID = 0x20B1
|
||||
mcu_data.pid_uac1[0] = 0x00;
|
||||
mcu_data.pid_uac1[1] = 0x17; // PID = 0x0017
|
||||
|
||||
// Configure UAC2.0 device information
|
||||
mcu_data.vid_uac2[0] = 0x20;
|
||||
mcu_data.vid_uac2[1] = 0xB1; // VID = 0x20B1
|
||||
mcu_data.pid_uac2[0] = 0x00;
|
||||
mcu_data.pid_uac2[1] = 0x16; // PID = 0x0016
|
||||
|
||||
// Configure product information
|
||||
memcpy(mcu_data.product_manufacturer, "Phaten", 6);
|
||||
// Set product name
|
||||
memcpy(mcu_data.product_name, "XMOS XU316", 11);
|
||||
// Set product serial number
|
||||
memcpy(mcu_data.product_serial, "123456789ABCDEF", 15);
|
||||
|
||||
// Calculate and store CRC32 checksum for basic information (56 bytes)
|
||||
crc = calculate_crc32(mcu_data.vid_uac1, 56);
|
||||
mcu_data.basic_info_crc[0] = (crc >> 24) & 0xFF;
|
||||
mcu_data.basic_info_crc[1] = (crc >> 16) & 0xFF;
|
||||
mcu_data.basic_info_crc[2] = (crc >> 8) & 0xFF;
|
||||
mcu_data.basic_info_crc[3] = crc & 0xFF;
|
||||
|
||||
|
||||
// Initialize device status and audio configuration
|
||||
mcu_data.startup_status = 0x00;
|
||||
memcpy(&mcu_data.audio_mode, audio_mode, 5);
|
||||
|
||||
// Configure mute duration (400ms)
|
||||
mcu_data.mute_duration[0] = MUTE_DURATION_CONFIG >> 8;
|
||||
mcu_data.mute_duration[1] = MUTE_DURATION_CONFIG;
|
||||
|
||||
// Initialize volume settings
|
||||
mcu_data.mic_volume = MIC_VOLUME_CONFIG;
|
||||
// Initialize left and right channel DAC volumes
|
||||
mcu_data.dac_l_volume = DAC_L_VOLUME_CONFIG;
|
||||
mcu_data.dac_r_volume = DAC_R_VOLUME_CONFIG;
|
||||
|
||||
// Calculate and store CRC32 checksum for power configuration (10 bytes)
|
||||
crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 0x0a);
|
||||
mcu_data.power_cfg_crc[0] = (crc >> 24) & 0xFF;
|
||||
mcu_data.power_cfg_crc[1] = (crc >> 16) & 0xFF;
|
||||
mcu_data.power_cfg_crc[2] = (crc >> 8) & 0xFF;
|
||||
mcu_data.power_cfg_crc[3] = crc & 0xFF;
|
||||
|
||||
|
||||
// Initialize communication buffer
|
||||
ring_buffer_init();
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
// 3. Communication Buffer Operations
|
||||
// 3.1 Ring Buffer Operation Functions
|
||||
|
||||
// Write data to ring buffer
|
||||
|
||||
```c
|
||||
uint8_t ring_buffer_write(uint8_t *data, uint16_t len) {
|
||||
uint16_t i;
|
||||
for(i = 0; i < len; i++) {
|
||||
if(uart_ring_buffer.count >= RING_BUFFER_SIZE) {
|
||||
return 0; // Buffer full, write failed
|
||||
}
|
||||
uart_ring_buffer.buffer[uart_ring_buffer.head] = data[i];
|
||||
uart_ring_buffer.head = (uart_ring_buffer.head + 1) % RING_BUFFER_SIZE;
|
||||
uart_ring_buffer.count++;
|
||||
}
|
||||
return 1; // Write successful
|
||||
}
|
||||
|
||||
// Read data from ring buffer
|
||||
uint8_t ring_buffer_read(uint8_t *data, uint16_t len) {
|
||||
uint16_t i;
|
||||
if(uart_ring_buffer.count < len) {
|
||||
return 0; // Insufficient data
|
||||
}
|
||||
for(i = 0; i < len; i++) {
|
||||
data[i] = uart_ring_buffer.buffer[uart_ring_buffer.tail];
|
||||
uart_ring_buffer.tail = (uart_ring_buffer.tail + 1) % RING_BUFFER_SIZE;
|
||||
uart_ring_buffer.count--;
|
||||
}
|
||||
return 1; // Read successful
|
||||
}
|
||||
|
||||
// Peek data (without moving read pointer)
|
||||
uint8_t ring_buffer_peek(uint8_t *data, uint16_t len) {
|
||||
uint16_t i;
|
||||
uint16_t temp_tail = uart_ring_buffer.tail;
|
||||
for(i = 0; i < len; i++) {
|
||||
data[i] = uart_ring_buffer.buffer[temp_tail];
|
||||
temp_tail = (temp_tail + 1) % RING_BUFFER_SIZE;
|
||||
}
|
||||
return 0; // Peek successful
|
||||
}
|
||||
```
|
||||
|
||||
// 4. Checksum Calculation
|
||||
// 4.1 CRC32 Calculation
|
||||
|
||||
```c
|
||||
uint32_t calculate_crc32(const uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
uint32_t crc = 0xFFFFFFFF;
|
||||
const uint32_t poly = 0xEDB88320; // CRC32 polynomial
|
||||
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
crc ^= buffer[i];
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if (crc & 1) {
|
||||
crc = (crc >> 1) ^ poly;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ~crc; // Return CRC32 checksum value
|
||||
}
|
||||
|
||||
// Calculate simple checksum
|
||||
uint8_t xu316_calc_checksum(uint8_t *data, uint8_t len)
|
||||
{
|
||||
uint8_t sum = 0;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
sum += data[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
```
|
||||
|
||||
// 5. Communication Protocol Processing
|
||||
// 5.1 Frame Validation
|
||||
// Verify frame data integrity
|
||||
|
||||
```c
|
||||
uint8_t uart_frame_check(uint8_t *buf, uint8_t len)
|
||||
{
|
||||
// Check minimum length requirement
|
||||
if (len < 6) { // Header(2) + Version(1) + Command(1) + Length(2) + Checksum(1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Verify frame header
|
||||
if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get data length (big-endian mode)
|
||||
uint16_t data_len = buf[4];
|
||||
|
||||
// Verify data length validity
|
||||
if (data_len > 256 || len < (data_len + 6)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Calculate and verify checksum
|
||||
uint8_t sum = xu316_calc_checksum(buf, data_len + 5);
|
||||
if (sum != buf[data_len + 5]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_TEMP(LOG_RECV, "", buf, len);
|
||||
return 1;
|
||||
}
|
||||
```
|
||||
|
||||
// 5.2 Data Frame Encapsulation
|
||||
|
||||
```c
|
||||
int xu316_pack_frame(uint8_t cmd, uint8_t *data, uint8_t len)
|
||||
{
|
||||
uint8_t tx_data[256] = {0};
|
||||
if (len >= 255) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Build frame header
|
||||
tx_data[0] = FRAME_HEADER_H;
|
||||
tx_data[1] = FRAME_HEADER_L;
|
||||
tx_data[2] = PROTOCOL_VERSION_RX;
|
||||
tx_data[3] = cmd;
|
||||
tx_data[4] = len;
|
||||
|
||||
// Copy data payload
|
||||
if (data && len > 0) {
|
||||
memcpy(tx_data + 5, data, len);
|
||||
}
|
||||
|
||||
// Calculate and add checksum
|
||||
tx_data[len + 5] = xu316_calc_checksum(tx_data, len + 5);
|
||||
len += 6;
|
||||
|
||||
// Send data
|
||||
usart_dma_send(tx_data, len);
|
||||
LOG_INFO("Sending frame: cmd=0x%02X, len=%d", cmd, len);
|
||||
LOG_TEMP(LOG_SEND, "", tx_data, len);
|
||||
return len;
|
||||
}
|
||||
```
|
||||
|
||||
// 5.3 Frame Length Check
|
||||
|
||||
```c
|
||||
int check_frame_length(uint8_t *buf, uint16_t len) {
|
||||
// Verify frame header
|
||||
if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
|
||||
LOG_DEBUG("Frame header check failed %02x %02x", buf[0], buf[1]);
|
||||
return -1;
|
||||
}
|
||||
// Get data length (big-endian mode)
|
||||
int data_len = buf[4];
|
||||
// Return complete frame length
|
||||
return data_len + 6;
|
||||
}
|
||||
|
||||
// 5.4 Data Reception Processing
|
||||
void uart_data_process(void)
|
||||
{
|
||||
uint8_t peek_buffer[8]; // Peek buffer
|
||||
uint8_t process_buffer[256]; // Processing buffer
|
||||
int frame_length;
|
||||
|
||||
while(uart_ring_buffer.count >= 6) { // Need at least 6 bytes to start checking
|
||||
// Peek frame header information
|
||||
ring_buffer_peek(peek_buffer, 6);
|
||||
|
||||
// Debug output
|
||||
for(int i = 0; i < 6; i++) {
|
||||
LOG_DEBUG("peek_buffer[%d]: %02x", i, peek_buffer[i]);
|
||||
}
|
||||
|
||||
// Check frame length
|
||||
frame_length = check_frame_length(peek_buffer, 6);
|
||||
if(frame_length < 0) {
|
||||
// Invalid frame, discard one byte
|
||||
uint8_t dummy;
|
||||
ring_buffer_read(&dummy, 1);
|
||||
LOG_ERROR("Frame length check failed %02x", dummy);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if there's enough data
|
||||
if(uart_ring_buffer.count < frame_length) {
|
||||
LOG_ERROR("Not enough data");
|
||||
break; // Wait for more data
|
||||
}
|
||||
|
||||
// Read and process complete frame
|
||||
if(ring_buffer_read(process_buffer, frame_length)) {
|
||||
uart_data_parse();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
// 5.5 Data Parsing Processing
|
||||
|
||||
```c
|
||||
int uart_data_parse(void)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t cmd = 0;
|
||||
uint16_t data_len = 0;
|
||||
uint16_t rx_len = 0;
|
||||
uint8_t tmp;
|
||||
static uint8_t buffer[256] = {0};
|
||||
rx_len = g_rx_count;
|
||||
|
||||
// Verify frame integrity
|
||||
ret = uart_frame_check((uint8_t *)g_rx_data, rx_len);
|
||||
if (ret == 0) {
|
||||
LOG_ERROR("Frame check failed %d", rx_len);
|
||||
LOG_TEMP(LOG_RECV, "", g_rx_data, rx_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Parse frame information
|
||||
data_len = rx_len - 6;
|
||||
cmd = g_rx_data[3];
|
||||
if (g_rx_data[4] != data_len) {
|
||||
LOG_ERROR("Data length mismatch: expected %d, got %d", g_rx_data[4], data_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_DEBUG("Received frame: cmd=0x%02X, len=%d", cmd, data_len);
|
||||
LOG_VERBOSE("--------------------------------");
|
||||
LOG_VERBOSE("cmd : %02X", cmd);
|
||||
memcpy(buffer, g_rx_data + 5, data_len);
|
||||
|
||||
// Process data according to command type
|
||||
switch (cmd) {
|
||||
case 0x00: // Startup information
|
||||
// ... Process startup information ...
|
||||
break;
|
||||
|
||||
case 0x01: // Basic information
|
||||
// ... Process basic information ...
|
||||
break;
|
||||
|
||||
case 0x02: // Power configuration
|
||||
// ... Process power configuration ...
|
||||
break;
|
||||
|
||||
// ... Other command processing ...
|
||||
|
||||
default:
|
||||
LOG_ERROR("Unknown command: 0x%02X", cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
|
||||
## Consultation and Feedback
|
||||
|
||||
<details>
|
||||
<summary>Click to expand consultation feedback form</summary>
|
||||
|
||||
--8<-- "common/customer_form.md"
|
||||
|
||||
</details>
|
||||
@@ -1,10 +1,8 @@
|
||||
---
|
||||
title: XMOS AI Development SDK and Examples
|
||||
title: XMOS AI SDK Examples
|
||||
hide:
|
||||
-toc
|
||||
---
|
||||
|
||||
--8<-- "common/phaten_xmos_support_img.md"
|
||||
|
||||
|
||||
Development SDK and Examples
|
||||
Reference in New Issue
Block a user