From 5151e8a094b3793861eff3df0867edadc803b96d Mon Sep 17 00:00:00 2001 From: Ioannis Konstantelias Date: Wed, 14 Nov 2018 20:47:25 +0200 Subject: [PATCH] boards: nucleo_l496zg: Add pwm mapping and RTC Supported PWM at pins A0, D3, D5 and D6 which are also Arduino compatible. Also the onboard red LED can be used with PWM. The basic/{fade_led, blink_led} samples to apply to this board seemlessly and operate on the onboard red LED. Also supported RTC. Signed-off-by: Ioannis Konstantelias --- boards/arm/nucleo_l496zg/Kconfig.defconfig | 16 +++++++ boards/arm/nucleo_l496zg/doc/nucleol496zg.rst | 8 ++++ boards/arm/nucleo_l496zg/nucleo_l496zg.dts | 45 +++++++++++++++++++ boards/arm/nucleo_l496zg/nucleo_l496zg.yaml | 1 + .../arm/nucleo_l496zg/nucleo_l496zg_defconfig | 3 -- boards/arm/nucleo_l496zg/pinmux.c | 11 +++++ drivers/pinmux/stm32/pinmux_stm32l4x.h | 11 +++++ samples/basic/blink_led/README.rst | 5 +++ samples/basic/blink_led/sample.yaml | 2 +- samples/basic/fade_led/README.rst | 9 +++- samples/basic/fade_led/sample.yaml | 2 +- 11 files changed, 106 insertions(+), 7 deletions(-) diff --git a/boards/arm/nucleo_l496zg/Kconfig.defconfig b/boards/arm/nucleo_l496zg/Kconfig.defconfig index fbd5ec1994d7fb..69f1eeac5b1977 100644 --- a/boards/arm/nucleo_l496zg/Kconfig.defconfig +++ b/boards/arm/nucleo_l496zg/Kconfig.defconfig @@ -24,4 +24,20 @@ config LPUART_1 endif # SERIAL +if PWM + +config PWM_STM32_1 + default y + +config PWM_STM32_2 + default y + +config PWM_STM32_4 + default y + +config PWM_STM32_15 + default y + +endif # PWM + endif # BOARD_NUCLEO_L496ZG diff --git a/boards/arm/nucleo_l496zg/doc/nucleol496zg.rst b/boards/arm/nucleo_l496zg/doc/nucleol496zg.rst index a80cbc229b6f05..185d1215b8c492 100644 --- a/boards/arm/nucleo_l496zg/doc/nucleol496zg.rst +++ b/boards/arm/nucleo_l496zg/doc/nucleol496zg.rst @@ -121,6 +121,10 @@ The Zephyr nucleo_l496zg board configuration supports the following hardware fea +-----------+------------+-------------------------------------+ | GPIO | on-chip | gpio | +-----------+------------+-------------------------------------+ +| PWM | on-chip | pwm | ++-----------+------------+-------------------------------------+ +| RTC | on-chip | rtc | ++-----------+------------+-------------------------------------+ Other hardware features are not yet supported on this Zephyr port. @@ -142,6 +146,10 @@ Default Zephyr Peripheral Mapping: - UART_2 TX/RX : PD5/PD6 - UART_3 TX/RX : PD8/PD9 - LPUART_1 TX/RX : PG7/PG8 +- PWM_1_CH1: PE9 +- PWM_1_CH2: PE11 +- PWM_1_CH3: PE13 +- PWM_2_CH1: PA0 - USER_PB : PC13 - LD1 : PC7 - LD2 : PB7 diff --git a/boards/arm/nucleo_l496zg/nucleo_l496zg.dts b/boards/arm/nucleo_l496zg/nucleo_l496zg.dts index 0a70ef5cd8e381..cf07c08370f0b0 100644 --- a/boards/arm/nucleo_l496zg/nucleo_l496zg.dts +++ b/boards/arm/nucleo_l496zg/nucleo_l496zg.dts @@ -33,6 +33,14 @@ }; }; + pwmleds { + compatible = "pwm-leds"; + + red_pwm_led: red_pwm_led { + pwms = <&{/soc/timers@40014000/pwm} 1 4>; + }; + }; + gpio_keys { compatible = "gpio-keys"; user_button: button { @@ -45,6 +53,7 @@ led0 = &green_led_1; led1 = &blue_led_2; led2 = &red_led_3; + pwm-led0 = &red_pwm_led; sw0 = &user_button; }; }; @@ -71,3 +80,39 @@ arduino_serial: &lpuart1 {}; pinctrl-names = "default"; status = "ok"; }; + +&timers1 { + status = "ok"; + + pwm { + status = "ok"; + }; +}; + +&timers2 { + status = "ok"; + + pwm { + status = "ok"; + }; +}; + +&timers4 { + status = "ok"; + + pwm { + status = "ok"; + }; +}; + +&timers15 { + status = "ok"; + + pwm { + status = "ok"; + }; +}; + +&rtc { + status = "ok"; +}; diff --git a/boards/arm/nucleo_l496zg/nucleo_l496zg.yaml b/boards/arm/nucleo_l496zg/nucleo_l496zg.yaml index 4c720db3cf4fc1..6b4f8b11cf83d4 100644 --- a/boards/arm/nucleo_l496zg/nucleo_l496zg.yaml +++ b/boards/arm/nucleo_l496zg/nucleo_l496zg.yaml @@ -9,3 +9,4 @@ ram: 320 flash: 1024 supported: - gpio + - pwm diff --git a/boards/arm/nucleo_l496zg/nucleo_l496zg_defconfig b/boards/arm/nucleo_l496zg/nucleo_l496zg_defconfig index f9f3556b206f65..f778c80b1c7a7b 100644 --- a/boards/arm/nucleo_l496zg/nucleo_l496zg_defconfig +++ b/boards/arm/nucleo_l496zg/nucleo_l496zg_defconfig @@ -34,8 +34,5 @@ CONFIG_CLOCK_STM32_APB2_PRESCALER=1 CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -#enable pwm -CONFIG_PWM=n - #enable MPU CONFIG_ARM_MPU=y diff --git a/boards/arm/nucleo_l496zg/pinmux.c b/boards/arm/nucleo_l496zg/pinmux.c index d068d6eed487f8..2e62e81e3fbe22 100644 --- a/boards/arm/nucleo_l496zg/pinmux.c +++ b/boards/arm/nucleo_l496zg/pinmux.c @@ -22,6 +22,17 @@ static const struct pin_config pinconf[] = { {STM32_PIN_PG7, STM32L4X_PINMUX_FUNC_PG7_LPUART1_TX}, {STM32_PIN_PG8, STM32L4X_PINMUX_FUNC_PG8_LPUART1_RX}, #endif /* CONFIG_LPUART_1 */ +#ifdef CONFIG_PWM_STM32_1 + {STM32_PIN_PE9, STM32L4X_PINMUX_FUNC_PE9_PWM1_CH1}, + {STM32_PIN_PE11, STM32L4X_PINMUX_FUNC_PE11_PWM1_CH2}, + {STM32_PIN_PE13, STM32L4X_PINMUX_FUNC_PE13_PWM1_CH3}, +#endif /* CONFIG_PWM_STM32_1 */ +#ifdef CONFIG_PWM_STM32_2 + {STM32_PIN_PA0, STM32L4X_PINMUX_FUNC_PA0_PWM2_CH1}, +#endif /* CONFIG_PWM_STM32_2 */ +#ifdef CONFIG_PWM_STM32_15 + {STM32_PIN_PB14, STM32L4X_PINMUX_FUNC_PB14_PWM15_CH1}, +#endif /* CONFIG_PWM_STM32_15 */ }; static int pinmux_stm32_init(struct device *port) diff --git a/drivers/pinmux/stm32/pinmux_stm32l4x.h b/drivers/pinmux/stm32/pinmux_stm32l4x.h index b34b0c9b0660b9..7169af040d48c0 100644 --- a/drivers/pinmux/stm32/pinmux_stm32l4x.h +++ b/drivers/pinmux/stm32/pinmux_stm32l4x.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2016 Open-RnD Sp. z o.o. * Copyright (c) 2016 BayLibre, SAS + * Copyright (c) 2018 Centaur Analytics, Inc * * SPDX-License-Identifier: Apache-2.0 */ @@ -85,6 +86,8 @@ (STM32_PINMUX_ALT_FUNC_7 | STM32_PUPDR_NO_PULL) #define STM32L4X_PINMUX_FUNC_PB13_I2C2_SCL \ (STM32_PINMUX_ALT_FUNC_4 | STM32_OPENDRAIN_PULLUP) +#define STM32L4X_PINMUX_FUNC_PB14_PWM15_CH1 \ + (STM32_PINMUX_ALT_FUNC_14 | STM32_PUSHPULL_NOPULL) #define STM32L4X_PINMUX_FUNC_PB14_I2C2_SDA \ (STM32_PINMUX_ALT_FUNC_4 | STM32_OPENDRAIN_PULLUP) @@ -126,6 +129,14 @@ #define STM32L4X_PINMUX_FUNC_PD13_I2C4_SDA \ (STM32_PINMUX_ALT_FUNC_4 | STM32_OPENDRAIN_PULLUP) +/* Port E */ +#define STM32L4X_PINMUX_FUNC_PE9_PWM1_CH1 \ + (STM32_PINMUX_ALT_FUNC_1 | STM32_PUSHPULL_NOPULL) +#define STM32L4X_PINMUX_FUNC_PE11_PWM1_CH2 \ + (STM32_PINMUX_ALT_FUNC_1 | STM32_PUSHPULL_NOPULL) +#define STM32L4X_PINMUX_FUNC_PE13_PWM1_CH3 \ + (STM32_PINMUX_ALT_FUNC_1 | STM32_PUSHPULL_NOPULL) + /* Port F */ #define STM32L4X_PINMUX_FUNC_PF1_I2C3_SCL \ (STM32_PINMUX_ALT_FUNC_4 | STM32_OPENDRAIN_PULLUP) diff --git a/samples/basic/blink_led/README.rst b/samples/basic/blink_led/README.rst index 55ac826e218349..dfff320ce45990 100644 --- a/samples/basic/blink_led/README.rst +++ b/samples/basic/blink_led/README.rst @@ -25,6 +25,11 @@ Nucleo_F103RB ============= Connect PWM1(PA8) to LED +Nucleo_L496ZG +============= +No special board setup is necessary because there are three on-board LEDs (red, +green, blue) connected to the Nucleo's PWM. + Hexiwear K64 ============ No special board setup is necessary because there is an on-board RGB LED diff --git a/samples/basic/blink_led/sample.yaml b/samples/basic/blink_led/sample.yaml index fe836f5a0ddbd6..cd3ca58f29a29e 100644 --- a/samples/basic/blink_led/sample.yaml +++ b/samples/basic/blink_led/sample.yaml @@ -5,6 +5,6 @@ tests: # FIXME: We should remove those and just rely on depends_on platform_whitelist: arduino_101 quark_d2000_crb nucleo_f103rb nucleo_f302r8 nucleo_f401re nucleo_l476rg stm32f4_disco - hexiwear_k64 colibri_imx7d_m4 nrf52832_mdk nrf52840_mdk + hexiwear_k64 colibri_imx7d_m4 nrf52832_mdk nrf52840_mdk, nucleo_l496zg tags: drivers pwm depends_on: pwm diff --git a/samples/basic/fade_led/README.rst b/samples/basic/fade_led/README.rst index 588035d7100902..09795b76b78a74 100644 --- a/samples/basic/fade_led/README.rst +++ b/samples/basic/fade_led/README.rst @@ -17,14 +17,19 @@ repeat this cycle for ever. Wiring ****** -Nucleo_F401RE and Nucleo_L476RG -=============================== +Nucleo_F401RE, Nucleo_L476RG +============================ Connect PWM2(PA0) to LED Nucleo_F103RB ============= Connect PWM1(PA8) to LED +Nucleo_L496ZG +============= +No special board setup is necessary because there are three on-board LEDs (red, +green, blue) connected to the Nucleo's PWM. + Hexiwear K64 ============ No special board setup is necessary because there is an on-board RGB LED diff --git a/samples/basic/fade_led/sample.yaml b/samples/basic/fade_led/sample.yaml index d46aaea2de86c3..28c02941b9b684 100644 --- a/samples/basic/fade_led/sample.yaml +++ b/samples/basic/fade_led/sample.yaml @@ -4,6 +4,6 @@ tests: test: # FIXME: We should remove those and just rely on depends_on platform_whitelist: arduino_101 quark_d2000_crb - nucleo_f103rb nucleo_f401re nucleo_l476rg hexiwear_k64 + nucleo_f103rb nucleo_f401re nucleo_l476rg nucleo_l496zg hexiwear_k64 tags: drivers pwm depends_on: pwm