From 2154a1cb72612ce70c181a5432678fa22c61ed70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Fri, 21 Feb 2020 18:25:28 +0100 Subject: [PATCH] Add charge-pump driver for HS load switch --- boards/arm/mppt_2420_hpx/Kconfig.defconfig | 3 ++- boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts | 21 +++++++++++++++++++++ boards/arm/mppt_2420_hpx/pinmux.c | 9 +++++++++ src/load_drv.cpp | 17 +++++++++++++++++ zephyr/prj.conf | 2 ++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/boards/arm/mppt_2420_hpx/Kconfig.defconfig b/boards/arm/mppt_2420_hpx/Kconfig.defconfig index ea4c886..e7f97ae 100644 --- a/boards/arm/mppt_2420_hpx/Kconfig.defconfig +++ b/boards/arm/mppt_2420_hpx/Kconfig.defconfig @@ -40,8 +40,9 @@ endif # I2C if PWM -config PWM_STM32_2 +config PWM_STM32_3 default y + depends on PWM endif # PWM diff --git a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts index dcbedd0..ec9ea3c 100644 --- a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts +++ b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts @@ -57,6 +57,17 @@ }; }; + pwmouts { + compatible = "pwm-out"; + + charge_pump: charge_pump { + pwms = <&{/soc/timers@40000400/pwm} 1 4>; /* TIM3 */ + /* originally planned TIM8 not working with current Zephyr driver */ + /* pwms = <&{/soc/timers@40013400/pwm} 1 4>; */ + label = "Charge pump for HS MOSFET drivers"; + }; + }; + switches { compatible = "switch"; load { @@ -70,6 +81,7 @@ uext-uart = &usart2; spi-uext = &spi1; i2c-uext = &i2c1; + pwm-cp = &charge_pump; }; }; @@ -133,3 +145,12 @@ &adc2 { status = "okay"; }; + +/* for charge pump and PWM solar input */ +&timers3 { + status = "okay"; + + pwm { + status = "okay"; + }; +}; \ No newline at end of file diff --git a/boards/arm/mppt_2420_hpx/pinmux.c b/boards/arm/mppt_2420_hpx/pinmux.c index f4f35d1..13037eb 100644 --- a/boards/arm/mppt_2420_hpx/pinmux.c +++ b/boards/arm/mppt_2420_hpx/pinmux.c @@ -12,6 +12,9 @@ #include +#define STM32G4X_PINMUX_FUNC_PC6_PWM8_CH1 \ + (STM32_PINMUX_ALT_FUNC_4 | STM32_PUSHPULL_NOPULL) + static const struct pin_config pinconf[] = { #ifdef CONFIG_UART_1 {STM32_PIN_PA9, STM32G4X_PINMUX_FUNC_PA9_USART1_TX}, @@ -32,6 +35,12 @@ static const struct pin_config pinconf[] = { #ifdef CONFIG_PWM_STM32_2 {STM32_PIN_PA5, STM32G4X_PINMUX_FUNC_PA5_PWM2_CH1}, #endif /* CONFIG_PWM_STM32_2 */ +#ifdef CONFIG_PWM_STM32_3 + {STM32_PIN_PC6, STM32G4X_PINMUX_FUNC_PC6_PWM3_CH1}, +#endif /* CONFIG_PWM_STM32_3 */ +#ifdef CONFIG_PWM_STM32_8 + {STM32_PIN_PC6, STM32G4X_PINMUX_FUNC_PC6_PWM8_CH1}, +#endif /* CONFIG_PWM_STM32_8 */ #ifdef CONFIG_SPI_1 /* SPI1 on the Arduino connectors pins A2, D3, D11, D12 */ #ifdef CONFIG_SPI_STM32_USE_HW_SS diff --git a/src/load_drv.cpp b/src/load_drv.cpp index 49dc7ec..5d0bc45 100644 --- a/src/load_drv.cpp +++ b/src/load_drv.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #if defined(CONFIG_SOC_SERIES_STM32L0X) #include @@ -231,6 +232,19 @@ void usb_out_set(bool status) #endif } +void load_cp_enable() +{ +#ifdef DT_PWM_OUT_CHARGE_PUMP_PWMS_CONTROLLER + struct device *pwm_dev; + pwm_dev = device_get_binding(DT_PWM_OUT_CHARGE_PUMP_PWMS_CONTROLLER); + if (!pwm_dev) { + print_error("Cannot find %s!\n", DT_PWM_OUT_CHARGE_PUMP_PWMS_CONTROLLER); + return; + } + pwm_pin_set_usec(pwm_dev, DT_PWM_OUT_CHARGE_PUMP_PWMS_CHANNEL, 200, 100, 0); +#endif +} + void load_out_init() { #ifdef DT_SWITCH_LOAD_GPIOS_CONTROLLER @@ -239,6 +253,9 @@ void load_out_init() // analog comparator to detect short circuits and trigger immediate load switch-off short_circuit_comp_init(); + + // enable charge pump for high-side switches (if existing) + load_cp_enable(); } void usb_out_init() diff --git a/zephyr/prj.conf b/zephyr/prj.conf index 16d7342..0de7ec0 100644 --- a/zephyr/prj.conf +++ b/zephyr/prj.conf @@ -12,6 +12,8 @@ CONFIG_I2C_1=y CONFIG_ADC=y CONFIG_ADC_1=y +CONFIG_PWM=y + # disable log by default to save memory for STM32F0 with little RAM CONFIG_LOG=y CONFIG_LOG_MINIMAL=y