@@ -70,6 +70,17 @@ pub fn attach() -> i32 {
7070
7171 if config_result == 0 {
7272 unsafe { esp_rom_spiflash_attach ( spiconfig, false ) } ;
73+
74+ #[ cfg( feature = "esp32s3" ) ]
75+ {
76+ extern "C" {
77+ fn ets_efuse_flash_octal_mode ( ) -> bool ;
78+ }
79+ if unsafe { ets_efuse_flash_octal_mode ( ) } {
80+ init_ospi_funcs ( ) ;
81+ }
82+ }
83+
7384 0
7485 } else {
7586 -1
@@ -115,3 +126,73 @@ pub fn wait_for_idle() -> i32 {
115126
116127 0
117128}
129+
130+ #[ cfg( feature = "esp32s3" ) ]
131+ #[ allow( non_camel_case_types) ]
132+ fn init_ospi_funcs ( ) {
133+ #[ repr( C ) ]
134+ struct spiflash_legacy_funcs_t {
135+ pp_addr_bit_len : u8 ,
136+ se_addr_bit_len : u8 ,
137+ be_addr_bit_len : u8 ,
138+ rd_addr_bit_len : u8 ,
139+ read_sub_len : u32 ,
140+ write_sub_len : u32 ,
141+ unlock : Option < spi_flash_op_t > ,
142+ erase_sector : Option < spi_flash_erase_t > ,
143+ erase_block : Option < spi_flash_erase_t > ,
144+ read : Option < spi_flash_rd_t > ,
145+ write : Option < spi_flash_wr_t > ,
146+ encrypt_write : Option < spi_flash_ewr_t > ,
147+ check_sus : Option < spi_flash_func_t > ,
148+ wren : Option < spi_flash_wren_t > ,
149+ wait_idle : Option < spi_flash_op_t > ,
150+ erase_area : Option < spi_flash_erase_area_t > ,
151+ }
152+
153+ type spi_flash_func_t = unsafe extern "C" fn ( ) ;
154+ type spi_flash_op_t = unsafe extern "C" fn ( ) -> i32 ;
155+ type spi_flash_erase_t = unsafe extern "C" fn ( u32 ) -> i32 ;
156+ type spi_flash_rd_t = unsafe extern "C" fn ( u32 , * mut ( ) , i32 ) -> i32 ;
157+ type spi_flash_wr_t = unsafe extern "C" fn ( u32 , * const u32 , i32 ) -> i32 ;
158+ type spi_flash_ewr_t = unsafe extern "C" fn ( u32 , * const ( ) , u32 ) -> i32 ;
159+ type spi_flash_wren_t = unsafe extern "C" fn ( * mut ( ) ) -> i32 ;
160+ type spi_flash_erase_area_t = unsafe extern "C" fn ( u32 , u32 ) -> i32 ;
161+
162+ extern "C" {
163+ static mut rom_spiflash_legacy_funcs: * const spiflash_legacy_funcs_t ;
164+
165+ fn esp_rom_opiflash_wait_idle ( ) -> i32 ;
166+ fn esp_rom_opiflash_erase_block_64k ( addr : u32 ) -> i32 ;
167+ fn esp_rom_opiflash_erase_sector ( addr : u32 ) -> i32 ;
168+ fn esp_rom_opiflash_read ( addr : u32 , buf : * mut ( ) , len : i32 ) -> i32 ;
169+ fn esp_rom_opiflash_write ( addr : u32 , data : * const u32 , len : i32 ) -> i32 ;
170+ fn esp_rom_opiflash_wren ( p : * mut ( ) ) -> i32 ;
171+ fn esp_rom_opiflash_erase_area ( start_addr : u32 , end_addr : u32 ) -> i32 ;
172+ }
173+
174+ static FUNCS : spiflash_legacy_funcs_t = spiflash_legacy_funcs_t {
175+ pp_addr_bit_len : 24 ,
176+ se_addr_bit_len : 24 ,
177+ be_addr_bit_len : 24 ,
178+ rd_addr_bit_len : 24 ,
179+ read_sub_len : 16 ,
180+ write_sub_len : 32 ,
181+ unlock : Some ( esp_rom_opiflash_wait_idle) ,
182+ erase_block : Some ( esp_rom_opiflash_erase_block_64k) ,
183+ erase_sector : Some ( esp_rom_opiflash_erase_sector) ,
184+ read : Some ( esp_rom_opiflash_read) ,
185+ write : Some ( esp_rom_opiflash_write) ,
186+ encrypt_write : None ,
187+ check_sus : None ,
188+ wait_idle : Some ( esp_rom_opiflash_wait_idle) ,
189+ wren : Some ( esp_rom_opiflash_wren) ,
190+ erase_area : Some ( esp_rom_opiflash_erase_area) ,
191+ } ;
192+
193+ unsafe {
194+ let funcs_iram = & raw const FUNCS ;
195+ rom_spiflash_legacy_funcs =
196+ ( ( funcs_iram as usize ) - 0x4038_0400 + 0x3FC9_0400 ) as * const spiflash_legacy_funcs_t ;
197+ }
198+ }
0 commit comments