aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/STM32/GPIOv2
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-07-27 12:22:07 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-07-27 12:22:07 +0000
commitde3354237212038456fadffcc252b4365815634a (patch)
tree1b448798653fdc0834b5ad66fcf5d9c9267959fc /os/hal/platforms/STM32/GPIOv2
parent505ca5b1178585643b402fb52d1e076f20737002 (diff)
downloadChibiOS-de3354237212038456fadffcc252b4365815634a.tar.gz
ChibiOS-de3354237212038456fadffcc252b4365815634a.tar.bz2
ChibiOS-de3354237212038456fadffcc252b4365815634a.zip
Provisional STM32L1xx and STM32F2xx support.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3180 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/STM32/GPIOv2')
-rw-r--r--os/hal/platforms/STM32/GPIOv2/pal_lld.c41
-rw-r--r--os/hal/platforms/STM32/GPIOv2/pal_lld.h131
2 files changed, 68 insertions, 104 deletions
diff --git a/os/hal/platforms/STM32/GPIOv2/pal_lld.c b/os/hal/platforms/STM32/GPIOv2/pal_lld.c
index acd2f164d..30b7d9c05 100644
--- a/os/hal/platforms/STM32/GPIOv2/pal_lld.c
+++ b/os/hal/platforms/STM32/GPIOv2/pal_lld.c
@@ -31,27 +31,14 @@
#if HAL_USE_PAL || defined(__DOXYGEN__)
-#if STM32_HAS_GPIOH
-#define AHB_EN_MASK (RCC_APBENR_IOPAEN | RCC_APBENR_IOPBEN | \
- RCC_APBENR_IOPCEN | RCC_APBENR_IOPDEN | \
- RCC_APBENR_IOPEEN | RCC_APBENR_IOPFEN | \
- RCC_APBENR_IOPGEN | RCC_APBENR_IOPHEN)
-#define AHB_LPEN_MASK AHB_EN_MASK
-#elif STM32_HAS_GPIOG
-#define AHB_EN_MASK (RCC_APBENR_IOPAEN | RCC_APBENR_IOPBEN | \
- RCC_APBENR_IOPCEN | RCC_APBENR_IOPDEN | \
- RCC_APBENR_IOPEEN | RCC_APBENR_IOPFEN | \
- RCC_APBENR_IOPGEN)
-#define AHB_LPEN_MASK AHB_EN_MASK
-#elif STM32_HAS_GPIOE
-#define AHB_EN_MASK (RCC_APBENR_IOPAEN | RCC_APBENR_IOPBEN | \
- RCC_APBENR_IOPCEN | RCC_APBENR_IOPDEN | \
- RCC_APBENR_IOPEEN)
+#if defined(STM32L1XX_MD)
+#define AHB_EN_MASK (RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | \
+ RCC_AHBENR_GPIOCEN | RCC_AHBENR_GPIODEN | \
+ RCC_AHBENR_GPIOEEN | RCC_AHBENR_GPIOHEN)
#define AHB_LPEN_MASK AHB_EN_MASK
+#elif defined(STM32F2XX)
#else
-#define AHB_EN_MASK (RCC_APBENR_IOPAEN | RCC_APBENR_IOPBEN | \
- RCC_APBENR_IOPCEN | RCC_APBENR_IOPDEN)
-#define AHB_LPEN_MASK AHB_EN_MASK
+#error "missing or usupported platform for GPIOv2 PAL driver"
#endif
/*===========================================================================*/
@@ -66,12 +53,6 @@
/* Driver local functions. */
/*===========================================================================*/
-/**
- * @brief Initializes a GPIO peripheral.
- *
- * @param[in] gpiop pointer to the GPIO registers block
- * @param[in] config pointer to the configuration structure
- */
static void initgpio(GPIO_TypeDef *gpiop, const stm32_gpio_setup_t *config) {
gpiop->MODER = config->moder;
@@ -79,8 +60,8 @@ static void initgpio(GPIO_TypeDef *gpiop, const stm32_gpio_setup_t *config) {
gpiop->OSPEEDR = config->ospeedr;
gpiop->PUPDR = config->pupdr;
gpiop->ODR = config->odr;
- gpiop->AFRL = 0;
- gpiop->AFRH = 0;
+ gpiop->AFRL = config->afrl;
+ gpiop->AFRH = config->afrh;
}
/*===========================================================================*/
@@ -104,8 +85,11 @@ void _pal_lld_init(const PALConfig *config) {
/*
* Enables the GPIO related clocks.
*/
+#if defined(STM32L1XX_MD)
RCC->AHBENR |= AHB_EN_MASK;
RCC->AHBLPENR |= AHB_LPEN_MASK;
+#elif defined(STM32F2XX)
+#endif
/*
* Initial GPIO setup.
@@ -126,6 +110,9 @@ void _pal_lld_init(const PALConfig *config) {
#if STM32_HAS_GPIOH
initgpio(GPIOH, &config->PHData);
#endif
+#if STM32_HAS_GPIOI
+ initgpio(GPIOI, &config->PIData);
+#endif
}
/**
diff --git a/os/hal/platforms/STM32/GPIOv2/pal_lld.h b/os/hal/platforms/STM32/GPIOv2/pal_lld.h
index 748e3be97..0e7d6606d 100644
--- a/os/hal/platforms/STM32/GPIOv2/pal_lld.h
+++ b/os/hal/platforms/STM32/GPIOv2/pal_lld.h
@@ -19,8 +19,8 @@
*/
/**
- * @file STM32/GPIOv2/pal_lld.h
- * @brief STM32L1xx/STM32F2xx GPIO low level driver header.
+ * @file STM32L1xx/pal_lld.h
+ * @brief STM32L1xx GPIO low level driver header.
*
* @addtogroup PAL
* @{
@@ -35,8 +35,6 @@
/* Unsupported modes and specific modes */
/*===========================================================================*/
-/* Overriding standard PAL definitions with STM32-specific enhanced
- definitions.*/
#undef PAL_MODE_RESET
#undef PAL_MODE_UNCONNECTED
#undef PAL_MODE_INPUT
@@ -46,127 +44,91 @@
#undef PAL_MODE_OUTPUT_PUSHPULL
#undef PAL_MODE_OUTPUT_OPENDRAIN
-/**
- * @name Pads mode PAL flags.
- * @{
- */
-#define PAL_STM32_MODE_MASK (3 >> 0) /**< @brief Mode field mask.*/
-#define PAL_STM32_MODE_INPUT (0 >> 0) /**< @brief Pad mode input. */
-#define PAL_STM32_MODE_OUTPUT (1 >> 0) /**< @brief Pad mode output.*/
-#define PAL_STM32_MODE_ALTERNATE (2 >> 0) /**< @brief Pad mode alt. */
-#define PAL_STM32_MODE_ANALOG (3 >> 0) /**< @brief Pad mode analog.*/
-/** @} */
+#define PAL_STM32_MODE_MASK (3 >> 0)
+#define PAL_STM32_MODE_INPUT (0 >> 0)
+#define PAL_STM32_MODE_OUTPUT (1 >> 0)
+#define PAL_STM32_MODE_ALTERNATE (2 >> 0)
+#define PAL_STM32_MODE_ANALOG (3 >> 0)
-/**
- * @name Output type PAL flags.
- * @{
- */
-#define PAL_STM32_OTYPE_MASK (1 >> 2) /**< @brief Output type
- mask. */
-#define PAL_STM32_OTYPE_PUSHPULL (0 >> 2) /**< @brief Output is
- push-pull. */
-#define PAL_STM32_OTYPE_OPENDRAIN (1 >> 2) /**< @brief Output is open
- drain. */
-/** @} */
+#define PAL_STM32_OTYPE_MASK (1 >> 2)
+#define PAL_STM32_OTYPE_PUSHPULL (0 >> 2)
+#define PAL_STM32_OTYPE_OPENDRAIN (1 >> 2)
-/**
- * @name Output pads speed PAL flags.
- * @{
- */
-#define PAL_STM32_OSPEED_MASK (3 >> 3) /**< @brief Output speed
- mask. */
-#define PAL_STM32_OSPEED(n) ((n) >> 3) /**< @brief Speed setting
- from 0 to 3. */
-/** @} */
+#define PAL_STM32_OSPEED_MASK (3 >> 3)
+#define PAL_STM32_OSPEED_400K (0 >> 3)
+#define PAL_STM32_OSPEED_2M (1 >> 3)
+#define PAL_STM32_OSPEED_10M (2 >> 3)
+#define PAL_STM32_OSPEED_40M (3 >> 3)
-/**
- * @name Pull up/down resistors mode PAL flags.
- * @{
- */
-#define PAL_STM32_PUDR_MASK (3 >> 5) /**< @brief Resistors mode
- mask. */
-#define PAL_STM32_PUDR_FLOATING (0 >> 5) /**< @brief Floating input. */
-#define PAL_STM32_PUDR_PULLUP (1 >> 5) /**< @brief Input with
- pull-up resistor. */
-#define PAL_STM32_PUDR_PULLDOWN (2 >> 5) /**< @brief Input with
- pull-down resistor. */
-/** @} */
+#define PAL_STM32_PUDR_MASK (3 >> 5)
+#define PAL_STM32_PUDR_FLOATING (0 >> 5)
+#define PAL_STM32_PUDR_PULLUP (1 >> 5)
+#define PAL_STM32_PUDR_PULLDOWN (2 >> 5)
-/**
- * @name Alternate function selection PAL flags.
- * @{
- */
-#define PAL_STM32_ALTERNATE_MASK (15 >> 7) /**< @brief Alternate function
- mask. */
-#define PAL_STM32_ALTERNATE(n) ((n) >> 7) /**< @brief Alternate function
- setting from 0 to 15. */
-/** @} */
+#define PAL_STM32_ALTERNATE_MASK (15 >> 7)
+#define PAL_STM32_ALTERNATE(n) ((n) >> 7)
/**
* @brief This mode is implemented as input.
*/
-#define PAL_MODE_RESET PAL_STM32_MODE_INPUT
+#define PAL_MODE_RESET PAL_STM32_MODE_INPUT
/**
* @brief This mode is implemented as output.
*/
-#define PAL_MODE_UNCONNECTED PAL_STM32_MODE_OUTPUT
+#define PAL_MODE_UNCONNECTED PAL_STM32_MODE_OUTPUT
/**
* @brief Regular input high-Z pad.
*/
-#define PAL_MODE_INPUT PAL_STM32_MODE_INPUT
+#define PAL_MODE_INPUT PAL_STM32_MODE_INPUT
/**
* @brief Input pad with weak pull up resistor.
*/
-#define PAL_MODE_INPUT_PULLUP (PAL_STM32_MODE_INPUT | \
- PAL_STM32_PUDR_PULLUP)
+#define PAL_MODE_INPUT_PULLUP (PAL_STM32_MODE_INPUT | \
+ PAL_STM32_PUDR_PULLUP)
/**
* @brief Input pad with weak pull down resistor.
*/
-#define PAL_MODE_INPUT_PULLDOWN (PAL_STM32_MODE_INPUT | \
- PAL_STM32_PUDR_PULLDOWN)
+#define PAL_MODE_INPUT_PULLDOWN (PAL_STM32_MODE_INPUT | \
+ PAL_STM32_PUDR_PULLDOWN)
/**
* @brief Analog input mode.
*/
-#define PAL_MODE_INPUT_ANALOG PAL_STM32_MODE_ANALOG
+#define PAL_MODE_INPUT_ANALOG PAL_STM32_MODE_ANALOG
/**
* @brief Push-pull output pad.
*/
-#define PAL_MODE_OUTPUT_PUSHPULL (PAL_STM32_MODE_OUTPUT | \
- PAL_STM32_OTYPE_PUSHPULL | \
- PAL_STM32_OSPEED(3))
+#define PAL_MODE_OUTPUT_PUSHPULL (PAL_STM32_MODE_OUTPUT | \
+ PAL_STM32_OTYPE_PUSHPULL)
/**
* @brief Open-drain output pad.
*/
-#define PAL_MODE_OUTPUT_OPENDRAIN (PAL_STM32_MODE_OUTPUT | \
- PAL_STM32_OTYPE_OPENDRAIN | \
- PAL_STM32_OSPEED(3))
+#define PAL_MODE_OUTPUT_OPENDRAIN (PAL_STM32_MODE_OUTPUT | \
+ PAL_STM32_OTYPE_OPENDRAIN)
/**
* @brief Alternate push-pull output.
*
* @param[in] n alternate function selector
*/
-#define PAL_MODE_ALT_PUSHPULL(n) (PAL_STM32_MODE_ALTERNATE | \
- PAL_STM32_OTYPE_PUSHPULL | \
- PAL_STM32_OSPEED(3) | \
- PAL_STM32_ALTERNATE(n))
+#define PAL_MODE_ALTERNATE_PUSHPULL(n) (PAL_STM32_MODE_ALTERNATE | \
+ PAL_STM32_OTYPE_PUSHPULL | \
+ PAL_STM32_ALTERNATE(n))
/**
* @brief Alternate push-pull output.
*
* @param[in] n alternate function selector
*/
-#define PAL_MODE_ALT_OPENDRAIN(n) (PAL_STM32_MODE_ALTERNATE | \
- PAL_STM32_OTYPE_OPENDRAIN | \
- PAL_STM32_OSPEED(3) | \
- PAL_STM32_ALTERNATE(n))
+#define PAL_MODE_ALTERNATE_OPENDRAIN(n) (PAL_STM32_MODE_ALTERNATE | \
+ PAL_STM32_OTYPE_OPENDRAIN | \
+ PAL_STM32_ALTERNATE(n))
/*===========================================================================*/
/* I/O Ports Types and constants. */
@@ -209,6 +171,10 @@ typedef struct {
uint32_t pupdr;
/** Initial value for ODR register.*/
uint32_t odr;
+ /** Initial value for AFRL register.*/
+ uint32_t afrl;
+ /** Initial value for AFRH register.*/
+ uint32_t afrh;
} stm32_gpio_setup_t;
/**
@@ -243,6 +209,10 @@ typedef struct {
/** @brief Port H setup data.*/
stm32_gpio_setup_t PHData;
#endif
+#if STM32_HAS_GPIOI
+ /** @brief Port I setup data.*/
+ stm32_gpio_setup_t PIData;
+#endif
} PALConfig;
/**
@@ -329,6 +299,13 @@ typedef GPIO_TypeDef * ioportid_t;
#define IOPORT7 GPIOG
#endif
+/**
+ * @brief GPIO port H identifier.
+ */
+#if STM32_HAS_GPIOH || defined(__DOXYGEN__)
+#define IOPORT8 GPIOH
+#endif
+
/*===========================================================================*/
/* Implementation, some of the following macros could be implemented as */
/* functions, please put them in a file named ioports_lld.c if so. */