mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
Merge branch 'feat/rng_support_h21' into 'master'
H21 RNG support Closes IDF-11503 See merge request espressif/esp-idf!50061
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#include "bootloader_random.h"
|
||||
#include "hal/rng_ll.h"
|
||||
|
||||
void bootloader_random_enable(void)
|
||||
{
|
||||
rng_ll_enable();
|
||||
}
|
||||
|
||||
void bootloader_random_disable(void)
|
||||
{
|
||||
rng_ll_disable();
|
||||
}
|
||||
@@ -6,26 +6,90 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "soc/soc.h"
|
||||
#include "soc/lpperi_reg.h"
|
||||
#include "soc/wdev_reg.h"
|
||||
#include "soc/lpperi_struct.h"
|
||||
#include "hal/lp_clkrst_ll.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Read random data from RNG
|
||||
*
|
||||
* @return 32-bit random data
|
||||
*/
|
||||
static inline uint32_t rng_ll_read_data(void)
|
||||
{
|
||||
return REG_READ(LPPERI_RNG_DATA_REG);
|
||||
return REG_READ(WDEV_RND_REG);
|
||||
}
|
||||
|
||||
/* For compatibility. */
|
||||
/**
|
||||
* @brief Enable or disable RNG sampling.
|
||||
*
|
||||
* @param enable True to enable, False to disable
|
||||
*/
|
||||
static inline void rng_ll_enable_sample(bool enable)
|
||||
{
|
||||
LPPERI.rng_cfg.rng_sample_enable = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable rng xor rtc timer.
|
||||
*
|
||||
* @param enable True to enable, False to disable
|
||||
*/
|
||||
static inline void rng_ll_enable_rtc_timer(bool enable)
|
||||
{
|
||||
LPPERI.rng_cfg.rtc_timer_en = enable ? 0x3 : 0x0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable rng xor async rng timer.
|
||||
*
|
||||
* @param enable True to enable, False to disable
|
||||
*/
|
||||
static inline void rng_ll_enable_rng_timer(bool enable)
|
||||
{
|
||||
LPPERI.rng_cfg.rng_timer_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset RNG.
|
||||
*/
|
||||
static inline void rng_ll_reset(void)
|
||||
{
|
||||
// ESP32-H21 does not expose a dedicated RNG reset bit.
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable RNG module
|
||||
*
|
||||
* TODO: unify in rng_hal.c
|
||||
*/
|
||||
static inline void rng_ll_enable(void)
|
||||
{
|
||||
_lp_clkrst_ll_enable_rng_clock(true);
|
||||
rng_ll_enable_sample(true);
|
||||
rng_ll_enable_rtc_timer(false);
|
||||
rng_ll_enable_rng_timer(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable RNG module
|
||||
*
|
||||
* TODO: unify in rng_hal.c
|
||||
*/
|
||||
static inline void rng_ll_disable(void)
|
||||
{
|
||||
rng_ll_enable_sample(false);
|
||||
rng_ll_enable_rtc_timer(false);
|
||||
rng_ll_enable_rng_timer(false);
|
||||
_lp_clkrst_ll_enable_rng_clock(false);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -179,6 +179,10 @@ config SOC_SPI_EXTERNAL_NOR_FLASH_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_RNG_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_MODEM_CLOCK_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
#define SOC_RTC_WDT_SUPPORTED 1
|
||||
#define SOC_SPI_FLASH_SUPPORTED 1
|
||||
#define SOC_SPI_EXTERNAL_NOR_FLASH_SUPPORTED 1
|
||||
// #define SOC_RNG_SUPPORTED 1 //TODO: [ESP32H21] IDF-11503
|
||||
#define SOC_RNG_SUPPORTED 1
|
||||
#define SOC_MODEM_CLOCK_SUPPORTED 1
|
||||
#define SOC_REGI2C_SUPPORTED 1
|
||||
#define SOC_PHY_SUPPORTED 1
|
||||
|
||||
@@ -10,4 +10,4 @@
|
||||
#include "soc/lpperi_reg.h"
|
||||
|
||||
/* Hardware random number generator register */
|
||||
#define WDEV_RND_REG LPPERI_RNG_DATA_REG
|
||||
#define WDEV_RND_REG LPPERI_RNG_DATA_SYNC_REG
|
||||
|
||||
Reference in New Issue
Block a user