-
Hello, I saw this earlier discussion and followed it as reference, but a lot has changed in the last year: #1596 I've tried with both an ESP32 WROOM and ESP32-C3 (super mini board) and have gotten the same error on both boards. I confirmed the microphone is functional and wired up correctly by flashing an example Arduino sketch to the same board. The error is occurring on the unwrap of Thank you in advance for any assistance! Here is my setup and the error: #![no_std]
#![no_main]
use embassy_executor::Spawner;
use esp_backtrace as _;
use esp_hal::clock::CpuClock;
use esp_hal::dma_buffers;
use esp_hal::i2s::master::{DataFormat, I2s, Standard};
use esp_hal::{time::RateExtU32, timer::systimer::SystemTimer};
use esp_hal_embassy::main;
use esp_println::println;
use log::info;
extern crate alloc;
// DMA buffer size
const I2S_BYTES: usize = 4092;
#[main]
async fn main(_spawner: Spawner) {
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(72 * 1024);
esp_println::logger::init_logger_from_env();
let timer0 = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(timer0.alarm0);
info!("Embassy initialized!");
let bclk = peripherals.GPIO0; // sck - purple
let din = peripherals.GPIO2; // sd - black
let ws = peripherals.GPIO1; // ws - blue
let dma_channel = peripherals.DMA_CH0;
let (mut rx_buffer, rx_descriptors, _, tx_descriptors) = dma_buffers!(0, 4 * I2S_BYTES);
let i2s = I2s::new(
peripherals.I2S0,
Standard::Philips,
DataFormat::Data32Channel32,
44100.Hz(),
dma_channel,
rx_descriptors,
tx_descriptors,
);
let mut i2s_rx = i2s.i2s_rx.with_bclk(bclk).with_ws(ws).with_din(din).build();
let mut transfer = i2s_rx.read_dma_circular(&mut rx_buffer).unwrap();
loop {
let avail = transfer.available().unwrap();
if avail > 0 {
let mut rcv = [0u8; 5000];
transfer.pop(&mut rcv[..avail]).unwrap();
println!("{:?}", &rcv[..avail]);
}
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
A few things to note here:
|
Beta Was this translation helpful? Give feedback.
-
But I have to admit the panic is quite confusing and misleading |
Beta Was this translation helpful? Give feedback.
A few things to note here:
let (mut rx_buffer, rx_descriptors, _, tx_descriptors) = dma_buffers!(0, 4 * I2S_BYTES);
- you are creating an RX buffer of size 0 - that's the problem here, you probably wantlet (mut rx_buffer, rx_descriptors, _, tx_descriptors) = dma_buffers!(4 * I2S_BYTES, 0);
(note the changed order of parameters)println!("{:?}", &rcv[..avail]);
is pretty slow and will result in a situation where you won't be able to pop the read data fast enough - for this simple example you can work around by just printing a smaller part of the buffer, e.g.prin…