Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32WB0: add timers support #83692

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boards/st/nucleo_wb05kz/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ The Zephyr ``nucleo_wb05kz`` board target supports the following hardware featur
+-----------+------------+-------------------------------------+
| ADC | on-chip | adc |
+-----------+------------+-------------------------------------+
| TIMER | on-chip | counter, pwm |
+-----------+------------+-------------------------------------+
| RADIO | on-chip | Bluetooth Low Energy |
+-----------+------------+-------------------------------------+

Expand Down
22 changes: 22 additions & 0 deletions boards/st/nucleo_wb05kz/nucleo_wb05kz.dts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
};
};

pwmleds: pwmleds {
compatible = "pwm-leds";
status = "okay";
pwm_red_led_1: pwm_led_1 {
pwms = <&pwm2 3 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
};
};

gpio_keys {
compatible = "gpio-keys";
user_button_1: button_0 {
Expand All @@ -62,6 +70,7 @@
led0 = &blue_led_1;
led1 = &green_led_1;
led2 = &red_led_1;
pwm-led0 = &pwm_red_led_1;
sw0 = &user_button_1;
sw1 = &user_button_2;
sw2 = &user_button_3;
Expand Down Expand Up @@ -122,6 +131,19 @@
<&rcc STM32_SRC_SYSCLK SPI3_I2S3_SEL(3)>;
};


&timers2 {
status = "okay";
st,prescaler = <10000>;

pwm2: pwm {
/* PWM on red_led_1 */
pinctrl-0 = <&tim2_ch3_pb2>;
pinctrl-names = "default";
status = "okay";
};
};

&flash0 {
partitions {
compatible = "fixed-partitions";
Expand Down
2 changes: 2 additions & 0 deletions boards/st/nucleo_wb05kz/nucleo_wb05kz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ supported:
- adc
- arduino_i2c
- arduino_spi
- counter
- dma
- gpio
- i2c
- pwm
- spi
- bluetooth
vendor: st
2 changes: 2 additions & 0 deletions boards/st/nucleo_wb07cc/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ The Zephyr ``nucleo_wb07cc`` board target supports the following hardware featur
+-----------+------------+-------------------------------------+
| ADC | on-chip | adc |
+-----------+------------+-------------------------------------+
| TIMER | on-chip | counter, pwm |
+-----------+------------+-------------------------------------+
| RADIO | on-chip | Bluetooth Low Energy |
+-----------+------------+-------------------------------------+

Expand Down
19 changes: 19 additions & 0 deletions boards/st/nucleo_wb07cc/nucleo_wb07cc.dts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
};
};

pwmleds: pwmleds {
compatible = "pwm-leds";
pwm_red_led_1: pwm_red_led_1 {
pwms = <&pwm1 3 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
};
};

gpio_keys {
compatible = "gpio-keys";
user_button_1: button_0 {
Expand All @@ -62,6 +69,7 @@
led0 = &blue_led_1;
led1 = &green_led_1;
led2 = &red_led_1;
pwm-led0 = &pwm_red_led_1;
sw0 = &user_button_1;
sw1 = &user_button_2;
sw2 = &user_button_3;
Expand Down Expand Up @@ -122,6 +130,17 @@
<&rcc STM32_SRC_SYSCLK SPI2_I2S2_SEL(1)>;
};

&timers1 {
status = "okay";
st,prescaler = <10000>;

pwm1: pwm {
status = "okay";
pinctrl-0 = <&tim1_ch3_pb2>;
pinctrl-names = "default";
};
};

&flash0 {
partitions {
compatible = "fixed-partitions";
Expand Down
2 changes: 2 additions & 0 deletions boards/st/nucleo_wb07cc/nucleo_wb07cc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ supported:
- adc
- arduino_i2c
- arduino_spi
- counter
- dma
- gpio
- i2c
- pwm
- spi
- bluetooth
vendor: st
2 changes: 2 additions & 0 deletions boards/st/nucleo_wb09ke/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ The Zephyr ``nucleo_wb09ke`` board target supports the following hardware featur
+-----------+------------+-------------------------------------+
| ADC | on-chip | adc |
+-----------+------------+-------------------------------------+
| TIMER | on-chip | counter, pwm |
+-----------+------------+-------------------------------------+
| RADIO | on-chip | Bluetooth Low Energy |
+-----------+------------+-------------------------------------+

Expand Down
21 changes: 21 additions & 0 deletions boards/st/nucleo_wb09ke/nucleo_wb09ke.dts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
};
};

pwmleds: pwmleds {
compatible = "pwm-leds";
status = "okay";
pwm_red_led_1: pwm_led_1 {
pwms = <&pwm2 3 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
};
};

gpio_keys {
compatible = "gpio-keys";
user_button_1: button_0 {
Expand All @@ -62,6 +70,7 @@
led0 = &blue_led_1;
led1 = &green_led_1;
led2 = &red_led_1;
pwm-led0 = &pwm_red_led_1;
sw0 = &user_button_1;
sw1 = &user_button_2;
sw2 = &user_button_3;
Expand Down Expand Up @@ -122,6 +131,18 @@
<&rcc STM32_SRC_SYSCLK SPI3_I2S3_SEL(3)>;
};

&timers2 {
status = "okay";
st,prescaler = <10000>;

pwm2: pwm {
/* PWM on red_led_1 */
pinctrl-0 = <&tim2_ch3_pb2>;
pinctrl-names = "default";
status = "okay";
};
};

&flash0 {
partitions {
compatible = "fixed-partitions";
Expand Down
2 changes: 2 additions & 0 deletions boards/st/nucleo_wb09ke/nucleo_wb09ke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ supported:
- adc
- arduino_i2c
- arduino_spi
- counter
- dma
- gpio
- i2c
- pwm
- spi
- bluetooth
vendor: st
5 changes: 4 additions & 1 deletion drivers/counter/counter_ll_stm32_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ static int counter_stm32_get_tim_clk(const struct stm32_pclken *pclken, uint32_t
return r;
}

#if defined(CONFIG_SOC_SERIES_STM32H7X)
#if defined(CONFIG_SOC_SERIES_STM32WB0X)
/* Timers are clocked by SYSCLK on STM32WB0 */
apb_psc = 1;
#elif defined(CONFIG_SOC_SERIES_STM32H7X)
if (pclken->bus == STM32_CLOCK_BUS_APB1) {
apb_psc = STM32_D2PPRE1;
} else {
Expand Down
12 changes: 9 additions & 3 deletions drivers/pwm/pwm_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,19 @@ static const uint32_t ch2ll[TIMER_MAX_CH] = {
#endif
};

/** Some stm32 mcus have complementary channels : 3 or 4 */
/** STM32 MCUs have between 1 and 4 complementary channels */
static const uint32_t ch2ll_n[] = {
#if defined(LL_TIM_CHANNEL_CH1N)
LL_TIM_CHANNEL_CH1N,
#if defined(LL_TIM_CHANNEL_CH2N)
LL_TIM_CHANNEL_CH2N,
#if defined(LL_TIM_CHANNEL_CH3N)
LL_TIM_CHANNEL_CH3N,
#if defined(LL_TIM_CHANNEL_CH4N)
/** stm32g4x and stm32u5x have 4 complementary channels */
LL_TIM_CHANNEL_CH4N,
#endif /* LL_TIM_CHANNEL_CH4N */
#endif /* LL_TIM_CHANNEL_CH3N */
#endif /* LL_TIM_CHANNEL_CH2N */
#endif /* LL_TIM_CHANNEL_CH1N */
};
/** Maximum number of complemented timer channels is ARRAY_SIZE(ch2ll_n)*/
Expand Down Expand Up @@ -231,7 +234,10 @@ static int get_tim_clk(const struct stm32_pclken *pclken, uint32_t *tim_clk)
return r;
}

#if defined(CONFIG_SOC_SERIES_STM32H7X)
#if defined(CONFIG_SOC_SERIES_STM32WB0X)
/* Timers are clocked by SYSCLK on STM32WB0 */
apb_psc = 1;
#elif defined(CONFIG_SOC_SERIES_STM32H7X)
if (pclken->bus == STM32_CLOCK_BUS_APB1) {
apb_psc = STM32_D2PPRE1;
} else {
Expand Down
66 changes: 66 additions & 0 deletions dts/arm/st/wb0/stm32wb05.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,71 @@
/ {
soc {
compatible = "st,stm32wb05", "st,stm32wb0", "simple-bus";

timers2: timers@40002000 {
compatible = "st,stm32-timers";
reg = <0x40002000 DT_SIZE_K(1)>;
clocks = <&rcc STM32_CLOCK(APB0, 0)>;
resets = <&rctl STM32_RESET(APB0, 0)>;
interrupts = <10 0>;
interrupt-names = "global";
st,prescaler = <0>;
status = "disabled";

pwm {
compatible = "st,stm32-pwm";
status = "disabled";
#pwm-cells = <3>;
};

counter {
compatible = "st,stm32-counter";
status = "disabled";
};
};

timers16: timers@40005000 {
compatible = "st,stm32-timers";
reg = <0x40005000 DT_SIZE_K(1)>;
clocks = <&rcc STM32_CLOCK(APB0, 1)>;
resets = <&rctl STM32_RESET(APB0, 1)>;
interrupts = <26 0>;
interrupt-names = "global";
st,prescaler = <0>;
status = "disabled";

pwm {
compatible = "st,stm32-pwm";
status = "disabled";
#pwm-cells = <3>;
};

counter {
compatible = "st,stm32-counter";
status = "disabled";
};
};

timers17: timers@40006000 {
compatible = "st,stm32-timers";
reg = <0x40006000 DT_SIZE_K(1)>;
clocks = <&rcc STM32_CLOCK(APB0, 2)>;
resets = <&rctl STM32_RESET(APB0, 2)>;
interrupts = <27 0>;
interrupt-names = "global";
st,prescaler = <0>;
status = "disabled";

pwm {
compatible = "st,stm32-pwm";
status = "disabled";
#pwm-cells = <3>;
};

counter {
compatible = "st,stm32-counter";
status = "disabled";
};
};
};
};
22 changes: 22 additions & 0 deletions dts/arm/st/wb0/stm32wb07.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,27 @@
interrupts = <6 0>;
status = "disabled";
};

timers1: timers@40002000 {
compatible = "st,stm32-timers";
reg = <0x40002000 DT_SIZE_K(1)>;
clocks = <&rcc STM32_CLOCK(APB0, 0)>;
resets = <&rctl STM32_RESET(APB0, 0)>;
interrupts = <10 0>;
interrupt-names = "global";
st,prescaler = <0>;
status = "disabled";

pwm {
compatible = "st,stm32-pwm";
status = "disabled";
#pwm-cells = <3>;
};

counter {
compatible = "st,stm32-counter";
status = "disabled";
};
};
};
};
Loading