Trying to understand uart_driver_install()

zliudr
Posts: 357
Joined: Thu Oct 03, 2019 5:15 am

Trying to understand uart_driver_install()

Postby zliudr » Mon Oct 21, 2019 2:57 am

I'm used to Arduino serial port and its simplicity but I'm ready to learn the uart driver in esp32.
I'm reading the uart_echo sample code. It is fairly simple but I wonder where I can find explanation of the function uart_driver_install(). I don't understand how to use it except for how it is used in the sample. I want to be able to uninstall uart, use new TX and RX pins and install driver on those new pins. I need to know the right way to do it. I guess I could find the definition of the function but if someone knows where to find it, it would be great.

Again, great platform to be learning. I like the xTask thing although I don't know where to find the reference to xTaskCreate().

Thank you!


zliudr
Posts: 357
Joined: Thu Oct 03, 2019 5:15 am

Re: Trying to understand uart_driver_install()

Postby zliudr » Mon Oct 21, 2019 5:00 am

Thanks. I'll print out all 1600 pages of the document tomorrow.

Regarding the page you provided:

Code: Select all

// Setup UART buffered IO with event queue
const int uart_buffer_size = (1024 * 2);
QueueHandle_t uart_queue;
// Install UART driver using an event queue here
ESP_ERROR_CHECK(uart_driver_install(UART_NUM_2, uart_buffer_size, \
                                        uart_buffer_size, 10, &uart_queue, 0));
Does this mean the rx and tx buffers will be each of the size uart_buffer_size? The install call allocates the buffer itself? 2KB for each seems pretty large. What is the meaning of 10 and 0?

I didn't realize some functions are clickable in the doc so I've got some better idea now.

The uart_echo sample code has this:

Code: Select all

uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0);
So there is BUF_SIZE*2 rx buffer but no tx buffer or is there no rx buffer? What is the consequence of not having one of the buffers? Will the call to read or write wait until done?

I didn't realize some functions are clickable in the doc so I've got some better idea now.

I'm looking for the meaning and the consequence of each parameter in uart_driver_install(). Just a 10 is not good enough as an explanation. I'm slightly better now.

zliudr
Posts: 357
Joined: Thu Oct 03, 2019 5:15 am

Re: Trying to understand uart_driver_install()

Postby zliudr » Tue Oct 22, 2019 4:01 pm

Regarding the uart_driver_install() call, where does the function allocate the buffers from, the caller task stack or somewhere else independent from the caller's task stack? I currently only have 1024 bytes for caller stack. Maybe that is causing the kernel panic etc?

Thank you!

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Trying to understand uart_driver_install()

Postby WiFive » Wed Oct 23, 2019 2:15 am

Global heap memory

zliudr
Posts: 357
Joined: Thu Oct 03, 2019 5:15 am

Re: Trying to understand uart_driver_install()

Postby zliudr » Wed Oct 23, 2019 3:25 am

Thanks. That helps.

Who is online

Users browsing this forum: No registered users and 138 guests