cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 HAL UART: TX error, HAL_BUSY (FreeRTOS)

balazs
Associate II
Posted on September 12, 2015 at 00:46

Hi All,

I'm trying to build an application which can receive commands through UART, and can also send messages.

I have created 2 threads using FreeRTOS: one for a continuous RX, and one for a repetitive TX.

The RX task seems to run fine, it captures all the raw data coming in through the UART. However in the other thread when I'm trying to send out a few bytes, I always got a HAL_BUSY flag.

I'm using HAL drivers, and project is generated with MXCube.

I'm not using currently a DMA or even an IT callback, I'm just trying to get things working first with the most simple blocking RX/TX.

I'm wondering if I should synchronise the reader and writer flags - however if the UART peripheral is meant to be full duplex then parallel TX and RX should work.

The whole communication is going to be used to manage an ESP8266 through UART with AT command set. Also looking at the SPWF01.

Please advise, thanks,

Bal

#stm32 #hal #uart #cubemx
1 REPLY 1
balazs
Associate II
Posted on September 12, 2015 at 08:50

Here are the codes:

This is sending the AT command:

void StartDefaultTask(void const * argument)

{

  /* USER CODE BEGIN 5 */

printf(''Starting default task\r\n'');

  /* Infinite loop */

osDelay(2000);

printf(''Starting default TX\r\n'');

for(;;)

  {

HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);

char command[] = ''AT\r\n'';

sendATCommand(&huart1, command, 4);

osDelay(3000);

  }

  /* USER CODE END 5 */ 

}

void sendATCommand(UART_HandleTypeDef * huart, char * command, uint8_t commandLength) {

uint8_t data[commandLength+2];

uint8_t count = 0;

for (count = 0; count < commandLength; count++) {

data[count] = command[count];

}

data[commandLength] = '\r';

data[commandLength+1] = '\n';

HAL_StatusTypeDef halStatus;

halStatus = HAL_UART_Transmit_DMA(huart, data, commandLength+2);

if (halStatus != HAL_OK) {

printf(''EST TX error: %d\r\n'', halStatus);

} else {

printf(''EST TX OK\r\n'');

}

}

And this is the RX thread:

void StartRXTask(void const * argument)

{

  /* USER CODE BEGIN StartRXTask */

  printf(''Starting RX task\r\n'');

const uint8_t BUFFER_READ_SIZE = 10;

const uint16_t BUFFER_INPUT_SIZE = 256;

const uint16_t UART_READ_TO = 1000;

uint8_t inputDataBuffer[BUFFER_INPUT_SIZE];

uint8_t uart2RXData;

uint16_t bufferPointer;

for(;;)

  {

HAL_StatusTypeDef status;

status = HAL_OK;

memset(inputDataBuffer, 0x00, BUFFER_INPUT_SIZE);

bufferPointer = 0;

while (status == HAL_OK && bufferPointer < BUFFER_INPUT_SIZE) {

if (bufferPointer + BUFFER_READ_SIZE <= BUFFER_INPUT_SIZE) {

status = HAL_UART_Receive(&huart1, &(inputDataBuffer[bufferPointer]), BUFFER_READ_SIZE, UART_READ_TO);

} else {

status = HAL_UART_Receive(&huart1, &(inputDataBuffer[bufferPointer]), BUFFER_INPUT_SIZE - bufferPointer, UART_READ_TO);

}

if (status == HAL_OK) {

bufferPointer += BUFFER_READ_SIZE;

}

}

if (bufferPointer > 0) {

printf(''%s'', inputDataBuffer);

}

osDelay(200);

  }

  /* USER CODE END StartRXTask */

}

The result is that I see continuously the following error message on the console:

EST TX error: 2

Where error 2 means HAL_BUSY.

No package is sent out.

Thanks,

Bal