Skip to content

Commit

Permalink
Samples: Bluetooth: Mesh: Fix MPSL uninit in light_ctrl
Browse files Browse the repository at this point in the history
This fixes a problem in the light_ctrl sample where the call to
`mpsl_lib_uninit` would not do anything because the required Kconfig
options were not set.

  * Add the required Kconfig options
  * Add error checking for the call to `mpsl_lib_uninit` and a call to
    `log_panic` to make sure this error message is actually printed
    before the sample halts after pressing the EMDS button.

Signed-off-by: Ludvig Jordet <[email protected]>
  • Loading branch information
ludvigsj authored and rlubos committed Oct 31, 2024
1 parent abb1738 commit d9629b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh/light_ctrl/overlay-emds.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
#
CONFIG_EMDS=y
CONFIG_BT_MESH_RPL_STORAGE_MODE_EMDS=y

# MPSL dynamic interrupts required to be able to uninitialize MPSL before
# storing EMDS data.
CONFIG_DYNAMIC_INTERRUPTS=y
CONFIG_DYNAMIC_DIRECT_INTERRUPTS=y
CONFIG_MPSL_DYNAMIC_INTERRUPTS=y
10 changes: 8 additions & 2 deletions samples/bluetooth/mesh/light_ctrl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/** @file
* @brief Nordic mesh light fixture sample
*/
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <bluetooth/mesh/models.h>
#include <bluetooth/mesh/dk_prov.h>
Expand Down Expand Up @@ -46,6 +47,8 @@ static void button_handler_cb(uint32_t pressed, uint32_t changed)

static void app_emds_cb(void)
{
/* Flush logs before halting. */
log_panic();
dk_set_leds(DK_LED2_MSK | DK_LED3_MSK | DK_LED4_MSK);
k_fatal_halt(K_ERR_CPU_EXCEPTION);
}
Expand All @@ -55,8 +58,11 @@ static void isr_emds_cb(void *arg)
ARG_UNUSED(arg);

#if defined(CONFIG_BT_CTLR)
/* Stop mpsl to reduce power usage. */
mpsl_lib_uninit();
int32_t err = mpsl_lib_uninit();

if (err != 0) {
printk("Could not stop MPSL (err %d)\n", err);
}
#endif

emds_store();
Expand Down

0 comments on commit d9629b1

Please sign in to comment.