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

sd_evt_get sd_flash_page_erase and not all events

Hello,

I desperatly try to implement a bootloader with the s310 softdevice. When I received the data to be written (via BLE), I erase the flash:

std::uint32_t rc = NRF_ERROR_BUSY;

while ( rc == NRF_ERROR_BUSY )
    rc = sd_flash_page_erase( start_addr_ / page_size );

Next I wait for one of NRF_EVT_FLASH_OPERATION_SUCCESS or NRF_EVT_FLASH_OPERATION_ERROR, start the flash write operation:

std::uint32_t rc = NRF_ERROR_BUSY;
while ( rc == NRF_ERROR_BUSY )
    rc = sd_flash_write(
        static_cast< std::uint32_t* >( static_cast< void* >( flash_start ) ),
        static_cast< std::uint32_t* >( static_cast< void* >( &buffer_[ content_start ] ) ),
        page_size / 4 );

Finaly I wait again for the evens from above and notify the bootloader client that the block was written.

In the main application loop I wait on sd_app_evt_wait() and then use sd_ble_evt_get() and sd_evt_get() to get and handle the specific events.

for (;;)
{
    check_error( sd_app_evt_wait() );
    ...
    while ( sd_ble_evt_get( &buffer.buffer[ 0 ], &buffer_size ) == NRF_SUCCESS )
    {
        // from this context, sd_flash_page_erase() is called
    }
    ...
    for ( std::uint32_t event_type; sd_evt_get( &event_type ) == NRF_SUCCESS; )
    {
        // from this context, sd_flash_write is called 
        // and sd_ble_gatts_hvx() called to notify the client
    }
    ...

What happens now, is that the first block arrives, I call the sd_flash_page_erase() function, but sd_evt_get() does not receives an event. Next, the bootloader client that waits for the notification, times out (20s) and sends the data again. Again the sd_flash_page_erase() will be called and this time, a NRF_EVT_FLASH_OPERATION_SUCCESS event will be generated.

All in all it looks to me like that every second event is dropped. What could be the reason for my observation? Any help and tipps are appreciated.

Edit: The version of the used S310 is 2.0.0. The FICR.CONFIGID is 0xFFFF007A, which belongs to IC revision 3.

Edit: The softdevice is initialized like this:

init_hardware::init_hardware()
{
    sd_mbr_command_t command = { SD_MBR_COMMAND_INIT_SD };
    check_error( sd_mbr_command( &command ) );

    check_error( sd_softdevice_vector_table_base_set( &__unaligned_rom_start_address__ - static_cast< char* >( nullptr ) ) );
    check_error( sd_softdevice_enable( nRF51::fag_default_low_frequency_clock_source, &softdevice_assertation_handler ) );
}

Kind regards, Torstem

Parents Reply Children
No Data
Related