Page 1 of 1

Project FreeCopter (aka an example for ChibiOS SPI SLAVE)

Posted: Wed Apr 10, 2013 3:11 pm
by formica
Dear all,
I'm developing the FreeCopter project using ChibiOS on STM32F1, and I'd like to share with you the code also because I succeed to build an SPI Master/Slave communication... could be interesting for someone because there is no official support for the SPI SLAVE in Chibios.

The code is on GITHUB:
https://github.com/formica-multiuso/freecopter-imu
https://github.com/formica-multiuso/freecopter-control

The 'freecopter-control' software provide a ChibiOS patch to implement SPI Slave (chibios_patch folder).

The software is intended to work on a custom board about which I will publish as soon as possible.

Regards
Roberto

Re: Project FreeCopter (aka an example for ChibiOS SPI SLAVE

Posted: Thu Apr 11, 2013 11:49 am
by formica
Here the patch to use SPI in slave mode on the STM32F1x (but I think should work alson on F4).

Code: Select all

--- spi_lld.c   2012-06-18 19:14:28.000000000 +0200
+++ /home/formica/chibios/chibios/os/hal/platforms/STM32/spi_lld.c   2013-04-10 12:21:44.096847872 +0200
@@ -294,10 +294,16 @@
   }
   /* SPI setup and enable.*/
   spip->spi->CR1  = 0;
+  #if !defined(STM32_SPI_SLAVE_MODE)
   spip->spi->CR1  = spip->config->cr1 | SPI_CR1_MSTR | SPI_CR1_SSM |
                     SPI_CR1_SSI;
   spip->spi->CR2  = SPI_CR2_SSOE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
   spip->spi->CR1 |= SPI_CR1_SPE;
+  #else
+  spip->spi->CR1 = spip->config->cr1 | SPI_CR1_RXONLY; //| SPI_CR1_DFF;
+  spip->spi->CR2 = SPI_CR2_RXDMAEN; //| SPI_CR2_RXNEIE;
+  spip->spi->CR1 |= SPI_CR1_SPE;
+  #endif
 }
 
 /**



Re: Project FreeCopter (aka an example for ChibiOS SPI SLAVE

Posted: Thu Apr 11, 2013 12:15 pm
by Giovanni
Hi,

Thanks for the patch, some may need that. The current SPI driver model is not meant to be a slave SPI so it can't be merged in this moment.

The general idea is to have a specific SPI-slave driver at some point.

Giovanni