我的Beetle ESP32-C3开发板在烧写正常的烧写完程序后就失去了JTAG串口,导致无法使用。从新拔插开发板,可以听到提示音,但是无法识别设备,但是设备工作正常。
可以ping通设备
故障过程的控制台输出,
G:\eeworld\esp32c3\test\mqtt\tcp>idf.py -p COM11 flash
Executing action: flash
Running ninja in directory G:\eeworld\esp32c3\test\mqtt\tcp\build
Executing "ninja flash"...
[1/5] cmd.exe /C "cd /D G:\eeworld\esp32c3\test\mqtt\tcp\b...e.bin G:/eeworld/esp32c3/test/mqtt/tcp/build/mqtt_tcp.bin"
mqtt_tcp.bin binary size 0xe6bd0 bytes. Smallest app partition is 0x100000 bytes. 0x19430 bytes (10%) free.
[1/1] cmd.exe /C "cd /D G:\eeworld\esp32c3\test\mqtt\tcp\b...rld/esp32c3/test/mqtt/tcp/build/bootloader/bootloader.bin"
Bootloader binary size 0x5170 bytes. 0x2e90 bytes (36%) free.
[2/3] cmd.exe /C "cd /D C:\Espressif\frameworks\esp-idf-v5...00 mqtt_tcp.bin 0x8000 partition_table/partition-table.bin
esptool.py v4.7.0
Serial port COM11
Connecting...
Chip is ESP32-C3 (QFN32) (revision v0.3)
Features: WiFi, BLE, Embedded Flash 4MB (XMC)
Crystal is 40MHz
MAC: 84:f7:03:a7:96:38
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00005fff...
Flash will be erased from 0x00010000 to 0x000f6fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Compressed 20848 bytes to 12752...
Writing at 0x00000000... (100 %)
Wrote 20848 bytes (12752 compressed) at 0x00000000 in 0.4 seconds (effective 452.7 kbit/s)...
Hash of data verified.
Compressed 945104 bytes to 545594...
Writing at 0x00010000... (2 %)
Writing at 0x0001dda2... (5 %)
Writing at 0x00027554... (8 %)
Writing at 0x0002c3be... (11 %)
Writing at 0x0003455e... (14 %)
Writing at 0x0003c643... (17 %)
Writing at 0x00042baf... (20 %)
Writing at 0x0004a111... (23 %)
Writing at 0x00051afa... (26 %)
Writing at 0x00058bcf... (29 %)
Writing at 0x0005fd95... (32 %)
Writing at 0x000661ae... (35 %)
Writing at 0x0006cabd... (38 %)
Writing at 0x000735da... (41 %)
Writing at 0x00079b8f... (44 %)
Writing at 0x000800e3... (47 %)
Writing at 0x0008612a... (50 %)
Writing at 0x0008c203... (52 %)
Writing at 0x00092071... (55 %)
Writing at 0x000983ce... (58 %)
Writing at 0x0009e91a... (61 %)
Writing at 0x000a487f... (64 %)
Writing at 0x000ab583... (67 %)
Writing at 0x000b23e3... (70 %)
Writing at 0x000b9435... (73 %)
Writing at 0x000c0607... (76 %)
Writing at 0x000c6c67... (79 %)
Writing at 0x000ccb1d... (82 %)
Writing at 0x000d326a... (85 %)
Writing at 0x000d91d8... (88 %)
Writing at 0x000df6ab... (91 %)
Writing at 0x000e7812... (94 %)
Writing at 0x000ee3ae... (97 %)
Writing at 0x000f4aac... (100 %)
Wrote 945104 bytes (545594 compressed) at 0x00010000 in 7.5 seconds (effective 1007.1 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 394.0 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
ool_py && C:\Espressif\tools\cmake\3.24.0\bin\cmake.exe -D IDF_PATH=C:/Espressif/frameworks/esp-idf-v5.2.1 -D SERIAL_TOOL=C:/Espressif/python_env/idf5.2_py3.11_env/Scripts/python.exe;;C:/Espressif/frameworks/esp-idf-v5.2.1/components/esptool_py/esptool/esptool.py;--chip;esp32c3 -D SERIAL_TOOL_ARGS=--before=default_reset;--after=hard_reset;write_flash;@flash_args -D WORKING_DIRECTORY=G:/eeworld/esp32c3/test/mqtt/tcp/build -P C:/Espressif/frameworks/esp-idf-v5.2.1/components/esptool_py/run_serial_tool.cmake"
Done
G:\eeworld\esp32c3\test\mqtt\tcp>idf.py -p COM11 monitor
Executing action: monitor
Running idf_monitor in directory G:\eeworld\esp32c3\test\mqtt\tcp
Executing "C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe C:\Espressif\frameworks\esp-idf-v5.2.1\tools/idf_monitor.py -p COM11 -b 115200 --toolchain-prefix riscv32-esp-elf- --target esp32c3 --revision 3 --decode-panic backtrace G:\eeworld\esp32c3\test\mqtt\tcp\build\mqtt_tcp.elf --force-color -m 'C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe' 'C:\Espressif\frameworks\esp-idf-v5.2.1\tools\idf.py' '-p' 'COM11'"...
--- WARNING: GDB cannot open serial ports accessed as COMx
--- Using \\.\COM11 instead...
--- esp-idf-monitor 1.4.0 on \\.\COM11 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
could not open port '\\\\.\\COM11': FileNotFoundError(2, '系统找不到指定的文件。', None, 2)
Connection to \\.\COM11 failed. Available ports:
COM1
COM3
引起故障的程序代码,GPIO_OUTPUT_0和GPIO_OUTPUT_1的配置是我加的。
menu "Example Configuration"
config BROKER_URL
string "Broker URL"
default "mqtt://mqtt.eclipseprojects.io"
help
URL of the broker to connect to
config BROKER_URL_FROM_STDIN
bool
default y if BROKER_URL = "FROM_STDIN"
config GPIO_OUTPUT_0
int "GPIO output pin 0"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 8 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
default 18
help
GPIO pin number to be used as GPIO_OUTPUT_IO_0.
config GPIO_OUTPUT_1
int "GPIO output pin 1"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 9 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
default 19
help
GPIO pin number to be used as GPIO_OUTPUT_IO_1.
endmenu
主程序的代码,程序中的GPIO部分是我增加的,参考代码是:MQTT->TCP例程。
/* MQTT (over TCP) Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "protocol_examples_common.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "lwip/sockets.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"
#include "esp_log.h"
#include "mqtt_client.h"
#include "driver/gpio.h"
#define GPIO_OUTPUT_IO_0 CONFIG_GPIO_OUTPUT_0
#define GPIO_OUTPUT_IO_1 CONFIG_GPIO_OUTPUT_1
#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_OUTPUT_IO_0) | (1ULL<<GPIO_OUTPUT_IO_1))
static const char *TAG = "mqtt_example";
static void log_error_if_nonzero(const char *message, int error_code)
{
if (error_code != 0) {
ESP_LOGE(TAG, "Last error %s: 0x%x", message, error_code);
}
}
/*
* [url=home.php?mod=space&uid=159083]@brief[/url] Event handler registered to receive MQTT events
*
* This function is called by the MQTT client event loop.
*
* @param handler_args user data registered to the event.
* @param base Event base for the handler(always MQTT Base in this example).
* @param event_id The id for the received event.
* @param event_data The data for the event, esp_mqtt_event_handle_t.
*/
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32 "", base, event_id);
esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client;
int msg_id;
switch ((esp_mqtt_event_id_t)event_id) {
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "data_3", 0, 1, 0);
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1");
ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
break;
case MQTT_EVENT_ERROR:
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) {
log_error_if_nonzero("reported from esp-tls", event->error_handle->esp_tls_last_esp_err);
log_error_if_nonzero("reported from tls stack", event->error_handle->esp_tls_stack_err);
log_error_if_nonzero("captured as transport's socket errno", event->error_handle->esp_transport_sock_errno);
ESP_LOGI(TAG, "Last errno string (%s)", strerror(event->error_handle->esp_transport_sock_errno));
}
break;
default:
ESP_LOGI(TAG, "Other event id:%d", event->event_id);
break;
}
}
static void mqtt_app_start(void)
{
esp_mqtt_client_config_t mqtt_cfg = {
.broker.address.uri = CONFIG_BROKER_URL,
};
#if CONFIG_BROKER_URL_FROM_STDIN
char line[128];
if (strcmp(mqtt_cfg.broker.address.uri, "FROM_STDIN") == 0) {
int count = 0;
printf("Please enter url of mqtt broker\n");
while (count < 128) {
int c = fgetc(stdin);
if (c == '\n') {
line[count] = '\0';
break;
} else if (c > 0 && c < 127) {
line[count] = c;
++count;
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
mqtt_cfg.broker.address.uri = line;
printf("Broker url: %s\n", line);
} else {
ESP_LOGE(TAG, "Configuration mismatch: wrong broker url");
abort();
}
#endif /* CONFIG_BROKER_URL_FROM_STDIN */
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
/* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
esp_mqtt_client_start(client);
}
void app_main(void)
{
//zero-initialize the config structure.
gpio_config_t io_conf = {};
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO);
esp_log_level_set("mqtt_client", ESP_LOG_VERBOSE);
esp_log_level_set("mqtt_example", ESP_LOG_VERBOSE);
esp_log_level_set("transport_base", ESP_LOG_VERBOSE);
esp_log_level_set("esp-tls", ESP_LOG_VERBOSE);
esp_log_level_set("transport", ESP_LOG_VERBOSE);
esp_log_level_set("outbox", ESP_LOG_VERBOSE);
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());
mqtt_app_start();
}
曾试图将rst引脚接地拔插设备。故障不能回复。
|