cancel
Showing results for 
Search instead for 
Did you mean: 

Two Serial ports with HAL_UARTEx_RxEventCallback don't work for me

Beamspot
Associate

Hi everybody:

First post here.

I'm working with a GPS parser that re-sends data to another board, and receives some feedback from this other obard.

BTW, both perform GPS parsing, with the same algos.

One is Feather STM32F407 (the one with the problem) and the other is Nucleo STM32F439 that is also a UDP server/broadcaster.

The issue is that the first one uses USART 3 to interface to a GPS (in this case, TESEO3), and USART 6 to re send the NMEA sentence.

In both cases, I'm using the DMA receive to IDLE, since in both cases data stream is continuous.

The issue, is that the HAL_UARTEx_RxEventCallback only seems to work with ONE of the serial ports. If I use only one, then it works fine with whatever port is being used, but I find no way to use both.

The code of the callback is:

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)

{

if (huart->Instance == USART3)

{

//Data received from GPS. Send it by remote link to Tracker

if (DataToParse == 0) DataToParse = 1;

else return;

HAL_UARTEx_ReceiveToIdle_DMA(&huart3,(unsigned char*)NMEABuff,4096);

//HAL_UART_Transmit_DMA(&huart6,(unsigned char*)NMEABuff, Size);

//ParseGPS(NMEABuff,Size,&GPSData);

//Send data received by USB to debug link

SizeToParse = Size;

//CDC_Transmit_FS((unsigned char*)NMEABuff, Size);

}

if (huart->Instance == USART6)

{

//DataToParse = 1;

HAL_UARTEx_ReceiveToIdle_DMA(&huart6,(unsigned char*)Buff,255);

//Data received by remote link, thus info about contro --> Send to Pilot

}

}

Attached you can find both .ioc.

Any hint about the reason?

 

Thanks in advance,

Beamspot.

2 REPLIES 2
Sarra.S
ST Employee

Hello @Beamspot

Try: 

if (huart->Instance == USART3)
    {
        // Data received from GPS. Send it by remote link to Tracker
        if (DataToParse == 0) 
        {
            DataToParse = 1;
            SizeToParse = Size;
            HAL_UARTEx_ReceiveToIdle_DMA(&huart3, (unsigned char*)NMEABuff, 4096);
            // Process the received data
            // HAL_UART_Transmit_DMA(&huart6, (unsigned char*)NMEABuff, Size);
            // ParseGPS(NMEABuff, Size, &GPSData);
            // Send data received by USB to debug link
            // CDC_Transmit_FS((unsigned char*)NMEABuff, Size);
        }
    }
    else if (huart->Instance == USART6)
    {
        HAL_UARTEx_ReceiveToIdle_DMA(&huart6, (unsigned char*)Buff, 255);
    }
}

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thank you very much. A nice improvement over my code, for sure.

But it still doesn't work.

Keep in mind, that trying to solve the issues, maybe I've made things worse: when I posted the question, I was still receiving the data through USART6 (I had uncommented the line 

HAL_UART_Transmit_DMA(&huart6, (unsigned char*)NMEABuff, Size);

), but now it is again uncommented, and I don't reveive anything.

Maybe there are other problems too, and I don't have the HW tools required at hand, so when I go back to work on January 7, I will do more tests.

If finally I succeed, I will post the solution over here.

To be honest, the most probable way to do will be by getting rid of HAL and write my own code for that. I've done in the past for a different project (MODBUS master & slave with Nucleo F439), but it worked slightly different. Time to "rescue" such old code and work at register level instead.

Since I'm lazy, I expected HAL to handle this for me, and indeed it works fine with ONLY one USART in different projects.

Thanks again for your support!

Beamspot.