cancel
Showing results for 
Search instead for 
Did you mean: 

Data transfer between CAN Bus to DMA on HAL LIBRARY STM32F4 Discovery board

ninad911
Associate III
Posted on August 18, 2016 at 21:37

hello,

i want to know can we transfer data from CAN Bus to DMA memory on board on HAL Library? 

if yes or no can some one please explain how ?

Thanks in advance!!!

#hal #hal #can #!stm32-!cubemx-!can-!bug #canbus #cubemx #uart #stm32 #stm32
5 REPLIES 5
Posted on August 18, 2016 at 22:17

It would seem readily apparent from the Reference Manual that it can't.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock23
Associate III
Posted on August 18, 2016 at 23:14

Given the short packet size and multiple receive buffers there is little or no benefit in using DMA.  The setup time for DMA becomes significant when transfer sizes are so small.

CAN data rarely streams in a nice linear fashion suitable for DMA.  Each message can reference a different object, and there are two priority levels for RX which makes any kind of DMA impractical.  Streaming packets into one large buffer only means you have to add additional overhead to determine where to route each one, something done just as easily as each one arrives. 

How do you handle out of order arrivals?  Messages queued for transmit don't arrive in the same order.  Higher priority objects take precedence, which means your nice circular DMA buffer needs a software scatter-gather handler to sort out messages.  In large part this duplicates what happens in the interrupt handler.

So there is a good reason there's no DMA.  You will see the same thing for FS USB, low speed packets processed directly.

  Jack Peacock

Posted on August 18, 2016 at 23:34

I agree on the pointlessness of the endeavour. You'd waste more time/resources than could be possibly gained.

So there is a good reason there's no DMA. 

The fact that it is bolted on Third Party IP is also a very strong reason to leave it alone rather than integrate it like a normal peripheral. It is designed to function reasonably autonomously.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ninad911
Associate III
Posted on August 19, 2016 at 14:13

i need to to receive my data from CAN bus, merge the data(2 bytes of data from CAN bus into one Hexa decimal 1 byte) and then transfer it on UART.  

That is the reason i asked. 

i thought to use DMA-to-UART buffer to store. is it possible in this condition?

Posted on August 19, 2016 at 19:23

It is certainly possible to feed data to the USART via DMA, large buffers would clearly be preferable to reduce overhead.

The description of what you want to do with the CAN data is a bit cryptic. How are you merging the data into a byte? Perhaps you can illustrate with a typical CAN packet, or packets, and then how you expect that data to be presented on the serial console.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..