This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bus fault sometimes when reading ADC

Hallo Nordic team,

We are developing our own product based on the nRF9160. The software we wrote must use ADC in order to measure battery voltage and things are working well. However, sometimes we are encountering a BUS FAULT when the function adc_read(adc_dev, &sequence); is called. This bus fault is not persistent and doesn't happen all the time (sometimes once every 100 or 200 calls to adc_read(adc_dev, &sequence); sometimes twice or 3 times. 

The ADC  peripheral is in the non-secure sector and the same bus fault happens using SDK 1.2.1 and 1.3.1. Debugging is a bit hard as we dont know when this problem happens. Also, looking at the bus faults (as you can see in the following log) doesn't tell so many information other than the BFAR address is located in the SRAM (my assumption).

I am afraid that this problem is happening because of unaligned memory access somehow as it happened only one time that we got a USAGE FAULT instead of BUS FAULT (see LOG of usage fault).  I wish you could help me to find out what is causing this strange problem and more information can be provided if required. Thanks

LOG of 3 bus faults:

E: ***** BUS FAULT *****
E: Precise data bus error
E: BFAR Address: 0x2e343430
E: r0/a1: 0x2e34342c r1/a2: 0x00000000 r2/a3: 0x40008000
E: r3/a4: 0x200225b8 r12/ip: 0x200253fc r14/lr: 0x0001940f
E: xpsr: 0x81020000
E: s[ 0]: 0x00000000 s[ 1]: 0x00000000 s[ 2]: 0x00000000 s[ 3]: 0x00000000
E: s[ 4]: 0x00000000 s[ 5]: 0x00000000 s[ 6]: 0x00000000 s[ 7]: 0x00000000
E: s[ 8]: 0x00000000 s[ 9]: 0x00000000 s[10]: 0x00000000 s[11]: 0x00000000
E: s[12]: 0x00000000 s[13]: 0x00000000 s[14]: 0x00000000 s[15]: 0x00000000
E: fpscr: 0x40008000
E: Faulting instruction address (r15/pc): 0x00019442
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
E: Current thread: 0x20025b7c (unknown)
E: Halting system

 

E: ***** BUS FAULT *****
E: Precise data bus error
E: BFAR Address: 0x2c4d2c37
E: r0/a1: 0x2c4d2c33 r1/a2: 0x00000000 r2/a3: 0x40008000
E: r3/a4: 0x200225b8 r12/ip: 0x200253fc r14/lr: 0x0001940f
E: xpsr: 0x81020000
E: s[ 0]: 0x00000000 s[ 1]: 0x00000000 s[ 2]: 0x00000000 s[ 3]: 0x00000000
E: s[ 4]: 0x00000000 s[ 5]: 0x00000000 s[ 6]: 0x00000000 s[ 7]: 0x00000000
E: s[ 8]: 0x00000000 s[ 9]: 0x00000000 s[10]: 0x00000000 s[11]: 0x00000000
E: s[12]: 0x00000000 s[13]: 0x00000000 s[14]: 0x00000000 s[15]: 0x00000000
E: fpscr: 0x40008000
E: Faulting instruction address (r15/pc): 0x00019442
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
E: Current thread: 0x20025b7c (unknown)
E: Halting system

E: ***** BUS FAULT *****
E: Precise data bus error
E: BFAR Address: 0x322e3230
E: r0/a1: 0x322e322c r1/a2: 0x00000000 r2/a3: 0x40008000
E: r3/a4: 0x200225b8 r12/ip: 0x200253fc r14/lr: 0x0001940f
E: xpsr: 0x81020000
E: s[ 0]: 0x00000000 s[ 1]: 0x00000000 s[ 2]: 0x00000000 s[ 3]: 0x00000000
E: s[ 4]: 0x00000000 s[ 5]: 0x00000000 s[ 6]: 0x00000000 s[ 7]: 0x00000000
E: s[ 8]: 0x00000000 s[ 9]: 0x00000000 s[10]: 0x00000000 s[11]: 0x00000000
E: s[12]: 0x00000000 s[13]: 0x00000000 s[14]: 0x00000000 s[15]: 0x00000000
E: fpscr: 0x40008000
E: Faulting instruction address (r15/pc): 0x00019442
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
E: Current thread: 0x20025b7c (unknown)
E: Halting system

LOG of usage fault:

E: ***** USAGE FAULT *****
E: Unaligned memory access
E: r0/a1: 0x4d2c3839 r1/a2: 0x00000000 r2/a3: 0x40008000
E: r3/a4: 0x200225b8 r12/ip: 0x200253fc r14/lr: 0x0001940f
E: xpsr: 0x81020000
E: s[ 0]: 0x00000000 s[ 1]: 0x00000000 s[ 2]: 0x00000000 s[ 3]: 0x00000000
E: s[ 4]: 0x00000000 s[ 5]: 0x00000000 s[ 6]: 0x00000000 s[ 7]: 0x00000000
E: s[ 8]: 0x00000000 s[ 9]: 0x00000000 s[10]: 0x00000000 s[11]: 0x00000000
E: s[12]: 0x00000000 s[13]: 0x00000000 s[14]: 0x00000000 s[15]: 0x00000000
E: fpscr: 0x40008000
E: Faulting instruction address (r15/pc): 0x00019442
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
E: Current thread: 0x20025b7c (unknown)
E: Halting system

 

  • the BFAR address is located in the SRAM (my assumption).

    Wrong assumtion. Those addresses are outside the SRAM address space.

    Buffer overflow..?

  • Hi,

     

    When you get a fault print out, you can map the addresses to actual code lines, atleast the values that are located in flash (from 0 -> 1MB).

    The 0x19??? range is in the non-secure application space, which would be the ELF file in build-folder/zephyr/zephyr.elf.

    If you use arm-none-eabi-addr2line (or manually check the zephyr/zephyr.map file), you can highly likely (but not always) get a file/line from the program if the lookup address is in flash.

    Example:

    arm-none-eabi-addr2line -e build/zephyr/zephyr.elf 0x19442

     

    R14 (LR = link register = 0x1940f) can also be interesting to look up.

     

    Turbo J said:
    Buffer overflow..?

    This is the most common one. 

    E: Current thread: 0x20025b7c (unknown)

     Which thread is running on this memory address? You can check this in your map file.

    If it is the main thread, you can try to increase the stack size in your prj.conf:

    CONFIG_MAIN_STACK_SIZE=HIGHER_THAN_YOUR_CURRENT_VALUE_FOR_INSTANCE_8192

     

    Kind regards,

    Håkon

Related