先说问题
Neptune开放版,调试Demo只实现了UART0可以输出,而且是和Type-C一个接口,UART1~4都没有输出。
我的项目来源
通过VScode的DevEco Device Tool插件,创建项目向导选择Neptune开发板的iot工程,里面有Demo。
![cke_7448.png](//file.elecfans.com/web2/M00/7E/B4/poYBAGOG6v2AEJfJAABOTxH9ycE062.png)
![cke_10274.png](//file.elecfans.com/web2/M00/7F/40/pYYBAGOG6wuAXdYuAAAu5NuOuGw351.png)
其中一个案例的代码
#include
#include
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "wifiiot_uart.h"
#include "wifiiot_uart_ex.h"
#include "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
#define UART_TASK_STACK_SIZE 512
#define UART_TASK_PRIO 25
#define TEST_UART_SIZE 8
#define INIT_BAUD_RATE 115200
#define TEST_BUF_SIZE 2048
#define UART_PORT WIFI_IOT_UART_IDX_1
unsigned char uart1ReadBuff[2048] = {0};
static void *UartTask(const char *arg)
{
(void)arg;
unsigned int ret;
int len;
unsigned char uartWriteBuff[] = "hello uart!";
WifiIotUartAttribute uartAttr;
uartAttr.baudRate = INIT_BAUD_RATE,
uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8;
uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1;
uartAttr.parity = WIFI_IOT_UART_PARITY_NONE;
uartAttr.pad ='M';
WifiIotUartExtraAttr extraAttr;
(void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr));
extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT;
extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS;
extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT;
extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK;
extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK;
extraAttr.txBufSize = TEST_BUF_SIZE;
extraAttr.rxBufSize = TEST_BUF_SIZE;
extraAttr.txUseDma = WIFI_IOT_UART_USE_DMA;
extraAttr.rxUseDma = WIFI_IOT_UART_USE_DMA;
ret = UartDeinit(UART_PORT);
ret = UartInit(UART_PORT, &uartAttr, &extraAttr);
while (1) {
len = UartWrite(UART_PORT, uartWriteBuff, sizeof(uartWriteBuff));
osDelay(400);
len = UartRead(UART_PORT, uart1ReadBuff, sizeof(uart1ReadBuff));
printf("UART 1 Read Len %d \n", len);
if(len > 0)
UartWrite(UART_PORT, uart1ReadBuff, len);
}
return NULL;
}
static void UartExampleEntry(void)
{
osThreadAttr_t attr;
attr.name = "UartTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = UART_TASK_STACK_SIZE;
attr.priority = UART_TASK_PRIO;
printf("[UartExample] create UartTask!\n");
if (osThreadNew((osThreadFunc_t)UartTask, NULL, &attr) == NULL) {
printf("[UartExample] Falied to create UartTask!\n");
}
}
SYS_RUN(UartExampleEntry);
代码都是一样的,只有UART0正常,其他的都输出不了,
![0713b62bd5c5f2c0e93ffd1445ed8b6.png](//file.elecfans.com/web2/M00/7F/40/pYYBAGOG64SAEFJ5AAAMPiKwqCI220.png)
![68d19abbd4d63ff52f4d6ad758f2ed4.jpg](//file.elecfans.com/web2/M00/7F/40/pYYBAGOG65OAEXs9AALoQ78NKcM885.jpg)
把几个UART都 Rx Tx进行短接。 printf("UART 1 Read Len %d \n", len);打印出来的一直是0