pdf-icon

ESP-IDF 上手教程

CoreS3 ESP-IDF BSP 使用教程

本教程将介绍如何在 ESP-IDF 开发环境中集成 CoreS3 板级支持包(BSP),以便快速初始化和管理板载外设驱动,提升开发效率。

1.准备工作

  1. 环境配置: 本教程基于Ubuntu操作系统搭建ESP-IDF开发环境,其他平台的编译环境搭建方式,具体请参考ESP-IDF - ESP32-S3上手教程
ESP-IDF 版本
本教程推荐使用ESP-IDF版本v5.4.1
  1. 使用git版本管理工具拉取esp-idf项目,切换至指定分支并执行脚本安装相关工具链。
注意事项
. ./export.sh指令的"."与脚本之间有一个空格,该指令等同于source ./export.sh
git clone --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
git checkout v5.4.1 # recommend
./install.sh
. ./export.sh
  1. 后续教程使用到的idf.py指令均依赖ESP-IDF,运行指令前需要在项目工程路径下调用ESP-IDF中. ./export.sh用于激活相关的环境变量。详细说明请参考ESP-IDF - ESP32-S3上手教程

2.项目创建

  1. 打开终端并进入工作目录,创建项目文件夹cores3_projects。切换路径进入文件夹后,调用esp-idf项目中export.sh用于激活相关的环境变量。以下指令适用于项目文件夹cores3_projects与esp-idf处于同级目录,其他路径则需根据实际情况修改指令。执行以下idf.py create-project指令创建空白项目模板,演示的项目名为my_project
mkdir cores3_projects
cd cores3_projects
. ../esp-idf/export.sh
idf.py create-project my_project
  1. 切换路径进入项目工程,并使用 Espressif Component Registry 组件管理工具指令添加 M5Stack CoreS3 BSP
cd my_project
idf.py add-dependency "espressif/m5stack_core_s3^3.0.0"
  1. 设置编译目标芯片平台
idf.py set-target esp32s3
  1. 由于API兼容性问题,程序编译前需参考下方指令进入配置菜单Component config->Audio Codec Device Configuration,关闭向后兼容I2C Driver选项。
idf.py menuconfig

3.案例程序

  1. 打开空白模板的程序入口文件,并将下方案例程序内容复制到文件中。
vim main/my_project.c 
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "lv_demos.h"
#include "bsp/esp-bsp.h"
static char *TAG = "app_main";
#define LOG_MEM_INFO (0)
void app_main(void) {
/* Initialize display and LVGL */
bsp_display_start();
/* Set display brightness to 100% */
bsp_display_backlight_on();
ESP_LOGI(TAG, "Display LVGL demo");
bsp_display_lock(0);
lv_demo_widgets(); /* A widgets example */
// lv_demo_music(); /* A modern, smartphone-like music player demo. */
// lv_demo_stress(); /* A stress test for LVGL. */
// lv_demo_benchmark(); /* A demo to measure the performance of LVGL or
// to compare different settings. */
bsp_display_unlock();
}
  1. 该案例程序演示如何驱动屏幕显示LGVL组件案例,您还可以切换不同的案例注释来编译不同的显示案例。使用对应的案例组件前,请使用idf.py menuconfig进入配置菜单Component config->LVGL Configuration->Demos,启用对应的LGVL案例。

4.程序编译与烧录

  1. 长按设备复位按键(大约2秒)直到内部绿色LED灯亮起,便可松开,此时设备已进入下载模式,等待烧录。
  1. 执行以下指令进行程序编译与烧录。
idf.py flash
On This Page