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
+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