MPU FAULT, Data access violation

Hello,

I am working with the NRF 52 DK, communicating with a sensor through I2C. The communication is working and I can read the values from the sensor. I record the data in a vector for 15 seconds with a sample rate of 25sps, after this, I want to do some processing of the data at this point appears the following error

[00:00:13.764,984] <err> os: ***** BUS FAULT *****
[00:00:13.765,014] <err> os: ***** HARD FAULT *****
[00:00:13.766,357] <err> os: Fault escalation (see below)
[00:00:13.767,669] <err> os: ***** MPU FAULT *****
[00:00:13.773,345] <err> os: Data Access Violation
[00:00:13.779,144] <err> os: MMFAR Address: 0x1ffffb94
[00:00:13.785,644] <err> os: r0/a1: 0x00018963 r1/a2: 0x200007f1 r2/a3: 0x00000008
[00:00:13.791,351] <err> os: r3/a4: 0x00018963 r12/ip: 0x00000069 r14/lr: 0x0000783f
[00:00:13.797,241] <err> os: xpsr: 0x21000005
[00:00:13.803,527] <err> os: Faulting instruction address (r15/pc): 0x0000a8a8
[00:00:13.812,622] <err> os: >>> ZEPHYR FATAL ERROR 19: Unknown error on CPU 0

When debugging the code it starts the processing without any problem until a point where variables start changing for strange values so It seems to be a memory-related problem. I have tried fixing it by increasing CONFIG_MAIN_STACK_SIZE. 

Also, I have looked for the faulting instruction address using addr2line but the result is a function inside Zephyr drivers, it changes every time I run it

Does anyone know what could be the problem here?

  • Hello,

    The code does not define other threats is just the main, two additional header files with their respective .c files with some functions for the initialization of the sensor and processing of the data. The error occurs in one of the data-processing functions.

    Is this what you mean by the Threat analyzer? 

    [00:00:00.266,845] <inf> thread_analyzer: Thread analyze:
    [00:00:00.266,998] <inf> thread_analyzer: thread_analyzer : STACK: unused 700 usage 324 / 1024 (31 %); CPU: 3 %
    [00:00:00.267,028] <inf> thread_analyzer: : Total CPU cycles used: 5
    [00:00:00.267,120] <inf> thread_analyzer: logging : STACK: unused 240 usage 528 / 768 (68 %); CPU: 79 %
    [00:00:00.267,120] <inf> thread_analyzer: : Total CPU cycles used: 124
    [00:00:00.267,303] <inf> thread_analyzer: idle : STACK: unused 288 usage 32 / 320 (10 %); CPU: 0 %
    [00:00:00.267,303] <inf> thread_analyzer: : Total CPU cycles used: 0
    [00:00:00.267,974] <inf> thread_analyzer: main : STACK: unused 3080 usage 5112 / 8192 (62 %); CPU: 14 %
    [00:00:00.268,005] <inf> thread_analyzer: : Total CPU cycles used: 27
    [00:00:00.268,249] <inf> thread_analyzer: ISR0 : STACK: unused 1656 usage 392 / 2048 (19 %)

    With the threat analyzer enable there is no error message, it just resets at the same point of the code

  • Hello,

    Yes, this is the log output I was expecting, but I thought maybe you had more threads running. Would you be able to share your project here or in a private ticket. I probably won't be able to reproduce the issue since I don't have your I2C sensor, but I can try to see if I can spot any potential issues with the code.

  • Hello,

    I will create a private ticket, thank you.

  • Thanks for sharing your project. I noticed that you're placing several large arrays on the stack in the analysis() function and its subroutines. As a test, could you try increasing the CONFIG_MAIN_STACK_SIZE to 20kB? Additionally, I noticed that you're iterating through the output float array after casting it to a double, which may be causing some buffer overruns.

  • Thank you, it worked by increasing the CONFIG_MAIN_STACK_SIZE I will check the code and the functions for other errors

Related