Skip to content

Commit

Permalink
Merge pull request #6714 from OTAkeys/pr/stm32_unify_gpio
Browse files Browse the repository at this point in the history
cpu/stm32_common: unify gpio driver
  • Loading branch information
lebrush authored Mar 13, 2017
2 parents 28ce575 + c302b76 commit 2af148d
Show file tree
Hide file tree
Showing 33 changed files with 181 additions and 1,427 deletions.
12 changes: 6 additions & 6 deletions boards/f4vi1/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ extern "C" {
#define LED1_MASK (1 << 3)
#define LED2_MASK (1 << 2)

#define LED0_ON (LED_PORT->BSRRH = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRRL = LED0_MASK)
#define LED0_ON (LED_PORT->BSRR = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (LED_PORT->ODR ^= LED0_MASK)

#define LED1_ON (LED_PORT->BSRRH = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRRL = LED1_MASK)
#define LED1_ON (LED_PORT->BSRR = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRR = (LED1_MASK << 16))
#define LED1_TOGGLE (LED_PORT->ODR ^= LED1_MASK)

#define LED2_ON (LED_PORT->BSRRH = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRRL = LED2_MASK)
#define LED2_ON (LED_PORT->BSRR = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRR = (LED2_MASK << 16))
#define LED2_TOGGLE (LED_PORT->ODR ^= LED2_MASK)
/** @} */

Expand Down
4 changes: 2 additions & 2 deletions boards/limifrog-v1/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ extern "C" {
#define LED0_PORT (GPIOC)
#define LED0_MASK (1 << 3)

#define LED0_ON (LED0_PORT->BSRRL = LED0_MASK)
#define LED0_OFF (LED0_PORT->BSRRH = LED0_MASK)
#define LED0_ON (LED0_PORT->BSRR = LED0_MASK)
#define LED0_OFF (LED0_PORT->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (LED0_PORT->ODR ^= LED0_MASK)
/** @} */

Expand Down
20 changes: 4 additions & 16 deletions boards/msbiot/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "board.h"
#include "periph/gpio.h"

static void leds_init(void);

Expand All @@ -44,20 +45,7 @@ void board_init(void)
*/
static void leds_init(void)
{
/* enable clock for port GPIOB */
periph_clk_en(AHB1, RCC_AHB1ENR_GPIOBEN);

/* set output speed to 50MHz */
LED_PORT->OSPEEDR &= ~(0xF0030000);
LED_PORT->OSPEEDR |= 0xA0020000;
/* set output type to push-pull */
LED_PORT->OTYPER &= ~(0x0000C100);
/* configure pins as general outputs */
LED_PORT->MODER &= ~(0xF0030000);
LED_PORT->MODER |= 0x50010000;
/* disable pull resistors */
LED_PORT->PUPDR &= ~(0xF0030000);

/* turn all LEDs off */
LED_PORT->BSRRL = 0xC100;
gpio_init(GPIO_PIN(PORT_B, 8), GPIO_OUT);
gpio_init(GPIO_PIN(PORT_B, 14), GPIO_OUT);
gpio_init(GPIO_PIN(PORT_B, 15), GPIO_OUT);
}
12 changes: 6 additions & 6 deletions boards/msbiot/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ extern "C" {
#define LED1_MASK (1 << 14)
#define LED2_MASK (1 << 15)

#define LED0_ON (LED_PORT->BSRRH = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRRL = LED0_MASK)
#define LED0_ON (LED_PORT->BSRR = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (LED_PORT->ODR ^= LED0_MASK)

#define LED1_ON (LED_PORT->BSRRH = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRRL = LED1_MASK)
#define LED1_ON (LED_PORT->BSRR = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRR = (LED1_MASK << 16))
#define LED1_TOGGLE (LED_PORT->ODR ^= LED1_MASK)

#define LED2_ON (LED_PORT->BSRRH = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRRL = LED2_MASK)
#define LED2_ON (LED_PORT->BSRR = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRR = (LED2_MASK << 16))
#define LED2_TOGGLE (LED_PORT->ODR ^= LED2_MASK)
/** @} */

Expand Down
17 changes: 3 additions & 14 deletions boards/nucleo-common/include/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,9 @@ extern "C" {

#define LED0_MASK (1 << 5)

#if defined(CPU_FAM_STM32F4)
#define LED_CREG BSRRH
#else
#define LED_CREG BRR
#endif
#if defined(CPU_FAM_STM32F3) || defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L1)
#define LED_SREG BSRRL
#else
#define LED_SREG BSRR
#endif

#define LED0_ON (GPIOA->LED_SREG = LED0_MASK)
#define LED0_OFF (GPIOA->LED_CREG = LED0_MASK)
#define LED0_TOGGLE (GPIOA->ODR ^= LED0_MASK)
#define LED0_ON (GPIOA->BSRR = LED0_MASK)
#define LED0_OFF (GPIOA->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (GPIOA->ODR ^= LED0_MASK)
/** @} */

/**
Expand Down
21 changes: 9 additions & 12 deletions boards/nucleo144-f413/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,23 @@ extern "C" {
* @brief LED pin definitions and handlers
* @{
*/
#define LED_CREG BSRRH
#define LED_SREG BSRRL

#define LED0_PIN GPIO_PIN(PORT_B, 0)
#define LED0_MASK (1 << 0)
#define LED0_ON (GPIOA->LED_SREG = LED0_MASK)
#define LED0_OFF (GPIOA->LED_CREG = LED0_MASK)
#define LED0_TOGGLE (GPIOA->ODR ^= LED0_MASK)
#define LED0_ON (GPIOB->BSRR = LED0_MASK)
#define LED0_OFF (GPIOB->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (GPIOB->ODR ^= LED0_MASK)

#define LED1_PIN GPIO_PIN(PORT_B, 7)
#define LED1_MASK (1 << 7)
#define LED1_OFF (GPIOA->LED_CREG = LED1_MASK)
#define LED1_ON (GPIOA->LED_SREG = LED1_MASK)
#define LED1_TOGGLE (GPIOA->ODR ^= LED1_MASK)
#define LED1_ON (GPIOB->BSRR = LED1_MASK)
#define LED1_OFF (GPIOB->BSRR = (LED1_MASK << 16))
#define LED1_TOGGLE (GPIOB->ODR ^= LED1_MASK)

#define LED2_PIN GPIO_PIN(PORT_B, 14)
#define LED2_MASK (1 << 14)
#define LED2_ON (GPIOA->LED_SREG = LED2_MASK)
#define LED2_OFF (GPIOA->LED_CREG = LED2_MASK)
#define LED2_TOGGLE (GPIOA->ODR ^= LED2_MASK)
#define LED2_ON (GPIOB->BSRR = LED2_MASK)
#define LED2_OFF (GPIOB->BSRR = (LED2_MASK << 16))
#define LED2_TOGGLE (GPIOB->ODR ^= LED2_MASK)
/** @} */

/**
Expand Down
4 changes: 2 additions & 2 deletions boards/nucleo32-f303/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extern "C" {

#define LED0_MASK (1 << 3)

#define LED0_ON (GPIOB->BSRRL = LED0_MASK)
#define LED0_OFF (GPIOB->BSRRH = LED0_MASK)
#define LED0_ON (GPIOB->BSRR = LED0_MASK)
#define LED0_OFF (GPIOB->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (GPIOB->ODR ^= LED0_MASK)
/** @} */

Expand Down
32 changes: 16 additions & 16 deletions boards/stm32f3discovery/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,36 @@ extern "C" {
#define LED6_MASK (1 << 12)
#define LED7_MASK (1 << 13)

#define LED0_ON (LED_PORT->BSRRL = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRRH = LED0_MASK)
#define LED0_ON (LED_PORT->BSRR = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (LED_PORT->ODR ^= LED0_MASK)

#define LED1_ON (LED_PORT->BSRRL = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRRH = LED1_MASK)
#define LED1_ON (LED_PORT->BSRR = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRR = (LED1_MASK << 16))
#define LED1_TOGGLE (LED_PORT->ODR ^= LED1_MASK)

#define LED2_ON (LED_PORT->BSRRL = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRRH = LED2_MASK)
#define LED2_ON (LED_PORT->BSRR = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRR = (LED2_MASK << 16))
#define LED2_TOGGLE (LED_PORT->ODR ^= LED2_MASK)

#define LED3_ON (LED_PORT->BSRRL = LED3_MASK)
#define LED3_OFF (LED_PORT->BSRRH = LED3_MASK)
#define LED3_ON (LED_PORT->BSRR = LED3_MASK)
#define LED3_OFF (LED_PORT->BSRR = (LED3_MASK << 16))
#define LED3_TOGGLE (LED_PORT->ODR ^= LED3_MASK)

#define LED4_ON (LED_PORT->BSRRL = LED4_MASK)
#define LED4_OFF (LED_PORT->BSRRH = LED4_MASK)
#define LED4_ON (LED_PORT->BSRR = LED4_MASK)
#define LED4_OFF (LED_PORT->BSRR = (LED4_MASK << 16))
#define LED4_TOGGLE (LED_PORT->ODR ^= LED4_MASK)

#define LED5_ON (LED_PORT->BSRRL = LED5_MASK)
#define LED5_OFF (LED_PORT->BSRRH = LED5_MASK)
#define LED5_ON (LED_PORT->BSRR = LED5_MASK)
#define LED5_OFF (LED_PORT->BSRR = (LED5_MASK << 16))
#define LED5_TOGGLE (LED_PORT->ODR ^= LED5_MASK)

#define LED6_ON (LED_PORT->BSRRL = LED6_MASK)
#define LED6_OFF (LED_PORT->BSRRH = LED6_MASK)
#define LED6_ON (LED_PORT->BSRR = LED6_MASK)
#define LED6_OFF (LED_PORT->BSRR = (LED6_MASK << 16))
#define LED6_TOGGLE (LED_PORT->ODR ^= LED6_MASK)

#define LED7_ON (LED_PORT->BSRRL = LED7_MASK)
#define LED7_OFF (LED_PORT->BSRRH = LED7_MASK)
#define LED7_ON (LED_PORT->BSRR = LED7_MASK)
#define LED7_OFF (LED_PORT->BSRR = (LED7_MASK << 16))
#define LED7_TOGGLE (LED_PORT->ODR ^= LED7_MASK)
/** @} */

Expand Down
16 changes: 8 additions & 8 deletions boards/stm32f4discovery/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ extern "C" {
#define LED2_MASK (1 << 14)
#define LED3_MASK (1 << 15)

#define LED0_ON (LED_PORT->BSRRL = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRRH = LED0_MASK)
#define LED0_ON (LED_PORT->BSRR = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRR = (LED0_MASK << 16))
#define LED0_TOGGLE (LED_PORT->ODR ^= LED0_MASK)

#define LED1_ON (LED_PORT->BSRRL = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRRH = LED1_MASK)
#define LED1_ON (LED_PORT->BSRR = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRR = (LED1_MASK << 16))
#define LED1_TOGGLE (LED_PORT->ODR ^= LED1_MASK)

#define LED2_ON (LED_PORT->BSRRL = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRRH = LED2_MASK)
#define LED2_ON (LED_PORT->BSRR = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRR = (LED2_MASK << 16))
#define LED2_TOGGLE (LED_PORT->ODR ^= LED2_MASK)

#define LED3_ON (LED_PORT->BSRRL = LED3_MASK)
#define LED3_OFF (LED_PORT->BSRRH = LED3_MASK)
#define LED3_ON (LED_PORT->BSRR = LED3_MASK)
#define LED3_OFF (LED_PORT->BSRR = (LED3_MASK << 16))
#define LED3_TOGGLE (LED_PORT->ODR ^= LED3_MASK)
/** @} */

Expand Down
45 changes: 44 additions & 1 deletion cpu/stm32_common/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Freie Universität Berlin
* 2017 OTA keys S.A.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -14,6 +15,7 @@
* @brief Shared CPU specific definitions for the STM32 family
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Vincent Dupont <vincent@otakeys.com>
*/

#ifndef PERIPH_CPU_COMMON_H
Expand Down Expand Up @@ -120,11 +122,11 @@ typedef enum {
GPIO_AF1, /**< use alternate function 1 */
GPIO_AF2, /**< use alternate function 2 */
GPIO_AF3, /**< use alternate function 3 */
#ifndef CPU_FAM_STM32F0
GPIO_AF4, /**< use alternate function 4 */
GPIO_AF5, /**< use alternate function 5 */
GPIO_AF6, /**< use alternate function 6 */
GPIO_AF7, /**< use alternate function 7 */
#ifndef CPU_FAM_STM32F0
GPIO_AF8, /**< use alternate function 8 */
GPIO_AF9, /**< use alternate function 9 */
GPIO_AF10, /**< use alternate function 10 */
Expand All @@ -137,6 +139,47 @@ typedef enum {
#endif
} gpio_af_t;

#ifndef CPU_FAM_STM32F1
/**
* @brief Generate GPIO mode bitfields
*
* We use 5 bit to encode the mode:
* - bit 0+1: pin mode (input / output)
* - bit 2+3: pull resistor configuration
* - bit 4: output type (0: push-pull, 1: open-drain)
*/
#define GPIO_MODE(io, pr, ot) ((io << 0) | (pr << 2) | (ot << 4))

#ifndef DOXYGEN
/**
* @brief Override GPIO mode options
* @{
*/
#define HAVE_GPIO_MODE_T
typedef enum {
GPIO_IN = GPIO_MODE(0, 0, 0), /**< input w/o pull R */
GPIO_IN_PD = GPIO_MODE(0, 2, 0), /**< input with pull-down */
GPIO_IN_PU = GPIO_MODE(0, 1, 0), /**< input with pull-up */
GPIO_OUT = GPIO_MODE(1, 0, 0), /**< push-pull output */
GPIO_OD = GPIO_MODE(1, 0, 1), /**< open-drain w/o pull R */
GPIO_OD_PU = GPIO_MODE(1, 1, 1) /**< open-drain with pull-up */
} gpio_mode_t;
/** @} */

/**
* @brief Override flank configuration values
* @{
*/
#define HAVE_GPIO_FLANK_T
typedef enum {
GPIO_RISING = 1, /**< emit interrupt on rising flank */
GPIO_FALLING = 2, /**< emit interrupt on falling flank */
GPIO_BOTH = 3 /**< emit interrupt on both flanks */
} gpio_flank_t;
/** @} */
#endif /* ndef DOXYGEN */
#endif /* ndef CPU_FAM_STM32F1 */

/**
* @brief Timer configuration
*/
Expand Down
Loading

0 comments on commit 2af148d

Please sign in to comment.