Skip to content

Commit

Permalink
adc: update adc calibration efuse version
Browse files Browse the repository at this point in the history
ADC calibration scheme and algorithm are not changed. Only the eFuse bit BLOCK1_VERSION is changed. This MR updated the logic to recognize the adc efuse version
  • Loading branch information
Icarus113 authored and dskulina committed Feb 5, 2022
1 parent 8936091 commit 61a65f3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 41 deletions.
15 changes: 5 additions & 10 deletions components/efuse/esp32s3/esp_efuse_rtc_calib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@

int esp_efuse_rtc_calib_get_ver(void)
{
uint32_t blk1_version = 0;
uint32_t blk2_version = 0;
ESP_ERROR_CHECK(esp_efuse_read_field_blob(ESP_EFUSE_BLOCK1_VERSION, &blk1_version, ESP_EFUSE_BLOCK1_VERSION[0]->bit_count));
ESP_ERROR_CHECK(esp_efuse_read_field_blob(ESP_EFUSE_BLOCK2_VERSION, &blk2_version, ESP_EFUSE_BLOCK2_VERSION[0]->bit_count));
uint32_t blk_ver_major = 0;
ESP_ERROR_CHECK(esp_efuse_read_field_blob(ESP_EFUSE_BLK_VER_MAJOR, &blk_ver_major, ESP_EFUSE_BLK_VER_MAJOR[0]->bit_count));

if (blk1_version == blk2_version) {
return blk1_version;
} else {
blk1_version = 0;
blk2_version = 0;
uint32_t cali_version_v1 = (blk_ver_major == 1) ? 1 : 0;
if (!cali_version_v1) {
ESP_LOGW("eFuse", "calibration efuse version does not match, set default version: %d", 0);
}

return blk2_version;
return cali_version_v1;
}

uint16_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int atten)
Expand Down
18 changes: 9 additions & 9 deletions components/efuse/esp32s3/esp_efuse_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <assert.h>
#include "esp_efuse_table.h"

// md5_digest_table ee5142bc489eee22230a49b5c7cafe00
// md5_digest_table 9444b887379d924049af42806ca71d45
// This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY.
// If you want to change some fields, you need to change esp_efuse_table.csv file
// then run `efuse_common_table` or `efuse_custom_table` command it will generate this file.
Expand Down Expand Up @@ -412,8 +412,8 @@ static const esp_efuse_desc_t PKG_VERSION[] = {
{EFUSE_BLK1, 117, 3}, // Package version,
};

static const esp_efuse_desc_t BLOCK1_VERSION[] = {
{EFUSE_BLK1, 120, 3}, // BLOCK1 efuse version 0:No calibration 1:With calibration,
static const esp_efuse_desc_t BLK_VER_MINOR[] = {
{EFUSE_BLK1, 120, 3}, // BLK_VERSION_MINOR,
};

static const esp_efuse_desc_t ADC2_CAL_VOL_ATTEN3[] = {
Expand All @@ -424,8 +424,8 @@ static const esp_efuse_desc_t OPTIONAL_UNIQUE_ID[] = {
{EFUSE_BLK2, 0, 128}, // Optional unique 128-bit ID,
};

static const esp_efuse_desc_t BLOCK2_VERSION[] = {
{EFUSE_BLK2, 128, 4}, // Version of BLOCK2,
static const esp_efuse_desc_t BLK_VER_MAJOR[] = {
{EFUSE_BLK2, 128, 2}, // BLK_VERSION_MAJOR,
};

static const esp_efuse_desc_t TEMP_CALIB[] = {
Expand Down Expand Up @@ -1031,8 +1031,8 @@ const esp_efuse_desc_t* ESP_EFUSE_PKG_VERSION[] = {
NULL
};

const esp_efuse_desc_t* ESP_EFUSE_BLOCK1_VERSION[] = {
&BLOCK1_VERSION[0], // BLOCK1 efuse version 0:No calibration 1:With calibration
const esp_efuse_desc_t* ESP_EFUSE_BLK_VER_MINOR[] = {
&BLK_VER_MINOR[0], // BLK_VERSION_MINOR
NULL
};

Expand All @@ -1046,8 +1046,8 @@ const esp_efuse_desc_t* ESP_EFUSE_OPTIONAL_UNIQUE_ID[] = {
NULL
};

const esp_efuse_desc_t* ESP_EFUSE_BLOCK2_VERSION[] = {
&BLOCK2_VERSION[0], // Version of BLOCK2
const esp_efuse_desc_t* ESP_EFUSE_BLK_VER_MAJOR[] = {
&BLK_VER_MAJOR[0], // BLK_VERSION_MAJOR
NULL
};

Expand Down
4 changes: 2 additions & 2 deletions components/efuse/esp32s3/esp_efuse_table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@
SPI_PAD_CONFIG_D7, EFUSE_BLK1, 108, 6, SPI_PAD_configure D7
WAFER_VERSION, EFUSE_BLK1, 114, 3, WAFER version 0:A
PKG_VERSION, EFUSE_BLK1, 117, 3, Package version
BLOCK1_VERSION, EFUSE_BLK1, 120, 3, BLOCK1 efuse version 0:No calibration 1:With calibration
BLK_VER_MINOR, EFUSE_BLK1, 120, 3, BLK_VERSION_MINOR, won't influence users
ADC2_CAL_VOL_ATTEN3, EFUSE_BLK1, 186, 6, ADC2 calibration voltage at atten3

# SYS_DATA_PART1 BLOCK# - System configuration
#######################
OPTIONAL_UNIQUE_ID, EFUSE_BLK2, 0, 128, Optional unique 128-bit ID
BLOCK2_VERSION, EFUSE_BLK2, 128, 4, Version of BLOCK2
BLK_VER_MAJOR, EFUSE_BLK2, 128, 2, BLK_VERSION_MAJOR, change of this bit means users need to update firmware
TEMP_CALIB, EFUSE_BLK2, 132, 9, Temperature calibration data
OCODE, EFUSE_BLK2, 141, 8, ADC OCode
ADC1_INIT_CODE_ATTEN0, EFUSE_BLK2, 149, 8, ADC1 init code at atten0
Expand Down
6 changes: 3 additions & 3 deletions components/efuse/esp32s3/include/esp_efuse_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {
#endif


// md5_digest_table ee5142bc489eee22230a49b5c7cafe00
// md5_digest_table 9444b887379d924049af42806ca71d45
// This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY.
// If you want to change some fields, you need to change esp_efuse_table.csv file
// then run `efuse_common_table` or `efuse_custom_table` command it will generate this file.
Expand Down Expand Up @@ -114,10 +114,10 @@ extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D6[];
extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D7[];
extern const esp_efuse_desc_t* ESP_EFUSE_WAFER_VERSION[];
extern const esp_efuse_desc_t* ESP_EFUSE_PKG_VERSION[];
extern const esp_efuse_desc_t* ESP_EFUSE_BLOCK1_VERSION[];
extern const esp_efuse_desc_t* ESP_EFUSE_BLK_VER_MINOR[];
extern const esp_efuse_desc_t* ESP_EFUSE_ADC2_CAL_VOL_ATTEN3[];
extern const esp_efuse_desc_t* ESP_EFUSE_OPTIONAL_UNIQUE_ID[];
extern const esp_efuse_desc_t* ESP_EFUSE_BLOCK2_VERSION[];
extern const esp_efuse_desc_t* ESP_EFUSE_BLK_VER_MAJOR[];
extern const esp_efuse_desc_t* ESP_EFUSE_TEMP_CALIB[];
extern const esp_efuse_desc_t* ESP_EFUSE_OCODE[];
extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN0[];
Expand Down
26 changes: 9 additions & 17 deletions components/esp_hw_support/port/esp32s3/rtc_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,17 @@ void rtc_init(rtc_config_t cfg)
REGI2C_WRITE_MASK(I2C_DIG_REG, I2C_DIG_REG_EXT_RTC_DREG, RTC_CNTL_DBIAS_1V10);

if (cfg.cali_ocode) {
uint32_t blk1_version = 0;
uint32_t blk2_version = 0;
esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_BLOCK1_VERSION, &blk1_version, 3);
uint32_t blk_ver_major = 0;
esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_BLK_VER_MAJOR, &blk_ver_major, ESP_EFUSE_BLK_VER_MAJOR[0]->bit_count);
if (err != ESP_OK) {
blk1_version = 0;
SOC_LOGW(TAG, "efuse read fail, set default blk1_version: %d\n", blk1_version);
blk_ver_major = 0;
SOC_LOGW(TAG, "efuse read fail, set default blk_ver_major: %d\n", blk_ver_major);
}
err = esp_efuse_read_field_blob(ESP_EFUSE_BLOCK2_VERSION, &blk2_version, 4);
if (err != ESP_OK) {
blk2_version = 0;
SOC_LOGW(TAG, "efuse read fail, set default blk2_version: %d\n", blk2_version);
}
if (blk1_version != blk2_version) {
blk1_version = 0;
blk2_version = 0;
SOC_LOGW(TAG, "calibration efuse version does not match, set default version: %d\n", 0);
}
if (blk2_version == 1) {
set_ocode_by_efuse(blk2_version);

//default blk_ver_major will fallback to using the self-calibration way for OCode
bool ocode_efuse_cali = (blk_ver_major == 1);
if (ocode_efuse_cali) {
set_ocode_by_efuse(blk_ver_major);
} else {
calibrate_ocode();
}
Expand Down

0 comments on commit 61a65f3

Please sign in to comment.