@@ -5,7 +5,7 @@ use core::task::Poll;
55
66use aligned:: { A4 , Aligned } ;
77#[ cfg( feature = "time" ) ]
8- use embassy_time:: Timer ;
8+ use embassy_time:: { Duration , Ticker } ;
99use sdio_host:: common_cmd:: { R1 , Resp , cmd} ;
1010use sdio_host:: sd:: { BusWidth , OCR , RCA , SD } ;
1111use sdio_host:: { Cmd , sd_cmd} ;
@@ -110,30 +110,25 @@ impl<'a, 'b> SerialDataInterface<'a, 'b> {
110110 // the SDMMC_CK frequency must be no more than 400 kHz.
111111 self . sdmmc . init_idle ( ) ?;
112112
113- // Retry CMD5 (IO_SEND_OP_COND) up to 500 times with 1 ms delays, matching the
114- // Infineon/Cypress WHD driver (SDIO_ENUMERATION_TRIES / SDIO_RETRY_DELAY_MS).
115- // The SDMMC peripheral stays POWER_ON throughout so the card clock keeps running,
116- // which is required for SDIO chips (e.g. CYW4373) that need the clock during
117- // their internal power-up sequence before they can ACK CMD5.
118- let _ocr: OCR < SD > = {
119- let mut result = Err ( Error :: Timeout ) ;
120- for _ in 0 ..500u16 {
121- match self . sdmmc . cmd ( io_send_op_cond ( false , 0x0 ) , false , false ) {
122- Ok ( r) => {
123- result = Ok ( r) ;
124- break ;
125- }
126- Err ( Error :: Timeout ) => {
127- #[ cfg( feature = "time" ) ]
128- Timer :: after_millis ( 1 ) . await ;
129- #[ cfg( not( feature = "time" ) ) ]
130- crate :: block_for_us ( 1000 ) ;
131- }
132- Err ( e) => return Err ( e) ,
113+ // Get IO OCR
114+ #[ cfg( feature = "time" ) ]
115+ let mut ticker = Ticker :: every ( Duration :: from_millis ( 1 ) ) ;
116+ let mut i = 0 ;
117+
118+ let _ocr: OCR < SD > = loop {
119+ match self . sdmmc . cmd ( io_send_op_cond ( false , 0x0 ) , false , false ) {
120+ Ok ( r) => break Ok ( r) ,
121+ Err ( Error :: Timeout ) if i == 500 => break Err ( Error :: Timeout ) ,
122+ Err ( Error :: Timeout ) => {
123+ i += 1 ;
124+
125+ #[ cfg( feature = "time" ) ]
126+ ticker. next ( ) . await ;
133127 }
128+ Err ( e) => break Err ( e) ,
134129 }
135- result? . into ( )
136- } ;
130+ } ?
131+ . into ( ) ;
137132
138133 // UDB-based SDIO does not support io volt switch sequence
139134
0 commit comments