0
0
Fork 0

feat(uart): Change baudrate by first ime recv content

This commit is contained in:
windowsair 2022-01-18 22:12:41 +08:00
parent 2c4f61007f
commit 08d5a81383
2 changed files with 35 additions and 4 deletions

View File

@ -66,8 +66,6 @@ There is built-in ipv4 only mDNS server. You can access the device using `dap.lo
|----------------|--------|
| SWCLK | GPIO14 |
| SWDIO | GPIO13 |
| LED\_CONNECTED | GPIO2 |
| LED\_RUNNING | GPIO15 |
| TVCC | 3V3 |
| GND | GND |
@ -83,11 +81,18 @@ There is built-in ipv4 only mDNS server. You can access the device using `dap.lo
| TDO | GPIO16 |
| nTRST \(optional\) | GPIO0\* |
| nRESET | GPIO5 |
| LED\_CONNECTED | GPIO2 |
| LED\_RUNNING | GPIO15 |
| TVCC | 3V3 |
| GND | GND |
--------------
| Other | |
|--------------------|---------------|
| LED\_WIFI_STATUS | GPIO15 |
| Tx | GPIO2 |
| Rx | GPIO3 (U0RXD) |
> Rx and Tx is used for uart bridge, not enabled by default.
----
@ -252,6 +257,18 @@ The flash size of the board can be checked with the esptool.py tool:
esptool.py -p (PORT) flash_id
```
### Uart TCP Bridge
This feature provides a bridge between TCP and Uart:
```
Send data -> TCP -> Uart TX -> external devices
Recv data <- TCP <- Uart Rx <- external devices
```
For performance reasons, this feature is not enabled by default. You can can modify [wifi_configuration.h](main/wifi_configuration.h) to turn it on.
----
## Develop

View File

@ -74,6 +74,7 @@ static uint8_t uart_read_buffer[UART_BUF_SIZE];
// use lwip buffer to write back
static struct netconn *uart_netconn = NULL;
static bool is_conn_valid = false; // lock free
static bool is_first_time_recv = false;
void uart_bridge_close() {
netconn_events events;
@ -215,6 +216,7 @@ void uart_bridge_task() {
uart_netconn = nc_in;
is_conn_valid = true;
is_first_time_recv = true;
} else if (events.nc->state != NETCONN_LISTEN) {
// if (events.nc && events.nc->pcb.tcp)
// tcp_nagle_disable(events.nc->pcb.tcp);
@ -233,6 +235,18 @@ void uart_bridge_task() {
do {
netbuf_data(netbuf, (void *)&buffer, &len_buf);
// write to uart
if (is_first_time_recv) { // change bard rate
if (len_buf > 2 && buffer[len_buf - 2] == '\r' && buffer[len_buf - 1] == '\n') {
buffer[len_buf - 2] = '\0';
int baudrate = atoi(buffer);
if (baudrate > 0 && baudrate < 2000000) {
printf("change bard:%d\r\n", baudrate);
uart_set_baudrate(UART_NUM_0, baudrate);
uart_set_baudrate(UART_NUM_1, baudrate);
}
}
is_first_time_recv = true;
}
uart_write_bytes(UART_NUM_1, (const char *)buffer, len_buf);
} while (netbuf_next(netbuf) >= 0);
netbuf_delete(netbuf);