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

Facing an error while initializing Crypto module along with the BLE Stack

Development Kit - NRF 52

SDK - 15.0.0

Softdevice - S132

Computer Platform - Windows 7 - 64 Bit

Hi,

I am trying to integrate the ECDSA example with a custom ble application, both of which are working separately, but throw an error when integrating them together.

I am facing an error when I intialize the crypto module along with initializing the BLE stack. I've pinpointed the source of the error, which seems to occur when intializing the hardware RNG.

To reproduce this issue, in the sdk config.h, edit the following parameters.

// <e> NRF_CRYPTO_BACKEND_NRF_HW_RNG_ENABLED - Enable the nRF HW RNG backend.

// <i> The nRF HW backend provide access to RNG peripheral in nRF5x devices.
//==========================================================
#ifndef NRF_CRYPTO_BACKEND_NRF_HW_RNG_ENABLED
#define NRF_CRYPTO_BACKEND_NRF_HW_RNG_ENABLED 1
#endif
// <q> NRF_CRYPTO_BACKEND_NRF_HW_RNG_MBEDTLS_CTR_DRBG_ENABLED  - Enable mbed TLS CTR-DRBG algorithm.
 

// <i> Enable mbed TLS CTR-DRBG standardized by NIST (NIST SP 800-90A Rev. 1). The nRF HW RNG is used as an entropy source for seeding.

#ifndef NRF_CRYPTO_BACKEND_NRF_HW_RNG_MBEDTLS_CTR_DRBG_ENABLED
#define NRF_CRYPTO_BACKEND_NRF_HW_RNG_MBEDTLS_CTR_DRBG_ENABLED 1
#endif


// <h> nrf_crypto_rng - RNG Configuration

//==========================================================
// <q> NRF_CRYPTO_RNG_STATIC_MEMORY_BUFFERS_ENABLED  - Use static memory buffers for context and temporary init buffer.
 

// <i> Always recommended when using the nRF HW RNG as the context and temporary buffers are small. Consider disabling if using the CC310 RNG in a RAM constrained application. In this case, memory must be provided to nrf_crypto_rng_init, or it can be allocated internally provided that NRF_CRYPTO_ALLOCATOR does not allocate memory on the stack.

#ifndef NRF_CRYPTO_RNG_STATIC_MEMORY_BUFFERS_ENABLED
#define NRF_CRYPTO_RNG_STATIC_MEMORY_BUFFERS_ENABLED 1
#endif

// <q> NRF_CRYPTO_RNG_AUTO_INIT_ENABLED  - Initialize the RNG module automatically when nrf_crypto is initialized.
 

// <i> Automatic initialization is only supported with static or internally allocated context and temporary memory.

#ifndef NRF_CRYPTO_RNG_AUTO_INIT_ENABLED
#define NRF_CRYPTO_RNG_AUTO_INIT_ENABLED 1
#endif


// <e> NRFX_RNG_ENABLED - nrfx_rng - RNG peripheral driver
//==========================================================
#ifndef NRFX_RNG_ENABLED
#define NRFX_RNG_ENABLED 1


// <e> RNG_ENABLED - nrf_drv_rng - RNG peripheral driver - legacy layer
//==========================================================
#ifndef RNG_ENABLED
#define RNG_ENABLED 1
#endif

Then, initialize the crypto module and the ble stack together in the main.c file, and run the program. Is there a way to get around this?

  • Hi,

    Are you calling "crypto init" after ble_stack_init() in your code? This is necessary because the RNG HW is accessed through SD API. 

    Best regards,

    Vidar

  • Hi,

    Thanks for replying. 

    I've tried calling it before ble_stack_init() as well as after, but the error shows up in both the cases.

    Regards,

    Varun

  • Below is what the main function looks like

    int main(void)
    {
        ret_code_t err_code = NRF_SUCCESS;
    
        bool erase_bonds;
    
        log_init();
    
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
            
    //    Initialize ble stack
        ble_stack_init();
        
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        peer_manager_init();
    
        err_code = nrf_mem_init();
        DEMO_ERROR_CHECK(err_code);
    
    //    Initialize crypto library
        crypto_init();
    
    
        // Start execution.
        NRF_LOG_INFO("Template example started.");
        application_timers_start();
        
        advertising_start(erase_bonds);
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }

    Screenshot of the error 

  • If I initialize the crypto module before ble_stack_init, the crypto module is initialized, but the error shows up while initializing the ble stack.

    Below is the modified code in the main function

    int main(void)
    {
        ret_code_t err_code = NRF_SUCCESS;
    
        bool erase_bonds;
    
        log_init();
    
        err_code = nrf_mem_init();
        DEMO_ERROR_CHECK(err_code);
    
    //    Initialize crypto library
        crypto_init();
    
    
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
            
    //    Initializa ble stack
        ble_stack_init();
        
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        peer_manager_init();
    
    
        // Start execution.
        NRF_LOG_INFO("Template example started.");
        application_timers_start();
        
        advertising_start(erase_bonds);
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }

    And the error screenshot below,

  • Hi Varun,

    Are you able to share your project so I can try debugging it here? The last error you posted corresponds to NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION, but don't see how that could be related to nrf_crypto. 

Related