Skip to content

Commit

Permalink
Merge branch 'bugfix/c6_h2_decrease_rng_frequency' into 'master'
Browse files Browse the repository at this point in the history
esp_hw_support: decrease RNG read frequency for C6 and H2

See merge request espressif/esp-idf!23977
  • Loading branch information
mahavirj committed May 31, 2023
2 parents bb5ea35 + d7ce04a commit aed0e36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion components/bootloader_support/src/bootloader_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

#if !defined CONFIG_IDF_TARGET_ESP32S3
#if (defined CONFIG_IDF_TARGET_ESP32C6 || defined CONFIG_IDF_TARGET_ESP32H2)
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 12) // higher frequency because we are reading bytes instead of words
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 16) // Keep the byte sampling frequency in the ~62KHz range which has been
// tested.
#else
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 32 * 2) /* extra factor of 2 is precautionary */
#endif
Expand Down
12 changes: 6 additions & 6 deletions components/esp_hw_support/hw_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
#endif

#if defined CONFIG_IDF_TARGET_ESP32S3
#define APB_CYCLE_WAIT_NUM (1778) /* If APB clock is 80 MHz, maximum sampling frequency is around 45 KHz*/
#define APB_CYCLE_WAIT_NUM (1778) /* If APB clock is 80 MHz, the maximum sampling frequency is around 45 KHz*/
/* 45 KHz reading frequency is the maximum we have tested so far on S3 */
#elif defined CONFIG_IDF_TARGET_ESP32C6
#define APB_CYCLE_WAIT_NUM (160 * 5) /* We want to have a maximum sampling frequency below 50KHz for
* 32-bit samples. But on ESP32C6, we only read one byte at a time,
* hence, the wait time is 4 times lower. The current value translates
* to a sampling frequency of 50 KHz for reading 32 bit samples,
#define APB_CYCLE_WAIT_NUM (160 * 16) /* On ESP32C6, we only read one byte at a time, then XOR the value with
* an asynchronous timer (see code below).
* The current value translates to a sampling frequency of around 62.5 KHz
* for reading 8 bit samples, which is the rate at which the RNG was tested,
* plus additional overhead for the calculation, making it slower. */
#elif defined CONFIG_IDF_TARGET_ESP32H2
#define APB_CYCLE_WAIT_NUM (160 * 3) /* Same reasoning as for ESP32C6, but the CPU frequency on ESP32H2 is
#define APB_CYCLE_WAIT_NUM (96 * 16) /* Same reasoning as for ESP32C6, but the CPU frequency on ESP32H2 is
* 96MHz instead of 160 MHz */
#else
#define APB_CYCLE_WAIT_NUM (16)
Expand Down

0 comments on commit aed0e36

Please sign in to comment.