cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS + UART + DMA stops working on second debug session

SYako
Associate III

On first debug session everything works fine. However on second and beyond session dma stop working.

Hardware: custom stm32l4p5cet based board, original ft232 uart bridge, stlink v2.

CubeMX settings: UART with DMA on RX and TX (RX in circular mode), Global interrupt enabled with priority 5.

Code:

Start DMA returning HAL_OK:

HAL_UART_Receive_DMA(&huart2, serial_data, 128);

Task to put data from uart in to message queue:

static uint16_t tail;
 
void serial_input_task(void *arg)
{
	for (;;) {
		uint16_t len = 128 - huart2.hdmarx->Instance->CNDTR;
		while (len - tail) {
			uint8_t tmp = serial_data[tail];
			osMessageQueuePut(at_input_queue, (const void*) &tmp, 0, 0);
			tail++;
			if (tail >= 128)
				tail = 0;
		}
		osDelay(1);
	}
}

task to read message queue and process data:

static uint8_t at_serial_input[128];
 
void input_task(void *arg)
{
	uint32_t count;
	while (1) {
		count = osMessageQueueGetCount(input_queue);
		for (uint32_t i = 0; i < count; i++)
			osMessageQueueGet(input_queue,(void*) &serial_input[i], 0, 0);
		if (count)
			input(serial_input, count); //handle raw data from uart
	}
}

function input never get called, for testing purposes I added RxCpltCallback to light up led. Never get called or light up, even in first debug session.

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
}

1 ACCEPTED SOLUTION

Accepted Solutions

Hi, after deep analysis, error was caused by external device that was connected to uart, and generated errors on RX line.

View solution in original post

2 REPLIES 2

Hello @SYako​,

Could you please share you project for further check ?

Thanks in advance.

Walid.

Hi, after deep analysis, error was caused by external device that was connected to uart, and generated errors on RX line.