ESP32-S3 DevKit C 每隔几秒就会出现一次简单代码错误

ESP32-S3 DevKit C Error Every Few Seconds with Simple Code

我是 运行 我的 ESP32 S3 DevKit C 上的一个简单程序,它只读取从 ADC 通道读取的数据并将它们打印到监视器。一切运行良好,但几秒钟后,读数被这个错误打断,然后它就不断重复自己。 (有趣的是错误发生在打印出整数766并拆分7和66的中间)。

这里是监视器读数:

2094, 767
2095, 767
2093, 767
2099, 7E (50298) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (50298) task_wdt:  - IDLE (CPU 0)
E (50298) task_wdt: Tasks currently running:
E (50298) task_wdt: CPU 0: main
E (50298) task_wdt: CPU 1: IDLE
E (50298) task_wdt: Print CPU 0 (current core) backtrace


Backtrace:0x42008262:0x3FC910C00x4037673A:0x3FC910E0 0x4200305A:0x3FCF4250 0x42003EB2:0x3FCF4280 0x42002A95:0x3FCF42A0 0x4200262F:0x3FCF42C0 0x4200A5E5:0x3FCF42E0 0x4201203E:0x3FCF4300 0x420120C6:0x3FCF4320 0x4200A015:0x3FCF4350 0x42015599:0x3FCF4380 0x42010DDF:0x3FCF43A0 0x4200A1B1:0x3FCF46B0 0x42005525:0x3FCF4700 0x42018315:0x3FCF4730 0x4037B759:0x3FCF4750
0x42008262: task_wdt_isr at C:/Espressif/frameworks/esp-idf-v4.4/components/esp_system/task_wdt.c:183 (discriminator 3)

0x4037673a: _xt_lowint1 at C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/xtensa/xtensa_vectors.S:1111

0x4200305a: uart_ll_get_txfifo_len at c:\espressif\frameworks\esp-idf-v4.4\projects\esi2022\build/../../../components/hal/esp32s3/include/hal/uart_ll.h:316 (discriminator 1)
 (inlined by) uart_tx_char at C:/Espressif/frameworks/esp-idf-v4.4/components/vfs/vfs_uart.c:156 (discriminator 1)

0x42003eb2: uart_write at C:/Espressif/frameworks/esp-idf-v4.4/components/vfs/vfs_uart.c:209

0x42002a95: console_write at C:/Espressif/frameworks/esp-idf-v4.4/components/vfs/vfs_console.c:73

0x4200262f: esp_vfs_write at C:/Espressif/frameworks/esp-idf-v4.4/components/vfs/vfs.c:431 (discriminator 4)

0x4200a5e5: __swrite at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/stdio.c:94

0x4201203e: __sflush_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/fflush.c:224

0x420120c6: _fflush_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/fflush.c:278

0x4200a015: __sfvwrite_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/fvwrite.c:251

0x42015599: __sprint_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/vfprintf.c:433
 (inlined by) __sprint_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/vfprintf.c:403

0x42010ddf: _vfprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/vfprintf.c:1781 (discriminator 1)

0x4200a1b1: printf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/printf.c:56 (discriminator 5)

0x42005525: app_main at c:\espressif\frameworks\esp-idf-v4.4\projects\esi2022\build/../main/hello_world_main.c:36 (discriminator 1)

0x42018315: main_task at C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/port_common.c:129 (discriminator 2)

0x4037b759: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/xtensa/port.c:131


E (50298) task_wdt: Print CPU 1 backtrace


Backtrace:0x40377C6D:0x3FC916C00x4037673A:0x3FC916E0 0x400559DD:0x3FCF56B0  |<-CORRUPTED
0x40377c6d: esp_crosscore_isr at C:/Espressif/frameworks/esp-idf-v4.4/components/esp_system/crosscore_int.c:92

0x4037673a: _xt_lowint1 at C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/xtensa/xtensa_vectors.S:1111


66
2207, 766
2092, 775
2095, 775
2095, 767
2093, 767
2093, 774
2095, 767

这是我的代码 运行:

/* This script creates a representative dataset of audio from the ESP32-S3
   
    TO RUN: >> idf.py set-target esp32s3
           >> idf.py -p COM3 -b 480600 flash monitor

    MAKE SURE SPI FLASH SIZE IS 8MB:
            >> idf.py menuconfig
            >> Serial Flasher Config >> Flash Size (8 MB)
            
*/
#include <stdio.h>
#include <driver/adc.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"

void app_main(void)
{   
    printf("Hello world!\n");

    /* Configure desired precision and attenuation for ADC pins
        Right Channel: GPIO 4 ADC1 Channel 3
        Left Channel: GPIO 11 ADC2 Channel 0                  */

    adc1_config_width(ADC_WIDTH_BIT_DEFAULT);
    adc1_config_channel_atten(ADC1_CHANNEL_3,ADC_ATTEN_DB_0);
    adc2_config_channel_atten(ADC2_CHANNEL_0,ADC_ATTEN_DB_0);
    
    int val2 = 0;
    int* pval2 = &val2;
    while(true){
        int val1 = adc1_get_raw(ADC1_CHANNEL_3);
        adc2_get_raw(ADC2_CHANNEL_0,ADC_WIDTH_BIT_DEFAULT,pval2);
        printf("%d, %d\n",val1,val2);
    }

如果有人知道为什么会发生这种情况,我将不胜感激。 谢谢!

通过整合vTaskDelay();进入 while(true) 循环,问题就解决了。 Dave M. 如果缓冲区填满得太快是正确的。这限制了进入缓冲区的数据量。 (见下面的评论)