<?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>zephyr PWM - how to set default clock on 16MHz using devicetree</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82812/zephyr-pwm---how-to-set-default-clock-on-16mhz-using-devicetree</link><description>Hello 
 I need to configure PWM on 16 MHz clock and i really don&amp;#39;t know how to do this via device tree.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Dec 2021 10:39:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82812/zephyr-pwm---how-to-set-default-clock-on-16mhz-using-devicetree" /><item><title>RE: zephyr PWM - how to set default clock on 16MHz using devicetree</title><link>https://devzone.nordicsemi.com/thread/344769?ContentTypeID=1</link><pubDate>Wed, 22 Dec 2021 10:39:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a87ee0d-46c0-436d-950c-8407bfcc7054</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I agree with your findings, it does not seem like it is possible to set the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pwm.html?cp=4_2_0_46_4_7#register.PRESCALER"&gt;PWM prescaler&lt;/a&gt; to 16 MHz yourself through the devicetree.&lt;/p&gt;
&lt;p&gt;I took a closer look, to confirm this, and to figure out if it was possible to set it in any other way (API, Kconfigs etc..).&lt;/p&gt;
&lt;p&gt;I can see that nrf_pwm.h--&amp;gt;nrf_pwm_configure() will set the PRESCALER register, and this function is called from two places:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span&gt;&lt;span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.0-ncs1/drivers/pwm/pwm_nrfx.c#L271"&gt;pwm_nrfx_init()&lt;/a&gt;--&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;a href="https://github.com/nrfconnect/sdk-hal_nordic/blob/8f013ea950f41bf69b18bf688bfb0dd80a3fdc44/nrfx/drivers/src/nrfx_pwm.c#L156"&gt;nrfx_pwm_init()&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;This will use the initial_config struct with the 1MHz value, so nothting to do&amp;nbsp;here&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.0-ncs1/include/drivers/pwm.h#L181"&gt;pwm_pin_set_cycles()&lt;/a&gt;--&amp;gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.0-ncs1/drivers/pwm/pwm_nrfx.c#L125"&gt;pwm_nrfx_pin_set()&lt;/a&gt;--&amp;gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.0-ncs1/drivers/pwm/pwm_nrfx.c#L71"&gt;pwm_period_check_and_set()&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So there are no ways to change the PRESCALER value directly, but you you can set the period using the function&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.0-ncs1/include/drivers/pwm.h#L181"&gt;pwm_pin_set_cycles()&lt;/a&gt;, and the PRESCALER will be set automatically to an appropriate value.&lt;/p&gt;
&lt;p&gt;Of course, you could run&amp;nbsp;&lt;span&gt;nrf_pwm_configure()&amp;nbsp;directly from your application, but that is not the intended &amp;quot;Zephyr way&amp;quot; of doing it.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Another option is to use the nrfx drivers directly, that requires some more work than using the Zephyr drivers, but you get more control. Check out the sample&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/v2.7.0-ncs1/samples/boards/nrf/nrfx"&gt;zephyr/samples/boards/nrf/nrfx&lt;/a&gt;&amp;nbsp;to get an understanding of how to use the nrfx api directly.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: zephyr PWM - how to set default clock on 16MHz using devicetree</title><link>https://devzone.nordicsemi.com/thread/343798?ContentTypeID=1</link><pubDate>Thu, 16 Dec 2021 07:24:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:181dd748-7fb3-4e08-819c-37f046587f5f</guid><dc:creator>creative.industry.ag</dc:creator><description>&lt;p&gt;Thought&amp;nbsp;i would check the driver implementation in file pwm_nrfx.c.&lt;/p&gt;
&lt;p&gt;It turned out that apart from assigning pins to individual channels, all other PWM configs are default and it is not possible to configure them from the device tree level.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Part of&amp;nbsp;&lt;span&gt;pwm_nrfx.c&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define PWM_NRFX_DEVICE(idx)						      \
	static struct pwm_nrfx_data pwm_nrfx_##idx##_data;		      \
	static const struct pwm_nrfx_config pwm_nrfx_##idx##config = {	      \
		.pwm = NRFX_PWM_INSTANCE(idx),				      \
		.initial_config = {					      \
			.output_pins = {				      \
				PWM_NRFX_OUTPUT_PIN(idx, 0),		      \
				PWM_NRFX_OUTPUT_PIN(idx, 1),		      \
				PWM_NRFX_OUTPUT_PIN(idx, 2),		      \
				PWM_NRFX_OUTPUT_PIN(idx, 3),		      \
			},						      \
			.base_clock = NRF_PWM_CLK_1MHz,			      \
			.count_mode = PWM_NRFX_COUNT_MODE(idx),		      \
			.top_value = 1000,				      \
			.load_mode = NRF_PWM_LOAD_INDIVIDUAL,		      \
			.step_mode = NRF_PWM_STEP_TRIGGERED,		      \
		},							      \
		.seq.values.p_raw = pwm_nrfx_##idx##_data.current,	      \
		.seq.length = NRF_PWM_CHANNEL_COUNT			      \
	};		&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: zephyr PWM - how to set default clock on 16MHz using devicetree</title><link>https://devzone.nordicsemi.com/thread/343690?ContentTypeID=1</link><pubDate>Wed, 15 Dec 2021 14:22:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef4cb03c-91c5-49d9-9869-f8c99528effb</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;ll take a look at this and provide you with an answer tomorrow&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>