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

sd_rand_application_vector_get() crashes system

My code:


uint32_t err_code;
uint8_t randomBytes[6];

err_code = sd_rand_application_vector_get(randomBytes, sizeof(randomBytes));

When this function is called my system goes off in the weeds. Anyone else have this problem?

=]

Parents
  • Try something like this:

    ```   
        uint8_t randomBytes[6] = {0,0,0,0,0,0};
        uint8_t bytes_available = 0;
                
        err_code = sd_rand_application_bytes_available_get(&bytes_available);
        APP_ERROR_CHECK(err_code);
        bytes_available = (bytes_available > sizeof(randomBytes) ? sizeof(randomBytes) : bytes_available);
               
        if (bytes_available)
        {
            err_code = sd_rand_application_vector_get(randomBytes, bytes_available);        
            APP_ERROR_CHECK(err_code);
            randomBytes[0] = randomBytes[0];        // Debugging purposes.
        }
    
    ```
    

    Note that if you debug and halt on a breakpoint while the softdevice is active, it will get a timing error internally and assert (remember, you halt the MCU, not the peripherals).

    *edit: formatting, and do remember to check error codes :-)

    Best regards Håkon

Reply
  • Try something like this:

    ```   
        uint8_t randomBytes[6] = {0,0,0,0,0,0};
        uint8_t bytes_available = 0;
                
        err_code = sd_rand_application_bytes_available_get(&bytes_available);
        APP_ERROR_CHECK(err_code);
        bytes_available = (bytes_available > sizeof(randomBytes) ? sizeof(randomBytes) : bytes_available);
               
        if (bytes_available)
        {
            err_code = sd_rand_application_vector_get(randomBytes, bytes_available);        
            APP_ERROR_CHECK(err_code);
            randomBytes[0] = randomBytes[0];        // Debugging purposes.
        }
    
    ```
    

    Note that if you debug and halt on a breakpoint while the softdevice is active, it will get a timing error internally and assert (remember, you halt the MCU, not the peripherals).

    *edit: formatting, and do remember to check error codes :-)

    Best regards Håkon

Children
Related