Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
[uart] fix UART line-ending (#9)
Browse files Browse the repository at this point in the history
This commit disables CRLF conversion in ESP_IDF vfs/uart module every
time we write radio frame through UART and enables the conversion for
CLI UART after finishing writing radio frame. This works because the
OpenThread stack is ran in a single task/thread, so there is no CLI
operations when we are reading or writing RADIO UART.
  • Loading branch information
wgtdkp authored Jun 12, 2020
1 parent 8017f11 commit eae32c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 0 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ Connect to the ESP32 board from the Linux host:
make monitor
```

_Note: Dependending on your Linux distribution, the new line characters ('\r', '\n') may cause commands display issues. To have good look of the CLI, Connect the ESP32 board with advanced command `picocom -b 115200 /dev/ttyUSB0 --imap lfcrlf` (install `picocom` with `sudo apt-get install picocom`)._

The CLI application is now in interactive mode and waiting for commands, start the OpenThread stack to verify your setup:

```shell
Expand Down
9 changes: 8 additions & 1 deletion src/spinel_hdlc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,14 @@ otError HdlcInterface::Write(const uint8_t *aFrame, uint16_t aLength)

while (aLength)
{
ssize_t rval = write(mUartFd, aFrame, aLength);
ssize_t rval;

// Configure ESP-IDF UART to never convert "\n" to "\r\n" just before
// writing radio frames through UART. This is a workaround for issue:
// https://github.com/openthread/ot-esp32/issues/5.
esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_LF);
rval = write(mUartFd, aFrame, aLength);
esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);

if (rval > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void platformCliUartInit()
esp_vfs_dev_uart_use_driver(OT_CLI_UART_NUM);

esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_LF);
esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_LF);
esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);

sprintf(uartPath, "/dev/uart/%d", OT_CLI_UART_NUM);
sCliUartFd = open(uartPath, O_RDWR | O_NONBLOCK);
Expand Down

0 comments on commit eae32c5

Please sign in to comment.