在 stm32f4xx 中使用 RNG 库
use RNG library in stm32f4xx
我想编写简单的代码来使用 stm32f4xx 发现板中的内置硬件生成随机数。我写了下面的代码,但它不起作用。它停留在内部 while 循环中,并且标志从未设置为跳出循环。
#include <stm32f4xx.h>
#include <stm32f4xx_rng.h>
#include <stm32f4xx_rcc.h>
void RNG_Config(void)
{
/* Enable RNG clock source */
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
/* RNG Peripheral enable */
RNG_Cmd(ENABLE);
}
int main(void)
{
uint32_t temp = 0;
RNG_Config();
while(1)
{
while (RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
temp = RNG_GetRandomNumber();
}
}
我已经通过在主函数的开头添加 SystemInit() 自己解决了这个问题。
简单学习STMicroelectronics的例子在
STM32CubeH7-master\Projects\NUCLEO-H743ZI\Examples\RNG\RNG_MultiRNG
代码可以从github下载。 Google搜索STM32CubeH7-master和github
我想编写简单的代码来使用 stm32f4xx 发现板中的内置硬件生成随机数。我写了下面的代码,但它不起作用。它停留在内部 while 循环中,并且标志从未设置为跳出循环。
#include <stm32f4xx.h>
#include <stm32f4xx_rng.h>
#include <stm32f4xx_rcc.h>
void RNG_Config(void)
{
/* Enable RNG clock source */
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
/* RNG Peripheral enable */
RNG_Cmd(ENABLE);
}
int main(void)
{
uint32_t temp = 0;
RNG_Config();
while(1)
{
while (RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
temp = RNG_GetRandomNumber();
}
}
我已经通过在主函数的开头添加 SystemInit() 自己解决了这个问题。
简单学习STMicroelectronics的例子在 STM32CubeH7-master\Projects\NUCLEO-H743ZI\Examples\RNG\RNG_MultiRNG
代码可以从github下载。 Google搜索STM32CubeH7-master和github