pinmux: Move STM32 boards to the pinmux model

This moves the STM32 based boards (Nucleo F103RB and STM32 Mini A15) to
the "new" pinmux model.

Change-Id: I190df271a6b83fafeec0b281cd4ee7cf13d7e7db
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
This commit is contained in:
Vinicius Costa Gomes 2016-03-21 17:14:15 -03:00 committed by Anas Nashif
commit d872bb173c
13 changed files with 135 additions and 172 deletions

View file

@ -1,4 +1,4 @@
obj-y += soc.o obj-y += soc.o
obj-$(CONFIG_GPIO) += soc_gpio.o obj-$(CONFIG_GPIO) += soc_gpio.o
obj-$(CONFIG_PINMUX) += soc_pinmux.o soc_config.o obj-$(CONFIG_PINMUX) += soc_config.o

View file

@ -17,7 +17,7 @@
#include "soc.h" #include "soc.h"
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <pinmux/pinmux_stm32.h> #include <pinmux/stm32/pinmux_stm32.h>
#include <drivers/clock_control/stm32_clock_control.h> #include <drivers/clock_control/stm32_clock_control.h>
static const stm32_pin_func_t pin_pa9_funcs[] = { static const stm32_pin_func_t pin_pa9_funcs[] = {

View file

@ -1,42 +0,0 @@
/*
* Copyright (c) 2016 Open-RnD Sp. z o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @brief
*
* Based on reference manual:
* STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and STM32F107xx
* advanced ARM ® -based 32-bit MCUs
*
* Chapter 9: General-purpose and alternate-function I/Os
* (GPIOs and AFIOs)
*/
#include "soc.h"
#include <pinmux/pinmux_stm32.h>
#include <gpio/gpio_stm32.h>
int stm32_pin_configure(int pin, int func)
{
/* determine IO port registers location */
uint32_t offset = STM32_PORT(pin) * GPIO_REG_SIZE;
uint8_t *port_base = (uint8_t *)(GPIO_PORTS_BASE + offset);
/* not much here, on STM32F10x the alternate function is
* controller by setting up GPIO pins in specific mode.
*/
return stm32_gpio_configure((uint32_t *)port_base, STM32_PIN(pin), func);
}

View file

@ -14,27 +14,3 @@
* limitations under the License. * limitations under the License.
*/ */
#include <pinmux/pinmux_stm32.h>
/* pin assignments for NUCLEO-F103RB board */
static const struct pin_config pinconf[] = {
#ifdef CONFIG_UART_STM32_PORT_0
{STM32_PIN_PA9, STM32F1_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32F1_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_UART_STM32_PORT_0 */
#ifdef CONFIG_UART_STM32_PORT_1
{STM32_PIN_PA2, STM32F1_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32F1_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_UART_STM32_PORT_1 */
#ifdef CONFIG_UART_STM32_PORT_2
{STM32_PIN_PB10, STM32F1_PINMUX_FUNC_PB10_USART3_TX},
{STM32_PIN_PB11, STM32F1_PINMUX_FUNC_PB11_USART3_RX},
#endif /* CONFIG_UART_STM32_PORT_2 */
};
const struct pin_config *stm32_board_get_pinconf(size_t *pins)
{
*pins = ARRAY_SIZE(pinconf);
return pinconf;
}

View file

@ -13,28 +13,3 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <pinmux/pinmux_stm32.h>
/* pin assignments for STM32 MINI A15 board */
static const struct pin_config pinconf[] = {
#ifdef CONFIG_UART_STM32_PORT_0
{STM32_PIN_PA9, STM32F1_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32F1_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_UART_STM32_PORT_0 */
#ifdef CONFIG_UART_STM32_PORT_1
{STM32_PIN_PA2, STM32F1_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32F1_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_UART_STM32_PORT_1 */
#ifdef CONFIG_UART_STM32_PORT_2
{STM32_PIN_PB10, STM32F1_PINMUX_FUNC_PB10_USART3_TX},
{STM32_PIN_PB11, STM32F1_PINMUX_FUNC_PB11_USART3_RX},
#endif /* CONFIG_UART_STM32_PORT_2 */
};
const struct pin_config *stm32_board_get_pinconf(size_t *pins)
{
*pins = ARRAY_SIZE(pinconf);
return pinconf;
}

View file

@ -21,7 +21,7 @@
#include <soc.h> #include <soc.h>
#include <gpio.h> #include <gpio.h>
#include <clock_control/stm32_clock_control.h> #include <clock_control/stm32_clock_control.h>
#include <pinmux/pinmux_stm32.h> #include <pinmux/stm32/pinmux_stm32.h>
#include <pinmux.h> #include <pinmux.h>
#include <gpio/gpio_stm32.h> #include <gpio/gpio_stm32.h>
#include <misc/util.h> #include <misc/util.h>

View file

@ -23,7 +23,7 @@
#include <clock_control/stm32_clock_control.h> #include <clock_control/stm32_clock_control.h>
#include <pinmux/pinmux_stm32.h> #include <pinmux/stm32/pinmux_stm32.h>
#include <gpio.h> #include <gpio.h>
/** /**

View file

@ -2,7 +2,9 @@ ccflags-y +=-I$(srctree)/drivers
# Board initialization # Board initialization
obj-$(CONFIG_PINMUX_K64) += frdm_k64f/pinmux_k64.o frdm_k64f/pinmux_board_frdm_k64f.o obj-$(CONFIG_PINMUX_K64) += frdm_k64f/pinmux_k64.o frdm_k64f/pinmux_board_frdm_k64f.o
obj-$(CONFIG_PINMUX_STM32) += pinmux_stm32.o obj-$(CONFIG_PINMUX_STM32) += stm32/pinmux_stm32.o
obj-$(CONFIG_BOARD_NUCLEO_F103RB) += stm32/pinmux_board_nucleo_f103rb.o
obj-$(CONFIG_BOARD_STM32_MINI_A15) += stm32/pinmux_board_stm32_mini_a15.o
obj-$(CONFIG_BOARD_ARDUINO_101) += quark_mcu/pinmux_board_arduino_101.o obj-$(CONFIG_BOARD_ARDUINO_101) += quark_mcu/pinmux_board_arduino_101.o
obj-$(CONFIG_BOARD_ARDUINO_DUE) += sam3x/pinmux_board_arduino_due.o obj-$(CONFIG_BOARD_ARDUINO_DUE) += sam3x/pinmux_board_arduino_due.o
obj-$(CONFIG_BOARD_GALILEO) += galileo/pinmux_board_galileo.o galileo/pinmux_galileo.o obj-$(CONFIG_BOARD_GALILEO) += galileo/pinmux_board_galileo.o galileo/pinmux_galileo.o

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2016 Open-RnD Sp. z o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <nanokernel.h>
#include <device.h>
#include <init.h>
#include <pinmux.h>
#include <sys_io.h>
#include "pinmux/pinmux.h"
#include "pinmux_stm32.h"
/* pin assignments for NUCLEO-F103RB board */
static const struct pin_config pinconf[] = {
#ifdef CONFIG_UART_STM32_PORT_0
{STM32_PIN_PA9, STM32F1_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32F1_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_UART_STM32_PORT_0 */
#ifdef CONFIG_UART_STM32_PORT_1
{STM32_PIN_PA2, STM32F1_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32F1_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_UART_STM32_PORT_1 */
#ifdef CONFIG_UART_STM32_PORT_2
{STM32_PIN_PB10, STM32F1_PINMUX_FUNC_PB10_USART3_TX},
{STM32_PIN_PB11, STM32F1_PINMUX_FUNC_PB11_USART3_RX},
#endif /* CONFIG_UART_STM32_PORT_2 */
};
static int pinmux_stm32_init(struct device *port)
{
ARG_UNUSED(port);
stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf));
return 0;
}
SYS_INIT(pinmux_stm32_init, PRIMARY, CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2016 Open-RnD Sp. z o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <nanokernel.h>
#include <device.h>
#include <init.h>
#include <pinmux.h>
#include <sys_io.h>
#include "pinmux/pinmux.h"
#include "pinmux_stm32.h"
/* pin assignments for STM32 MINI A15 board */
static const struct pin_config pinconf[] = {
#ifdef CONFIG_UART_STM32_PORT_0
{STM32_PIN_PA9, STM32F1_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32F1_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_UART_STM32_PORT_0 */
#ifdef CONFIG_UART_STM32_PORT_1
{STM32_PIN_PA2, STM32F1_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32F1_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_UART_STM32_PORT_1 */
#ifdef CONFIG_UART_STM32_PORT_2
{STM32_PIN_PB10, STM32F1_PINMUX_FUNC_PB10_USART3_TX},
{STM32_PIN_PB11, STM32F1_PINMUX_FUNC_PB11_USART3_RX},
#endif /* CONFIG_UART_STM32_PORT_2 */
};
static int pinmux_stm32_init(struct device *port)
{
ARG_UNUSED(port);
stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf));
return 0;
}
SYS_INIT(pinmux_stm32_init, PRIMARY, CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);

View file

@ -26,8 +26,9 @@
#include <soc.h> #include <soc.h>
#include "pinmux.h" #include "pinmux.h"
#include <pinmux.h> #include <pinmux.h>
#include <pinmux/pinmux_stm32.h> #include <gpio/gpio_stm32.h>
#include <clock_control/stm32_clock_control.h> #include <clock_control/stm32_clock_control.h>
#include <pinmux/stm32/pinmux_stm32.h>
/** /**
* @brief enable IO port clock * @brief enable IO port clock
@ -49,6 +50,18 @@ static int enable_port(uint32_t port, struct device *clk)
return clock_control_on(clk, subsys); return clock_control_on(clk, subsys);
} }
static int stm32_pin_configure(int pin, int func)
{
/* determine IO port registers location */
uint32_t offset = STM32_PORT(pin) * GPIO_REG_SIZE;
uint8_t *port_base = (uint8_t *)(GPIO_PORTS_BASE + offset);
/* not much here, on STM32F10x the alternate function is
* controller by setting up GPIO pins in specific mode.
*/
return stm32_gpio_configure((uint32_t *)port_base, STM32_PIN(pin), func);
}
/** /**
* @brief pin setup * @brief pin setup
* *
@ -58,7 +71,7 @@ static int enable_port(uint32_t port, struct device *clk)
* *
* @return 0 on success, error otherwise * @return 0 on success, error otherwise
*/ */
static inline int __pinmux_stm32_set(uint32_t pin, uint32_t func, int _pinmux_stm32_set(uint32_t pin, uint32_t func,
struct device *clk) struct device *clk)
{ {
int config; int config;
@ -74,49 +87,14 @@ static inline int __pinmux_stm32_set(uint32_t pin, uint32_t func,
return stm32_pin_configure(pin, config); return stm32_pin_configure(pin, config);
} }
static int pinmux_stm32_set(struct device *dev,
uint32_t pin, uint32_t func)
{
ARG_UNUSED(dev);
return __pinmux_stm32_set(pin, func, NULL);
}
static int pinmux_stm32_get(struct device *dev,
uint32_t pin, uint32_t *func)
{
return -ENOTSUP;
}
static int pinmux_stm32_input(struct device *dev,
uint32_t pin,
uint8_t func)
{
return -ENOTSUP;
}
static int pinmux_stm32_pullup(struct device *dev,
uint32_t pin,
uint8_t func)
{
return -ENOTSUP;
}
static struct pinmux_driver_api pinmux_stm32_api = {
.set = pinmux_stm32_set,
.get = pinmux_stm32_get,
.pullup = pinmux_stm32_pullup,
.input = pinmux_stm32_input,
};
/** /**
* @brief setup pins according to their assignments * @brief setup pins according to their assignments
* *
* @param pinconf board pin configuration array * @param pinconf board pin configuration array
* @param pins array size * @param pins array size
*/ */
static inline void __setup_pins(const struct pin_config *pinconf, void stm32_setup_pins(const struct pin_config *pinconf,
size_t pins) size_t pins)
{ {
struct device *clk; struct device *clk;
int i; int i;
@ -124,39 +102,7 @@ static inline void __setup_pins(const struct pin_config *pinconf,
clk = device_get_binding(STM32_CLOCK_CONTROL_NAME); clk = device_get_binding(STM32_CLOCK_CONTROL_NAME);
for (i = 0; i < pins; i++) { for (i = 0; i < pins; i++) {
__pinmux_stm32_set(pinconf[i].pin_num, _pinmux_stm32_set(pinconf[i].pin_num,
pinconf[i].mode, clk); pinconf[i].mode, clk);
} }
} }
int pinmux_stm32_init(struct device *port)
{
size_t pins = 0;
const struct pin_config *pinconf;
pinconf = stm32_board_get_pinconf(&pins);
if (pins != 0) {
/* configure pins */
__setup_pins(pinconf, pins);
}
port->driver_api = &pinmux_stm32_api;
return 0;
}
static struct pinmux_config pinmux_stm32_cfg = {
#ifdef CONFIG_SOC_STM32F1X
.base_address = GPIO_PORTS_BASE,
#endif
};
/**
* @brief device init
*
* Device priority set to 2, so that we come after clock_control and
* before any other devices
*/
DEVICE_INIT(pinmux_stm32, STM32_PINMUX_NAME, &pinmux_stm32_init,
NULL, &pinmux_stm32_cfg,
PRIMARY, CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);

View file

@ -24,7 +24,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <clock_control.h> #include <clock_control.h>
#include "pinmux.h" #include "pinmux/pinmux.h"
/** /**
* @brief numerical IDs for IO ports * @brief numerical IDs for IO ports
@ -258,8 +258,11 @@ clock_control_subsys_t stm32_get_port_clock(int port);
* *
* @param pin IO pin, STM32PIN() encoded * @param pin IO pin, STM32PIN() encoded
* @param func IO function encoded * @param func IO function encoded
* @param clk clock control device, for enabling/disabling clock gate
* for the port
*/ */
int stm32_pin_configure(int pin, int func); int _pinmux_stm32_set(uint32_t pin, uint32_t func,
struct device *clk);
/** /**
* @brief helper for obtaining pin configuration for the board * @brief helper for obtaining pin configuration for the board
@ -274,7 +277,8 @@ int stm32_pin_configure(int pin, int func);
* *
* @return array of pin assignments * @return array of pin assignments
*/ */
const struct pin_config *stm32_board_get_pinconf(size_t *pins); void stm32_setup_pins(const struct pin_config *pinconf,
size_t pins);
/* common pinmux device name for all STM32 chips */ /* common pinmux device name for all STM32 chips */
#define STM32_PINMUX_NAME "stm32-pinmux" #define STM32_PINMUX_NAME "stm32-pinmux"