From 4a410391cc7539fbcd686292778613267d1772c9 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 2 Jan 2023 15:40:11 +0100 Subject: [PATCH] ulp risc-v rtc i2c: Fix a bug where RTC I2C failed to initialize after esp_restart() This commit fixes a bug wherein the RTC I2C peripheral got stuck after the main CPU performs a soft reset by using esp_restart(). This is because the RTC domain config registers for the RTC I2C domain are not cleared after the soft restart and hence need to be cleared manually while initializing the RTC I2C peripheral again. Closes https://github.com/espressif/esp-idf/issues/10468 --- components/ulp/ulp_riscv/ulp_riscv_i2c.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/ulp/ulp_riscv/ulp_riscv_i2c.c b/components/ulp/ulp_riscv/ulp_riscv_i2c.c index 1f1234ed94..c682a20c18 100644 --- a/components/ulp/ulp_riscv/ulp_riscv_i2c.c +++ b/components/ulp/ulp_riscv/ulp_riscv_i2c.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -398,6 +398,10 @@ void ulp_riscv_i2c_master_write_to_device(uint8_t *data_wr, size_t size) esp_err_t ulp_riscv_i2c_master_init(const ulp_riscv_i2c_cfg_t *cfg) { + /* Clear any stale config registers */ + WRITE_PERI_REG(RTC_I2C_CTRL_REG, 0); + WRITE_PERI_REG(SENS_SAR_I2C_CTRL_REG, 0); + /* Reset RTC I2C */ #if CONFIG_IDF_TARGET_ESP32S2 i2c_dev->ctrl.i2c_reset = 1;