Rust & Esp32

러스트 언어를 사용하여 esp32의 개발하는 방법에는

std 

esp32 보드의 회사인 Espressif에서 c언어 기반 ESP-IDF 프레임워크를 제공합니다. esp32 이후로 나오는 칩은 모두 지원할 예정이고 std인 만큼 rust standard library를 사용할 수 있습니다.

풍부한 라이브러리와 간편하게 제어할 수 있는 점이 강점입니다.

 

 

no_std

rust standard library 대신 rust core library를 사용할 수 있습니다. 러스트 코어는 스탠다드보다 더 기본적인 부분으로 스탠다드엔 당연히 코어가 포함되어 있어서 no_std로 만든 것은 std로 가져가서 컴파일할 수 있지만 반대의 경우엔 안됩니다. core인 만큼 필수적인 것만 포함되어 있어서 코드크기나 메모리사용량 등 경량화 부분에서 유리합니다.

 

 

https://docs.esp-rs.org/book/

 

Introduction - The Rust on ESP Book

The goal of this book is to provide a comprehensive guide on using the Rust Programming Language with Espressif devices. Rust support for these devices is still a work in progress, and progress is being made rapidly. Because of this, parts of this document

docs.esp-rs.org

 

위 웹사이트에서 no_std는 제한된 임베디드 시스템상황에서 메모리 사용량이 적어야 하는경우,

낮은 수준의 장치 즉 하드웨어에 더 직접적인 제어가 필요한 경우, std가 성능에 영향을 미칠 수 있는 지연을 유발할 수 있으므로 실시간 성능 또는 낮은 응답 지연시간이 필요한 경우 사용하라고 나와 있다.

 

두 가지  써본 결과 확실히 빌드부터 플래시까지 no_std가 훨씬 빠른 속도로 진행되었다.

 

 

 


 

 

 


Rust로 ESP32 보드 개발환경 구축하기 위해 필요한 준비물


 

Rust Programming Language

A language empowering everyone to build reliable and efficient software.

www.rust-lang.org

러스트

 

 

 

Visual Studio Code - Code Editing. Redefined

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

code.visualstudio.com

IDE

vscode 사용 시 확장프로그램으로

 

rust

rust-analyzer

rust syntax

 

위 세 가지를 설치해 주세요.

 

 

 

 

std의 경우

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html

 

Standard Setup of Toolchain for Windows - ESP32 - — ESP-IDF Programming Guide latest documentation

After opening a new project, you should first set the target with idf.py set-target esp32. Note that existing builds and configurations in the project, if any, are cleared and initialized in this process. The target may be saved in the environment variable

docs.espressif.com

ESP-IDF를 설치해주어야 합니다. ESP-IDF 이외에 파이썬이나 git도 설치가 필요합니다.

설치가 끝나면 콘솔 터미널을 열어 필요한 도구들을 설치해 주세요.

cargo install ldproxy
cargo install cargo-generate
cargo install cargo-espflash

 

 

 

 

no_std의 경우

cargo install espup
espup install
cargo install cargo-generate
cargo install cargo-espflash

 

 

 

 


 

 

 


Cargo-generate를 이용해 템플릿에서 프로젝트 생성


 

 

std의 경우

cargo generate esp-rs/esp-idf-template cargo

 

 

 

no_std의 경우

cargo generate esp-rs/esp-template

 


 

프로젝트 이름을 정하고 사용 할 칩을 선택합니다.
기본 적인 경우엔 false로 넘어갑니다.
템플릿이 만들어 졌습니다.
생성된 템플릿

만들어진 템플릿에는 hello world! 를 출력한 후 계속 루프를 돌게 되어 있습니다.

가장 기본적인 모습으로 개발할 때마다 위 템플릿으로 받아 시작하게 됩니다.

 

이제 보드를 연결해 빌드 및 플래시까지 진행해 봅니다.

cargo espflash flash --monitor

시리얼 포트를 정해준 후 보드의 boot 버튼을 누르고 있는다.

포트는 하나만 있으면 자동으로 선택되지만 여러 개를 사용할 경우 몇 번 포트인지 물어봅니다.

Connecting.. 이 나올 때 esp32 보드의 두 개의 버튼 중 boot버튼을 잠깐 눌렀다가

Using flash stub에 손을 때 주면 됩니다.

 

 

간단히 보드의 스펙과 플래싱 과정이 나온다.

--monitor 옵션을 꼭 넣어줘야 IDE에서 모니터링 가능

 

 

 

 


 

 

 

esp32를 rust로 개발하기 위한 환경

esp32 보드 중 제일 기본인 esp32를 가지고 있고

러스트 코어만 가지고 해 보기로 했는데

 

esp-rs.org의 예제들이 모두 esp-32-c3를 이용한 예제들이었다.

 

esp32, esp32S시리즈  <- xtensa 아키텍처

esp32C시리즈 <- RISC-V 아키텍처

 

사용하는 툴체인이 다르고, 지원하는 크레이트가 달라 와이파이 연결등 삽질을 많이 했기때문에

esp32를 구매하고자 하시는 분은 C시리즈 구매하는 것을 추천드립니다.

앞으로 블로그에 올라오는 esp32 예제는

 

no_std

xtensa-esp32-none-elf

 

C시리즈를 사용하시는 분은 esp-rs.org에 자세한 예제들이 많습니다.

https://docs.esp-rs.org/book/writing-your-own-application/nostd.html

 

Writing no_std Applications - The Rust on ESP Book

If you want to learn how to develop no_std application, see the following training materials: The training is based on ESP32-C3-DevKit-RUST-1. You can use any other Espressif development board but code changes and configuration changes might be needed. The

docs.esp-rs.org

 

 

 


 

esp32 보드에서 rust를 이용해 GPIO 조작해 보기

https://3d-storyge.tistory.com/24

 

[Rust와 ESP32] Rust로 ESP32 보드 GPIO 제어하기

esp32 보드에서 Rust 언어로 GPIO를 제어하는 방법 #![no_std] #![no_main] use esp32_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, IO}; use esp_backtrace as _; use esp_println::println; 기본 템플릿에서 esp32_hal

3d-storyge.tistory.com

 

아키텍처 간의 차이, esp32 구입 시 유의할 점

https://3d-storyge.tistory.com/25

 

[Rust와 ESP32] esp32-hal모듈과 아키텍처 차이, esp32구입은 최신시리즈로.

Cargo generate를 사용해 템플릿 생성 시 esp32-hal을 사용하도록 되어 있다. https://docs.rs/esp32-hal/latest/esp32_hal/# esp32_hal - Rust no_std HAL for the ESP32 from Espressif. Implements a number of the traits defined by the various pac

3d-storyge.tistory.com

 


 

  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기