rust:rust_on_esp_install

ESP32 Rust 開発環境のインストール

Rust 関連 - インストール も参照…🤔
Fedora での手順

$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/tomoyan/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/tomoyan/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /home/tomoyan/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/tomoyan/.profile
  /home/tomoyan/.bash_profile
  /home/tomoyan/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
> Enter で続行

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2022-12-15, rust version 1.66.0 (69f9c33d7 2022-12-12)
info: downloading component 'cargo'
  6.5 MiB /   6.5 MiB (100 %)   1.2 MiB/s in  5s ETA:  0s
info: downloading component 'clippy'
  2.9 MiB /   2.9 MiB (100 %)   2.3 MiB/s in  1s ETA:  0s
info: downloading component 'rust-docs'
 19.0 MiB /  19.0 MiB (100 %)   1.7 MiB/s in 12s ETA:  0s
info: downloading component 'rust-std'
 29.7 MiB /  29.7 MiB (100 %)   1.9 MiB/s in 17s ETA:  0s
info: downloading component 'rustc'
 68.0 MiB /  68.0 MiB (100 %)   1.5 MiB/s in 45s ETA:  0s    
info: downloading component 'rustfmt'
  4.4 MiB /   4.4 MiB (100 %)   1.0 MiB/s in  4s ETA:  0s
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 19.0 MiB /  19.0 MiB (100 %)   5.5 MiB/s in  3s ETA:  0s
info: installing component 'rust-std'
 29.7 MiB /  29.7 MiB (100 %)   8.6 MiB/s in  3s ETA:  0s
info: installing component 'rustc'
 68.0 MiB /  68.0 MiB (100 %)   9.0 MiB/s in  7s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.66.0 (69f9c33d7 2022-12-12)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"

$ echo 'source $HOME/.cargo/env' >> ~/.bashrc
$ . ~/.bashrc
$ rustup --version

rustup 1.27.0 (bbb9276d2 2024-03-08)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.77.2 (25ef9e3d8 2024-04-09)`

$ rustc --version

rustc 1.77.2 (25ef9e3d8 2024-04-09)

$ cargo --version

cargo 1.77.2 (e52e36006 2024-03-26)

$ which rustup rustc cargo

~/.cargo/bin/rustup
~/.cargo/bin/rustc
~/.cargo/bin/cargo

参考: Linux - GitHub - esp-rs/espup: Tool for installing and maintaining ESP Rust ecosystem. 翻訳
Fedora での手順

$ sudo dnf install -y git python3 python3-pip perl gcc systemd-devel

メタデータの期限切れの最終確認: 0:57:25 前の 2024年05月06日 07時28分16秒 に実施しました。
依存関係が解決しました。
==============================================================================================================
 パッケージ                  アーキテクチャー     バージョン                      リポジトリー          サイズ
==============================================================================================================
インストール:
 gcc                         x86_64               14.0.1-0.15.fc40                fedora                 37 M
 git                         x86_64               2.45.0-1.fc40                   updates                53 k
 perl                        x86_64               4:5.38.2-506.fc40               fedora                 14 k
 python3                     x86_64               3.12.3-2.fc40                   updates                27 k
 python3-pip                 noarch               23.3.2-1.fc40                   fedora                3.2 M
 systemd-devel               x86_64               255.4-1.fc40                    fedora                651 k

トランザクションの概要
==============================================================================================================

ダウンロードサイズの合計: 41 M
インストール後のサイズ: 119 M
パッケージのダウンロード:
(1/6): perl-5.38.2-506.fc40.x86_64.rpm                                         33 kB/s |  14 kB     00:00    
(2/6): python3-pip-23.3.2-1.fc40.noarch.rpm                                   1.7 MB/s | 3.2 MB     00:01    
(3/6): git-2.45.0-1.fc40.x86_64.rpm                                            13 kB/s |  53 kB     00:03    
(4/6): systemd-devel-255.4-1.fc40.x86_64.rpm                                  114 kB/s | 651 kB     00:05    
(5/6): python3-3.12.3-2.fc40.x86_64.rpm                                       6.1 kB/s |  27 kB     00:04    
(6/6): gcc-14.0.1-0.15.fc40.x86_64.rpm                                        2.7 MB/s |  37 MB     00:13    
--------------------------------------------------------------------------------------------------------------
合計                                                                          2.6 MB/s |  41 MB     00:15     
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                      1/1 
  インストール中   : python3-3.12.3-2.fc40.x86_64                                                        1/12 
  インストール中   : python3-pip-23.3.2-1.fc40.noarch                                                    2/12 
  インストール中   : git-2.45.0-1.fc40.x86_64                                                            3/12 
  インストール中   : systemd-devel-255.4-1.fc40.x86_64                                                   4/12 
  インストール中   : perl-4:5.38.2-506.fc40.x86_64                                                       5/12 
  インストール中   : gcc-14.0.1-0.15.fc40.x86_64                                                         6/12 
  scriptletの実行中: gcc-14.0.1-0.15.fc40.x86_64                                                         6/12 
  整理             : python3-pip-23.3.2-1.fc40.noarch                                                    7/12 
  整理             : git-2.45.0-1.fc40.x86_64                                                            8/12 
  整理             : systemd-devel-255.4-1.fc40.x86_64                                                   9/12 
  整理             : perl-4:5.38.2-506.fc40.x86_64                                                      10/12 
  整理             : python3-3.12.3-2.fc40.x86_64                                                       11/12 
  整理             : gcc-14.0.1-0.15.fc40.x86_64                                                        12/12 
  scriptletの実行中: gcc-14.0.1-0.15.fc40.x86_64                                                        12/12 

インストール済み:
  gcc-14.0.1-0.15.fc40.x86_64      git-2.45.0-1.fc40.x86_64             perl-4:5.38.2-506.fc40.x86_64        
  python3-3.12.3-2.fc40.x86_64     python3-pip-23.3.2-1.fc40.noarch     systemd-devel-255.4-1.fc40.x86_64    

完了しました!

公式: 1. Install espup - RISC-V and Xtensa targets - The Rust on ESP Book 翻訳
公式: Installation - GitHub - esp-rs/espup: Tool for installing and maintaining ESP Rust ecosystem. 翻訳

cargo でビルドせずにバイナリをインストールする場合🤔

$ curl -L https://github.com/esp-rs/espup/releases/latest/download/espup-x86_64-unknown-linux-gnu -o espup

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100 10.2M  100 10.2M    0     0   672k      0  0:00:15  0:00:15 --:--:-- 1003k

$ chmod a+x espup

または、cargo でビルドを行ってインストールする🤔

$ cargo install espup

    Updating crates.io index
  Downloaded espup v0.11.0
  Downloaded 1 crate (44.6 KB) in 0.52s
  Installing espup v0.11.0
    Updating crates.io index
  Downloaded anstream v0.6.14
  Downloaded autocfg v1.3.0
  Downloaded anstyle-query v1.0.3
  Downloaded anstyle-parse v0.2.4
  Downloaded anstyle v1.0.7
  Downloaded base64 v0.21.7
  Downloaded async-trait v0.1.80
  Downloaded aes v0.8.4
  Downloaded bytes v1.6.0
  Downloaded clap_complete v4.5.2
  Downloaded flate2 v1.0.30
  Downloaded rustls-pki-types v1.5.0
  Downloaded is_terminal_polyfill v1.70.0
  Downloaded sync_wrapper v0.1.2
  Downloaded colorchoice v1.0.1
  Downloaded try-lock v0.2.5
  Downloaded strum v0.26.2
  Downloaded http-body v0.4.6
  Downloaded supports-unicode v2.1.0
  Downloaded rustversion v1.0.15
  Downloaded base64 v0.22.1
  Downloaded strum_macros v0.26.2
  Downloaded pin-project-internal v1.1.5
  Downloaded socket2 v0.5.7
  Downloaded pin-project v1.1.5
  Downloaded http v0.2.12
  Downloaded ureq v2.9.7
  Downloaded tokio-util v0.7.11
  Downloaded h2 v0.3.26
  Downloaded reqwest v0.11.27
  Downloaded hyper v0.14.28
  Downloaded rustls-webpki v0.102.3
  Downloaded rustls v0.21.12
  Downloaded webpki-roots v0.25.4
  Downloaded webpki-roots v0.26.1
  Downloaded openssl v0.10.64
  Downloaded rustls v0.22.4
  Downloaded zstd-sys v2.0.10+zstd.1.5.6
  Downloaded tokio v1.37.0
  Downloaded encoding_rs v0.8.34
  Downloaded ring v0.17.8
  Downloaded openssl-src v300.2.3+3.2.1
  Downloaded 42 crates (20.0 MB) in 8.51s (largest was `openssl-src` at 9.6 MB)
   Compiling libc v0.2.154
   Compiling once_cell v1.19.0
   Compiling cfg-if v1.0.0
   Compiling proc-macro2 v1.0.81
   Compiling unicode-ident v1.0.12
   Compiling pkg-config v0.3.30
   Compiling autocfg v1.3.0
   Compiling memchr v2.7.2
   Compiling jobserver v0.1.31
   Compiling quote v1.0.36
   Compiling typenum v1.17.0
   Compiling cc v1.0.96
   Compiling syn v2.0.60
   Compiling version_check v0.9.4
   Compiling getrandom v0.2.14
   Compiling generic-array v0.14.7
   Compiling lock_api v0.4.12
   Compiling pin-project-lite v0.2.14
   Compiling parking_lot_core v0.9.10
   Compiling itoa v1.0.11
   Compiling log v0.4.21
   Compiling openssl-src v300.2.3+3.2.1
   Compiling vcpkg v0.2.15
   Compiling bytes v1.6.0
   Compiling smallvec v1.13.2
   Compiling subtle v2.5.0
   Compiling scopeguard v1.2.0
   Compiling openssl-sys v0.9.102
   Compiling bitflags v2.5.0
   Compiling parking_lot v0.12.2
   Compiling crypto-common v0.1.6
   Compiling num_cpus v1.16.0
   Compiling signal-hook-registry v1.4.2
   Compiling socket2 v0.5.7
   Compiling mio v0.8.11
   Compiling adler v1.0.2
   Compiling miniz_oxide v0.7.2
   Compiling ring v0.17.8
   Compiling tokio-macros v2.2.0
   Compiling rand_core v0.6.4
   Compiling slab v0.4.9
   Compiling serde v1.0.200
   Compiling futures-core v0.3.30
   Compiling tinyvec_macros v0.1.1
   Compiling tinyvec v1.6.0
   Compiling tokio v1.37.0
   Compiling serde_derive v1.0.200
   Compiling zstd-sys v2.0.10+zstd.1.5.6
   Compiling block-buffer v0.10.4
   Compiling crc32fast v1.4.0
   Compiling openssl v0.10.64
   Compiling foreign-types-shared v0.1.1
   Compiling utf8parse v0.2.1
   Compiling fnv v1.0.7
   Compiling percent-encoding v2.3.1
   Compiling form_urlencoded v1.2.1
   Compiling http v0.2.12
   Compiling anstyle-parse v0.2.4
   Compiling foreign-types v0.3.2
   Compiling digest v0.10.7
   Compiling unicode-normalization v0.1.23
   Compiling openssl-macros v0.1.1
   Compiling tracing-core v0.1.32
   Compiling futures-sink v0.3.30
   Compiling rustix v0.38.34
   Compiling cpufeatures v0.2.12
   Compiling unicode-bidi v0.3.15
   Compiling colorchoice v1.0.1
   Compiling rustls-pki-types v1.5.0
   Compiling untrusted v0.9.0
   Compiling anstyle-query v1.0.3
   Compiling is_terminal_polyfill v1.70.0
   Compiling futures-io v0.3.30
   Compiling anstyle v1.0.7
   Compiling native-tls v0.2.11
   Compiling ryu v1.0.17
   Compiling equivalent v1.0.1
   Compiling futures-task v0.3.30
   Compiling pin-utils v0.1.0
   Compiling spin v0.9.8
   Compiling httparse v1.8.0
   Compiling hashbrown v0.14.5
   Compiling indexmap v2.2.6
   Compiling futures-util v0.3.30
   Compiling anstream v0.6.14
   Compiling idna v0.5.0
   Compiling tracing v0.1.40
   Compiling tokio-util v0.7.11
   Compiling backtrace v0.3.71
   Compiling bzip2-sys v0.1.11+1.0.8
   Compiling is-terminal v0.4.12
   Compiling aho-corasick v1.1.3
   Compiling rustls v0.22.4
   Compiling rustversion v1.0.15
   Compiling regex-syntax v0.8.3
   Compiling linux-raw-sys v0.4.13
   Compiling openssl-probe v0.1.5
   Compiling serde_json v1.0.116
   Compiling gimli v0.28.1
   Compiling zstd-safe v5.0.2+zstd.1.5.2
   Compiling ppv-lite86 v0.2.17
   Compiling try-lock v0.2.5
   Compiling want v0.3.1
   Compiling rand_chacha v0.3.1
   Compiling addr2line v0.21.0
   Compiling regex-automata v0.4.6
   Compiling flate2 v1.0.30
   Compiling h2 v0.3.26
   Compiling url v2.5.0
   Compiling rustls-webpki v0.102.3
   Compiling http-body v0.4.6
   Compiling futures-channel v0.3.30
   Compiling lzma-sys v0.1.20
   Compiling inout v0.1.3
   Compiling object v0.32.2
   Compiling heck v0.5.0
   Compiling zeroize v1.7.0
   Compiling httpdate v1.0.3
   Compiling option-ext v0.2.0
   Compiling unicode-width v0.1.12
   Compiling thiserror v1.0.59
   Compiling tower-service v0.3.2
   Compiling powerfmt v0.2.0
   Compiling rustc-demangle v0.1.23
   Compiling strsim v0.11.1
   Compiling clap_lex v0.7.0
   Compiling semver v1.0.22
   Compiling base64ct v1.6.0
   Compiling password-hash v0.4.2
   Compiling clap_builder v4.5.2
   Compiling deranged v0.3.11
   Compiling hyper v0.14.28
   Compiling dirs-sys v0.4.1
   Compiling clap_derive v4.5.4
   Compiling cipher v0.4.4
   Compiling regex v1.10.4
   Compiling rand v0.8.5
   Compiling webpki-roots v0.26.1
   Compiling sha2 v0.10.8
   Compiling hmac v0.12.1
   Compiling thiserror-impl v1.0.59
   Compiling pin-project-internal v1.1.5
   Compiling time-core v0.1.2
   Compiling is_ci v1.2.0
   Compiling unicode-linebreak v0.1.5
   Compiling heck v0.4.1
   Compiling base64 v0.22.1
   Compiling num-conv v0.1.0
   Compiling smawk v0.3.2
   Compiling base64 v0.21.7
   Compiling textwrap v0.15.2
   Compiling rustls-pemfile v1.0.4
   Compiling ureq v2.9.7
   Compiling time v0.3.36
   Compiling strum_macros v0.26.2
   Compiling supports-color v2.1.0
   Compiling pin-project v1.1.5
   Compiling pbkdf2 v0.11.0
   Compiling bzip2 v0.4.4
   Compiling env_filter v0.1.0
   Compiling aes v0.8.4
   Compiling clap v4.5.4
   Compiling directories v5.0.1
   Compiling backtrace-ext v0.2.1
   Compiling xattr v1.3.1
   Compiling supports-unicode v2.1.0
   Compiling supports-hyperlinks v2.1.0
   Compiling serde_urlencoded v0.7.1
   Compiling sha1 v0.10.6
   Compiling miette-derive v5.10.0
   Compiling terminal_size v0.1.17
   Compiling filetime v0.2.23
   Compiling errno v0.2.8
   Compiling encoding_rs v0.8.34
   Compiling mime v0.3.17
   Compiling fastrand v2.1.0
   Compiling byteorder v1.5.0
   Compiling humantime v2.1.0
   Compiling ipnet v2.9.0
   Compiling constant_time_eq v0.1.5
   Compiling lazy_static v1.4.0
   Compiling owo-colors v3.5.0
   Compiling sync_wrapper v0.1.2
   Compiling console v0.15.8
   Compiling miette v5.10.0
   Compiling env_logger v0.11.3
   Compiling tempfile v3.10.1
   Compiling zstd v0.11.2+zstd.1.5.2
   Compiling guess_host_triple v0.1.3
   Compiling zip v0.6.6
   Compiling tar v0.4.40
   Compiling update-informer v1.1.0
   Compiling clap_complete v4.5.2
   Compiling xz2 v0.1.7
   Compiling tokio-retry v0.3.0
   Compiling strum v0.26.2
   Compiling retry v2.0.0
   Compiling async-trait v0.1.80
   Compiling tokio-native-tls v0.3.1
   Compiling hyper-tls v0.5.0
   Compiling reqwest v0.11.27
   Compiling espup v0.11.0
    Finished release [optimized] target(s) in 6m 34s
   Replacing /home/tomoyan/.cargo/bin/espup
    Replaced package `espup v0.5.0` with `espup v0.11.0` (executable `espup`)

動作確認する😉

$ espup --version

espup 0.11.0

公式: 2. Install Necessary Toolchains - RISC-V and Xtensa targets - The Rust on ESP Book 翻訳

Fedora

$ espup install

[info]: Installing the Espressif Rust ecosystem
[info]: Checking Rust installation
[info]: Installing RISC-V Rust targets ('riscv32imc-unknown-none-elf', 'riscv32imac-unknown-none-elf' and 'riscv32imafc-unknown-none-elf') for 'nightly' toolchain
[info]: Installing GCC (xtensa-esp-elf)
[info]: Installing Xtensa LLVM
[info]: Downloading 'idf_tool_xtensa_elf_clang.tar.xz'
[info]: Downloading 'xtensa-esp-elf.tar.xz'
[info]: Uninstalling Xtensa Rust toolchain
[info]: Installing Xtensa Rust 1.77.0.0 toolchain
[info]: Downloading 'rust.tar.xz'
[info]: Creating symlink between '/home/tomoyan/.rustup/toolchains/esp/xtensa-esp32-elf-clang/esp-16.0.4-20231113/esp-clang/lib' and '/home/tomoyan/.espup/esp-clang'
[info]: Installing 'rust' component for Xtensa Rust toolchain
[info]: Downloading 'rust-src.tar.xz'
[info]: Installing 'rust-src' component for Xtensa Rust toolchain
[info]: Installation successfully completed!

	To get started, you need to set up some environment variables by running: '. /home/tomoyan/export-esp.sh'
	This step must be done every time you open a new terminal.
	    See other methods for setting the environment in https://esp-rs.github.io/book/installation/riscv-and-xtensa.html#3-set-up-the-environment-variables

DietPi😢

$ espup install  

[2023-08-18T00:00:25Z INFO ] 💽  Installing the Espressif Rust ecosystem
[2023-08-18T00:00:25Z WARN ] uname returned unrecognised machine "armv6l"
[2023-08-18T00:00:25Z WARN ] Could not guess triple for (Unknown, Little, Linux)
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/dietpi/.cargo/registry/src/index.crates.io-1cd66030c949c28d/espup-0.5.0/src/host_triple.rs:37:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

バージョン指定して古いツールチェーンをインストールしたい場合

$ espup install --toolchain-version 1.67.0.0

[info]: Installing the Espressif Rust ecosystem
[info]: Checking Rust installation
[info]: Installing RISC-V Rust targets ('riscv32imc-unknown-none-elf', 'riscv32imac-unknown-none-elf' and 'riscv32imafc-unknown-none-elf') for 'nightly' toolchain
[info]: Installing GCC (xtensa-esp-elf)
[warn]: Previous installation of GCC exists in: '/home/tomoyan/.rustup/toolchains/esp/xtensa-esp-elf/esp-13.2.0_20230928'. Reusing this installation
[warn]: Previous installation of LLVM exists in: '/home/tomoyan/.rustup/toolchains/esp/xtensa-esp32-elf-clang/esp-15.0.0-20221201'. Reusing this installation
[info]: Creating symlink between '/home/tomoyan/.rustup/toolchains/esp/xtensa-esp32-elf-clang/esp-15.0.0-20221201/esp-clang/lib' and '/home/tomoyan/.espup/esp-clang'
[info]: Uninstalling Xtensa Rust toolchain
[info]: Installing Xtensa Rust 1.67.0.0 toolchain
[info]: Downloading 'rust.tar.xz'
[info]: Installing 'rust' component for Xtensa Rust toolchain
[info]: Downloading 'rust-src.tar.xz'
[info]: Installing 'rust-src' component for Xtensa Rust toolchain
[info]: Installation successfully completed!

	To get started, you need to set up some environment variables by running: '. /home/tomoyan/export-esp.sh'
	This step must be done every time you open a new terminal.
	    See other methods for setting the environment in https://esp-rs.github.io/book/installation/riscv-and-xtensa.html#3-set-up-the-environment-variables

ツールチェーンは esp の名前でインストールされている🤔

$ rustup toolchain list

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
esp

esp ツールチェーンのコンパイラバージョンを確認する😉

$ rustup run esp rustc -V

rustc 1.67.0-nightly (725e31c21 2023-01-25)

Fedora

$ bat -p ~/export-esp.sh

export PATH="/home/tomoyan/.rustup/toolchains/esp/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin:$PATH"
export LIBCLANG_PATH="/home/tomoyan/.rustup/toolchains/esp/xtensa-esp32-elf-clang/esp-15.0.0-20221201/esp-clang/lib"

$ . ~/export-esp.sh

Z shell の場合

$ cat << EOF >> ~/.zshrc

# espup initialize
. ~/export-esp.sh
EOF

bash の場合

$ cat << EOF >> ~/.bashrc

# espup initialize
. ~/export-esp.sh
EOF

公式: std Development Requirements - The Rust on ESP Book 翻訳

Fedora

$ python -VV

Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)]

$ git version

git version 2.45.0

$ cargo install ldproxy

    Updating crates.io index
     Ignored package `ldproxy v0.3.3` is already installed, use --force to override

公式: Generating Projects from Templates - The Rust on ESP Book 翻訳
公式: Installation - Cargo Generate Documentation 翻訳 も参照。
プロジェクトテンプレートより独自のプロジェクトを生成することで、起こり得るエラーを防いで時間を短縮できます。

cargo-generateのインストール

$ cargo install cargo-generate

    Updating crates.io index
  Downloaded cargo-generate v0.20.0
  Downloaded 1 crate (98.0 KB) in 0.74s
  Installing cargo-generate v0.20.0
    Updating crates.io index
  Downloaded ahash v0.8.11
  Downloaded faster-hex v0.9.0
  Downloaded deranged v0.3.11
  Downloaded env_filter v0.1.0
  Downloaded cc v1.0.96
  Downloaded auth-git2 v0.5.4
  Downloaded env_logger v0.11.3
  Downloaded fs-err v2.11.0
  Downloaded gix-actor v0.31.1
  Downloaded gix-lock v13.1.1
  Downloaded getrandom v0.2.14
  Downloaded hashbrown v0.14.5
  Downloaded gix-validate v0.8.4
  Downloaded gix-config-value v0.14.6
  Downloaded gix-glob v0.16.2
  Downloaded gix-fs v0.10.2
  Downloaded gix-config v0.36.1
  Downloaded gix-utils v0.1.12
  Downloaded gix-hash v0.14.2
  Downloaded gix-date v0.8.5
  Downloaded gix-tempfile v13.1.1
  Downloaded gix-object v0.42.1
  Downloaded gix-trace v0.1.9
  Downloaded gix-sec v0.10.6
  Downloaded git2 v0.18.3
  Downloaded gix-ref v0.43.0
  Downloaded gix-path v0.10.7
  Downloaded gix-features v0.38.1
  Downloaded pest_meta v2.7.10
  Downloaded num_threads v0.1.7
  Downloaded normpath v1.2.0
  Downloaded thin-vec v0.2.13
  Downloaded pest_generator v2.7.10
  Downloaded num-conv v0.1.0
  Downloaded jobserver v0.1.31
  Downloaded pest_derive v2.7.10
  Downloaded openssl-sys v0.9.102
  Downloaded serde_derive v1.0.200
  Downloaded ignore v0.4.22
  Downloaded time v0.3.36
  Downloaded time-macros v0.2.18
  Downloaded rhai_codegen v2.1.0
  Downloaded prodash v28.0.0
  Downloaded pest v2.7.10
  Downloaded zerocopy v0.7.32
  Downloaded rhai v1.17.1
  Downloaded libgit2-sys v0.16.2+1.7.2
  Downloaded libz-sys v1.1.16
  Downloaded 48 crates (7.9 MB) in 3.97s (largest was `libz-sys` at 4.0 MB)
   Compiling proc-macro2 v1.0.81
   Compiling libc v0.2.154
   Compiling unicode-ident v1.0.12
   Compiling thiserror v1.0.59
   Compiling memchr v2.7.2
   Compiling once_cell v1.19.0
   Compiling quote v1.0.36
   Compiling autocfg v1.2.0
   Compiling syn v2.0.60
   Compiling aho-corasick v1.1.3
   Compiling regex-syntax v0.8.3
   Compiling cfg-if v1.0.0
   Compiling tinyvec_macros v0.1.1
   Compiling tinyvec v1.6.0
   Compiling jobserver v0.1.31
   Compiling cc v1.0.96
   Compiling regex-automata v0.4.6
   Compiling unicode-normalization v0.1.23
   Compiling pkg-config v0.3.30
   Compiling bitflags v2.5.0
   Compiling thiserror-impl v1.0.59
   Compiling fastrand v2.1.0
   Compiling serde v1.0.200
   Compiling vcpkg v0.2.15
   Compiling serde_derive v1.0.200
   Compiling bstr v1.9.1
   Compiling gix-trace v0.1.9
   Compiling same-file v1.0.6
   Compiling powerfmt v0.2.0
   Compiling num-conv v0.1.0
   Compiling time-core v0.1.2
   Compiling time-macros v0.2.18
   Compiling deranged v0.3.11
   Compiling walkdir v2.5.0
   Compiling gix-utils v0.1.12
   Compiling faster-hex v0.9.0
   Compiling itoa v1.0.11
   Compiling num_threads v0.1.7
   Compiling time v0.3.36
   Compiling gix-hash v0.14.2
   Compiling libz-sys v1.1.16
   Compiling openssl-sys v0.9.102
   Compiling rustix v0.38.34
   Compiling sha1_smol v1.0.0
   Compiling smallvec v1.13.2
   Compiling prodash v28.0.0
   Compiling gix-features v0.38.1
   Compiling lock_api v0.4.12
   Compiling version_check v0.9.4
   Compiling linux-raw-sys v0.4.13
   Compiling crunchy v0.2.2
   Compiling parking_lot_core v0.9.10
   Compiling ucd-trie v0.1.6
   Compiling pest v2.7.10
   Compiling regex v1.10.4
   Compiling libssh2-sys v0.3.0
   Compiling getrandom v0.2.14
   Compiling num-traits v0.2.18
   Compiling winnow v0.6.7
   Compiling static_assertions v1.1.0
   Compiling tiny-keccak v2.0.2
   Compiling percent-encoding v2.3.1
   Compiling log v0.4.21
   Compiling scopeguard v1.2.0
   Compiling pest_meta v2.7.10
   Compiling tempfile v3.10.1
   Compiling lazy_static v1.4.0
   Compiling home v0.5.9
   Compiling crossbeam-utils v0.8.19
   Compiling gix-path v0.10.7
   Compiling parking_lot v0.12.2
   Compiling pest_generator v2.7.10
   Compiling gix-fs v0.10.2
   Compiling gix-date v0.8.5
   Compiling libgit2-sys v0.16.2+1.7.2
   Compiling anstyle v1.0.6
   Compiling either v1.11.0
   Compiling unicode-bidi v0.3.15
   Compiling itertools v0.10.5
   Compiling idna v0.5.0
   Compiling gix-actor v0.31.1
   Compiling gix-tempfile v13.1.1
   Compiling pest_derive v2.7.10
   Compiling const-random-macro v0.1.16
   Compiling form_urlencoded v1.2.1
   Compiling kstring v2.0.0
   Compiling rand_core v0.6.4
   Compiling smartstring v1.0.1
   Compiling ahash v0.8.11
   Compiling gix-validate v0.8.4
   Compiling liquid-derive v0.26.4
   Compiling hashbrown v0.14.5
   Compiling unicode-width v0.1.12
   Compiling ppv-lite86 v0.2.17
   Compiling doc-comment v0.3.3
   Compiling option-ext v0.2.0
   Compiling anymap2 v0.13.0
   Compiling portable-atomic v1.6.0
   Compiling equivalent v1.0.1
   Compiling utf8parse v0.2.1
   Compiling bitflags v1.3.2
   Compiling nix v0.26.4
   Compiling anstyle-parse v0.2.3
   Compiling indexmap v2.2.6
   Compiling liquid-core v0.26.4
   Compiling dirs-sys v0.4.1
   Compiling rand_chacha v0.3.1
   Compiling console v0.15.8
   Compiling gix-object v0.42.1
   Compiling crossbeam-epoch v0.9.18
   Compiling const-random v0.1.18
   Compiling url v2.5.0
   Compiling gix-lock v13.1.1
   Compiling toml_datetime v0.6.5
   Compiling serde_spanned v0.6.5
   Compiling cvt v0.1.2
   Compiling memmap2 v0.9.4
   Compiling fs-err v2.11.0
   Compiling zerocopy v0.7.32
   Compiling unicode-segmentation v1.11.0
   Compiling anstyle-query v1.0.2
   Compiling openssl-probe v0.1.5
   Compiling paste v1.0.14
   Compiling anyhow v1.0.82
   Compiling heck v0.5.0
   Compiling clap_lex v0.7.0
   Compiling names v0.14.0
   Compiling semver v1.0.22
   Compiling colorchoice v1.0.0
   Compiling anstream v0.6.13
   Compiling clap_builder v4.5.2
   Compiling clap_derive v4.5.4
   Compiling liquid-lib v0.26.4
   Compiling gix-ref v0.43.0
   Compiling fs_at v0.1.10
   Compiling toml_edit v0.22.12
   Compiling crossbeam-deque v0.8.5
   Compiling rand v0.8.5
   Compiling dirs v5.0.1
   Compiling gix-config-value v0.14.6
   Compiling gix-glob v0.16.2
   Compiling globset v0.4.14
   Compiling env_filter v0.1.0
   Compiling gix-sec v0.10.6
   Compiling rhai_codegen v2.1.0
   Compiling path-dedot v3.1.1
   Compiling terminal-prompt v0.2.3
   Compiling shell-words v1.1.0
   Compiling zeroize v1.7.0
   Compiling number_prefix v0.4.0
   Compiling normpath v1.2.0
   Compiling humantime v2.1.0
   Compiling unicode-bom v2.0.3
   Compiling thin-vec v0.2.13
   Compiling env_logger v0.11.3
   Compiling rhai v1.17.1
   Compiling gix-config v0.36.1
   Compiling remove_dir_all v0.8.2
   Compiling indicatif v0.17.8
   Compiling dialoguer v0.11.0
   Compiling path-absolutize v3.1.1
   Compiling ignore v0.4.22
   Compiling toml v0.8.12
   Compiling liquid v0.26.4
   Compiling clap v4.5.4
   Compiling sanitize-filename v0.5.0
   Compiling git2 v0.18.3
   Compiling auth-git2 v0.5.4
   Compiling cargo-generate v0.20.0
    Finished release [optimized] target(s) in 6m 03s
   Replacing /home/tomoyan/.cargo/bin/cargo-generate
    Replaced package `cargo-generate v0.18.5` with `cargo-generate v0.20.0` (executable `cargo-generate`)

動作確認

$ cargo generate -V

cargo generate-generate 0.20.0

プロジェクトの作成

  • esp-template - no_std テンプレート
  • esp-idf-template - std テンプレート

「お気に入り `esp-rs/esp-template` が設定に見つかりません。」と言われる場合🤔

$ cargo generate esp-rs/esp-template

⚠️   Favorite `esp-rs/esp-template` not found in config, using it as a git repository: https://github.com/esp-rs/esp-template.git
🤷   Project Name:

予めテンプレートを clone してから…

$ git clone --depth 1 https://github.com/esp-rs/esp-template

Cloning into 'esp-template'...
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 37 (delta 1), reused 21 (delta 1), pack-reused 0
Receiving objects: 100% (37/37), 17.57 KiB | 148.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.

プロジェクトテンプレートからプロジェクトを作成する😉

$ cargo generate --path ./esp-template

no_std テンプレートの場合

公式: Generating using a local template - Cargo Generate Documentation 翻訳
ローカルテンプレートからプロジェクトを作成する🤔

$ git clone --depth 1 https://github.com/esp-rs/esp-template

Cloning into 'esp-template'...
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 37 (delta 1), reused 21 (delta 1), pack-reused 0
Receiving objects: 100% (37/37), 17.57 KiB | 148.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.

$ cargo generate --path ./esp-template

🤷   Project Name: haruo_nostd_esp32 ->プロジェクト名を入力して Enter

⚠️   Renaming project called `haruo_nostd_esp32` to `haruo-nostd-esp32`...
🔧   Destination: /home/tomoyan/my_projects/haruo-nostd-esp32 ...
🔧   project-name: haruo-nostd-esp32 ...
🔧   Generating template ...

? 🤷   Which MCU to target? 
 esp32 ->MCU を選択して Enter
  esp32c2
  esp32c3
  esp32c6
  esp32h2
  esp32s2
  esp32s3

 🤷   Which MCU to target? · esp32

? 🤷   Configure advanced template options? 
 false ->Enter
  true

 🤷   Configure advanced template options? · false
🔧   Moving generated files into: `/home/tomoyan/my_projects/haruo-nostd-esp32`...
🔧   Initializing a fresh Git repositoryDone! New project created /home/tomoyan/my_projects/haruo-nostd-esp32

std テンプレートの場合

公式: Generating using a local template - Cargo Generate Documentation 翻訳
ローカルテンプレートからプロジェクトを作成する🤔

$ git clone --depth 1 https://github.com/esp-rs/esp-idf-template

Cloning into 'esp-idf-template'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 64 (delta 8), reused 38 (delta 1), pack-reused 0
Receiving objects: 100% (64/64), 27.56 KiB | 4.59 MiB/s, done.
Resolving deltas: 100% (8/8), done.

$ cargo generate --path ./esp-idf-template

? 🤷   Which template should be expanded? 

 cargo ->Enter
  cmake

✔ 🤷   Which template should be expanded? · cargo

🤷   Project Name: haruo_eps32 ->プロジェクト名を入力して Enter

⚠️   Renaming project called `haruo_std_esp32` to `haruo_std_esp32`...
🔧   Destination: /home/tomoyan/my_projects/haruo_std_esp32 ...
🔧   project-name: haruo_std_esp32 ...
🔧   Generating template ...
? 🤷   Which MCU to target? 

 esp32 ->MCU を選択して Enter
  esp32c2
  esp32c3
  esp32c6
  esp32h2
  esp32s2
  esp32s3

 🤷   Which MCU to target? · esp32
? 🤷   Configure advanced template options? 

 false ->Enter
  true

 🤷   Configure advanced template options? · false
🔧   Moving generated files into: `/home/tomoyan/my_projects/haruo_std_esp32`...
🔧   Initializing a fresh Git repositoryDone! New project created /home/tomoyan/my_projects/haruo_std_esp32

公式: GitHub - cargo-bins/cargo-binstall: Binary installation for rust projects 翻訳

$ curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash

++ mktemp -d
+ cd /tmp/tmp.aFNKUP4XyV
+ base_url=https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-
++ uname -s
+ os=Linux
+ '[' Linux == Darwin ']'
+ '[' Linux == Linux ']'
++ uname -m
+ machine=x86_64
+ target=x86_64-unknown-linux-musl
+ '[' x86_64 == armv7 ']'
+ url=https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz
+ curl -L --proto =https --tlsv1.2 -sSf https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz
+ tar -xvzf -
cargo-binstall
+ ./cargo-binstall -y --force cargo-binstall
 WARN Failed to retrieve token from `gh auth token` err=Os { code: 2, kind: NotFound, message: "No such file or directory" }
 WARN Failed to read git credential file
 INFO resolve: Resolving package: 'cargo-binstall'
 INFO resolve: Verified signature for package 'cargo-binstall': gh=cargo-bins/cargo-binstall git=dfdaf6952e30a0fc88fe8f8afc4906244bdeccf8 ts=2024-05-03T08:38:48.184Z run=8936278573
 WARN The package cargo-binstall v1.6.5 (x86_64-unknown-linux-gnu) has been downloaded from github.com
 INFO This will install the following binaries:
 INFO   - cargo-binstall (cargo-binstall -> /home/tomoyan/.cargo/bin/cargo-binstall)
 INFO Installing binaries...
 INFO Done in 7.661177467s
+ CARGO_HOME=/home/tomoyan/.cargo
+ [[ :/home/tomoyan/.rustup/toolchains/esp/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin:/home/tomoyan/.rustup/toolchains/esp/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin:/home/tomoyan/.rustup/toolchains/esp/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin:/home/tomoyan/.rustup/toolchains/esp/xtensa-esp32s3-elf/esp-12.2.0_20230208/xtensa-esp32s3-elf/bin:/home/tomoyan/.rustup/toolchains/esp/xtensa-esp32s2-elf/esp-12.2.0_20230208/xtensa-esp32s2-elf/bin:/home/tomoyan/micromamba/condabin:/home/tomoyan/.local/bin:/home/tomoyan/go/bin:/home/tomoyan/.anyenv/envs/nodenv/shims:/home/tomoyan/.anyenv/envs/nodenv/bin:/home/tomoyan/.anyenv/bin:/home/tomoyan/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin: == *\:\/\h\o\m\e\/\t\o\m\o\y\a\n\/\.\c\a\r\g\o\/\b\i\n\:* ]]

動作確認🤔

$ cargo binstall -V

1.6.5

公式: Running the Code - Understanding esp-template - The Rust on ESP Book 翻訳

cargo run コマンドで esp32 ボードにコードをフラッシュするには、espflash をインストールしておく必要がある🤔

$ cargo run

    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running `espflash flash --monitor target/xtensa-esp32-none-elf/debug/haruo-nostd-esp32`
error: could not execute process `espflash flash --monitor target/xtensa-esp32-none-elf/debug/haruo-nostd-esp32` (never executed)

Caused by:
  No such file or directory (os error 2)

公式: espflash/espflash at main · esp-rs/espflash · GitHub 翻訳 の手順で espflash をインストールする🤔
※ esp-rs/espflash リポジトリには cargo-espflash も存在するが、cargo-espflash ではなく espflash です🤔

Fedora
systemd-devel がインストールされていない場合はインストールする🤔

$ sudo dnf install systemd-devel

メタデータの期限切れの最終確認: 1:06:39 前の 2023年11月30日 11時33分17秒 に実施しました。
パッケージ systemd-devel-253.12-1.fc38.x86_64 は既にインストールされています。
依存関係が解決しました。
行うべきことはありません。
完了しました!

espflash のインストール🤔

$ cargo install espflash

    Updating crates.io index
  Downloaded espflash v3.0.0
  Downloaded 1 crate (5.4 MB) in 3.32s
  Installing espflash v3.0.0
    Updating crates.io index
  Downloaded bytemuck v1.15.0
  Downloaded defmt-parser v0.3.4
  Downloaded derive_more v0.99.17
  Downloaded esp-idf-part v0.5.0
  Downloaded defmt-decoder v0.3.10
  Downloaded bytemuck_derive v1.6.0
  Downloaded hash32 v0.3.1
  Downloaded miette-derive v7.2.0
  Downloaded num-traits v0.2.19
  Downloaded supports-hyperlinks v3.0.0
  Downloaded miette v7.2.0
  Downloaded supports-unicode v3.0.0
  Downloaded supports-color v3.0.0
  Downloaded unescaper v0.1.4
  Downloaded slip-codec v0.4.0
  Downloaded owo-colors v4.0.0
  Downloaded serialport v4.3.0
  Downloaded heapless v0.8.0
  Downloaded ruzstd v0.5.0
  Downloaded comfy-table v7.1.1
  Downloaded 20 crates (718.3 KB) in 1.92s
   Compiling proc-macro2 v1.0.81
   Compiling unicode-ident v1.0.12
   Compiling libc v0.2.154
   Compiling cfg-if v1.0.0
   Compiling serde v1.0.200
   Compiling syn v1.0.109
   Compiling memchr v2.7.2
   Compiling bitflags v2.5.0
   Compiling cc v1.0.96
   Compiling quote v1.0.36
   Compiling syn v2.0.60
   Compiling crc32fast v1.4.0
   Compiling autocfg v1.3.0
   Compiling byteorder v1.5.0
   Compiling adler v1.0.2
   Compiling miniz_oxide v0.7.2
   Compiling rustix v0.38.34
   Compiling thiserror v1.0.59
   Compiling flate2 v1.0.30
   Compiling smallvec v1.13.2
   Compiling static_assertions v1.1.0
   Compiling stable_deref_trait v1.2.0
   Compiling typenum v1.17.0
   Compiling version_check v0.9.4
   Compiling linux-raw-sys v0.4.13
   Compiling generic-array v0.14.7
   Compiling twox-hash v1.6.3
   Compiling ring v0.17.8
   Compiling itoa v1.0.11
   Compiling serde_derive v1.0.200
   Compiling thiserror-impl v1.0.59
   Compiling derive_more v0.99.17
   Compiling fnv v1.0.7
   Compiling rustversion v1.0.15
   Compiling tinyvec_macros v0.1.1
   Compiling hashbrown v0.14.5
   Compiling unicode-width v0.1.12
   Compiling strsim v0.10.0
   Compiling ident_case v1.0.1
   Compiling cpp_demangle v0.4.3
   Compiling ryu v1.0.17
   Compiling ruzstd v0.5.0
   Compiling utf8parse v0.2.1
   Compiling equivalent v1.0.1
   Compiling indexmap v2.2.6
   Compiling object v0.32.2
   Compiling log v0.4.21
   Compiling anstyle-parse v0.2.4
   Compiling darling_core v0.14.4
   Compiling tinyvec v1.6.0
   Compiling gimli v0.28.1
   Compiling lock_api v0.4.12
   Compiling getrandom v0.2.14
   Compiling aho-corasick v1.1.3
   Compiling untrusted v0.9.0
   Compiling spin v0.9.8
   Compiling regex-syntax v0.8.3
   Compiling radium v0.7.0
   Compiling anstyle v1.0.7
   Compiling scopeguard v1.2.0
   Compiling winnow v0.5.40
   Compiling toml_datetime v0.6.5
   Compiling signal-hook v0.3.17
   Compiling serde_json v1.0.116
   Compiling parking_lot_core v0.9.10
   Compiling rustls-pki-types v1.5.0
   Compiling colorchoice v1.0.1
   Compiling anstyle-query v1.0.3
   Compiling pkg-config v0.3.30
   Compiling is_terminal_polyfill v1.70.0
   Compiling lazy_static v1.4.0
   Compiling anstream v0.6.14
   Compiling libudev-sys v0.1.4
   Compiling toml_edit v0.19.15
   Compiling regex-automata v0.4.6
   Compiling darling_macro v0.14.4
   Compiling unicode-normalization v0.1.23
   Compiling terminal_size v0.3.0
   Compiling num-traits v0.2.19
   Compiling backtrace v0.3.71
   Compiling signal-hook-registry v1.4.2
   Compiling memmap2 v0.5.10
   Compiling zeroize v1.7.0
   Compiling unicode-bidi v0.3.15
   Compiling rustc-demangle v0.1.23
   Compiling tap v1.0.1
   Compiling heck v0.4.1
   Compiling fallible-iterator v0.3.0
   Compiling rustls v0.22.4
   Compiling percent-encoding v2.3.1
   Compiling once_cell v1.19.0
   Compiling cfg_aliases v0.1.1
   Compiling nix v0.28.0
   Compiling proc-macro-crate v1.3.1
   Compiling addr2line v0.21.0
   Compiling form_urlencoded v1.2.1
   Compiling strum_macros v0.26.2
   Compiling wyz v0.5.1
   Compiling idna v0.5.0
   Compiling darling v0.14.4
   Compiling rustls-webpki v0.102.3
   Compiling regex v1.10.4
   Compiling block-buffer v0.10.4
   Compiling crypto-common v0.1.6
   Compiling mio v0.8.11
   Compiling portable-atomic v1.6.0
   Compiling heck v0.5.0
   Compiling clap_lex v0.7.0
   Compiling semver v1.0.22
   Compiling strsim v0.11.1
   Compiling powerfmt v0.2.0
   Compiling option-ext v0.2.0
   Compiling num-conv v0.1.0
   Compiling subtle v2.5.0
   Compiling funty v2.0.0
   Compiling anyhow v1.0.82
   Compiling time-core v0.1.2
   Compiling heapless v0.8.0
   Compiling time-macros v0.2.18
   Compiling bitvec v1.0.1
   Compiling dirs-sys v0.4.1
   Compiling deranged v0.3.11
   Compiling clap_builder v4.5.2
   Compiling clap_derive v4.5.4
   Compiling signal-hook-mio v0.2.3
   Compiling digest v0.10.7
   Compiling parking_lot v0.12.2
   Compiling deku_derive v0.16.0
   Compiling strum v0.26.2
   Compiling url v2.5.0
   Compiling console v0.15.8
   Compiling webpki-roots v0.26.1
   Compiling serde_spanned v0.6.5
   Compiling hash32 v0.3.1
   Compiling csv-core v0.1.11
   Compiling smawk v0.3.2
   Compiling fastrand v2.1.0
   Compiling unicode-linebreak v0.1.5
   Compiling bitflags v1.3.2
   Compiling is_ci v1.2.0
   Compiling winnow v0.6.7
   Compiling minimal-lexical v0.2.1
   Compiling base64 v0.22.1
   Compiling ureq v2.9.7
   Compiling toml_edit v0.22.12
   Compiling nom v7.1.3
   Compiling time v0.3.36
   Compiling supports-color v3.0.0
   Compiling nix v0.26.4
   Compiling textwrap v0.16.1
   Compiling tempfile v3.10.1
   Compiling csv v1.3.0
   Compiling deku v0.16.0
   Compiling backtrace-ext v0.2.1
   Compiling parse_int v0.6.0
   Compiling clap v4.5.4
   Compiling crossterm v0.27.0
   Compiling libudev v0.3.0
   Compiling directories v5.0.1
   Compiling env_filter v0.1.0
   Compiling colored v2.1.0
   Compiling defmt-json-schema v0.1.0
   Compiling serde_plain v1.0.2
   Compiling defmt-parser v0.3.4
   Compiling unescaper v0.1.4
   Compiling miette-derive v7.2.0
   Compiling bytemuck_derive v1.6.0
   Compiling number_prefix v0.4.0
   Compiling zero v0.1.3
   Compiling shell-words v1.1.0
   Compiling cpufeatures v0.2.12
   Compiling owo-colors v4.0.0
   Compiling humantime v2.1.0
   Compiling supports-unicode v3.0.0
   Compiling dissimilar v1.0.8
   Compiling supports-hyperlinks v3.0.0
   Compiling md5 v0.7.0
   Compiling defmt-decoder v0.3.10
   Compiling miette v7.2.0
   Compiling esp-idf-part v0.5.0
   Compiling env_logger v0.11.3
   Compiling bytemuck v1.15.0
   Compiling sha2 v0.10.8
   Compiling dialoguer v0.11.0
   Compiling xmas-elf v0.9.1
   Compiling indicatif v0.17.8
   Compiling serialport v4.3.0
   Compiling update-informer v1.1.0
   Compiling comfy-table v7.1.1
   Compiling ctrlc v3.4.4
   Compiling clap_complete v4.5.2
   Compiling toml v0.8.12
   Compiling md-5 v0.10.6
   Compiling hex v0.4.3
   Compiling slip-codec v0.4.0
   Compiling espflash v3.0.0
    Finished release [optimized] target(s) in 3m 55s
   Replacing /home/tomoyan/.cargo/bin/espflash
    Replaced package `espflash v2.1.0` with `espflash v3.0.0` (executable `espflash`)

動作確認🤔

$ espflash -V

espflash 3.0.0

標準ではシリアルポートの権限を設定する必要がある🤔

$ cargo run

    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `espflash flash --monitor target/xtensa-esp32-none-elf/debug/haruo-nostd-esp32`
[2023-11-30T05:26:14Z INFO ] Serial port: '/dev/ttyUSB0'
[2023-11-30T05:26:14Z INFO ] Connecting...
Error: espflash::serial_error

  × Failed to open serial port /dev/ttyUSB0
  ├─▶ Failed to open serial port /dev/ttyUSB0
  ├─▶ Error while connecting to device
  ├─▶ IO error while using serial port: Permission denied
  ╰─▶ Permission denied

EPS32-WROOM-32

ESP32-WROOM-32 (cp210x)

ESP32 の接続ポートを確認
lsusb コマンドで Bus と Device 番号、デバイス名を調べる🤔

$ lsusb

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 04f2:b34c Chicony Electronics Co., Ltd [unknown]
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0bda:8723 Realtek Semiconductor Corp. RTL8723A Bluetooth
Bus 002 Device 004: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver

lsusb -t コマンドでドライバを調べる🤔

$ lsusb -t

/:  Bus 001.Port 001: Dev 001, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 001: Dev 002, If 0, Class=Hub, Driver=hub/6p, 480M
        |__ Port 006: Dev 003, If 0, Class=Video, Driver=uvcvideo, 480M
        |__ Port 006: Dev 003, If 1, Class=Video, Driver=uvcvideo, 480M
/:  Bus 002.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 480M
    |__ Port 001: Dev 004, If 0, Class=Vendor Specific Class, Driver=cp210x, 12M
    |__ Port 004: Dev 003, If 0, Class=Wireless, Driver=btusb, 12M
    |__ Port 004: Dev 003, If 1, Class=Wireless, Driver=btusb, 12M
/:  Bus 003.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/:  Bus 004.Port 001: Dev 001, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 001: Dev 002, If 0, Class=Hub, Driver=hub/6p, 480M
        |__ Port 002: Dev 004, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 002: Dev 004, If 1, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 002: Dev 004, If 2, Class=Human Interface Device, Driver=usbhid, 12M

シリアルデバイスの by-id、by-path で /dev/ttyUSB0 であることが確認できる🤔

$ ls -l /dev/serial/{by-id,by-path}

/dev/serial/by-id:
合計 0
lrwxrwxrwx 1 root root 13  5月  6 09:22 usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0 -> ../../ttyUSB0

/dev/serial/by-path:
合計 0
lrwxrwxrwx 1 root root 13  5月  6 09:22 pci-0000:00:14.0-usb-0:1:1.0-port0 -> ../../ttyUSB0
lrwxrwxrwx 1 root root 13  5月  6 09:22 pci-0000:00:14.0-usbv2-0:1:1.0-port0 -> ../../ttyUSB0

公式: espflash/espflash/README.md at main · esp-rs/espflash · GitHub 翻訳
シリアルコンソールに接続する前に、ポートの権限を設定

/dev/ttyUSB0dialout グループで読み書きできる🤔

$ ls -l /dev/ttyUSB0

crw-rw---- 1 root dialout 188, 0 11月 30 12:16 /dev/ttyUSB0

現在のユーザー $USERdialout グループに所属させる🤔

$ sudo usermod -a -G dialout $USER

$ id tomoyan

uid=1000(tomoyan) gid=1000(tomoyan) groups=1000(tomoyan),10(wheel),18(dialout),135(mock),974(docker)

dialout グループへの所属を再ログインせずに反映するには newgrp dialout コマンドを実行する🤔

$ newgrp dialout
$ id

uid=1000(tomoyan) gid=18(dialout) groups=18(dialout),10(wheel),135(mock),974(docker),1000(tomoyan)

公式: Running the Code - Understanding esp-template - The Rust on ESP Book 翻訳
上記までの手順でフラッシュへ書き込む準備ができているので、cargo run コマンドでビルドからフラッシュ書き込みができる😉

サンプル: esp32-nostd-ssd1306 - Wokwi ESP32, STM32, Arduino Simulator

$ cargo run

    Updating crates.io index
  Downloaded float-cmp v0.9.0
  Downloaded profont v0.7.0
  Downloaded esp-backtrace v0.9.0
  Downloaded esp-hal-procmacros v0.7.0
  Downloaded embedded-io v0.6.1
  Downloaded micromath v2.1.0
  Downloaded mipidsi v0.7.1
  Downloaded ssd1306 v0.8.4
  Downloaded esp32-hal v0.16.0
  Downloaded esp-hal-common v0.13.1
  Downloaded embedded-graphics v0.8.1
  Downloaded esp32 v0.27.0
  Downloaded 12 crates (3.7 MB) in 4.42s (largest was `embedded-graphics` at 2.5 MB)
  Downloaded addr2line v0.17.0
  Downloaded getopts v0.2.21
  Downloaded cc v1.0.76
  Downloaded rustc-demangle v0.1.21
  Downloaded miniz_oxide v0.5.3
  Downloaded libc v0.2.138
  Downloaded object v0.29.0
  Downloaded gimli v0.26.1
  Downloaded compiler_builtins v0.1.84
  Downloaded 9 crates (1.9 MB) in 6.86s
   Compiling compiler_builtins v0.1.84
   Compiling core v0.0.0 (/home/tomoyan/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.70
   Compiling unicode-ident v1.0.12
   Compiling autocfg v1.1.0
   Compiling syn v1.0.109
   Compiling rustversion v1.0.14
   Compiling serde v1.0.193
   Compiling quote v1.0.33
   Compiling heck v0.4.1
   Compiling syn v2.0.39
   Compiling version_check v0.9.4
   Compiling memchr v2.6.4
   Compiling aho-corasick v1.1.2
   Compiling regex-syntax v0.8.2
   Compiling anyhow v1.0.75
   Compiling fnv v1.0.7
   Compiling ident_case v1.0.1
   Compiling strsim v0.10.0
   Compiling darling_core v0.20.3
   Compiling serde_derive v1.0.193
   Compiling rustc-std-workspace-core v1.99.0 (/home/tomoyan/.rustup/toolchains/esp/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling nb v1.1.0
   Compiling nb v0.1.3
   Compiling byteorder v1.5.0
   Compiling void v1.0.2
   Compiling regex-automata v0.4.3
   Compiling lock_api v0.4.11
   Compiling xtensa-lx v0.8.0
   Compiling az v1.2.1
   Compiling semver v1.0.20
   Compiling darling_macro v0.20.3
   Compiling embedded-hal v0.2.7
   Compiling regex v1.10.2
   Compiling scopeguard v1.2.0
   Compiling strum_macros v0.24.3
   Compiling enum-as-inner v0.4.0
   Compiling proc-macro-error-attr v1.0.4
   Compiling hashbrown v0.14.3
   Compiling strum v0.24.1
   Compiling equivalent v1.0.1
   Compiling indexmap v2.1.0
   Compiling core-isa-parser v0.2.0
   Compiling darling v0.20.3
   Compiling minijinja v1.0.10
   Compiling bare-metal v1.0.0
   Compiling critical-section v1.1.2
   Compiling stable_deref_trait v1.2.0
   Compiling proc-macro-error v1.0.4
   Compiling num-traits v0.2.17
   Compiling winnow v0.5.19
   Compiling toml_datetime v0.6.5
   Compiling embedded-graphics-core v0.4.0
   Compiling rustc_version v0.4.0
   Compiling basic-toml v0.1.7
   Compiling toml_edit v0.20.7
   Compiling spin v0.9.8
   Compiling mutex-trait v0.2.0
   Compiling display-interface v0.4.1
   Compiling paste v1.0.14
   Compiling esp32 v0.27.0
   Compiling esp-hal-common v0.13.1
   Compiling proc-macro-crate v2.0.0
   Compiling heapless v0.7.16
   Compiling xtensa-lx-rt-proc-macros v0.2.1
   Compiling vcell v0.1.3
   Compiling embedded-hal v1.0.0-rc.1
   Compiling r0 v1.0.0
   Compiling gcd v2.3.0
   Compiling strum_macros v0.25.3
   Compiling litrs v0.4.1
   Compiling esp-println v0.7.1
   Compiling esp-hal-procmacros v0.7.0
   Compiling fugit v0.3.7
   Compiling embedded-hal-nb v1.0.0-rc.1
   Compiling float-cmp v0.9.0
   Compiling strum v0.25.0
   Compiling embedded-dma v0.2.0
   Compiling hash32 v0.2.1
   Compiling embedded-can v0.4.1
   Compiling cfg-if v1.0.0
   Compiling byte-slice-cast v0.3.5
   Compiling bitfield v0.14.0
   Compiling micromath v2.1.0
   Compiling embedded-io v0.6.1
   Compiling bitflags v2.4.1
   Compiling esp-backtrace v0.9.0
   Compiling xtensa-lx-rt v0.16.0
   Compiling esp32-hal v0.16.0
   Compiling embedded-graphics v0.8.1
   Compiling display-interface-spi v0.4.1
   Compiling display-interface-i2c v0.4.0
   Compiling ssd1306 v0.8.4
   Compiling profont v0.7.0
   Compiling mipidsi v0.7.1
   Compiling rust_project_esp32 v0.1.0 (/home/tomoyan/my_projects/haruo-nostd-esp32)

    Finished dev [optimized + debuginfo] target(s) in 7m 41s
     Running `espflash flash --monitor target/xtensa-esp32-none-elf/debug/rust_project_esp32`
[2024-05-06T00:37:27Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-05-06T00:37:27Z INFO ] Connecting...
[2024-05-06T00:37:27Z INFO ] Using flash stub
Chip type:         esp32 (revision v1.0)
Crystal frequency: 40 MHz
Flash size:        4MB
Features:          WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC address:       7c:9e:bd:36:81:8c
App/part. size:    108,688/4,128,768 bytes, 2.63%
[00:00:01] [========================================]      17/17      0x1000                                  [2024-05-06T00:37:31Z INFO ] Segment at address '0x8000' has not changed, skipping write
[00:00:04] [========================================]      40/40      0x10000                                 [2024-05-06T00:37:36Z INFO ] Flashing has completed!
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7104
load:0x40078000,len:15576
load:0x40080400,len:4
ho 8 tail 4 room 4
load:0x40080404,len:3876
entry 0x4008064c
0x4008064c - core::fmt::Arguments::new_v1
    at /home/tomoyan/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:398
I (30) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader
I (31) boot: compile time Jun  7 2023 07:48:23
I (33) boot: Multicore bootloader
I (37) boot: chip revision: v1.0
I (41) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 4MB
I (54) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (86) boot:  2 factory          factory app      00 00 00010000 003f0000
I (93) boot: End of partition table
I (97) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=07f24h ( 32548) map
I (118) esp_image: segment 1: paddr=00017f4c vaddr=3ffb0000 size=00004h (     4) load
I (118) esp_image: segment 2: paddr=00017f58 vaddr=40080000 size=01098h (  4248) load
I (127) esp_image: segment 3: paddr=00018ff8 vaddr=00000000 size=07020h ( 28704) 
I (143) esp_image: segment 4: paddr=00020020 vaddr=400d0020 size=0a84ch ( 43084) map
I (160) boot: Loaded app from partition at offset 0x10000
I (160) boot: Disabling RNG early entropy source...
esp-hal
Chip: ESP32...
Haruo World!...
esp-hal
Chip: ESP32...
Haruo World!...
esp-hal
Chip: ESP32...
Haruo World!...

  • rust/rust_on_esp_install.txt
  • 最終更新: 2024/05/06 09:55
  • by ともやん