SDK baud rate calibration function¶
1. Functional characteristics¶
- Only when the SDK is configured to use an internal crystal oscillator, the baud rate calibration function can be enabled.
- Enable baud rate calibration, and at the same time, enable the serial port protocol of the SDK. A command will be sent regularly to the communication client (hereinafter referred to as the client). The communication client will reply to the same command within the timeout period to achieve real-time baud rate calibration. The voice module protocols V1 (first generation protocol) and V2 (second generation protocol) included in the SDK all have this function.
- The interval time of baud rate calibration frequency can be configured, and the timeout time for waiting for reply can also be configured.
- The protocol command of baud rate calibration can be modified and customized.
- This function is only supported in 3rd generation SDK V1.5.7 and above.
2. SDK configuration and usage¶
2.1 Enable internal RC function¶
Configure to use internal RC in “user_config. h”
#define USE_ EXTERNAL_ CRYSTAL_ OSC 0//0: use internal RC, 1. use external crystal oscillator
2.2 Enable baud rate calibration function¶
In “user_config. h”, configure to enable the baud rate calibration function, the sending interval, and the maximum waiting time for receiving replies
#define UART_ BAUDRATE_ CALIBRATE 1//Enable the baud rate calibration function
#define BAUDRATE_ SYNC_ PERIOD 180000//Baud rate synchronization cycle, in milliseconds (transmission interval)
#define BAUD_ CALIBRATE_ MAX_ WAIT_ TIME 400//The timeout time for waiting for the feedback packet, in milliseconds (the time for receiving the reply)
**Note* *: The above configuration means that a baud rate calibration command will be sent to the communication client every 180000 milliseconds (180 seconds). The communication client needs to reply within 400 milliseconds. If the timeout occurs, the calibration fails.
**Note * *: When configuring as described above, if the client wants to receive a completely correct power-on notification protocol, please be sure to reply to the calibration feedback package within 400 milliseconds. The time to wait for a feedback packet should be less than 400ms as many calibration requests will be initiated each time to avoid excessive calibration time.
2.3 Setting Synchronization Commands (SDK comes with its own serial port protocol)¶
If you use the communication protocol that comes with the SDK and have implemented the command sending and receiving functions, you only need to add or modify in the “Command Word Information Table” ($SDK/projects/ofline_asr_sample/firmware/user_file/cmd_info/[60000] xxx. xls), as shown below:
The SDK’s built-in serial port protocol will send this command as a voice recognition result command as a baud rate synchronization command. When the client parses this command word ID, it needs to return the original command data without any modification. If you use the SDK’s built-in serial port protocol, the baud rate calibration function has been configured. If you use a custom serial port protocol, please continue to read.
2.4 Modification related to user-defined serial port protocol¶
2.4.1 Module Initialization¶
When initializing the user-defined protocol, you need to call the baud rate calibration module initialization function:
//UARTx: serial port number.
//Baudrate: the default baud rate.
//send_ sync_ req_ Func: The synchronization command sends the callback function pointer, and the baud rate calibration module sends the synchronization command by calling this function pointer.
void baudrate_ calibrate_ init(UART_TypeDef *UARTx, uint32_t baudrate, send_sync_req_func_t send_sync_req_func);
2.4.2 Implement synchronous command sending interface¶
Implement the synchronous command sending interface, so that it can be passed to the baud rate calibration module as the last parameter of the “baudrate_calibrate_init” function. The baud rate calibration module sends the synchronization command by calling this function pointer. Because the generation, sending and receiving of synchronization commands are completed by the serial port protocol module, it can be flexibly customized. You can design synchronization commands and write them in code in the form of constants.
2.4.3 Add synchronous command processing in the receiving command processing logic¶
In baud rate calibration, the serial port protocol module is still required to receive synchronization commands. When the baud rate synchronization command is received, the baud rate calibration module is notified by calling the interface:
void baudrate_ calibrate_ set_ ack();
So far, the baud wave rate calibration function has been configured.