Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sirhcel
Created January 23, 2022 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirhcel/831b7ee3f53940676a4445c77407db36 to your computer and use it in GitHub Desktop.
Save sirhcel/831b7ee3f53940676a4445c77407db36 to your computer and use it in GitHub Desktop.
Attempt of simple example for ledc driver
use embedded_hal::{
pwm::blocking::PwmPin,
delay::blocking::DelayUs,
};
use esp_idf_hal::delay::Ets;
use esp_idf_hal::ledc::{
config::TimerConfig,
Channel,
Timer,
};
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::prelude::*;
use esp_idf_sys::EspError;
fn main() -> anyhow::Result<()> {
let peripherals = Peripherals::take().unwrap();
let config = TimerConfig::default().frequency(25.kHz().into());
let timer = Timer::new(peripherals.ledc.timer0, &config)?;
let mut channel = Channel::new(peripherals.ledc.channel0, &timer, peripherals.pins.gpio1)?;
let max_duty = channel.get_max_duty()?;
for numerator in [0, 1, 2, 3, 4, 5].iter().cycle() {
channel.set_duty(max_duty * numerator / 5)?;
Ets.delay_ms(2000)?;
}
Ok(())
}
@sirhcel
Copy link
Author

sirhcel commented Jan 23, 2022

  • As an additional binary in rust-esp32-std-demo/src/bin/ledc-simple.rs
  • Build
    rust-esp32-std-demo $ cargo build --bin ledc-simple
       Compiling rust-esp32-std-demo v0.22.1 (/[...]/rust-esp32-std-demo)
    [...]
    error: linking with `ldproxy` failed: exit status: 1
    [...]
          = note: Running ldproxy
              Error: Linker /[...]/rust-esp32-std-demo/.embuild/platformio/packages/toolchain-riscv32-esp/bin/riscv32-esp-elf-gcc failed: exit status: 1
          STDERR OUTPUT:
              /[...]/rust-esp32-std-demo/.embuild/platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: /Users/christian/Entwicklung/rust/moisture-control/rust-esp32-std-demo/target/riscv32imc-esp-espidf/debug/deps/libstd-1a8e956410aa5a11.rlib(std-1a8e956410aa5a11.std.78656cc7-cgu.4.rcgu.o): in function `std::sys::unix::rwlock::RWLock::read':
              /[...]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/unix/rwlock.rs:25: undefined reference to `pthread_rwlock_rdlock'
              /[...]/rust-esp32-std-demo/.embuild/platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: /[...]/rust-esp32-std-demo/target/riscv32imc-esp-espidf/debug/deps/libstd-1a8e956410aa5a11.rlib(std-1a8e956410aa5a11.std.78656cc7-cgu.4.rcgu.o): in function `std::sys::unix::rwlock::RWLock::raw_unlock':
              /[...]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/unix/rwlock.rs:114: undefined reference to `pthread_rwlock_unlock'
          collect2: error: ld returned 1 exit status
    
      = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
      = note: use the `-l` flag to specify native libraries to link
      = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
    
    warning: `rust-esp32-std-demo` (bin "ledc-simple") generated 1 warning
    error: could not compile `rust-esp32-std-demo` due to previous error; 1 warning emitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment