Skip to main content
MacLaren
Associate III
January 25, 2020
Question

Data Buffer for serial and spi

  • January 25, 2020
  • 8 replies
  • 1989 views

hi hope have good day

i need to buffer data for save on every 1ms

for serial and spi i use dma to receive data

for example hal_uart_receviveDMA on this function must set buffer size ...

i test one example :

50Hz send to mcu data each time 1000 and 1001 and 1002... to full load data and baud 921600

1khz buffering(hal_uart_rec_dma) in 2000 length variable.

but i have some problem

in first time on the dma interrupt 1000 was ok second form 1000 to 2000 data add and 1 data lost and lost increase every 2 time buffer full

how can i find how many data receive for copy on other buffer and how can i receive without lost

thanks

This topic has been closed for replies.

8 replies

waclawek.jan
Super User
January 25, 2020

For high data rate, use circular DMA.

JW

KnarfB
Super User
January 25, 2020
MacLaren
MacLarenAuthor
Associate III
January 30, 2020

thanks for reply

i use circular DMA and it work just for test board that is f1 not H7

now in H7 its a few complex

i do this change but i cant see any data in Buffer

ALIGN_32BYTES (uint8_t U1RxBuff[1000]);
ALIGN_32BYTES (uint8_t U2RxBuff[1000]);
ALIGN_32BYTES (uint8_t U3RxBuff[1000]);
ALIGN_32BYTES (uint8_t U4RxBuff[1000]);
ALIGN_32BYTES (uint8_t U5RxBuff[1000]);
int main(void)
{
 SCB_EnableICache();
 SCB_EnableDCache();
 
//some thing
  MX_GPIO_Init();
 MX_DMA_Init();
 MX_UART4_Init();
 MX_UART5_Init();
 MX_UART7_Init();
 MX_UART8_Init();
 MX_USART1_UART_Init();
 
//some thing
 
			SCB_InvalidateDCache_by_Addr ((uint32_t *) U1RxBuff, 1000);
			SCB_InvalidateDCache_by_Addr ((uint32_t *) U2RxBuff, 1000);
			SCB_InvalidateDCache_by_Addr ((uint32_t *) U3RxBuff, 1000);
			SCB_InvalidateDCache_by_Addr ((uint32_t *) U4RxBuff, 1000);
			SCB_InvalidateDCache_by_Addr ((uint32_t *) U5RxBuff, 1000);
			HAL_UART_Receive_DMA(&huart1, U1RxBuff, 1000);
			HAL_UART_Receive_DMA(&huart7, U2RxBuff, 1000);
			HAL_UART_Receive_DMA(&huart8, U3RxBuff, 1000);
			HAL_UART_Receive_DMA(&huart4, U4RxBuff, 1000);
			HAL_UART_Receive_DMA(&huart5, U5RxBuff, 1000);
 
//some thing
}
static void MX_DMA_Init(void) 
{
 
 /* DMA controller clock enable */
 __HAL_RCC_DMA1_CLK_ENABLE();
 
 /* DMA interrupt init */
 /* DMA1_Stream0_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
 /* DMA1_Stream1_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
 /* DMA1_Stream2_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(DMA1_Stream2_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(DMA1_Stream2_IRQn);
 /* DMA1_Stream3_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);
 /* DMA1_Stream4_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);
 
}

i cant see interrupt for dma in hal...it.c

 data stream from source is continue send and i must save all of them

baud rate is 921600 and full load

MacLaren
MacLarenAuthor
Associate III
January 31, 2020

i test lot of solution such as this link https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices?t=1580438940317

and template in cube mx folder for H7 uart dma but yet i cant receive correct data

i use cube ide

waclawek.jan
Super User
January 31, 2020

So, you first said:

> form 1000 to 2000 data add and 1 data lost

and then

> i do this change but i cant see any data in Buffer

So what is it, no data or 1 data point out of 1000 missing?

Read out and check the relevant DMA, DMAMUX and UART registers content.

JW

MacLaren
MacLarenAuthor
Associate III
January 31, 2020

yes

i mention to that

at first i just use f1 ev borad for test (with your answer that work )

but at last in h7 borad I didn't get the previous answer(no data or 1 data)

MacLaren
MacLarenAuthor
Associate III
January 31, 2020

my question is that why st cube mx example not correct receive uart ?

waclawek.jan
Super User
January 31, 2020

Well, I don't know and I don't care, I don't use CubeMX and I don't use 'H7.

The chip doesn't care about CubeMX either, it works out of its settings. That's why you should look at the registers.

JW

MacLaren
MacLarenAuthor
Associate III
February 1, 2020

i have some change and now i can see data in buffer

but have new problem

in circular dma mode data continuously received but lot of data wrong

in normal mode i can just one time correct frame and stop receive data

MacLaren
MacLarenAuthor
Associate III
February 4, 2020

any one have solution for this post?