Unaligned memory access Fault

Hi, I am using LittleFS with some external flash.  This works great on it's own, but when part of our growing program it has started crashing with the "Unaligned memory access" fault.  It was fine before our project grew in size.  This may be a memory issue somewhere.  I am not sure how to locate the problem.

Here is the fault message:

[00:00:00.603,668] <err> os: ***** USAGE FAULT *****
[00:00:00.603,668] <err> os:   Unaligned memory access
[00:00:00.603,698] <err> os: r0/a1:  0x00000000  r1/a2:  0x00000001  r2/a3:  0x00000001
[00:00:00.603,698] <err> os: r3/a4:  0x200009ce r12/ip:  0x00000000 r14/lr:  0x00016cad
[00:00:00.603,729] <err> os:  xpsr:  0x61000000
[00:00:00.603,729] <err> os: s[ 0]:  0x200008bd  s[ 1]:  0x00000001  s[ 2]:  0x2000597c  s[ 3]:  0x2000a538
[00:00:00.603,790] <err> os: s[ 4]:  0x00000004  s[ 5]:  0x0002f048  s[ 6]:  0x00000000  s[ 7]:  0x0001667f
[00:00:00.603,790] <err> os: s[ 8]:  0x20001bf8  s[ 9]:  0x200008bd  s[10]:  0x2000a5c0  s[11]:  0x2000a5c0
[00:00:00.603,820] <err> os: s[12]:  0x000257e1  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x0001223d
[00:00:00.603,820] <err> os: fpscr:  0x20005858
[00:00:00.603,851] <err> os: Faulting instruction address (r15/pc): 0x0002e07a
[00:00:00.603,881] <err> os: >>> ZEPHYR FATAL ERROR 31: Unknown error on CPU 0
[00:00:00.603,912] <err> os: Current thread: 0x20005688 (unknown)
[00:00:01.046,905] <err> fatal_error: Resetting system
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***

addr2line = C:/ncs/v2.6.1/zephyr/kernel/mutex.c:57

line 57 = mutex->lock_count = 0U;

variable mutex is at 0x200009ce <flash_storage+240> while debugging.

This happens while mounting the littlefs on the external flash chip

Some more info:

CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_LOG_BUFFER_SIZE=4000
I'm not sure where else to look next.  Any suggestions?
Parents
  • Hi,

     

    addr2line = C:/ncs/v2.6.1/zephyr/kernel/mutex.c:57

    line 57 = mutex->lock_count = 0U;

    variable mutex is at 0x200009ce <flash_storage+240> while debugging.

    Is this the resolved r15/PC value? What about the r14/LR content? This can tell you where you branched from.

     

    In addition, you can check the build/zephyr/zephyr.map file and search for the current thread address (omit the 0x, ie. if 0x20005688 is listed as failing thread, then search for 20005688)

     

    Kind regards,

    Håkon

  • [00:00:00.603,668] <err> os: ***** USAGE FAULT *****
    [00:00:00.603,668] <err> os: Unaligned memory access
    [00:00:00.603,698] <err> os: r0/a1: 0x00000000 r1/a2: 0x00000001 r2/a3: 0x00000001
    [00:00:00.603,729] <err> os: r3/a4: 0x200009ce r12/ip: 0x00000000 r14/lr: 0x00016cad
    [00:00:00.603,729] <err> os: xpsr: 0x61000000
    [00:00:00.603,759] <err> os: s[ 0]: 0x200008bd s[ 1]: 0x00000001 s[ 2]: 0x2000420c s[ 3]: 0x20008db8
    [00:00:00.603,790] <err> os: s[ 4]: 0x00000004 s[ 5]: 0x0002f048 s[ 6]: 0x00000000 s[ 7]: 0x0001667f
    [00:00:00.603,790] <err> os: s[ 8]: 0x20001bf8 s[ 9]: 0x200008bd s[10]: 0x20008e40 s[11]: 0x20008e40
    [00:00:00.603,820] <err> os: s[12]: 0x000257e1 s[13]: 0x00000000 s[14]: 0x00000000 s[15]: 0x0001223d
    [00:00:00.603,820] <err> os: fpscr: 0x200040e8
    [00:00:00.603,851] <err> os: Faulting instruction address (r15/pc): 0x0002e07a
    [00:00:00.603,881] <err> os: >>> ZEPHYR FATAL ERROR 31: Unknown error on CPU 0
    [00:00:00.603,912] <err> os: Current thread: 0x20003f18 (unknown)
    [00:00:01.047,760] <err> fatal_error: Resetting system


    thread: 0x20003f18 = .bss.z_main_thread
    0x0000000020003f18 0xc8 zephyr/kernel/libkernel.a(init.c.obj)
    0x0000000020003f18 z_main_thread


    (r15/pc): 0x0002e07a = C:/ncs/v2.6.1/zephyr/kernel/mutex.c:57
    mutex->lock_count = 0U; //int z_impl_k_mutex_init(struct k_mutex *mutex)


    (r14/lr): 0x00016cad = C:/ncs/v2.6.1/zephyr/subsys/fs/littlefs_fs.c:890
    fs_lock(fs); //static int littlefs_mount(struct fs_mount_t *mountp)

    So it's in the main thread.  Looks like setting the lock_count to 0U is not aligned to 32-bits?  Is there a way to align it?  Maybe a compiler switch?

    It looks like optimizing the build for speed or debug solves the problem. Optimizing for size gives the "unaligned memory access" fault. Is there another way around this?

  • Hi,

     

    Given that it fails only on one specific compiler optimization hints that this has to do with memory usage - could you try adjusting CONFIG_MAIN_STACK_SIZE higher just to ensure that this is not overflowing?

     

    Can you also share the partitions.yml + zephyr.dts + .config file generated in your build folder?

     

    Kind regards,

    Håkon

Reply Children
Related