cancel
Showing results for 
Search instead for 
Did you mean: 

some Precautions for safe transmission(USART and DMA)

parisa
Senior
Posted on September 09, 2016 at 14:55

Hello

you assume a system as shown below 0690X00000605DzQAI.png I have written a simple code to collect 100 chars from USART and DMA to a buffer.I want to estimate my system safety.

DMA_DeInit(DMA1_Channel5);
DMAStruc.DMA_PeripheralBaseAddr=(uint32_t) &USART1->DR;
DMAStruc.DMA_MemoryBaseAddr=(uint32_t) buffer; 
DMAStruc.DMA_DIR=DMA_DIR_PeripheralSRC;
DMAStruc.DMA_BufferSize=100;
DMAStruc.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMAStruc.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMAStruc.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Byte;
DMAStruc.DMA_MemoryDataSize=DMA_MemoryDataSize_Byte;
DMAStruc.DMA_Mode=DMA_Mode_Circular;
DMAStruc.DMA_Priority=DMA_Priority_High;
DMAStruc.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5,&DMAStruc);
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
DMA_ITConfig(DMA1_Channel5, DMA_IT_TC | DMA_IT_TE, ENABLE);
DMA_Cmd(DMA1_Channel5, ENABLE);

1)when 100 chars(a simple packet) receive DMA arise an interrupt to make me aware of input data.You assume 50chars received from packet1 and suddenly we lost our connection and after some seconds it establishes a new connection and send packet2(100 new chars) to receiver.In this scenario buffer variable collect two different packets content to each other(50 chars from the first pack and 50 chars from the second packet) and arise new interrupt.In this statues we can't find out our buffer contains wrong value.How can prevent? 2)Now you assume we send a string with this format [Start char][98 chars , don't contain start and stop char][Stop char] and we can rely on our buffer value by checking start and stop chars Now we suppose In receiver we lost one char from 98 chars therefore we get DMA interrupt when it fill up the buffer variable such as this new string [Start char][97 chars , don't contain start and stop char][Stop char][Start char] so we check start and stop chars and finally we ignore this packet and other packets ( because their first and end chars position have changed in all strings) if we don't use DMA we can fill up the buffer with incoming chars and check start and stop chars and also string length and ignore fault string without any effect on other input strings. so what is your idea to have a safe communication with dma?(without any checksum)
0 REPLIES 0