<?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>Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84064/call-to-sd_ble_gatts_value_set-does-not-return---s113</link><description>I&amp;#39;m working with firmware and hardware that has previously worked properly. I recently migrated to S113 from S140, and changed the data format of what was being set in the attribute. RAM and Flash are set up properly in the linker, all of the flags are</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Feb 2022 18:59:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84064/call-to-sd_ble_gatts_value_set-does-not-return---s113" /><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/350751?ContentTypeID=1</link><pubDate>Tue, 01 Feb 2022 18:59:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e89cde8-f62b-4daa-b423-d58e1ed0eb6b</guid><dc:creator>underpickled</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;I found the problem. I was calling this from a TWI manager callback with the interrupt priority configured HIGH. I switched it to LOW and it seems to work now, though oddly enough some blocking transactions had to be switched to LOW_MID to work.&lt;/p&gt;
&lt;p&gt;I eventually stumbled across &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/18077/things-allow-not-allowed-to-call-from-callbacks-nrf52-s132"&gt;this issue&lt;/a&gt;, which gave me the clue.&lt;/p&gt;
&lt;p&gt;If you have any parting wisdom related to something like this, I&amp;#39;d be interested to hear it.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;Dylan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/350279?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 18:07:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e9f94e3-273e-46f4-a678-a2caa55a0d99</guid><dc:creator>underpickled</dc:creator><description>&lt;p&gt;Sure, here&amp;#39;s the beginning of the function up to the call, including the payload data (the pointer being fed to the SD call is to a static variable).&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static sensor_payload_t m_payload = {0};

void ble_man_sensor_update(sensor_payload_t *payload)
{
    memcpy(&amp;amp;m_payload, payload, sizeof(sensor_payload_t));
    cap_value_update(&amp;amp;m_cus, m_payload);
}

uint32_t cap_value_update(ble_cus_t *p_cus, sensor_payload_t custom_value) {
    if (p_cus == NULL) {
        return NRF_ERROR_NULL;
    }

    uint32_t err_code = NRF_SUCCESS;
    ble_gatts_value_t gatts_value;

    memset(&amp;amp;gatts_value, 0, sizeof(gatts_value));

    gatts_value.len = sizeof(sensor_payload_t);
    gatts_value.offset = 0;
    gatts_value.p_value = (uint8_t * ) &amp;amp; custom_value;

    NRF_LOG_INFO(&amp;quot;about to set gatts value&amp;quot;)
    err_code = sd_ble_gatts_value_set(p_cus-&amp;gt;conn_handle, p_cus-&amp;gt;cap_value_handles.value_handle, &amp;amp;gatts_value);
    NRF_LOG_INFO(&amp;quot;ble gatts value set return: %u&amp;quot;, err_code)
    if (err_code != NRF_SUCCESS) {
        return err_code;
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The connection handle is assigned on connection (which occurs without any issues, as you can see in the initial post). I added another print right before this to collect the arguments going into the call:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: conn handle: 0, value handle: 19, gatts value addr: 537001568&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is the new sensor payload:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef struct {
    uint32_t timestamp;
    uint32_t cap1;
    uint32_t cap2;
    uint32_t cap3;
    uint32_t cap4;
    uint32_t cap5;
    uint32_t cap6;
    uint32_t cap7;
    uint32_t cap8;
    uint32_t cap9;
    uint32_t cap10;
    uint32_t cap11;
    uint32_t cap12;
    uint32_t cap13;
    uint32_t cap14;
    uint32_t cap15;
    uint32_t cap16;
    int16_t acc_x;
    int16_t acc_y;
    int16_t acc_z;
} sensor_payload_t;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the old one:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef struct {
    uint16_t timestamp;
    uint32_t cap1;
    uint32_t cap2;
    uint32_t cap3;
    uint32_t cap4;
    uint32_t cap5;
    uint32_t cap6;
    uint32_t cap7;
    uint32_t cap8;
    int16_t acc_x;
    int16_t acc_y;
    int16_t acc_z;
    int16_t gyro_x;
    int16_t gyro_y;
    int16_t gyro_z;
    int16_t mag_x;
    int16_t mag_y;
    int16_t mag_z;
} cap_value_t;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In sdk_config.h I have the following settings&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define NRF_SDH_BLE_GAP_DATA_LENGTH 74 // 16 channels @ 4 bytes each, 3 accel axes @ 2 bytes each, 4 byte timestamp = 74
#define NRF_SDH_BLE_GAP_EVENT_LENGTH 32
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 240
#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/350192?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 12:03:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64546ff5-0fd4-4669-bf1f-e8ee1e651d5d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you post some code that shows how you use&amp;nbsp;&lt;span&gt;sd_ble_gatts_value_set() ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What is the value of&amp;nbsp;conn_handle,&amp;nbsp;handle and&amp;nbsp;*p_value?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is&amp;nbsp;*p_value a valid address?&lt;/span&gt;&lt;/p&gt;
[quote user=""]I recently migrated to S113 from S140, and changed the data format of what was being set in the attribute.[/quote]
&lt;p&gt;&lt;span&gt;&amp;nbsp;What changes to the data format did you do?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/350062?ContentTypeID=1</link><pubDate>Thu, 27 Jan 2022 17:24:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf360b81-e504-40f5-84d4-10ac29d73dce</guid><dc:creator>underpickled</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;I get $(SDK_ROOT)/components/softdevice/s113/headers/ble_gatts.h:547 when I run it on the .out file. This points to&lt;/p&gt;
&lt;pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:&amp;#39;JetBrains Mono&amp;#39;,monospace;font-size:9.8pt;"&gt;&lt;span style="color:#908b25;"&gt;SVCALL&lt;/span&gt;(&lt;span style="color:#9876aa;font-style:italic;"&gt;SD_BLE_GATTS_VALUE_SET&lt;/span&gt;&lt;span style="color:#cc7832;"&gt;, &lt;/span&gt;&lt;span style="color:#b9bcd1;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#cc7832;"&gt;, &lt;/span&gt;&lt;span style="color:#ffc66d;"&gt;sd_ble_gatts_value_set&lt;/span&gt;(&lt;span style="color:#b9bcd1;"&gt;uint16_t &lt;/span&gt;conn_handle&lt;span style="color:#cc7832;"&gt;, &lt;/span&gt;&lt;span style="color:#b9bcd1;"&gt;uint16_t &lt;/span&gt;handle&lt;span style="color:#cc7832;"&gt;, &lt;/span&gt;&lt;span style="color:#b9bcd1;"&gt;ble_gatts_value_t &lt;/span&gt;*p_value))&lt;span style="color:#cc7832;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349959?ContentTypeID=1</link><pubDate>Thu, 27 Jan 2022 12:06:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db6714df-e453-48a6-a8fc-ecffedfb8887</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;What did you get when you called this?&lt;/p&gt;
&lt;p&gt;arm-none-eabi-addr2line 0x0002345E -e your_app.elf&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349950?ContentTypeID=1</link><pubDate>Thu, 27 Jan 2022 11:38:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9612d8c0-b341-4052-bfe0-048a485dcd4e</guid><dc:creator>underpickled</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;Thanks, but I have a couple of clarifying questions.&lt;/p&gt;
&lt;p&gt;1. Should I interpret PC as the address the hard fault occurred at? Otherwise there doesn&amp;#39;t seem to be a PC parameter specified&lt;/p&gt;
&lt;p&gt;2. Is it not otherwise clear that the hard fault is occuring within the soft device call? That won&amp;#39;t point me to anything I can use as far as I can tell.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Dylan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349882?ContentTypeID=1</link><pubDate>Thu, 27 Jan 2022 08:40:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81e43ed9-1373-4196-91ac-c042e54753d7</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The value of the&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;code&gt;pc&lt;/code&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;parameter&lt;/span&gt;&lt;span&gt;&amp;nbsp;will contain the address of the instruction that executed the invalid memory access, or the address of the instruction following the violation&lt;/span&gt;&lt;span&gt;. To find out the filename and line number within your application source code that correspond to the&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;code&gt;pc&lt;/code&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;you can use the appropriate tool provided with your toolchain. For example if your linker outputs files in the ELF format you can use the addr2line tool which is part of the GNU ARM Embedded toolchain for this purpose.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Syntax
arm-none-eabi-addr2line &amp;lt;pc&amp;gt; -e application.elf
 
// Example, pc=0x01da6a
$ arm-none-eabi-addr2line 0x01da6a -e app_beacon.elf
C:\dev\app_beacon\src\main.c:34&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349845?ContentTypeID=1</link><pubDate>Wed, 26 Jan 2022 19:36:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cb776ea-336a-4fe8-ac5e-c2f4ea2d0001</guid><dc:creator>underpickled</dc:creator><description>&lt;p&gt;Thanks for that extra info. I had already enabled it in the SDK, but I was missing the preprocessor definition. Here&amp;#39;s what that turns up:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: about to set gatts value
&amp;lt;error&amp;gt; hardfault: HARD FAULT at 0x0002345E
&amp;lt;error&amp;gt; hardfault:   R0:  0x00000000  R1:  0x00000013  R2:  0x2001FE50  R3:  0x00000099
&amp;lt;error&amp;gt; hardfault:   R12: 0x00000000  LR:  0x0002365F  PSR: 0x61000013&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;[Update]: From the .map file, the fault seems to occur from an address shortly after that of sd_ble_gatts_value_set()&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt; .text.sd_ble_gatts_value_set
                0x000000000002345c        0x4 _build/nrf52833/ble_drg_custom_service.c.o
 .text.sd_ble_gatts_hvx
                0x0000000000023460        0x4 _build/nrf52833/ble_drg_custom_service.c.o&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349843?ContentTypeID=1</link><pubDate>Wed, 26 Jan 2022 19:29:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94c1dc15-b6b0-40bc-9726-81848f5e318d</guid><dc:creator>Sigurd</dc:creator><description>[quote user="geode"]It looks like it ends up in a hard fault handler. [/quote]
&lt;p&gt;Make sure that the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_hardfault.html"&gt;hardfault library&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is used.&lt;/p&gt;
&lt;p&gt;Add these to your projects:&lt;/p&gt;
&lt;p&gt;$(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c&lt;br /&gt;$(SDK_ROOT)/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And set HARDFAULT_HANDLER_ENABLED to 1 in sdk_config.h, and add DEBUG_NRF in your preprocessor definitions&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349841?ContentTypeID=1</link><pubDate>Wed, 26 Jan 2022 19:05:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8ccb22d-ea60-40bf-b02c-00923cbee4b9</guid><dc:creator>underpickled</dc:creator><description>&lt;p&gt;It looks like it ends up in a hard fault handler. If I set a breakpoint at the functiona call I can step through a handful of assembly instructions, and then it hits the hard fault. &lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the call stack:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screen-Shot-2022_2D00_01_2D00_26-at-10.57.15-AM.png" /&gt;&lt;/p&gt;
&lt;p&gt;Here are the different chunks of disassembly (a new pic each time it jumps)&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screen-Shot-2022_2D00_01_2D00_26-at-10.57.36-AM.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screen-Shot-2022_2D00_01_2D00_26-at-10.57.53-AM.png" /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screen-Shot-2022_2D00_01_2D00_26-at-10.58.18-AM.png" /&gt;&lt;/p&gt;
&lt;p&gt;It looks like it goes to the fault once I step through that &amp;quot;bx r3&amp;quot; instruction at address 0x1ae86.&lt;/p&gt;
&lt;p&gt;And here&amp;#39;s after it hits the fault:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screen-Shot-2022_2D00_01_2D00_26-at-11.00.55-AM.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349796?ContentTypeID=1</link><pubDate>Wed, 26 Jan 2022 14:28:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd4839c4-a042-4d1e-b65d-569c9fe26ee3</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;How does the callstack look like? and the disassembly? What is the value of the PC(program counter)? Does the PC change when this occurs?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349767?ContentTypeID=1</link><pubDate>Wed, 26 Jan 2022 13:16:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0462c403-2297-4c6c-ba66-8ea11a50a22d</guid><dc:creator>underpickled</dc:creator><description>&lt;p&gt;Hi Sigurd, I&amp;#39;ve already got that in there. That&amp;#39;s how I know it doesn&amp;#39;t return. Sorry, I probably should have specified that more explicitly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call to sd_ble_gatts_value_set() does not return - S113</title><link>https://devzone.nordicsemi.com/thread/349733?ContentTypeID=1</link><pubDate>Wed, 26 Jan 2022 11:53:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1af33e70-baab-4f60-ad58-efcde058ebda</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="103271" url="~/f/nordic-q-a/84064/call-to-sd_ble_gatts_value_set-does-not-return---s113"](the last info print is the line before the function call):[/quote]
&lt;p&gt;Try adding a print line after as well. Snippet:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;err_code = sd_ble_gatts_value_set();
NRF_LOG_INFO(&amp;quot;sd_ble_gatts_value_set() returned %d&amp;quot;,err_code);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and set&amp;nbsp;NRF_LOG_DEFERRED to 0 in sdk_config.h&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>