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

Hi!

I'm using the RNG to encrypt data that I must send via SPI to another module. I'm using the function "sd_rand_application_vector_get", because I'm working with Soft Device 132.

In my first steps, I used the functions of the RNG without SD, and all was working ok, but, when I include SD and I use this function, my application returns to the first line of the code.

To get a 32 bytes random vector, I make this:

for(ii=0; ii<32; ii++){
	length = random_vector_generate(&clave_compartida[ii], RANDOM_BUFF_SIZE);
	dat[ii+1] = clave_compartida[ii];
}

and the function that gets one random byte from the pool:

uint8_t random_vector_generate(uint8_t * p_buff, uint8_t size){
do{
	err_code = sd_rand_application_vector_get(p_buff, size);
}while(err_code != NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES);
return size;}

The code returns to the first line when

err_code = sd_rand_application_vector_get(p_buff, size);

is executed. The error code returned, "err_code", is 0x00, but the code breaks anyway.

Do I need to consider something else? Do I skip something in my code, variables, functions...?

Thank you all! Bye!

  • You write that the return value from the call to sd_rand_application_vector_get() is 0 (NRF_SUCCESS), but the "code breaks anyway". In what way does the code break? What happens and how do you debug it?

  • Hi Einar, i got this function:

        uint8_t random_vector_generate(uint8_t * p_buff, uint8_t size){
    
    	uint8_t p_bytes_available;	
    	do{
    		sd_rand_application_bytes_available_get(&p_bytes_available);
    	}while(p_bytes_available < size);
    	
    			err_code = sd_rand_application_vector_get(p_buff, size)
    
    	return size;
    }
    

    The app breaks (Make a reset) when it get the line :err_code = sd_rand_application_vector_get(p_buff, size).. The last value of err_code is "0" (NRF_SUCCESS)

    I'm debugging tracking the value of err_code with Keil, i tried with optimization Level-0 and Level-3 and is the same... I don't know if i'm missing something in my code.Please help

  • I don't really understand this. Does the chip reset while inside sd_rand_application_vector_get() or after it has returned? Or is it after your random_vector_generate() function has returned? Why do you not check err_codewith aAPP_ERROR_CHECK()`? (You should always turn off optimization (set it to 0) when debugging, particularly when stepping through the code, if not, you will get nonsense.)

Related