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

Hi, I want to write some data to flash. SDK12.3, use FSTORAGE.The stack failed to generate system events .

I have added 'sys_evt_dispatch' to the stack, but the callback function is still not called

  • Hi,

    Are you registering the callback through softdevice_sys_evt_handler_set() in ble_stack_init() as the other examples do it? In that case, please try to \ describe how you verify that the callback is not invoked on SD SoC events. 

  • Hello, thank you for your reply. I used J_link online debugging. It's part of my code

    static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
    {
         if( (evt->id == FS_EVT_STORE) && (result == FS_SUCCESS) )
         {
              store_flag = 0;
         }
         else if( (evt->id == FS_EVT_ERASE) && (result == FS_SUCCESS) )
         {
              erase_flag = 0;
         }
         else if (result != NRF_SUCCESS) 
         {
    				printf("flash ERASE or STORE error\r\n");
         }
    }
    
    FS_REGISTER_CFG(fs_config_t fs_config) =
    {
    		.callback  = fs_evt_handler,
    		.num_pages = 1,             
    		.priority  = 0xFE          
    };
    
    void m_flash_write(uint32_t const * const m_datas)
    {
          fs_ret_t ret;
          erase_flag=1;
          ret = fs_erase(&fs_config, address_of_page(0), 1,NULL);
          if (ret != FS_SUCCESS)
          {
    	//	 NRF_LOG_INFO("fs_erase error\r\n");
                     printf("fs_erase error\r\n");
    		 printf("err_code is:%d\r\n",ret);
          }
          else
          {
    		//printf("fs_erase FS_SUCCESS\r\n");
    		//NRF_LOG_INFO("fs_erase FS_SUCCESS\r\n");
    				fs_flag=1;
           }
            while(erase_flag == 1) 
    				{ power_manage(); }
    		if( fs_flag==1)
    		{
    
            store_flag=1;
    				fs_flag=0;
    			ret = fs_store(&fs_config, fs_config.p_start_addr, m_datas,16,NULL);
    			if (ret != FS_SUCCESS)
    			{
    		//  NRF_LOG_INFO("fs_store error\r\n");
    				//printf("fs_store error\r\n");
    				printf("err code is:%d\r\n",ret);
    			}
    			else
    			{
    		//NRF_LOG_INFO("fs_store FS_SUCCESS\r\n");
    	  	 //printf("fs_store FS_SUCCESS\r\n");
    			}
    		}
    	while(store_flag == 1) { power_manage(); }
    }
    
    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        fs_sys_event_handler(sys_evt);
    }
    
    static void ble_stack_init(void)
    {
        uint32_t err_code;
    
        nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
    
        // Initialize the SoftDevice handler module.
        SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
    
        ble_enable_params_t ble_enable_params;
        err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
                                                        PERIPHERAL_LINK_COUNT,
                                                        &ble_enable_params);
        APP_ERROR_CHECK(err_code);
    
        //Check the ram settings against the used number of links
        CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT);
    
        // Enable BLE stack.
    #if (NRF_SD_BLE_API_VERSION == 3)
        ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE;
    #endif
        err_code = softdevice_enable(&ble_enable_params);
        APP_ERROR_CHECK(err_code);
    
        // Register with the SoftDevice handler module for BLE events.
        err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    		err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    
    }

  • Hi,

    Looks like you have registered the handler correctly. But the while loop you have at the end of m_flash_write() will become blocking if you're calling it from an interrupt with equal or higher priority than the Softdevice system events. Could that maybe explain the problem, or are you using m_flash_write() only in main context (not in an interrupt)? I suggest testing without the while loop if you're unsure. 

  • Thanks for your reply. I called it in the serial interrupt event, and now I changed it to the main loop. A flag is given in the serial port interrupt. The main loop detects the flag call m_flash_write().However, there is still no callback for the softdevice system events.Do I need to change the priority of the function?

  • If you're using the debugger to debug the application, can you halt the CPU after the flash write to make sure the program is not stuck in a loop somewhere? Also, maybe place a breakpoint in sys_evt_dispatch() to confirm it's not being reached. 

    It should not be necessary to change the interrupt priorities. 

Related