簡體   English   中英

如何從 ESP32 的定時器回調中執行調試打印?

[英]How to execute debug print from within timer callback in ESP32?

我上周開始使用 ESP32,目前我正在嘗試將 BLE iBeacon 和 1 秒警報計時器的示例代碼放在一起。 我在運行程序時收到錯誤abort() was called at PC 0x403774b7 on core 0 0x403774b7: lock_acquire_generic at /home/boko/esp/esp-idf/components/newlib/locks.c:130 我在計時器回調timer_alarm_cb中有一個ESP_LOGI()語句,這似乎導致了問題,但我不知道為什么以及如何(如果我刪除該語句,程序工作正常)。 我想用代碼實現的是每 1 秒獲取一次調試打印作為視覺反饋,以便了解在 1 秒間隔內檢測到多少 iBeacon 和哪些 iBeacon。

所以,我的兩個問題是:

  1. 為什么定時器回調中的 ESP_LOGI() 語句會導致程序中止?
  2. 在 ESP32 中使用計時器每 1 秒獲取一次調試打印的正確方法是什么?

我的代碼是:

 * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Unlicense OR CC0-1.0
 */



/****************************************************************************
*
* This file is for iBeacon demo. It supports both iBeacon sender and receiver
* which is distinguished by macros IBEACON_SENDER and IBEACON_RECEIVER,
*
* iBeacon is a trademark of Apple Inc. Before building devices which use iBeacon technology,
* visit https://developer.apple.com/ibeacon/ to obtain a license.
*
****************************************************************************/

#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>

#include "nvs_flash.h"

#include "esp_bt.h"
#include "esp_gap_ble_api.h"
#include "esp_gattc_api.h"
#include "esp_gatt_defs.h"
#include "esp_bt_main.h"
#include "esp_bt_defs.h"
#include "esp_ibeacon_api.h"

#include "esp_log.h"

#include "freertos/FreeRTOS.h"  // If you include FreeRTOS.h before task.h then portmacro.h will be included for you (do not include portmacro.h manually, just include FreeRTOS.h). However, if you fail to include FreeRTOS.h before tasks.h, then your code will not build

// #include "freertos/task.h"  // BaseType_t

#include "driver/gptimer.h"

static const char* PROGRAM_NAME = "iBeacon2Omnicomm" ;  // "iBeacons-ESP32-Tracker-Server" ;  // "IBEACON_DEMO";
extern esp_ble_ibeacon_vendor_t vendor_config;

///Declare static functions
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);

#if (IBEACON_MODE == IBEACON_RECEIVER)
static esp_ble_scan_params_t ble_scan_params = {
    .scan_type              = BLE_SCAN_TYPE_ACTIVE,
    .own_addr_type          = BLE_ADDR_TYPE_PUBLIC,
    .scan_filter_policy     = BLE_SCAN_FILTER_ALLOW_ALL,
    .scan_interval          = 0x50,     // 50 ms scan interval, i.e. start scanning for BLE devices every 50 ms elapsed
    .scan_window            = 0x30,     // 30 ms scan duration, i.e. whenever a scan interval starts, keep scanning for 30 ms
    .scan_duplicate         = BLE_SCAN_DUPLICATE_DISABLE
};

#elif (IBEACON_MODE == IBEACON_SENDER)
static esp_ble_adv_params_t ble_adv_params = {
    .adv_int_min        = 0x20,
    .adv_int_max        = 0x40,
    .adv_type           = ADV_TYPE_NONCONN_IND,
    .own_addr_type      = BLE_ADDR_TYPE_PUBLIC,
    .channel_map        = ADV_CHNL_ALL,
    .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};
#endif


static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{
    esp_err_t err;

    switch (event) {
    case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:{
#if (IBEACON_MODE == IBEACON_SENDER)
        esp_ble_gap_start_advertising(&ble_adv_params);
#endif
        break;
    }
    case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
#if (IBEACON_MODE == IBEACON_RECEIVER)
        //the unit of the duration is second, 0 means scan permanently
        uint32_t duration = 0;
        ESP_LOGI(PROGRAM_NAME, "starting a scan == calling esp_ble_gap_start_scanning()");
        esp_ble_gap_start_scanning(duration);
#endif
        break;
    }
    case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
        //scan start complete event to indicate scan start successfully or failed
        if ((err = param->scan_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
            ESP_LOGE(PROGRAM_NAME, "Scan start failed: %s", esp_err_to_name(err));
        } else {
            ESP_LOGI(PROGRAM_NAME, "Scan start successful");
        }
        break;
    case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
        //adv start complete event to indicate adv start successfully or failed
        if ((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
            ESP_LOGE(PROGRAM_NAME, "Adv start failed: %s", esp_err_to_name(err));
        }
        break;
    case ESP_GAP_BLE_SCAN_RESULT_EVT: {
        esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;  // make a local copy of the passed address of parameters
        switch (scan_result->scan_rst.search_evt) {
        case ESP_GAP_SEARCH_INQ_RES_EVT:
            /* Search for BLE iBeacon Packet */
            if (esp_ble_is_ibeacon_packet(scan_result->scan_rst.ble_adv, scan_result->scan_rst.adv_data_len)){
                esp_ble_ibeacon_t *ibeacon_data = (esp_ble_ibeacon_t*)(scan_result->scan_rst.ble_adv);
                
                // ESP_LOGI("iBeacon Found:");  // error: macro "ESP_LOGI" requires 3 arguments, but only 1 given
                ESP_LOGI(PROGRAM_NAME, "iBeacon Found ==========");
                
                esp_log_buffer_hex("MAC address:", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN );
                
                esp_log_buffer_hex("UUID:", ibeacon_data->ibeacon_vendor.proximity_uuid, ESP_UUID_LEN_128);

                uint16_t major = ENDIAN_CHANGE_U16(ibeacon_data->ibeacon_vendor.major);
                uint16_t minor = ENDIAN_CHANGE_U16(ibeacon_data->ibeacon_vendor.minor);
                
                ESP_LOGI(PROGRAM_NAME, "Major: 0x%04x (%d)", major, major);
                ESP_LOGI(PROGRAM_NAME, "Minor: 0x%04x (%d)", minor, minor);
                
                //ESP_LOGI(PROGRAM_NAME, "Measured power (RSSI at a 1m distance):%d dbm", ibeacon_data->ibeacon_vendor.measured_power);
                
                ESP_LOGI(PROGRAM_NAME, "RSSI:%d dbm", scan_result->scan_rst.rssi);
            }
            break;
        default:
            break;
        }
        break;
    }

    case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
        if ((err = param->scan_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
            ESP_LOGE(PROGRAM_NAME, "Scan stop failed: %s", esp_err_to_name(err));
        }
        else {
            ESP_LOGI(PROGRAM_NAME, "Stop scan successfully");
        }
        break;

    case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
        if ((err = param->adv_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
            ESP_LOGE(PROGRAM_NAME, "Adv stop failed: %s", esp_err_to_name(err));
        }
        else {
            ESP_LOGI(PROGRAM_NAME, "Stop adv successfully");
        }
        break;

    default:
        break;
    }
}


void ble_ibeacon_appRegister(void)
{
    esp_err_t status;

    ESP_LOGI(PROGRAM_NAME, "registering callback == calling esp_ble_gap_register_callback()");

    //register the scan callback function to the gap module:
    if ((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
        ESP_LOGE(PROGRAM_NAME, "gap register error: %s", esp_err_to_name(status));
        return;
    } else {
        ESP_LOGI(PROGRAM_NAME, "successful");
    }

}

void ble_ibeacon_init(void)
{
    esp_bluedroid_init();
    esp_bluedroid_enable();
    ble_ibeacon_appRegister();
}

//## BaseType_t timerOverflow = pdFALSE;
// IRAM_ATTR: Forces code into IRAM instead of flash
static bool IRAM_ATTR timer_alarm_cb ( gptimer_handle_t timer, const gptimer_alarm_event_data_t * edata, void * user_data ) {    // == ISR on timer overflow event
    /*
    BaseType_t high_task_awoken = pdFALSE;
    QueueHandle_t queue = (QueueHandle_t) user_data;
    // Retrieve count value and send to queue
    example_queue_element_t ele = {
        .event_count = edata->count_value
    };
    xQueueSendFromISR(queue, &ele, &high_task_awoken);
    // return whether we need to yield at the end of ISR
    return (high_task_awoken == pdTRUE);
    */

    //## timerOverflow = pdTRUE ;    // #define pdTRUE ( ( BaseType_t ) 1 )  --> typedef portBASE_TYPE BaseType_t; --> #define portBASE_TYPE int

    ESP_LOGI(PROGRAM_NAME, "1 s elapsed");

    // @return Whether a high priority task has been waken up by this function:
    return pdFALSE ;
}
// if prototype declared as "static bool IRAM_ATTR ..." --> error: no return statement in function returning non-void [-Werror=return-type]


void app_main(void) {
    ESP_ERROR_CHECK(nvs_flash_init());

    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));

    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    esp_bt_controller_init(&bt_cfg);
    esp_bt_controller_enable(ESP_BT_MODE_BLE);

    ble_ibeacon_init();

    /* set scan parameters */
#if (IBEACON_MODE == IBEACON_RECEIVER)
    ESP_LOGI(PROGRAM_NAME, "setting RECEIVER scan parameters == calling esp_ble_gap_set_scan_params()");
    esp_ble_gap_set_scan_params(&ble_scan_params);

#elif (IBEACON_MODE == IBEACON_SENDER)
    esp_ble_ibeacon_t ibeacon_adv_data;
    esp_err_t status = esp_ble_config_ibeacon_data (&vendor_config, &ibeacon_adv_data);
    if (status == ESP_OK){
        esp_ble_gap_config_adv_data_raw((uint8_t*)&ibeacon_adv_data, sizeof(ibeacon_adv_data));
    }
    else {
        ESP_LOGE(PROGRAM_NAME, "Config iBeacon data failed: %s\n", esp_err_to_name(status));
    }
#endif

    // Creating a GPTimer Handle with Resolution (frequency) of 1 MHz:
    ESP_LOGI(PROGRAM_NAME, "Creating new timer (handle)");
    gptimer_handle_t gptimer = NULL;
    gptimer_config_t timer_config = {
        .clk_src = GPTIMER_CLK_SRC_DEFAULT,
        .direction = GPTIMER_COUNT_UP,
        .resolution_hz = 1 * 1000 * 1000,   // 1MHz, 1 tick = 1us
    };
    ESP_ERROR_CHECK(gptimer_new_timer(&timer_config, &gptimer));
    
    // Prepare Triggering of Periodic Events (set up the alarm action before starting the timer !) every 1 sec:
    ESP_LOGI(PROGRAM_NAME, "Setting alarm action");

    gptimer_alarm_config_t alarm_config = {
        .reload_count = 0,                  // counter will reload with 0 on alarm event
        .alarm_count = 1000000,             // period = 1s @resolution 1MHz
        .flags.auto_reload_on_alarm = true, // enable auto-reload
    };
    ESP_ERROR_CHECK(gptimer_set_alarm_action(gptimer, &alarm_config));

    ESP_LOGI(PROGRAM_NAME, "Registering callback function to execute on alarm event");
    gptimer_event_callbacks_t cbs = {
        .on_alarm = timer_alarm_cb, // register user callback
    };
    ESP_ERROR_CHECK(gptimer_register_event_callbacks(gptimer, &cbs, NULL));

    ESP_ERROR_CHECK(gptimer_enable(gptimer));

    ESP_LOGI(PROGRAM_NAME, "Starting timer");
    ESP_ERROR_CHECK(gptimer_start(gptimer));

    /*
    while ( 1 ) {
        if ( timerOverflow ) {
            timerOverflow = pdFALSE ;
            ESP_LOGI(PROGRAM_NAME, "1 s elapsed");
        }
    }
    */
}

示例終端 output 是:

/home/boko/.espressif/python_env/idf5.1_py3.10_envboko@boko-HP-EliteBook-850-G8-Notebook-PC:~/Desktop/ESP32/ble_ibeacon$ export IDF_PATH=/home/boko/esp/esp-idf
boko@boko-HP-EliteBook-850-G8-Notebook-PC:~/Desktop/ESP32/ble_ibeacon$ /home/boko/.espressif/python_env/idf5.1_py3.10_env/bin/python /home/boko/esp/esp-idf/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32s3-elf- --target esp32s3 /home/boko/Desktop/ESP32/ble_ibeacon/build/ble_ibeacon_demo.elf
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
) UUID:: fd a5�ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3810,len:0x16ac
load:0x403c9700,len:0xbc8
load:0x403cc700,len:0x2d64
entry 0x403c98fc
I (25) boot: ESP-IDF v5.1-dev-1626-g4b6d9c8ad3 2nd stage bootloader
I (25) boot: compile time Nov 11 2022 16:57:52
I (25) boot: chip revision: V001
I (29) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (36) boot.esp32s3: Boot SPI Speed : 80MHz
I (41) boot.esp32s3: SPI Mode       : DIO
I (46) boot.esp32s3: SPI Flash Size : 2MB
I (51) boot: Enabling RNG early entropy source...
I (56) boot: Partition Table:
I (60) boot: ## Label            Usage          Type ST Offset   Length
I (67) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (74) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (82) boot:  2 factory          factory app      00 00 00010000 00100000
I (89) boot: End of partition table
I (93) boot_comm: chip revision: 1, min. application chip revision: 0
I (101) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=1e524h (124196) map
I (131) esp_image: segment 1: paddr=0002e54c vaddr=3fc96a00 size=01acch (  6860) load
I (133) esp_image: segment 2: paddr=00030020 vaddr=42000020 size=7514ch (479564) map
I (223) esp_image: segment 3: paddr=000a5174 vaddr=3fc984cc size=02484h (  9348) load
I (225) esp_image: segment 4: paddr=000a7600 vaddr=40374000 size=12998h ( 76184) load
I (253) boot: Loaded app from partition at offset 0x10000
I (253) boot: Disabling RNG early entropy source...
I (265) cpu_start: Pro cpu up.
I (265) cpu_start: Starting app cpu, entry point is 0x403753cc
0x403753cc: call_start_cpu1 at /home/boko/esp/esp-idf/components/esp_system/port/cpu_start.c:146

I (0) cpu_start: App cpu up.
I (279) cpu_start: Pro cpu start user code
I (279) cpu_start: cpu freq: 160000000 Hz
I (280) cpu_start: Application information:
I (282) cpu_start: Project name:     ble_ibeacon_demo
I (288) cpu_start: App version:      1
I (293) cpu_start: Compile time:     Nov 11 2022 16:57:45
I (299) cpu_start: ELF file SHA256:  2432859c4fe13f02...
I (305) cpu_start: ESP-IDF:          v5.1-dev-1626-g4b6d9c8ad3
I (311) heap_init: Initializing. RAM available for dynamic allocation:
I (318) heap_init: At 3FC9E8F8 len 0004AE18 (299 KiB): D/IRAM
I (325) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (332) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (338) heap_init: At 600FE010 len 00001FF0 (7 KiB): RTCRAM
I (345) spi_flash: detected chip: generic
I (349) spi_flash: flash io: dio
W (353) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (366) coexist: coexist rom version e7ae62f
I (371) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (415) BT_INIT: BT controller compile version [76c24c9]
I (415) phy_init: phy_version 503,13653eb,Jun  1 2022,17:47:08
I (455) system_api: Base MAC address is not set
I (455) system_api: read default base MAC address from EFUSE
I (455) BT_INIT: Bluetooth MAC: 7c:df:a1:e3:55:fa

I (485) iBeacon2Omnicomm: registering callback == calling esp_ble_gap_register_callback()
I (485) iBeacon2Omnicomm: successful
I (485) iBeacon2Omnicomm: setting RECEIVER scan parameters == calling esp_ble_gap_set_scan_params()
I (495) iBeacon2Omnicomm: starting a scan == calling esp_ble_gap_start_scanning()
I (505) iBeacon2Omnicomm: Scan start successful
I (505) iBeacon2Omnicomm: Creating new timer (handle)
I (515) iBeacon2Omnicomm: Setting alarm action
I (515) iBeacon2Omnicomm: Registering callback function to execute on alarm event
I (525) iBeacon2Omnicomm: Starting timer
I (755) iBeacon2Omnicomm: iBeacon Found ==========
I (755) MAC address:: ac 23 3f a8 c3 a8 
I (755) UUID:: fd a5 06 93 a4 e2 4f b1 af cf c6 eb 07 64 78 25 
I (765) iBeacon2Omnicomm: Major: 0x08ae (2222)
I (765) iBeacon2Omnicomm: Minor: 0x08ae (2222)
I (775) iBeacon2Omnicomm: RSSI:-48 dbm
I (805) iBeacon2Omnicomm: iBeacon Found ==========
I (805) MAC address:: ac 23 3f a8 c3 a8 
I (805) UUID:: fd a5 06 93 a4 e2 4f b1 af cf c6 eb 07 64 78 25 
I (805) iBeacon2Omnicomm: Major: 0x04d2 (1234)
I (815) iBeacon2Omnicomm: Minor: 0x269e (9886)
I (815) iBeacon2Omnicomm: RSSI:-43 dbm

abort() was called at PC 0x403774b7 on core 0
0x403774b7: lock_acquire_generic at /home/boko/esp/esp-idf/components/newlib/locks.c:130



Backtrace: 0x40375ebe:0x3fc979f0 0x4037ec61:0x3fc97a10 0x403846a6:0x3fc97a30 0x403774b7:0x3fc97aa0 0x403775cd:0x3fc97ad0 0x4037769c:0x3fc97af0 0x420653c1:0x3fc97b20 0x42068505:0x3fc97e30 0x42075151:0x3fc97e60 0x40384555:0x3fc97e90 0x40377b75:0x3fc97ee0 0x40379d85:0x3fc97f00 0x40377295:0x3fc97f30 0x4037d8a7:0x3fcf3fb0 0x42003bc2:0x3fcf3fd0 0x40380151:0x3fcf3ff0 0x4038195d:0x3fcf4010
0x40375ebe: panic_abort at /home/boko/esp/esp-idf/components/esp_system/panic.c:423

0x4037ec61: esp_system_abort at /home/boko/esp/esp-idf/components/esp_system/esp_system.c:135

0x403846a6: abort at /home/boko/esp/esp-idf/components/newlib/abort.c:38

0x403774b7: lock_acquire_generic at /home/boko/esp/esp-idf/components/newlib/locks.c:130

0x403775cd: _lock_acquire_recursive at /home/boko/esp/esp-idf/components/newlib/locks.c:158

0x4037769c: __retarget_lock_acquire_recursive at /home/boko/esp/esp-idf/components/newlib/locks.c:314 (discriminator 3)

0x420653c1: _vfprintf_r at ??:?

0x42068505: vprintf at /builds/idf/crosstool-NG/.build/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/vprintf.c:34 (discriminator 5)

0x42075151: esp_log_writev at /home/boko/esp/esp-idf/components/log/log.c:200

0x40384555: esp_log_write at /home/boko/esp/esp-idf/components/log/log.c:210

0x40377b75: timer_alarm_cb at /home/boko/Desktop/ESP32/ble_ibeacon/main/ibeacon_demo.c:200

0x40379d85: gptimer_default_isr at /home/boko/esp/esp-idf/components/driver/gptimer.c:512

0x40377295: _xt_lowint1 at /home/boko/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1118

0x4037d8a7: xt_utils_wait_for_intr at /home/boko/esp/esp-idf/components/xtensa/include/xt_utils.h:81
 (inlined by) esp_cpu_wait_for_intr at /home/boko/esp/esp-idf/components/esp_hw_support/cpu.c:115

0x42003bc2: esp_vApplicationIdleHook at /home/boko/esp/esp-idf/components/esp_system/freertos_hooks.c:59

0x40380151: prvIdleTask at /home/boko/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4273 (discriminator 1)

0x4038195d: vPortTaskWrapper at /home/boko/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:152





ELF file SHA256: 2432859c4fe13f02

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4037585c
0x4037585c: esp_restart_noos_dig at /home/boko/esp/esp-idf/components/esp_system/esp_system.c:46 (discriminator 1)

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3810,len:0x16ac
load:0x403c9700,len:0xbc8
load:0x403cc700,len:0x2d64
entry 0x403c98fc
I (29) boot: ESP-IDF v5.1-dev-1626-g4b6d9c8ad3 2nd stage bootloader
I (29) boot: compile time Nov 11 2022 16:57:52
I (30) boot: chip revision: V001
I (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot.esp32s3: Boot SPI Speed : 80MHz
I (46) boot.esp32s3: SPI Mode       : DIO
I (50) boot.esp32s3: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (79) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (86) boot:  2 factory          factory app      00 00 00010000 00100000
I (94) boot: End of partition table
I (98) boot_comm: chip revision: 1, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=1e524h (124196) map
I (136) esp_image: segment 1: paddr=0002e54c vaddr=3fc96a00 size=01acch (  6860) load
I (138) esp_image: segment 2: paddr=00030020 vaddr=42000020 size=7514ch (479564) map
I (228) esp_image: segment 3: paddr=000a5174 vaddr=3fc984cc size=02484h (  9348) load
I (230) esp_image: segment 4: paddr=000a7600 vaddr=40374000 size=12998h ( 76184) load
I (258) boot: Loaded app from partition at offset 0x10000
I (258) boot: Disabling RNG early entropy source...
I (269) cpu_start: Pro cpu up.
I (269) cpu_start: Starting app cpu, entry point is 0x403753cc
0x403753cc: call_start_cpu1 at /home/boko/esp/esp-idf/components/esp_system/port/cpu_start.c:146

I (0) cpu_start: App cpu up.
I (284) cpu_start: Pro cpu start user code
I (284) cpu_start: cpu freq: 160000000 Hz
I (284) cpu_start: Application information:
I (287) cpu_start: Project name:     ble_ibeacon_demo
I (293) cpu_start: App version:      1
I (297) cpu_start: Compile time:     Nov 11 2022 16:57:45
I (303) cpu_start: ELF file SHA256:  2432859c4fe13f02...
I (309) cpu_start: ESP-IDF:          v5.1-dev-1626-g4b6d9c8ad3
I (316) heap_init: Initializing. RAM available for dynamic allocation:
I (323) heap_init: At 3FC9E8F8 len 0004AE18 (299 KiB): D/IRAM
I (329) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (336) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (342) heap_init: At 600FE010 len 00001FF0 (7 KiB): RTCRAM
I (349) spi_flash: detected chip: generic
I (353) spi_flash: flash io: dio
W (357) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (371) coexist: coexist rom version e7ae62f
I (375) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (420) BT_INIT: BT controller compile version [76c24c9]
I (420) phy_init: phy_version 503,13653eb,Jun  1 2022,17:47:08
I (460) system_api: Base MAC address is not set
I (460) system_api: read default base MAC address from EFUSE
I (460) BT_INIT: Bluetooth MAC: 7c:df:a1:e3:55:fa

I (490) iBeacon2Omnicomm: registering callback == calling esp_ble_gap_register_callback()
I (490) iBeacon2Omnicomm: successful
I (490) iBeacon2Omnicomm: setting RECEIVER scan parameters == calling esp_ble_gap_set_scan_params()
I (500) iBeacon2Omnicomm: starting a scan == calling esp_ble_gap_start_scanning()
I (510) iBeacon2Omnicomm: Scan start successful
I (510) iBeacon2Omnicomm: Creating new timer (handle)
I (520) iBeacon2Omnicomm: Setting alarm action
I (520) iBeacon2Omnicomm: Registering callback function to execute on alarm event
I (530) iBeacon2Omnicomm: Starting timer
I (580) iBeacon2Omnicomm: iBeacon Found ==========
I (580) MAC address:: ac 23 3f a8 c3 a8 
I (580) UUID:: fd a5 06 93 a4 e2 4f b1 af cf c6 eb 07 64 78 25 
I (590) iBeacon2Omnicomm: Major: 0x2711 (10001)
I (590) iBeacon2Omnicomm: Minor: 0x4cb9 (19641)
I (600) iBeacon2Omnicomm: RSSI:-37 dbm
I (1220) iBeacon2Omnicomm: iBeacon Found ==========
I (1220) MAC address:: ac 23 3f a8 c3 a8 
I (1220) UUID:: fd a5 06 93 a4 e2 4f b1 af cf c6 eb 07 64 78 25 
I (1230) iBeacon2Omnicomm: Major: 0x04d2 (1234)
I (1230) iBeacon2Omnicomm: Minor: 0x269e (9886)
I (1240) iBeacon2Omnicomm: RSSI:-51 dbm

abort() was called at PC 0x403774b7 on core 0
0x403774b7: lock_acquire_generic at /home/boko/esp/esp-idf/components/newlib/locks.c:130



Backtrace: 0x40375ebe:0x3fc979f0 0x4037ec61:0x3fc97a10 0x403846a6:0x3fc97a30 0x403774b7:0x3fc97aa0 0x403775cd:0x3fc97ad0 0x4037769c:0x3fc97af0 0x420653c1:0x3fc97b20 0x42068505:0x3fc97e30 0x42075151:0x3fc97e60 0x40384555:0x3fc97e90 0x40377b75:0x3fc97ee0 0x40379d85:0x3fc97f00 0x40377295:0x3fc97f30 0x4037d8a7:0x3fcf3fb0 0x42003bc2:0x3fcf3fd0 0x40380151:0x3fcf3ff0 0x4038195d:0x3fcf4010
0x40375ebe: panic_abort at /home/boko/esp/esp-idf/components/esp_system/panic.c:423

0x4037ec61: esp_system_abort at /home/boko/esp/esp-idf/components/esp_system/esp_system.c:135

0x403846a6: abort at /home/boko/esp/esp-idf/components/newlib/abort.c:38

0x403774b7: lock_acquire_generic at /home/boko/esp/esp-idf/components/newlib/locks.c:130

0x403775cd: _lock_acquire_recursive at /home/boko/esp/esp-idf/components/newlib/locks.c:158

0x4037769c: __retarget_lock_acquire_recursive at /home/boko/esp/esp-idf/components/newlib/locks.c:314 (discriminator 3)

0x420653c1: _vfprintf_r at ??:?

0x42068505: vprintf at /builds/idf/crosstool-NG/.build/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/vprintf.c:34 (discriminator 5)

0x42075151: esp_log_writev at /home/boko/esp/esp-idf/components/log/log.c:200

0x40384555: esp_log_write at /home/boko/esp/esp-idf/components/log/log.c:210

0x40377b75: timer_alarm_cb at /home/boko/Desktop/ESP32/ble_ibeacon/main/ibeacon_demo.c:200

0x40379d85: gptimer_default_isr at /home/boko/esp/esp-idf/components/driver/gptimer.c:512

0x40377295: _xt_lowint1 at /home/boko/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1118

0x4037d8a7: xt_utils_wait_for_intr at /home/boko/esp/esp-idf/components/xtensa/include/xt_utils.h:81
 (inlined by) esp_cpu_wait_for_intr at /home/boko/esp/esp-idf/components/esp_hw_support/cpu.c:115

0x42003bc2: esp_vApplicationIdleHook at /home/boko/esp/esp-idf/components/esp_system/freertos_hooks.c:59

0x40380151: prvIdleTask at /home/boko/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4273 (discriminator 1)

0x4038195d: vPortTaskWrapper at /home/boko/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:152

您正在嘗試從通用定時器中斷中登錄。 引用日志庫的文檔

不應從中斷中使用此 function 或這些宏。

一位 Espressif 開發人員也發表了一篇更長的評論來解釋原因。 似乎還有另一個宏ESP_DRAM_LOGE用於從中斷中打印(這通常不是一個好主意)。

不管怎樣,除了最嚴格的實時標准之外,我建議使用高分辨率定時器 它仍然在硬件定時器外設之上運行,但回調的處理被推遲到一個專用的定時器任務(是的,你必須等待一小段時間,直到調度程序開始執行該任務)。 這意味着您的回調在常規任務中運行並且可以調用日志記錄函數。 不要 go 過火 - 您仍然希望延遲計時器回調相當快以避免時間抖動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM