nrf5340 net core crashes when multiplying 2 uint16_t

Hi all,

I'm currently trying to get Nimble controller running on the nrf53 net core. All seems fine except that the core is crashing when I multiply 2 uint16_t variables together. When I'm using uint32_t variables the core doesn't crash. 

Is there any constraint regarding the variable alignment?

Here is the code that fails:

uint16_t temp = 2, temp2 = 4;
temp = temp * temp2;

temp is located at address 0x2100d396 and temp2 is at 0x2100d394. When I run the code, it crashes on temp and temp2 multiplication.

Same code with uint32_t that works fine:

uint32_t temp = 2, temp2 = 4;
temp = temp * temp2;

temp is at 0x2100d394 and temp2 at 0x2100d390.

Any idea what I'm missing here? Thanks

Jocelyn

Parents
  • Hi,

    Do you have a minimal example of this failing in a project? (That is, a full project, not only the two lines of code?) Also, do you have more details regarding the crash, such as any log, crash log, observations from a debug session, etc.?

    Regards,
    Terje

  • Hi, thanks for your reply.

    The code is super simple. I can get the Network core to crash directly from the reset handler:

    extern unsigned long _sidata;   /* start address for the initialization values of the .data section. defined in linker script */
    extern unsigned long _sdata;    /* start address for the .data section. defined in linker script */
    extern unsigned long _edata;    /* end address for the .data section. defined in linker script */
    extern unsigned long _sbss;     /* start address for the .bss section. defined in linker script */
    extern unsigned long _ebss;     /* end address for the .bss section. defined in linker script */
    extern unsigned long _estack;
    
    void Reset_Handler(void)
    {
    	unsigned long *src, *dest;
    	
    	src = &_sidata;
    	
    	for(dest = &_sdata; dest < &_edata; )
    	{
    		*(dest++) = *(src++);
    	}
        
    	for(dest = &_sbss; dest < &_ebss; )
    	{
    		*(dest++) = 0;
    	}
    
    	uint16_t temp = 2, temp2 = 4;
    	temp = temp * temp2;
    
    	main();
    }

    The core dump I'm getting:

    error   [FAULT]: [************* Hard fault *************]                                     
    error   [FAULT]: r0 = 0x4                                                                     
    error   [FAULT]: r1 = 0xffffffb8                                                              
    error   [FAULT]: r2 = 0x1c                                                                    
    error   [FAULT]: r3 = 0x0                                                                     
    error   [FAULT]: r12 = 0x2                                                                    
    error   [FAULT]: lr = 0x4                                                                     
    error   [FAULT]: pc = 0x1016b4f                                                               
    error   [FAULT]: psr = 0x1000c0b                                                              
    error   [FAULT]: icsr = 0x803                                                                 
    error   [FAULT]: bfar = 0xe000ed38                                                            
    error   [FAULT]: cfsr = 0x10000                                                               
    error   [FAULT]: hfsr = 0x40000000                                                            
    error   [FAULT]: mmfar = 0xe000ed34                                                           
    error   [FAULT]: sfsr = 0x0                                                                   
    error   [FAULT]: sfar = 0x0                                                                   
    error   [FAULT]: [**************************************]  

    The observation I made so far is that the variable alignment seems to be the culprit.

    Thanks,

    Jocelyn

Reply
  • Hi, thanks for your reply.

    The code is super simple. I can get the Network core to crash directly from the reset handler:

    extern unsigned long _sidata;   /* start address for the initialization values of the .data section. defined in linker script */
    extern unsigned long _sdata;    /* start address for the .data section. defined in linker script */
    extern unsigned long _edata;    /* end address for the .data section. defined in linker script */
    extern unsigned long _sbss;     /* start address for the .bss section. defined in linker script */
    extern unsigned long _ebss;     /* end address for the .bss section. defined in linker script */
    extern unsigned long _estack;
    
    void Reset_Handler(void)
    {
    	unsigned long *src, *dest;
    	
    	src = &_sidata;
    	
    	for(dest = &_sdata; dest < &_edata; )
    	{
    		*(dest++) = *(src++);
    	}
        
    	for(dest = &_sbss; dest < &_ebss; )
    	{
    		*(dest++) = 0;
    	}
    
    	uint16_t temp = 2, temp2 = 4;
    	temp = temp * temp2;
    
    	main();
    }

    The core dump I'm getting:

    error   [FAULT]: [************* Hard fault *************]                                     
    error   [FAULT]: r0 = 0x4                                                                     
    error   [FAULT]: r1 = 0xffffffb8                                                              
    error   [FAULT]: r2 = 0x1c                                                                    
    error   [FAULT]: r3 = 0x0                                                                     
    error   [FAULT]: r12 = 0x2                                                                    
    error   [FAULT]: lr = 0x4                                                                     
    error   [FAULT]: pc = 0x1016b4f                                                               
    error   [FAULT]: psr = 0x1000c0b                                                              
    error   [FAULT]: icsr = 0x803                                                                 
    error   [FAULT]: bfar = 0xe000ed38                                                            
    error   [FAULT]: cfsr = 0x10000                                                               
    error   [FAULT]: hfsr = 0x40000000                                                            
    error   [FAULT]: mmfar = 0xe000ed34                                                           
    error   [FAULT]: sfsr = 0x0                                                                   
    error   [FAULT]: sfar = 0x0                                                                   
    error   [FAULT]: [**************************************]  

    The observation I made so far is that the variable alignment seems to be the culprit.

    Thanks,

    Jocelyn

Children
Related