Questions about SPI and DMA

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Flo89
Posts: 8
Joined: Fri Oct 25, 2013 9:39 pm

Questions about SPI and DMA

Post 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
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Questions about SPI and DMA

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Questions about SPI and DMA

Post 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
Flo89
Posts: 8
Joined: Fri Oct 25, 2013 9:39 pm

Re: Questions about SPI and DMA

Post by Flo89 »

Thank you for your explanations, this helps me a lot!

Best regards,
Florian
Post Reply