From 941545ea7ef2de8723c6b12eb63340a54ddb5de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Sat, 12 Dec 2020 00:06:08 +0100 Subject: [PATCH] Move to pinmux based on devicetree --- boards/arm/mppt_1210_hus/CMakeLists.txt | 9 --- boards/arm/mppt_1210_hus/mppt_1210_hus.dts | 10 +++ boards/arm/mppt_1210_hus/pinmux.c | 59 ------------------ boards/arm/mppt_2420_hc/CMakeLists.txt | 9 --- boards/arm/mppt_2420_hc/mppt_2420_hc.dts | 12 ++++ boards/arm/mppt_2420_hc/pinmux.c | 62 ------------------- boards/arm/mppt_2420_hpx/CMakeLists.txt | 9 --- boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts | 17 ++++-- boards/arm/mppt_2420_hpx/pinmux.c | 67 -------------------- boards/arm/mppt_2420_lc/CMakeLists.txt | 9 --- boards/arm/mppt_2420_lc/mppt_2420_lc.dts | 12 ++++ boards/arm/mppt_2420_lc/pinmux.c | 71 ---------------------- boards/arm/mppt_2420_rc/CMakeLists.txt | 9 --- boards/arm/mppt_2420_rc/mppt_2420_rc.dts | 9 ++- boards/arm/mppt_2420_rc/pinmux.c | 62 ------------------- boards/arm/pwm_2420_lus/CMakeLists.txt | 9 --- boards/arm/pwm_2420_lus/pinmux.c | 52 ---------------- boards/arm/pwm_2420_lus/pwm_2420_lus.dts | 13 ++++ src/half_bridge.cpp | 15 +++++ src/pwm_switch_driver.c | 9 +++ 20 files changed, 92 insertions(+), 432 deletions(-) delete mode 100644 boards/arm/mppt_1210_hus/CMakeLists.txt delete mode 100644 boards/arm/mppt_1210_hus/pinmux.c delete mode 100644 boards/arm/mppt_2420_hc/CMakeLists.txt delete mode 100644 boards/arm/mppt_2420_hc/pinmux.c delete mode 100644 boards/arm/mppt_2420_hpx/CMakeLists.txt delete mode 100644 boards/arm/mppt_2420_hpx/pinmux.c delete mode 100644 boards/arm/mppt_2420_lc/CMakeLists.txt delete mode 100644 boards/arm/mppt_2420_lc/pinmux.c delete mode 100644 boards/arm/mppt_2420_rc/CMakeLists.txt delete mode 100644 boards/arm/mppt_2420_rc/pinmux.c delete mode 100644 boards/arm/pwm_2420_lus/CMakeLists.txt delete mode 100644 boards/arm/pwm_2420_lus/pinmux.c diff --git a/boards/arm/mppt_1210_hus/CMakeLists.txt b/boards/arm/mppt_1210_hus/CMakeLists.txt deleted file mode 100644 index ac5a362..0000000 --- a/boards/arm/mppt_1210_hus/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_PINMUX) -zephyr_library() -zephyr_library_sources(pinmux.c) -zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) -endif() - -zephyr_include_directories(.) diff --git a/boards/arm/mppt_1210_hus/mppt_1210_hus.dts b/boards/arm/mppt_1210_hus/mppt_1210_hus.dts index a8dd312..d08f32c 100644 --- a/boards/arm/mppt_1210_hus/mppt_1210_hus.dts +++ b/boards/arm/mppt_1210_hus/mppt_1210_hus.dts @@ -6,6 +6,7 @@ /dts-v1/; #include +#include / { model = "Libre Solar MPPT 1210 HUS"; @@ -156,21 +157,25 @@ }; &usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; current-speed = <115200>; status = "okay"; }; &usart2 { + pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>; current-speed = <115200>; status = "okay"; }; &i2c1 { + pinctrl-0 = <&i2c1_scl_pb6 &i2c1_sda_pb7>; clock-frequency = ; status = "okay"; }; &spi1 { + pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>; cs-gpios = <&gpioa 15 GPIO_ACTIVE_LOW>; status = "okay"; }; @@ -179,6 +184,11 @@ status = "okay"; }; +&timers3 { + status = "okay"; + pinctrl-0 = <&tim3_ch3_pb0 &tim3_ch4_pb1>; +}; + &eeprom { status = "okay"; }; diff --git a/boards/arm/mppt_1210_hus/pinmux.c b/boards/arm/mppt_1210_hus/pinmux.c deleted file mode 100644 index 9335d1c..0000000 --- a/boards/arm/mppt_1210_hus/pinmux.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2019 Martin Jäger / Libre Solar - */ - -#include -#include -#include -#include -#include - -#include - -#define STM32L0_PINMUX_FUNC_PB0_TIM3_CH3 \ - (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL) -#define STM32L0_PINMUX_FUNC_PB1_TIM3_CH4 \ - (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL) - -static const struct pin_config pinconf[] = { - /* TIM3_CH3 and TIM3_CH4 */ - {STM32_PIN_PB0, STM32L0_PINMUX_FUNC_PB0_TIM3_CH3}, - {STM32_PIN_PB1, STM32L0_PINMUX_FUNC_PB1_TIM3_CH4}, -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL - {STM32_PIN_PA9, STM32L0_PINMUX_FUNC_PA9_USART1_TX}, - {STM32_PIN_PA10, STM32L0_PINMUX_FUNC_PA10_USART1_RX}, -#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay) && CONFIG_SERIAL - {STM32_PIN_PA2, STM32L0_PINMUX_FUNC_PA2_USART2_TX}, - {STM32_PIN_PA3, STM32L0_PINMUX_FUNC_PA3_USART2_RX}, -#endif /* CONFIG_SERIAL, usart2 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C - {STM32_PIN_PB6, STM32L0_PINMUX_FUNC_PB6_I2C1_SCL}, - {STM32_PIN_PB7, STM32L0_PINMUX_FUNC_PB7_I2C1_SDA}, -#endif /* CONFIG_I2C, i2c1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI - {STM32_PIN_PB3, STM32L0_PINMUX_FUNC_PB3_SPI1_SCK}, - {STM32_PIN_PB4, STM32L0_PINMUX_FUNC_PB4_SPI1_MISO}, - {STM32_PIN_PB5, STM32L0_PINMUX_FUNC_PB5_SPI1_MOSI}, -#endif /* CONFIG_SPI, spi1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc1), okay) && CONFIG_ADC - {STM32_PIN_PA0, STM32L0_PINMUX_FUNC_PA0_ADC_IN0}, -#endif /* CONFIG_ADC, adc1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dac1), okay) && CONFIG_DAC - {STM32_PIN_PA4, STM32L0_PINMUX_FUNC_PA4_DAC_OUT1}, -#endif /* CONFIG_DAC, dac1 */ -}; - -static int pinmux_stm32_init(const struct device *port) -{ - ARG_UNUSED(port); - - stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf)); - - return 0; -} - -SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, - CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY); diff --git a/boards/arm/mppt_2420_hc/CMakeLists.txt b/boards/arm/mppt_2420_hc/CMakeLists.txt deleted file mode 100644 index ac5a362..0000000 --- a/boards/arm/mppt_2420_hc/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_PINMUX) -zephyr_library() -zephyr_library_sources(pinmux.c) -zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) -endif() - -zephyr_include_directories(.) diff --git a/boards/arm/mppt_2420_hc/mppt_2420_hc.dts b/boards/arm/mppt_2420_hc/mppt_2420_hc.dts index 129db0f..572e4ad 100644 --- a/boards/arm/mppt_2420_hc/mppt_2420_hc.dts +++ b/boards/arm/mppt_2420_hc/mppt_2420_hc.dts @@ -6,6 +6,7 @@ /dts-v1/; #include +#include / { model = "Libre Solar MPPT 2420 HC"; @@ -135,20 +136,24 @@ }; &usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; current-speed = <115200>; status = "okay"; }; &usart2 { + pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>; current-speed = <115200>; status = "okay"; }; &i2c1 { + pinctrl-0 = <&i2c1_scl_pa15 &i2c1_sda_pb7>; status = "okay"; }; &spi1 { + pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>; cs-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>; status = "okay"; }; @@ -177,12 +182,18 @@ status = "okay"; }; +&timers1 { + status = "okay"; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>; +}; + /* TIM8 (CH2) used for charge pump */ &timers8 { status = "okay"; pwm8: pwm { status = "okay"; st,prescaler = <149>; /* reduce counter clock frequency to 1 MHz */ + pinctrl-0 = <&tim8_ch2_pb8>; }; }; @@ -208,6 +219,7 @@ /* // This requires https://github.com/zephyrproject-rtos/zephyr/pull/22832 &can1 { + pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>; bus-speed = <250000>; bus-speed-data = <250000>; sjw = <1>; diff --git a/boards/arm/mppt_2420_hc/pinmux.c b/boards/arm/mppt_2420_hc/pinmux.c deleted file mode 100644 index 505dc5e..0000000 --- a/boards/arm/mppt_2420_hc/pinmux.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2020 Martin Jäger / Libre Solar - */ - -#include -#include -#include -#include -#include - -#include - -/* this should normally go to drivers/pinmux/stm32/pinmux_stm32g4x.h */ -#define STM32G4X_PINMUX_FUNC_PB8_PWM8_CH2 \ - (STM32_PINMUX_ALT_FUNC_10 | STM32_PUSHPULL_NOPULL) - -#define STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1 \ - (STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL) -#define STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N \ - (STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL) - -static const struct pin_config pinconf[] = { - /* USART1 */ - {STM32_PIN_PA9, STM32G4X_PINMUX_FUNC_PA9_USART1_TX}, - {STM32_PIN_PA10, STM32G4X_PINMUX_FUNC_PA10_USART1_RX}, - /* TIM1_CH1 and TIM1_CH1N */ - {STM32_PIN_PA8, STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1}, - {STM32_PIN_PB13, STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N}, - /* PWM for charge pump */ - {STM32_PIN_PB8, STM32G4X_PINMUX_FUNC_PB8_PWM8_CH2}, -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) && CONFIG_SERIAL - {STM32_PIN_PA2, STM32G4X_PINMUX_FUNC_PA2_USART2_TX}, - {STM32_PIN_PA3, STM32G4X_PINMUX_FUNC_PA3_USART2_RX}, -#endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C - {STM32_PIN_PA15, STM32G4X_PINMUX_FUNC_PA15_I2C1_SCL}, - {STM32_PIN_PB7, STM32G4X_PINMUX_FUNC_PB7_I2C1_SDA}, -#endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI - {STM32_PIN_PB3, STM32G4X_PINMUX_FUNC_PB3_SPI1_SCK}, - {STM32_PIN_PB4, STM32G4X_PINMUX_FUNC_PB4_SPI1_MISO}, - {STM32_PIN_PB5, STM32G4X_PINMUX_FUNC_PB5_SPI1_MOSI}, -#endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) && CONFIG_CAN - {STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_FDCAN1_RX}, - {STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_FDCAN1_TX}, -#endif -}; - -static int pinmux_stm32_init(const struct device *port) -{ - ARG_UNUSED(port); - - stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf)); - - return 0; -} - -SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, - CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY); diff --git a/boards/arm/mppt_2420_hpx/CMakeLists.txt b/boards/arm/mppt_2420_hpx/CMakeLists.txt deleted file mode 100644 index ac5a362..0000000 --- a/boards/arm/mppt_2420_hpx/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_PINMUX) -zephyr_library() -zephyr_library_sources(pinmux.c) -zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) -endif() - -zephyr_include_directories(.) diff --git a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts index 022ce46..e0084ad 100644 --- a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts +++ b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts @@ -6,6 +6,7 @@ /dts-v1/; #include +#include / { model = "Libre Solar MPPT 2420 HPX"; @@ -151,28 +152,28 @@ }; &usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; current-speed = <115200>; status = "okay"; }; &usart3 { + pinctrl-0 = <&usart3_tx_pc10 &usart3_rx_pc11>; current-speed = <115200>; status = "okay"; }; &i2c1 { + pinctrl-0 = <&i2c1_scl_pa15 &i2c1_sda_pb7>; status = "okay"; }; &spi1 { + pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>; cs-gpios = <&gpiod 2 GPIO_ACTIVE_LOW>; status = "okay"; }; -&usb { - status = "okay"; -}; - &rtc { status = "okay"; }; @@ -199,11 +200,17 @@ status = "okay"; }; +&timers1 { + status = "okay"; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>; +}; + /* TIM3 (CH2) used for PWM power switch */ &timers3 { status = "okay"; pwm3: pwm { status = "okay"; + pinctrl-0 = <&tim3_ch2_pc7>; }; }; @@ -213,10 +220,12 @@ pwm8: pwm { status = "okay"; st,prescaler = <149>; /* reduce counter clock frequency to 1 MHz */ + pinctrl-0 = <&tim8_ch1_pc6>; }; }; &i2c3 { + pinctrl-0 = <&i2c3_scl_pc8 &i2c3_sda_pc9>; status = "okay"; clock-frequency = ; eeprom@50 { diff --git a/boards/arm/mppt_2420_hpx/pinmux.c b/boards/arm/mppt_2420_hpx/pinmux.c deleted file mode 100644 index cd10438..0000000 --- a/boards/arm/mppt_2420_hpx/pinmux.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2020 Martin Jäger / Libre Solar - */ - -#include -#include -#include -#include -#include - -#include - -/* this should normally go to drivers/pinmux/stm32/pinmux_stm32g4x.h */ -#define STM32G4X_PINMUX_FUNC_PC6_PWM8_CH1 \ - (STM32_PINMUX_ALT_FUNC_4 | STM32_PUSHPULL_NOPULL) - -#define STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1 \ - (STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL) -#define STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N \ - (STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL) - -static const struct pin_config pinconf[] = { - /* TIM1_CH1 and TIM1_CH1N */ - {STM32_PIN_PA8, STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1}, - {STM32_PIN_PB13, STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N}, -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL - {STM32_PIN_PA9, STM32G4X_PINMUX_FUNC_PA9_USART1_TX}, - {STM32_PIN_PA10, STM32G4X_PINMUX_FUNC_PA10_USART1_RX}, -#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */ - {STM32_PIN_PC6, STM32G4X_PINMUX_FUNC_PC6_PWM8_CH1}, - {STM32_PIN_PC7, STM32G4X_PINMUX_FUNC_PC7_PWM3_CH2}, -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart3), okay) && CONFIG_SERIAL - {STM32_PIN_PC10, STM32G4X_PINMUX_FUNC_PC10_USART3_TX}, - {STM32_PIN_PC11, STM32G4X_PINMUX_FUNC_PC11_USART3_RX}, -#endif /* CONFIG_SERIAL, usart3 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C - {STM32_PIN_PA15, STM32G4X_PINMUX_FUNC_PA15_I2C1_SCL}, - {STM32_PIN_PB7, STM32G4X_PINMUX_FUNC_PB7_I2C1_SDA}, -#endif /* CONFIG_I2C, i2c1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c3), okay) && CONFIG_I2C - {STM32_PIN_PC8, STM32G4X_PINMUX_FUNC_PC8_I2C3_SCL}, - {STM32_PIN_PC9, STM32G4X_PINMUX_FUNC_PC9_I2C3_SDA}, -#endif /* CONFIG_I2C, i2c3 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI - {STM32_PIN_PB3, STM32G4X_PINMUX_FUNC_PB3_SPI1_SCK}, - {STM32_PIN_PB4, STM32G4X_PINMUX_FUNC_PB4_SPI1_MISO}, - {STM32_PIN_PB5, STM32G4X_PINMUX_FUNC_PB5_SPI1_MOSI}, -#endif /* CONFIG_SPI, spi1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb), okay) && CONFIG_USB_DC_STM32 - {STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_USB_DM}, - {STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_USB_DP}, -#endif /* CONFIG_USB_DC_STM32 */ -}; - -static int pinmux_stm32_init(const struct device *port) -{ - ARG_UNUSED(port); - - stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf)); - - return 0; -} - -SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, - CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY); diff --git a/boards/arm/mppt_2420_lc/CMakeLists.txt b/boards/arm/mppt_2420_lc/CMakeLists.txt deleted file mode 100644 index ac5a362..0000000 --- a/boards/arm/mppt_2420_lc/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_PINMUX) -zephyr_library() -zephyr_library_sources(pinmux.c) -zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) -endif() - -zephyr_include_directories(.) diff --git a/boards/arm/mppt_2420_lc/mppt_2420_lc.dts b/boards/arm/mppt_2420_lc/mppt_2420_lc.dts index 64a0ed6..c31747e 100644 --- a/boards/arm/mppt_2420_lc/mppt_2420_lc.dts +++ b/boards/arm/mppt_2420_lc/mppt_2420_lc.dts @@ -6,6 +6,7 @@ /dts-v1/; #include +#include / { model = "Libre Solar MPPT 2420 LC"; @@ -151,22 +152,26 @@ }; &usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; current-speed = <115200>; status = "okay"; }; &usart2 { + pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>; current-speed = <115200>; status = "okay"; }; &i2c1 { status = "okay"; + pinctrl-0 = <&i2c1_scl_pb6 &i2c1_sda_pb7>; clock-frequency = ; }; &i2c2 { status = "okay"; + pinctrl-0 = <&i2c2_scl_pb10 &i2c2_sda_pb11>; clock-frequency = ; eeprom@50 { // Microchip 24AA32A @@ -185,6 +190,7 @@ }; &spi1 { + pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>; cs-gpios = <&gpioc 13 GPIO_ACTIVE_LOW>; status = "okay"; }; @@ -193,7 +199,13 @@ status = "okay"; }; +&timers1 { + status = "okay"; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>; +}; + &can1 { + pinctrl-0 = <&can_rx_pb8 &can_tx_pb9>; bus-speed = <250000>; status = "okay"; }; diff --git a/boards/arm/mppt_2420_lc/pinmux.c b/boards/arm/mppt_2420_lc/pinmux.c deleted file mode 100644 index 2a8af0d..0000000 --- a/boards/arm/mppt_2420_lc/pinmux.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2020 Martin Jäger / Libre Solar - */ - -#include -#include -#include -#include -#include - -#include - -// preliminary fix, as Zephyr doesn't yet include all possible pinmuxes -#ifndef STM32F0_PINMUX_FUNC_PB6_I2C1_SCL -#define STM32F0_PINMUX_FUNC_PB6_I2C1_SCL \ - (STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP) -#endif -#ifndef STM32F0_PINMUX_FUNC_PB7_I2C1_SDA -#define STM32F0_PINMUX_FUNC_PB7_I2C1_SDA \ - (STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP) -#endif - -#define STM32F0_PINMUX_FUNC_PA8_TIM1_CH1 \ - (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL) -#define STM32F0_PINMUX_FUNC_PB13_TIM1_CH1N \ - (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL) - -static const struct pin_config pinconf[] = { - /* TIM1_CH1 and TIM1_CH1N */ - {STM32_PIN_PA8, STM32F0_PINMUX_FUNC_PA8_TIM1_CH1}, - {STM32_PIN_PB13, STM32F0_PINMUX_FUNC_PB13_TIM1_CH1N}, -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL - {STM32_PIN_PA9, STM32F0_PINMUX_FUNC_PA9_USART1_TX}, - {STM32_PIN_PA10, STM32F0_PINMUX_FUNC_PA10_USART1_RX}, -#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay) && CONFIG_SERIAL - {STM32_PIN_PA2, STM32F0_PINMUX_FUNC_PA2_USART2_TX}, - {STM32_PIN_PA3, STM32F0_PINMUX_FUNC_PA3_USART2_RX}, -#endif /* CONFIG_SERIAL, usart2 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C - {STM32_PIN_PB6, STM32F0_PINMUX_FUNC_PB6_I2C1_SCL}, - {STM32_PIN_PB7, STM32F0_PINMUX_FUNC_PB7_I2C1_SDA}, -#endif /* CONFIG_I2C, i2c1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C - {STM32_PIN_PB10, STM32F0_PINMUX_FUNC_PB10_I2C2_SCL}, - {STM32_PIN_PB11, STM32F0_PINMUX_FUNC_PB11_I2C2_SDA}, -#endif /* CONFIG_I2C, i2c1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI - {STM32_PIN_PB3, STM32F0_PINMUX_FUNC_PB3_SPI1_SCK}, - {STM32_PIN_PB4, STM32F0_PINMUX_FUNC_PB4_SPI1_MISO}, - {STM32_PIN_PB5, STM32F0_PINMUX_FUNC_PB5_SPI1_MOSI}, -#endif /* CONFIG_SPI, spi1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) && CONFIG_CAN - {STM32_PIN_PB8, STM32F0_PINMUX_FUNC_PB8_FDCAN_RX}, - {STM32_PIN_PB9, STM32F0_PINMUX_FUNC_PB9_FDCAN_TX}, -#endif /* CONFIG_CAN, can1 */ -}; - -static int pinmux_stm32_init(const struct device *port) -{ - ARG_UNUSED(port); - - stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf)); - - return 0; -} - -SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, - CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY); diff --git a/boards/arm/mppt_2420_rc/CMakeLists.txt b/boards/arm/mppt_2420_rc/CMakeLists.txt deleted file mode 100644 index ac5a362..0000000 --- a/boards/arm/mppt_2420_rc/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_PINMUX) -zephyr_library() -zephyr_library_sources(pinmux.c) -zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) -endif() - -zephyr_include_directories(.) diff --git a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts index dc3242b..1412d6c 100644 --- a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts +++ b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts @@ -6,6 +6,7 @@ /dts-v1/; #include +#include / { model = "Libre Solar MPPT 2420 RC"; @@ -122,22 +123,26 @@ }; &usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; current-speed = <115200>; status = "okay"; }; &usart2 { + pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>; current-speed = <115200>; status = "okay"; }; &spi1 { + pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>; cs-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>; status = "okay"; }; -&rtc { +&timers1 { status = "okay"; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>; }; &flash0 { @@ -165,6 +170,7 @@ &i2c1 { /* shared between UEXT and EEPROM */ status = "okay"; + pinctrl-0 = <&i2c1_scl_pa15 &i2c1_sda_pb7>; clock-frequency = ; eeprom@50 { // Microchip 24AA32A @@ -185,6 +191,7 @@ /* // This requires https://github.com/zephyrproject-rtos/zephyr/pull/22832 &can1 { + pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>; bus-speed = <250000>; bus-speed-data = <250000>; sjw = <1>; diff --git a/boards/arm/mppt_2420_rc/pinmux.c b/boards/arm/mppt_2420_rc/pinmux.c deleted file mode 100644 index fcb546c..0000000 --- a/boards/arm/mppt_2420_rc/pinmux.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2020 Martin Jäger / Libre Solar - */ - -#include -#include -#include -#include -#include - -#include - -#define STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1 \ - (STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL) -#define STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N \ - (STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL) - -static const struct pin_config pinconf[] = { - /* USART1 */ - {STM32_PIN_PA9, STM32G4X_PINMUX_FUNC_PA9_USART1_TX}, - {STM32_PIN_PA10, STM32G4X_PINMUX_FUNC_PA10_USART1_RX}, - /* USART2 */ - {STM32_PIN_PA2, STM32G4X_PINMUX_FUNC_PA2_USART2_TX}, - {STM32_PIN_PA3, STM32G4X_PINMUX_FUNC_PA3_USART2_RX}, - /* TIM1_CH1 and TIM1_CH1N */ - {STM32_PIN_PA8, STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1}, - {STM32_PIN_PB13, STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N}, -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C - {STM32_PIN_PA15, STM32G4X_PINMUX_FUNC_PA15_I2C1_SCL}, - {STM32_PIN_PB7, STM32G4X_PINMUX_FUNC_PB7_I2C1_SDA}, -#endif /* CONFIG_I2C, i2c1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI - {STM32_PIN_PB3, STM32G4X_PINMUX_FUNC_PB3_SPI1_SCK}, - {STM32_PIN_PB4, STM32G4X_PINMUX_FUNC_PB4_SPI1_MISO}, - {STM32_PIN_PB5, STM32G4X_PINMUX_FUNC_PB5_SPI1_MOSI}, -#endif /* CONFIG_SPI, spi1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb), okay) && CONFIG_USB_DC_STM32 - {STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_USB_DM}, - {STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_USB_DP}, -#endif /* CONFIG_USB_DC_STM32 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) && CONFIG_CAN - {STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_FDCAN1_RX}, - {STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_FDCAN1_TX}, -#endif -#if defined(CONFIG_USB_DC_STM32) && DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) -#error "PINMUX does not allow concurrent USB and CAN." -#endif -}; - -static int pinmux_stm32_init(const struct device *port) -{ - ARG_UNUSED(port); - - stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf)); - - return 0; -} - -SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, - CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY); diff --git a/boards/arm/pwm_2420_lus/CMakeLists.txt b/boards/arm/pwm_2420_lus/CMakeLists.txt deleted file mode 100644 index ac5a362..0000000 --- a/boards/arm/pwm_2420_lus/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_PINMUX) -zephyr_library() -zephyr_library_sources(pinmux.c) -zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) -endif() - -zephyr_include_directories(.) diff --git a/boards/arm/pwm_2420_lus/pinmux.c b/boards/arm/pwm_2420_lus/pinmux.c deleted file mode 100644 index 6c6a082..0000000 --- a/boards/arm/pwm_2420_lus/pinmux.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include - -#include - -/* this should normally go to drivers/pinmux/stm32/pinmux_stm32l0.h */ -#define STM32L0_PINMUX_FUNC_PB1_PWM3_CH4 \ - (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL) - -static const struct pin_config pinconf[] = { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm3), okay) - {STM32_PIN_PB1, STM32L0_PINMUX_FUNC_PB1_PWM3_CH4}, -#endif /* CONFIG_PWM, pwm3 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL - {STM32_PIN_PA9, STM32L0_PINMUX_FUNC_PA9_USART1_TX}, - {STM32_PIN_PA10, STM32L0_PINMUX_FUNC_PA10_USART1_RX}, -#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay) && CONFIG_SERIAL - {STM32_PIN_PA2, STM32L0_PINMUX_FUNC_PA2_USART2_TX}, - {STM32_PIN_PA3, STM32L0_PINMUX_FUNC_PA3_USART2_RX}, -#endif /* CONFIG_SERIAL, usart2 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C - {STM32_PIN_PB6, STM32L0_PINMUX_FUNC_PB6_I2C1_SCL}, - {STM32_PIN_PB7, STM32L0_PINMUX_FUNC_PB7_I2C1_SDA}, -#endif /* CONFIG_I2C, i2c1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI - {STM32_PIN_PB3, STM32L0_PINMUX_FUNC_PB3_SPI1_SCK}, - {STM32_PIN_PA11, STM32L0_PINMUX_FUNC_PA11_SPI1_MISO}, - {STM32_PIN_PA12, STM32L0_PINMUX_FUNC_PA12_SPI1_MOSI}, -#endif /* CONFIG_SPI, spi1 */ -}; - -static int pinmux_stm32_init(const struct device *port) -{ - ARG_UNUSED(port); - - stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf)); - - return 0; -} - -SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, - CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY); diff --git a/boards/arm/pwm_2420_lus/pwm_2420_lus.dts b/boards/arm/pwm_2420_lus/pwm_2420_lus.dts index c9fddbe..d6edeaa 100644 --- a/boards/arm/pwm_2420_lus/pwm_2420_lus.dts +++ b/boards/arm/pwm_2420_lus/pwm_2420_lus.dts @@ -6,6 +6,7 @@ /dts-v1/; #include +#include / { model = "Libre Solar PWM 2420 LUS"; @@ -169,21 +170,25 @@ }; &usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; current-speed = <115200>; status = "okay"; }; &usart2 { + pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>; current-speed = <115200>; status = "okay"; }; &i2c1 { + pinctrl-0 = <&i2c1_scl_pb6 &i2c1_sda_pb7>; status = "okay"; clock-frequency = ; }; &spi1 { + pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>; cs-gpios = <&gpioa 15 GPIO_ACTIVE_LOW>; status = "okay"; }; @@ -192,6 +197,14 @@ status = "okay"; }; +&timers3 { + status = "okay"; + pwm3: pwm { + status = "okay"; + pinctrl-0 = <&tim3_ch4_pb1>; + }; +}; + &eeprom { status = "okay"; }; diff --git a/src/half_bridge.cpp b/src/half_bridge.cpp index f352ebf..4be742f 100644 --- a/src/half_bridge.cpp +++ b/src/half_bridge.cpp @@ -12,6 +12,13 @@ #include "mcu.h" +#ifndef UNIT_TEST +#include +#include + +#define DT_DRV_COMPAT st_stm32_timers +#endif + #if DT_NODE_EXISTS(DT_PATH(dcdc)) static uint16_t tim_ccr_min; // capture/compare register min/max @@ -39,8 +46,12 @@ static uint16_t clamp_ccr(uint16_t ccr_target) #if PWM_TIMER_ADDR == TIM3_BASE +static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_PINCTRL(timers3, 0); + static void tim_init_registers(int freq_kHz) { + stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), PWM_TIMER_ADDR); + // Enable TIM3 clock RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; @@ -114,8 +125,12 @@ bool half_bridge_enabled() #elif PWM_TIMER_ADDR == TIM1_BASE +static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_PINCTRL(timers1, 0); + static void tim_init_registers(int freq_kHz) { + stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), PWM_TIMER_ADDR); + // Enable TIM1 clock RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; diff --git a/src/pwm_switch_driver.c b/src/pwm_switch_driver.c index 9a93fa0..196025d 100644 --- a/src/pwm_switch_driver.c +++ b/src/pwm_switch_driver.c @@ -23,6 +23,11 @@ #include #include +#include +#include + +#define DT_DRV_COMPAT st_stm32_pwm + // all PWM charge controllers use TIM3 at the moment static TIM_TypeDef *tim = TIM3; @@ -53,6 +58,8 @@ static TIM_TypeDef *tim = TIM3; #define PWM_GPIO_PIN_HIGH (GPIOC->IDR & GPIO_IDR_ID7) #endif +static const struct soc_gpio_pinctrl pwm_pinctrl[] = ST_STM32_DT_PINCTRL(pwm3, 0); + static bool _pwm_active; static int _pwm_resolution; @@ -69,6 +76,8 @@ static void TIM3_IRQHandler(void *args) void pwm_signal_init_registers(int freq_Hz) { + stm32_dt_pinctrl_configure(pwm_pinctrl, ARRAY_SIZE(pwm_pinctrl), (uint32_t)tim); + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3); // Set timer clock to 10 kHz