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

BLE + FDS Problem to read/write FDS

Hello there;

My setup: 

NRF52832
SDK 15.3

I'm facing some problems with FDS when i use it with BLE activated.

When i read or write on FDS using fds_record_open or fds_record_update with BLE activated i get fatal erros.
But if i dont initialize the BLE the FDS operates normal without any errors.

Some one have any advice about it? I just need to read the FDS on the initialization of the device and write in flash one or two times while the application runs.

Debug:

<info> app: Fast advertising.
<info> app: Event: FDS_EVT_INIT received (FDS_SUCCESS)
(After FDS INIT i try to read the FDS)
<error> app: Fatal error

My BLE Init:

void ble_init(void) {
    bool erase_bonds;
    ble_conn.sts.disconnected = 1;

    log_init();
    timers_init();
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();

    services_init();
    advertising_init();
    
    conn_params_init();
    peer_manager_init();

    NRF_LOG_INFO("Modelo esta sendo executado.");
    application_timers_start();

    advertising_start(erase_bonds);
}

FDS init:

void init_flash_fds(void) {
   ret_code_t rc;    
   // Registro p/ receber evento de quanto a inicialização está completa
   (void) fds_register(fds_evt_handler);
   // Inicia flash FDS    
   rc = fds_init();
   APP_ERROR_CHECK(rc);
   // Aguarda o FDS inicializar
   wait_for_fds_ready();    
   // Analisa estado do FDS
   fds_stat_t stat = {0};
   rc = fds_stat(&stat);

}

Parents
  • Hi,

    Can you build the application with the debug configuration, or with the DEBUG and DEBUG_NRF preprocessor symbols defined? That should help you get the exact error code and location of the error output on the log.

    Are you using the softdevice backend for FDS, and not the NVMC backend? The NVMC backend will generate a softdevice assert when trying to write/erase flash.

    Best regards,
    Jørgen

  • The error you are seeing is FDS_ERR_CRC_CHECK_FAILED. Are you using fds_record_update to update a record before opening the record again? If you are, do you wait for the FDS_EVT_UPDATE event before opening the record?

  • For now i'm just trying to do these steps for tests:

    1st boot of the device:
    - init FDS
    - fds_flash_write to write a new config
    - fds_update to store a value that represent boot count

    Then i reset the device and hope to:
    - Init FDS
    - Open the record <<- Error happens
    - Close record
    - Update the boot count var

    But when i open the record i get the error mentioned before

  • Did you wait for the FDS_EVT_UPDATE event before resetting the device? If not, the record may not have been successfully written before the reset.

  • Yes, i'm debugging FDS_EVT_UPDATE by a NRF LOG:

    <info> app: Modelo esta sendo executado.
    <info> app: Fast advertising.
    <info> app: Event: FDS_EVT_INIT received (FDS_SUCCESS)
    <info> app: Escrevendo config file...
    <info> app: Event: FDS_EVT_WRITE received (FDS_SUCCESS)
    <info> app: Writed!
    <info> app: Event: FDS_EVT_UPDATE received (FDS_SUCCESS)
    <info> app: Updated!


    After i receive the "Updated!" message i reset the device

    The function to read or write:

    ret_code_t flash_read_n_write(bool wr) {
        ret_code_t rc;
        ret_code_t rc2;
        fds_record_desc_t record_desc = {0};
        fds_find_token_t    ftok;
    	
        ftok.page=0;
        ftok.p_addr=NULL;
    
    
        static fds_record_t const m_dummy_record =
        {
            .file_id           = FILE_ID,       // ID Onde sera escrito no FDS
            .key               = REC_KEY,       // Chave de Record
            .data.p_data       = &flash_mngt,   // Estrutura onde estarão os dados que serão armazenados na Flash        
            .data.length_words = (sizeof(flash_mngt) + 3) / sizeof(uint32_t), // O tamanho do record é sempre expressado em 4-byte unidades (words)
        }; 
       
             // Procura um record de Flash FDS com os dados configurados anteriormente
             rc = fds_record_find(FLASH_ID, FLASH_REC_KEY, &record_desc, &ftok);
    
             if (rc == FDS_SUCCESS)
             {
              if(wr) {
    
                     NRF_LOG_INFO("Encontrado Records");
                     // Atualização do arquivo de config da Flash
                     fds_flash_record_t config = {0};
        
                     // Leitura Flash - Abre a flash FDS e le o conteudo
                     rc = fds_record_open(&record_desc, &config);
                     APP_ERROR_CHECK(rc);
                     NRF_LOG_INFO("Encntrou records");
                     // Copia a configuracao da Flash para o m_dummy_cfg
                     memcpy(&flash_mngt, config.p_data, sizeof(flash_mngt));       
                     NRF_LOG_INFO("Arquivo de config encontrado, atualizando numero de boot p/ %d.", flash_mngt.boot_cnt);
                     flash_mngt.boot_cnt++;
                     // Fecha a flash FDS
                     rc = fds_record_close(&record_desc);
                     APP_ERROR_CHECK(rc);
                     } else { 
          
                         flash_mngt.test++;
                         // Atualiza a Flash
                         rc2 = fds_record_update(&record_desc, &m_dummy_record);
                         APP_ERROR_CHECK(rc);
                         NRF_LOG_INFO("GRAVEI!!!!");
                         return rc;
                     }
           
            } else {
       
           // Configuracao nao encontrada, escreve uma nova
           NRF_LOG_INFO("Escrevendo config file...");
    
           rc = fds_record_write(&record_desc, &m_dummy_record);
           APP_ERROR_CHECK(rc);
       }
      
    }

    The write,update and open works normally without BLE

  • Could you post your full project for us to reproduce and debug this?

Reply Children
No Data
Related