<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>In NCS, unable to set high drive mode on PWM LEDs anymore from v2.2.0 onwards</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102487/in-ncs-unable-to-set-high-drive-mode-on-pwm-leds-anymore-from-v2-2-0-onwards</link><description>Hi, I am working with PWM LEDs and have pinpointed a difference in behaviour in the SDK upgrade between NCS v2.1.0 and v2.2.0 with regard to the pin output drive for PWM devices. Specifically, while in v2.1.0 I was able to set the drive to NRF_DRIVE_H0H1</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Aug 2023 09:50:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102487/in-ncs-unable-to-set-high-drive-mode-on-pwm-leds-anymore-from-v2-2-0-onwards" /><item><title>RE: In NCS, unable to set high drive mode on PWM LEDs anymore from v2.2.0 onwards</title><link>https://devzone.nordicsemi.com/thread/440919?ContentTypeID=1</link><pubDate>Fri, 11 Aug 2023 09:50:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e43a5647-8760-4d78-8d75-a1e5dab9e53a</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Thanks for providing this information. Our developers were able to reproduce and find the root cuase.&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The problem is that for &lt;code&gt;CONFIG_LED=y&lt;/code&gt; and an enabled &lt;code&gt;&amp;quot;gpio-leds&amp;quot;&lt;/code&gt; node in devicetree, the &lt;code&gt;led_gpio.c&lt;/code&gt; driver is enabled by default.&lt;/p&gt;
&lt;p&gt;This has changed between NCS v2.1.0, where the &lt;code&gt;LED_GPIO&lt;/code&gt; option was defined as:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;config LED_GPIO
    bool &amp;quot;GPIO LED driver&amp;quot;
    depends on GPIO &amp;amp;&amp;amp; $(dt_compat_enabled,gpio-leds)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;p&gt;and v2.2.0, since which it is defined in this way:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;config LED_GPIO
    bool &amp;quot;GPIO LED driver&amp;quot;
    default y
    depends on GPIO &amp;amp;&amp;amp; DT_HAS_GPIO_LEDS_ENABLED&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;p&gt;And this driver is initialized after the &lt;code&gt;pwm_nrfx.c&lt;/code&gt; one (which correctly configures the PWM output pins through pinctrl with the H0H1 drive), and it reconfigures the LED pins according to what is specified in child nodes of the &lt;code&gt;&amp;quot;gpio-leds&amp;quot;&lt;/code&gt; node, where the &lt;code&gt;&lt;span&gt;NRF_GPIO_DRIVE_H0H1&lt;/span&gt;&lt;/code&gt; flags are apparently not present. The solution is to disable the &lt;code&gt;led_gpio.c&lt;/code&gt; driver, either by specifying &lt;code&gt;CONFIG_LED_GPIO=n&lt;/code&gt; or by disabling the &lt;code&gt;&amp;quot;gpio-leds&amp;quot;&lt;/code&gt; node in devicetree&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: In NCS, unable to set high drive mode on PWM LEDs anymore from v2.2.0 onwards</title><link>https://devzone.nordicsemi.com/thread/440918?ContentTypeID=1</link><pubDate>Fri, 11 Aug 2023 09:50:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a108dde-e1e2-422c-aa2c-809d3f0af568</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Thanks for providing this information. Our developers were able to reproduce and find the root cuase.&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The problem is that for &lt;code&gt;CONFIG_LED=y&lt;/code&gt; and an enabled &lt;code&gt;&amp;quot;gpio-leds&amp;quot;&lt;/code&gt; node in devicetree, the &lt;code&gt;led_gpio.c&lt;/code&gt; driver is enabled by default.&lt;/p&gt;
&lt;p&gt;This has changed between NCS v2.1.0, where the &lt;code&gt;LED_GPIO&lt;/code&gt; option was defined as:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;config LED_GPIO
    bool &amp;quot;GPIO LED driver&amp;quot;
    depends on GPIO &amp;amp;&amp;amp; $(dt_compat_enabled,gpio-leds)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;p&gt;and v2.2.0, since which it is defined in this way:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;config LED_GPIO
    bool &amp;quot;GPIO LED driver&amp;quot;
    default y
    depends on GPIO &amp;amp;&amp;amp; DT_HAS_GPIO_LEDS_ENABLED&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;p&gt;And this driver is initialized after the &lt;code&gt;pwm_nrfx.c&lt;/code&gt; one (which correctly configures the PWM output pins through pinctrl with the H0H1 drive), and it reconfigures the LED pins according to what is specified in child nodes of the &lt;code&gt;&amp;quot;gpio-leds&amp;quot;&lt;/code&gt; node, where the &lt;code&gt;&lt;span&gt;NRF_GPIO_DRIVE_H0H1&lt;/span&gt;&lt;/code&gt; flags are apparently not present. The solution is to disable the &lt;code&gt;led_gpio.c&lt;/code&gt; driver, either by specifying &lt;code&gt;CONFIG_LED_GPIO=n&lt;/code&gt; or by disabling the &lt;code&gt;&amp;quot;gpio-leds&amp;quot;&lt;/code&gt; node in devicetree&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: In NCS, unable to set high drive mode on PWM LEDs anymore from v2.2.0 onwards</title><link>https://devzone.nordicsemi.com/thread/440175?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 15:23:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76e8e483-0768-4586-9ffe-559b91d24334</guid><dc:creator>dtp</dc:creator><description>&lt;p&gt;Hi Oyvind, thanks for the help. That&amp;#39;s interesting. I am running a modified blinky that can be run with either PWM or GPIO LEDs. Here&amp;#39;s the main.c:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;soc.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/led.h&amp;gt;
#include &amp;lt;zephyr/drivers/pwm.h&amp;gt;
#include &amp;lt;zephyr/dt-bindings/gpio/nordic-nrf-gpio.h&amp;gt;
#include &amp;lt;zephyr/init.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;
#include &amp;lt;zephyr/pm/device.h&amp;gt;
#include &amp;lt;zephyr/pm/pm.h&amp;gt;
#include &amp;lt;zephyr/pm/policy.h&amp;gt;

LOG_MODULE_REGISTER(blinky, LOG_LEVEL_INF);

#define SLEEP_TIME_MS 1000
#define DEEP_SLEEP_TIME_MS 10000

/* Enable to use GPIO LEDs rather than PWM LEDs */
// #define USE_GPIO_LEDS

enum led_colour {
	LED_GREEN,
	LED_AMBER,
};

#ifdef USE_GPIO_LEDS
static const struct gpio_dt_spec green_gpio_led = GPIO_DT_SPEC_GET(DT_NODELABEL(green_led), gpios);
static const struct gpio_dt_spec amber_gpio_led = GPIO_DT_SPEC_GET(DT_NODELABEL(yellow_led), gpios);
#else

#define GREEN_LED_PWM_PCT 50
#define AMBER_LED_PWM_PCT 30

static const struct pwm_dt_spec green_pwm_led = PWM_DT_SPEC_GET(DT_NODELABEL(green_led_pwm));
static const struct pwm_dt_spec amber_pwm_led = PWM_DT_SPEC_GET(DT_NODELABEL(yellow_led_pwm));
static const struct device *pwm_leds_dev = DEVICE_DT_GET(DT_PARENT(DT_NODELABEL(green_led_pwm)));
#endif /* USE_GPIO_LEDS */

/* Prevent deep sleep (system off) from being entered on long timeouts
 * or `K_FOREVER` due to the default residency policy.
 *
 * This has to be done before anything tries to sleep, which means
 * before the threading system starts up between PRE_KERNEL_2 and
 * POST_KERNEL.  Do it at the start of PRE_KERNEL_2.
 */
static int disable_ds_1(const struct device *dev)
{
	ARG_UNUSED(dev);

	pm_policy_state_lock_get(PM_STATE_SOFT_OFF, PM_ALL_SUBSTATES);
	return 0;
}

SYS_INIT(disable_ds_1, PRE_KERNEL_2, 0);

static void enter_deep_sleep(void)
{
	/* Above we disabled entry to deep sleep based on duration of
	 * controlled delay.  Here we need to override that, then
	 * force entry to deep sleep on any delay.
	 */
	pm_state_force(0u, &amp;amp;(struct pm_state_info){ PM_STATE_SOFT_OFF, 0, 0 });

	/* Now we need to go sleep. This will let the idle thread runs and
	 * the pm subsystem will use the forced state. To confirm that the
	 * forced state is used, lets set the same timeout used previously.
	 */
	k_msleep(DEEP_SLEEP_TIME_MS);
}

void led_on_turn(enum led_colour colour)
{
	switch (colour) {
	case LED_GREEN:
#ifdef USE_GPIO_LEDS
		gpio_pin_set_dt(&amp;amp;green_gpio_led, true);
#else
		led_set_brightness(pwm_leds_dev, green_pwm_led.channel, GREEN_LED_PWM_PCT);
#endif /* USE_GPIO_LEDS */
		break;
	case LED_AMBER:
#ifdef USE_GPIO_LEDS
		gpio_pin_set_dt(&amp;amp;amber_gpio_led, true);
#else
		led_set_brightness(pwm_leds_dev, amber_pwm_led.channel, AMBER_LED_PWM_PCT);
#endif /* USE_GPIO_LEDS */
		break;
	}
}

void led_off_turn(enum led_colour colour)
{
	switch (colour) {
	case LED_GREEN:
#ifdef USE_GPIO_LEDS
		gpio_pin_set_dt(&amp;amp;green_gpio_led, false);
#else
		led_off(pwm_leds_dev, green_pwm_led.channel);
#endif /* USE_GPIO_LEDS */
		break;
	case LED_AMBER:
#ifdef USE_GPIO_LEDS
		gpio_pin_set_dt(&amp;amp;amber_gpio_led, false);
#else
		led_off(pwm_leds_dev, amber_pwm_led.channel);
#endif /* USE_GPIO_LEDS */
		break;
	}
}

void main(void)
{
#ifdef USE_GPIO_LEDS
	if (!device_is_ready(green_gpio_led.port)) {
		return;
	}
	if (!device_is_ready(amber_gpio_led.port)) {
		return;
	}

	if (gpio_pin_configure_dt(&amp;amp;green_gpio_led, (GPIO_OUTPUT_INACTIVE | NRF_GPIO_DRIVE_H0H1)) &amp;lt; 0) {
		return;
	}
	if (gpio_pin_configure_dt(&amp;amp;amber_gpio_led, (GPIO_OUTPUT_INACTIVE | NRF_GPIO_DRIVE_H0H1)) &amp;lt; 0) {
		return;
	}
#else
	if (!device_is_ready(pwm_leds_dev)) {
		LOG_ERR(&amp;quot;Device %s is not ready&amp;quot;, pwm_leds_dev-&amp;gt;name);
		return;
	}
	if (!device_is_ready(green_pwm_led.dev)) {
		LOG_ERR(&amp;quot;Device %s is not ready&amp;quot;, green_pwm_led.dev-&amp;gt;name);
		return;
	}
	if (!device_is_ready(amber_pwm_led.dev)) {
		LOG_ERR(&amp;quot;Device %s is not ready&amp;quot;, amber_pwm_led.dev-&amp;gt;name);
		return;
	}
#endif /* USE_GPIO_LEDS */

	/* Wait a bit before starting */
	k_msleep(DEEP_SLEEP_TIME_MS);

	int counter = 0;
	while (true) {
		if (counter == 40) {
			led_off_turn(LED_GREEN);
			led_off_turn(LED_AMBER);

			enter_deep_sleep();
		}

		if (counter % 4 == 0) {
			led_on_turn(LED_GREEN);
		} else if (counter % 4 == 1) {
			led_off_turn(LED_GREEN);
		} else if (counter % 4 == 2) {
			led_on_turn(LED_AMBER);
		} else if (counter % 4 == 3) {
			led_off_turn(LED_AMBER);
		}

		counter += 1;
		k_msleep(SLEEP_TIME_MS);
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;prj.conf:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y
CONFIG_SERIAL=n
CONFIG_LOG=n
CONFIG_CONSOLE=n
CONFIG_USE_SEGGER_RTT=n
CONFIG_PRINTK=n
CONFIG_BOOT_BANNER=n
CONFIG_PM=y
CONFIG_PM_DEVICE=y
CONFIG_LED=y
CONFIG_PWM=y
CONFIG_LED_PWM=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;When I measure the power consumption of the device running the modified blinky, when comparing the app run with GPIO LEDs, I see no difference between v2.1.0 and v2.3.0:&lt;br /&gt;&lt;img style="max-height:600px;max-width:1040px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/2080x1200/__key/communityserver-discussions-components-files/4/gpio_5F00_leds.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But then you can see the difference when using PWM LEDs:&lt;br /&gt;&lt;img style="height:auto;max-width:1040px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/2080x0/__key/communityserver-discussions-components-files/4/pwm_5F00_leds.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: In NCS, unable to set high drive mode on PWM LEDs anymore from v2.2.0 onwards</title><link>https://devzone.nordicsemi.com/thread/440076?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 10:05:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfae92d8-d348-4093-b37f-ee83b1b847dc</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Our team have&amp;nbsp;done a quick test and are not able to reproduce. Can you provide more information for us to test? E.g. your project?&lt;br /&gt;&lt;br /&gt;Thanks.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;&amp;Oslash;yvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: In NCS, unable to set high drive mode on PWM LEDs anymore from v2.2.0 onwards</title><link>https://devzone.nordicsemi.com/thread/439600?ContentTypeID=1</link><pubDate>Thu, 03 Aug 2023 05:59:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4efc36ce-9abe-46f3-b819-d3ba18e4d493</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I&amp;#39;m currently looking into you question. Hope to have an answer by end of today or tomorrow.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At first glance it does look like an issue with the pin controller.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>