从模板生成项目
我们目前维护了两个模板仓库:
esp-generate
-no_std
模板。esp-idf-template
-std
模板。
esp-generate
esp-generate
is project generation tool that can be used to generate an application with all the required configurations and dependencies
-
Install
esp-generate
:cargo install esp-generate
-
Generate a project based on the template, selecting the chip and the name of the project:
esp-generate --chip=esp32c6 your-project
See Understanding
esp-generate
for more details on the template project.When the
esp-generate
subcommand is invoked, you will be prompted with a TUI where you can select the configuration of your application. Upon completion of this process, you will have a buildable project with all the correct configurations. -
Build/Run the generated project:
- Use
cargo build
to compile the project using the appropriate toolchain and target. - Use
cargo run
to compile the project, flash it, and open a serial monitor with our target device.
- Use
esp-idf-template
esp-idf-template
is based on cargo-generate
, a tool that allows you to create a new project based on some existing template. In our case, esp-idf-template
can be used to generate an application with all the required configurations and dependencies.
-
安装
cargo generate
:cargo install cargo-generate
-
Generate a project based on the template:
cargo generate esp-rs/esp-idf-template cargo
See Understanding
esp-idf-template
for more details on the template project.调用
cargo generate
子命令时,它会询问几个关于应用程序目标的问题。完成这些问题后,就会生成一个配置好的项目,可以直接构建。 -
构建/运行生成的项目:
- 用
cargo build
编译项目(自动使用合适的工具链和目标)。 - 用
cargo run
编译项目、向目标设备烧写程序、并开启一个串口监视器。
- 用
在模板中使用开发容器(Dev Container)
两个模板仓库都带有开发容器支持。
开发容器使用 idf-rust
镜像,配置开发环境中的使用容器一节对此进行了解释。这个镜像提供了一个无需安装即可为乐鑫芯片开发 Rust 应用程序的环境。开发容器还可以与 Wokwi 模拟器协作,以模拟项目,并允许使用 web-flash
从容器中进行烧写。