cancel
Showing results for 
Search instead for 
Did you mean: 

Problem configuring duty cycle in devicetree

obedPH
Associate III

Hello,
I am trying to configure a PWM in the boot process. I followed the steps in the documentation https://wiki.st.com/stm32mpu/wiki/TIM_device_tree_configuration .

I configured the pwmleds node

pwmleds {
		compatible = "pwm-leds";
		example {
			label = "stm32-pwm-leds-example";
			/* Use pwm1 channel 0 (e.g. TIM1_CH1) */
			/* period in nanoseconds (500000), normal polarity (0) */
			pwms = <&pwm1 0 30518 0>;
			max-brightness = <255>;
		};
	};
/* PWM DT provider on TIM1: "pwm1" */
&timers1 {
	status = "okay";
	/* spare all DMA channels since they are not needed for PWM output */
	/delete-property/dmas;
	/delete-property/dma-names;
	/* define pwm1 label */
	pwm1: pwm {
		/* configure PWM pins on TIM1_CH1 */
		pinctrl-0 = <&pwm1_pins_a>;
		pinctrl-1 = <&pwm1_sleep_pins_a>;
		pinctrl-names = "default", "sleep";
		/* enable PWM on TIM1 */
		status = "okay";
	};
};

I run the command cat /sys/kernel/debug/pwm
I see the next line
pwm-0   (example             :( requested enabled period: 30518 ns duty: 0 ns polarity: normal


The period is OK, but the  duty cycle is 0, so  basically the signal is always low.

How can I configure the duty cycle in the devicetree if I want to have the pwm working well in  the boot process?

I am in the 6.1 kernel version in the mickledore branch.

 

Regards, @obedPH 

2 REPLIES 2
PatrickF
ST Employee

Hi @obedPH 

I fear PWM cannot put in 'run' only by Device Tree settings, which is mostly HW configuration.

You need to use it thru the framework.

https://wiki.st.com/stm32mpu/wiki/PWM_overview

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi, @PatrickF , thank you for your response.

I see. I'm trying something different. I'll give you more context. I am using a MuRata module for the wifi in a custom PCB with a STM32MP15, for several reasons I have to use a timer for the LPO pin, since I don't have more lsco available sources. I need to use a pwm timer before the brcmfmac starts in order to make the wifi module work properly. I modified the leds-pwm.c file and the PWM was working, bit it didn't work as I wanted,  because, apparently, it needs to start way before if I want my wifi module to bring on correctly. Now I am trying to modify the u-boot, I added this lines in the stm32mp157f-dk2.dts.

 

pwmleds {
        compatible = "pwm-leds";
        example {
            //label = "stm32-pwm-leds-example";
            /* Use pwm1 channel 0 (e.g. TIM1_CH1) */
            /* period in nanoseconds (500000), normal polarity (0) */
            pwms = <&pwm1 2 30518>;
            max-brightness = <255>;
            u-boot,default-brightness = <127>;
        };
	};

 

 I saw the /drivers/led/led_pwm.c and this file reads the u-boot,default-brightness attribute. The problem is, in the u-boot process, the pwm is not active.

 

Searching in the configuration files, I noticed that the configs/stm32mp15_defconfig does not have the LED_PWM = y line

 

CONFIG_SYS_I2C_STM32F7=y
CONFIG_LED=y
CONFIG_LED_GPIO=y
CONFIG_STM32_FMC2_EBI=y

 

It just has the LED_GPIO configured, so I suspect that this is the reason why the driver is not working, since I added some logs in the driver and I don't see those log messages during the boot process.

How should I configure the devicetree if I want to load that driver in the u-boot? I suspect that I have to edit the config node in the stm32mp157f-dk2-u-boot.dtsi file, because I can see some leds configurations there, but I don't know how:

 

// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause)
/*
 * Copyright (C) 2024, STMicroelectronics - All Rights Reserved
 * Author: STM32CubeMX code generation for STMicroelectronics.
 */

/* For more information on Device Tree configuration, please refer to
 * https://wiki.st.com/stm32mpu/wiki/Category:Device_tree_configuration
 */

/* USER CODE BEGIN includes */
#include "stm32mp15-scmi-u-boot.dtsi"
/* USER CODE END includes */

/ {

    /* USER CODE BEGIN root */

    aliases{
        i2c3 = &i2c4;
        usb0 = &usbotg_hs;
    };

    config{
        u-boot,boot-led = "heartbeat";
        u-boot,error-led = "error";
        u-boot,mmc-env-partition = "u-boot-env";
        //st,adc_usb_pd = <&adc1 18>, <&adc1 19>;
        st,fastboot-gpios = <&gpioa 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
        st,stm32prog-gpios = <&gpioa 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
    };

    led{

        led-red{
            label = "error";
            gpios = <&gpioa 13 GPIO_ACTIVE_LOW>;
            default-state = "off";
            status = "okay";
        };
    };
    /* USER CODE END root */

}; /*root*/

/* USER CODE BEGIN addons */

&pmic {
        u-boot,dm-pre-reloc;
};

&uart4{
    u-boot,dm-pre-reloc;
};

&usbotg_hs{
    u-boot,force-b-session-valid;
};

&uart4_pins_mx {
    u-boot,dm-pre-reloc;
    pins1 {    /* UART4_RX */
        u-boot,dm-pre-reloc;
        /* pull-up on rx to avoid floating level */
        bias-pull-up;
    };
    pins2 {
        u-boot,dm-pre-reloc;
    };
};

 

 

Regards, @obedPH