Merge branch 'bugfix/reset_periph_modules_v4.0' into 'release/v4.0'
driver: Add a reset before enabling if a module is off (v4.0) See merge request espressif/esp-idf!6015
This commit is contained in:
commit
ecdffe531e
6 changed files with 40 additions and 24 deletions
|
@ -677,6 +677,7 @@ esp_err_t can_driver_install(const can_general_config_t *g_config, const can_tim
|
||||||
ret = ESP_ERR_INVALID_STATE;
|
ret = ESP_ERR_INVALID_STATE;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
periph_module_reset(PERIPH_CAN_MODULE);
|
||||||
periph_module_enable(PERIPH_CAN_MODULE); //Enable APB CLK to CAN peripheral
|
periph_module_enable(PERIPH_CAN_MODULE); //Enable APB CLK to CAN peripheral
|
||||||
configASSERT(can_enter_reset_mode() == ESP_OK); //Must enter reset mode to write to config registers
|
configASSERT(can_enter_reset_mode() == ESP_OK); //Must enter reset mode to write to config registers
|
||||||
can_config_pelican(); //Use PeliCAN addresses
|
can_config_pelican(); //Use PeliCAN addresses
|
||||||
|
|
|
@ -886,12 +886,6 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co
|
||||||
I2S_CHECK(!((i2s_config->mode & I2S_MODE_DAC_BUILT_IN) && (i2s_num != I2S_NUM_0)), "I2S DAC built-in only support on I2S0", ESP_ERR_INVALID_ARG);
|
I2S_CHECK(!((i2s_config->mode & I2S_MODE_DAC_BUILT_IN) && (i2s_num != I2S_NUM_0)), "I2S DAC built-in only support on I2S0", ESP_ERR_INVALID_ARG);
|
||||||
I2S_CHECK(!((i2s_config->mode & I2S_MODE_PDM) && (i2s_num != I2S_NUM_0)), "I2S DAC PDM only support on I2S0", ESP_ERR_INVALID_ARG);
|
I2S_CHECK(!((i2s_config->mode & I2S_MODE_PDM) && (i2s_num != I2S_NUM_0)), "I2S DAC PDM only support on I2S0", ESP_ERR_INVALID_ARG);
|
||||||
|
|
||||||
if (i2s_num == I2S_NUM_1) {
|
|
||||||
periph_module_enable(PERIPH_I2S1_MODULE);
|
|
||||||
} else {
|
|
||||||
periph_module_enable(PERIPH_I2S0_MODULE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i2s_config->mode & I2S_MODE_ADC_BUILT_IN) {
|
if(i2s_config->mode & I2S_MODE_ADC_BUILT_IN) {
|
||||||
//in ADC built-in mode, we need to call i2s_set_adc_mode to
|
//in ADC built-in mode, we need to call i2s_set_adc_mode to
|
||||||
//initialize the specific ADC channel.
|
//initialize the specific ADC channel.
|
||||||
|
@ -1099,8 +1093,10 @@ esp_err_t i2s_driver_install(i2s_port_t i2s_num, const i2s_config_t *i2s_config,
|
||||||
|
|
||||||
//To make sure hardware is enabled before any hardware register operations.
|
//To make sure hardware is enabled before any hardware register operations.
|
||||||
if (i2s_num == I2S_NUM_1) {
|
if (i2s_num == I2S_NUM_1) {
|
||||||
|
periph_module_reset(PERIPH_I2S1_MODULE);
|
||||||
periph_module_enable(PERIPH_I2S1_MODULE);
|
periph_module_enable(PERIPH_I2S1_MODULE);
|
||||||
} else {
|
} else {
|
||||||
|
periph_module_reset(PERIPH_I2S0_MODULE);
|
||||||
periph_module_enable(PERIPH_I2S0_MODULE);
|
periph_module_enable(PERIPH_I2S0_MODULE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,11 @@ esp_err_t pcnt_unit_config(const pcnt_config_t *pcnt_config)
|
||||||
PCNT_CHECK((pcnt_config->pos_mode < PCNT_COUNT_MAX) && (pcnt_config->neg_mode < PCNT_COUNT_MAX), PCNT_COUNT_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
PCNT_CHECK((pcnt_config->pos_mode < PCNT_COUNT_MAX) && (pcnt_config->neg_mode < PCNT_COUNT_MAX), PCNT_COUNT_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||||
PCNT_CHECK((pcnt_config->hctrl_mode < PCNT_MODE_MAX) && (pcnt_config->lctrl_mode < PCNT_MODE_MAX), PCNT_CTRL_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
PCNT_CHECK((pcnt_config->hctrl_mode < PCNT_MODE_MAX) && (pcnt_config->lctrl_mode < PCNT_MODE_MAX), PCNT_CTRL_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||||
/*Enalbe hardware module*/
|
/*Enalbe hardware module*/
|
||||||
|
static bool pcnt_enable = false;
|
||||||
|
if (pcnt_enable == false) {
|
||||||
|
periph_module_reset(PERIPH_PCNT_MODULE);
|
||||||
|
pcnt_enable = true;
|
||||||
|
}
|
||||||
periph_module_enable(PERIPH_PCNT_MODULE);
|
periph_module_enable(PERIPH_PCNT_MODULE);
|
||||||
/*Set counter range*/
|
/*Set counter range*/
|
||||||
pcnt_set_event_value(unit, PCNT_EVT_H_LIM, pcnt_config->counter_h_lim);
|
pcnt_set_event_value(unit, PCNT_EVT_H_LIM, pcnt_config->counter_h_lim);
|
||||||
|
|
|
@ -424,6 +424,11 @@ esp_err_t rmt_config(const rmt_config_t* rmt_param)
|
||||||
RMT_CHECK((!carrier_en || carrier_freq_hz > 0), "RMT carrier frequency can't be zero", ESP_ERR_INVALID_ARG);
|
RMT_CHECK((!carrier_en || carrier_freq_hz > 0), "RMT carrier frequency can't be zero", ESP_ERR_INVALID_ARG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool rmt_enable = false;
|
||||||
|
if (rmt_enable == false) {
|
||||||
|
periph_module_reset(PERIPH_RMT_MODULE);
|
||||||
|
rmt_enable = true;
|
||||||
|
}
|
||||||
periph_module_enable(PERIPH_RMT_MODULE);
|
periph_module_enable(PERIPH_RMT_MODULE);
|
||||||
|
|
||||||
RMT.conf_ch[channel].conf0.div_cnt = clk_div;
|
RMT.conf_ch[channel].conf0.div_cnt = clk_div;
|
||||||
|
|
|
@ -222,6 +222,7 @@ esp_err_t sdmmc_host_init()
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
periph_module_reset(PERIPH_SDMMC_MODULE);
|
||||||
periph_module_enable(PERIPH_SDMMC_MODULE);
|
periph_module_enable(PERIPH_SDMMC_MODULE);
|
||||||
|
|
||||||
// Enable clock to peripheral. Use smallest divider first.
|
// Enable clock to peripheral. Use smallest divider first.
|
||||||
|
|
|
@ -665,20 +665,35 @@ esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num)
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static periph_module_t get_periph_module(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
periph_module_t periph_module = PERIPH_UART0_MODULE;
|
||||||
|
if (uart_num == UART_NUM_0) {
|
||||||
|
periph_module = PERIPH_UART0_MODULE;
|
||||||
|
} else if (uart_num == UART_NUM_1) {
|
||||||
|
periph_module = PERIPH_UART1_MODULE;
|
||||||
|
}
|
||||||
|
#if SOC_UART_NUM > 2
|
||||||
|
else if (uart_num == UART_NUM_2) {
|
||||||
|
periph_module = PERIPH_UART2_MODULE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else {
|
||||||
|
assert(0 && "uart_num error");
|
||||||
|
}
|
||||||
|
return periph_module;
|
||||||
|
}
|
||||||
|
|
||||||
esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config)
|
esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config)
|
||||||
{
|
{
|
||||||
esp_err_t r;
|
esp_err_t r;
|
||||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
||||||
UART_CHECK((uart_config), "param null", ESP_FAIL);
|
UART_CHECK((uart_config), "param null", ESP_FAIL);
|
||||||
if(uart_num == UART_NUM_0) {
|
periph_module_t periph_module = get_periph_module(uart_num);
|
||||||
periph_module_enable(PERIPH_UART0_MODULE);
|
if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM) {
|
||||||
} else if(uart_num == UART_NUM_1) {
|
periph_module_reset(periph_module);
|
||||||
periph_module_enable(PERIPH_UART1_MODULE);
|
|
||||||
#if UART_NUM > 2
|
|
||||||
} else if(uart_num == UART_NUM_2) {
|
|
||||||
periph_module_enable(PERIPH_UART2_MODULE);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
periph_module_enable(periph_module);
|
||||||
r = uart_set_hw_flow_ctrl(uart_num, uart_config->flow_ctrl, uart_config->rx_flow_ctrl_thresh);
|
r = uart_set_hw_flow_ctrl(uart_num, uart_config->flow_ctrl, uart_config->rx_flow_ctrl_thresh);
|
||||||
if (r != ESP_OK) return r;
|
if (r != ESP_OK) return r;
|
||||||
|
|
||||||
|
@ -1463,16 +1478,9 @@ esp_err_t uart_driver_delete(uart_port_t uart_num)
|
||||||
free(p_uart_obj[uart_num]);
|
free(p_uart_obj[uart_num]);
|
||||||
p_uart_obj[uart_num] = NULL;
|
p_uart_obj[uart_num] = NULL;
|
||||||
|
|
||||||
if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM ) {
|
if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM) {
|
||||||
if(uart_num == UART_NUM_0) {
|
periph_module_t periph_module = get_periph_module(uart_num);
|
||||||
periph_module_disable(PERIPH_UART0_MODULE);
|
periph_module_disable(periph_module);
|
||||||
} else if(uart_num == UART_NUM_1) {
|
|
||||||
periph_module_disable(PERIPH_UART1_MODULE);
|
|
||||||
#if UART_NUM > 2
|
|
||||||
} else if(uart_num == UART_NUM_2) {
|
|
||||||
periph_module_disable(PERIPH_UART2_MODULE);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue