<?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>nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/97107/nrf52811-ble-hangs-or-crashes-after-central-disconnects-with-uart-enabled</link><description>We have an nRF9160 connected to an nRF52811 via a UART to pass data to the BLE processor that can then relay the info to a connected central device (iPhone). While the UART is enabled, either passing data over or not, when the central device disconnects</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Jul 2023 07:42:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/97107/nrf52811-ble-hangs-or-crashes-after-central-disconnects-with-uart-enabled" /><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/434362?ContentTypeID=1</link><pubDate>Tue, 04 Jul 2023 07:42:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5765ded-f71e-4743-a0b9-d8a3397a1d17</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Harold&lt;/p&gt;
&lt;p&gt;Good to hear you discovered the issue. Thanks for sharing your findings &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I must admit I wasn&amp;#39;t aware that the disconnected callback would be&amp;nbsp;triggered separately for every handle in your attribute table.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/434129?ContentTypeID=1</link><pubDate>Mon, 03 Jul 2023 09:11:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a9e9232-6c93-4c3d-86e7-dd6cd0b0843a</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It&amp;#39;s been a while since I was on. &amp;nbsp;Been doing a lot of different things and thought I would go through my various tickets and see if I have any answers for them.&lt;/p&gt;
&lt;p&gt;On this one, I have figured it out. &amp;nbsp;The issue with the 52811 crashing when a BT connected peripheral disconnects is due to insufficient stack size on the work queue. &amp;nbsp;It was originally set to only 256 bytes and it appears to be used to unwind the BT services and characteristics. &amp;nbsp;The hang/crashes never gave me stack overflow and maybe that is because there was so much data that it whacked everything out of shape. &amp;nbsp;But I would see only up to 4 of the cb&amp;#39;s getting handled when there were at least 28 and probably more and other things to be dealt with on the disconnect. &amp;nbsp;After that, the disconnected callback would be called and I would be able to do things:&lt;/p&gt;
&lt;p&gt;00&amp;gt; [01:58:42.914,550] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24d68, handle: 1, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.915,740] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24d7c, handle: 2, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.916,870] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24d90, handle: 3, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.918,060] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24da4, handle: 4, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.919,189] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24db8, handle: 5, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.920,379] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24dcc, handle: 6, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.921,508] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24978, handle: 7, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.922,698] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x2498c, handle: 8, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.923,828] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x249a0, handle: 9, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.925,018] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x249b4, handle: 10, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.926,147] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x249c8, handle: 11, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.927,337] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x249dc, handle: 12, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.928,527] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x249f0, handle: 13, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.929,656] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a04, handle: 14, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.930,847] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a18, handle: 15, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.932,006] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a2c, handle: 16, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.933,166] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a40, handle: 17, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.934,326] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a54, handle: 18, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.935,516] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a68, handle: 19, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.936,645] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a7c, handle: 20, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.937,835] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24a90, handle: 21, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.939,025] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24aa4, handle: 22, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.940,155] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24ab8, handle: 23, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.941,345] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24acc, handle: 24, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.942,504] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24ae0, handle: 25, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.943,695] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24af4, handle: 26, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.944,824] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24b08, handle: 27, and ud: 0x200017e0&lt;br /&gt;00&amp;gt; [01:58:42.946,014] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x24b1c, handle: 28, and ud: 0x200017e0&lt;/p&gt;
&lt;p&gt;I had to increase the work queue to 1024 to get it to stop crashing. &amp;nbsp;And running the thread analyzer showed that I was using upwards of 80% of the space when it wasn&amp;#39;t crashing at 1k. &amp;nbsp;But that&amp;#39;s the most it will to, so that&amp;#39;s probably ok. &amp;nbsp;It&amp;#39;s such a little device... &amp;nbsp;And that sent the SRAM from 91% to 97% utilized as I had to adjust a couple other stacks that were getting close to 100%.&lt;/p&gt;
&lt;p&gt;Anyway, thanks for your help.&lt;/p&gt;
&lt;p&gt;You can close this ticket.&lt;/p&gt;
&lt;p&gt;h.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/414298?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 08:39:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6dd63ea6-35ae-464b-b810-be1c646dbc49</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Harold&lt;/p&gt;
&lt;p&gt;Fair point, the thread will eat up a bit of RAM as well. You can adjust the stack size through&amp;nbsp;one of the config parameters, if you are careful about stack use in the callback function.&amp;nbsp;&lt;/p&gt;
[quote user="keegretupmoc"]&lt;span&gt;We did disable the assert (config_assert=n) in&amp;nbsp;&lt;/span&gt;prj.conf which looks like recovered about 23k of flash space. &amp;nbsp;That is just for debugging, correct? &amp;nbsp;You don&amp;#39;t want that on for production? [/quote]
&lt;p&gt;You are correct. The idea is to use this during development to detect and identify runtime errors etc, and then disable it in production to improve performance and reduce the memory footprint. The &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.3.0/kconfig/index.html#!CONFIG_ASSERT"&gt;documentation for the config&lt;/a&gt; has a bit more context.&amp;nbsp;&lt;/p&gt;
[quote user="keegretupmoc"]I am not completely abandoning the new UART code, just putting it on hold for now until we get FOTA working on the 52811. &amp;nbsp;We really have to get that working. &amp;nbsp;It is a top priority.[/quote]
&lt;p&gt;Sounds like a good decision, having a stable FOTA solution is pretty critical&amp;nbsp; &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/414238?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 19:45:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be46a7ee-045f-4cc5-b8aa-5ef6d9f7d546</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I was more concerned about the additional thread.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;We did disable the assert (config_assert=n) in&amp;nbsp;&lt;/span&gt;prj.conf which looks like recovered about 23k of flash space. &amp;nbsp;That is just for debugging, correct? &amp;nbsp;You don&amp;#39;t want that on for production? &amp;nbsp;I checked on the 9160 side and it isn&amp;#39;t enabled or even listed in the prj.conf. &amp;nbsp;I didn&amp;#39;t really see any articles on it...&lt;/p&gt;
&lt;p&gt;I am not completely abandoning the new UART code, just putting it on hold for now until we get FOTA working on the 52811. &amp;nbsp;We really have to get that working. &amp;nbsp;It is a top priority. &amp;nbsp;So once we get that going, we will see about implementing the code. &amp;nbsp;Since you mentioned that it should be in the 2.2.0 version of the sdk, that will work well for us. &amp;nbsp;We are planning at some point to upgrade to sdk 2.2.0 (currently on 2.0.0).&lt;/p&gt;
&lt;p&gt;At some point in the future if we redesign our device, we will select a BLE chip with more flash/ram...&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;h.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/414039?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 09:04:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fd957f9-0e76-4ab8-bbf6-49bbb6860f6f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Harold&lt;/p&gt;
&lt;p&gt;Keep in mind that the app_uart driver doesn&amp;#39;t use dynamic memory allocation, which means if you don&amp;#39;t need this anywhere else you can reduce the size of the heap, or remove it altogether. This should give you some extra RAM.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can also configure the size of the static buffers through the configuration parameters, to reduce RAM consumption of the driver itself.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The best of luck with the memory optimization task!&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/414004?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 07:03:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8eee506a-0453-4f00-b3af-8560af949bb2</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;ve been looking at your UART code. &amp;nbsp;I am&amp;nbsp;probably going to wait a while before trying it. &amp;nbsp;I don&amp;#39;t think I have enough memory at the moment. &amp;nbsp;I need to open another ticket to try to reduce the size. &amp;nbsp;Here&amp;#39;s where we are currently. &amp;nbsp;This is again on the 52811 BLE processor:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Memory region Used Size Region Size %age Used&lt;br /&gt; FLASH: &amp;nbsp; &amp;nbsp; &amp;nbsp;173112 B &amp;nbsp; 192 KB &amp;nbsp; &amp;nbsp;88.05%&lt;br /&gt; SRAM: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24014 B &amp;nbsp; &amp;nbsp; 24 KB &amp;nbsp; &amp;nbsp;97.71%&lt;br /&gt; IDT_LIST: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 GB 2 KB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.00%&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;h.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/413990?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 02:05:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cec07568-7697-41f1-b1d3-05e86c7b3457</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I will look at the new UART code and see if it helps. &amp;nbsp;If it reduces the footprint and complexity, every little bit helps.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;On the setting the logging to immediate, it didn&amp;#39;t reduce the crashing, it stopped the hanging. &amp;nbsp;if you remember,&amp;nbsp;&lt;/span&gt;originally the iOS device disconnecting from bluetooth would result in either a crash, or the BLE would hang. &amp;nbsp;With the immediate display flag set to y, the hanging stopped happening. &amp;nbsp;So each time we disconnected from the BLE, it crashed. &amp;nbsp;So nothing was reduced, just the behavior changed. &amp;nbsp;And it was more clear that it was in the sysworkq, as I was seeing that every time.&lt;/p&gt;
&lt;p&gt;Let me know if you want anymore data on the crashing with immediate enabled, or if there is something else to check when that is running.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;h.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/413890?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2023 14:36:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d560f9c8-bef2-4800-aad8-2794c134251b</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Harold&lt;/p&gt;
&lt;p&gt;Thanks for sharing the TX code, it makes sense that this would fail if you tried to free a static buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You don&amp;#39;t have a similar code snippet for the disconnected case?&lt;/p&gt;
[quote user="keegretupmoc"]The other issue I am starting to work on is to try to reduce the footprint of the 52811 to get mcuboot in there. &amp;nbsp;Again, probably another ticket?[/quote]
&lt;p&gt;Yes, this is not really related to this issue and should definitely be a separate ticket. The devzone is not really designed to handle multiple different issues in the same ticket.&amp;nbsp;&lt;/p&gt;
[quote user="keegretupmoc"]So not sure how this changes the behavior. &amp;nbsp;When I set it back to n, and start doing disconnects, I see it hang again and the WDT is resetting it. &amp;nbsp;So something changes with that being enabled. &amp;nbsp;Hopefully that gives us a hint or something.[/quote]
&lt;p&gt;It&amp;#39;s odd that enabling immediate logging would lead to less crashes, usually it is the other way around since immediate logging will try to write the log output right away, even when you are inside an interrupt. Normal logging will buffer the log message in RAM and have it printed at a later time, outside interrupt context.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The fact that the current thread is the sysworkq is a bit interesting, this implies that the crash happens inside a work item scheduled from the application. Do you have any log output to go with this crash?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Another request I have is if you could set aside an hour or so to test my UART wrapper and see if it solves your issues.&lt;/p&gt;
&lt;p&gt;Normally I wouldn&amp;#39;t insist you test this driver before I have had time to integrate it in the official SDK, but if it does work it should save you&amp;nbsp;significant time going forward.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The driver and accompanying samples are available &lt;a href="https://github.com/too1/ncs-uart-handler"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Included in the repo you will also find a&amp;nbsp;port of the peripheral_uart sample, replacing the original UART async code with the app_uart driver. This change alone reduced the size of main.c by almost 300 lines of code thanks to the significantly simpler interface it provides.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Initialization looks like &lt;a href="https://github.com/too1/ncs-uart-handler/blob/master/samples/peripheral_uart/src/main.c#L104-L112"&gt;this&lt;/a&gt;, receiving data and forwarding it to the BLE stack looks like &lt;a href="https://github.com/too1/ncs-uart-handler/blob/master/samples/peripheral_uart/src/main.c#L79-L81"&gt;this&lt;/a&gt;, and forwarding data from the BLE stack to the UART is done like &lt;a href="https://github.com/too1/ncs-uart-handler/blob/master/samples/peripheral_uart/src/main.c#L244-L251"&gt;this&lt;/a&gt;.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The repo has been updated for v2.2.0 of the SDK, but I tested the peripheral_uart sample in V2.0.0 as well and it seems to work fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you do decide to give this driver a go and have any issues getting it running just let me know, and I will do my best to help. Obviously you should be able to run this both on the nRF9160 and the nRF52811 side.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/413685?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2023 03:17:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a6c2e5c-9c6d-4fc1-9636-821f55aceded</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;One thing I forgot to mention. &amp;nbsp;When you had me set&amp;nbsp;&lt;em&gt;CONFIG_LOG_MODE_IMMEDIATE=y &lt;/em&gt;to see if any additional information might be&amp;nbsp;printed when I disconnect the BT. &amp;nbsp;When I had first enabled it, it seemed like the BLE started crashing. &amp;nbsp;I think this was before I had even try to connect the iOS app. &amp;nbsp;So I turned it off. &amp;nbsp;I just turned it back on, and it&amp;#39;s not crashing the BLE (52811) outright, but the behavior of the disconnect hang/crash seems to have changed when that parameter is enabled:&lt;/p&gt;
&lt;p&gt;It seems to crash differently with it enabled. &amp;nbsp;The disconnect still causes a crash, but it seems like it&amp;#39;s in a different place and it doesn&amp;#39;t hang anymore. &amp;nbsp;I have tried it about 20 times and I would think I would have at least 25% of the be a hang. &amp;nbsp;But there have been no hangs. &amp;nbsp;Here&amp;#39;s what the crash looks like and it seems similar:&lt;/p&gt;
&lt;p&gt;10&amp;gt; [00:00:05.018,951] &amp;lt;err&amp;gt; os: ***** USAGE FAULT *****&lt;br /&gt;10&amp;gt; [00:00:05.019,409] &amp;lt;err&amp;gt; os: Illegal use of the EPSR&lt;br /&gt;10&amp;gt; [00:00:05.019,897] &amp;lt;err&amp;gt; os: r0/a1: 0x200022bc r1/a2: 0x00021d83 r2/a3: 0x00000000&lt;br /&gt;10&amp;gt; [00:00:05.020,568] &amp;lt;err&amp;gt; os: r3/a4: 0x00000000 r12/ip: 0x00026aa0 r14/lr: 0x20004adc&lt;br /&gt;10&amp;gt; [00:00:05.021,240] &amp;lt;err&amp;gt; os: xpsr: 0x20004a00&lt;br /&gt;10&amp;gt; [00:00:05.021,697] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x01000000&lt;br /&gt;10&amp;gt; [00:00:05.022,308] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 0: CPU exception on CPU 0&lt;br /&gt;10&amp;gt; [00:00:05.022,888] &amp;lt;err&amp;gt; os: Current thread: 0x20001df0 (sysworkq)&lt;br /&gt;10&amp;gt; [00:00:05.028,350] &amp;lt;err&amp;gt; fatal_error: Resetting system[0m&lt;/p&gt;
&lt;p&gt;So not sure how this changes the behavior. &amp;nbsp;When I set it back to n, and start doing disconnects, I see it hang again and the WDT is resetting it. &amp;nbsp;So something changes with that being enabled. &amp;nbsp;Hopefully that gives us a hint or something.&lt;/p&gt;
&lt;p&gt;But no additional info from it, though since the behavior changes, it&amp;#39;s hard to know if there was still something we weren&amp;#39;t seeing...&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;h&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/413679?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2023 01:54:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:648417f9-8a3a-4037-ac8b-767b735a2c64</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yes, the callback code is a conglomeration of the initial sample peripheral_uart code as well as some examples, etc. and then some tweaking on my part as a result of a lot of testing. &amp;nbsp;It works pretty good, except for that strangeness where the UART pipe from the 9160 appears to hang up for several seconds so that 4 messages get put into one message that then overflows into several full message buffers.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The code that generates the BLE_connecd message is:&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;#ifdef&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;CONFIG_NRFX_UARTE0&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;LOG_INF&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Sending BLE_connected, Ptr: &lt;/span&gt;&lt;span&gt;%p&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;, &amp;amp;&lt;/span&gt;&lt;span&gt;theMsg&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;uart_tx&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;uart&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;theMsg&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;strlen&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;theMsg&lt;/span&gt;&lt;span&gt;), &lt;/span&gt;&lt;span&gt;SYS_FOREVER_MS&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;LOG_WRN&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;uart_tx_done: Failed to send data over UART&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;#endif&lt;/span&gt;&lt;span&gt; // CONFIG_NRFX_UARTE0&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;span&gt;On the UART_TX_DONE section that was commented out, I was starting to see if I could communicate from the BLE (52811) back to the 9160, and I was getting hung up in UART_TX_DONE that was crashing the BLE processor. &amp;nbsp;I think what was happening was that I was calling uart_tx() like in the above, and&amp;nbsp;when it ended up in UART_TX_DONE, it was trying to free the pointer connected to the string I think, which was not&amp;nbsp;originally malloc&amp;#39;d, that that was bad.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now one of the things we need to do (not related to the above issue) is to be able to send messages form the BLE to the 9160. &amp;nbsp;So if I need some of the code in UART_TX_DONE to do that, please let me know. &amp;nbsp;I can also create another ticket on that specific issue. &amp;nbsp;The other issue I am starting to work on is to try to reduce the footprint of the 52811 to get mcuboot in there. &amp;nbsp;Again, probably another ticket?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please advise.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your help.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;h.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/413541?ContentTypeID=1</link><pubDate>Mon, 06 Mar 2023 12:57:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97b09682-1c36-4b49-84d5-e31253495f95</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Harold&lt;/p&gt;
&lt;p&gt;If you use the JLink Viewer then you are using the RTT backend, as opposed to the UART backend which is the most common.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t spot anything in the code, it seems you have copied most of it from the original example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I do notice that you removed all of the code from the UART_TX_DONE callback?&amp;nbsp;&lt;br /&gt;Is there any particular reason for that?&lt;/p&gt;
&lt;p&gt;Looking at your earlier log it includes the following:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;peripheral_uart: Sending BLE_connected, Ptr: 0x20003e74&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do you have a similar message sent when you disconnect?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you send me the code you use to send these messages (BLE_connected, and similar for disconnected if you have one)?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/413357?ContentTypeID=1</link><pubDate>Sat, 04 Mar 2023 04:38:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6799edea-f33b-44ae-801e-44aa21eebba3</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Not sure what you mean by backend. &amp;nbsp;I am using a&amp;nbsp;couple of&amp;nbsp;segger&amp;#39;s to interface with the 9160 and 52811. &amp;nbsp;And the JLink Viewer to see the log information. &amp;nbsp;I did try setting the config log mode immediate to y. &amp;nbsp;I crashed it several times, but didn&amp;#39;t see anything more with it.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I did implement the WDT so that when it hangs it will reset the processor. &amp;nbsp;That works pretty well. &amp;nbsp;I have it set to 15 seconds and&amp;nbsp;feed it every 10 seconds. &amp;nbsp;I&amp;#39;ve tested the hang over 30 times and every time it was reset anywhere from 5 to 15 seconds after the disconnect. &amp;nbsp;So that will bandaid the situation while we figure out what&amp;#39;s going on.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As far as the uart code, here&amp;#39;s the callback:&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;#ifdef CONFIG_NRFX_UARTE0
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
/*
LOG_INF(&amp;quot;\n\n\n%p %s %s %s %s entered uart_cb callback: type %d\n&amp;quot;,
k_current_get(),
k_thread_name_get(k_current_get()),
k_is_in_isr() ? &amp;quot;ISR&amp;quot; : &amp;quot;THREAD&amp;quot;,
k_is_pre_kernel() ? &amp;quot;preK&amp;quot; : &amp;quot;postK&amp;quot;,
k_is_preempt_thread() ? &amp;quot;preempt&amp;quot; : &amp;quot;nopreempt&amp;quot;,
evt-&amp;gt;type);
*/

ARG_UNUSED(dev);

static uint8_t *current_buf;
static size_t aborted_len;
static bool buf_release, disable_req;
struct uart_data_t *buf;
static uint8_t *aborted_buf;
//static uint8_t theBuf[21];

switch (evt-&amp;gt;type) {

case UART_TX_DONE:
LOG_INF(&amp;quot;uart_tx_done: len: %d&amp;quot;, evt-&amp;gt;data.tx.len);

/*
if ((evt-&amp;gt;data.tx.len == 0) ||
(!evt-&amp;gt;data.tx.buf)) {
LOG_INF(&amp;quot;uart_tx_done: no evt data buf or len 0, exiting&amp;quot;);
return;
}

if (aborted_buf) {
buf = CONTAINER_OF(aborted_buf, struct uart_data_t, data);
aborted_buf = NULL;
aborted_len = 0;
} else {
buf = CONTAINER_OF(evt-&amp;gt;data.tx.buf, struct uart_data_t, data);
}

LOG_INF(&amp;quot;uart_tx_done: freeing buf: %p&amp;quot;, buf);
k_free(buf);

buf = k_fifo_get(&amp;amp;fifo_uart_tx_data, K_NO_WAIT);
LOG_INF(&amp;quot;uart_tx_done: buf %p from fifo queue&amp;quot;, buf);
if (!buf) {
LOG_INF(&amp;quot;uart_tx_done: no buf, exiting&amp;quot;);
return;
}

LOG_INF(&amp;quot;uart_tx_done: data |%*s| len %d sent to uart_tx(...)&amp;quot;, buf-&amp;gt;len, buf-&amp;gt;data, buf-&amp;gt;len);
if (uart_tx(uart, buf-&amp;gt;data, buf-&amp;gt;len, SYS_FOREVER_MS)) {
LOG_WRN(&amp;quot;uart_tx_done: Failed to send data over UART&amp;quot;);
}
*/

break;

case UART_RX_RDY:
// LOG_INF(&amp;quot;uart_rx_rdy: len %d&amp;quot;, evt-&amp;gt;data.rx.len);

buf = CONTAINER_OF(evt-&amp;gt;data.rx.buf, struct uart_data_t, data);
buf-&amp;gt;len += evt-&amp;gt;data.rx.len;

// LOG_INF(&amp;quot;uart_rx_rdy: buf %p&amp;quot;, buf);

// LOG_INF(&amp;quot;uart_rx_rdy: buf %p, %d bytes |%s|&amp;quot;, buf, buf-&amp;gt;len, buf-&amp;gt;data);

if (disable_req) {
// LOG_INF(&amp;quot;uart_rx_rdy: disable_req set, exiting&amp;quot;);
return;
}

if ((evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\n&amp;#39;) ||
(evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\r&amp;#39;)) {
disable_req = true;
// LOG_INF(&amp;quot;uart_rx_rdy: set disable_req to true and call uart_rx_disable for %p&amp;quot;, buf);
uart_rx_disable(uart);
}

break;

case UART_RX_DISABLED:
// LOG_INF(&amp;quot;uart_rx_disabled: buf wants %d bytes, buf is %p&amp;quot;, sizeof(*buf), buf);

disable_req = false;

buf = k_malloc(sizeof(*buf));
if (buf) {
buf-&amp;gt;len = 0;
// LOG_INF(&amp;quot;uart_rx_disabled: after k_malloc with buf %p&amp;quot;, buf);
} else {
LOG_WRN(&amp;quot;uart_rx_disabled: Not able to allocate UART receive buffer&amp;quot;);
k_work_reschedule(&amp;amp;uart_work, UART_WAIT_FOR_BUF_DELAY);
return;
}

// LOG_INF(&amp;quot;uart_rx_disabled: calling uart_rx_enable with buf %p&amp;quot;, buf);
uart_rx_enable(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data),
UART_WAIT_FOR_RX);

break;

case UART_RX_BUF_REQUEST:
// LOG_INF(&amp;quot;uart_rx_buf_request: buf wants %d bytes, buf is %p&amp;quot;, sizeof(*buf), buf);

buf = k_malloc(sizeof(*buf));
if (buf) {
buf-&amp;gt;len = 0;
// LOG_INF(&amp;quot;uart_rx_buf_request: after k_malloc, calling uart_rx_buf_rsp with buf %p&amp;quot;, buf);
uart_rx_buf_rsp(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data));
} else {
LOG_WRN(&amp;quot;uart_rx_buf_request: Not able to allocate UART receive buffer&amp;quot;);
}

break;

case UART_RX_BUF_RELEASED: // section that needs the debug logic to work //
// LOG_INF(&amp;quot;uart_rx_buf_released: for evt %p, %d bytes, buf %p&amp;quot;,
// evt, sizeof(*evt), CONTAINER_OF(evt-&amp;gt;data.rx_buf.buf, struct uart_data_t, data));

buf = CONTAINER_OF(evt-&amp;gt;data.rx_buf.buf, struct uart_data_t, data);

///*
if (buf-&amp;gt;len &amp;gt; 0) {
// LOG_INF(&amp;quot;uart_rx_buf_released: fifo %p put |%s| for %d bytes&amp;quot;, buf, buf-&amp;gt;data, buf-&amp;gt;len);
k_fifo_put(&amp;amp;fifo_uart_rx_data, buf);
} else {
// LOG_INF(&amp;quot;uart_rx_buf_released: freeing buf %p, %d bytes&amp;quot;, buf, buf-&amp;gt;len);
k_free(buf);
}
//*/

//if (!buf-&amp;gt;len) k_free(buf);/

break;

case UART_TX_ABORTED:
// LOG_INF(&amp;quot;uart_tx_aborted:&amp;quot;);

if (!aborted_buf) {
aborted_buf = (uint8_t *)evt-&amp;gt;data.tx.buf;
}

aborted_len += evt-&amp;gt;data.tx.len;
buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
data);

LOG_INF(&amp;quot;uart_tx_aborted: calling uart_tx(...)&amp;quot;);
uart_tx(uart, &amp;amp;buf-&amp;gt;data[aborted_len],
buf-&amp;gt;len - aborted_len, SYS_FOREVER_MS);

break;

case UART_RX_STOPPED:
LOG_INF(&amp;quot;uart_rx_stopped: reason %d&amp;quot;, evt-&amp;gt;data.rx_stop.reason);
break;

default:
LOG_INF(&amp;quot;evt type %d on default:&amp;quot;, evt-&amp;gt;type);
break;
}
}

static void uart_work_handler(struct k_work *item)
{
LOG_INF(&amp;quot;uart_work_handler: callback:&amp;quot;);
struct uart_data_t *buf;

LOG_INF(&amp;quot;uart_work_handler: buf wants %d bytes, buf is %p&amp;quot;, sizeof(*buf), buf);

buf = k_malloc(sizeof(*buf));
if (buf) {
buf-&amp;gt;len = 0;
} else {
LOG_WRN(&amp;quot;uart_work_handler: not able to allocate UART receive buffer&amp;quot;);
k_work_reschedule(&amp;amp;uart_work, UART_WAIT_FOR_BUF_DELAY);
return;
}

LOG_INF(&amp;quot;uart_work_handler: calling uart_rx_enable:&amp;quot;);
uart_rx_enable(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data), UART_WAIT_FOR_RX);
}

static int uart_init(void)
{
int err;
struct uart_data_t *rx;

LOG_INF(&amp;quot;uart_init: %p %s %s %s %s calling device_get_binding&amp;quot;,
k_current_get(),
k_thread_name_get(k_current_get()),
k_is_in_isr() ? &amp;quot;ISR&amp;quot; : &amp;quot;THREAD&amp;quot;,
k_is_pre_kernel() ? &amp;quot;preK&amp;quot; : &amp;quot;postK&amp;quot;,
k_is_preempt_thread() ? &amp;quot;preempt&amp;quot; : &amp;quot;nopreempt&amp;quot;);

uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
if (!uart) {
return -ENXIO;
}

rx = k_malloc(sizeof(*rx));
if (rx) {
rx-&amp;gt;len = 0;
LOG_INF(&amp;quot;uart_init: k_malloc %d bytes for intial rx uart buffer %p&amp;quot;, sizeof(*rx), rx);
} else {
return -ENOMEM;
}

LOG_INF(&amp;quot;uart_init: calling k_work_init_delayable&amp;quot;);

k_work_init_delayable(&amp;amp;uart_work, uart_work_handler);

LOG_INF(&amp;quot;uart_init: calling uart_callback_set to start uart_cb callback&amp;quot;);

err = uart_callback_set(uart, uart_cb, NULL);
if (err) {
return err;
}

LOG_INF(&amp;quot;uart_init: calling uart_rx_enable for first time as we exit uart_init&amp;quot;);
return uart_rx_enable(uart, rx-&amp;gt;data, sizeof(rx-&amp;gt;data), UART_WAIT_FOR_RX);
}
#endif // CONFIG_NRFX_UARTE0&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Let me know if you see anything. &amp;nbsp;I have the buffer set to about 50 bytes. &amp;nbsp;And I am trying not to send any messages from the 9160 over that and end all messages with \r\n which should get caught in uart_rx_rdy where we then call uart_rx_disable(). &amp;nbsp;And then in uart_rx_buf_released we put the buffer that is a length greater than 0 in the fifo queue. &amp;nbsp;If the length is zero we free the buffer.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Another thread sits on the fifo queue doing a get forever until there is something there and processes the message.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;As I said in a. previous message, there is some kind of delay that cause 4 or 5 seconds of messages on the 9160 side to come over ran together on the BLE side and so we have a few message buffers that are full and not terminated with \r\n which causes some difficulty. &amp;nbsp;I have some code that checks the format and if it is incorrect it discards the data.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Thanks,&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;h.&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/412718?ContentTypeID=1</link><pubDate>Wed, 01 Mar 2023 11:13:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e80334a-9994-4455-978e-6d8439edf36e</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Harold&lt;/p&gt;
&lt;p&gt;Talking about logging, which backend are you using?&lt;/p&gt;
&lt;p&gt;Typically UART is used for logging, but possibly you are using a different backend since the UART is used in the application?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Logging will be deferred by default, which means that log messages will be stored in a buffer, and printed later from a thread. Console (printk) is not, and will be printed right away, even if called from interrupt context.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In order to make logging work the same way you can add the following configuration to your project:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;CONFIG_LOG_MODE_IMMEDIATE=y&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Then the log calls will be blocking, and the code execution should not proceed until the log output is complete. &lt;br /&gt;Could you try to make this change and see if the log output changes when the crash occurs?&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Best regards&lt;br /&gt;Torbjørn&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/412606?ContentTypeID=1</link><pubDate>Tue, 28 Feb 2023 20:19:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:130ff9b5-a824-4f91-b132-564c10b4a149</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The&amp;nbsp;logging may very well be deferred. &amp;nbsp;I have thought on a&amp;nbsp;number of&amp;nbsp;&lt;/span&gt;occasions that it may behave that way, but I am not that familiar with its various operational modes. &amp;nbsp;If you have something for me to change so it is more responsive that would be great. &amp;nbsp;I also see it skipping messages if a lot come through at one time. &amp;nbsp;So, as you say, it may be possible that there are&amp;nbsp;more statements before we hang or crash.&lt;/p&gt;
&lt;p&gt;As far as the uart_rx_disable, it is separate from the BT disconnect. &amp;nbsp;So I wouldn&amp;#39;t think that would be a factor. &amp;nbsp;We don&amp;#39;t disable the 9160 UART messaging when a device is not connected. &amp;nbsp;Also, as I had said before, I did test where no messages were being sent from the 9160 over the UART, so although everything was initialized, there was no message traffic and it didn&amp;#39;t seem to matter.&lt;/p&gt;
&lt;p&gt;As far as things going on with the UART before disconnect, there isn&amp;#39;t a specific time or place with the UART, it could be sending, or not, or not having any data coming across. &amp;nbsp;It doesn&amp;#39;t seem to matter. &amp;nbsp;And on the BLE side, just a simple disconnect after a simple connect (no notification, etc) will cause this.&lt;/p&gt;
&lt;p&gt;I do think if we can get the jlink messages not deferred that would be good. &amp;nbsp;I see some times where it seems like the messages are buffered up and display in spike a couple of seconds apart, etc.&lt;/p&gt;
&lt;p&gt;I will try to provide the rest of the info from your message soon.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;h.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/412420?ContentTypeID=1</link><pubDate>Tue, 28 Feb 2023 08:38:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f75e54d-ef9b-4073-9b7d-fa23555d8136</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;HI Harold&lt;/p&gt;
&lt;p&gt;Is the logging deferred or direct?&amp;nbsp;&lt;br /&gt;Have you tried to change the logging in the UART async handler to use console/printk or non deferred logging, in order to make sure that all the messages go through before the crash?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If the logging is deferred (which is default) we might very well be missing some of the last messages that occur before the crash.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For instance, your log doesn&amp;#39;t show any indication that the uart_rx_disable request is happening before the crash, but I have earlier seen issues with this code related to the disable request. Knowing the flow of your program,&amp;nbsp;does it seem reasonable that a Bluetooth disconnect would lead to a RX disable request?&lt;/p&gt;
&lt;p&gt;Do you send anything over the UART when the disconnect happens?&lt;/p&gt;
&lt;p&gt;Would you be able to attach the async handler code so I can have a look at it?&amp;nbsp;&lt;br /&gt;If you don&amp;#39;t want to share your code in a public ticket just let me know, and I will make the ticket private.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As a side note I have been working on a more streamlined wrapper for the UART async driver that removes the need to handle the async handler directly, and makes all the temporary buffers static rather than relying on heap.&amp;nbsp;With this wrapper you essentially just gave an init function, a transmit function, and a callback providing RX messages. I haven&amp;#39;t gotten the time to get it properly integrated in the SDK yet, but if you want to have a look at it I made it available &lt;a href="https://github.com/too1/ncs-uart-handler"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/412350?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 18:51:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a6e79f3-025a-4225-a3dd-bcf27928eaa5</guid><dc:creator>keegretupmoc</dc:creator><description>&lt;p&gt;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;There have been a lot of changes. &amp;nbsp;I don&amp;#39;t think it is related to a memory leak or something like that from allocating buffers and not releasing them. &amp;nbsp;In my testing, I have tried to isolate the various routines that are processing the UART messages from the 9160 side to the BLE side including not starting the&amp;nbsp;thread on the 9160 side that calls uart_tx to send the messages over to the 52811. &amp;nbsp;And also the routine that processes the messages on the BLE side after the callback has taken the message and put it in the fifo queue (so we only recover the message from the queue, then release the buffer).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The message buffer size is 50 and both sides are set up async. &amp;nbsp;There is only one call to the RDY callback. &amp;nbsp;So I don&amp;#39;t think it&amp;#39;s related to the buffers. &amp;nbsp;In getting the UART &amp;quot;working&amp;quot; over the months, I can tell when memory runs out and have a LOG_INF where we allocate the buffer in the DISABLE&amp;nbsp;section and also print out the pointer address, which doesn&amp;#39;t change over time, so I know we aren&amp;#39;t leaking there because the address&amp;nbsp;doesn&amp;#39;t change except for the other buffer that is allocated.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As I said, I have also tried not transmitting any data from the 9160 side, so from the BLE side, it only starts up the UART by calling uart_rx_enable, but never receives any data from the 9160 side. &amp;nbsp;But it sill hangs/crashes on disconnect from a BT device. &amp;nbsp;It&amp;#39;s only when I have the&amp;nbsp;CONFIG_NRFX_UARTE0 turned off that it doesn&amp;#39;t have any issues. &amp;nbsp;It also happens right away if I disconnect right after the BLE side has reset, so no time to run out of memory. &amp;nbsp;I also thought it was when you have notifications enabled, as the iOS app does automatically, but it happens even when it is not enabled.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I just used my android with a BLE scanner on it to connect and then disconnect a few seconds later (no notifications or access to any of the services) and it crashed. &amp;nbsp;Here&amp;#39;s the output:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;10&amp;gt; [00:00:06.107,635] &amp;lt;inf&amp;gt; peripheral_uart: Starting to advertise&lt;br /&gt;10&amp;gt; &lt;br /&gt;10&amp;gt; &lt;br /&gt;10&amp;gt; &lt;br /&gt;10&amp;gt; [00:00:06.109,130] &amp;lt;inf&amp;gt; peripheral_uart: uart_init: 0x20002250 main THREAD postK preempt calling device_get_binding&lt;br /&gt;10&amp;gt; [00:00:06.109,191] &amp;lt;inf&amp;gt; peripheral_uart: uart_init: k_malloc 56 bytes for intial rx uart buffer 0x20005490&lt;br /&gt;10&amp;gt; [00:00:06.109,222] &amp;lt;inf&amp;gt; peripheral_uart: uart_init: calling k_work_init_delayable&lt;br /&gt;10&amp;gt; [00:00:06.109,252] &amp;lt;inf&amp;gt; peripheral_uart: uart_init: calling uart_callback_set to start uart_cb callback&lt;br /&gt;10&amp;gt; [00:00:06.109,252] &amp;lt;inf&amp;gt; peripheral_uart: uart_init: calling uart_rx_enable for first time as we exit uart_init&lt;br /&gt;10&amp;gt; [00:00:06.116,363] &amp;lt;inf&amp;gt; peripheral_uart: &lt;br /&gt;10&amp;gt; &lt;br /&gt;10&amp;gt; Entered connected callback&lt;br /&gt;10&amp;gt; &lt;br /&gt;10&amp;gt; [00:00:06.116,699] &amp;lt;inf&amp;gt; peripheral_uart: Connected to 7C:45:CB:93:51:AD (random)&lt;br /&gt;10&amp;gt; [00:00:06.116,729] &amp;lt;inf&amp;gt; peripheral_uart: Sending BLE_connected, Ptr: 0x20003e74&lt;br /&gt;10&amp;gt; [00:00:06.118,804] &amp;lt;inf&amp;gt; peripheral_uart: uart_tx_done: len: 24&lt;br /&gt;10&amp;gt; [00:00:10.539,428] &amp;lt;inf&amp;gt; peripheral_uart: uart_rx_disabled: after k_malloc with buf 0x200054d0&lt;br /&gt;10&amp;gt; [00:00:11.613,555] &amp;lt;inf&amp;gt; peripheral_uart: uart_rx_disabled: after k_malloc with buf 0x20005490&lt;br /&gt;10&amp;gt; [00:00:11.614,196] &amp;lt;inf&amp;gt; peripheral_uart: Move: 501 12900 10237 32767 32767 32767&lt;br /&gt;10&amp;gt; [00:00:12.612,701] &amp;lt;inf&amp;gt; peripheral_uart: uart_rx_disabled: after k_malloc with buf 0x200054d0&lt;br /&gt;10&amp;gt; [00:00:12.613,189] &amp;lt;inf&amp;gt; peripheral_uart: THP: 65086 1000 285 9762198&lt;br /&gt;10&amp;gt; [00:00:13.611,083] &amp;lt;inf&amp;gt; peripheral_uart: uart_rx_disabled: after k_malloc with buf 0x20005490&lt;br /&gt;10&amp;gt; [00:00:13.611,328] &amp;lt;inf&amp;gt; peripheral_uart: BIO: 0 0&lt;br /&gt;10&amp;gt; [00:00:14.611,541] &amp;lt;inf&amp;gt; peripheral_uart: uart_rx_disabled: after k_malloc with buf 0x200054d0&lt;br /&gt;10&amp;gt; [00:00:14.611,785] &amp;lt;inf&amp;gt; peripheral_uart: Alerts: 00001000&lt;br /&gt;10&amp;gt; [00:00:15.611,450] &amp;lt;inf&amp;gt; peripheral_uart: uart_rx_disabled: after k_malloc with buf 0x20005490&lt;br /&gt;10&amp;gt; [00:00:15.611,724] &amp;lt;inf&amp;gt; peripheral_uart: BATS: 399 85&lt;br /&gt;10&amp;gt; [00:00:17.842,437] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x257bc, handle: 1, and ud: 0x20001cf8&lt;br /&gt;10&amp;gt; [00:00:17.842,468] &amp;lt;inf&amp;gt; bt_gatt: disconnected_cb: passed in attr: 0x257d0, handle: 2, and ud: 0x20001cf8&lt;br /&gt;10&amp;gt; [00:00:17.842,529] &amp;lt;err&amp;gt; os: ***** MPU FAULT *****&lt;br /&gt;10&amp;gt; [00:00:17.842,559] &amp;lt;err&amp;gt; os: Instruction Access Violation&lt;br /&gt;10&amp;gt; [00:00:17.842,590] &amp;lt;err&amp;gt; os: r0/a1: 0xffffffff r1/a2: 0x0001c4cb r2/a3: 0x00000002&lt;br /&gt;10&amp;gt; [00:00:17.842,620] &amp;lt;err&amp;gt; os: r3/a4: 0x00027017 r12/ip: 0x00000004 r14/lr: 0x200052d8[0m&lt;br /&gt;10&amp;gt; [00:00:17.842,620] &amp;lt;err&amp;gt; os: xpsr: 0x20005200&lt;br /&gt;10&amp;gt; [00:00:17.842,651] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00000000&lt;br /&gt;10&amp;gt; [00:00:17.842,681] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 0: CPU exception on CPU 0&lt;br /&gt;10&amp;gt; [00:00:17.842,712] &amp;lt;err&amp;gt; os: Current thread: 0x200022e8 (sysworkq)&lt;br /&gt;10&amp;gt; [00:00:18.141,235] &amp;lt;err&amp;gt; fatal_error: Resetting system&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;We were trying to send a message back to the 9160 which is what is happening at 6.116,729/118,804 (I have tried commenting that out, so nothing is trying to send to the 9160 but it still hangs/crashes). &amp;nbsp;The k_malloc&amp;#39;s are for the normal 9160 messages coming over. &amp;nbsp;You can see the messages after the k_malloc (Move, THP, BIO, ALERTS, BATS). &amp;nbsp;You can see the addresses on the malloc&amp;#39;s&amp;nbsp;&lt;/span&gt;aren&amp;#39;t advancing which is why I don&amp;#39;t think there is a memory leak. &amp;nbsp;You can see the calls to disconnected_cb right before the fault which is where the device disconnected. &amp;nbsp;There is a message in the disconnect callback like you see when we connect (&amp;quot;entered connected callback&amp;quot;), so we haven&amp;#39;t called the associated disconnect callback, which is probably done last after all the handles to the services have been dealt with, which is where I think it is hanging/crashing..&lt;/p&gt;
&lt;p&gt;There is one other oddity that bears mentioning in case you know what might be causing that. &amp;nbsp;Sometimes the messages do not come through clean and nice as in the above. &amp;nbsp;If you look at the timestamp for the messages you will see that they are being sent with a 1 second wait in-between on the 9160 side so they don&amp;#39;t come in too fast. &amp;nbsp;The oddity is sometimes I get several buffers on the BLE side with multiple messages in them. &amp;nbsp;Since the messages are sent over a roughly 5 second period, and the timeout for uart_tx is 100ms, they must somehow get delayed on the BLE side and maybe prior to going into the callback until they come all at once and there are a couple or so of the 50 byte buffers instead of the normal less then 50 byte messages with the \r\n end of messages which we look for in UART_RX_RDY:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; ((&lt;/span&gt;&lt;span&gt;evt&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;rx&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;len&lt;/span&gt;&lt;span&gt; - &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;] == &lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;\n&lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;) ||&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;evt&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;rx&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;len&lt;/span&gt;&lt;span&gt; - &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;] == &lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;\r&lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;//// if (buf-&amp;gt;len &amp;lt; UART_BUF_SIZE) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;disable_req&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;true&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;// LOG_INF(&amp;quot;uart_rx_rdy: set disable_req to true and call uart_rx_disable for %p&amp;quot;, buf);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uart_rx_disable&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;uart&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;This doesn&amp;#39;t happen very often, and I have some code that mostly detects this and discards it as a corrupted message. &amp;nbsp;But it does give me the impression that something is happening that is delaying the normal flow for at least 5 seconds. &amp;nbsp;It also doesn&amp;#39;t appear to happen at regular intervals, etc. so it&amp;#39;s not a regularly occurring process. &amp;nbsp;But the main issue is with the hanging/crashing. &amp;nbsp;It wouldn&amp;#39;t be as bad if it was only crashing, since this was from a device disconnect. &amp;nbsp;It would probably not even be noticed. &amp;nbsp;But when the BLE hangs, I have to reset it from the programmer. &amp;nbsp;So in a production device, the power would need to be cycled on the entire device to get the BLE unstuck when it happens there.&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I tried isolating out all that I could of the process on both sides of sending data across the UART but just the fact that it is active seems to cause the issue. &amp;nbsp;I didn&amp;#39;t try not initializing the UART on the BLE side, I guess I could try that...&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;h.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52811 BLE hangs or crashes after central disconnects with UART enabled</title><link>https://devzone.nordicsemi.com/thread/412218?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 10:13:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8290e66-e766-4e4d-b9fe-75fc57a2bb0a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Harold&lt;/p&gt;
&lt;p&gt;Have you made a lot of changes to the example, or is it&amp;nbsp;close to the original peripheral_uart code?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Put another way, would you be able to reproduce the issue with the standard example, or is it somehow related to the changes you made?&lt;/p&gt;
&lt;p&gt;To be fair the way the example uses dynamic memory allocation for allocating UART buffers is a bit unreliable, and there might be some issues in the original example. Once I manage to reproduce it on my end I will look into it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>