<?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 nrfx SAADC driver on Zephyr RTOS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72487/how-to-use-nrfx-saadc-driver-on-zephyr-rtos</link><description>Hello guys. 
 We use NCS v1.4.2 and Zephyr RTOS to develop the application code for our nRF52840 SoC. 
 Thanks to your support, we were able to use Zephyr ADC APIs and take the readings from some ADC channels ( thread ). 
 However, we would like to benefit</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 08 Mar 2021 14:56:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72487/how-to-use-nrfx-saadc-driver-on-zephyr-rtos" /><item><title>RE: How to use nrfx SAADC driver on Zephyr RTOS</title><link>https://devzone.nordicsemi.com/thread/298438?ContentTypeID=1</link><pubDate>Mon, 08 Mar 2021 14:56:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2f018c9-f5da-4e7a-aeb3-b5cfbedf8cab</guid><dc:creator>bojan</dc:creator><description>&lt;p&gt;Hello, &lt;a href="https://devzone.nordicsemi.com/members/markus-schellenberger"&gt;Albrecht Markus Schellenberger&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Thank you very much for your support!&lt;/p&gt;
&lt;p&gt;Great to read that nrfx_timer_init() returns NRFX_SUCCESS. Let me dive deeper into my work then!&lt;/p&gt;
&lt;p&gt;I will feel free to come back again if I run into some trouble.&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use nrfx SAADC driver on Zephyr RTOS</title><link>https://devzone.nordicsemi.com/thread/298434?ContentTypeID=1</link><pubDate>Mon, 08 Mar 2021 14:47:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00769554-1af9-442a-87e3-fe493c4f60b4</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p&gt;Hello Bojan,&lt;/p&gt;
&lt;p&gt;You are getting a fatal error because you have not connected your SAADC peripheral to an interrupt service handler yet. You can do this with the following command:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;IRQ_CONNECT(DT_IRQN(DT_NODELABEL(adc)),
            DT_IRQ(DT_NODELABEL(adc), priority),
            nrfx_saadc_irq_handler, NULL, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding the timer:&lt;/p&gt;
&lt;p&gt;Actually, error code &lt;strong&gt;0xBAD0000&amp;nbsp;&lt;/strong&gt;is equal to &lt;strong&gt;NRFX_SUCCESS&lt;/strong&gt; (see also &lt;em&gt;nrfx_errors.h&lt;/em&gt; in ../modules/hal/nordic/nrfx/drivers). To avoid confusion, you could add something like this after the call of the init-function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (err_code != NRFX_SUCCESS) {
        LOG_ERR(&amp;quot;nrfx_timer_init error: %08x&amp;quot;, err_code);
        return;
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then you do not have to care about the error code value anymore.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use nrfx SAADC driver on Zephyr RTOS</title><link>https://devzone.nordicsemi.com/thread/298359?ContentTypeID=1</link><pubDate>Mon, 08 Mar 2021 12:30:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db00c606-5484-430e-b294-69d99bb49ff8</guid><dc:creator>bojan</dc:creator><description>&lt;p&gt;I wanted to give it a try with nrfx timer, by including only &lt;em&gt;&lt;span style="background-color:rgba(204, 255, 255, 1);"&gt;timer_init() &lt;/span&gt;&lt;/em&gt;function in main.c:&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void timer_init(void)
{
    nrfx_err_t err_code;

    nrfx_timer_config_t timer_config = NRFX_TIMER_DEFAULT_CONFIG;
    timer_config.frequency = NRF_TIMER_FREQ_31250Hz;
    err_code = nrfx_timer_init(&amp;amp;m_sample_timer, &amp;amp;timer_config, timer_handler);
    printk(&amp;quot;nrfx_timer_init: %u\n&amp;quot;, err_code);
    //APP_ERROR_CHECK(err_code);
    nrfx_timer_extended_compare(&amp;amp;m_sample_timer,
                                NRF_TIMER_CC_CHANNEL0,
                                nrfx_timer_ms_to_ticks(&amp;amp;m_sample_timer, saadc_sampling_rate),
                                NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                false);

    nrfx_timer_resume(&amp;amp;m_sample_timer);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Now the code runs but &lt;em&gt;&lt;span style="background-color:rgba(204, 255, 255, 1);"&gt;nrfx_timer_init() &lt;/span&gt;&lt;/em&gt;function returns &lt;span style="background-color:#ff00ff;"&gt;&lt;strong&gt;0xBAD0000&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For the nrfx timers, I included the following in &lt;span style="background-color:rgba(255, 153, 204, 1);"&gt;&lt;em&gt;prj.config&lt;/em&gt;&lt;/span&gt; file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_NRFX_TIMER=y
CONFIG_NRFX_TIMER1=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;nrfx_timer.h&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in main.c.&lt;/p&gt;
&lt;p&gt;I also tried to connect Zephyr&amp;#39;s and nrfx timer IRQ handlers with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;IRQ_CONNECT(TIMER1_IRQn, NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
            nrfx_timer_1_irq_handler, NULL, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;but to no avail. What I am missing in the case of nrfx timers?&lt;/p&gt;
&lt;p&gt;My impressions are that some deeper explanation is needed (e.g. in the form of tutorials) on how we can benefit from nrfx drivers in Zephyr environment. One example we currently have (&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/boards/nrf/nrfx/README.html?highlight=nrfx#nrfx-use-example" rel="noopener noreferrer" target="_blank"&gt;link&lt;/a&gt;) is not enough.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Bojan.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use nrfx SAADC driver on Zephyr RTOS</title><link>https://devzone.nordicsemi.com/thread/298296?ContentTypeID=1</link><pubDate>Mon, 08 Mar 2021 09:44:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e87db1a2-1912-4ff9-b03a-54ca31797dd0</guid><dc:creator>bojan</dc:creator><description>&lt;p&gt;Just figured out that I needed to include:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_ADC=n
CONFIG_NRFX_SAADC=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Instead of:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_ADC=n
CONFIG_ADC_NRFX_SAADC=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The code now compiles but when I try to debug it I get stuck:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.4.0-ncs2  ***
[00:00:00.345,001] &#x1B;[1;31m&amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 1: Unhandled interrupt on CPU 0&#x1B;[0m
[00:00:00.353,698] &#x1B;[1;31m&amp;lt;err&amp;gt; os: Current thread: 0x20002708 (unknown)&#x1B;[0m
[00:00:00.365,783] &#x1B;[1;31m&amp;lt;err&amp;gt; fatal_error: Resetting system&#x1B;[0m&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1615200056123v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;The only thing I have in my main() function is adc_configure() with the following content:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void adc_configure(void)
{
    int err_code;

    nrfx_saadc_adv_config_t saadc_adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG;
    saadc_adv_config.internal_timer_cc = 0;
    saadc_adv_config.start_on_end = true;

    err_code = nrfx_saadc_init(NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY);
    //APP_ERROR_CHECK(err_code);

    static nrfx_saadc_channel_t channel_configs[ADC_CHANNELS_IN_USE];

    uint8_t channel_mask = 0;
    for(int i = 0; i &amp;lt; ADC_CHANNELS_IN_USE; i++) {
        nrf_saadc_input_t pin = ANALOG_INPUT_MAP[i];
        // Apply default config to each channel
        nrfx_saadc_channel_t config = NRFX_SAADC_DEFAULT_CHANNEL_SE(pin, i);

        // Replace some parameters in default config
        config.channel_config.reference = NRF_SAADC_REFERENCE_VDD4;          
        config.channel_config.gain = NRF_SAADC_GAIN1_4;

        // Copy to list of channel configs
        memcpy(&amp;amp;channel_configs[i], &amp;amp;config, sizeof(config));

        // Update channel mask
        channel_mask |= 1 &amp;lt;&amp;lt; i;
    }

    err_code = nrfx_saadc_channels_config(channel_configs, ADC_CHANNELS_IN_USE);
    //APP_ERROR_CHECK(err_code);

    err_code = nrfx_saadc_advanced_mode_set(channel_mask,
                                            NRF_SAADC_RESOLUTION_14BIT,
                                            &amp;amp;saadc_adv_config,
                                            event_handler);
    //APP_ERROR_CHECK(err_code);
                                            
    // Configure two buffers to ensure double buffering of samples, to avoid data loss when the sampling frequency is high
    err_code = nrfx_saadc_buffer_set(&amp;amp;samples[next_free_buf_index()][0], SAADC_BUF_SIZE);
    //APP_ERROR_CHECK(err_code);

    err_code = nrfx_saadc_buffer_set(&amp;amp;samples[next_free_buf_index()][0], SAADC_BUF_SIZE);
    //APP_ERROR_CHECK(err_code);

    err_code = nrfx_saadc_mode_trigger();
    //APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Please help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>