7.5.5 UART 使用指南
S100 MCU 芯片共有3路 Uart,即 Uart4~Uart6。其中 Uart4作为调试控制台使用(MCU0、MCU1共用 调试串口),默认不开启 DMA,默认配置如下:
| 配置项 | uart4 | uart5 | uart6 |
|---|---|---|---|
| 通道标识符 | Uart_Channel0 | Uart_Channel1 | Uart_Channel2 |
| 波特率 | 921600 | 921600 | 921600 |
| 校验位 | 无 | 无 | 无 |
| 停止位 | 1位 | 1位 | 1位 |
| 数据位 | 8位 | 8位 | 8位 |
硬件支持
- MCU 最大可用 UART 数量: 3个
- UART FIFO 深度:64 * 8bit,水位:half full
- 支持4800、9600、38400、115200、921600等常用波特率
- 支持5~8位数据位配置
- 支持奇偶校验配置
- 支持1、1.5、2位停止位配置
- 支持 DMA 模式,DMA 模式下应用层提供的发送和接收 buffer 地址必须是64字节对齐的
S600 MCU 芯片共有4路 Uart,即 Uart8~Uart11。其中 Uart8作为调试控制台使用(MCU0、MCU1共用调试串口),默认不开启 DMA,默认配置如下:
| 配置项 | uart8 | uart9 | uart10 | uart11 |
|---|---|---|---|---|
| 通道标识符 | Uart_Channel0 | Uart_Channel1 | Uart_Channel2 | Uart_Channel3 |
| 波特率 | 921600 | 921600 | 921600 | 921600 |
| 校验位 | 无 | 无 | 无 | 无 |
| 停止位 | 1位 | 1位 | 1位 | 1位 |
| 数据位 | 8位 | 8位 | 8位 | 8位 |
硬件支持
- MCU 最大可用 UART 数量: 4个
- UART FIFO 深度:8byte x 16
- 支持4800、9600、38400 115200、921600等常用波特率
- 支持5~8位数据位配置
- 支持奇偶校验配置
- 支持1、1.5、2位停止位配置
- 支持 DMA 模式,DMA 模式下应用层提供的发送和接收 buffer 地址必须是64字节对齐的
软件架构
- UART APP: Uart 的应用层代码。
- UART Interface: Uart 的接口层代码,提供标准化的 UART 操作接口。
- UART LLD: Uart 的底层驱动代码,直接操作硬件寄存器,实现异步/同步传输、中断处理、FIFO 管理能核心功能。
- UART PBcfg: Uart 的 PB 配置文件,用于外设的配置参数。
- Hardware: UART 硬件。
代码路径
McalCdd/Common/Register/inc/Uart_Register.h:寄存器相关内容McalCdd/Uart/src/Uart.c:驱动代码McalCdd/Uart/src/Uart_Lld.c:底层驱动代码McalCdd/Uart/inc/Uart.h:驱动头文件McalCdd/Uart/inc/Uart_Lld.h:底层驱动头文件Config/McalCdd/gen_xxx/Uart/src/Uart_PBcfg.c:mcu PB 配置文件Config/McalCdd/gen_xxx/Uart/inc/Uart_PBcfg.h:PB 配置头文件Config/McalCdd/gen_xxx/Uart/Uart_Board.h:板级配置文件samples/Uart/src/Uart_Test.c:测试代码
应用 sample
使用示例
S100 开发板将 Uart5引出供用户开发学习使用,PIN 脚位于Main Board板上的MCU Expansion Header(J22)。

提示
当 Uart5 可能用于 Ipc 透传时会与测试用例产生冲突,产生测试失败的现象,可以通过 ipcbox_set_mode debug 命令确认,若 uart 所在行显示 Enable 则代表已经被占用。
D-Robotics:/$ ipcbox_set_mode debug
[0427.611385 0]Module: runcmd, Enable
[0427.611637 0]Module: uart, Enable
[0427.612039 0]Module: spi, Disable
[0427.612440 0]Module: i2c, Disable
若确认被占用,在测试前需要在 mcu 的控制终端输入 ipcbox_set_mode uart 0 命令,释放占用的 Uart5:
D-Robotics:/$ ipcbox_set_mode uart 0
[0774.571200 0]uart processing disabled
[0774.690237 0]IpcBox_uart task resources released and terminating
[0775.071611 0]IpcBox_uart task exited properly
D-Robotics:/$ ipcbox_set_mode debug
[0781.748204 0]Module: runcmd, Enable
[0781.748456 0]Module: uart, Disable
[0781.748868 0]Module: spi, Disable
[0781.749270 0]Module: i2c, Disable
uarttest 1自环测试,注意将 RX 引脚接 TX 引脚
D-Robotics:/$ uarttest 1
[073.515926 0]Async receive ret: 0
Tx: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 41 42 43 44 45
Rx: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 41 42 43 44 45
[073.523782 0]SyncSend & AsyncReceive test pass!
uarttest 2接收数据 这里使用了串口助手(配置:921600波特率8-N-1)向 mcu 发送数据
D-Robotics:/$ uarttest 2
Rx: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 41 42 43 44 45
[0359.598869 0]AsyncSend & ASyncReceive test pass!
uarttest 3发送数据
D-Robotics:/$ uarttest 3
Tx: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 41 42 43 44 45
-
uarttest 4获取 GPS 数据,RDK 内部测试用例。 -
uarttest 5设置波特率为9600
D-Robotics:/$ uarttest 5
[042602.833314 0]Channel 1 Baud: 9600
uarttest 6设置波特率为115200
D-Robotics:/$ uarttest 6
[042617.473286 0]Channel 1 Baud: 115200
S600 开发板将 Uart10和 Uart11引出供用户开发学习使用,PIN 脚位于Main Board板上上的2x UART(MAIN)/2x UART(MCU)(J18)

使用示例
- 语法格式
test_id: 测试用例 ID(必需)bus: UART 总线编号(可选,部分测试用例使用)baudrate: 波特率设置(可选,部分测试用例使用)parity: 校验位设置(可选,部分测试用例使用)stopbit: 停止位设置(可选,部分测试用例使用)databits: 数据位设置(可选,部分测试用例使用)
uarttest <test_id> [bus] [baudrate] [parity] [stopbit] [databits]
uarttest 0 11 921600 0 1 8配置并初始化指定 UART 通道
D-Robotics:/$ uarttest 0 11 921600 0 1 8
[0619.864809 0]g_UartTest updated:
[0619.865186 0] HwChannel: 3
[0619.865522 0] BaudRate: 921600
[0619.866698 0] Parity: 0
[0619.867002 0] StopBit: 1
[0619.867317 0] DataBits: 8
[0619.867654 0]Init Uart 3
[0619.867958 0]set data bit success!
[0619.868377 0]set stop bit success!
[0619.868797 0]UART configuration test passed!
uarttest 1初始化默认 UART 配置
D-Robotics:/$ uarttest 1
[015229.133055 0]Init Uart 3
[015229.133373 0]set data bit success!
[015229.133816 0]set stop bit success!
[015229.134257 0]UART configuration test passed!
uarttest 2接收数据,测试 UART 接收功能 这里使用了串口助手(配置:921600波特率8-N-1)向 mcu 发送数据
D-Robotics:/$ uarttest 2
Rx: 12 32 34 53 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0268.494060 0]AsyncSend & ASyncReceive test pass!
uarttest 3发送数据,测试 UART 发送功能
D-Robotics:/$ uarttest 3
Tx: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 41 42 43 44 45
uarttest 4回环测试,同时测试发送和接收功能
D-Robotics:/$ uarttest 4
Tx: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 41 42 43 44 45
Rx: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 41 42 43 44 45
[0640.943787 0]SyncSend & AsyncReceive test pass!
应用程序接口
void Uart_Init(void)
Description:Subsystem driver initialization function.
Parameters(in)
None
Parameters(inout)
None
Parameters(out)
None
Return value:None
void Uart_Deinit(void)
Description:Subsystem driver deinitialization function.
Parameters(in)
None
Parameters(inout)
None
Parameters(out)
None
Return value:None
Std_ReturnType Uart_BaudSet(uint8 Channel, Uart_BaudrateType Baudrate)
Description:Set baud for an Uart channel.
Parameters(in)
Channel: Uart Channel
Baudrate: Desired baud
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: set success
E_NOT_OK: set failed
Std_ReturnType Uart_BaudGet(uint8 Channel, uint32* Baudrate)
Description:Get baud for an Uart channel.
Parameters(in)
Channel: Uart Channel
Parameters(inout)
None
Parameters(out)
Baudrate: current baud
Return value:Std_ReturnType
E_OK: get success
E_NOT_OK: get failed
Std_ReturnType Uart_SetDatabits(uint8 Channel, uint8 Databits)
Description:Set Databits for an Uart channel.
Parameters(in)
Channel: Uart Channel
Databits:Desired Databits
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: set success
E_NOT_OK: set failed
Std_ReturnType Uart_SetStopbit(uint8 Channel, uint8 Stopbit)
Description:Set Stopbit for an Uart channel.
Parameters(in)
Channel: Uart Channel
Stopbit: Desired Stopbit
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: set success
E_NOT_OK: set failed
Std_ReturnType Uart_SetParity(uint8 Channel, Uart_ParityType CurParity)
Description:Set Parity type for an Uart channel.
Parameters(in)
Channel: Uart Channel
CurParity:Desired Parity
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: set success
E_NOT_OK: set failed
Uart_StatusType Uart_StatusGet(uint8 Channel, uint32* BytesTransfered, Uart_DataDirectionType TransferType)
Description:Gets the status of an Uart channel.
Sync/Async: Synchronous
Parameters(in)
Channel: Uart Channel
BytesTransfered: Byte has transfered
TransferType: Send or Receive
Parameters(inout)
None
Parameters(out)
None
Return value:Uart_StatusType
Uart current state
Std_ReturnType Uart_SyncDataTrans(uint8 Channel, const uint8* Buffer, uint32 BufferSize, uint32 Timeout)
Description:Sends an Uart message blocking.
Sync/Async: Synchronous
Parameters(in)
Channel: Uart Channel
Buffer: pointer to Data buffer
BufferSize: number bytes buffer
Timeout: Timeout value
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: command has been accepted
E_NOT_OK: command has not been accepted
Std_ReturnType Uart_SyncDataReceive(uint8 Channel, const uint8* Buffer, uint32 BufferSize, uint32 Timeout)
Description:Receive an Uart message blocking.
Sync/Async: Synchronous
Parameters(in)
Channel: Uart Channel
Buffer: pointer to Data buffer
ufferSize: number bytes buffer
Timeout: Timeout value
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: command has been accepted
E_NOT_OK: command has not been accepted
Std_ReturnType Uart_AsyncDataTrans(uint8 Channel, const uint8* Buffer, uint32 BufferSize)
Description:Sends an Uart message async.
Sync/Async:Asynchronous
Parameters(in)
Channel: Uart Channel
Buffer: pointer to Data buffer
ufferSize: number bytes buffer
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: command has been accepted
E_NOT_OK: command has not been accepted
Std_ReturnType Uart_AsyncDataReceive(uint8 Channel, const uint8* Buffer, uint32 BufferSize)
Description:Receive an Uart message async.
Sync/Async:Asynchronous
Parameters(in)
Channel: Uart Channel
Buffer: pointer to Data buffer
ufferSize: number bytes buffer
Parameters(inout)
None
Parameters(out)
None
Return value:Std_ReturnType
E_OK: command has been accepted
E_NOT_OK: command has not been accepted
void Uart_GetVersionInfo(Std_VersionInfoType* VersionInfo)
Description:This function Gets the version information of this module
Sync/Async: Synchronous
Parameters(in)
None
Parameters(inout)
None
Parameters(out)
VersionInfo: version information of this module
Return value: None