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

Pstorage with S210

I cannot seem to get pstorage working using the S210 softdevice. I can get it to work using the S130. I was not able to find any info on pstorage using S210.

I used the example here :

devzone.nordicsemi.com/.../

When trying to use it with ant, the problem as traced back to the softdevice_sys_evt_handler_set. That seems to require softdevice_handler.h. When I include this with all its dependencies, I get an error because it needs ble.h and I cannot include that when using the S210 (I tried it with S310 too)

I then tried using softdevice_ant_evt_handler_set, and just including "ant_stack_handler_type.h" but there is a type mismatch.

I can't get the the softdevice_sys_evt_handler_set(sys_evt_dispatch) to work because of the ble.h requirement.

Is there a good example on setting up the event handler properly for the S210? I cannot seem to get it to work with the S210.

//TEST CODE BEGIN/


 #include "pstorage.h"
 //#include "ant_stack_handler_types.h"
 #include "softdevice_handler.h"

static uint8_t ps_flag = 0;
uint8_t test_data[4] __attribute__((aligned(4)));
uint8_t test_data[4] = {0x01,0x02,0x03,0x04};


static void sys_evt_dispatch(uint32_t sys_evt)
{
    pstorage_sys_event_handler(sys_evt);
}

static void softdevice_setup(void)
{    
    uint32_t err_code;
    
    err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback); 
    APP_ERROR_CHECK(err_code);

    // Configure application-specific interrupts.
    // Set application IRQ to lowest priority and
    // enable application IRQ (triggered from ANT protocol stack) 
    err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW); 
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn);
    APP_ERROR_CHECK(err_code);
	
    err_code = softdevice_ant_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);

     // If I replace softdevice_ant_evt_handler_set(sys_evt_dispatch) 
     //with softdevice_sys_evt_handler_set(sys_evt_dispatch) 
     //it still does not work because of the ble.h requirement
 }

static void dm_pstorage_cb_handler(pstorage_handle_t * p_handle,
                                   uint8_t             op_code,
                                   uint32_t            result,
                                   uint8_t           * p_data,
                                   uint32_t            data_len)
{
    switch(op_code)
    {
        case PSTORAGE_ERROR_OP_CODE:
                ps_flag = 1;
            break;
        case PSTORAGE_STORE_OP_CODE: 
                ps_flag = 2;           
            break;
        case PSTORAGE_LOAD_OP_CODE:
                ps_flag = 3;           
            break;
        case PSTORAGE_CLEAR_OP_CODE:
                ps_flag = 4;            
            break;
        case PSTORAGE_UPDATE_OP_CODE:
                ps_flag = 5;
            break;
        default:
                ps_flag = 6;
            break;
    }
}



static void pstorage_test(void)
{
    pstorage_module_param_t flashparam;
    pstorage_handle_t       flashhandle;
    pstorage_handle_t       flash_block_handle;

    uint32_t retval;

    flashparam.block_size  = 20;
    flashparam.block_count = 1;
    flashparam.cb          = dm_pstorage_cb_handler;

    retval = pstorage_init();   
    retval = pstorage_register(&flashparam, &flashhandle);   

    retval = pstorage_clear(&flashhandle, 20);  



    retval = pstorage_block_identifier_get(&flashhandle, 0, &flash_block_handle);      
    retval = pstorage_store(&flash_block_handle, test_data, 4, 0);


    retval = pstorage_block_identifier_get(&flashhandle, 0, &flash_block_handle);

    uint8_t load_data[4];
    retval = pstorage_load(load_data, &flash_block_handle, 4, 0);

    while(ps_flag == 0);
    ps_flag = 0;

    if (retval == NRF_SUCCESS)
    {   
        if ((load_data[0] == 0x01)&(load_data[1] == 0x02)&(load_data[2] == 0x03)&(load_data[3] == 0x04))
        {
            ps_flag = 100;
        }
    }   
}

// Test code end

Here is the error when I include softdevice_handler.h

C:...\softdevice_handler\ble_stack_handler_types.h(28): error: #5: cannot open source input file "ble.h": No such file or directory #include "ble.h"

This is because it is Ant and not BLE. Any suggestions on how to incoporate the softdevice_ant_evt_handler_set(sys_evt_dispatch); using S210?

Thanks!

    1. add BLE_STACK_SUPPORT_REQD to the preprocessor symbols (strange for ANT but unavoidable for pstorage module)
    2. use SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, false); instead of sd_softdevice_enable, and comment sd_nvic_SetPriority, sd_nvic_EnableIRQ out
    3. use softdevice_sys_evt_handler_set(sys_evt_dispatch); (ble.h is not required)
    4. if applied, comment SD_EVT_IRQHandler out (SWI2_IRQHandler in softdevice_handler.c will be used instead)
  • Thanks Testy,

    BLE_STACK_SUPPORT_REQD was already included in my pre processor symbols. I tried your suggestions and it is still looking for ble.h. See screenshot below.

    I have a screenshot, but cannot seem to add it to the comments, but softdevice_handler.c is still asking for ble.h

    Any suggestions? Thank again!

     #include "pstorage.h"
     //#include "ant_stack_handler_types.h"
     #include "softdevice_handler.h"
    
    static uint8_t ps_flag = 0;
    uint8_t test_data[4] __attribute__((aligned(4)));
    uint8_t test_data[4] = {0x01,0x02,0x03,0x04};
    
    static __INLINE void softdevice_setup(void)
    {    
        uint32_t err_code;
        
        err_code = SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, false); 
        APP_ERROR_CHECK(err_code);
    
        // Configure application-specific interrupts.
        // Set application IRQ to lowest priority and
        // enable application IRQ (triggered from ANT protocol stack) 
      //  err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW); 
     //   APP_ERROR_CHECK(err_code);
        
    		err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    	  APP_ERROR_CHECK(err_code);
    	
      //  err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn);
     //   APP_ERROR_CHECK(err_code);
    }
    
  • Looks good.

    ble.h is not required - I meant it for main.c

    I have these Include Paths set:

    • components\softdevice\s310\headers\
    • components\softdevice\common\softdevice_handler\

    Tested with s210_nrf51422_4.0.1_softdevice.hex (but I prefer sd_flash_page_erase, sd_flash_write with NRF_EVT_FLASH_OPERATION_SUCCESS system event to pstorage module)

  • It worked Testy, Thanks! The only thing is that I did define my own SWI2_IRQHandler. When I comment my own out, the application no longer works. If I comment out the one on softdevice_handler.c the application does work. I'm not an expert in interrupts so not sure if this is safe to do.

Related