aboutsummaryrefslogtreecommitdiffstats
path: root/os/io/platforms
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-10-30 15:45:38 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-10-30 15:45:38 +0000
commit43f9fd4180030081daae9122bd57a521ec9c58e1 (patch)
treeaf4185a0b33d984503a16c0b55e2febe2a9a73bf /os/io/platforms
parent5ccb308ed861f6f7a42b7d826e939fd8efa68bac (diff)
downloadChibiOS-43f9fd4180030081daae9122bd57a521ec9c58e1.tar.gz
ChibiOS-43f9fd4180030081daae9122bd57a521ec9c58e1.tar.bz2
ChibiOS-43f9fd4180030081daae9122bd57a521ec9c58e1.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1258 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/platforms')
-rw-r--r--os/io/platforms/STM32/spi_lld.c46
-rw-r--r--os/io/platforms/STM32/spi_lld.h12
2 files changed, 42 insertions, 16 deletions
diff --git a/os/io/platforms/STM32/spi_lld.c b/os/io/platforms/STM32/spi_lld.c
index d0a84ddf7..fb3021d80 100644
--- a/os/io/platforms/STM32/spi_lld.c
+++ b/os/io/platforms/STM32/spi_lld.c
@@ -179,7 +179,6 @@ void spi_lld_init(void) {
SPID1.spd_dmarx = DMA1_Channel2;
SPID1.spd_dmatx = DMA1_Channel3;
SPID1.spd_dmaprio = SPI1_DMA_PRIORITY << 12;
- RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
GPIOA->CRH = (GPIOA->CRH & 0x000FFFFF) | 0xB4B00000;
#endif
@@ -190,17 +189,30 @@ void spi_lld_init(void) {
SPID2.spd_dmarx = DMA1_Channel4;
SPID2.spd_dmatx = DMA1_Channel5;
SPID2.spd_dmaprio = SPI2_DMA_PRIORITY << 12;
- RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
GPIOB->CRL = (GPIOB->CRL & 0x000FFFFF) | 0xB4B00000;
#endif
}
/**
- * @brief Low level SPI bus setup.
- *
+ * @brief Configures and activates the SPI peripheral.
+ *
* @param[in] spip pointer to the @p SPIDriver object
*/
-void spi_lld_setup(SPIDriver *spip) {
+void spi_lld_start(SPIDriver *spip) {
+
+ /* If in stopped state then enables the SPI clock.*/
+ if (spip->spd_state == SPI_STOP) {
+#if USE_STM32_SPI1
+ if (&SPID1 == spip) {
+ RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
+ }
+#endif
+#if USE_STM32_SPI2
+ if (&SPID2 == spip) {
+ RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
+ }
+#endif
+ }
/* SPI setup.*/
spip->spd_spi->CR1 = spip->spd_config->spc_cr1 | SPI_CR1_MSTR;
@@ -226,6 +238,28 @@ void spi_lld_setup(SPIDriver *spip) {
}
/**
+ * @brief Deactivates the SPI peripheral.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ */
+void spi_lld_stop(SPIDriver *spip) {
+
+ /* If in ready state then disables the SPI clock.*/
+ if (spip->spd_state == SPI_READY) {
+#if USE_STM32_SPI1
+ if (&SPID1 == spip) {
+ RCC->APB2ENR &= ~RCC_APB2ENR_SPI1EN;
+ }
+#endif
+#if USE_STM32_SPI2
+ if (&SPID2 == spip) {
+ RCC->APB1ENR &= ~RCC_APB1ENR_SPI2EN;
+ }
+#endif
+ }
+}
+
+/**
* @brief Asserts the slave select signal and prepares for transfers.
*
* @param[in] spip pointer to the @p SPIDriver object
@@ -236,7 +270,7 @@ void spi_lld_select(SPIDriver *spip) {
}
/**
- * @brief De-asserts the slave select signal.
+ * @brief Deasserts the slave select signal.
* @details The previously selected peripheral is unselected.
*
* @param[in] spip pointer to the @p SPIDriver object
diff --git a/os/io/platforms/STM32/spi_lld.h b/os/io/platforms/STM32/spi_lld.h
index 5775b67db..7348b72a6 100644
--- a/os/io/platforms/STM32/spi_lld.h
+++ b/os/io/platforms/STM32/spi_lld.h
@@ -82,15 +82,6 @@
/*===========================================================================*/
/**
- * @brief Driver state machine possible states.
- */
-typedef enum {
- SPI_UNINIT = 0,//!< SPI_UNINIT
- SPI_IDLE = 1, //!< SPI_IDLE
- SPI_ACTIVE = 2 //!< SPI_ACTIVE
-} spistate_t;
-
-/**
* @brief Driver configuration structure.
*/
typedef struct {
@@ -175,7 +166,8 @@ extern SPIDriver SPID2;
extern "C" {
#endif
void spi_lld_init(void);
- void spi_lld_setup(SPIDriver *spip);
+ void spi_lld_start(SPIDriver *spip);
+ void spi_lld_stop(SPIDriver *spip);
void spi_lld_select(SPIDriver *spip);
void spi_lld_unselect(SPIDriver *spip);
msg_t spi_lld_exchange(SPIDriver *spip, size_t n, void *rxbuf, void *txbuf);