Trying to use an SPI epaper display gets stuck somewhere #2754
-
Hello, I am making a project on an esp32 (esp-wroom-32, My suspicion is that there's some kind of deadlock happening but I don't know why or how. My #![no_std]
#![no_main]
use core::cell::RefCell;
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use embedded_graphics::{
prelude::{Point, Primitive},
primitives::{Line, PrimitiveStyle},
Drawable,
};
use embedded_hal_bus::spi::RefCellDevice;
use esp_backtrace as _;
use esp_hal::{
gpio::{Input, Level, NoPin, Output, Pull},
peripherals::SPI2,
prelude::*,
spi::{
master::{Config, Spi},
SpiMode,
},
Blocking,
};
use log::info;
extern crate alloc;
use epd_waveshare::{epd2in9bc::*, prelude::*};
#[main]
async fn main(spawner: Spawner) {
let peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
config
});
esp_alloc::heap_allocator!(72 * 1024);
//let mut delay = embassy_time::Delay;
let mut delay = esp_hal::delay::Delay::new();
esp_println::logger::init_logger_from_env();
let timer0 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1);
esp_hal_embassy::init(timer0.timer0);
info!("Embassy initialized!");
/*
let timer1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0);
let _init = esp_wifi::init(
timer1.timer0,
esp_hal::rng::Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
)
.unwrap();
*/
info!("Initializing pins");
let cs = Output::new_typed(peripherals.GPIO5, Level::High);
let busy_in = Input::new_typed(peripherals.GPIO4, Pull::None);
let rst = Output::new_typed(peripherals.GPIO16, Level::High);
let dc = Output::new_typed(peripherals.GPIO17, Level::Low);
info!("Initializing spi bus");
let spi_bus: Spi<'static, Blocking, SPI2> = Spi::new_typed_with_config(
peripherals.SPI2,
Config {
frequency: 8.MHz(),
mode: SpiMode::Mode0,
..Config::default()
},
)
//.with_cs(peripherals.GPIO5)
.with_sck(peripherals.GPIO18)
.with_mosi(peripherals.GPIO23)
.with_miso(NoPin)
.with_cs(NoPin);
let spi_bus = RefCell::new(spi_bus);
info!("Initializing spi device");
//let mut spi = SpiDevice::new(spi_bus, Output::new(peripherals.GPIO5, Level::High));
let mut spi = RefCellDevice::new(&spi_bus, cs, delay).unwrap();
info!("Initializing epd");
let mut epd =
Epd2in9bc::new(&mut spi, busy_in, dc, rst, &mut delay, None).expect("EPD creation error");
info!("Drawing");
let mut mono_display = Display2in9bc::default();
mono_display.set_rotation(DisplayRotation::Rotate90);
let _ = Line::new(Point::new(0, 120), Point::new(0, 200))
.into_styled(PrimitiveStyle::with_stroke(Color::Black, 1))
.draw(&mut mono_display);
let mut chromatic_display = Display2in9bc::default();
chromatic_display.set_rotation(DisplayRotation::Rotate90);
let _ = Line::new(Point::new(15, 120), Point::new(15, 200))
.into_styled(PrimitiveStyle::with_stroke(Color::Black, 1))
.draw(&mut chromatic_display);
info!("Updating color frame");
epd.update_color_frame(
&mut spi,
&mut delay,
mono_display.buffer(),
chromatic_display.buffer(),
)
.unwrap();
epd.display_frame(&mut spi, &mut delay).unwrap();
info!("Pre sleep");
epd.sleep(&mut spi, &mut delay).unwrap();
info!("Post sleep");
// TODO: Spawn some tasks
let _ = spawner;
loop {
info!("Hello world!");
Timer::after(Duration::from_secs(1)).await;
}
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/v0.22.0/examples/src/bin
} And these are the crate versions used: [dependencies]
esp-backtrace = { version = "0.14.2", features = [
"esp32",
"exception-handler",
"panic-handler",
"println",
]}
esp-hal = { version = "0.22.0", features = [
"esp32",
] }
esp-println = { version = "0.12.0", features = ["esp32", "log"] }
log = { version = "0.4.21" }
esp-alloc = { version = "0.5.0" }
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
embassy-net = { version = "0.4.0", features = [ "tcp", "udp", "dhcpv4", "medium-ethernet"] }
esp-wifi = { version = "0.11.0", default-features=false, features = [
"esp32",
"utils",
"wifi",
"esp-alloc",
"log",
] }
heapless = { version = "0.8.0", default-features = false }
smoltcp = { version = "0.11.0", default-features = false, features = [
"medium-ethernet",
"proto-dhcpv4",
"proto-igmp",
"proto-ipv4",
"socket-dhcpv4",
"socket-icmp",
"socket-raw",
"socket-tcp",
"socket-udp",
] }
embassy-executor = { version = "0.6.0", features = [
"task-arena-size-12288",
] }
embassy-time = { version = "0.3.1", features = ["generic-queue-8"] }
esp-hal-embassy = { version = "0.5.0", features = ["esp32"] }
static_cell = { version = "2.1.0", features = ["nightly"] }
critical-section = "1.2.0"
epd-waveshare = "0.6.0"
embedded-graphics = "0.8.1"
embassy-embedded-hal = "0.2.0"
embassy-sync = "0.6.1"
embedded-hal-bus = "0.2.0" I am using embassy because I intend to also use wifi to make a small desktop calendar. What am I doing wrong? Please help me with this problem, I don't know what is going on on the inside and don't know how to debug to see the exact point the board gets stuck at. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
First, a real long shot based on an issue I currently have - how do you know it gets stuck? Because you don't see the If it's not that, then inside the init there's a |
Beta Was this translation helpful? Give feedback.
-
Doing this doesn't stop the program from hanging in the same place.
A project by another person, I've used it to try and tweak my code in some places: https://github.com/GnomedDev/epaper-simplyplural-badge/blob/0440c798289a3b36dcfb42f4938d9fc3a9111da9/src/main.rs#L92
|
Beta Was this translation helpful? Give feedback.
Yeah, this is an issue with the display driver library, I've opened an issue on their repository now that captures my latest findings in an clean form: caemor/epd-waveshare#226