Page 1 of 1

Question to the uart_async_rxtxtasks_main.c example

Posted: Fri Mar 04, 2022 11:09 am
by NRollo
In the "uart_async_rxtxtasks_main.c" UART example I came across these two lines of code:

Code: Select all

 uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);

Code: Select all

xTaskCreate(rx_task, "uart_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL);
Why use the
*2
in these cases, is to "inform" about eg. a 16 bit data configuration?

Thanks!

Re: Question to the uart_async_rxtxtasks_main.c example

Posted: Sat Mar 05, 2022 1:30 am
by ESP_Sprite
I don't know why RX_BUF_SIZE * 2 is there, could be that the UART driver is storing metadata next to each received byte. The 1024*2 probably is because it's a more readable/adjustable way to say '2K of memory' than 2048.

Re: Question to the uart_async_rxtxtasks_main.c example

Posted: Sat Mar 05, 2022 10:38 am
by NRollo
@ESP_Sprite, thanks for the reply.

It just seemed wired to me - because later on in the code the RX buffer is allocated as:

Code: Select all

uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1);
not taking into account that the driver was installed with an RX buffer of size 2048?

Re: Question to the uart_async_rxtxtasks_main.c example

Posted: Sat Mar 05, 2022 4:45 pm
by WiFive
Seems like it is saying we're going to process at most RX_BUF_SIZE data at once and we'll keep a ring buffer of twice that size for overhead.

Re: Question to the uart_async_rxtxtasks_main.c example

Posted: Tue Mar 08, 2022 1:46 pm
by NRollo
@WiFive - You are right, that could be it - make sense at least.

Thanks for chipping in.