<?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>spi nor flash issues with spinlock asserting on nrf52832 with NCS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/88531/spi-nor-flash-issues-with-spinlock-asserting-on-nrf52832-with-ncs</link><description>hello Nordic 
 i am working with nrf52832, ncs 1.7.1 
 we have to turn on the power before trying to read jedec and to avooide changing ncs spi_nor or using SYS_INIT we decided to take the spi_nor driver and copy it and create our own flash driver based</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 14 Jun 2022 10:55:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/88531/spi-nor-flash-issues-with-spinlock-asserting-on-nrf52832-with-ncs" /><item><title>RE: spi nor flash issues with spinlock asserting on nrf52832 with NCS</title><link>https://devzone.nordicsemi.com/thread/372347?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2022 10:55:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96ca3f12-b337-4a92-b50e-6ca01362ebf5</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am happy to hear that you solved the initial issue.&lt;/p&gt;
&lt;p&gt;Please create a new ticket for the new issue.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spi nor flash issues with spinlock asserting on nrf52832 with NCS</title><link>https://devzone.nordicsemi.com/thread/372330?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2022 09:12:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2091fa7-1a61-4152-b565-72fde8a7a2f8</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;hi tesc&lt;/p&gt;
[quote userid="8164" url="~/f/nordic-q-a/88531/spi-nor-flash-issues-with-spinlock-asserting-on-nrf52832-with-ncs/370833#370833"]Have you had similar issues (recursive spinlock or other spinlock issues) earlier, and if so are there other DevZone threads where this has been discussed? Providing links to those would give valuable information to solving the current issue.[/quote]
&lt;p&gt;there is the thread and it can be closed (not sure how to close it without verifying the answer)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/88263/using-spi_nor-driver-with-nrf-sdk-connect-zephyr---driver-not-found"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/88263/using-spi_nor-driver-with-nrf-sdk-connect-zephyr---driver-not-found&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="8164" url="~/f/nordic-q-a/88531/spi-nor-flash-issues-with-spinlock-asserting-on-nrf52832-with-ncs/370833#370833"]In general, the &amp;quot;Recursive spinlock&amp;quot; assert happens if the same lock is attempted required twice without being unlocked in the meantime.[/quote]
&lt;p&gt;the problem was actually that in the init (called at POST_KERNAL) the flash driver is not yet powered on by that pin and eventually decided to implement the spi_nor ourselves and copied it and for start just added the power on&amp;nbsp; in the init and changed the call for the init to be at APPLICATION. that solved the issue.&lt;/p&gt;
&lt;p&gt;the spinlock happened because the init driver function failed at&amp;nbsp;the POST_KERNAL cause it could not get the id from the flash due to the flash not being powered on, so there was no device instance created, and then&amp;nbsp;in the power_request call with the instance that does not exist it&amp;nbsp;asserted.&lt;/p&gt;
&lt;p&gt;but thanks for the explanation regarding the spin-lock, its good to know&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;Ziv&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spi nor flash issues with spinlock asserting on nrf52832 with NCS</title><link>https://devzone.nordicsemi.com/thread/372329?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2022 09:11:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d029aa5-3009-4a51-a0ab-6bc45d69a45d</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;hi tesc&lt;/p&gt;
[quote userid="8164" url="~/f/nordic-q-a/88531/spi-nor-flash-issues-with-spinlock-asserting-on-nrf52832-with-ncs/370833#370833"]Have you had similar issues (recursive spinlock or other spinlock issues) earlier, and if so are there other DevZone threads where this has been discussed? Providing links to those would give valuable information to solving the current issue.[/quote]
&lt;p&gt;there is the thread and it can be closed (not sure how to close it without verifying the answer)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/88263/using-spi_nor-driver-with-nrf-sdk-connect-zephyr---driver-not-found"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/88263/using-spi_nor-driver-with-nrf-sdk-connect-zephyr---driver-not-found&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="8164" url="~/f/nordic-q-a/88531/spi-nor-flash-issues-with-spinlock-asserting-on-nrf52832-with-ncs/370833#370833"]In general, the &amp;quot;Recursive spinlock&amp;quot; assert happens if the same lock is attempted required twice without being unlocked in the meantime.[/quote]
&lt;p&gt;the problem was actually that in the init (called at POST_KERNAL) the flash driver is not yet powered on by that pin and eventually decided to implement the spi_nor ourselves and copied it and for start just added the power on&amp;nbsp; in the init and changed the call for the init to be at APPLICATION. that solved the issue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;but thanks for the explanation regarding the spin-lock, its good to know &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;how ever i have 2 questions and if you prefer than let me know and i will open a new thread for that&amp;nbsp;&lt;/p&gt;
&lt;p&gt;when tying to write a page (256 bytes) to the flash at a test in the beginning of the app it take 1ms to write that page but when trying to write within the app it takes 3ms and also i get a BUS FAULT. here is the log:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00000018] &amp;lt;err&amp;gt; os: ***** BUS FAULT *****
[00000018] &amp;lt;err&amp;gt; os:   Unstacking error
[00000018] &amp;lt;err&amp;gt; os: ***** HARD FAULT *****
[00000018] [1;31m&amp;lt;err&amp;gt; os:   Fault escalation (see below)
[00000018] &amp;lt;err&amp;gt; os: ***** BUS FAULT *****
[00000018] &amp;lt;err&amp;gt; os:   Precise data bus error
[00000018] &amp;lt;err&amp;gt; os:   BFAR Address: 0xfe80fec0
[00000018] &amp;lt;err&amp;gt; os: r0/a1:  0x2000bef0  r1/a2:  0xfe80fec0  r2/a3:  0xfe80ff28
[00000018] &amp;lt;err&amp;gt; os: r3/a4:  0x2000beef r12/ip:  0xfa000000 r14/lr:  0x00016d79
[00000018] &amp;lt;err&amp;gt; os:  xpsr:  0x81000005
[00000018] &amp;lt;err&amp;gt; os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
[00000018] &amp;lt;err&amp;gt; os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000
[00000018] &amp;lt;err&amp;gt; os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
[00000018] &amp;lt;err&amp;gt; os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
[00000018] &amp;lt;err&amp;gt; os: fpscr:  0x20001d78
[00000018] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x0003ef10
[00000018] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
[00000018] &amp;lt;err&amp;gt; os: Fault during interrupt handling

[00000018] &amp;lt;err&amp;gt; os: Current thread: 0x20003210 (unknown)
[00000018] &amp;lt;err&amp;gt; fatal_error: Resetting system
*** Booting Zephyr OS build v2.6.99-ncs1-1  ***&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;now i do have in the app another driver that uses spi (at the same time (getting samples and writing samples to flash), but it uses a different instance of spi so i don&amp;#39;t see why it shell create such a delay .. here is my complete .dts file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Copyright (c) 2022 Nordic Semiconductor ASA
// SPDX-License-Identifier: Apache-2.0

/dts-v1/;
#include &amp;lt;nordic/nrf52832_qfaa.dtsi&amp;gt;

/ {
	model = &amp;quot;halo_ep2&amp;quot;;
	compatible = &amp;quot;halo-ep2&amp;quot;;

	chosen {
		zephyr,sram = &amp;amp;sram0;
		zephyr,flash = &amp;amp;flash0;
		zephyr,code-partition = &amp;amp;slot0_partition;
		nordic,pm-ext-flash = &amp;amp;augu_flash_is25lp128;
	};

	sensors_on: sensors_on_node {
		compatible = &amp;quot;augury,gpio-power&amp;quot;;
		power_gpios = &amp;lt;&amp;amp;gpio0 22 GPIO_ACTIVE_LOW&amp;gt;;
		label = &amp;quot;SENSORS_ON&amp;quot;;
		status = &amp;quot;okay&amp;quot;;
		#power_resource-cells = &amp;lt;0&amp;gt;;
	};

	flash_on: flash_on_node {
		compatible = &amp;quot;augury,gpio-power&amp;quot;;
		power_gpios = &amp;lt;&amp;amp;gpio0 23 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
		label = &amp;quot;FLASH_ON&amp;quot;;
		status = &amp;quot;okay&amp;quot;;
		#power_resource-cells = &amp;lt;0&amp;gt;;
	};	

    leds {
        compatible = &amp;quot;gpio-leds&amp;quot;;
        led0_red: led_0 {
            gpios = &amp;lt;&amp;amp;gpio0 25 GPIO_ACTIVE_HIGH&amp;gt;;
            label = &amp;quot;RED_LED_0&amp;quot;;
        };
        led1_orange: led_1 {
            gpios = &amp;lt;&amp;amp;gpio0 26 GPIO_ACTIVE_HIGH&amp;gt;;
            label = &amp;quot;ORANGE_LED_1&amp;quot;;
        };
        led2_green: led_2 {
            gpios = &amp;lt;&amp;amp;gpio0 27 GPIO_ACTIVE_HIGH&amp;gt;;
            label = &amp;quot;GREEN_LED_2&amp;quot;;
        };							
    };

	aliases {
		led0-red = &amp;amp;led0_red;
		led1-orange = &amp;amp;led1_orange;
		led2-green = &amp;amp;led2_green;

	};
};

	&amp;amp;adc {
		status =&amp;quot;okay&amp;quot;;
	};

	&amp;amp;gpiote {
		status =&amp;quot;okay&amp;quot;;
	};

	&amp;amp;gpio0 {
		status =&amp;quot;okay&amp;quot;;
	};


	&amp;amp;spi1 {
		compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
		status = &amp;quot;okay&amp;quot;;
		sck-pin = &amp;lt;20&amp;gt;;
		mosi-pin = &amp;lt;14&amp;gt;;    // p0.14
		miso-pin = &amp;lt;16&amp;gt;;    // p0.16
		cs-gpios = &amp;lt;&amp;amp;gpio0 13 GPIO_ACTIVE_LOW&amp;gt;;
		iis3dwb@0 {
			compatible = &amp;quot;st,iis3dwb&amp;quot;;
			reg = &amp;lt;0&amp;gt;;
			int1_gpios = &amp;lt;&amp;amp;gpio0 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)&amp;gt;;
			int2_gpios = &amp;lt;&amp;amp;gpio0 12 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)&amp;gt;;
			label = &amp;quot;IIS3DWB&amp;quot;;
			power_resources = &amp;lt;&amp;amp;sensors_on&amp;gt;;
			spi-max-frequency = &amp;lt;8000000&amp;gt;;
		};
	};

	&amp;amp;spi2 {
		status = &amp;quot;okay&amp;quot;;
		sck-pin = &amp;lt;5&amp;gt;; // gpio 0 pin 5
		mosi-pin = &amp;lt;4&amp;gt;; // gpio 0 pin 4
		miso-pin = &amp;lt;2&amp;gt;; // gpio 0 pin 2
		compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
		cs-gpios = &amp;lt;&amp;amp;gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
		augu_flash_is25lp128: augu_flash_is25lp128@0 {
			compatible = &amp;quot;issi,augu_flash_is25lp128&amp;quot;;
			reg = &amp;lt;0&amp;gt;;
			label = &amp;quot;AUGU_FLASH_IS25LP128&amp;quot;;
			power_resources = &amp;lt;&amp;amp;flash_on&amp;gt;;
			jedec_id = [9d 60 18];
			spi-max-frequency = &amp;lt;8000000&amp;gt;; //&amp;lt;133000000&amp;gt;;
			page_size = &amp;lt;256&amp;gt;;
			block_size = &amp;lt;65536&amp;gt;;
			size = &amp;lt;0x8000000&amp;gt;;
		};
	};
	&amp;amp;flash0 {
		partitions {
			compatible = &amp;quot;fixed-partitions&amp;quot;;
			#address-cells = &amp;lt;1&amp;gt;;
			#size-cells = &amp;lt;1&amp;gt;;

			mbr_partition: partition@0 {
				label = &amp;quot;mbr&amp;quot;;
				reg = &amp;lt;0x00000000 0x00001000&amp;gt;;
			};
			boot_partition: partition@1000 {
				label = &amp;quot;mcuboot&amp;quot;;
				reg = &amp;lt;0x1000 0xc000&amp;gt;;
			};
			slot0_partition: partition@d000 {
				label = &amp;quot;image-0&amp;quot;;
				reg = &amp;lt;0xd000 0x6c800&amp;gt;;
			};
			slot1_partition: partition@79800 {
				label = &amp;quot;image-1&amp;quot;;
				reg = &amp;lt;0x79800 0x800&amp;gt;;
			};
			storage_partition: partition@7a000 {
				label = &amp;quot;storage&amp;quot;;
				reg = &amp;lt;0x7a000 0x6000&amp;gt;;
			};
		};
	};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;(running the app on another baord with nrd52840, with nand flash that writes 2k each time, works well, so i don&amp;#39;t know if it is a performance issue or something else.. i will also mention that the RAM take on the nrf52832 with zephyr and all is high:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[567/572] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      253604 B     419328 B     60.48%
            SRAM:       60282 B        64 KB     91.98%
        IDT_LIST:          0 GB         2 KB      0.00%
[568/572] Generating zephyr/mcuboot_primary_app.hex
[569/572] Generating zephyr/mcuboot_primary.hex
[570/572] Generating ../../zephyr/app_update.bin, ../../zephyr/app_signed.hex, ../../zephyr/app_test_update.hex, ../../zephyr/app_moved_test_update.hex
[571/572] Generating ../../zephyr/dfu_application.zip
[572/572] Generating zephyr/merged.hex&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;any idea why i get the BUS FAULT ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;the other question i will leave for now it is also regarding a try to improve the current spi_nor_write function but anyhow it will not solve the 3ms issue and if it will remain on 1ms per page write as seen in the first test then we will be ok&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;hope to read from you soon&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;Ziv&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spi nor flash issues with spinlock asserting on nrf52832 with NCS</title><link>https://devzone.nordicsemi.com/thread/370833?ContentTypeID=1</link><pubDate>Fri, 03 Jun 2022 09:46:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b60a9ef-d13e-48d0-ba7b-8389965677a7</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]we again fall on assertions of spinlock[/quote]
&lt;p&gt;Have you had similar issues (recursive spinlock or other spinlock issues) earlier, and if so are there other DevZone threads where this has been discussed? Providing links to those would give valuable information to solving the current issue.&lt;/p&gt;
&lt;p&gt;In general, the &amp;quot;Recursive spinlock&amp;quot; assert happens if the same lock is attempted required twice without being unlocked in the meantime. Trying to acquire a lock that you already have, will assert and give this error. This may happen for instance if the lock is needed from two different places running in different interrupt contexts on the same core.&lt;/p&gt;
[quote user=""]and there is my&amp;nbsp;addition to the spi_nor_configure function in the&amp;nbsp;copied driver[/quote]
&lt;p&gt;I assume we are talking about changes to zephyr/drivers/flash/spi_nor.c.&lt;/p&gt;
&lt;p&gt;Based on the log, you never reach &amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOG_INF(&amp;quot;passed id test&amp;quot;);&amp;#39;, which means your custom augu_power_request function might be at fault. I would either do a debug session putting breakpoints various locations in that function, or simply add some debug output (logging) at some locations in that function, to establish how far it gets.&lt;/p&gt;
&lt;p&gt;For instance you could add to this portion a TEMPORARY log message (remember to remove it after debugging) just to confirm the step is passed:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	int err = onoff_request(&amp;amp;data-&amp;gt;onoff_mgr, &amp;amp;power_client);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;failed in power resource request: err = %d\n&amp;quot;, err);
		return err;
	} else {
	    LOG_ERR(&amp;quot;succeeded in power resource request&amp;quot;);
	}&lt;/pre&gt;By the way, I do notice in your added code, you are not checking the return value of the device_get_binding call:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	const struct device* power_dev = device_get_binding(&amp;quot;FLASH_ON&amp;quot;);
    int ret = augu_power_request(power_dev);&lt;/pre&gt;&lt;br /&gt;If the returned power_dev is NULL, because of some error in configuration or other, then you are sending a NULL reference to augu_power_request which could make things break. Checking the value (either before calling augu_power_request or inside augu_power_request before using it) would be a good idea.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>