Skip to content

Commit d4ed7f6

Browse files
Felipe Nevescfriedt
authored andcommitted
drivers: entropy: esp32: enable rng driver
for esp32c3 allowing wifi subsystem to use inside its driver. Signed-off-by: Felipe Neves <[email protected]>
1 parent bb88140 commit d4ed7f6

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

boards/riscv/esp32c3_devkitm/Kconfig.defconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ config BOARD
77
default "esp32c3"
88
depends on BOARD_ESP32C3_DEVKITM
99

10+
config ENTROPY_ESP32_RNG
11+
default y if ENTROPY_GENERATOR
12+
1013
if BT
1114

1215
config HEAP_MEM_POOL_SIZE
@@ -16,4 +19,4 @@ choice BT_HCI_BUS_TYPE
1619
default BT_ESP32
1720
endchoice
1821

19-
endif # BT
22+
endif # BT

boards/riscv/esp32c3_devkitm/esp32c3_devkitm.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@
2323
status = "okay";
2424
current-speed = <115200>;
2525
};
26+
27+
&trng0 {
28+
status = "okay";
29+
};

drivers/entropy/Kconfig.esp32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
config ENTROPY_ESP32_RNG
77
bool "ESP32 entropy number generator driver"
8-
depends on SOC_ESP32
8+
depends on SOC_ESP32 || SOC_ESP32C3
99
select ENTROPY_HAS_DRIVER
1010
default y
1111
help

drivers/entropy/entropy_esp32.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
#define DT_DRV_COMPAT espressif_esp32_trng
88

99
#include <string.h>
10-
#include <drivers/entropy.h>
11-
#include <soc/dport_reg.h>
10+
#include <hal/cpu_hal.h>
11+
#include <esp_clk.h>
1212
#include <soc/rtc.h>
1313
#include <soc/wdev_reg.h>
1414
#include <soc/rtc_cntl_reg.h>
1515
#include <soc/apb_ctrl_reg.h>
1616
#include <esp_system.h>
1717
#include <soc.h>
18-
#include <xtensa/core-macros.h>
18+
#include <drivers/entropy.h>
1919

20-
extern int esp_clk_cpu_freq(void);
21-
extern int esp_clk_apb_freq(void);
20+
#ifdef CONFIG_SOC_ESP32
21+
#include <xtensa/core-macros.h>
22+
#include <soc/dport_reg.h>
23+
#endif
2224

2325
static inline uint32_t entropy_esp32_get_u32(void)
2426
{
@@ -37,9 +39,10 @@ static inline uint32_t entropy_esp32_get_u32(void)
3739
uint32_t ccount;
3840

3941
do {
40-
ccount = XTHAL_GET_CCOUNT();
42+
ccount = cpu_hal_get_cycle_count();
4143
} while (ccount - last_ccount < cpu_to_apb_freq_ratio * 16);
4244
last_ccount = ccount;
45+
4346
return REG_READ(WDEV_RND_REG);
4447
}
4548

dts/riscv/espressif/esp32c3.dtsi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
/ {
99
#address-cells = <1>;
1010
#size-cells = <1>;
11+
chosen {
12+
zephyr,entropy = &trng0;
13+
};
1114

1215
cpus {
1316
#address-cells = <1>;
@@ -37,6 +40,13 @@
3740
label = "UART_0";
3841
status = "disabled";
3942
};
43+
44+
trng0: trng@3ff700b0 {
45+
compatible = "espressif,esp32-trng";
46+
reg = <0x3FF700B0 0x4>;
47+
label = "TRNG_0";
48+
status = "disabled";
49+
};
4050
};
4151

4252
};

soc/riscv/esp32c3/linker.ld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ SECTIONS
130130
*libzephyr.a:log_backend_uart.*(.literal .text .literal.* .text.*)
131131
*liblib__libc__minimal.a:string.*(.literal .text .literal.* .text.*)
132132
*libgcov.a:(.literal .text .literal.* .text.*)
133+
134+
*libnet80211.a:( .wifi0iram .wifi0iram.* .wifislpiram .wifislpiram.*)
135+
*libpp.a:( .wifi0iram .wifi0iram.* .wifislpiram .wifislpiram.*)
136+
*libnet80211.a:( .wifirxiram .wifirxiram.* .wifislprxiram .wifislprxiram.*)
137+
*libpp.a:( .wifirxiram .wifirxiram.* .wifislprxiram .wifislprxiram.*)
138+
133139
. = ALIGN(4);
134140
_init_end = ABSOLUTE(.);
135141
_iram_text_end = ABSOLUTE(.); *(.srodata)

0 commit comments

Comments
 (0)