<?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>How to use device tree to set up PDM pin configurations with nrfx pdm directly (no dmic)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/109455/how-to-use-device-tree-to-set-up-pdm-pin-configurations-with-nrfx-pdm-directly-no-dmic</link><description>I&amp;#39;ve implemented a PDM microphone driver using the nrfx_pdm.c module directly, NOT the zephyr dmic module. We are in the early stages of development, so we are still supporting the nrf7002-dk development kit in addition to the first custom prototype.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 23 Mar 2024 05:45:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/109455/how-to-use-device-tree-to-set-up-pdm-pin-configurations-with-nrfx-pdm-directly-no-dmic" /><item><title>RE: How to use device tree to set up PDM pin configurations with nrfx pdm directly (no dmic)</title><link>https://devzone.nordicsemi.com/thread/475476?ContentTypeID=1</link><pubDate>Sat, 23 Mar 2024 05:45:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09a9e096-9d5f-44b4-a406-a6fef2a73e32</guid><dc:creator>elliottke</dc:creator><description>&lt;p&gt;Ok, I found the issue--I missed the top line of your example, PINCTRL_DT_DEFINE(DT_NODELABEL(dmic_dev));&lt;/p&gt;
&lt;p&gt;Everything after that worked!&lt;/p&gt;
&lt;p&gt;And also, I found out about a way to figure out which pin is which:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define PDM0 DT_NODELABEL(pdm0)
PINCTRL_DT_DEFINE(PDM0);
static const struct pinctrl_dev_config* p_pinctrl_dev_cfg = PINCTRL_DT_DEV_CONFIG_GET(PDM0);
    
void init_function()
{
    const struct pinctrl_state *state = &amp;amp;(p_pinctrl_dev_cfg-&amp;gt;states[0]);

    for (unsigned i = 0; i &amp;lt; state-&amp;gt;pin_cnt; ++i)
    {
        switch (NRF_GET_FUN(state-&amp;gt;pins[i]))
        {
        case NRF_FUN_PDM_CLK:
            pdm_config.clk_pin = NRF_GET_PIN(state-&amp;gt;pins[i]);
            LOG_DBG(&amp;quot;pdm_config.clk_pin = %d\n&amp;quot;, pdm_config.clk_pin);
            break;
        case NRF_FUN_PDM_DIN:
            pdm_config.din_pin = NRF_GET_PIN(state-&amp;gt;pins[i]);
            LOG_DBG(&amp;quot;pdm_config.din_pin = %d\n&amp;quot;, pdm_config.din_pin);
            break;
        default:
            __ASSERT(0,&amp;quot;Unknown pin function\n&amp;quot;);
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use device tree to set up PDM pin configurations with nrfx pdm directly (no dmic)</title><link>https://devzone.nordicsemi.com/thread/475053?ContentTypeID=1</link><pubDate>Thu, 21 Mar 2024 10:07:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5595357b-8cb7-443a-af15-01962b3b8352</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi KE,&lt;/p&gt;
&lt;p&gt;It is actually more often due to a Devicetree issue than due to Kconfig.&amp;nbsp;&lt;br /&gt;The line that you meet the error only deal with Devicetree, and should not have any&amp;nbsp;problem from Kconfig. However,&amp;nbsp;the overlay in your opening post should have made it work...&lt;br /&gt;Could you please&amp;nbsp;follow the recommendations my colleague Maria writes in&amp;nbsp;this DevZone case, and let me know if it help?&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/103713/spi-and-gpios-defined-via-device-tree-report-as-undefined-references-at-linking-time"&gt;SPI and GPIOs defined via device tree report as &amp;quot;undefined references&amp;quot; at linking time.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If that doesn&amp;#39;t help, please share the compiled&amp;nbsp;zephyr.dts and .config files, located in &amp;lt;build directory&amp;gt;/zephyr.&lt;/p&gt;
&lt;p&gt;By the way, the Kconfig file you gave is not your project configuration, but rather the definition of additional Kconfig. The configurations are done in prj.conf file and any additional overlay files you included in the build.&lt;br /&gt;For more information, refer to:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.0/zephyr/build/kconfig/index.html"&gt;Configuration System (Kconfig) — Zephyr Project documentation (nRF Connect SDK) (nordicsemi.com)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use device tree to set up PDM pin configurations with nrfx pdm directly (no dmic)</title><link>https://devzone.nordicsemi.com/thread/474982?ContentTypeID=1</link><pubDate>Thu, 21 Mar 2024 05:27:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41ceedf7-297d-486c-b8d0-6435cf66ff0d</guid><dc:creator>elliottke</dc:creator><description>&lt;p&gt;When I tried the following (modified to align with my overlay file):&lt;/p&gt;
&lt;p&gt;const struct pinctrl_dev_config* p_pinctrl_dev_cfg = &lt;br /&gt; PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(mic_dev));&lt;/p&gt;
&lt;p&gt;it fails with error: &amp;quot;&lt;span&gt;identifier &amp;quot;__pinctrl_dev_config__device_dts_ord_107&amp;quot; is undefined&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I see documentation saying that means the device is not allocated, usually due to an issue with Kconfig. I am not sure what to change in Kconfig, and the documentation makes it appear non-trivial to make changes. Hopefully it is something else that needs changing.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If we&amp;#39;re using dmic, the magic must happen when we enable&amp;nbsp;&lt;/span&gt;CONFIG_AUDIO_DMIC in prj.conf, but I can&amp;#39;t easily trace how that happens. But we are not using dmic, so I have to make that connection myself.&amp;nbsp;&lt;span&gt;There must be some step I&amp;#39;m missing to actually get the device allocated. Any ideas?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Our Kconfig, which I believe is unchanged from example projects:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2022 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

source &amp;quot;Kconfig.zephyr&amp;quot;

menu &amp;quot;Nordic Sta sample&amp;quot;

config CONNECTION_IDLE_TIMEOUT
	int &amp;quot;Time to be waited for a station to connect&amp;quot;
	default 30

config STA_SAMPLE_SSID
	string &amp;quot;SSID&amp;quot;
	help
	  Specify the SSID to connect

choice  STA_KEY_MGMT_SELECT
	prompt &amp;quot;Security Option&amp;quot;
	default STA_KEY_MGMT_WPA3

config STA_KEY_MGMT_NONE
	bool &amp;quot;Open Security&amp;quot;
	help
	  Enable for Open Security

config STA_KEY_MGMT_WPA2
	bool &amp;quot;WPA2 Security&amp;quot;
	help
	  Enable for WPA2 Security

config STA_KEY_MGMT_WPA2_256
	bool &amp;quot;WPA2 SHA 256 Security&amp;quot;
	help
	  Enable for WPA2-PSK-256 Security

config STA_KEY_MGMT_WPA3
	bool &amp;quot;WPA3 Security&amp;quot;
	help
	  Enable for WPA3 Security
endchoice

config STA_SAMPLE_PASSWORD
	string &amp;quot;Passphrase (WPA2) or password (WPA3)&amp;quot;
	help
	  Specify the Password to connect

config NRF700X_QSPI_ENCRYPTION_KEY
	string &amp;quot;16 bytes QSPI encryption key, only for testing purposes&amp;quot;
	depends on BOARD_NRF7002DK_NRF5340_CPUAPP
	help
	  Specify the QSPI encryption key
endmenu
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;KE&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use device tree to set up PDM pin configurations with nrfx pdm directly (no dmic)</title><link>https://devzone.nordicsemi.com/thread/474969?ContentTypeID=1</link><pubDate>Wed, 20 Mar 2024 21:34:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d283ffe-783d-4cf9-9840-6c424f236123</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi KE,&lt;/p&gt;
[quote user=""]&lt;div&gt;But I need that to be different pins for the different boards.&amp;nbsp;&lt;span style="font-family:inherit;"&gt;So my questions are:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;1) What should I change in the overlay configuration below? and&lt;/div&gt;[/quote]
&lt;p&gt;The pins are defined in the pinctrl node. In particular, the NRF_PSEL macro lines.&lt;/p&gt;
&lt;p&gt;For example, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;NRF_PSEL(PDM_CLK, 0, 25)&lt;/span&gt; means P0.25 is used for&amp;nbsp;PDM_CLK.&lt;/p&gt;
[quote user=""]2) How do I initialize the module in code, or alternatively, access the pin numbers to be able to pass to nrfx_pdm_config_t and do the initialization there?[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I dived a bit into the&amp;nbsp;drivers&amp;#39; implementation and was able to derive the pin numbers in the DMIC sample with this code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
PINCTRL_DT_DEFINE(DT_NODELABEL(dmic_dev));

int main(void)
{
	const struct device *const dmic_dev = DEVICE_DT_GET(DT_NODELABEL(dmic_dev));
	int ret;

	const struct pinctrl_dev_config* p_pinctrl_dev_cfg = 
							PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(dmic_dev));
	printk(&amp;quot;===================================================\n&amp;quot;);
	
	uint8_t t_state_cnt = p_pinctrl_dev_cfg-&amp;gt;state_cnt;
	printk(&amp;quot;pinctrl state_cnt = %d\n&amp;quot;, t_state_cnt);
	
	for (uint8_t i = 0; i &amp;lt; t_state_cnt; i++)
	{
		const struct pinctrl_state* tp_pinctrl_state = &amp;amp;p_pinctrl_dev_cfg-&amp;gt;states[i];

		printk(&amp;quot;  state #%02d - id = %d\n&amp;quot;, i, tp_pinctrl_state-&amp;gt;id);

		uint8_t t_pin_cnt = tp_pinctrl_state-&amp;gt;pin_cnt;
		printk(&amp;quot;  t_pin_cnt = %d\n&amp;quot;, t_pin_cnt);

		for (uint8_t j = 0; j &amp;lt; t_pin_cnt; j++)
		{
			const pinctrl_soc_pin_t t_pin = tp_pinctrl_state-&amp;gt;pins[j];
			uint32_t nrfx_abs_pin_num = t_pin &amp;amp; 0x0000FFFFU;
			printk(&amp;quot;    pin #%02d = 0x%08x - nrfx_abs_pin_num = 0x%08x\n&amp;quot;, 
						j, 
						t_pin,
						nrfx_abs_pin_num);
		}
	}

	printk(&amp;quot;===================================================\n&amp;quot;);
	
	...
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;arrived at that after&amp;nbsp;these steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Look into the PDM driver implementation to see how the pinctrl node are associated with the device node.&lt;br /&gt;Found:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/drivers/audio/dmic_nrfx_pdm.c#L570"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/drivers/audio/dmic_nrfx_pdm.c#L570&lt;br /&gt;&lt;br /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Look into&amp;nbsp;where the pinctrl macro above is defined, and investigate the definitions in the same file.&lt;br /&gt;Refer:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/include/zephyr/drivers/pinctrl.h"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/include/zephyr/drivers/pinctrl.h&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Associate the value of the pin variables with the definition of the NRF_PSEL macro used in the Devicetree.&lt;br /&gt;Refer:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h#L202-L204"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h#L202-L204&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I hope this&amp;nbsp;helps.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>