Can't write to UART when ISR is freed.

Noedel-Man
Posts: 3
Joined: Mon Mar 18, 2019 7:23 pm

Can't write to UART when ISR is freed.

Postby Noedel-Man » Mon Mar 18, 2019 7:53 pm

Hi,

I'm trying to write data to the UART while my custom ISR is active. The ISR gets triggered on incoming UART data. And is able to send the bytes back (echo). This however only works when the tx_buffer in `uart_driver_install()` is 0. But when It's 0 then any `uart_write_bytes()` outside of the ISR don't really send anything (up to 10 bytes per boot). So when I set a tx buffer (512 in the code below) the ISR is not able to echo the data and any `uart_write_bytes()` function outside of the ISR report that all the bytes are written but the tx buffer seem to be never handeled. Please see my code below.

Code: Select all

ESP_LOGI("MAIN", "hello world!");
ESP_LOGD("UART", "START");
    uart_config_t uart_config = {
            .baud_rate = 921600,
            .data_bits = UART_DATA_8_BITS,
            .parity    = UART_PARITY_DISABLE,
            .stop_bits = UART_STOP_BITS_1,
            .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
            .rx_flow_ctrl_thresh = 122
    };
    ESP_ERROR_CHECK(uart_param_config(UART_NUM_0, &uart_config));
    ESP_ERROR_CHECK(uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
    ESP_ERROR_CHECK(uart_driver_install(UART_NUM_0, 1024, 512, 0, NULL, 0));
    ESP_ERROR_CHECK(uart_isr_free(UART_NUM_0));
    ESP_ERROR_CHECK(uart_isr_register(UART_NUM_0, uart_intr_handle, NULL, ESP_INTR_FLAG_IRAM, &handle_console));
    ESP_ERROR_CHECK(uart_enable_rx_intr(UART_NUM_0));

    const char test[] = "CCis is a test string.\n";
    ESP_LOGI("UART", "write:%d",uart_write_bytes(UART_NUM_0, "4444\n", 5));
    ESP_LOGI("UART", "write:%d",uart_write_bytes(UART_NUM_0, "4444\n", 5));
    ESP_LOGI("UART", "write:%d",uart_write_bytes(UART_NUM_0, "55555\n", 6));
    ESP_LOGI("UART", "write:%d",uart_write_bytes(UART_NUM_0, "666666\n", 7));
    ESP_LOGI("UART", "write:%d",uart_write_bytes(UART_NUM_0, test, 23));
    ESP_LOGI("MAIN", "Job done!");
output:

Code: Select all

I (112) MAIN: hello world!
D (112) UART: START
D (112) intr_alloc: Connected src 34 to int 13 (cpu 0)
D (112) intr_alloc: Connected src 34 to int 13 (cpu 0)
I (112) UART: write:5
I (112) UART: write:5
I (112) UART: write:6
I (112) UART: write:7
I (112) UART: write:23
I (112) MAIN: Job done!
When I don't run `uart_isr_free()` and `uart_isr_register()` the code is able to run perfectly fine. I do however require the ISR, is there any solution to my problem?

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

Re: Can't write to UART when ISR is freed.

Postby WiFive » Tue Mar 19, 2019 3:22 am

If you are using a custom isr you should either call the default isr from yours and make sure they do not conflict or duplicate the functions you need from the built in isr in yours or use your own complete driver. You can't just get rid of the default isr that is part of the idf driver.

Noedel-Man
Posts: 3
Joined: Mon Mar 18, 2019 7:23 pm

Re: Can't write to UART when ISR is freed.

Postby Noedel-Man » Tue Mar 19, 2019 8:17 am

WiFive wrote:
Tue Mar 19, 2019 3:22 am
If you are using a custom isr you should either call the default isr from yours and make sure they do not conflict or duplicate the functions you need from the built in isr in yours or use your own complete driver. You can't just get rid of the default isr that is part of the idf driver.
Yea, i thought that something like that would be needed. However I have read the uart documentation and the source code. But can't seem to find the default uart isr :(.


Noedel-Man
Posts: 3
Joined: Mon Mar 18, 2019 7:23 pm

Re: Can't write to UART when ISR is freed.

Postby Noedel-Man » Tue Mar 19, 2019 7:05 pm

Thanks for the info WiFive, I have looked into it some more. But executing a static function from my ISR is not really ideal, because then I have to adjust the ESP-IDF to make it executable from another file. And I really don't want to make changes to the ESP-IDF for me to do something so trivial.
I think that using FreeRTOS `xQueueReceive` function to just watch the rx array and trigger some function when it's changes results in the cleanest solution. Thanks for your help.

Who is online

Users browsing this forum: Google [Bot] and 121 guests