My application using Zephyr RTOS v4.1.0 on ESP32-WROVER-IE and ESP32-S3-WROOM-1 to implement MCUmgr over Bluetooth (SMP transport) based on the smp_svr sample builds successfully, but flashing results in a fatal CPU exception in the mcumgr smp thread:
[00:00:14.935,000] <err> os: ** FATAL EXCEPTION
[00:00:14.936,000] <err> os: ** CPU 0 EXCCAUSE 0 (illegal instruction)
[00:00:14.936,000] <err> os: ** VADDR 0 Invalid SP 0x3fcae368
[00:00:14.936,000] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
[00:00:14.936,000] <err> os: Current thread: 0x3fcc6bb0 (mcumgr smp)
Switching to ESP32-S3 gave the same error. To debug I enabled CONFIG_STACK_SENTINEL=y, rebuilt and flashed, revealing a stack overflow in the Bluetooth long workqueue:
[00:00:00.281,000] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
[00:00:00.281,000] <err> os: Current thread: 0x3fcc8a20 (BT LW WQ)
Bluetooth initialization code from bluetooth.c:
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/mgmt/mcumgr/transport/smp_bt.h>
static struct k_work advertise_work;
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_UUID128_ALL, SMP_BT_SVC_UUID_VAL),
};
static void advertise(struct k_work *work) {
int rc = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, ARRAY_SIZE(ad), NULL, 0);
if (rc) {
// Handle error
}
}
void start_smp_bluetooth_adverts(void) {
k_work_init(&advertise_work, advertise);
int rc = bt_enable(NULL);
if (rc) {
// Handle error
}
k_work_submit(&advertise_work);
}
CONFIG_BT_LONG_WQ_STACK_SIZE was fixed at 1300 in menuconfig. How can I increase it?