Skip to content

Commit 9385774

Browse files
weeTikesean-madigan
authored andcommitted
bluetooth: controller: Improve SDC and MPSL assert handling
This change makes sure that the SDC and MPSL assert information is not optimised out by the compiler. This is important for memfault crash reports that come from the field and dont have logs. This is also useful for debugging when a device crashes without uart attached. Signed-off-by: Timothy Keys <[email protected]>
1 parent 4a40792 commit 9385774

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

subsys/bluetooth/controller/hci_driver.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,23 @@ void sdc_assertion_handler(const char *const file, const uint32_t line)
327327
#else /* !IS_ENABLED(CONFIG_BT_CTLR_ASSERT_HANDLER) */
328328
void sdc_assertion_handler(const char *const file, const uint32_t line)
329329
{
330+
volatile char assert_file_id[11] = { 0 };
331+
volatile uint32_t assert_line = line;
332+
333+
strncpy((char *)assert_file_id, file, sizeof(assert_file_id) - 1);
334+
330335
#if defined(CONFIG_ASSERT) && defined(CONFIG_ASSERT_VERBOSE) && !defined(CONFIG_ASSERT_NO_MSG_INFO)
331-
__ASSERT(false, "SoftDevice Controller ASSERT: %s, %d\n", file, line);
336+
__ASSERT(false, "SoftDevice Controller ASSERT: %s, %d\n",
337+
(char *)assert_file_id, assert_line);
332338
#elif defined(CONFIG_LOG)
333-
LOG_ERR("SoftDevice Controller ASSERT: %s, %d", file, line);
339+
LOG_ERR("SoftDevice Controller ASSERT: %s, %d", (char *)assert_file_id, assert_line);
334340
k_oops();
335341
#elif defined(CONFIG_PRINTK)
336-
printk("SoftDevice Controller ASSERT: %s, %d\n", file, line);
342+
printk("SoftDevice Controller ASSERT: %s, %d\n", (char *)assert_file_id, assert_line);
337343
printk("\n");
338344
k_oops();
339345
#else
346+
(void)assert_line;
340347
k_oops();
341348
#endif
342349
}

subsys/mpsl/init/mpsl_init.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,22 @@ void m_assert_handler(const char *const file, const uint32_t line)
308308
#else /* !IS_ENABLED(CONFIG_MPSL_ASSERT_HANDLER) */
309309
static void m_assert_handler(const char *const file, const uint32_t line)
310310
{
311+
volatile char assert_file_id[11] = { 0 };
312+
volatile uint32_t assert_line = line;
313+
314+
strncpy((char *)assert_file_id, file, sizeof(assert_file_id) - 1);
315+
311316
#if defined(CONFIG_ASSERT) && defined(CONFIG_ASSERT_VERBOSE) && !defined(CONFIG_ASSERT_NO_MSG_INFO)
312-
__ASSERT(false, "MPSL ASSERT: %s, %d\n", file, line);
317+
__ASSERT(false, "MPSL ASSERT: %s, %d\n", (char *)assert_file_id, assert_line);
313318
#elif defined(CONFIG_LOG)
314-
LOG_ERR("MPSL ASSERT: %s, %d", file, line);
319+
LOG_ERR("MPSL ASSERT: %s, %d", (char *)assert_file_id, assert_line);
315320
k_oops();
316321
#elif defined(CONFIG_PRINTK)
317-
printk("MPSL ASSERT: %s, %d\n", file, line);
322+
printk("MPSL ASSERT: %s, %d\n", (char *)assert_file_id, assert_line);
318323
printk("\n");
319324
k_oops();
320325
#else
326+
(void)assert_line;
321327
k_oops();
322328
#endif
323329
}

0 commit comments

Comments
 (0)