<?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>Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/121802/zephyr-app-at-custom-location-causing-hard-fault</link><description>HI all, 
 i am using NRF52832. I have a custom bootloader because it needs to be able to receive an update file via BLE, even if the main application is broken. Also there is no space for two slots for he main app. 
 So there is just the custom bootloader</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 May 2025 13:12:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/121802/zephyr-app-at-custom-location-causing-hard-fault" /><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537197?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 13:12:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fcc0c2e-43c3-48f4-90d3-3e762bb5befb</guid><dc:creator>Mark G.</dc:creator><description>&lt;p&gt;Ok the issue is resolved. Cross tested it on multiple boards with different people. works on all of them except for this single board. That has been in use some years ago already. Maybe it has some strange configuration / issues. &lt;br /&gt;&lt;br /&gt;We can close this thread :) Thanks all!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537187?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 12:56:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a52b59d8-2629-4616-9f74-3a760f2343ec</guid><dc:creator>Mark G.</dc:creator><description>&lt;p&gt;showed the result as expected: 00000200.&lt;br /&gt;&lt;br /&gt;Another interesting discovery. I have two PCA 10040. One with Version 3.0.0, the other with Version 3.0.4.&lt;/p&gt;
&lt;p&gt;On Version 3.0.4 everything works as expected! The problems only occur on the other board. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537136?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 11:02:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f142d8c0-2408-4b14-88a9-5be73d4f018c</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hmm, then there is a lot that I cannot guess about your setup.&lt;/p&gt;
&lt;p&gt;Please check the RAM size &lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52832/page/ficr.html#d917e10070"&gt;(FICR.INFO:FLASH)&lt;/a&gt; in the hardware&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrfjprog --memrd 0x10000110 --w 4&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and see what result you get. If you get 00000200 then you have 512KB and after that I do not know what could be wrong. After that I strongly recommend you to follow this up in Zephyr forum as you are not using our tested release tags.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537127?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 10:44:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd3953b9-ad93-46f3-8d2b-03e823ebbbc9</guid><dc:creator>Mark G.</dc:creator><description>&lt;p&gt;The variable CONFIG_PARTITION_MANAGER_ENABLED does not even exist as valid configuration.&lt;/p&gt;
&lt;p&gt;Maybe one important part of information is that I currently use &amp;quot;raw Zephyr&amp;quot;, no nrf sdk.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537122?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 10:27:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:523de9f7-3a44-46cc-a0c2-22b191df92c4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Mark,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for that test and results. That helps. So it is not related to Bluetooth and the stack sizes then.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Can you please check your &amp;quot;.config&amp;quot; file in your build folder and see if &amp;quot;&lt;em&gt;CONFIG_PARTITION_MANAGER_ENABLED&lt;/em&gt;&amp;quot; is enabled? If enabled, then you need to then your pm.yml file in your bootloader to reflect the sizes of your partition correctly (and your devicetree settings in this case does not matter as partition manager takes control).&lt;/p&gt;
&lt;p&gt;Also make sure that the names for the partitions is the same as your bootloader expects something like below in your pm.hyml file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# pm.yml
partitions:
  flash0:
    # FIXME: fix names of partitions as my bootloaders expect
    bootloader:
      address: 0x00000000
      size:    0x00030000
    app:
      address: 0x00030000
      size:    0x00050000
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537083?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 08:24:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2307d2b2-2e08-4c8e-a0fd-29699fd4dfda</guid><dc:creator>Mark G.</dc:creator><description>&lt;p&gt;Thanks for the quick reply!&lt;br /&gt;&lt;br /&gt;I am testing with a minimal &amp;quot;blinky&amp;quot;-like main.cpp that is the only source for this build. I set the partition and the start of the partition. And then I tested by varying the offset adresses in the Flash and by enabling different features in the config.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;I look at the output size of the binary:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[100%] Linking CXX executable trigger.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      163508 B       320 KB     49.90%
             RAM:       23428 B        64 KB     35.75%
        IDT_LIST:          0 GB        32 KB      0.00%&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and then add the &amp;quot;flash offset&amp;quot; to it. By testing different combinations of start address and size I figured that somehow a total size of 256kb is the magic boundary between working and not working.&lt;/p&gt;
&lt;p&gt;I even did further testing with complete deactivating of the Blueetooth. By controlling the occupied Flash memory of the app with some constant array I could reproduce the issue.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// occupy 141kb of Flash memory, together with the offest &amp;gt; 256kb
constexpr uint8_t magicData[1024 * 141] = {1, 2};// does lead to error

// results in slightly less than 256kb flash memory
// constexpr uint8_t magicData[1024 * 140] = {1, 2}; // no error!

volatile uint8_t sum = 0;

int main(void)
{
    for (size_t i = 0; i &amp;lt; sizeof(magicData); ++i) {
        sum += magicData[i];
    }
    
    ....&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As soon as more than 256 KB are occupied it fails.&lt;/p&gt;
&lt;p&gt;So its pretty clear that its not related to BT, but somehow the partition / memory management. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537072?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 07:54:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2dc5a817-bec7-41b0-aeeb-f449b26067a8</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;OK, then we look somewhere else.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="Mark G."]Ok Interestingly the hard fault seems to occur once the offset (0x00030000) + size is bigger than &amp;gt; 256kb. Which is very telling.[/quote]
&lt;p&gt;Can you please tell me how you came to this conclusion? What debug info did you get or see and what tests you attempted to come to this conclusion?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am suspecting that if you came to this conclusion with a debugger, then the debug info might be misleading if there is a stack corruption.&lt;/p&gt;
[quote user=""]However, once I enable BT in my Config with CONFIG_BT=y and CONFIG_BT_PERIPHERAL=y then the app crashes in a very early startup phase in Zephyr, causing a hard fault.[/quote]
&lt;p&gt;I think this smells like a stack corruption. If you enable some features and have been having some minimal stack sizes, then I would recommend you to increase the stack sizes like&amp;nbsp;CONFIG_MAIN_STACK_SIZE,&amp;nbsp;CONFIG_BT_RX_STACK_SIZE,&amp;nbsp;CONFIG_BT_HCI_TX_STACK_SIZE etc in your prj.conf (double their sizes for testing) and see if you still have this issue. If you still do have this issue, then we focus away from insufficient RAM and stack and then look again into your partition manager settings.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537052?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 06:53:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65444110-433a-4237-bbe7-0b03ef170ce7</guid><dc:creator>Mark G.</dc:creator><description>&lt;p&gt;Looks like n52832QFAAG02208AJ, which should have 512kb&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/photo_5F00_2025_2D00_05_2D00_27_5F00_08_2D00_51_2D00_14.jpg" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537044?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 06:39:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7c6d65d-82d0-499c-8003-37e6cfb8d06a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Please check the laser markings on the chip you have on your board to know which variant of memory you have in side the SoC.&lt;br /&gt;The details of chip reversion and its memory sizes are given &lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52832/page/memory.html"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr app at custom location causing hard fault</title><link>https://devzone.nordicsemi.com/thread/537033?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 05:34:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27820dbd-381e-430b-89de-6c8a4348bd47</guid><dc:creator>Mark G.</dc:creator><description>&lt;p&gt;Ok Interestingly the hard fault seems to occur once the offset (0x00030000) + size is bigger than &amp;gt; 256kb. Which is very telling. I am currently testing with PCA10040, which uses NRF52832 and should have 512kb of flash memory? I compile with this board config: nrf52dk/nrf52832 and the overlay shown above.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>