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

FDS Writing Issue with FreeRTOS and Softdevice

Hello,

I am currently trying to get a project working that uses FDS, but I am having trouble getting the writing and updating working.

The peripherals in my project are FDS, FreeRTOS, the Soft Device, BLE, SPI, and TWI. 

The issue I am facing lies within the NRF_SDH_DISPATCH_MODEL config in the sdk_config.h

// <o> NRF_SDH_DISPATCH_MODEL
 

// <i> NRF_SDH_DISPATCH_MODEL_INTERRUPT: SoftDevice events are passed to the application from the interrupt context.
// <i> NRF_SDH_DISPATCH_MODEL_APPSH: SoftDevice events are scheduled using @ref app_scheduler.
// <i> NRF_SDH_DISPATCH_MODEL_POLLING: SoftDevice events are to be fetched manually.
// <0=> NRF_SDH_DISPATCH_MODEL_INTERRUPT 
// <1=> NRF_SDH_DISPATCH_MODEL_APPSH 
// <2=> NRF_SDH_DISPATCH_MODEL_POLLING 

#ifndef NRF_SDH_DISPATCH_MODEL
#define NRF_SDH_DISPATCH_MODEL 0
#endif

When NRF_SDH_DISPATCH_MODEL is set to 2 and the softdevice is enabled with nrf_sdh_enable_request(), the FDS writing/updating fails with the error of FDS_ERR_CRC_CHECK_FAILED. 

For reference, this is the piece of the sdk_config refers to the meaning of this check failing

// <o> FDS_CRC_CHECK_ON_WRITE  - Perform a CRC check on newly written records.
 

// <i> Perform a CRC check on newly written records.
// <i> This setting can be used to make sure that the record data was not altered while being written to flash.
// <1=> Enabled 
// <0=> Disabled 

#ifndef FDS_CRC_CHECK_ON_WRITE
#define FDS_CRC_CHECK_ON_WRITE 0
#endif

When NRF_SDH_DISPATCH_MODEL is set to 0, the FDS writing/updating works, but once FreeRTOS is included into the project, there is a compiling issue that I am unsure how to solve. 

The compiling error is: multiple definition of `SWI2_EGU2_IRQHandler' at components/softdevice/common/nrf_sdh_freertos.c:62 and components/softdevice/common/nrf_sdh.c:366 .

What possible solutions would there be in order for me to be able to use FDS properly and still have all my peripherals included and working?

Either a solution that fixes the compiling issue or a solution that fixes FDS writing/updating?

  • The compiling error is: multiple definition of `SWI2_EGU2_IRQHandler' at components/softdevice/common/nrf_sdh_freertos.c:62 and components/softdevice/common/nrf_sdh.c:366 .

     you need to remove nrf_sdh.c file from your project when using freertos.

  • Hello, I tried removing nrf_sdh.c, but I received a lot of compiling errors for undefined references since that file was removed. Is there another way to fix the issue?

    Also there may be a chance that getting the program to compile will not fix my main issue of FDS not writing. I had tried a different method to get the program to compile by removing the 'SD_EVT_IRQHandler' call from nrf_sdh.c and the program successfully compiled, but it did not help FDS to successfully write.

    Here are the undefined errors for reference as well:

    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/puzzle.dir/lora_ble_twi/main.c.obj: in function `ble_stack_init':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/apps/lora_ble_twi/main.c:259: undefined reference to `nrf_sdh_enable_request'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c.obj: in function `nrf_pwr_mgmt_run':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c:349: undefined reference to `nrf_sdh_is_enabled'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c.obj: in function `vPortSuppressTicksAndSleep':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c:239: undefined reference to `nrf_sdh_is_enabled'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/integration/nrfx/legacy/nrf_drv_clock.c.obj: in function `lfclk_stop':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/integration/nrfx/legacy/nrf_drv_clock.c:121: undefined reference to `nrf_sdh_is_enabled'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/integration/nrfx/legacy/nrf_drv_clock.c.obj: in function `nrf_drv_clock_init':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/integration/nrfx/legacy/nrf_drv_clock.c:176: undefined reference to `nrf_sdh_is_enabled'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/integration/nrfx/legacy/nrf_drv_rng.c.obj: in function `nrfx_rng_handler':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/integration/nrfx/legacy/nrf_drv_rng.c:95: undefined reference to `nrf_sdh_is_enabled'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/components/softdevice/common/nrf_sdh_freertos.c.obj: in function `softdevice_task':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/components/softdevice/common/nrf_sdh_freertos.c:84: undefined reference to `nrf_sdh_evts_poll'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/components/libraries/fstorage/nrf_fstorage_sd.c.obj: in function `nrf_fstorage_sys_evt_handler':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/components/libraries/fstorage/nrf_fstorage_sd.c:577: undefined reference to `nrf_sdh_request_continue'
    [build] /usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major/gcc/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../sdk/CMakeFiles/sdk.dir/nRF5_SDK/components/libraries/fstorage/nrf_fstorage_sd.c.obj: in function `init':
    [build] /Users/Sshalf869/Desktop/puzzle/pzl/sdk/nRF5_SDK/components/libraries/fstorage/nrf_fstorage_sd.c:382: undefined reference to `nrf_sdh_is_enabled'
    

  • please attach your project here and I can try to solve the compilation issues and reattach the project after that. 

  • Hi, 

    I can't post the my application/project due to privacy reasons, but I can send you a project that emulates my same issue.

    I modified the ble_app_hrs_freertos example in the NRF5SDK and added fds initializing, writing, and reading. I also enabled the CRC_CHECK for fds reading and writing in the SDK. 

    You should also see the following output upon running this program

    <info> app: Initializing fds...
    <info> app: Event: FDS_EVT_INIT received (NRF_SUCCESS)
    <info> app: FDS CHECK-1: FDS_SUCCESS
    <info> app: FDS OPEN: FDS_ERR_CRC_CHECK_FAILED
    <info> app: FDS CLOSE: FDS_ERR_NO_OPEN_RECORDS
    <info> app: HRS FreeRTOS example started.
    <info> app: Fast advertising.
    <info> app: Event: FDS_EVT_UPDATE received (FDS_ERR_CRC_CHECK_FAILED)

    ble_app_hrs_freertos_edit.zip

  • Thanks for a nice demo to show the issue. 

    I think the issue lies in where you initiate a flash write command. Flash write operation events are received using softdevice SOC events and I think doing flash operations way before softdevice_task is running is the main problem here.

    removing the write from main and moving it into the softdevice_task as follows 

    /* This function gets events from the SoftDevice and processes them. */
    static void softdevice_task(void * pvParameter)
    {
        NRF_LOG_DEBUG("Enter softdevice_task.");
    
        if (m_task_hook != NULL)
        {
            m_task_hook(pvParameter);
        }
    
        //** FDS MAIN START **
        uint8_t write_data[1] = {0x57};
        uint8_t read_data[1] = {0x00};
    
        init_fds();
        save_stack_data(write_data,1);
        read_stack_data(read_data,1);
        //** FDS MAIN END **
    
        while (true)
        {
            nrf_sdh_evts_poll();                    /* let the handlers run first, incase the EVENT occured before creating this task */
    
            (void) ulTaskNotifyTake(pdTRUE,         /* Clear the notification value before exiting (equivalent to the binary semaphore). */
                                    portMAX_DELAY); /* Block indefinitely (INCLUDE_vTaskSuspend has to be enabled).*/
        }
    }

    gives the below results

    <info> app: HRS FreeRTOS example started.
    <info> app: Fast advertising.
    <info> app: Initializing fds...
    <info> app: Event: FDS_EVT_INIT received (NRF_SUCCESS)
    <info> app: FDS CHECK-1: FDS_SUCCESS
    <info> app: FDS OPEN: FDS_ERR_CRC_CHECK_FAILED
    <info> app: FDS CLOSE: FDS_ERR_NO_OPEN_RECORDS
    <info> app: Event: FDS_EVT_UPDATE received (NRF_SUCCESS)
    

Related