esp_hal/soc/esp32s3/
mod.rs1use core::ptr::addr_of_mut;
13
14use crate::rtc_cntl::SocResetReason;
15
16crate::unstable_module! {
17 pub mod efuse;
18 #[cfg(feature = "psram")]
19 pub mod psram;
20 pub mod trng;
21 pub mod ulp_core;
22}
23pub mod cpu_control;
24pub mod gpio;
25pub mod peripherals;
26pub(crate) mod regi2c;
27
28#[macro_export]
30macro_rules! chip {
31 () => {
32 "esp32s3"
33 };
34}
35
36#[doc(hidden)]
38#[macro_export]
39macro_rules! trm_link {
40 () => { "https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf" };
41}
42
43#[cfg_attr(not(feature = "unstable"), allow(unused))]
44pub(crate) mod constants {
45 use crate::time::Rate;
46
47 pub const I2S_SCLK: u32 = 160_000_000;
49 pub const I2S_DEFAULT_CLK_SRC: u8 = 2;
51
52 pub const RMT_RAM_START: usize = 0x60016800;
54 pub const RMT_CHANNEL_RAM_SIZE: usize = 48;
56 pub const RMT_CLOCK_SRC: u8 = 1;
58 pub const RMT_CLOCK_SRC_FREQ: Rate = Rate::from_mhz(80);
60
61 pub const RC_FAST_CLK: Rate = Rate::from_khz(17500);
63}
64
65#[doc(hidden)]
66#[unsafe(link_section = ".rwtext")]
67pub unsafe fn configure_cpu_caches() {
68 unsafe extern "C" {
73 fn rom_config_instruction_cache_mode(
74 cfg_cache_size: u32,
75 cfg_cache_ways: u8,
76 cfg_cache_line_size: u8,
77 );
78 }
79
80 const CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE: u32 = 0x8000; const CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS: u8 = 8; const CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE: u8 = 32; unsafe {
87 rom_config_instruction_cache_mode(
88 CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE,
89 CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS,
90 CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE,
91 );
92 }
93}
94
95#[doc(hidden)]
102#[unsafe(no_mangle)]
103#[unsafe(link_section = ".rwtext")]
104pub unsafe extern "C" fn ESP32Reset() -> ! {
105 unsafe {
106 configure_cpu_caches();
107 }
108
109 unsafe extern "C" {
111 static mut _rtc_fast_bss_start: u32;
112 static mut _rtc_fast_bss_end: u32;
113 static mut _rtc_fast_persistent_start: u32;
114 static mut _rtc_fast_persistent_end: u32;
115
116 static mut _rtc_slow_bss_start: u32;
117 static mut _rtc_slow_bss_end: u32;
118 static mut _rtc_slow_persistent_start: u32;
119 static mut _rtc_slow_persistent_end: u32;
120
121 static mut _stack_start_cpu0: u32;
122
123 static mut __stack_chk_guard: u32;
124 }
125
126 unsafe {
128 xtensa_lx::set_stack_pointer(addr_of_mut!(_stack_start_cpu0));
129 }
130
131 unsafe {
136 xtensa_lx_rt::zero_bss(
137 addr_of_mut!(_rtc_fast_bss_start),
138 addr_of_mut!(_rtc_fast_bss_end),
139 );
140 xtensa_lx_rt::zero_bss(
141 addr_of_mut!(_rtc_slow_bss_start),
142 addr_of_mut!(_rtc_slow_bss_end),
143 );
144 }
145 if matches!(
146 crate::system::reset_reason(),
147 None | Some(SocResetReason::ChipPowerOn)
148 ) {
149 unsafe {
150 xtensa_lx_rt::zero_bss(
151 addr_of_mut!(_rtc_fast_persistent_start),
152 addr_of_mut!(_rtc_fast_persistent_end),
153 );
154 xtensa_lx_rt::zero_bss(
155 addr_of_mut!(_rtc_slow_persistent_start),
156 addr_of_mut!(_rtc_slow_persistent_end),
157 );
158 }
159 }
160
161 let stack_chk_guard = core::ptr::addr_of_mut!(__stack_chk_guard);
162 unsafe {
165 stack_chk_guard.write_volatile(esp_config::esp_config_int!(
166 u32,
167 "ESP_HAL_CONFIG_STACK_GUARD_VALUE"
168 ));
169 }
170
171 crate::interrupt::setup_interrupts();
172
173 unsafe { xtensa_lx_rt::Reset() }
175}
176
177#[doc(hidden)]
180#[unsafe(no_mangle)]
181#[rustfmt::skip]
182pub extern "Rust" fn __init_data() -> bool {
183 false
184}
185
186#[doc(hidden)]
188#[unsafe(link_section = ".rwtext")]
189pub unsafe fn cache_writeback_addr(addr: u32, size: u32) {
190 unsafe extern "C" {
191 fn rom_Cache_WriteBack_Addr(addr: u32, size: u32);
192 fn Cache_Suspend_DCache_Autoload() -> u32;
193 fn Cache_Resume_DCache_Autoload(value: u32);
194 }
195 unsafe {
197 let autoload = Cache_Suspend_DCache_Autoload();
198 rom_Cache_WriteBack_Addr(addr, size);
199 Cache_Resume_DCache_Autoload(autoload);
200 }
201}
202
203#[doc(hidden)]
205#[unsafe(link_section = ".rwtext")]
206pub unsafe fn cache_invalidate_addr(addr: u32, size: u32) {
207 unsafe extern "C" {
208 fn Cache_Invalidate_Addr(addr: u32, size: u32);
209 }
210 unsafe {
211 Cache_Invalidate_Addr(addr, size);
212 }
213}
214
215#[doc(hidden)]
217#[unsafe(link_section = ".rwtext")]
218pub unsafe fn cache_get_dcache_line_size() -> u32 {
219 unsafe extern "C" {
220 fn Cache_Get_DCache_Line_Size() -> u32;
221 }
222 unsafe { Cache_Get_DCache_Line_Size() }
223}
224
225pub(crate) fn pre_init() {}