diff --git a/arch/arm/soc/st_stm32/stm32f1/Kbuild b/arch/arm/soc/st_stm32/stm32f1/Kbuild index 4844a3a21cd..28d382d305b 100644 --- a/arch/arm/soc/st_stm32/stm32f1/Kbuild +++ b/arch/arm/soc/st_stm32/stm32f1/Kbuild @@ -1,4 +1,4 @@ obj-y += soc.o obj-$(CONFIG_GPIO) += soc_gpio.o -obj-$(CONFIG_PINMUX) += soc_pinmux.o soc_config.o +obj-$(CONFIG_PINMUX) += soc_config.o diff --git a/arch/arm/soc/st_stm32/stm32f1/soc_config.c b/arch/arm/soc/st_stm32/stm32f1/soc_config.c index 465d7107ecf..f069b3db4e4 100644 --- a/arch/arm/soc/st_stm32/stm32f1/soc_config.c +++ b/arch/arm/soc/st_stm32/stm32f1/soc_config.c @@ -17,7 +17,7 @@ #include "soc.h" #include #include -#include +#include #include static const stm32_pin_func_t pin_pa9_funcs[] = { diff --git a/arch/arm/soc/st_stm32/stm32f1/soc_pinmux.c b/arch/arm/soc/st_stm32/stm32f1/soc_pinmux.c deleted file mode 100644 index 9e3ed3f4827..00000000000 --- a/arch/arm/soc/st_stm32/stm32f1/soc_pinmux.c +++ /dev/null @@ -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 -#include - -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); -} diff --git a/boards/nucleo_f103rb/board.c b/boards/nucleo_f103rb/board.c index a734888f89d..fbbc770861e 100644 --- a/boards/nucleo_f103rb/board.c +++ b/boards/nucleo_f103rb/board.c @@ -14,27 +14,3 @@ * limitations under the License. */ -#include - -/* 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; -} diff --git a/boards/stm32_mini_a15/board.c b/boards/stm32_mini_a15/board.c index f4c53cc42a6..cf7031b193f 100644 --- a/boards/stm32_mini_a15/board.c +++ b/boards/stm32_mini_a15/board.c @@ -13,28 +13,3 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include - -/* 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; -} diff --git a/drivers/gpio/gpio_stm32.c b/drivers/gpio/gpio_stm32.c index 6acab3db19a..cfea4ab1e36 100644 --- a/drivers/gpio/gpio_stm32.c +++ b/drivers/gpio/gpio_stm32.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/gpio/gpio_stm32.h b/drivers/gpio/gpio_stm32.h index 25bd0297064..5673cda3b34 100644 --- a/drivers/gpio/gpio_stm32.h +++ b/drivers/gpio/gpio_stm32.h @@ -23,7 +23,7 @@ #include -#include +#include #include /** diff --git a/drivers/pinmux/Makefile b/drivers/pinmux/Makefile index a40d160efca..83a35bcc219 100644 --- a/drivers/pinmux/Makefile +++ b/drivers/pinmux/Makefile @@ -2,7 +2,9 @@ ccflags-y +=-I$(srctree)/drivers # Board initialization 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_DUE) += sam3x/pinmux_board_arduino_due.o obj-$(CONFIG_BOARD_GALILEO) += galileo/pinmux_board_galileo.o galileo/pinmux_galileo.o diff --git a/drivers/pinmux/stm32/pinmux_board_nucleo_f103rb.c b/drivers/pinmux/stm32/pinmux_board_nucleo_f103rb.c new file mode 100644 index 00000000000..5f9a612d841 --- /dev/null +++ b/drivers/pinmux/stm32/pinmux_board_nucleo_f103rb.c @@ -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 +#include +#include +#include +#include +#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); diff --git a/drivers/pinmux/stm32/pinmux_board_stm32_mini_a15.c b/drivers/pinmux/stm32/pinmux_board_stm32_mini_a15.c new file mode 100644 index 00000000000..2bc7a64f0e1 --- /dev/null +++ b/drivers/pinmux/stm32/pinmux_board_stm32_mini_a15.c @@ -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 +#include +#include +#include +#include +#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); diff --git a/drivers/pinmux/pinmux_stm32.c b/drivers/pinmux/stm32/pinmux_stm32.c similarity index 56% rename from drivers/pinmux/pinmux_stm32.c rename to drivers/pinmux/stm32/pinmux_stm32.c index d4484bdc20c..cb7f818497b 100644 --- a/drivers/pinmux/pinmux_stm32.c +++ b/drivers/pinmux/stm32/pinmux_stm32.c @@ -26,8 +26,9 @@ #include #include "pinmux.h" #include -#include +#include #include +#include /** * @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); } +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 * @@ -58,7 +71,7 @@ static int enable_port(uint32_t port, struct device *clk) * * @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) { int config; @@ -74,49 +87,14 @@ static inline int __pinmux_stm32_set(uint32_t pin, uint32_t func, 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 * * @param pinconf board pin configuration array * @param pins array size */ -static inline void __setup_pins(const struct pin_config *pinconf, - size_t pins) +void stm32_setup_pins(const struct pin_config *pinconf, + size_t pins) { struct device *clk; int i; @@ -124,39 +102,7 @@ static inline void __setup_pins(const struct pin_config *pinconf, clk = device_get_binding(STM32_CLOCK_CONTROL_NAME); for (i = 0; i < pins; i++) { - __pinmux_stm32_set(pinconf[i].pin_num, - pinconf[i].mode, clk); + _pinmux_stm32_set(pinconf[i].pin_num, + 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); diff --git a/drivers/pinmux/pinmux_stm32.h b/drivers/pinmux/stm32/pinmux_stm32.h similarity index 97% rename from drivers/pinmux/pinmux_stm32.h rename to drivers/pinmux/stm32/pinmux_stm32.h index cdf35538223..c2925aaf62f 100644 --- a/drivers/pinmux/pinmux_stm32.h +++ b/drivers/pinmux/stm32/pinmux_stm32.h @@ -24,7 +24,7 @@ #include #include #include -#include "pinmux.h" +#include "pinmux/pinmux.h" /** * @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 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 @@ -274,7 +277,8 @@ int stm32_pin_configure(int pin, int func); * * @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 */ #define STM32_PINMUX_NAME "stm32-pinmux" diff --git a/drivers/pinmux/pinmux_stm32f1.h b/drivers/pinmux/stm32/pinmux_stm32f1.h similarity index 100% rename from drivers/pinmux/pinmux_stm32f1.h rename to drivers/pinmux/stm32/pinmux_stm32f1.h