UART read fails after a few attempts

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
5 posts / 0 new
Last post
ainwood87
Offline
Last seen:2年6个月前
加入:2017-08-21 21:10
UART read fails after a few attempts

我想创建一个任务响应sible for reading from serial using UART1.I find that after calling ad_uart_read a few times, eventually ad_uart_read() will block forever. I am using a USB to TTL adapter, which I can probe using a logic analyzer, so I know that the messages are going out on the wire, but ad_uart_read() still does not return.

By adding prints, I know that ad_uart_read() is blocking on this line:
OS_EVENT_WAIT(device->bus_data->event_read, timeout);

Some details about how I'm configuring the UARTs (UART1 for communication, UART2 for printf)

in main.c:
static const gpio_config gpio_cfg[] = {
HW_GPIO_PINCONFIG(HW_GPIO_PORT_1, HW_GPIO_PIN_3, OUTPUT, UART2_TX, false),
HW_GPIO_PINCONFIG(HW_GPIO_PORT_2, HW_GPIO_PIN_3, INPUT, UART2_RX, false),
HW_GPIO_PINCONFIG(HW_GPIO_PORT_3,HW_GPIO_PIN_2, OUTPUT, UART_TX, false),
HW_GPIO_PINCONFIG(HW_GPIO_PORT_3, HW_GPIO_PIN_3, INPUT, UART_RX, false),
HW_GPIO_PINCONFIG_END
};

..
hw_gpio_configure(gpio_cfg);

in custom_config_qspi.h:

#define CONFIG_RETARGET
#define CONFIG_RETARGET_UART HW_UART2

#define dg_configUART_ADAPTER (1)

//#define dg_configUART_SOFTWARE_FIFO (1)
#define dg_configUART_RX_CIRCULAR_DMA (1)

#define dg_configUART1_RX_CIRCULAR_DMA_BUF_SIZE (100)
//#定义dg_configuart1_software_fifo_size(100)

Note that I've tried switching between using software FIFO and DMA and I get the same behaviour either way.

in platform_device.h:
UART_BUS(UART1, SERIAL1, HW_UART_BAUDRATE_19200, HW_UART_DATABITS_8, HW_UART_PARITY_NONE,
HW_UART_STOPBITS_1, 1, 1, HW_DMA_CHANNEL_1, HW_DMA_CHANNEL_0, 0, 0)

UART_BUS(UART2, SERIAL2, HW_UART_BAUDRATE_115200, HW_UART_DATABITS_8, HW_UART_PARITY_NONE,
HW_UART_STOPBITS_1, 0, 1, HW_DMA_CHANNEL_3, HW_DMA_CHANNEL_2, 0, 0)

in mytask.c:

ad_uart_init();

uart_device uart = ad_uart_open(SERIAL1);

for (;;) {
int len = ad_uart_read()
...
}

Keywords:
Device:
PM_Dialog
Offline
Last seen:3 hours 9 min ago
Staff
加入:2018-02-08 11:03
Hi ainwood87,

Hi ainwood87,

The problem that I believe you experience is caused by the use of extended sleep. When you are using the extended sleep, the device will not wake up automatically by the traffic on the UART Rx pin. Such function to wake up from sleep is supported only from UART2 using the CTS pin. UART1 does not support any flow control, so there is no way to wake from sleep without using bits. We replicate your problem by testing your code that you have posted, and we conclude that the reason why you code halts is a sleep configuration issue. It is strongly recommended to change the buffer size in order to be one less than dma circular buffer size.

Suggestions:

  1. When using UART, disable the extended sleep mode. UART does not work in power saved.
  2. Please, use UART2 for you data and use CTS for wake up
  3. 有一个单独的引脚以唤醒您的系统,以便在通过UART发送数据之前唤醒您的设备。

Thanks, PM_Dialog

ainwood87
Offline
Last seen:2年6个月前
加入:2017-08-21 21:10
Hi Dialog,

Hi Dialog,

Can you explain how to configure the board to use the CTS pin? Is that something I need to assign manually to a GPIO pin, or is it built into the USB connection?

ainwood87
Offline
Last seen:2年6个月前
加入:2017-08-21 21:10
Hi Dialog,

Hi Dialog,

You mentioned that the FIFO size should be 1 less than the DMA circular buffer size. However, when I try to compile with both options enabled, I get the following warning:
#error uart2无法配置为同时使用软件FIFO和圆形DMA FIFO

This seems to contradict your recommendation.

PM_Dialog
Offline
Last seen:3 hours 9 min ago
Staff
加入:2018-02-08 11:03
Hi ainwood87,

Hi ainwood87,

According to the DA14680 datasheet, the UART2 implements hardware flow control with a FIFO of 16 bytes depth, so you are not able to configure it as software UART. Only UART1 supports software implementation. For a full UART functionality, you should add jumpers between RTS – P1_5 and CTS – P1_6 into the header (J15). It is strongly recommended to have a look into5.3.4 HCI / UART header (J15)paragraph of the«DA1468x/DA1510x PRODevelopment kit UM-B-060»user manual document. Be aware that the CTS pin is multiplexed with K1 push button through jumper J8. Then, you should configure CTS pin in the periph_init() function as follow:

hw_gpio_configure_pin(HW_GPIO_PORT_1,HW_GPIO_PIN_6,HW_GPIO_MODE_INPUT_PULLUP,

HW_GPIO_FUNC_UART2_CTSN, 1);

Thanks, PM_Dialog