cancel
Showing results for 
Search instead for 
Did you mean: 

HAL USART DMA buffer reset method?

BSang
Associate III

Hi Community,

I find a method to reset a buffer of USART DMA Buffer.

because I use USART DMA basically.

​

my system is consist of android smartphone, bluetooth and microcontroller(STM32F407VET), PC

​

when I click a button that implemented in a android, some packet is send to the bluetooth RX

and Bluetooth TX that connected to micro controller USART3 RX.

​

than Received USART3 Data directly send to USART1 and I can see the packet in PC program.

(So... long)

​

I learned about HAL USART DMA is need a fixed buffer size.

so I designed the system the length of the packet is always fixed.

​

But! when the Bluetooth is connected, the packet is occurred by Bluetooth like

"Connected X" (X is MAC address of Bluetooth)

​

Due to the packet that I don't want, DMA buffer is shifted.

​

like under example.

​

ex)​

Normal State

​buffer size 5

send "12345" => receive​ "12345"

​

Abnormal state​

send "12345" => add packet "ab"=>receive​ "ab123"​

​

For this reason, I would like to ask community How to reset DMA buffer.

​

Of course, using a ring buffer is best way, but I'm not have a code that work normally, and other is I can't understand the code algorithms.

​

Ask for help...

​

Thank.

This discussion is locked. Please start a new topic to ask your question.
12 REPLIES 12
BSang
Associate III

Thanks TJ,

what type is U1RxBufferPtrIN  and U1RxBufferPtrOUT?

char readableU1(void) {

  U1RxBufferPtrIN = U1RxBufSize - huart1.hdmarx->Instance->CNDTR;

  return U1RxBufferPtrIN - U1RxBufferPtrOUT;

}  

readableU1 is means that USART1 RX Channel is available?

It is not a clear buffer methods?

T J
Lead

uint32_t U1RxBufferPtrIN ;

uint32_t U1RxBufferPtrOUT=0;

make your buffer size 2^N like 256 or 512 or 1024 or 2048 or 4096 bytes

T J
Lead

Yes, use clear clearRxBuffer() to make the U1RxBufferPtrOUT equal to the DMA pointerIN , U1RxBufferPtrIN

then when you do readableU1() there return value will be Zero...