你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】STM32 随机数发生器相关函数和类型

[复制链接]
STMCU小助手 发布时间:2022-3-30 12:00
01. RNG概述
RNG 处理器是一个以连续模拟噪声为基础的随机数发生器,在主机读数时提供一个 32 位的随机数。

RNG 已通过 FIPS PUB 140-2(2001 年 10 月 10 日)测试,成功率达 99%。

随机数发生器支持库函数stm32f4xx_rng.c 和对应的头文件 stm32f4xx_rng.h。

02. 相关类型
  1. /** @defgroup RNG_flags_definition  
  2.   * @{
  3.   */
  4. #define RNG_FLAG_DRDY               ((uint8_t)0x0001) /*!< Data ready */
  5. #define RNG_FLAG_CECS               ((uint8_t)0x0002) /*!< Clock error current status */
  6. #define RNG_FLAG_SECS               ((uint8_t)0x0004) /*!< Seed error current status */

  7. #define IS_RNG_GET_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_DRDY) || \
  8.                                    ((RNG_FLAG) == RNG_FLAG_CECS) || \
  9.                                    ((RNG_FLAG) == RNG_FLAG_SECS))
  10. #define IS_RNG_CLEAR_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_CECS) || \
  11.                                     ((RNG_FLAG) == RNG_FLAG_SECS))
  12. /**
  13.   * @}
  14.   */

  15. /** @defgroup RNG_interrupts_definition   
  16.   * @{
  17.   */  
  18. #define RNG_IT_CEI                  ((uint8_t)0x20) /*!< Clock error interrupt */
  19. #define RNG_IT_SEI                  ((uint8_t)0x40) /*!< Seed error interrupt */

  20. #define IS_RNG_IT(IT) ((((IT) & (uint8_t)0x9F) == 0x00) && ((IT) != 0x00))
  21. #define IS_RNG_GET_IT(RNG_IT) (((RNG_IT) == RNG_IT_CEI) || ((RNG_IT) == RNG_IT_SEI))
复制代码

03. 相关函数
  1. /*  Function used to set the RNG configuration to the default reset state *****/
  2. void RNG_DeInit(void);

  3. /* Configuration function *****************************************************/
  4. void RNG_Cmd(FunctionalState NewState);

  5. /* Get 32 bit Random number function ******************************************/
  6. uint32_t RNG_GetRandomNumber(void);

  7. /* Interrupts and flags management functions **********************************/
  8. void RNG_ITConfig(FunctionalState NewState);
  9. FlagStatus RNG_GetFlagStatus(uint8_t RNG_FLAG);
  10. void RNG_ClearFlag(uint8_t RNG_FLAG);
  11. ITStatus RNG_GetITStatus(uint8_t RNG_IT);
  12. void RNG_ClearITPendingBit(uint8_t RNG_IT);
复制代码

04. 结构体封装
  1. /**
  2.   * @brief RNG
  3.   */

  4. typedef struct
  5. {
  6.   __IO uint32_t CR;  /*!< RNG control register, Address offset: 0x00 */
  7.   __IO uint32_t SR;  /*!< RNG status register,  Address offset: 0x04 */
  8.   __IO uint32_t DR;  /*!< RNG data register,    Address offset: 0x08 */
  9. } RNG_TypeDef;
复制代码



收藏 评论0 发布时间:2022-3-30 12:00

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版