<?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>Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115606/using-scanning-causes-program-crashes</link><description>The above is my code. 
 
 This is running log. 
 
 After scanning multiple times, my application may freeze, as shown in the log, and there will be no response after receiving the event.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 29 Oct 2024 06:03:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115606/using-scanning-causes-program-crashes" /><item><title>RE: Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/thread/508273?ContentTypeID=1</link><pubDate>Tue, 29 Oct 2024 06:03:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:424f07e0-b00d-49b1-ac81-5628e13a6d48</guid><dc:creator>MapleBay</dc:creator><description>&lt;p&gt;Thanks, I found the ble function in example.&amp;nbsp;The reason why it was not found last time is that the example may have been changed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/thread/508262?ContentTypeID=1</link><pubDate>Tue, 29 Oct 2024 02:11:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24bf24f3-addb-478f-b890-4f0b45661e55</guid><dc:creator>MapleBay</dc:creator><description>&lt;p&gt;I once tried to use the C language of pc-ble-driver to write a host computer program to drive it, but I found it was not convenient to use. Later, I urgently migrated it to SDK17 and implemented most of the functions. Currently, there is a problem only when searching. If possible, can you help me solve it?&lt;br /&gt;&lt;br /&gt;This is my project path :&amp;quot;examples\connectivity\ble_connectivity_raw\pca10059\ser_s140_usb_hci\arm5_no_packs\ble_connectivity_s140_usb_hci_pca10059.uvprojx&amp;quot;&lt;br /&gt;&lt;!--mce:protected %3C%21--StartFragment%20--%3E--&gt;&amp;nbsp;&lt;!--mce:protected %3C%21--StartFragment%20--%3E--&gt; &lt;a href="https://1drv.ms/u/s!AnwTT7jbuil-inXZLO22OtrNs11Q?e=PbQhGk"&gt;Nordic_SDK_17.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/thread/508141?ContentTypeID=1</link><pubDate>Mon, 28 Oct 2024 12:26:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a903261c-75e5-491c-8a39-465eda593128</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Genfeng,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you look at the function&amp;nbsp;cdc_acm_user_ev_handler() in main.c you can find that whenever there is enough data on RX or when there is an end of line byte it will call&amp;nbsp;ble_nus_data_send() to send data.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;The pc_ble_driver is the code to run on python on PC, so it&amp;#39;s different from the code on nRF52. I am not sure why you develop the logic based on pc_ble_driver.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/thread/508048?ContentTypeID=1</link><pubDate>Mon, 28 Oct 2024 05:48:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a3e3690-d704-477f-9bb2-f68a58012275</guid><dc:creator>MapleBay</dc:creator><description>&lt;p&gt;OK，I think i need to read usbd_uart_ble to getting start, my project developed logic is based on &lt;a href="https://github.com/NordicSemiconductor/pc-ble-driver"&gt;pc_ble_driver&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;And do you have something about usbd_uart_ble develop document. I read &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.0.2/page/usbd_ble_uart_example.html"&gt;this document&lt;/a&gt;, but i can&amp;#39;t get it how to use uart to called ble function, in the main.c, i can&amp;#39;t it find it&amp;nbsp;call the ble.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/thread/507266?ContentTypeID=1</link><pubDate>Tue, 22 Oct 2024 08:04:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:191501c8-7b4d-4c6e-8c28-8174a9da7fe6</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Genfeng,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please provide your full code, how do you start scanning ? Do you use the nrf_ble_scan module ?&amp;nbsp;&lt;br /&gt;The nrf_ble_scan already take care of restart scanning when you receiving ADV_REPORT.&lt;br /&gt;Please don&amp;#39;t use&amp;nbsp;usb_printf_variadic when you have an error with&amp;nbsp;sd_ble_gap_scan_start()&lt;br /&gt;How do you print the log ?&amp;nbsp;&lt;br /&gt;When do you print SD:Scan_Stop ?&lt;br /&gt;&lt;br /&gt;Have you tried to test with our example in ble_central folder ? Do you see the same issue ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/thread/507183?ContentTypeID=1</link><pubDate>Mon, 21 Oct 2024 14:46:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce10989a-7cd8-4872-8a15-5158c0853cb9</guid><dc:creator>MapleBay</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void on_adv_report(const ble_gap_evt_t *const p_ble_gap_evt)
{
  uint32_t err_code = 0;
  uint8_t str[STRING_BUFFER_SIZE] = {0};

  // Log the Bluetooth device address of advertisement packet received.
  // ble_address_to_string_convert(p_ble_gap_evt-&amp;gt;params.adv_report.peer_addr, str);
  // const uint8_t *address = p_ble_gap_evt-&amp;gt;params.adv_report.peer_addr.addr;
  // char _temp_str[250];
  // memset(_temp_str, 0, 250);
  // sprintf(_temp_str, &amp;quot;Advertising Report: Device Address: %02x%02x%02x%02x%02x%02x, &amp;quot;, address[5], address[4], address[3], address[2], address[1], address[0]);
  // sprintf(_temp_str + strlen(_temp_str), &amp;quot;Addr Type: 0x%d, &amp;quot;, p_ble_gap_evt-&amp;gt;params.adv_report.peer_addr.addr_type);
  // sprintf(_temp_str + strlen(_temp_str), &amp;quot;Addr ID Peer: 0x%d, &amp;quot;, p_ble_gap_evt-&amp;gt;params.adv_report.peer_addr.addr_id_peer);
  // sprintf(_temp_str + strlen(_temp_str), &amp;quot;Device Rssi: %d\n&amp;quot;, p_ble_gap_evt-&amp;gt;params.adv_report.rssi);
  // usb_printf_variadic(&amp;quot;%s\r\n&amp;quot;, _temp_str);
  // usb_printf_variadic(&amp;quot;Advertising Data: %s&amp;quot;, p_ble_gap_evt-&amp;gt;params.adv_report.data.p_data);
  // memset(mp_data, 0, 255);
  // m_adv_report_buffer.len = BLE_GAP_SCAN_BUFFER_EXTENDED_MIN * sizeof(mp_data);
  // err_code = sd_ble_gap_scan_stop();
  // nrf_delay_us(100000);

  err_code = sd_ble_gap_scan_start(NULL, &amp;amp;m_adv_report_buffer);
  if (err_code != NRF_SUCCESS)
  {
    usb_printf_variadic(&amp;quot;Error starting scan. Error code 0x%02X\r\n&amp;quot;, err_code);
  }
  else
  {
    // //printf(&amp;quot;Scan started\n&amp;quot;);
    // usb_printf_variadic(&amp;quot;GAP Scan Start\n&amp;quot;);
  }
}
&lt;/pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ok, here is my new code, I disabled usb_printf_variadic() as you said, but the problem still exists.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
[22:43:04.034]收←◆&amp;lt;info&amp;gt; app: uart Rx_data:&amp;gt;SD:Scan_Start

[22:43:04.092]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.155]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.186]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.262]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.299]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.388]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.462]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.492]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.555]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.595]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:04.657]收←◆&amp;lt;info&amp;gt; app: Received BLE event: 29
&amp;lt;info&amp;gt; app: Received BLE event: 29

[22:43:06.864]收←◆&amp;lt;info&amp;gt; app: uart Rx_data:&amp;gt;SD:Scan_Stop
&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using scanning causes program crashes</title><link>https://devzone.nordicsemi.com/thread/507057?ContentTypeID=1</link><pubDate>Mon, 21 Oct 2024 07:46:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:448f35b3-0e7f-4499-a84b-1f043e06d442</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Genfeng,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How often do you see the issue ?&lt;br /&gt;I suspect that there could be a problem of the functions you call in the&amp;nbsp;on_adv_report(). The context level of the event handler is at Softdevice low (level 4)&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/pastedimage1729496681439v1.png" alt=" " /&gt;&lt;br /&gt;There could be a chance that calling&amp;nbsp;usb_printf_variadic() inside that context causing a problem. Please try to comment out&amp;nbsp;usb_printf_variadic() and test printing out log on UART or RTT (or use GPIO) to see if you still see the problem.&lt;br /&gt;If&amp;nbsp;usb_printf_variadic() actually a problem, you can consider using a semaphore or use software interrupt to reduce the context to main for example, before calling the funtion.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>