uart tx interrupt
Posted: Mon Feb 19, 2024 12:03 pm
Hi every one.i need to handle tx uart interrupt and i write this code,but i get error.How can i solve this?my esp idf version is 4.4.6
my code:
and my error:
my code:
- #include "nvs_flash.h"
- #include "nvs.h"
- #include <string.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_netif.h"
- #include "esp_wifi.h"
- #include "esp_event.h"
- #include "esp_log.h"
- #include "driver/gpio.h"
- #include "lwip/err.h"
- #include "lwip/sys.h"
- #include "esp_log.h"
- #include "esp_event.h"
- #include "freertos/event_groups.h"
- #include "sdkconfig.h"
- #include <unistd.h>
- #include <sys/socket.h>
- #include <stdio.h>
- #include <errno.h>
- #include <netdb.h> // struct addrinfo
- #include <arpa/inet.h>
- #include "driver/uart.h"
- #include "esp_system.h"
- #include "esp_intr_alloc.h"
- #include "soc/uart_reg.h"
- #include "soc/uart_struct.h"
- #include <sys/time.h>
- #include "esp_attr.h"
- #include "soc/uart_periph.h"
- #include "soc/uart_struct.h"
- #include "hal/uart_types.h"
- #include "hal/uart_ll.h" //for status iin
- static const char *TAG = "uart_events";
- TaskHandle_t HandleCore0= NULL;
- #define EX_UART_NUM UART_NUM_0
- #define PATTERN_CHR_NUM (3) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
- #define BUF_SIZE (1024)
- static QueueHandle_t uart0_queue;
- //static uart_isr_handle_t *handle_console;
- static intr_handle_t handle_console;
- static uart_obj_t *p_uart[UART_NUM_MAX] = {0};
- bool Send=false;
- static void uart_event_task(void *pvParameters)
- {
- const char a="hello";
- while(1)
- {
- int size=5;
- vTaskDelay(pdMS_TO_TICKS(500));
- if(Send)
- {
- xSemaphoreTake(p_uart[EX_UART_NUM]->tx_mux, (portTickType)portMAX_DELAY);
- p_uart[EX_UART_NUM]->coll_det_flg = false;
- int offset = 0;
- uart_tx_data_t evt;
- evt.tx_data.size = size;
- evt.tx_data.brk_len = 0;
- evt.type = UART_DATA;
- xRingbufferSend(p_uart[EX_UART_NUM]->tx_ring_buf, (void *) &evt, sizeof(uart_tx_data_t), portMAX_DELAY);
- xRingbufferSend(p_uart[EX_UART_NUM]->tx_ring_buf, (void *) (a), size, portMAX_DELAY);
- xSemaphoreGive(p_uart[EX_UART_NUM]->tx_mux);
- Send=false;
- }
- vTaskDelay(pdMS_TO_TICKS(500));
- }
- }
- /*
- * Define UART interrupt subroutine to ackowledge interrupt
- */
- static void IRAM_ATTR uart_intr_handle(void *arg)
- {
- uint16_t rx_fifo_len, status;
- status = UART0.int_st.val; // read UART interrupt Status
- int i=0;
- if(status == UART_INTR_TXFIFO_EMPTY) //if we have tx interrupt
- {
- Send=true;
- uart_clear_intr_status(EX_UART_NUM,UART_INTR_TXFIFO_EMPTY);
- }
- }
- void app_main()
- {
- int ret;
- esp_log_level_set(TAG, ESP_LOG_INFO);
- uart_config_t uart_config = {
- .baud_rate = 115200,
- .data_bits = UART_DATA_8_BITS,
- .parity = UART_PARITY_DISABLE,
- .stop_bits = UART_STOP_BITS_1,
- .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
- };
- ESP_ERROR_CHECK(uart_param_config(EX_UART_NUM, &uart_config));
- esp_log_level_set(TAG, ESP_LOG_INFO);
- ESP_ERROR_CHECK(uart_set_pin(EX_UART_NUM, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE,
- UART_PIN_NO_CHANGE));
- ESP_ERROR_CHECK(uart_driver_install(EX_UART_NUM, BUF_SIZE*2, BUF_SIZE*2,10, uart0_queue, 0));
- ESP_ERROR_CHECK(uart_isr_free(EX_UART_NUM));
- ESP_ERROR_CHECK(uart_isr_register(EX_UART_NUM,uart_intr_handle, NULL, ESP_INTR_FLAG_IRAM, &handle_console));
- ESP_ERROR_CHECK(uart_enable_tx_intr(EX_UART_NUM, 1, 1));
- xTaskCreate(uart_event_task, "uart_event_task", 4096, NULL, 10, NULL);
- }
- Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).
- Core 0 register dump:
- PC : 0x40085c2b PS : 0x00060034 A0 : 0x80085bcc A1 : 0x3ffb1040
- 0x40085c2b: uart_ll_clr_intsts_mask at C:/Users/user/esp/esp-idf/components/hal/esp32/include/hal/uart_ll.h:199
- (inlined by) uart_clear_intr_status at C:/Users/user/esp/esp-idf/components/driver/uart.c:366
- A2 : 0x3ff40000 A3 : 0x00000002 A4 : 0x80091178 A5 : 0x3ffb5810
- A6 : 0x00000003 A7 : 0x3ffb1040 A8 : 0x00060920 A9 : 0x00000000
- A10 : 0xffffffff A11 : 0x3ffb5800 A12 : 0x80084fa0 A13 : 0x3ffb57d0
- A14 : 0x00000000 A15 : 0x00008000 SAR : 0x00000011 EXCCAUSE: 0x00000005
- EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
- Core 0 was running in ISR context:
- EPC1 : 0x400d1f17 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40085c2b
- 0x400d1f17: panic_print_char_uart at C:/Users/user/esp/esp-idf/components/esp_system/panic.c:80
- 0x40085c2b: uart_ll_clr_intsts_mask at C:/Users/user/esp/esp-idf/components/hal/esp32/include/hal/uart_ll.h:199
- (inlined by) uart_clear_intr_status at C:/Users/user/esp/esp-idf/components/driver/uart.c:366
- Backtrace: 0x40085c28:0x3ffb1040 0x40085bc9:0x3ffb1090 0x4008532d:0x3ffb10d0 0x400ebdfd:0x3ffb5850 0x400e0775:0x3ffb5870 0x400df3e5:0x3ffb5890 0x4008fda3:0x3ffb58c0
- 0x40085c28: uart_ll_clr_intsts_mask at C:/Users/user/esp/esp-idf/components/hal/esp32/include/hal/uart_ll.h:199
- (inlined by) uart_clear_intr_status at C:/Users/user/esp/esp-idf/components/driver/uart.c:366
- 0x40085bc9: uart_intr_handle at C:/Users/user/Desktop/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c:116
- 0x4008532d: _xt_lowint1 at C:/Users/user/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1114
- 0x400ebdfd: cpu_ll_waiti at C:/Users/user/esp/esp-idf/components/hal/esp32/include/hal/cpu_ll.h:183
- 0x400e0775: esp_pm_impl_waiti at C:/Users/user/esp/esp-idf/components/esp_pm/pm_impl.c:847
- 0x400df3e5: esp_vApplicationIdleHook at C:/Users/user/esp/esp-idf/components/esp_system/freertos_hooks.c:63
- 0x4008fda3: prvIdleTask at C:/Users/user/esp/esp-idf/components/freertos/tasks.c:3987 (discriminator 1)