diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-10-24 10:09:28 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-10-24 10:09:28 +0000 |
commit | fb68f0d51775b7e0bafa82fa67573e652babb6a6 (patch) | |
tree | 98788291c76294f69bc497d890e82d56fde226bf /os/io/platforms | |
parent | 09194e6f2232390b16ed37c65cf750bd47bc4bf4 (diff) | |
download | ChibiOS-fb68f0d51775b7e0bafa82fa67573e652babb6a6.tar.gz ChibiOS-fb68f0d51775b7e0bafa82fa67573e652babb6a6.tar.bz2 ChibiOS-fb68f0d51775b7e0bafa82fa67573e652babb6a6.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1251 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/platforms')
-rw-r--r-- | os/io/platforms/STM32/pal_lld.h | 6 | ||||
-rw-r--r-- | os/io/platforms/STM32/serial_lld.h | 6 | ||||
-rw-r--r-- | os/io/platforms/STM32/spi_lld.c | 30 | ||||
-rw-r--r-- | os/io/platforms/STM32/spi_lld.h | 44 |
4 files changed, 65 insertions, 21 deletions
diff --git a/os/io/platforms/STM32/pal_lld.h b/os/io/platforms/STM32/pal_lld.h index 9c234cac3..479b5e856 100644 --- a/os/io/platforms/STM32/pal_lld.h +++ b/os/io/platforms/STM32/pal_lld.h @@ -27,17 +27,11 @@ #ifndef _PAL_LLD_H_
#define _PAL_LLD_H_
-/*
- * Tricks required to make the TRUE/FALSE declaration inside the library
- * compatible.
- */
-#ifndef __STM32F10x_H
#undef FALSE
#undef TRUE
#include <stm32f10x.h>
#define FALSE 0
#define TRUE (!FALSE)
-#endif
/*===========================================================================*/
/* I/O Ports Types and constants. */
diff --git a/os/io/platforms/STM32/serial_lld.h b/os/io/platforms/STM32/serial_lld.h index ed80f8b5d..b5d32d605 100644 --- a/os/io/platforms/STM32/serial_lld.h +++ b/os/io/platforms/STM32/serial_lld.h @@ -27,17 +27,11 @@ #ifndef _SERIAL_LLD_H_
#define _SERIAL_LLD_H_
-/*
- * Tricks required to make the TRUE/FALSE declaration inside the library
- * compatible.
- */
-#ifndef __STM32F10x_H
#undef FALSE
#undef TRUE
#include <stm32f10x.h>
#define FALSE 0
#define TRUE (!FALSE)
-#endif
/*===========================================================================*/
/* Driver pre-compile time settings. */
diff --git a/os/io/platforms/STM32/spi_lld.c b/os/io/platforms/STM32/spi_lld.c index 4ef99e1ed..5e8ef614e 100644 --- a/os/io/platforms/STM32/spi_lld.c +++ b/os/io/platforms/STM32/spi_lld.c @@ -27,11 +27,41 @@ #include <ch.h>
#include <spi.h>
+#include "nvic.h"
+#include "board.h"
+
+#if USE_STM32_SPI1 || defined(__DOXYGEN__)
+/** @brief SPI1 driver identifier.*/
+SPIDriver SPID1;
+#endif
+
+#if USE_STM32_SPI2 || defined(__DOXYGEN__)
+/** @brief SPI2 driver identifier.*/
+SPIDriver SPID2;
+#endif
+
/**
* @brief Low level SPI driver initialization. */
void spi_lld_init(void) {
+#if USE_STM32_SPI1
+ spiObjectInit(&SPID1);
+ SPID1.spd_spi = SPI1;
+ SPID1.spd_dmarx = DMA1_Channel2;
+ SPID1.spd_dmatx = DMA1_Channel3;
+ RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
+ GPIOA->CRH = (GPIOA->CRH & 0x000FFFFF) | 0xB4B00000;
+#endif
+
+#if USE_STM32_SPI2
+ spiObjectInit(&SPID2);
+ SPID2.spd_spi = SPI2;
+ SPID2.spd_dmarx = DMA1_Channel4;
+ SPID2.spd_dmatx = DMA1_Channel5;
+ RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
+ GPIOB->CRL = (GPIOB->CRL & 0x000FFFFF) | 0xB4B00000;
+#endif
}
/**
diff --git a/os/io/platforms/STM32/spi_lld.h b/os/io/platforms/STM32/spi_lld.h index 26a70d0a4..23193bc0d 100644 --- a/os/io/platforms/STM32/spi_lld.h +++ b/os/io/platforms/STM32/spi_lld.h @@ -27,19 +27,32 @@ #ifndef _SPI_LLD_H_
#define _SPI_LLD_H_
+#undef FALSE
+#undef TRUE
+#include <stm32f10x.h>
+#define FALSE 0
+#define TRUE (!FALSE)
+
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
- * @brief Enables the mutual exclusion APIs on the SPI bus. + * @brief SPI1 driver enable switch.
+ * @details If set to @p TRUE the support for SPI is included.
+ * @note The default is @p TRUE.
*/
-#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define SPI_USE_MUTUAL_EXCLUSION TRUE
+#if !defined(USE_STM32_SPI1) || defined(__DOXYGEN__)
+#define USE_STM32_SPI1 TRUE
#endif
-#if SPI_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
-#error "SPI_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
+/**
+ * @brief SPI1 driver enable switch.
+ * @details If set to @p TRUE the support for SPI is included.
+ * @note The default is @p TRUE.
+ */
+#if !defined(USE_STM32_SPI2) || defined(__DOXYGEN__)
+#define USE_STM32_SPI2 TRUE
#endif
/*===========================================================================*/
@@ -50,9 +63,9 @@ * @brief Driver state machine possible states. */
typedef enum {
- SPI_UNINIT = 0,//!< SPI_UNINIT
- SPI_IDLE = 1, //!< SPI_IDLE
- SPI_ACTIVE = 2 //!< SPI_ACTIVE
+ SPI_UNINIT = 0,
+ SPI_IDLE = 1,
+ SPI_ACTIVE = 2
} spistate_t;
/**
@@ -85,16 +98,28 @@ typedef struct { #endif
#endif /* SPI_USE_MUTUAL_EXCLUSION */
/**
- * Current configuration data.
+ * @brief Current configuration data.
*/
const SPIConfig *spd_config;
/* End of the mandatory fields.*/
+ SPI_TypeDef *spd_spi;
+ DMA_Channel_TypeDef *spd_dmarx;
+ DMA_Channel_TypeDef *spd_dmatx;
} SPIDriver;
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
+/** @cond never*/
+#if USE_STM32_SPI1
+extern SPIDriver SPID1;
+#endif
+
+#if USE_STM32_SPI2
+extern SPIDriver SPID2;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -106,6 +131,7 @@ extern "C" { #ifdef __cplusplus
}
#endif
+/** @endcond*/
#endif /* _SPI_LLD_H_ */
|