Skip to content

adc_battery_estimation库中存在严重的共用体使用问题 (IDFGH-16549) (AEGHB-1249) #590

@zhiyoutech

Description

@zhiyoutech

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

所有版本

Espressif SoC revision.

ESP32S3

Operating System used.

Windows

How did you build your project?

Command line with Make

If you are using Windows, please specify command line type.

None

Development Kit.

Custom Board

Power Supply used.

USB

What is the expected behavior?

adc_battery_estimation_t结构体中定义了一个共用体,定义如下:
union {
struct {
adc_oneshot_unit_handle_t adc_handle; /*!< External ADC handle /
adc_cali_handle_t adc_cali_handle; /
!< External ADC calibration handle /
} external; /
!< Use external handles /
struct {
adc_unit_t adc_unit; /
!< ADC unit number /
adc_bitwidth_t adc_bitwidth; /
!< ADC bit width /
adc_atten_t adc_atten; /
!< ADC attenuation /
} internal; /
!< Create new ADC configuration */
};

当ESP32S3使用内部ADC2的时候,即adc_unit的值为0x01的时候,adc_handle也会被赋值为0x01。那么,在adc_battery_estimation_create函数中,执行到 以下判断时:

if (config->external.adc_handle != NULL && config->external.adc_cali_handle != NULL) {
ctx->adc_handle = config->external.adc_handle;
ctx->adc_cali_handle = config->external.adc_cali_handle;
ctx->is_adc_handle_owned = false;
}
默认会认为config->external.adc_handle != NULL && config->external.adc_cali_handle != NULL条件成立,从而不再执行else分支中的internal部分。此逻辑是错误的,因为开发者意图使用的是内部ADC2。

What is the actual behavior?

开发者意图使用ADC2,但是,adc_battery_estimation_create函数的执行逻辑确实外部ADC。

Steps to reproduce.

  1. Step
  2. Step
  3. Step
    ...

Debug Logs.


Diagnostic report archive.

No response

More Information.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions