nRF Connect SDK 2.0 crashes (1.9.x did not)

Hello,

i've trying to update the codebase of our current project (under development) from NCS 1.9.x to NCS 2.0.x.

I'm experiencing hard fault crashes when I try to perform operations that imply writing to the internal uC flash from inside a BLE attribute write callback. This never happened with the previous NCS versions (< 2).

In particular, I have a BLE characteristic for receiving commands via BLE, declared as

BT_GATT_CHARACTERISTIC(&cmds_uuid.uuid, BT_GATT_CHRC_WRITE, BT_GATT_PERM_WRITE, NULL, write_cmds_cb, NULL),

Inside the write callback (write_cmds_cb), I noticed that writing something like this:

settings_save_one("dev/conn_int", &val, sizeof(val));

causes a Hard Fault of the processor. The RTT Log is the following

00> [00:01:07.655,181] [1;31m<err> os: ***** USAGE FAULT *****
00> [00:01:07.655,212] [1;31m<err> os:   Illegal load of EXC_RETURN into PC[0m
00> [00:01:07.655,212] [1;31m<err> os: r0/a1:  0x00028dd8  r1/a2:  0x61000000  r2/a3:  0x00000040
00> [00:01:07.655,242] [1;31m<err> os: r3/a4:  0x0003d911 r12/ip:  0x20003864 r14/lr:  0x0003ce37[0m
00> [00:01:07.655,242] [1;31m<err> os:  xpsr:  0x20003800[0m
00> [00:01:07.655,242] [1;31m<err> os: Faulting instruction address (r15/pc): 0x00000008[0m
00> [00:01:07.655,273] [1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
00> 
00> [00:01:07.655,303] [1;31m<err> os: Current thread: 0x20002790 (logging)
00> 
00> [00:01:14.902,313] [1;31m<err> os: Halting system

Interestingly, the log reports the current thread to be "logging"...

If i move the settings_save_one operation out from the BLE callback into the system workqueue, it works without crashing.

As i said, I did not have any issues with the previous NCS versions based on Zephyr 2.x.

Any idea?

Thanks,

marco

Related