Unverified Commit 670bf2d6 authored by Johny Mattsson's avatar Johny Mattsson Committed by GitHub
Browse files

Make UART buffer sizes configurable. (#3500)

Also corrects assumption about number of UARTs available.
parent 8b1ef35b
...@@ -64,4 +64,82 @@ menu "NodeMCU platform config" ...@@ -64,4 +64,82 @@ menu "NodeMCU platform config"
Embedded LUA Flash Store size. Set to zero to use an LFS partition Embedded LUA Flash Store size. Set to zero to use an LFS partition
instead of embedding the LFS within the NodeMCU firmware itself. instead of embedding the LFS within the NodeMCU firmware itself.
menu "UART buffer size configuration"
config NODEMCU_UART_AT_LEAST_2
bool
default y if IDF_TARGET_ESP32
default y if IDF_TARGET_ESP32S2
default y if IDF_TARGET_ESP32S3
default y if IDF_TARGET_ESP32C3
default y if IDF_TARGET_ESP32H2
config NODEMCU_UART_AT_LEAST_3
bool
default y if IDF_TARGET_ESP32
default y if IDF_TARGET_ESP32S3
config NODEMCU_UART_DRIVER_BUF_SIZE_RX0
int "RX buffer size for UART0"
default 512
help
The rx buffer size to use for UART0.
This is a buffer used to/from the UART ISR. For high-speed scenarios,
it can be very helpful to increase the rx size. The ISR trying
to write to a full rx buffer results in lost data and an error
event posted.
config NODEMCU_UART_DRIVER_BUF_SIZE_TX0
int "TX buffer size for UART0"
default 512
help
The tx buffer size to use for UART0.
This is a buffer used to/from the UART ISR. In some scenarios it
can be helpful to increase the tx size. Writing to a full tx buffer
blocks the calling RTOS task.
config NODEMCU_UART_DRIVER_BUF_SIZE_RX1
int "RX buffer size for UART1"
depends on NODEMCU_UART_AT_LEAST_2
default 512
help
The rx buffer size to use for UART1.
This is a buffer used to/from the UART ISR. For high-speed scenarios,
it can be very helpful to increase the rx size. The ISR trying
to write to a full rx buffer results in lost data and an error
event posted.
config NODEMCU_UART_DRIVER_BUF_SIZE_TX1
int "TX buffer size for UART1"
depends on NODEMCU_UART_AT_LEAST_2
default 512
help
The tx buffer size to use for UART1.
This is a buffer used to/from the UART ISR. In some scenarios it
can be helpful to increase the tx size. Writing to a full tx buffer
blocks the calling RTOS task.
config NODEMCU_UART_DRIVER_BUF_SIZE_RX2
int "RX buffer size for UART2"
depends on NODEMCU_UART_AT_LEAST_3
default 512
help
The rx buffer size to use for UART2.
This is a buffer used to/from the UART ISR. For high-speed scenarios,
it can be very helpful to increase the rx size. The ISR trying
to write to a full rx buffer results in lost data and an error
event posted.
config NODEMCU_UART_DRIVER_BUF_SIZE_TX2
int "TX buffer size for UART2"
depends on NODEMCU_UART_AT_LEAST_3
default 512
help
The tx buffer size to use for UART2.
This is a buffer used to/from the UART ISR. In some scenarios it
can be helpful to increase the tx size. Writing to a full tx buffer
blocks the calling RTOS task.
endmenu
endmenu endmenu
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_spi_flash.h" #include "esp_spi_flash.h"
#define NUM_UART 3 #define NUM_UART SOC_UART_NUM
#define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE #define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE
#define INTERNAL_FLASH_WRITE_UNIT_SIZE 4 #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
......
...@@ -48,8 +48,6 @@ int platform_gpio_output_exists( unsigned gpio ); ...@@ -48,8 +48,6 @@ int platform_gpio_output_exists( unsigned gpio );
// ***************************************************************************** // *****************************************************************************
// UART subsection // UART subsection
#define UART_BUFFER_SIZE 512
enum enum
{ {
PLATFORM_UART_MODE_UART = 0x0, PLATFORM_UART_MODE_UART = 0x0,
......
...@@ -34,6 +34,24 @@ int platform_gpio_output_exists( unsigned gpio ) { return GPIO_IS_VALID_OUTPUT_G ...@@ -34,6 +34,24 @@ int platform_gpio_output_exists( unsigned gpio ) { return GPIO_IS_VALID_OUTPUT_G
#define PLATFORM_UART_EVENT_RX (UART_EVENT_MAX + 3) #define PLATFORM_UART_EVENT_RX (UART_EVENT_MAX + 3)
#define PLATFORM_UART_EVENT_BREAK (UART_EVENT_MAX + 4) #define PLATFORM_UART_EVENT_BREAK (UART_EVENT_MAX + 4)
typedef struct {
unsigned rx_buf_sz;
unsigned tx_buf_sz;
} uart_buf_sz_cfg_t;
static const uart_buf_sz_cfg_t uart_buf_sz_cfg[] = {
{ .rx_buf_sz = CONFIG_NODEMCU_UART_DRIVER_BUF_SIZE_RX0 +0,
.tx_buf_sz = CONFIG_NODEMCU_UART_DRIVER_BUF_SIZE_TX0 +0 },
#if NUM_UART > 1
{ .rx_buf_sz = CONFIG_NODEMCU_UART_DRIVER_BUF_SIZE_RX1 +0,
.tx_buf_sz = CONFIG_NODEMCU_UART_DRIVER_BUF_SIZE_TX1 +0 },
#endif
#if NUM_UART > 2
{ .rx_buf_sz = CONFIG_NODEMCU_UART_DRIVER_BUF_SIZE_RX2 +0,
.tx_buf_sz = CONFIG_NODEMCU_UART_DRIVER_BUF_SIZE_TX2 +0 },
#endif
};
typedef struct { typedef struct {
unsigned id; unsigned id;
int type; int type;
...@@ -295,7 +313,7 @@ int platform_uart_start( unsigned id ) ...@@ -295,7 +313,7 @@ int platform_uart_start( unsigned id )
uart_status_t *us = & uart_status[id]; uart_status_t *us = & uart_status[id];
esp_err_t ret = uart_driver_install(id, UART_BUFFER_SIZE, UART_BUFFER_SIZE, 3, & us->queue, 0); esp_err_t ret = uart_driver_install(id, uart_buf_sz_cfg[id].rx_buf_sz, uart_buf_sz_cfg[id].tx_buf_sz, 3, & us->queue, 0);
if(ret != ESP_OK) { if(ret != ESP_OK) {
return -1; return -1;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment