Skip to content

Commit bdf4daf

Browse files
committed
fix(soc): Fix wrong efuse register on esp32c61
1 parent caf1a18 commit bdf4daf

File tree

12 files changed

+60
-89
lines changed

12 files changed

+60
-89
lines changed

components/esp_driver_tsens/src/temperature_sensor.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -22,7 +22,6 @@
2222
#include "clk_ctrl_os.h"
2323
#include "freertos/FreeRTOS.h"
2424
#include "driver/temperature_sensor.h"
25-
#include "esp_efuse_rtc_calib.h"
2625
#include "esp_private/periph_ctrl.h"
2726
#include "temperature_sensor_private.h"
2827
#include "hal/temperature_sensor_ll.h"
@@ -36,7 +35,7 @@
3635

3736
static const char *TAG = "temperature_sensor";
3837

39-
static float s_deltaT = NAN; // unused number
38+
static int s_deltaT = INT_MIN; // unused number
4039

4140
#if SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
4241
static int8_t s_temperature_regval_2_celsius(temperature_sensor_handle_t tsens, uint8_t regval);
@@ -274,19 +273,20 @@ esp_err_t temperature_sensor_disable(temperature_sensor_handle_t tsens)
274273

275274
static esp_err_t read_delta_t_from_efuse(void)
276275
{
277-
if (temperature_sensor_ll_calib_get_tsens_val(&s_deltaT) != true) {
278-
ESP_LOGW(TAG, "Calibration failed");
276+
s_deltaT = temperature_sensor_ll_load_calib_param();
277+
if (s_deltaT == 0) {
278+
ESP_LOGW(TAG, "No calibration param in eFuse");
279279
}
280-
ESP_LOGD(TAG, "s_deltaT = %f", s_deltaT);
280+
ESP_LOGD(TAG, "s_deltaT = %d", s_deltaT);
281281
return ESP_OK;
282282
}
283283

284284
static float parse_temp_sensor_raw_value(int16_t tsens_raw)
285285
{
286-
if (isnan(s_deltaT)) { //suggests that the value is not initialized
286+
if (s_deltaT == INT_MIN) { //suggests that the value is not initialized
287287
read_delta_t_from_efuse();
288288
}
289-
float result = tsens_raw - s_deltaT / 10.0;
289+
float result = tsens_raw - (float)s_deltaT / 10.0;
290290
return result;
291291
}
292292

components/hal/esp32c2/include/hal/temperature_sensor_ll.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,15 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
155155
/**
156156
* @brief Retrieve and calculate the temperature sensor calibration value.
157157
*
158-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
159-
* The output is a signed floating-point value based on the efuse data.
160-
*
161-
* @return returns true to indicate successful retrieval. false for calibration failed.
158+
* @return Temperature calibration value.
162159
*/
163-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
160+
static inline int temperature_sensor_ll_load_calib_param(void)
164161
{
165162
uint32_t cal_temp = 0;
166163
cal_temp = EFUSE.rd_blk2_data2.temp_calib;
167164
// BIT(8) stands for sign: 1: negative, 0: positive
168-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
169-
return true;
165+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
166+
return tsens_cal;
170167
}
171168

172169
#ifdef __cplusplus

components/hal/esp32c3/include/hal/temperature_sensor_ll.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,17 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
155155
/**
156156
* @brief Retrieve and calculate the temperature sensor calibration value.
157157
*
158-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
159-
* The output is a signed floating-point value based on the efuse data.
160-
*
161-
* @return returns true to indicate successful retrieval. false for calibration failed.
158+
* @return Temperature calibration value.
162159
*/
163-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
160+
static inline int temperature_sensor_ll_load_calib_param(void)
164161
{
165-
uint32_t version = efuse_ll_get_blk_version_major();
166-
if (version == 0) {
167-
*tsens_cal = 0.0;
168-
return ESP_ERR_NOT_SUPPORTED;
162+
if (efuse_ll_get_blk_version_major() == 0) {
163+
return 0;
169164
}
170-
171165
uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib;
172-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
173-
return ESP_OK;
166+
// BIT(8) stands for sign: 1: negative, 0: positive
167+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
168+
return tsens_cal;
174169
}
175170

176171
#ifdef __cplusplus

components/hal/esp32c5/include/hal/temperature_sensor_ll.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
270270
/**
271271
* @brief Retrieve and calculate the temperature sensor calibration value.
272272
*
273-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
274-
* The output is a signed floating-point value based on the efuse data.
275-
*
276-
* @return returns true to indicate successful retrieval. false for calibration failed.
273+
* @return Temperature calibration value.
277274
*/
278-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
275+
static inline int temperature_sensor_ll_load_calib_param(void)
279276
{
280277
uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temperature_sensor;
281-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
282-
return true;
278+
// BIT(8) stands for sign: 1: negative, 0: positive
279+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
280+
return tsens_cal;
283281
}
284282

285283
#ifdef __cplusplus

components/hal/esp32c6/include/hal/temperature_sensor_ll.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
270270
/**
271271
* @brief Retrieve and calculate the temperature sensor calibration value.
272272
*
273-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
274-
* The output is a signed floating-point value based on the efuse data.
275-
*
276-
* @return returns true to indicate successful retrieval. false for calibration failed.
273+
* @return Temperature calibration value.
277274
*/
278-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
275+
static inline int temperature_sensor_ll_load_calib_param(void)
279276
{
280277
uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib;
281-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
282-
return true;
278+
// BIT(8) stands for sign: 1: negative, 0: positive
279+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
280+
return tsens_cal;
283281
}
284282

285283
#ifdef __cplusplus

components/hal/esp32c61/include/hal/temperature_sensor_ll.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
270270
/**
271271
* @brief Retrieve and calculate the temperature sensor calibration value.
272272
*
273-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
274-
* The output is a signed floating-point value based on the efuse data.
275-
*
276-
* @return returns true to indicate successful retrieval. false for calibration failed.
273+
* @return Temperature calibration value.
277274
*/
278-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
275+
static inline int temperature_sensor_ll_load_calib_param(void)
279276
{
280277
uint32_t cal_temp = EFUSE0.rd_sys_part1_data4.temperature_sensor;
281-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
282-
return true;
278+
// BIT(8) stands for sign: 1: negative, 0: positive
279+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
280+
return tsens_cal;
283281
}
284282

285283
#ifdef __cplusplus

components/hal/esp32h2/include/hal/temperature_sensor_ll.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
269269
/**
270270
* @brief Retrieve and calculate the temperature sensor calibration value.
271271
*
272-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
273-
* The output is a signed floating-point value based on the efuse data.
274-
*
275-
* @return returns true to indicate successful retrieval. false for calibration failed.
272+
* @return Temperature calibration value.
276273
*/
277-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
274+
static inline int temperature_sensor_ll_load_calib_param(void)
278275
{
279276
uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib;
280-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
281-
return true;
277+
// BIT(8) stands for sign: 1: negative, 0: positive
278+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
279+
return tsens_cal;
282280
}
283281

284282
#ifdef __cplusplus

components/hal/esp32p4/include/hal/temperature_sensor_ll.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
262262
/**
263263
* @brief Retrieve and calculate the temperature sensor calibration value.
264264
*
265-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
266-
* The output is a signed floating-point value based on the efuse data.
267-
*
268-
* @return returns true to indicate successful retrieval. false for calibration failed.
265+
* @return Temperature calibration value.
269266
*/
270-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
267+
static inline int temperature_sensor_ll_load_calib_param(void)
271268
{
272269
uint32_t cal_temp = EFUSE.rd_sys_part2_data3.temperature_sensor;
273-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
274-
return true;
270+
// BIT(8) stands for sign: 1: negative, 0: positive
271+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
272+
return tsens_cal;
275273
}
276274

277275
#ifdef __cplusplus

components/hal/esp32s2/include/hal/temperature_sensor_ll.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,17 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
144144
/**
145145
* @brief Retrieve and calculate the temperature sensor calibration value.
146146
*
147-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
148-
* The output is a signed floating-point value based on the efuse data.
149-
*
150-
* @return returns true to indicate successful retrieval. false for calibration failed.
147+
* @return Temperature calibration value.
151148
*/
152-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
149+
static inline int temperature_sensor_ll_load_calib_param(void)
153150
{
154-
uint32_t version = efuse_ll_get_blk_version_major();
155-
if (version == 0) {
156-
*tsens_cal = 0.0;
157-
return false;
151+
if (efuse_ll_get_blk_version_major() == 0) {
152+
return 0;
158153
}
159-
160154
uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib;
161-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
162-
return true;
155+
// BIT(8) stands for sign: 1: negative, 0: positive
156+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
157+
return tsens_cal;
163158
}
164159

165160
#ifdef __cplusplus

components/hal/esp32s3/include/hal/temperature_sensor_ll.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,17 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
144144
/**
145145
* @brief Retrieve and calculate the temperature sensor calibration value.
146146
*
147-
* @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored.
148-
* The output is a signed floating-point value based on the efuse data.
149-
*
150-
* @return returns true to indicate successful retrieval. false for calibration failed.
147+
* @return Temperature calibration value.
151148
*/
152-
static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal)
149+
static inline int temperature_sensor_ll_load_calib_param(void)
153150
{
154-
uint32_t version = efuse_ll_get_blk_version_major();
155-
if (version == 0) {
156-
*tsens_cal = 0.0;
157-
return false;
151+
if (efuse_ll_get_blk_version_major() == 0) {
152+
return 0;
158153
}
159-
160154
uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib;
161-
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
162-
return true;
155+
// BIT(8) stands for sign: 1: negative, 0: positive
156+
int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
157+
return tsens_cal;
163158
}
164159

165160
#ifdef __cplusplus

0 commit comments

Comments
 (0)