mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/c3_i2c_timeout' into 'master'
I2C: Fix i2c write randomly timeout and WDT triggered See merge request espressif/esp-idf!14722
This commit is contained in:
commit
da12db2904
@ -539,6 +539,7 @@ esp_err_t i2c_set_data_mode(i2c_port_t i2c_num, i2c_trans_mode_t tx_trans_mode,
|
|||||||
ESP_RETURN_ON_FALSE(rx_trans_mode < I2C_DATA_MODE_MAX, ESP_ERR_INVALID_ARG, I2C_TAG, I2C_TRANS_MODE_ERR_STR);
|
ESP_RETURN_ON_FALSE(rx_trans_mode < I2C_DATA_MODE_MAX, ESP_ERR_INVALID_ARG, I2C_TAG, I2C_TRANS_MODE_ERR_STR);
|
||||||
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
i2c_hal_set_data_mode(&(i2c_context[i2c_num].hal), tx_trans_mode, rx_trans_mode);
|
i2c_hal_set_data_mode(&(i2c_context[i2c_num].hal), tx_trans_mode, rx_trans_mode);
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -690,13 +691,13 @@ esp_err_t i2c_param_config(i2c_port_t i2c_num, const i2c_config_t *i2c_conf)
|
|||||||
i2c_hal_set_sda_timing(&(i2c_context[i2c_num].hal), I2C_SLAVE_SDA_SAMPLE_DEFAULT, I2C_SLAVE_SDA_HOLD_DEFAULT);
|
i2c_hal_set_sda_timing(&(i2c_context[i2c_num].hal), I2C_SLAVE_SDA_SAMPLE_DEFAULT, I2C_SLAVE_SDA_HOLD_DEFAULT);
|
||||||
i2c_hal_set_tout(&(i2c_context[i2c_num].hal), I2C_SLAVE_TIMEOUT_DEFAULT);
|
i2c_hal_set_tout(&(i2c_context[i2c_num].hal), I2C_SLAVE_TIMEOUT_DEFAULT);
|
||||||
i2c_hal_enable_slave_rx_it(&(i2c_context[i2c_num].hal));
|
i2c_hal_enable_slave_rx_it(&(i2c_context[i2c_num].hal));
|
||||||
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
|
||||||
} else {
|
} else {
|
||||||
i2c_hal_master_init(&(i2c_context[i2c_num].hal), i2c_num);
|
i2c_hal_master_init(&(i2c_context[i2c_num].hal), i2c_num);
|
||||||
//Default, we enable hardware filter
|
//Default, we enable hardware filter
|
||||||
i2c_hal_set_filter(&(i2c_context[i2c_num].hal), I2C_FILTER_CYC_NUM_DEF);
|
i2c_hal_set_filter(&(i2c_context[i2c_num].hal), I2C_FILTER_CYC_NUM_DEF);
|
||||||
i2c_hal_set_bus_timing(&(i2c_context[i2c_num].hal), i2c_conf->master.clk_speed, src_clk);
|
i2c_hal_set_bus_timing(&(i2c_context[i2c_num].hal), i2c_conf->master.clk_speed, src_clk);
|
||||||
}
|
}
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -709,6 +710,7 @@ esp_err_t i2c_set_period(i2c_port_t i2c_num, int high_period, int low_period)
|
|||||||
|
|
||||||
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
i2c_hal_set_scl_timing(&(i2c_context[i2c_num].hal), high_period, low_period);
|
i2c_hal_set_scl_timing(&(i2c_context[i2c_num].hal), high_period, low_period);
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -728,6 +730,7 @@ esp_err_t i2c_filter_enable(i2c_port_t i2c_num, uint8_t cyc_num)
|
|||||||
ESP_RETURN_ON_FALSE(p_i2c_obj[i2c_num] != NULL, ESP_FAIL, I2C_TAG, I2C_DRIVER_ERR_STR);
|
ESP_RETURN_ON_FALSE(p_i2c_obj[i2c_num] != NULL, ESP_FAIL, I2C_TAG, I2C_DRIVER_ERR_STR);
|
||||||
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
i2c_hal_set_filter(&(i2c_context[i2c_num].hal), cyc_num);
|
i2c_hal_set_filter(&(i2c_context[i2c_num].hal), cyc_num);
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -737,6 +740,7 @@ esp_err_t i2c_filter_disable(i2c_port_t i2c_num)
|
|||||||
ESP_RETURN_ON_FALSE(i2c_num < I2C_NUM_MAX, ESP_ERR_INVALID_ARG, I2C_TAG, I2C_NUM_ERROR_STR);
|
ESP_RETURN_ON_FALSE(i2c_num < I2C_NUM_MAX, ESP_ERR_INVALID_ARG, I2C_TAG, I2C_NUM_ERROR_STR);
|
||||||
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
i2c_hal_set_filter(&(i2c_context[i2c_num].hal), 0);
|
i2c_hal_set_filter(&(i2c_context[i2c_num].hal), 0);
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -749,6 +753,7 @@ esp_err_t i2c_set_start_timing(i2c_port_t i2c_num, int setup_time, int hold_time
|
|||||||
|
|
||||||
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
i2c_hal_set_start_timing(&(i2c_context[i2c_num].hal), setup_time, hold_time);
|
i2c_hal_set_start_timing(&(i2c_context[i2c_num].hal), setup_time, hold_time);
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -770,6 +775,7 @@ esp_err_t i2c_set_stop_timing(i2c_port_t i2c_num, int setup_time, int hold_time)
|
|||||||
|
|
||||||
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
i2c_hal_set_stop_timing(&(i2c_context[i2c_num].hal), setup_time, hold_time);
|
i2c_hal_set_stop_timing(&(i2c_context[i2c_num].hal), setup_time, hold_time);
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -791,6 +797,7 @@ esp_err_t i2c_set_data_timing(i2c_port_t i2c_num, int sample_time, int hold_time
|
|||||||
|
|
||||||
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
i2c_hal_set_sda_timing(&(i2c_context[i2c_num].hal), sample_time, hold_time);
|
i2c_hal_set_sda_timing(&(i2c_context[i2c_num].hal), sample_time, hold_time);
|
||||||
|
i2c_hal_update_config(&(i2c_context[i2c_num].hal));
|
||||||
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
I2C_EXIT_CRITICAL(&(i2c_context[i2c_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
@ -801,9 +801,12 @@ static inline void i2c_ll_master_fsm_rst(i2c_dev_t *hw)
|
|||||||
static inline void i2c_ll_master_clr_bus(i2c_dev_t *hw)
|
static inline void i2c_ll_master_clr_bus(i2c_dev_t *hw)
|
||||||
{
|
{
|
||||||
hw->scl_sp_conf.scl_rst_slv_num = 9;
|
hw->scl_sp_conf.scl_rst_slv_num = 9;
|
||||||
hw->scl_sp_conf.scl_rst_slv_en = 0;
|
|
||||||
hw->ctr.conf_upgate = 1;
|
|
||||||
hw->scl_sp_conf.scl_rst_slv_en = 1;
|
hw->scl_sp_conf.scl_rst_slv_en = 1;
|
||||||
|
hw->ctr.conf_upgate = 1;
|
||||||
|
// hardward will clear scl_rst_slv_en after sending SCL pulses,
|
||||||
|
// and we should set conf_upgate bit to synchronize register value.
|
||||||
|
while (hw->scl_sp_conf.scl_rst_slv_en);
|
||||||
|
hw->ctr.conf_upgate = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,25 +16,30 @@
|
|||||||
|
|
||||||
void i2c_hal_master_handle_tx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
|
void i2c_hal_master_handle_tx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
|
||||||
{
|
{
|
||||||
i2c_ll_master_get_event(hal->dev, event);
|
if (i2c_ll_get_intsts_mask(hal->dev) != 0) {
|
||||||
if ((*event < I2C_INTR_EVENT_END_DET) ||
|
// If intr status is 0, no need to handle it.
|
||||||
(*event == I2C_INTR_EVENT_TRANS_DONE)) {
|
i2c_ll_master_get_event(hal->dev, event);
|
||||||
i2c_ll_master_disable_tx_it(hal->dev);
|
if ((*event < I2C_INTR_EVENT_END_DET) ||
|
||||||
i2c_ll_master_clr_tx_it(hal->dev);
|
(*event == I2C_INTR_EVENT_TRANS_DONE)) {
|
||||||
} else if (*event == I2C_INTR_EVENT_END_DET) {
|
i2c_ll_master_disable_tx_it(hal->dev);
|
||||||
i2c_ll_master_clr_tx_it(hal->dev);
|
i2c_ll_master_clr_tx_it(hal->dev);
|
||||||
|
} else if (*event == I2C_INTR_EVENT_END_DET) {
|
||||||
|
i2c_ll_master_clr_tx_it(hal->dev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_hal_master_handle_rx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
|
void i2c_hal_master_handle_rx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
|
||||||
{
|
{
|
||||||
i2c_ll_master_get_event(hal->dev, event);
|
if (i2c_ll_get_intsts_mask(hal->dev) != 0) {
|
||||||
if ((*event < I2C_INTR_EVENT_END_DET) ||
|
i2c_ll_master_get_event(hal->dev, event);
|
||||||
(*event == I2C_INTR_EVENT_TRANS_DONE)) {
|
if ((*event < I2C_INTR_EVENT_END_DET) ||
|
||||||
i2c_ll_master_disable_rx_it(hal->dev);
|
(*event == I2C_INTR_EVENT_TRANS_DONE)) {
|
||||||
i2c_ll_master_clr_rx_it(hal->dev);
|
i2c_ll_master_disable_rx_it(hal->dev);
|
||||||
} else if (*event == I2C_INTR_EVENT_END_DET) {
|
i2c_ll_master_clr_rx_it(hal->dev);
|
||||||
i2c_ll_master_clr_rx_it(hal->dev);
|
} else if (*event == I2C_INTR_EVENT_END_DET) {
|
||||||
|
i2c_ll_master_clr_rx_it(hal->dev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user