软件下载
- ESP32-S3-Zero没有板载USB转串口,无法实现自动下载。
- 下载软件时要按住Boot按键再上电,此时电脑会识别到一个USB模拟的COM口,可用于下载软件。
开发环境
编程环境是使用的esp-idf-4.4.2;
值得注意的是在此之前安装了esp-idf-5.0.2、esp-idf-5.1.2都不能正常使用,安装好后使用"idf.py set-target"没有效果,配置不了MCU型号,使用"idf.py menuconfig"会报错,打不开配置界面。出现这些错误的具体原因未知。
参考例程
参考例程是"tusb_console"
例程存储路径"ESP-IDF\Espressif\frameworks\esp-idf-v4.4.2\examples\peripherals\usb\tusb_console"
代码
/* USB 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.
*/
// DESCRIPTION:
// This example contains minimal code to make ESP32-S2 based device
// recognizable by USB-host devices as a USB Serial Device printing output from
// the application.
#include <stdio.h>
#include <stdlib.h>
#include <sys/reent.h>
#include "esp_log.h"
#include "esp_vfs.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "tinyusb.h"
#include "tusb_cdc_acm.h"
#include "tusb_console.h"
#include "sdkconfig.h"
#include "esp_err.h"
static const char *TAG = "Main";
static const char *TaskTAG = "Task1";
static void hello_task(void *arg)
{
static int cnt = 0;
ESP_LOGI(TaskTAG, "Enter hello task.");
while (1) {
if(cnt % 2){
ESP_LOGI(TaskTAG, "Even num.");
}
else{
ESP_LOGI(TaskTAG, "Odd num.");
}
if(cnt >= 0xFFFFFFFF){
cnt = 0;
}
else{
cnt++;
}
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
void app_main(void)
{
/* Setting TinyUSB up */
tinyusb_config_t tusb_cfg = { 0 }; // the configuration uses default values
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
tinyusb_config_cdcacm_t amc_cfg = { 0 }; // the configuration uses default values
ESP_ERROR_CHECK(tusb_cdc_acm_init(&amc_cfg));
esp_tusb_init_console(TINYUSB_CDC_ACM_0); // log to usb
vTaskDelay(2000 / portTICK_PERIOD_MS);
ESP_LOGI(TAG, "APP Version 1.00");
ESP_LOGI(TAG, "USB initialization DONE");
xTaskCreatePinnedToCore(hello_task, "stats", 4096, NULL, 3, NULL, tskNO_AFFINITY);/*启动hello_task*/
while (1) {
ESP_LOGI(TAG, "log -> USB");
vTaskDelay(1000 / portTICK_PERIOD_MS);
fprintf(stdout, "example: print -> stdout\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
fprintf(stderr, "example: print -> stderr\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
现象
-
软件下载完毕后,按下reset按键,电脑会重新识别USB模拟的串口,因此串口号可能会改变;
-
连接串口后,可以看到相应的打印信息;