cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX's UART can not receive and transmit at the same time

hgyxbll
Associate II
Posted on May 04, 2017 at 08:47

CubeMX V1.12.0

I write below code to receive one bye and one bye:

HAL_UART_Receive_IT(&huart1, (T_U8*)&g_uart_receive_byte, 1);

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

if(huart == &huart1)

{

//get the byte

DrvUartOnReceiveOneByteAtInterupt(g_uart_receive_byte);

//receive next byte

HAL_UART_Receive_IT(huart, &g_uart_receive_byte, 1);

}

}

 and in the main I use HAL_UART_Transmit to transmit data.

but when HAL_UART_Transmit is doing, a new buffer is received and 

HAL_UART_RxCpltCallback will be called, then HAL_UART_Receive_IT will be fail because HAL_UART_Transmit has call __HAL_LOCK(huart). 

I think HAL_UART_Transmit and  

HAL_UART_Receive_IT should not use the same lock, they should can use at same time.

Is it right?

#cubemx #uart
2 REPLIES 2
Khouloud GARSI
Lead II
Posted on May 04, 2017 at 11:42

Hi

ll.hgyxb

‌,

  • First of all, I advise you to use the last version of CubeMX 4.1.
  • Also, I'd highly recommend you to refer to UART examples under your related firmware package.

There is examples describing UART transmission (transmit/receive) by using an interrupt: data buffers transmission/reception are done simultaneously.

Khouloud.

Posted on May 08, 2017 at 05:11

Sorry, there is a mistake, the version is STM32Cube_FW_F4_V1.12.0 and 

CubeMX 4.18.0 I used.

The example is use a flag at interrupt to notify the receive event and check the flag at main task.

But I think we can handle it at the interrupt and it can handle at once.