cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103T8 UART ReceiveToIdle trigger issue? & DMA issue

XD
Associate III

Im not sure what is going on...

The goal is to receive an unknown transmission length from the UART. 

Issues:

  1. HAL_UARTEx_ReceiveToIdle_IT(): Event callback is called "incorrectly".
  2. I am unable to get any DMA to function, neither the UART DMA or I2C. Simply nothing happens.

 

HAL_UARTEx_ReceiveToIdle_IT(): Issue

Baudrate: 9600
Reception interval: ~200 ms

The most common amount of bytes to receive is 8 (one packet). The RxEventCallback function is called at the start of the next packet.

Packet 1 is sent -> 200ms of nothing -> Packet 2 is sent -> RxEventCallback is immediately called with the reception size being 9-bytes. All data is correct and no errors are thrown. 

XD_0-1742376240166.png

 

 

Previous working approaches on other processors.
STM32F4:

HAL_UARTEx_ReceiveToIdle_DMA(&huart3, buffer, size);
__HAL_DMA_DISABLE_IT(&hdma_usart3_rx, DMA_IT_HT);
__HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);

Handle data in:

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){

 return;
}

 

Old 8-bit processors:

UART Rx IRQ
Read byte and start & reset timer counting register.

Timer overflows and calls interrupt when data is no longer received. 

 

What is going on with the DMA?

I would prefer the DMA approach for obvious reasons but cannot get it to work. 
I've tested the exact same code and configuration as on other ST processors but i get zero transmission or reception!

 

5 REPLIES 5
TDK
Guru

Put a breakpoint in HAL_UARTEx_RxEventCallback and go through the stack trace to understand why it's called. It's pretty unlikely there's a bug in HAL in that function. Probably something else is going on here.

Your reception code does nothing, how do you know when it's being called?

If you feel a post has answered your question, please click "Accept as Solution".
XD
Associate III

I was running out of time so "solved it" by using the same method as with the old 8-bit micros.

I'm still wondering why not a single DMA peripheral is functioning and why the I2C is not functioning correctly. My gut says that all of these issues are linked but im unable to find the reason...

 

Your reception code does nothing, how do you know when it's being called?
It actually does some things, just simplified the code when posting to make it easier to follow.

Ozone
Lead III

> The goal is to receive an unknown transmission length from the UART. 

That doesn't go very well with DMA, which has to be configured to a byte count.

For that few transmissions you have shown to occur, there is virtually no gain from using DMA.
Why not using Rx interrupts ?

XD
Associate III

That doesn't go very well with DMA, which has to be configured to a byte count.

The documentation states that the DMA will stop when all bytes are received or when an IDLE event occurs.
I just set the "expected bytes" to the size of the buffer and parse all the data in the IDLE event callback. 

XD_0-1743755688951.png

 

For that few transmissions you have shown to occur, there is virtually no gain from using DMA.
Why not using Rx interrupts ?

I'm using a interrupt based approach now since i cannot get any DMA to work. Interrupt based Rx will trigger for every bytes received while the DMA based Rx will trigger once for half-complete and once when the buffer is full. It's nice to handle a single event for a full packet rather than many "partial packets" when MCU is busy doing other things.
The transmission example in the OP is just an example. 

> The documentation states that the DMA will stop when all bytes are received or when an IDLE event occurs.

I never used the "idle" feature of this UART.
Are you sure you configured it correctly ? I wouldn't trust Cube and the examples coming with it in this regard.