Skip to content

Instantly share code, notes, and snippets.

@eloycoto
Last active February 27, 2023 09:16
Show Gist options
  • Save eloycoto/aed863aa3c078cbd6b0890553463cd34 to your computer and use it in GitHub Desktop.
Save eloycoto/aed863aa3c078cbd6b0890553463cd34 to your computer and use it in GitHub Desktop.

Install espup tool:

cargo install espup
espup install

Init path

source ~/export-esp.sh

Init project:

cargo generate --git https://github.com/esp-rs/esp-template
cargo generate --git https://github.com/esp-rs/esp-idf-template cargo
🤷   Project Name: test
🔧   Destination: /tmp/test/test ...
🔧   project-name: test ...
🔧   Generating template ...
✔ 🤷   Configure project to use Dev Containers (VS Code, GitHub Codespaces and Gitpod)? (beware: Dev Containers not available for esp-idf v4.3.2) · false
✔ 🤷   STD support · false
✔ 🤷   ESP-IDF native build version (v4.3.2 = previous stable, v4.4 = stable, mainline = UNSTABLE) · v4.4
✔ 🤷   MCU · esp32
[ 1/10]   Done: .cargo/config.toml
[ 2/10]   Done: .cargo
[ 3/10]   Done: .gitignore
[ 4/10]   Done: .vscode
[ 5/10]   Done: Cargo.toml                                                                                                                                               [ 6/10]   Done: build.rs                                                                                                                                                 [ 7/10]   Done: rust-toolchain.toml                                                                                                                                      [ 8/10]   Done: sdkconfig.defaults                                                                                                                                       [ 9/10]   Done: src/main.rs                                                                                                                                              [10/10]   Done: src                                                                                                                                                      🔧   Moving generated files into: `/tmp/test/test`...
💡   Initializing a fresh Git repository
✨   Done! New project created /tmp/test/test

Build and run

cd test/
cargo build
cargo run
https://kerkour.com/rust-on-esp32
use core::fmt::Write;
use cortex_m_semihosting::hio;
use log::LevelFilter;
use log::{Level, Metadata, Record};
struct SimpleLogger;
static LOGGER: SimpleLogger = SimpleLogger;
impl log::Log for SimpleLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
let res = metadata.level() <= Level::Debug;
return res;
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
// use cortex_m_semihosting::hio;
let hstdout = hio::hstdout();
if hstdout.is_ok() {
writeln!(hstdout.unwrap(), "{} - {}", record.level(), record.args()).unwrap();
}
}
}
fn flush(&self) {}
}
pub fn init() {
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(LevelFilter::Debug))
.unwrap();
}
[package]
authors = ["Eloy Coto <[email protected]>"]
edition = "2018"
readme = "README.md"
name = "chrono"
version = "0.1.0"
[dependencies]
cortex-m = "0.7.2"
cortex-m-rt = "0.7.2"
cortex-m-semihosting = "0.3.3"
panic-halt = "0.2.0"
nb = "1"
embedded-hal = "0.2.7"
heapless = "0.7.16"
log = "0.4.17"
# Uncomment for the panic example.
# panic-itm = "0.4.1"
# Uncomment for the allocator example.
# alloc-cortex-m = "0.4.0"
# Uncomment for the device example.
# Update `memory.x`, set target to `thumbv7em-none-eabihf` in `.cargo/config`,
# and then use `cargo build --examples device` to build it.
# [dependencies.stm32f3]
# features = ["stm32f303", "rt"]
# version = "0.7.1"
[dependencies.stm32f4xx-hal]
version = "0.14.0"
features = ["stm32f410"]
[dependencies.stm32f4]
features = ["stm32f410", "rt"]
version = "0.15.1"
# this lets you use `cargo fix`!
[[bin]]
name = "chrono"
test = false
bench = false
[profile.release]
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
```
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
Setup:
```
rustup update
rustup component add llvm-tools-preview
rustup target add thumbv7em-none-eabihf
cargo install cargo-binutils cargo-embed cargo-flash cargo-expand
cargo install cargo-generate
```
arm-toolchain
```
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
```
Initialize:
```
https://docs.rust-embedded.org/book/start/qemu.html
```
```
cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart --name stm
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment