<?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>Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/127355/dynamic-pin-control-changing-functionality-in-runtime</link><description>Hello, 
 
 I recently noticed that I may have an issue with our current design of PCB and firmware. We basically have created a datalogger using the nRF9160, and we take readings for a variety of sensors. One such thing that we have yet to add into firmware</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 13 Mar 2026 16:55:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/127355/dynamic-pin-control-changing-functionality-in-runtime" /><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/563240?ContentTypeID=1</link><pubDate>Fri, 13 Mar 2026 16:55:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b92420f-84b5-423a-934d-100a310dee46</guid><dc:creator>DamoL</dc:creator><description>&lt;p&gt;Hi Kenneth,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t have that in the devicetree. I realised why I had the issue though. I had forgotten, that when I print to the com port and I am not expecting any messages back, I use pm_device_runtime_enable() to put it in low power.&lt;br /&gt;&lt;br /&gt;I did have to change the&amp;nbsp;pm_device_action_run(uart, SUSPEND/RESUME) to&amp;nbsp;&lt;span&gt;pm_device_runtime_enable()&amp;nbsp;or&amp;nbsp;pm_device_runtime_disable(). I think that must do some extra configuration compared to action_run(), because it would cause the UART to hang after a couple of swicthes.&lt;br /&gt;I have had it running 24 hours and not had an issue, so I think it works!&lt;br /&gt;&lt;br /&gt;Thanks,&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Damien&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/563059?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2026 20:28:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb0e918b-9be2-4c3f-a2ff-e320589c29dc</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Sounds good. Can it be that you have &amp;quot;&lt;span&gt;zephyr,pm-device-runtime-auto&amp;quot; for the uart instance in the devicetree? Try to delete it.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Or maybe because you have it in the devicetree you don&amp;#39;t need to put it manually to suspend like earlier.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kenneth&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/563051?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2026 16:53:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b89b70b-57ac-4034-94d4-56921c6a23e4</guid><dc:creator>DamoL</dc:creator><description>&lt;p&gt;I can confirm this works.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Based on this answer -&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/107317/configuring-uart1-using-pinctrl-for-two-uarts/463996"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/107317/configuring-uart1-using-pinctrl-for-two-uarts/463996&lt;/a&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I did a similar thing by switching pins and sending some data over UART every second, and pins do get routed to alternative pins.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Only slight problem is when I call&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;err = pm_device_action_run(uart, PM_DEVICE_ACTION_SUSPEND);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It always comes back as -120 (EALREADY). If I just ignore it, it works, but I will investigate as to why, I wonder if things have been changed since SDK2.5 to SDK3.1 and I should be calling something else, but that can wait for tomorrow.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thanks for you assistance Kenneth!&lt;/div&gt;
&lt;div&gt;Damien&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/563045?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2026 14:40:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f62da960-732c-4aa8-9af6-67aa4dee006e</guid><dc:creator>DamoL</dc:creator><description>&lt;p&gt;I think I understand...&lt;/p&gt;
&lt;p&gt;For the majority of the time in my code, the UART is in&amp;nbsp;sleep mode (using pm_device_runtime_enable()), and the RX pin is attached to a GPIO interrupt, so if that fires it wakes up the UART (using&amp;nbsp;&lt;span&gt;pm_device_runtime_disable()&lt;/span&gt;). The UART is only really used for configuration and testing. There are already wrappers around code to stop trying to do a UART transaction if in sleep mode, so I guess I can do a similar thing, but use pm_suspend/pm_resume if I need to update the uart pins, do something, then switch back when needed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I dont think there are any other Zephyr modules that use my UART3, all the logging modules I have used are on RTT.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I may just have to try it and see if it falls over...&lt;br /&gt;&lt;br /&gt;Thanks,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Damien&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/563043?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2026 14:20:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5df48a1d-9732-4b38-9091-a2d6003db216</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi Damian,&lt;/p&gt;
&lt;p&gt;I can understand the contradiction here now.&lt;/p&gt;
&lt;p&gt;It should in theory be possible to do this runtime as suggested in the linked devzone case, but you just need to be very aware of and have full control over when and which UART configuration that is used at any given time, basically you need to ensure that you update at a safe time (e.g. not while it may be running a UART transaction) and that you are the one that is calling any kind of UART transaction at any given time, you can&amp;#39;t really allow other zephyr modules use the UART at it&amp;#39;s own free will if that make sense.&lt;/p&gt;
&lt;p&gt;Kenenth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/563042?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2026 14:10:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd9da85d-541c-4e80-a600-2320d161ff7b</guid><dc:creator>DamoL</dc:creator><description>&lt;p&gt;Thanks Kenneth, that&amp;#39;s very useful.&lt;/p&gt;
&lt;p&gt;I am a little confused at this first option though, looking at the code provided, it seems it is using zephyr UART0, and changing the pins, with PM_DEVICE_ACTION_SUSPEND / RESUME&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="149846" url="~/f/nordic-q-a/127355/dynamic-pin-control-changing-functionality-in-runtime/562923"]However, according to the documentation this should only be used &lt;strong data-start="632" data-end="668"&gt;before the device is initialized&lt;/strong&gt;, [/quote]
&lt;p&gt;Surely this violates what the documentation says though?&lt;br /&gt;&lt;br /&gt;Thanks,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Damien&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/563025?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2026 13:04:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d33b7bf-c7a8-4fab-b3df-89b1998e6581</guid><dc:creator>Kenneth</dc:creator><description>[quote user="DamoL"]Seems like disabling the Zephyr UART3, and writing my own UART driver with nrfx that will deinit, and init with different pins is the way to go.[/quote]
&lt;p&gt;Sounds like a good plan.&lt;/p&gt;
&lt;p&gt;As long as you have full control of when the UART3 is used, you may find this useful also (think this may still work in recent ncs versions):&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/107317/configuring-uart1-using-pinctrl-for-two-uarts/463996"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/107317/configuring-uart1-using-pinctrl-for-two-uarts/463996&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Alternatively, you can use the nrfx drivers directly. An example on how to do this is shown in:&lt;br /&gt;v3.2.1\modules\hal\nordic\nrfx\samples\src\nrfx_uarte&lt;/p&gt;
&lt;p&gt;Hope that helps,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/562999?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2026 08:43:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bc3a8cb-f4a7-49a5-b62f-5b77d978bb16</guid><dc:creator>DamoL</dc:creator><description>&lt;p&gt;Yea that would be the most ideal way, but we do have to support older hardware devices that have been made in that way. I cannot remember the exact reason for having two I2C ports in the first place, but I have to work with it.&amp;nbsp;&lt;br /&gt;Seems like disabling the Zephyr UART3, and writing my own UART driver with nrfx that will deinit, and init with different pins is the way to go.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/562961?ContentTypeID=1</link><pubDate>Tue, 10 Mar 2026 17:13:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ac9c3f7-ecc4-45c5-8c42-2611710f7dac</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;From a hardware perspective the only real limitation is what is described here:&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf9160/page/peripheral_interface.html#ariaid-title3"&gt;https://docs.nordicsemi.com/bundle/ps_nrf9160/page/peripheral_interface.html#ariaid-title3&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However the zephyr drivers do not really support this at all, they rely on static configuration compile time or early init. Only exception is if you were working at a low level driver, then you could for instance use the low level nrfx drivers to do pretty much do whatever you want, e.g. change between interfaces and pins for the same hardware ID instance. However the higher level sensor and serial drivers&amp;nbsp;in zephyr do not support this in any way.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I assume you are not able to do any changes to the hardware? Because if you were able to put both i2c sensors on the same i2c interface, then that would actually work well in zephyr, because&amp;nbsp;the i2c interface is by design built in such a way that if two&amp;nbsp;sensors try to use (read or write to) the i2c interface at the same time, then one would simply be delayed until the other is finished, however that is really the only interface that can do this.&lt;/p&gt;
&lt;p&gt;If you are not able to change the hardware, then&amp;nbsp;that limit the number of options here. There is a i2c_gpio (i2c_bitbang) implementation in zephyr, so that might potentially free up one of the i2c hardware instances, but bit-banging i2c will be less efficient and need to be tested in case the sensor have some hard requirements to how low speed the clock can in corner cases be (don&amp;#39;t think it&amp;#39;s a problem, but it must be tested).&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/562944?ContentTypeID=1</link><pubDate>Tue, 10 Mar 2026 15:01:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c79c7896-5c68-4c7c-8671-554bfa0215c1</guid><dc:creator>DamoL</dc:creator><description>&lt;p&gt;Surely at the low level it would be possible. It&amp;#39;s fairly standard on microcontrollers to init and deinit peripherals in runtime. I am guessing the limitation is coming from Zephyr rather than the nRF9160?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic Pin Control/Changing Functionality in runtime</title><link>https://devzone.nordicsemi.com/thread/562923?ContentTypeID=1</link><pubDate>Tue, 10 Mar 2026 13:43:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82762ade-da38-4dab-9559-a5a0ef5e533e</guid><dc:creator>FedericaMayorga</dc:creator><description>&lt;p&gt;Hi DamoL,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p data-start="439" data-end="565"&gt;Zephyr supports &lt;strong data-start="146" data-end="169"&gt;dynamic pin control&lt;/strong&gt; (&lt;code data-start="171" data-end="195"&gt;CONFIG_PINCTRL_DYNAMIC&lt;/code&gt;), which allows updating pin configurations &lt;strong&gt;at runtime&lt;/strong&gt;.&lt;/p&gt;
&lt;p data-start="439" data-end="565"&gt;&lt;/p&gt;
&lt;p data-start="439" data-end="565"&gt;&lt;/p&gt;
&lt;p data-start="567" data-end="851"&gt;However, according to the documentation this should only be used &lt;strong data-start="632" data-end="668"&gt;before the device is initialized&lt;/strong&gt;, typically during early boot. Changing pin configurations while a device is operating may lead to unexpected behavior, and Zephyr currently does not support device de-initialization.&lt;/p&gt;
&lt;p data-start="853" data-end="972"&gt;&lt;/p&gt;
&lt;p data-start="853" data-end="972"&gt;&lt;/p&gt;
&lt;p data-start="853" data-end="972"&gt;See the documentation here:&lt;br data-start="880" data-end="883" /&gt; &lt;a id="" class="decorated-link" href="https://docs.nordicsemi.com/bundle/ncs-2.2.0/page/zephyr/hardware/peripherals/pinmux.html" target="_new" data-start="883" data-end="972"&gt;https://docs.nordicsemi.com/bundle/ncs-2.2.0/page/zephyr/hardware/peripherals/pinmux.html&lt;/a&gt;&lt;/p&gt;
&lt;p data-start="853" data-end="972"&gt;&lt;/p&gt;
&lt;p data-start="853" data-end="972"&gt;&lt;/p&gt;
&lt;p data-start="853" data-end="972"&gt;Best regards,&lt;/p&gt;
&lt;p data-start="853" data-end="972"&gt;Federica from OWL Services.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>