Page 1 of 1

Questions about SPI and DMA

Posted: Thu Nov 07, 2013 9:21 pm
by Flo89
Hello :)
I wrote spi code of following structure:
spiSelect(...);
spiExchange(...);
spiUnselect(...);

Now I saw in the ARMCM3-STM32F100-DISCOVERY example code of the following structure:
spiSelectI(...);
spiStartSendI(...);
spiUnselectI(...);

Now my questions are: Are I'm using DMA automatically with my code (STM32F3 series MCU) and where are the differences in operation between the functions I am using and the macros which are used by the example code?

Thanks a lot for answers!
Florian

Re: Questions about SPI and DMA

Posted: Fri Nov 08, 2013 7:11 am
by Tectu
The ChibiOS/RT HAL drivers use DMA where possible - In your case, both codes will do so. You can change the DMA settings of each peripheral in your mcuconf.h file.
The spiExchange() commits a write command, followed by a read command (it' exchanges data). The spiStartSend() routine starts the SPI peripheral and simply sends some bytes, without reading back any "answer" as the former routine did.
You can find more detailed information about this in the SPI HAL documentation.


~Tectu

Re: Questions about SPI and DMA

Posted: Fri Nov 08, 2013 10:36 am
by Giovanni
Just a small correction, spiExchange() sends and receive at the same time, for each clock pulse a bit is transmitted and a bit is received.

In all drivers the DMA is used where applicable transparently to the user, you just need to take care to not use two peripherals sharing the same DMA channels at the same time (you can play with start/stop functions of the drivers and still use them in different moments).

Giovanni

Re: Questions about SPI and DMA

Posted: Mon Nov 11, 2013 11:42 am
by Flo89
Thank you for your explanations, this helps me a lot!

Best regards,
Florian