nrfxlib Softdevice Controller crashes (hardfault) on nRF52832 but not on nRF52840 without Zephyr (baremetal)

Hi, We are trying to work with nrfxlib directly baremetal without Zephyr.  Were able to do advertising with it.  On nRF52832 the SDC crashes when we tried to set new advertising data by calling

sdc_hci_cmd_le_set_adv_data

On the nRF52840, everything works smoothly. 

We saw the debug symbols that the libsoftdevice_controller_multirole.a was compiled for S140.  Could this be the issue.  Can Nordic provide a version for the S132 ?

I aslo suspect other issue.  it could be that some how when compiling for the nRF52832 it cause some global variable inside the lib to be unaligned causing the crash (hardfault).

Please review the library code to make sure proper variable alignment or enable unaligned access for the gcc compiler when compiling the lib.

crash location : sym_OC5GPSERLPE7TKXSCU3QAZ62H3OM4MWFYV7WX2I() at 0x2f5f8

UPDATE : Sorry I was talking to fast about the the nRF52840.  It also crashes but I can confirm this.  The crash was cause by unaligned access within either the mpsl or the sec lib.

Compile my code by disabling all optimization works but not when optimization is enable.  The different is that when no optimization all global vars are word aligned while optimization will pack all global on a byte align. 

Thanks. 

Parents Reply Children
  • The ones in the nRF5_SDK 17.1

    s132_nrf52_7.2.0_softdevice.hex

    s140_nrf52_7.2.0_softdevice.hex

    The problem isn't the Softdevice.

    I believe there are global variables that need aligned access but are not aligned using __ALIGN(x).  So when compiled with optimization.  Those variables become unaligned due to optimization compacting all global on a byte boundary. So you need to force those variables to be word aligned with __ALIGN(x).  That was the cause of the crash inside MPSL & SDC.

      

  • Hi, 

    Which version of Segger Embedded Studio are you using? Seems like others have gotten similar errors when using too new SES version.

    We always recommend using the IDE/compiler version that the SDK was tested with, this is mentioned in the SDK release notes:

    nRF5 SDK v17.1.0
    ------------------------
    Release Date: August, 2021
     
    The following toolchains/devices have been used for testing and verification:
     
     - ARM: MDK-ARM version 5.25   
     - GCC: GCC ARM Embedded 9.2020-q2.major
     - IAR: IAR Workbench 7.80.4
     - SES: SES 5.42a

    Regards,
    Amanda

  • We are not using SES.  We use GCC 10.3.  It is not compiler version or IDE issue.  This is in your code.  

    You can fix this by forcing alignment on all variable that are not unit8_t or char type or you can also enable the compiler option to allow unaligned access.  By default unaligned access is not allow.  That why it causes the hardfault. The draw back is that generating unaligned access the code will be slow.   

  • Hi,

    Nguyen Hoan Hoang said:
    We use GCC 10.3.

    Can you use GCC ARM Embedded 9.2020-q2.major this version? And you said it only happen with the optimization. 

    Compile my code by disabling all optimization works but not when optimization is enable.  The different is that when no optimization all global vars are word aligned while optimization will pack all global on a byte align. 

    So I would suspect the GCC version issue. Since we havent't tested and verified with GCC 10.3, I would suggest you use the supported GCC version. 

    -Amanda

  • It is not compiler version.  I recompiled using 9.2020-q2 for you.  Same problem.

    I've worked with with Nordic SDK for 10 years already.  I've fixed many bugs from the SDK.  This time I cannot do that for you because source code is not available. 

Related