MPU FAULT

I'm working with nRF Connect SDK (Zephyr). In that I am using 255 byte array to get response from nrf52832 through BLE. my code is getting crash in response back. when I decrease size of array to 50 byte it's working.

but when I compile same in nrf5 sdk code it's working properly with 255 bytes array. Can you provide any solution or workaround to get it work?

Error Log:

*** Booting nRF Connect SDK d96769faceca ***
GPIO pins initialized correctly
[00:00:00.002,777] <inf> adc_module: gpio_init: pin reset low: 0

I2C device ready
ADC device ready
Device MCP7940N is ready.
Device 1 is ready.
[00:00:06.940,979] <inf> bt_sdc_hci_driver: hci_driver_open: SoftDevice Controller build revision:
                                            36 f0 e5 0e 87 68 48 fb  02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{
                                            91 b1 5c ed                                      |..\.             
[00:00:06.943,237] <inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
[00:00:06.943,267] <inf> bt_hci_core: hci_vs_init: HW Variant: nRF52x (0x0002)
[00:00:06.943,298] <inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870
[00:00:06.944,122] <inf> bt_hci_core: bt_dev_show_info: Identity: E4:FA:82:90:32:AC (random)
[00:00:06.944,152] <inf> bt_hci_core: bt_dev_show_info: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059
[00:00:06.944,183] <inf> bt_hci_core: bt_dev_show_info: LMP: version 5.4 (0x0d) subver 0x118f
Bluetooth initialized
Advertising started
[00:00:06.946,380] <err> MCP7940N: read_time: RC = 0

localtime_buff = Thu 2024-08-29 19:27:49
[00:00:07.946,685] <err> MCP7940N: read_time: RC = -5

[00:00:07.946,685] <err> adc_module: sec_timer_handler: Failed to read time, error: 251

[00:00:08.000,549] <err> os: mem_manage_fault: ***** MPU FAULT *****
[00:00:08.000,549] <err> os: mem_manage_fault:   Data Access Violation
[00:00:08.000,579] <err> os: mem_manage_fault:   MMFAR Address: 0x0
[00:00:08.000,579] <err> os: esf_dump: r0/a1:  0x20002bb0  r1/a2:  0x00000000  r2/a3:  0x00000000
[00:00:08.000,610] <err> os: esf_dump: r3/a4:  0x00000000 r12/ip:  0x00000000 r14/lr:  0x0002130b
[00:00:08.000,610] <err> os: esf_dump:  xpsr:  0x21000221
[00:00:08.000,640] <err> os: esf_dump: Faulting instruction address (r15/pc): 0x000211a2
[00:00:08.000,671] <err> os: z_fatal_error: >>> ZEPHYR FATAL ERROR 19: Unknown error on CPU 0
[00:00:08.000,671] <err> os: z_fatal_error: Fault during interrupt handling

[00:00:08.000,732] <err> os: z_fatal_error: Current thread: 0x20001a78 (unknown)
[00:00:08.439,880] <err> fatal_error: k_sys_fatal_error_handler: Resetting system


 

Parents Reply Children
  • Hi, 

    Thanks for the reply,

    I adjust the CONFIG_MAIN_STACK_SIZE but still facing same error. Here you can see the peripheral I initialize in the main for nrf5 SDK and nrf connect sdk both are same configuration. I created a my custom ble service and added tx and rx characteristic. also I checked memory report, RAM 58% used.

    size of tx and rx buffers are 255

    Initialized in nrf connect sdk

    Initialized in nrf5 sdk ( working without any error )

    int main(void)
    {
        bool erase_bonds;

        // Initialize.
        log_init();
        timers_init();
        pins_init(&erase_bonds);
        // EPD Setup start
        epd_init();
        //displayGuide();
        power_management_init();
        ble_stack_init();
        adc_configure();
        twi_master_init();
        read_eeprom();
       // display_guide();
        gap_params_init();
        gatt_init();
        advertising_init();
        services_init();
        conn_params_init();
        MCP7940_begin();
        MCP7940_now(&current_epoch_time);
        weekly_adherence_calculate();
        nrf_delay_ms(3000);
        MCP7940_now(&current_epoch_time);
        nrf_drv_saadc_sample();

        // Format time, "ddd yyyy-mm-dd hh:mm:ss zzz"
        latest_minute = *localtime(&current_epoch_time);
        latest_minute.tm_year = latest_minute.tm_year - 100;

        // Start execution.
        application_timers_start();
        advertising_start();

      for(;;){

      }

    }

  • What value of CONFIG_MAIN_STACK_SIZE did you try?

    Please enable the following configs and provide the log again.

    • CONFIG_DEBUG_OPTIMIZATIONS â€“ Limits the optimizations done by the compiler to only those that do not impact debugging.
    • CONFIG_DEBUG_THREAD_INFO â€“ Adds additional information to the thread object so the debugger can discover the threads.
  • Hi Amanda,

    sorry for the late reply.
    I checked CONFIG_MAIN_STACK_SIZE with different values. max valued was 8192. but still facing same issue. I have created custom BLE service and added RX and TX characteristic for sending data from nrf connect app to nrf52832 device.

    Below is my custom service, that I define

    BT_GATT_SERVICE_DEFINE(my_service,
    BT_GATT_PRIMARY_SERVICE(BT_UUID_MY_SERVICE),
    BT_GATT_CHARACTERISTIC(BT_UUID_MY_SERVICE_RX,BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
    BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
    NULL, on_receive, NULL),
    BT_GATT_CHARACTERISTIC(BT_UUID_MY_SERVICE_TX,
    BT_GATT_CHRC_NOTIFY,
    BT_GATT_PERM_READ,
    NULL, NULL, NULL),
    BT_GATT_CCC(on_cccd_changed,
    BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
    );
    for your understanding.
    I send a command 0201 and 4bytes user id from nrf connect app to a nrf52832 device and I got successfully response from device.
    but got an error of buffer overflow detected.

    * buffer overflow detected *

    [00:00:45.221,405] <err> os: r0/a1:  0x00000002  r1/a2:  0x0000000b  r2/a3:  0x0000000a

    [00:00:45.221,435] <err> os: r3/a4:  0x00000004 r12/ip:  0x00000004 r14/lr:  0x000178b5

    [00:00:45.221,435] <err> os:  xpsr:  0x61000000

    [00:00:45.221,435] <err> os: Faulting instruction address (r15/pc): 0x000178c0

    [00:00:45.221,496] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0

    [00:00:45.221,527] <err> os: Current thread: 0x20002368 (BT RX)

    [00:00:45.698,181] <err> os: Halting system

    Due to above error my device is getting disconnect from application.

    also facing GATT errors. ERROR 133(0x85): GATT ERROR and ERROR 22(0x16): GATT CONN TERMINATE LOCAL HOST

    below is my switch case that will be execute when I send command.

    for response to client(application)

    also Increased RX & TX stack size in prj.conf file.

    provide a solution if any.

  • bhargav_gondaliya said:

    [00:00:45.221,496] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0

    [00:00:45.221,527] <err> os: Current thread: 0x20002368 (BT RX)

    The log indicated that the BT RX thread caused the fault.

    Try increasing the stack size for that thread, using for instance CONFIG_BT_RX_STACK_SIZE=4096 in your prj.conf. 

  • thread analyze logs.

    main stack usage is 536 out of 4096 cpu : 99% why?

    I increased CONFIG_BT_RX_STACK_SIZE to 4096 still facing same error.

Related