Move to pinmux based on devicetree

This commit is contained in:
Martin Jäger
2021-02-04 17:28:51 +01:00
parent 0f109297e4
commit 941545ea7e
20 changed files with 92 additions and 432 deletions
-9
View File
@@ -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(.)
@@ -6,6 +6,7 @@
/dts-v1/;
#include <st/l0/stm32l072Xz.dtsi>
#include <st/l0/stm32l072r(b-z)tx-pinctrl.dtsi>
/ {
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 = <I2C_BITRATE_FAST>;
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";
};
-59
View File
@@ -1,59 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2019 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
#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);
-9
View File
@@ -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(.)
+12
View File
@@ -6,6 +6,7 @@
/dts-v1/;
#include <st/g4/stm32g431Xb.dtsi>
#include <st/g4/stm32g431c(6-8-b)tx-pinctrl.dtsi>
/ {
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>;
-62
View File
@@ -1,62 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
/* 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);
-9
View File
@@ -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(.)
+13 -4
View File
@@ -6,6 +6,7 @@
/dts-v1/;
#include <st/g4/stm32g431Xb.dtsi>
#include <st/g4/stm32g431r(6-8-b)tx-pinctrl.dtsi>
/ {
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 = <I2C_BITRATE_STANDARD>;
eeprom@50 {
-67
View File
@@ -1,67 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
/* 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);
-9
View File
@@ -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(.)
+12
View File
@@ -6,6 +6,7 @@
/dts-v1/;
#include <st/f0/stm32f072Xb.dtsi>
#include <st/f0/stm32f072c(8-b)tx-pinctrl.dtsi>
/ {
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 = <I2C_BITRATE_FAST>;
};
&i2c2 {
status = "okay";
pinctrl-0 = <&i2c2_scl_pb10 &i2c2_sda_pb11>;
clock-frequency = <I2C_BITRATE_STANDARD>;
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";
};
-71
View File
@@ -1,71 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
// 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);
-9
View File
@@ -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(.)
+8 -1
View File
@@ -6,6 +6,7 @@
/dts-v1/;
#include <st/g4/stm32g431Xb.dtsi>
#include <st/g4/stm32g431c(6-8-b)tx-pinctrl.dtsi>
/ {
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 = <I2C_BITRATE_STANDARD>;
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>;
-62
View File
@@ -1,62 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
#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);
-9
View File
@@ -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(.)
-52
View File
@@ -1,52 +0,0 @@
/*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
/* 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);
+13
View File
@@ -6,6 +6,7 @@
/dts-v1/;
#include <st/l0/stm32l072Xz.dtsi>
#include <st/l0/stm32l072r(b-z)tx-pinctrl.dtsi>
/ {
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 = <I2C_BITRATE_FAST>;
};
&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";
};
+15
View File
@@ -12,6 +12,13 @@
#include "mcu.h"
#ifndef UNIT_TEST
#include <soc.h>
#include <pinmux/stm32/pinmux_stm32.h>
#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;
+9
View File
@@ -23,6 +23,11 @@
#include <stm32_ll_rcc.h>
#include <stm32_ll_bus.h>
#include <soc.h>
#include <pinmux/stm32/pinmux_stm32.h>
#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