<?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>Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/101071/saving-coredumps-to-external-flash</link><description>Hi, 
 Chip: nRF52840 
 OS: nRF Connect / Zephyr: v2.3.0 
 Problem: Saving coredumps to external flash 
 We&amp;#39;re trying to add a bunch of debugging features to our firmware before field trials. 
 We&amp;#39;ve been trying to saving coredumps to external flash, so</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 May 2024 10:43:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/101071/saving-coredumps-to-external-flash" /><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/486003?ContentTypeID=1</link><pubDate>Mon, 27 May 2024 10:43:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6222fe4b-f7fa-4cf8-9dde-c0abf175845e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello Sam,&lt;/p&gt;
&lt;p&gt;The team has not been able to prioritize this feature request, unfortunately.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/485892?ContentTypeID=1</link><pubDate>Fri, 24 May 2024 19:16:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:728c1ef3-a71c-4afb-94f4-7883569f2356</guid><dc:creator>motters</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thought i&amp;#39;d pop back 8 months later and see if this is now supported?&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Sam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/448277?ContentTypeID=1</link><pubDate>Fri, 29 Sep 2023 08:49:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ef4001a-f48d-448e-94a1-56556dd2a6fb</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Sam,&lt;/p&gt;
&lt;p&gt;Unfortunately, saving the coredump to external flash is still not supported. The test I&amp;nbsp;did was for internal flash. For external flash, I believe it might be necessary to create a separate backend.&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/issues/54325"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/54325&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/448274?ContentTypeID=1</link><pubDate>Fri, 29 Sep 2023 08:36:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f75f33f-883c-4467-90d2-69a4f3f2791c</guid><dc:creator>motters</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I did explore this but i had issue with writing to external flash.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think the zephyr method only supports writing to internal uC flash.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Sam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/448265?ContentTypeID=1</link><pubDate>Fri, 29 Sep 2023 08:19:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c46f07d-c34b-47a6-9875-013ae7837b42</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Sorry, there&amp;nbsp;is a flash backend; it&amp;#39;s just that&amp;nbsp;our documentation&amp;nbsp;has not&amp;nbsp;been updated to include it yet.&amp;nbsp;It is currently covered&amp;nbsp;in the upstream Zephyr documentation at&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/services/debugging/coredump.html"&gt;https://docs.zephyrproject.org/latest/services/debugging/coredump.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried testing the coredump module with the&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/bluetooth/peripheral_lbs/README.html"&gt;Bluetooth: Peripheral LBS&lt;/a&gt;&amp;nbsp;sample in nRF Connect SDK v2.4.2 and was able to get it to work after&amp;nbsp;I created&amp;nbsp;this workaround in the flash driver:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="diff"&gt;diff --git a/drivers/mpsl/flash_sync/flash_sync_mpsl.c b/drivers/mpsl/flash_sync/flash_sync_mpsl.c
index eea9cadaa..c37ebd78c 100644
--- a/drivers/mpsl/flash_sync/flash_sync_mpsl.c
+++ b/drivers/mpsl/flash_sync/flash_sync_mpsl.c
@@ -140,9 +140,15 @@ void nrf_flash_sync_set_context(uint32_t duration)
 	_context.request_length_us = duration;
 }
 
+bool is_in_fault_isr(void)
+{
+	uint32_t isr = __get_IPSR();
+	return (isr &amp;gt;= 3 &amp;amp;&amp;amp; isr &amp;lt;= 6);
+}
+
 bool nrf_flash_sync_is_required(void)
 {
-	return mpsl_is_initialized();
+	return mpsl_is_initialized() &amp;amp;&amp;amp; !is_in_fault_isr();
 }
 
 int nrf_flash_sync_exe(struct flash_op_desc *op_desc)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Summary of changes made to the peripheral LBS sample to enable and test the Coredump&amp;nbsp;module&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Added the following lines to the prj.conf file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Enable coredump with flash backend
CONFIG_SHELL=y
CONFIG_DEBUG_COREDUMP_SHELL=y
CONFIG_DEBUG_COREDUMP=y
CONFIG_DEBUG_COREDUMP_BACKEND_FLASH_PARTITION=y
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_LINKER_RAM=n
# Must be disabled to allow flash write from exception handler.
# https://github.com/zephyrproject-rtos/zephyr/issues/59116
CONFIG_ASSERT=n&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And&amp;nbsp;the following code in main.c to raise a fault when the button is pressed (Button 1 on DK)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void do_fault(void)
{
	*(uint32_t *) 0xFFFFFFFF = 1;
}

static void button_changed(uint32_t button_state, uint32_t has_changed)
{
	if (has_changed &amp;amp; USER_BUTTON) {
		uint32_t user_button_state = button_state &amp;amp; USER_BUTTON;

		bt_lbs_send_button_state(user_button_state);
		app_button_state = user_button_state ? true : false;
		do_fault();
		
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And lastly, the Devictree overlay to&amp;nbsp;allocate the coredump partition in flash (this is for the nRF52840):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;flash0 {
    partitions {
        storage_partition: partition@f8000 {
            reg = &amp;lt;0x000f8000 0x00004000&amp;gt;;
        };
        coredump_partition: partition@fc000 {
			label = &amp;quot;coredump_partition&amp;quot;;
            reg = &amp;lt;0x000fc000 0x00004000&amp;gt;;
        };

    };
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1.&amp;nbsp;After the fault has been triggered, connect a serial&amp;nbsp;terminal to the board to access the stored coredump via the shell&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1695974419647v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;2. Copy the coredump data to a text file. E.g., coredump.log. Then&amp;nbsp;perform step 1 to 4 here&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/services/debugging/coredump.html#example"&gt;https://docs.zephyrproject.org/latest/services/debugging/coredump.html#example&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;peripheral_lbs_coredump_flash$ arm-zephyr-eabi-gdb build/zephyr/zephyr.elf 
GNU gdb (Zephyr SDK 0.16.0) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &amp;lt;http://gnu.org/licenses/gpl.html&amp;gt;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type &amp;quot;show copying&amp;quot; and &amp;quot;show warranty&amp;quot; for details.
This GDB was configured as &amp;quot;--host=x86_64-build_pc-linux-gnu --target=arm-zephyr-eabi&amp;quot;.
Type &amp;quot;show configuration&amp;quot; for configuration details.
For bug reporting instructions, please see:
&amp;lt;https://github.com/zephyrproject-rtos/sdk-ng/issues&amp;gt;.
Find the GDB manual and other documentation resources online at:
    &amp;lt;http://www.gnu.org/software/gdb/documentation/&amp;gt;.

For help, type &amp;quot;help&amp;quot;.
Type &amp;quot;apropos word&amp;quot; to search for commands related to &amp;quot;word&amp;quot;...
Reading symbols from build/zephyr/zephyr.elf...
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x000113b0 in button_changed (button_state=&amp;lt;optimized out&amp;gt;, has_changed=&amp;lt;optimized out&amp;gt;) at ../src/main.c:177
177     }
(gdb) bt
#0  0x000113b0 in button_changed (button_state=&amp;lt;optimized out&amp;gt;, has_changed=&amp;lt;optimized out&amp;gt;) at ../src/main.c:177
#1  0x00000000 in ?? ()
(gdb) info registers 
r0             0xfffffff3          -13
r1             0x1                 1
r2             0x1                 1
r3             0xfffff000          -4096
r4             0x0                 0
r5             0x0                 0
r6             0x0                 0
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0x0                 0
r11            0x0                 0
r12            0xffffffff          -1
sp             0x2000ab18          0x2000ab18 &amp;lt;sys_work_q_stack+2008&amp;gt;
lr             0x113b1             70577
pc             0x113b0             0x113b0 &amp;lt;button_changed+28&amp;gt;
xpsr           0x1000000           16777216
(gdb) &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Project&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/peripheral_5F00_lbs_5F00_coredump_5F00_flash.zip"&gt;devzone.nordicsemi.com/.../peripheral_5F00_lbs_5F00_coredump_5F00_flash.zip&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/448154?ContentTypeID=1</link><pubDate>Thu, 28 Sep 2023 12:21:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74ca907b-5aaa-4112-81e9-f96389e47c46</guid><dc:creator>KLarocqueEMFluids</dc:creator><description>&lt;p&gt;Do you guys plan on implementing it or for now we have to implement our own code to do that&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/448143?ContentTypeID=1</link><pubDate>Thu, 28 Sep 2023 11:56:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f52298df-7d7e-4356-bfaf-67a8016c2dbd</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Memfault is not intended to replace the debug support in the SDK. Instead, it serves as an additional option for those who want remote device management without setting up and managing their own cloud solution. I&amp;#39;ve updated my internal feature request to highlight the need for a way to save core dumps to flash.&lt;/p&gt;
&lt;p&gt;Documentation for the Core dump module can be found here:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/zephyr/services/debugging/coredump.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/zephyr/services/debugging/coredump.html&lt;/a&gt;. &lt;span style="text-decoration:line-through;"&gt;There is currently no flash backend to save the output to a flash partition.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/447986?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2023 14:19:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a07cb191-b510-420e-b522-60ae70fac2c5</guid><dc:creator>KLarocqueEMFluids</dc:creator><description>&lt;p&gt;Thanks you for that. I will look into it. For some reasons there so little documentation on coredump and the coredump documentation flash partition tool from zephyr seems to not dump anything when I force an hardfault. I hate that Nordic is forcing you with Memfault instead of trying to finding a solution for offline debugging&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/437426?ContentTypeID=1</link><pubDate>Thu, 20 Jul 2023 10:11:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b15cf19a-ec55-459b-a27b-49945de8e52d</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;No problem! This is an internal system only, but I will update you on the progress here if there is any. I&amp;#39;m not sure how soon they will be able to prioritize this task.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/437408?ContentTypeID=1</link><pubDate>Thu, 20 Jul 2023 08:31:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:384ba422-073e-46cd-a99a-aad827e10cb4</guid><dc:creator>motters</dc:creator><description>&lt;p&gt;Thanks. Apologies late on this!&lt;/p&gt;
&lt;p&gt;Would be great to know if this feature does go anywhere. Is there anyway to track it&amp;#39;s progress or rejection? Or is it an internal system only.&lt;/p&gt;
&lt;p&gt;Yes, i might try giving the nrfx drivers a go. It&amp;#39;d be really useful to collect this data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/433635?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2023 09:50:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a13d9074-4ea9-41d7-9d3e-5b74d25ff13e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thank you for taking the time to provide this feedback.&amp;nbsp;I will report&amp;nbsp;it as a feature request internally.&lt;/p&gt;
[quote user="motters"]It would still be good to be able to write directly to flash/QSPI. As this way we could take a full memory dump.[/quote]
&lt;p&gt;I found that we support writing core dumps to the internal flash in the Memfault module, which can be found here: &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/modules/memfault-firmware-sdk/memfault_flash_coredump_storage.c"&gt;https://github.com/nrfconnect/sdk-nrf/blob/main/modules/memfault-firmware-sdk/memfault_flash_coredump_storage.c&lt;/a&gt; . I suppose the same approach could work with QSPI (i.e. use the nrfx driver directly instead of the Zephyr NOR driver).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/433631?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2023 09:25:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:403c761c-7846-42e1-b254-5c795f0a2733</guid><dc:creator>motters</dc:creator><description>&lt;p&gt;I&amp;#39;ve got this working, personally i think is area is lacking in nRF. With everyone shipping thousands of IoT devices with no remote debugging capability seems silly. Surely we shouldn&amp;#39;t all keep re-inventing the wheel. I&amp;#39;ll see if i get time to write a module which can implement everything.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It would still be good to be able to write directly to flash/QSPI. As this way we could take a full memory dump.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;Anyways, few pointers for anyone else interested:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If your using nrf52 there&amp;#39;s a really good example of how to use retained memory here:&amp;nbsp;&lt;a id="" href="https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/boards/nrf/system_off/src/retained.c"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/boards/nrf/system_off/src/retained.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To get the ESF you can override Zephyr&amp;#39;s fatal function and simply store the values in retained memory (as the above example shows).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf_input)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;To save the core dump you&amp;#39;ll have to create a file called &amp;quot;coredump_backend_empty.c&amp;quot; using this as a template&amp;nbsp;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/subsys/debug/coredump_backends/src/coredump_backend_empty.c"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/subsys/debug/coredump_backends/src/coredump_backend_empty.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can then simply &amp;quot;memcpy&amp;quot; the coredump in function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void coredump_empty_backend_buffer_output(uint8_t *c, size_t buflen)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I use the following settings to keep the coredump small enough for RAM retention&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_DEBUG_COREDUMP=y
CONFIG_DEBUG_COREDUMP_BACKEND_OTHER=y
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_LINKER_RAM=n
CONFIG_DEBUG_COREDUMP_SHELL=y
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hope that helps someone.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/432396?ContentTypeID=1</link><pubDate>Wed, 21 Jun 2023 16:49:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9116d0e0-598c-4ab7-af38-f3766dac67c2</guid><dc:creator>motters</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes i suppose thats a good solution. I was looking at Zephyr&amp;#39;s new flash simulator&amp;nbsp;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/flash/flash_simulator.c"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/flash/flash_simulator.c&lt;/a&gt;&amp;nbsp;but its v3.4 which nrf-sdk doesn&amp;#39;t support yet.&lt;/p&gt;
&lt;p&gt;My only concern with this was the sram usage if we were to take a whole dump and not just the pointers.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll have a play with this tomorrow.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving coredumps to external flash</title><link>https://devzone.nordicsemi.com/thread/432299?ContentTypeID=1</link><pubDate>Wed, 21 Jun 2023 11:51:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80c4e017-bfe0-4699-bc00-482dd355be45</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think it&amp;#39;s a&amp;nbsp;good idea to rely on Zephyr drivers&amp;nbsp;such as QSPI&amp;nbsp;NOR when you are in the fault handler, because you don&amp;#39;t know what state the system&amp;nbsp;will be in. Could it be an alternative to load the coredump to a &amp;quot;no init&amp;quot; section and have it written to flash on subsequent reboot?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve used this approach when debugging WDT timeouts in the past (the WDT does not give you enough time to write anything to flash before resetting):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;__noinit static z_arch_esf_t esf;
__noinit static uint32_t esf_crc;
void dump_stack(uint32_t *p_msp)
{
    /* Store stack frame along with a checksum value to the __noinit section in RAM  */
    memcpy(&amp;amp;esf, p_msp, sizeof(esf));
    esf_crc = crc32_ieee((uint8_t *)&amp;amp;esf, sizeof(esf));
    /* Wait for the impending Watchdog reset */
    while (1);
}
#if WDT_ALLOW_CALLBACK
static void wdt_callback(const struct device *wdt_dev, int channel_id)
{
    /* Get current stack frame from the process stack. 
     * 
     * TODO: implement logic to determine if the application
     * was running in thread or handler mode prior to the WDT interrupt.
     * For handler mode we would have to use the main stack pointer instead. 
     */
    __ASM(&amp;quot; mrs r0, psp          \n&amp;quot;
          &amp;quot; ldr r3, = dump_stack \n&amp;quot;
          &amp;quot; bx r3                \n&amp;quot;);
}
#endif /* WDT_ALLOW_CALLBACK */
/* To be called on startup to check if a new exception frame has been stored by our wdt_callback() */
void wdt_startup_check(void)
{
    uint32_t computed_crc = crc32_ieee((uint8_t *)&amp;amp;esf, sizeof(esf));
    if (computed_crc == esf_crc) {
        printk(&amp;quot;Exception stack frame:\n\r&amp;quot;);
        printk(&amp;quot;r0/a1:  0x%08x  r1/a2:  0x%08x  r2/a3:  0x%08x\n\r&amp;quot;, esf.basic.a1,
            esf.basic.a2, esf.basic.a3);
        printk(&amp;quot;r3/a4:  0x%08x r12/ip:  0x%08x r14/lr:  0x%08x\n\r&amp;quot;, esf.basic.a4,
            esf.basic.ip, esf.basic.lr);
        printk(&amp;quot;xpsr:  0x%08x  pc: 0x%08x\n\r&amp;quot;, esf.basic.xpsr, esf.basic.pc);
        esf_crc = 0; // Invalidate CRC
    } else {
        printk(&amp;quot;CRC mismatch\n\r&amp;quot;);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>