<?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>Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12537/hard-fault-sd132-with-timers-and-ble-rwauth</link><description>Hi, 
 i&amp;#39;m testing an application on nRF52, with nRF5_SDK_11.0.0-2.alpha and SoftDevice 132. 
 I took the ble_uart example and added a custom service with some characteristics with various permissions. Everything seems to work well, i then decided to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Mar 2016 10:13:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12537/hard-fault-sd132-with-timers-and-ble-rwauth" /><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47571?ContentTypeID=1</link><pubDate>Mon, 21 Mar 2016 10:13:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04d92101-4673-4e56-927d-0786e4b9055e</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;Hi, i submitted a new case with the project.
Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47570?ContentTypeID=1</link><pubDate>Fri, 18 Mar 2016 09:40:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b8860f4-fc0c-4396-8458-655772f83d06</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Are you able to share your project so I can try to debug here at my end? You can create a support ticket on &lt;a href="http://www.nordicsemi.com/eng/Support-Community"&gt;mypage&lt;/a&gt; in case you don&amp;#39;t want to post it here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47569?ContentTypeID=1</link><pubDate>Fri, 18 Mar 2016 08:46:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbd96362-4848-45df-96dc-6237e4683df3</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;Hi, thanks for the reply, as you pointed out the timer instance is not the problem and it looks stack related.&lt;/p&gt;
&lt;p&gt;It seems that when sd_ble_gatts_rw_authorize_reply() gets called, for some reason the program jumps to a specific address and, depending on what code is compiled there, i get HardFault.
Just modify one char in a string makes the program to jump on another place.&lt;/p&gt;
&lt;p&gt;Besides that, there are cases where added code doesn&amp;#39;t brake program, and this is why i didn&amp;#39;t noticed any fault untill i added timer instance.&lt;/p&gt;
&lt;p&gt;For what i was able to test, It looks like the other BLE operations don&amp;#39;t affect the code execution (no corruption).
Another thing that i noted is that if i debug and do step in on rw_authorize_reply(), i don&amp;#39;t get hardfault apparently. If i do run or stepover, crash.
Maybe it is something related to concurrent use of the stack area between my application and the sd.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47567?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 19:32:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27f05e31-eb4d-4917-90c2-e0889400571e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Posted my reply as an answer since the comments have a limit on number of characters.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47568?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 19:30:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb55fb64-3f18-4ae9-b7dd-51792d5392a3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Sorry for not responding sooner. I does sound like the stack frame may have gotten corrupted somehow, but don&amp;#39;t see why this would happen only after you added the timer instance. It could however explain why the same code works when built in Keil. Difference between these two is that Keil places the call stack just above the globals whereas GCC places it in top of RAM. In other words, it is possible that the same thing is happening in your Keil project, but it doesn&amp;#39;t corrupt the stack since it&amp;#39;s placed lower in RAM.&lt;/p&gt;
&lt;p&gt;I would suggest to try to move the stack upwards in RAM to see if this potential corruption is happening at a particular address in your current stack area. You can do that by increasing the RAM size in the linker script so that the total including softdevice is 64KB instead of 32K. Note that this will not work on the engineering A part (PCA10036) as the second RAM block was mapped to a different address range.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47566?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2016 11:11:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70ccbb98-0c01-4811-93f8-ed4bb63f17b9</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;This is the requested
&lt;a href="http://s12.postimg.org/ed19m5unx/screen1.png"&gt;screenshot&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see, when i perform an authorized read, the printf &amp;quot;ENTER SD_BLE_GATTS&amp;quot;, then rw_auth_reply() gets executed but it looks like the return address is corrupted infact the code jumps to strncpy and then the Hardfault.
What i have seen is that, if i change some lines of code (example i substitute &amp;quot;LOCKED&amp;quot; with &amp;quot;LOCKED1234&amp;quot; in strncpy), the program jumps to other places.
It looks like a buffer overflow of some kind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47565?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2016 09:22:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10bd2998-2ed1-4d68-baa4-38240eea3bfa</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Could you add a screen dump of the disassemble view at 0x21744 together with the core registers when the exception has occurred?&lt;/p&gt;
&lt;p&gt;To be able to set breakpoints in the startup file you need to do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;change the file extension from .s to
capital .S in
/components/toolchain/gcc&lt;/li&gt;
&lt;li&gt;Add the -g3 option to the assembler
flags.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, have experienced problems with debugging after updating to the 5.0 release of arm-none-eabi. I&amp;#39;d suggest to downgrade to 4.9 if you are using this one.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47564?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 13:37:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e0d1f33-01cc-44e3-a7e5-e21cb3d23967</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;In gcc makefile i can see that ASM_SOURCE_FILE included is gcc_startup_nrf52.s not arm_startup_nrf52.s. Is it correct?
I did open gcc_startup_nrf52.s anyway in Eclipse and set a breakpoint at line after HardFault_Handler: line (394) but it doesn&amp;#39;t hit.
But if i pause i can see the last call in the stack is&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;HardFault_Handler() at 0x2431a	
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The R0 here is 0x21744, which is the line inside on_rwauth() function just before rw_auth_reply()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47563?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 13:19:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a92a0a6-208c-4cc7-acfb-9855ea877149</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;Yeah that&amp;#39;s not a problem, it just means you&amp;#39;re wasting some RAM between the SD and the app areas.&lt;/p&gt;
&lt;p&gt;I assume you have a breakpoint in HardFault_Handler in arm_startup_nrf2.s. Can you check the value of the R0 register when that breakpoint hits?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47562?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 13:16:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1cd7e8ee-66f4-4d91-b1ae-7b1f253193b9</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;Yes i&amp;#39;m sure and app_error_fault_handler is not hit. Here is something more, this behaviour is seen in Eclipse GCC. I tried to compile with Keils 5 and i don&amp;#39;t see HardFault anymore.
One thing i noted in GCC is that sd debug info says:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;RAM START ADDR 0x20001F00 should be adjusted to 0x20001E00
RAM SIZE should be adjusted to 0xE200 
sd_ble_enable: RAM START at 0x20001F00
sd_ble_enable: app_ram_base should be adjusted to 0x20001E10
ram size should be adjusted to 0xE1F0 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I read that this shouldn&amp;#39;t bother anyway.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47561?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 11:42:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45b71d73-7900-441c-954a-389eb73a5d9a</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;Not sure to be honest, but have you made sure you don&amp;#39;t enter the block at all? Also can you verify if you are hitting the app_error_fault_handler() function, which will be called if APP_ERROR_CHECK() fails?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47560?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 11:34:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:236565a5-01d3-4a2f-a8db-b3e876dff377</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;Here is something strange: in my on_rwauth() i manage the read of another characteristic (i didnt show on snippet), which i don&amp;#39;t use. BUT if i comment this section i don&amp;#39;t get hard fault apparently. I tried to investigate the block and seems that leaving APP_ERROR_CHECK(err_code) after its rw_authorize_reply(), triggers the hard fault when i read the used characteristic.
I never enter the block, so uncommenting the code inside shouldn&amp;#39;t change anything. Might be some king of overlap in the memory?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47559?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 11:20:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a18cbbe0-b20e-4551-b241-803c3b1299a8</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;Also R0 should contain the PC that triggered the hard fault. If you have a breakpoint in your hard fault handler then take a  look at R0 to find out which instruction triggered it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47558?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 11:07:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e64652a-5c94-4829-867d-54175f816a27</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;So if you comment the call to rw_authorize_reply() then it still hard faults?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47557?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 11:05:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:caac4913-0e95-4935-912f-eb4be4285151</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;Thank you Carles, i corrected the gattc error but problem is still there. I have tried to comment but bad luck for now. I can&amp;#39;t spot anything. Is there something i can do with HardFault_handler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47556?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 10:32:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68af56d0-c93e-4174-8835-459be74ec788</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;Actually, I did spot something:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sd_ble_gatts_rw_authorize_reply(p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;should be&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sd_ble_gatts_rw_authorize_reply(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47555?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 10:31:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e1e1a0e-e02c-466c-833c-4cc20fbb6969</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;Thanks for the snippet, I see nothing obviously wrong in there. Have you tried commenting out the call to rw_authorize_reply() (leaving the timers on) to see if that still hardfaults?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47554?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 10:13:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7f3c260-a1ef-4b5d-8753-03839f9964cd</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;I added a snippet in the question, the behaviour is: if system not initialized (system locked)  print HELLO, else print state of LED.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47553?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 09:47:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1c5bcd7-4175-414a-bca1-36635b6f937e</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;Can you perhaps provide a snippet of the code you use to call rw_authorize_reply() ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47552?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 09:46:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24fa3995-4ebc-4eae-89bc-dc4256aa9173</guid><dc:creator>blungreen</dc:creator><description>&lt;p&gt;Hi, thank you for the reply. The pointers look good to me, what i do in the reply is just strncpy &amp;quot;HELLO&amp;quot; into a buffer, set the buffer and its strlen to the param, and set the update flag to 1.
SD seems to crash on authorized read, when program enters rw_authorize_reply().
It is very weird cause I get hard fault only if i place functions in the main loop&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault SD132 with timers and ble rwauth</title><link>https://devzone.nordicsemi.com/thread/47551?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2016 14:18:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfff2c28-acd8-4126-b55d-f3fd5e455893</guid><dc:creator>Carles</dc:creator><description>&lt;p&gt;This sounds like the data you are providing to rw_authorize_reply() is not valid. Can you check the pointer you are providing? Have you taken a look at the SD migration document, and more specifically the section where it describes how to handle authorized operations since there have been substantial changes since s130 v1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>