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

sd_softdevice_disable in hardfault.

Hi, I want to logg faults on my system so in the app_error_handler I want to store some data to flash. This location in flash is erased earlier when no error was present so I only want to do a write here. I want to call sd_softdevice_disable and then nrf_nvmc_write_bytes but sd_softdevice_disable hangs the system. Is there any other way to shut down the softdevice that I can do while in error state?

Parents
  • This would be the stack trace when it locks:

    sd_softdevice_disable (Locks here) settings_set_hardfault_reason (It is called hardfault but could be any fault) app_error_handler sd_assert_handler

    So sd_softdevice_disable is called from the sd_assert_handler. I assume that this may be why it locks.

    Some code:

    void sd_assert_handler(uint32_t pc, uint16_t line_num, const uint8_t* p_file_name)
    {
    	app_error_handler(pc,line_num,p_file_name);
    }
    void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
    {
    	settings_set_hardfault_reason(error_code,line_num,(char*)p_file_name);
    	char str[256];
    	sprintf(str, "C:%d, L:%d, F:%s\n",
    			(int)error_code,
    			(int)line_num,
    			p_file_name);
    
    	error_loop(str);
    }
    
    void settings_set_hardfault_reason(uint32_t code, uint16_t line, char *file)
    {
    	if(internal_lp_settings[0].hardfault_reason.line==0xFFFF)
    	{
    		char* filename=strrchr(file, '/') ? strrchr(file, '/') + 1 : file;
    		strncpy((char*)&internal_lp_settings[0].hardfault_reason.file,(char*) &filename[0], MIN(strlen(filename)+1,sizeof(internal_lp_settings[0].hardfault_reason.file)));
    		internal_lp_settings[0].hardfault_reason.code=code;
    		internal_lp_settings[0].hardfault_reason.line=line;
    		volatile pstorage_handle_t block_handle;
    		pstorage_block_identifier_get(&pstorage_lp_flash_handle,0,(pstorage_handle_t*)&block_handle);
    		sd_softdevice_disable();//Disable softdevice to ensure that no callback calls are made
    		uint32_t hard_fault_reason_offset=sizeof(internal_lp_settings[0])-sizeof(internal_lp_settings[0].hardfault_reason);
    		nrf_nvmc_write_bytes(block_handle.block_id+hard_fault_reason_offset,(void*)&internal_lp_settings[0].hardfault_reason,sizeof(internal_lp_settings[0].hardfault_reason));
    	}
    }
    
Reply
  • This would be the stack trace when it locks:

    sd_softdevice_disable (Locks here) settings_set_hardfault_reason (It is called hardfault but could be any fault) app_error_handler sd_assert_handler

    So sd_softdevice_disable is called from the sd_assert_handler. I assume that this may be why it locks.

    Some code:

    void sd_assert_handler(uint32_t pc, uint16_t line_num, const uint8_t* p_file_name)
    {
    	app_error_handler(pc,line_num,p_file_name);
    }
    void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
    {
    	settings_set_hardfault_reason(error_code,line_num,(char*)p_file_name);
    	char str[256];
    	sprintf(str, "C:%d, L:%d, F:%s\n",
    			(int)error_code,
    			(int)line_num,
    			p_file_name);
    
    	error_loop(str);
    }
    
    void settings_set_hardfault_reason(uint32_t code, uint16_t line, char *file)
    {
    	if(internal_lp_settings[0].hardfault_reason.line==0xFFFF)
    	{
    		char* filename=strrchr(file, '/') ? strrchr(file, '/') + 1 : file;
    		strncpy((char*)&internal_lp_settings[0].hardfault_reason.file,(char*) &filename[0], MIN(strlen(filename)+1,sizeof(internal_lp_settings[0].hardfault_reason.file)));
    		internal_lp_settings[0].hardfault_reason.code=code;
    		internal_lp_settings[0].hardfault_reason.line=line;
    		volatile pstorage_handle_t block_handle;
    		pstorage_block_identifier_get(&pstorage_lp_flash_handle,0,(pstorage_handle_t*)&block_handle);
    		sd_softdevice_disable();//Disable softdevice to ensure that no callback calls are made
    		uint32_t hard_fault_reason_offset=sizeof(internal_lp_settings[0])-sizeof(internal_lp_settings[0].hardfault_reason);
    		nrf_nvmc_write_bytes(block_handle.block_id+hard_fault_reason_offset,(void*)&internal_lp_settings[0].hardfault_reason,sizeof(internal_lp_settings[0].hardfault_reason));
    	}
    }
    
Children
No Data
Related