Rust starter for Daisy Seed

Hi chaosprint,

It seems like you have a problem building the stm32h7xx-hal crate and not the libdaisy-rust crate. What version of Rust are you using? Maybe you need to bump it up.

On another note, I don’t build with the nightly toolchain. Also, maybe try building another example, i.e. passthru. I know, that one worked for me.

This definitely doesn’t have anything to do with your revision of the board!

My rust version:

rustc 1.64.0 (a55dd71d5 2022-09-19)

If I don’t use nightly, there will be even more errors. I guess for embedded Rust to use nightly is quite common.
Now I disable the sdmmc feature and it compiles fine. But what would be the expected behaviour of the passthru example? I only have a headphone with me. It may be nice to have a testing sine tone.

I guess, delay, passthru and volume are the only examples with audio output. However, they depend on audio input. So you would need to have an audio source for that (like a phone or laptop).

I would like to use a customised DSP engine for playing the sound and I don’t need any input for now.

How can we create a variable to store the DSP engine?

I try to create the DSP instance during #[init], then return it to local:

let oscillator = SinOsc::new(440.0);
Local {
   oscillator
}

But in the audio_handler, when I call:

for _ in 0..1024 {
    let s = oscillator.next();
    audio.push_stereo((s, s)).unwrap();
}

No sound is played. Is it because I need to enable some features? Or any other reasons?

The audio callback should look something like this:

// Interrupt handler for audio
#[task(binds = DMA1_STR1, local = [audio, buffer, oscillator], priority = 8)] 
fn audio_handler(mut ctx: audio_handler::Context) {
    let audio = &mut ctx.local.audio;
    let buffer = &mut ctx.local.buffer;
    let oscillator = &mut ctx.local.oscillator;

    // this needs to be called
    audio.get_stereo(buffer);

    for _ in buffer {
        let s = oscillator.next();
        audio.push((s,s)).unwrap();
    }
}

audio.get_stereo(buffer) is mandatory. I never got it working, if I didn’t call this function.

And buffer should be initialized in the #[init] task like this:

let buffer = [(0.0, 0.0); audio::BLOCK_SIZE_MAX]; // audio ring buffer

I tried to simplify the code but it is still not working:

    #[task(binds = DMA1_STR1, shared = [], local = [audio, buffer, phase], priority = 8)]
    fn audio_handler(mut ctx: audio_handler::Context) {
        let audio = &mut ctx.local.audio;
        let buffer = &mut ctx.local.buffer;
        let phase = &mut ctx.local.phase;
        audio.get_stereo(buffer);
        for i in 0..buffer.len() {
            match i {
                0 => {
                    phase[i].0 = phase[phase.len()-1].0 + 440.0 / 48000.0;
                    phase[i].1 = phase[phase.len()-1].1 + 440.0 / 48000.0;
                },
                _ => {
                    phase[i].0 = phase[i-1].0 + 440.0 / 48000.0;
                    phase[i].1 = phase[i-1].1 + 440.0 / 48000.0;
                }
            }
            
            let l = libm::sin((phase[i].0 * 2.0 * core::f32::consts::PI).into()) as f32;
            let r = libm::sin((phase[i].1 * 2.0 * core::f32::consts::PI).into()) as f32;
            audio.push_stereo((l, r)).unwrap();
        };
    }

Here I have init phase exactly same as buffer, a stereo f32 tuple.
When I flash it, it seems that there is a very short time of beeping.
I am sure my HW connection is correct as I can play the DSP example from the browser programmer.

Hi, @backtail

I now further edit the audio.rs in src:

    /// Push data to the DMA buffer for output
    /// Call this once per sample per call to [get_stereo()](Audio#get_stereo)
    pub fn push_stereo(&mut self, data: (f32, f32)) -> Result<(), ()> {
        self.phase += 440.0 / 48000.0;
        let v = libm::sin((self.phase * 2.0 * core::f32::consts::PI).into()) as f32;
        if self.phase >= 1.0 {
            self.phase -= 1.0;
        }
        self.output.push((v, v))
    }

This should in theory overwrite the audio with a sin tone for the examples passthru or volume, but I just got a very short and low-volume beep, the same as the result from the code above. Since I don’t have a ST-LINK yet, what would be the cause in your opinion? Anyway, I would assume it’s good to add some sound synthesis in the example given the usage of Daisy Seed.

Does the Daisy Seed board expose SWD port that can be used with pico-probe

The Daisy Seed has a mini JTAG Header pins (2x5). Is that what you’re looking for your pico-probe? I haven’t used that type of probe before so I cannot concretely tell you that it would work with the Daisy.

Those pins are used for this debug probe by the way: ST LINK-V3 MINI Debugger — Electro-Smith (and you can see how it’s connected in the photo).

Ok thanks for the info. Assuming that it is this port: Documentation – Arm Developer and the reading that I have done, it should work out.

I will give it a try an report back here

How do you disable sdmmc?

This topic may help:

Daisy Seed Rev5 Rust Example

I can’t get the link in a post - error msg says 429 Too Many Requests

1 Like