|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
@@ -321,6 +321,7 @@ void ulp_riscv_i2c_master_read_from_device(uint8_t *data_rd, size_t size) |
321 | 321 | uint32_t i = 0; |
322 | 322 | uint32_t cmd_idx = 0; |
323 | 323 | esp_err_t ret = ESP_OK; |
| 324 | + uint32_t status = 0; |
324 | 325 |
|
325 | 326 | if (size == 0) { |
326 | 327 | // Quietly return |
@@ -379,17 +380,20 @@ void ulp_riscv_i2c_master_read_from_device(uint8_t *data_rd, size_t size) |
379 | 380 | /* Clear the Rx data interrupt bit */ |
380 | 381 | SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, RTC_I2C_RX_DATA_INT_CLR); |
381 | 382 | } else { |
382 | | - ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Read Failed!"); |
383 | | - uint32_t status = READ_PERI_REG(RTC_I2C_INT_RAW_REG); |
384 | | - ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status); |
385 | | - ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG)); |
| 383 | + status = READ_PERI_REG(RTC_I2C_INT_RAW_REG); |
386 | 384 | SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, status); |
387 | 385 | break; |
388 | 386 | } |
389 | 387 | } |
390 | 388 |
|
391 | 389 | portEXIT_CRITICAL(&rtc_i2c_lock); |
392 | 390 |
|
| 391 | + if (ret != ESP_OK) { |
| 392 | + ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Read Failed!"); |
| 393 | + ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status); |
| 394 | + ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG)); |
| 395 | + } |
| 396 | + |
393 | 397 | /* Clear the RTC I2C transmission bits */ |
394 | 398 | CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START_FORCE); |
395 | 399 | CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START); |
@@ -417,6 +421,7 @@ void ulp_riscv_i2c_master_write_to_device(uint8_t *data_wr, size_t size) |
417 | 421 | uint32_t i = 0; |
418 | 422 | uint32_t cmd_idx = 0; |
419 | 423 | esp_err_t ret = ESP_OK; |
| 424 | + uint32_t status = 0; |
420 | 425 |
|
421 | 426 | if (size == 0) { |
422 | 427 | // Quietly return |
@@ -455,17 +460,21 @@ void ulp_riscv_i2c_master_write_to_device(uint8_t *data_wr, size_t size) |
455 | 460 | /* Clear the Tx data interrupt bit */ |
456 | 461 | SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, RTC_I2C_TX_DATA_INT_CLR); |
457 | 462 | } else { |
458 | | - ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Write Failed!"); |
459 | | - uint32_t status = READ_PERI_REG(RTC_I2C_INT_RAW_REG); |
460 | | - ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status); |
461 | | - ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG)); |
| 463 | + status = READ_PERI_REG(RTC_I2C_INT_RAW_REG); |
462 | 464 | SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, status); |
463 | 465 | break; |
464 | 466 | } |
465 | 467 | } |
466 | 468 |
|
467 | 469 | portEXIT_CRITICAL(&rtc_i2c_lock); |
468 | 470 |
|
| 471 | + /* In case of error, print the status after critical section */ |
| 472 | + if (ret != ESP_OK) { |
| 473 | + ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Write Failed!"); |
| 474 | + ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status); |
| 475 | + ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG)); |
| 476 | + } |
| 477 | + |
469 | 478 | /* Clear the RTC I2C transmission bits */ |
470 | 479 | CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START_FORCE); |
471 | 480 | CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START); |
|
0 commit comments