We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi All,
I want to be able to write a very simple program to generate random number using the RNG. Unfortunately I am extremely new to embedded programming and so please pardon my lack of knowledge. For the moment I have done the following :
a) Using the "Manage Run-Time environment" for my 407 discovery board i added support for the RNG by selecting it from the "Device -> STM32Cube Hal" list
b) Then I try to use the functionalities of the api by including the "stm32f4xx_hal_rng.h" file. I can see that this file has the API's that i should initialize
/* Initialization/de-initialization functions **********************************/ HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng); HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng); void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng); void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
/* Peripheral Control functions ************************************************/ uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng); void HAL_RNG_ReadyCallback(RNG_HandleTypeDef* hrng); void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
However I dont know the proper way to use them. At best I have attempted the following.
Code
/*---------------------------------------------------------------------------- * CMSIS-RTOS 'main' function template *---------------------------------------------------------------------------*/ #define osObjectsPublic #include "osObjects.h" #include <stdio.h> #include <string.h> #include "stm32f4xx_hal_rng.h" /* main: initialize and start the system */ RNG_HandleTypeDef RngHandle; int main (void) { osKernelInitialize (); RngHandle.Instance = RNG; HAL_RNG_MspInit(&RngHandle); if(HAL_RNG_Init(&RngHandle) == HAL_OK){ uint32_t no = HAL_RNG_GetRandomNumber(&RngHandle); } osKernelStart (); }
I put a breakpoint hoping to catch a value in 'no' but does not happen. Eventually i plan to push the value to the UART for display. I have tried that as well but again I would leave that to another discussion. For the moment I would just want to be able to get a random number from my hardware .
I saw this link as the only useful reference. github.com/.../rng.c
Please advise me any learning materials.
That depends on processor.
A number of processors do have noise hardware to allow them to produce random numbers by hardware.
Next thing is of course what the requirements are.
Must it be cryptographically strong? Is there a need for non-volatile entropy or state information that is kept between reboots or needs to be rebuilt after each reboot?
And another question is what requirements there are for the distribution. Must each number have the same probability? And must there be zero correlation from previous value?