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.