@@ -112,7 +112,7 @@ static esp_err_t s_i2c_master_clear_bus(i2c_bus_handle_t handle)
112112 *
113113 * @param[in] i2c_master I2C master handle
114114 */
115- static esp_err_t s_i2c_hw_fsm_reset (i2c_master_bus_handle_t i2c_master )
115+ static esp_err_t s_i2c_hw_fsm_reset (i2c_master_bus_handle_t i2c_master , bool clear_bus )
116116{
117117 esp_err_t ret = ESP_OK ;
118118 i2c_hal_context_t * hal = & i2c_master -> base -> hal ;
@@ -124,7 +124,9 @@ static esp_err_t s_i2c_hw_fsm_reset(i2c_master_bus_handle_t i2c_master)
124124 i2c_ll_master_get_filter (hal -> dev , & filter_cfg );
125125
126126 //to reset the I2C hw module, we need re-enable the hw
127- ret = s_i2c_master_clear_bus (i2c_master -> base );
127+ if (clear_bus ) {
128+ ret = s_i2c_master_clear_bus (i2c_master -> base );
129+ }
128130 I2C_RCC_ATOMIC () {
129131 i2c_ll_reset_register (i2c_master -> base -> port_num );
130132 }
@@ -141,7 +143,9 @@ static esp_err_t s_i2c_hw_fsm_reset(i2c_master_bus_handle_t i2c_master)
141143 i2c_ll_master_set_filter (hal -> dev , filter_cfg );
142144#else
143145 i2c_ll_master_fsm_rst (hal -> dev );
144- ret = s_i2c_master_clear_bus (i2c_master -> base );
146+ if (clear_bus ) {
147+ ret = s_i2c_master_clear_bus (i2c_master -> base );
148+ }
145149#endif
146150 return ret ;
147151}
@@ -492,7 +496,7 @@ static void s_i2c_send_commands(i2c_master_bus_handle_t i2c_master, TickType_t t
492496 }
493497
494498 if (atomic_load (& i2c_master -> status ) == I2C_STATUS_TIMEOUT ) {
495- s_i2c_hw_fsm_reset (i2c_master );
499+ s_i2c_hw_fsm_reset (i2c_master , true );
496500 i2c_master -> cmd_idx = 0 ;
497501 i2c_master -> trans_idx = 0 ;
498502 ESP_LOGE (TAG , "I2C hardware timeout detected" );
@@ -608,7 +612,7 @@ static esp_err_t s_i2c_transaction_start(i2c_master_dev_handle_t i2c_dev, int xf
608612 // Sometimes when the FSM get stuck, the ACK_ERR interrupt will occur endlessly until we reset the FSM and clear bus.
609613 esp_err_t ret = ESP_OK ;
610614 if (atomic_load (& i2c_master -> status ) == I2C_STATUS_TIMEOUT || i2c_ll_is_bus_busy (hal -> dev )) {
611- ESP_RETURN_ON_ERROR (s_i2c_hw_fsm_reset (i2c_master ), TAG , "reset hardware failed" );
615+ ESP_RETURN_ON_ERROR (s_i2c_hw_fsm_reset (i2c_master , true ), TAG , "reset hardware failed" );
612616 }
613617
614618 if (i2c_master -> base -> pm_lock ) {
@@ -942,7 +946,7 @@ static esp_err_t s_i2c_synchronous_transaction(i2c_master_dev_handle_t i2c_dev,
942946
943947err :
944948 // When error occurs, reset hardware fsm in case not influence following transactions.
945- s_i2c_hw_fsm_reset (i2c_dev -> master_bus );
949+ s_i2c_hw_fsm_reset (i2c_dev -> master_bus , false );
946950 xSemaphoreGive (i2c_dev -> master_bus -> bus_lock_mux );
947951 return ret ;
948952}
@@ -1164,7 +1168,7 @@ esp_err_t i2c_master_bus_reset(i2c_master_bus_handle_t bus_handle)
11641168{
11651169 ESP_RETURN_ON_FALSE ((bus_handle != NULL ), ESP_ERR_INVALID_ARG , TAG , "This bus is not initialized" );
11661170 // Reset I2C master bus
1167- ESP_RETURN_ON_ERROR (s_i2c_hw_fsm_reset (bus_handle ), TAG , "I2C master bus reset failed" );
1171+ ESP_RETURN_ON_ERROR (s_i2c_hw_fsm_reset (bus_handle , true ), TAG , "I2C master bus reset failed" );
11681172 // Reset I2C status state
11691173 atomic_store (& bus_handle -> status , I2C_STATUS_IDLE );
11701174 return ESP_OK ;
@@ -1298,6 +1302,8 @@ esp_err_t i2c_master_probe(i2c_master_bus_handle_t bus_handle, uint16_t address,
12981302 i2c_ll_set_source_clk (hal -> dev , bus_handle -> base -> clk_src );
12991303 i2c_hal_set_bus_timing (hal , 100000 , bus_handle -> base -> clk_src , bus_handle -> base -> clk_src_freq_hz );
13001304 }
1305+ i2c_ll_txfifo_rst (hal -> dev );
1306+ i2c_ll_rxfifo_rst (hal -> dev );
13011307 i2c_ll_master_set_fractional_divider (hal -> dev , 0 , 0 );
13021308 i2c_ll_enable_intr_mask (hal -> dev , I2C_LL_MASTER_EVENT_INTR );
13031309 // 20ms is sufficient for stretch, since there is no device config on probe operation.
0 commit comments