0
votes

I am using two STM32H743 connected via RS232. These two modules connected to same power. They use UART with DMA. When I turn on modules at the same time, UART and DMA starts correctly. But when i restart one of the modules while other is awake, the reset module's UART and DMA does not start therefore they cannot communicate with each other.
This problem is also happened before with STM32F4 series. MCU is connected to FPGA and they communicate via UART. When FPGA starts before MCU, DMA and UART does not start properly. What could cause this problem? Do i need to have a high-z or floating pin states before starting UART?

2
If you are using HAL, then you should use the HAL_UART_DeInit(huart) in both sides to avoid any unexpected char to be received by one of the sides of the communication. I also had similar problem and turns out that when one of them is rebooting, any trash signal would trigger the other side as a start byte, and then the UART gets lost.campescassiano
I also debugged further and found that error registers indicates frame error. Also when i unplugged rs232 cable without power down, MCU triggers a uart error callback (frame error). When i get this interrupt, i reinit the uart perhibral and it works again. But sometimes, not always, when MCU first initialize UART, it does not start and DMA does not carry any bytes. It is really interesting. Why it happens when first initialization, i could not find the reason.bera
I have the impression that this is an electrical engineering problem, not a software problem. Please consider posting the question at Electrical Engineering Stack Exchange and removing it here.HelpingHand

2 Answers

0
votes

The UART and DMA peripherals usually have an error detector, thus has it's flags into the status register. When an error happen, the STM32 HAL will stop any transfer ongoing and wait until you treat this fail. You can check, with the debug module, the HAL status registers to troubleshoot the problem, and add the treatment to it in you code. At first you could reset the peripheral by run DeInit() and right after run Init() routine of the peripheral with error, and reset any other piece of code e.g. state machines and stuff that uses the data from this peripheral.

0
votes

After lots of debugging hours, I finally found the cause and solution. When first bytes reach to UART peripheral, due to clock mismatch, it triggers frame error then stops the DMA. This happens more than usual when UART datarate is very high. But I had added the ErrorCallback function to handle the interrupt. Unfortunately, I misused the function.

My use :

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
    HAL_UART_MspDeInit();   
    HAL_UART_Receive_DMA(...);
}

HAL_UART_MspDeInit does not clear structs and initializations therefore Receive_DMA function cannot start it again. So, my communication stops.

Correct use :

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
    HAL_UART_DeInit();  
    HAL_UART_Receive_DMA(...);
}

Thanks to three typos in my code, it caused to me a lot of time. But finally, it resolved.