<?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>BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll</link><description>Hi, 
 
 I am using an nRF52833dk to run a simple async SPI transceive API using k_poll My code is as below, for some reason it always returns BUS FAULT error Code: 
 
 Error: Kindly help to solve this. 
 
 Thanks, 
 Ubaid</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Feb 2022 09:31:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll" /><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/353300?ContentTypeID=1</link><pubDate>Wed, 16 Feb 2022 09:31:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ca61775-1097-49ee-a8c1-a56fe87a8a15</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Thank you for the help&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;,&lt;br /&gt;&lt;br /&gt;Noted, will resume the discussion on other ticket meant for this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/353210?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 23:34:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b572895-8997-4664-8118-0b45b6aad66f</guid><dc:creator>Simon</dc:creator><description>[quote user="Ubaid_M"]Is that every 200ms it should poll the API &amp;quot;spi_transceive_async&amp;quot;,&amp;nbsp;[/quote]
&lt;p&gt;I think It means that the k_poll will time out after 200ms, not that it will poll every 200ms.&lt;/p&gt;
[quote user="Ubaid_M"]&lt;p&gt;But still it polls only once, even after adding number of events to 2:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;ret&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;k_poll&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;async_evt&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;K_MSEC&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;200&lt;/span&gt;&lt;span&gt;));&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Kindly suggest how I can get above code to poll twice&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;Setting this to two will not make it poll twice, polling happens continuously all the time. According to my understanding, if you set it to 2, you need to&amp;nbsp;generate two events for k_poll to continue (&lt;span&gt;spi_transceive_async() will generate only 1 event&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;I would recommend you to read the&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/a4edab554f67590a89703067af703c7996604562/include/kernel.h#L5565-L5606"&gt; explanatory text above the definition of k_poll()&lt;/a&gt; to understand the function better.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/353209?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 23:29:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3d58129-5f8f-4fd5-bccd-702a44c95810</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Test the following code:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4718.spi_5F00_loopback_5F00_async.zip"&gt;spi_loopback_async.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t have an nRF52833 DK, so I tested it on an nRF52840 DK. You need to add an overlay file nrf52833dk_nrf52833.overlay and modify&amp;nbsp;SPI_DRV_NAME in main.c.&lt;/p&gt;
&lt;p&gt;If the program runs as expected, you should get the following output:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.7.99-ncs1-rc2  ***
Polling...
SPI test on buffers TX/RX 0x20000280/0x20000d70
Start async call
Polling...
Sent: &amp;#39;0123456789abcdef&amp;#39; |||  Received: &amp;#39;0123456789abcdef&amp;#39;
SPI test on buffers TX/RX 0x20000280/0x20000d70
Start async call
Polling...
Sent: &amp;#39;0123456789abcdef&amp;#39; |||  Received: &amp;#39;0123456789abcdef&amp;#39;
SPI test on buffers TX/RX 0x20000280/0x20000d70
Start async call
Polling...
Sent: &amp;#39;0123456789abcdef&amp;#39; |||  Received: &amp;#39;0123456789abcdef&amp;#39;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/352884?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 12:58:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:854fa3a5-13cf-4e43-993e-7b4c6cad95e5</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="72692" url="~/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll/352670#352670"]you can strip down the test sample and remove everything you don&amp;#39;t need[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I did just this in hopes to get the polling to work twice, as in below code:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;


#define STACK_SIZE 512
#define BUF_SIZE 17
uint8_t buffer_tx[] = &amp;quot;0123456789abcdef\0&amp;quot;;
uint8_t buffer_rx[BUF_SIZE] = {};

struct spi_cs_control spi_cs = {
	.gpio_pin = 11,
	.gpio_dt_flags = GPIO_ACTIVE_LOW,
	.delay = 0,
};

/*
 * We need 5x(buffer size) + 1 to print a comma-separated list of each
 * byte in hex, plus a null.
 */
uint8_t buffer_print_tx[BUF_SIZE * 5 + 1];
uint8_t buffer_print_rx[BUF_SIZE * 5 + 1];

#define SPI_CS (&amp;amp;spi_cs)

struct spi_config spi_cfg_slow = {
	.frequency = 250000,

	.operation = SPI_OP_MODE_MASTER | SPI_MODE_CPOL |
	SPI_MODE_CPHA | SPI_WORD_SET(8) | SPI_LINES_SINGLE,
	.slave = 1,
	.cs = SPI_CS,
};

#if (CONFIG_SPI_ASYNC)
static struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig);
static struct k_poll_event async_evt =
	K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
				 K_POLL_MODE_NOTIFY_ONLY,
				 &amp;amp;async_sig);
static K_SEM_DEFINE(caller, 0, 1);
K_THREAD_STACK_DEFINE(spi_async_stack, STACK_SIZE);
static int result = 1;

static void spi_async_call_cb(struct k_poll_event *async_evt,
			      struct k_sem *caller_sem,
			      void *unused)
{
	int ret;

	printk(&amp;quot;Polling...&amp;quot;);

	while (1) {
		ret = k_poll(async_evt, 2, K_MSEC(200));

		result = async_evt-&amp;gt;signal-&amp;gt;result;
		k_sem_give(caller_sem);

		/* Reinitializing for next call */
		async_evt-&amp;gt;signal-&amp;gt;signaled = 0U;
		async_evt-&amp;gt;state = K_POLL_STATE_NOT_READY;
	}
}

static int spi_async_call(const struct device *dev,
			  struct spi_config *spi_conf)
{
	const struct spi_buf tx_bufs[] = {
		{
			.buf = buffer_tx,
			.len = BUF_SIZE,
		},
	};
	const struct spi_buf rx_bufs[] = {
		{
			.buf = buffer_rx,
			.len = BUF_SIZE,
		},
	};
	const struct spi_buf_set tx = {
		.buffers = tx_bufs,
		.count = ARRAY_SIZE(tx_bufs)
	};
	const struct spi_buf_set rx = {
		.buffers = rx_bufs,
		.count = ARRAY_SIZE(rx_bufs)
	};
	int ret;

	printk(&amp;quot;Start async call&amp;quot;);

	ret = spi_transceive_async(dev, spi_conf, &amp;amp;tx, &amp;amp;rx, &amp;amp;async_sig);
	if (ret == -ENOTSUP) {
		printk(&amp;quot;Not supported&amp;quot;);
		return 0;
	}

	if (ret) {
		printk(&amp;quot;Code %d&amp;quot;, ret);
		return -1;
	}

	k_sem_take(&amp;amp;caller, K_FOREVER);

	if (result)  {
		printk(&amp;quot;Call code %d&amp;quot;, ret);
		return -1;
	}

	printk(&amp;quot;Passed&amp;quot;);

	return 0;
}
#endif


void test_spi_loopback(void)
{
#if (CONFIG_SPI_ASYNC)
	struct k_thread async_thread;
	k_tid_t async_thread_id;
#endif
	const struct device *spi_slow;
	const struct device *spi_fast;

	printk(&amp;quot;SPI test on buffers TX/RX %p/%p&amp;quot;, buffer_tx, buffer_rx);

#if defined(CONFIG_SPI_LOOPBACK_CS_GPIO)
	if (cs_ctrl_gpio_config()) {
		return;
	}
#endif /* CONFIG_SPI_LOOPBACK_CS_GPIO */

	spi_slow = device_get_binding(&amp;quot;SPI_0&amp;quot;);
	if (!spi_slow) {
		printk(&amp;quot;Cannot find !\n&amp;quot;);
		return;
	}

	spi_fast = spi_slow;

#if (CONFIG_SPI_ASYNC)
	async_thread_id = k_thread_create(&amp;amp;async_thread,
					  spi_async_stack, STACK_SIZE,
					  (k_thread_entry_t)spi_async_call_cb,
					  &amp;amp;async_evt, &amp;amp;caller, NULL,
					  K_PRIO_COOP(7), 0, K_NO_WAIT);
#endif

	printk(&amp;quot;SPI test slow config&amp;quot;);

	if (
#if (CONFIG_SPI_ASYNC)
	    spi_async_call(spi_slow, &amp;amp;spi_cfg_slow)
#endif
	    ) {
		goto end;
	}

	printk(&amp;quot;All tx/rx passed&amp;quot;);
end:
#if (CONFIG_SPI_ASYNC)
	k_thread_abort(async_thread_id);
#else
	;
#endif
}



void main(void)
{
	printk(&amp;quot;Hello World! %s\n&amp;quot;, CONFIG_BOARD);
	test_spi_loopback();
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But still it polls only once, even after adding number of events to 2:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;ret&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;k_poll&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;async_evt&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;K_MSEC&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;200&lt;/span&gt;&lt;span&gt;));&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Kindly suggest how I can get above code to poll twice&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/352782?ContentTypeID=1</link><pubDate>Sun, 13 Feb 2022 13:40:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:548b4e88-108b-4145-b8d0-43fa09f90a25</guid><dc:creator>Ubaid_M</dc:creator><description>[quote userid="72692" url="~/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll/352670#352670"]If you get that to work[/quote]
&lt;p&gt;Many Thanks @&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;&amp;nbsp;for helping me out, I was able to execute the spi_loopback with a few tweaks on nRF52833. As in the snap below:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644759146799v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Actually, my understanding of:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret = k_poll(async_evt, 1, K_MSEC(200));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is that every 200ms it should poll the API &amp;quot;spi_transceive_async&amp;quot;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So kindly help me understand what is the implication of the 2 arguments&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;strong&gt;int &lt;/strong&gt;&lt;span&gt;&lt;strong&gt;num_events&lt;/strong&gt; &amp;amp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;k_timeout_t timeout&amp;nbsp;&lt;/strong&gt;in API k_poll..?&lt;br /&gt;&lt;br /&gt;And how can I test their variations for&amp;nbsp;&lt;span&gt;&amp;quot;spi_transceive_async&amp;quot;&lt;/span&gt;..?&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Thanking you in anticipation,&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/352670?ContentTypeID=1</link><pubDate>Fri, 11 Feb 2022 14:21:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7aaa670-6c1c-4e98-8ccf-b0f8ad94283b</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;m not too familiar with spi_transceive_async(), so I decided to run the sample&amp;nbsp;zephyr\tests\drivers\spi\spi_loopback,&amp;nbsp;which demonstrates how to properly &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/901604f9c22db2cbe7976297639c3b2be1283089/tests/drivers/spi/spi_loopback/src/spi.c#L547"&gt;use spi_transceive_async()&lt;/a&gt;. I don&amp;#39;t have an nRF52833 DK at hand at the moment, but I built it for the nRF52840 DK. Then I connected P1.03 and P1.04 together and it worked fine. I also added a conf file for the nRF5232 and that also worked.&lt;/p&gt;
&lt;p&gt;Could you&amp;nbsp;add a file&amp;nbsp;nrf52833dk_nrf52833.conf to zephyr\tests\drivers\spi\spi_loopback\boards with the following content:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SPI_3_NRF_ORC=0x00
CONFIG_SPI_3_NRF_RX_DELAY=1

CONFIG_SPI_LOOPBACK_DRV_NAME=&amp;quot;SPI_1&amp;quot;
CONFIG_SPI_LOOPBACK_CS_GPIO=y
CONFIG_SPI_LOOPBACK_CS_CTRL_GPIO_DRV_NAME=&amp;quot;GPIO_0&amp;quot;
CONFIG_SPI_LOOPBACK_CS_CTRL_GPIO_PIN=28
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then connect together P0.30 and P1.08 (doublecheck \zephyr\tests\drivers\spi\spi_loopback\build\zephyr\zephyr.dts to see that this is the pins &amp;quot;SPI_1&amp;quot; uses), build and flash&amp;nbsp;&lt;span&gt;zephyr\tests\drivers\spi\spi_loopback and see if you get the following output:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.7.0-ncs1  ***
Running test suite test_spi
===================================================================
START - test_spi_loopback
I: SPI test on buffers TX/RX 0x200001ad/0x2000096a
I: SPI test slow config
I: Start complete multiple
I: Passed
I: Start complete loop
I: Passed
I: Start null tx
I: Passed
I: Start half start
I: Passed
I: Start half end
I: Passed
I: Start every 4
I: Passed
I: Start async call
I: Passed
I: SPI test fast config
I: Start complete multiple
I: Passed
I: Start complete loop
I: Passed
I: Start null tx
I: Passed
I: Start half start
I: Passed
I: Start half end
I: Passed
I: Start every 4
I: Passed
I: Start async call
I: Passed
I: Start complete loop
I: Passed
I: Start complete loop
I: Passed
I: All tx/rx passed
 PASS - test_spi_loopback in 0.60 seconds
===================================================================
Test suite test_spi succeeded
===================================================================
PROJECT EXECUTION SUCCESSFUL
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you see these lines printed, it means the spi_transceive_async() call worked:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;I: Start async call
I: Passed&lt;/pre&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you get that to work, you can strip down the test sample and remove everything you don&amp;#39;t need. If you don&amp;#39;t get it to work, please tell me and I will get a hold of an nRF52833 and test it myself.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/352468?ContentTypeID=1</link><pubDate>Fri, 11 Feb 2022 04:50:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:091c7eb7-75be-4a3f-94eb-1e189753c632</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;,&lt;/p&gt;
[quote userid="72692" url="~/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll/352384#352384"]Could you upload the whole project (main.c, prj.conf, CMakeLists.txt, .overlay files and so on...) in zipped format.[/quote]
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/SPI_5F00_Sample.7z"&gt;devzone.nordicsemi.com/.../SPI_5F00_Sample.7z&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please suggest&amp;nbsp;&lt;/p&gt;
[quote userid="108934" url="~/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll/352347#352347"]It seems even now the code is throwing faults:&lt;br /&gt;Please find the sequence of code execution leading to faults as in below:[/quote]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/352384?ContentTypeID=1</link><pubDate>Thu, 10 Feb 2022 14:35:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52603ac1-1827-43a1-b51d-1e8a3f63dac6</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Could you upload the whole project (main.c, prj.conf, CMakeLists.txt, .overlay files and so on...) in zipped format.&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: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/352347?ContentTypeID=1</link><pubDate>Thu, 10 Feb 2022 13:32:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:742b22f9-eb74-421c-8ad9-2adf58f4e918</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt;&amp;nbsp;&amp;amp; Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;It seems even now the code is throwing faults:&lt;br /&gt;Please find the sequence of code execution leading to faults as in below:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499476032v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;kernel.h&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499511116v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;poll.c&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499590888v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;poll.c&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499692773v5.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;fault_s.S&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499730125v6.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;fault_s.S&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499781241v7.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;fault.c&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499823040v8.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;fault.c&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499855084v9.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;fault.c&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644499887486v10.png" alt=" " /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My code is:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;

#define STACKSIZE 1024
#define PRIORITY 99

void main(void)
{
	struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig);
	uint8_t data = 40, val =0, sz = 9;
	    struct spi_buf bufs = {
            .buf = &amp;amp;data,
            .len = sizeof(data)
    };
    struct spi_buf_set tx = {
        .buffers = &amp;amp;bufs
    };

    tx.count = 1;

	struct spi_buf rbufs = {
            .buf = &amp;amp;val,
            .len = sizeof(val)
    };
    struct spi_buf_set rx = {
        .buffers = &amp;amp;rbufs
    };
	struct spi_config spi_cfg;
	struct spi_cs_control cs_ctrl;

	cs_ctrl.gpio_dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
    cs_ctrl.gpio_pin = 11;
    cs_ctrl.delay = 0;

	spi_cfg.operation = SPI_WORD_SET(8) | SPI_OP_MODE_MASTER | SPI_LINES_SINGLE; 
    spi_cfg.frequency = 1000000;
	spi_cfg.cs = &amp;amp;cs_ctrl;

	const struct device * sp;
	sp = device_get_binding(&amp;quot;SPI_0&amp;quot;);

			data++;
			struct k_poll_event  async_evt =
		K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
					 K_POLL_MODE_NOTIFY_ONLY,
					 &amp;amp;async_sig);

			printk(&amp;quot;transmitted data: %u \n&amp;quot;, data);
			int error = spi_transceive_async(sp,&amp;amp;spi_cfg,&amp;amp;tx, &amp;amp;rx,&amp;amp;async_sig);
			int ret = k_poll(&amp;amp;async_evt, 10, K_MSEC(1000));
			printk(&amp;quot;received data: %u \n&amp;quot;, val);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kindly help to solve this.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/352260?ContentTypeID=1</link><pubDate>Thu, 10 Feb 2022 09:40:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c4e7a5b-4ef2-4cec-a3ee-9058151dee2b</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt;,&lt;br /&gt;&lt;br /&gt;Thank you so much,&amp;nbsp;&lt;/p&gt;
[quote userid="6207" url="~/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll/351704#351704"]&lt;p&gt;It does not look like you have initialized your signal&lt;/p&gt;
&lt;div&gt;&lt;div class="evolution-code-editor theme-clouds"&gt;&lt;a href="#" class="fullscreen"&gt;Fullscreen&lt;/a&gt;&lt;div class=" ace_editor ace-clouds" style="width:100%;height:14px;"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;I was able to solve that bus fault issue.&lt;br /&gt;&lt;br /&gt;My updated code is:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;

#define STACKSIZE 1024
#define PRIORITY 99

void main(void)
{
	static struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig);
	uint8_t data = 40, val =0, sz = 9;
	    struct spi_buf bufs = {
            .buf = &amp;amp;data,
            .len = sizeof(data)
    };
    struct spi_buf_set tx = {
        .buffers = &amp;amp;bufs
    };

    tx.count = 1;

	struct spi_buf rbufs = {
            .buf = &amp;amp;val,
            .len = sizeof(val)
    };
    struct spi_buf_set rx = {
        .buffers = &amp;amp;rbufs
    };
	struct spi_config spi_cfg;
	struct spi_cs_control cs_ctrl;

	cs_ctrl.gpio_dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
    cs_ctrl.gpio_pin = 11;
    cs_ctrl.delay = 0;

	spi_cfg.operation = SPI_WORD_SET(8) | SPI_OP_MODE_MASTER | SPI_LINES_SINGLE; 
    spi_cfg.frequency = 1000000;
	spi_cfg.cs = &amp;amp;cs_ctrl;

	const struct device * sp;
	sp = device_get_binding(&amp;quot;SPI_0&amp;quot;);

			data++;
			struct k_poll_event  async_evt =
		K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
					 K_POLL_MODE_NOTIFY_ONLY,
					 &amp;amp;async_sig);

			printk(&amp;quot;transmitted data: %u \n&amp;quot;, data);
			int error = spi_transceive_async(sp,&amp;amp;spi_cfg,&amp;amp;tx, &amp;amp;rx,&amp;amp;async_sig);
			int ret = k_poll(&amp;amp;async_evt, 10, K_MSEC(1000));
			printk(&amp;quot;received data: %u \n&amp;quot;, val);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And the output is:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644485902583v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;The execution just exists after printing &amp;#39;r&amp;#39; from the last print statement&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;printk(&amp;quot;received data: %u \n&amp;quot;, val);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Why isn&amp;#39;t it polling at the specified frequency of 1000ms and rather prematurely exiting after one execution.&lt;/p&gt;
&lt;p&gt;Kindly suggest.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/351704?ContentTypeID=1</link><pubDate>Tue, 08 Feb 2022 09:00:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98c55d98-9970-4013-84cc-0ff86f1d5125</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;It does not look like you have initialized your signal&lt;/p&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;static struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig);&lt;/pre&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/351662?ContentTypeID=1</link><pubDate>Tue, 08 Feb 2022 05:09:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eaa9a40a-fa5d-4b73-aa95-e7c8e051c173</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;,&lt;br /&gt;&lt;br /&gt;I am a little short on time, so rather debugging in detail,&lt;br /&gt;Can you kindly suggest if this code is the right way to use async SPI API&lt;/p&gt;
[quote userid="108934" url="~/f/nordic-q-a/84480/bus-fault-in-application-code-using-k_poll"]Code:[/quote]
&lt;p&gt;&lt;br /&gt;I have never used k_poll &amp;amp; async APIs before, hence I doubt if it is right.&lt;br /&gt;Also, is the sequence fine..?&lt;br /&gt;&lt;br /&gt;Within main,&lt;br /&gt;Post SPI configuration I am calling&lt;br /&gt;&lt;br /&gt;&lt;span&gt; &lt;/span&gt;K_POLL_EVENT_INITIALIZER followed by&amp;nbsp;spi_transceive_async() followed by&amp;nbsp;k_poll()&lt;br /&gt;&lt;br /&gt;&lt;span&gt;spi_transceive_async() executes fine, post which I get the bus fault error in the above code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kindly help.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT in application code using k_poll</title><link>https://devzone.nordicsemi.com/thread/351654?ContentTypeID=1</link><pubDate>Tue, 08 Feb 2022 00:31:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08d217ca-43c8-4068-8daa-96f882ca5cbd</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Could you use addr2line to figure out what line the instruction address 0x0001dfde corresponds to? Follow the instuctions under&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-3-ncs-v1-4-0#mcetoc_1f4cg7h4q0"&gt;3.4 Other tips and tools&lt;/a&gt;&amp;nbsp;--&amp;gt; Hard faults, to see how you can do this.&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>