Page 2 of 3

Re: DMA example for UART communication for ESP32

Posted: Sat Feb 17, 2018 6:36 pm
by WiFive
If the baud is 115200 then the tout interrupt will come approx 90us after end of frame.

Re: DMA example for UART communication for ESP32

Posted: Mon Feb 19, 2018 6:01 pm
by Ritesh
WiFive wrote:If the baud is 115200 then the tout interrupt will come approx 90us after end of frame.
Hi,

Would you please provide any sample example to receive and handle received data with dynamic size and dynamic interval coming from UART module without DMA?

Because we had tried without DMA just to read data continuesly at every 100 msec and at that time we are facing Task Watchdog Timeout error after some amount of interval.

Hope you will understand my concern regarding this.

Re: DMA example for UART communication for ESP32

Posted: Mon Feb 19, 2018 8:06 pm
by WiFive
If you are using uart_read_bytes with nonzero wait time the task should unblock when tout interrupt pushes bytes to ringbuffer

Re: DMA example for UART communication for ESP32

Posted: Tue Feb 20, 2018 3:22 am
by Ritesh
WiFive wrote:If you are using uart_read_bytes with nonzero wait time the task should unblock when tout interrupt pushes bytes to ringbuffer
Hi,

Thanks for Reply.

I am just little bit confuse here regarding tout interrupt. would you please let me know tout interrupt is same as UART Receive Byte Interrupt or it is different?

Below is out UART configuration code.

Code: Select all

uart_config_t uart_config = {
          .baud_rate = baud_rate,
          .data_bits = UART_DATA_8_BITS,
          .parity = UART_PARITY_DISABLE,
          .stop_bits = UART_STOP_BITS_1,
         .flow_ctrl = hw_flow,
          .rx_flow_ctrl_thresh = 122,
      };
    vTaskDelay(10 / portTICK_RATE_MS);
	uart_status =  uart_param_config(uart_num, &uart_config);

	if(uart_status == ESP_OK)
    {
		DEBUG_LOGI(UART,TAG1,"UART %d configured successfully...",uart_num);
		if(hw_flow==GW_UART_HW_FLOWCTRL_DISABLE)
		{
			uart_status=uart_set_pin(uart_num,tx ,rx,UART_PIN_NO_CHANGE,UART_PIN_NO_CHANGE );
		}
		else if(hw_flow==GW_UART_HW_FLOWCTRL_RTS)
		{
			uart_status=uart_set_pin(uart_num,tx ,rx,rts,UART_PIN_NO_CHANGE );
		}
		else if(hw_flow==GW_UART_HW_FLOWCTRL_CTS)
		{
			uart_status=uart_set_pin(uart_num,tx ,rx,UART_PIN_NO_CHANGE,cts);
		}
		else
		{
			uart_status=uart_set_pin(uart_num,tx ,rx,rts,cts);
		}	
	}
	else
	{
		DEBUG_LOGI(UART,TAG1, "ERROR :  UART%d failed to configure...",uart_num);
		return false;
	}	
	
	if(uart_status==ESP_OK)
	{
		uart_status=uart_driver_install(uart_num, 1024 * 2, 1024*4, 128, &uart_queue[uart_num], 0);
		uart_flush(uart_num);
	}
	else
	{
		DEBUG_LOGE(UART,TAG1,"UART%d set pin error",uart_num);
		return false;
	}

Code: Select all

xTaskCreate(uart0_task, "uart_0", UART_TASK_SIZE, (void*)uart_num, UART_TASK_PRIO, &uart_handler[GW_UART0]);

Code: Select all

void uart0_task(void *arg)
{
	int uart_num = (int)arg;
     uart_event_t event;
	//int len;
     uart_data[uart_num]=(uint8_t*)malloc(PACK_SIZE);
	if(uart_data[uart_num] == NULL)
	{
		DEBUG_LOGE(UART,TAG1,"Memory allocation failed");
		vTaskDelete(NULL);
	}
    uart_ring_buf[uart_num]=(uint8_t*)malloc(RING_BUFF_SIZE);
	if(uart_ring_buf[uart_num]==NULL)
	{
		free(uart_data[uart_num]);
		DEBUG_LOGE(UART,TAG1,"Memory allocation failed");
		vTaskDelete(NULL);
	}
		
	if(rb_init(&rb_uart[uart_num],uart_ring_buf[uart_num],RING_BUFF_SIZE,1)==-1)
	{
		DEBUG_LOGE(UART,TAG1,"Ring buffer init failed");
		free(uart_data[uart_num]);
		free(uart_ring_buf[uart_num]);
		vTaskDelete(NULL);
	}
	DEBUG_LOGI(UART,TAG1,"***UART0 Task Started***");
      for(;;) {
		  #ifdef CONFIG_ESP32
         //Waiting for UART0 event.
          if(xQueueReceive(uart_queue[0], (void * )&event, 100)) {
			int len; // Not used in the code
            //  DEBUG_LOGI(UART,TAG1, "uart[%d] event:", uart_num);
              switch(event.type) {
                 
                  //Event of UART0 receving data
                  case UART_DATA:
						memset(uart_data[uart_num],0,PACK_SIZE);
						len = uart_read_bytes(uart_num, uart_data[uart_num], event.size, 10);
						DEBUG_LOGD(UART,TAG1,"UART0 RECEIVED DATA LENGTH:%d, DATA:'%s'",event.size,uart_data[uart_num]);
						rb_write(&rb_uart[uart_num],uart_data[uart_num],len);	
					  break;
                  //Event of HW FIFO overflow detected
                  case UART_FIFO_OVF:
                      DEBUG_LOGE(UART,TAG1, " uart_0 hw fifo overflow\n");
                      break;
                  //Event of UART ring buffer full
                  case UART_BUFFER_FULL:
                      DEBUG_LOGE(UART,TAG1, " uart_0 ring buffer full\n");
                      break;
                  //Event of UART RX break detected
                  case UART_BREAK:
                      DEBUG_LOGE(UART,TAG1, "uart_0 rx break\n");
                      break;
                  //Event of UART parity check error
                  case UART_PARITY_ERR:
                      DEBUG_LOGE(UART,TAG1, "uart_0 parity error\n");
                      break;
                  //Event of UART frame error
                  case UART_FRAME_ERR:
                      DEBUG_LOGE(UART,TAG1, "uart_0 frame error\n");
                      break;
                  //Others
                  default:
                      DEBUG_LOGI(UART,TAG1, "uart_0 event type: %d\n", event.type);
                      break;
              }
         }
		 #endif
		
		#ifdef CONFIG_NUVOTON
		 vTaskDelay(100 / portTICK_RATE_MS);
		#endif
      }
	free(uart_data[uart_num]);	
	free(uart_ring_buf[uart_num]);

    vTaskDelete(NULL);
}
Let me know if we had did anything wrong which is creating Task Watchdog Trigger Issue while reading data with dynamic interval and size from UART Module attached with ESP32.

Re: DMA example for UART communication for ESP32

Posted: Tue Feb 20, 2018 4:32 am
by WiFive
Yes tout interrupt generates UART_DATA event. Other than changing the wait timeouts not really. But you may want to ask do you need to use event queue and double buffered data or can you just do like this https://github.com/espressif/esp-idf/tr ... _rxtxtasks

Re: DMA example for UART communication for ESP32

Posted: Tue Feb 20, 2018 6:02 pm
by Ritesh
WiFive wrote:Yes tout interrupt generates UART_DATA event. Other than changing the wait timeouts not really. But you may want to ask do you need to use event queue and double buffered data or can you just do like this https://github.com/espressif/esp-idf/tr ... _rxtxtasks
Hi

In short, I just want to read data from UART module over Interrupt continuously with dynamic size and interval.

So, Please suggest me to achieve it either using queue or directly using UART driver API for faster Communication.

Re: DMA example for UART communication for ESP32

Posted: Tue Nov 02, 2021 9:54 am
by JISHNUE
Hello Is anyone update this question? I also facing problem with uart.My requirement is send large amount of data (greater than 120 bytes) through uart2.could you please help me to clearout my doubt? :?:

Re: DMA example for UART communication for ESP32

Posted: Tue Nov 09, 2021 10:21 am
by Ritesh
JISHNUE wrote:
Tue Nov 02, 2021 9:54 am
Hello Is anyone update this question? I also facing problem with uart.My requirement is send large amount of data (greater than 120 bytes) through uart2.could you please help me to clearout my doubt? :?:
Hello,
what kind of issue are you facing while sending large amount of data? can you please send logs with error or more details.

Because we are able to send data with 512 Bytes of chunk without any issue over UART1

Re: DMA example for UART communication for ESP32

Posted: Tue Mar 14, 2023 7:13 am
by mm_1993
Hi
does Anyone Run DMA UART?
I want to read data from UART0 and transfer it using UART1 and vice versa, I'm using ESP32-C3 Module.
I run the uart_events example and uart_async_rxtxtasks example But in the output, I have data loss and missing data.
so I need UART DMA.
can somebody help? or is there any doc?
Regards

Re: DMA example for UART communication for ESP32

Posted: Thu Mar 16, 2023 1:14 am
by MicroController
What bitrate do you need?

Do you already have one dedicated task for sending in each direction, each accepting the data provided by the RX event listener of the respective other UART?