在上一步的基础上添加uart模块。
main函数中: io_cfg.useUart = CyTrue;
在线程1之中添加uart初始化代码,波特率为115200,代码如下:
CyU3PReturnStatus_t
Uart_Init (
void)
{
CyU3PUartConfig_t uartConfig;
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
/* Initialize and configure the UART for logging. */
status = CyU3PUartInit ();
if (status != CY_U3P_SUCCESS)
{
return status;
}
CyU3PMemSet ((uint8_t *)&uartConfig, 0, sizeof (uartConfig));
uartConfig.baudRate = CY_U3P_UART_BAUDRATE_115200;
uartConfig.stopBit = CY_U3P_UART_ONE_STOP_BIT;
uartConfig.parity = CY_U3P_UART_NO_PARITY;
uartConfig.txEnable = CyTrue;
uartConfig.rxEnable = CyFalse;
uartConfig.flowCtrl = CyFalse;
uartConfig.isDma = CyTrue;
status = CyU3PUartSetConfig (&uartConfig, NULL);
if (status != CY_U3P_SUCCESS)
{
return status;
}
/* Set the dma for an inifinity transfer */
status = CyU3PUartTxSetBlockXfer (0xFFFFFFFF);
if (status != CY_U3P_SUCCESS)
{
return status;
}
/* Start the debug module for printing log messages. */
status = CyU3PDebugInit (CY_U3P_LPP_SOCKET_UART_CONS, 8);
/* Disable the message context preamble as we will be using a standard serial console. */
if (status == CY_U3P_SUCCESS)
CyU3PDebugPreamble (CyFalse);
return status;
}
void
Thread1_Entry (
uint32_t input)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
status = Uart_Init();
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "%x: Application failed to initialize. Error code: %d.\n", status);
while (1);
}
for (;;)
{
CyU3PThreadSleep (100);
CyU3PDebugPrint (4, "Thread 1...\n");
}
}
void
Thread2_Entry (
uint32_t input)
{
for (;;)
{
CyU3PThreadSleep (100);
CyU3PDebugPrint (4, "Thread 2...\n");
}
}
两个线程通过串口间隔打印信息。
如下图: