antoinevg / daisy_bsp

Board support package for the Electro-Smith Daisy Seed.
MIT License
67 stars 13 forks source link

Midi audio example compiles but cannot compile the same code in my own project #12

Closed scynthero closed 1 year ago

scynthero commented 1 year ago

Hi! First thanks for this awesome crate. My problem is, that when i compile audio_midi example it works.

cargo build --example audio_midi --features="alloc, uses_num"

I copied necessary files (including Cargo.toml) to my own project that i started using hello daisy and cargo generate as per readme in daisy_bsp

cargo generate \
    --git https://github.com/antoinevg/hello-daisy \
    --name hello-daisy

When i try to compile it this way i'm getting error:

error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait

error: `#[alloc_error_handler]` function required, but not found

note: use `#![feature(default_alloc_error_handler)]` for a default error handler

error: `#[panic_handler]` function required, but not found

error: could not compile `daisy-midi` due to 3 previous errors

I don't really understand why, as the code is the same and so are the dependencies and features. I'm using rustc 1.67.0-nightly (c97b539e4 2022-11-30) and target thumbv7em-none-eabihf.

Hope someone can help, thanks.

antoinevg commented 1 year ago

I don't think I've update the hello-daisy repo in a while so it may be a bit behind daisy_bsp.

That said, two things to try:

1. Enable alloc feature:

The MIDI example requires daisy_bsp to be compiled with the alloc feature.

Try editing your Cargo.toml file to enable this feature for daisy_bsp:

daisy_bsp = { version = "0.5.1", features = ["seed", "alloc"]  }

2. Use a panic crate:

All Embedded Rust applications need a panic handler. The one you pick depends on what kind of logging interface you're using.

To get your example to compile you can just use the simplest one:

scynthero commented 1 year ago

Thanks a lot! The alloc feature for daisy_bsp fixed the problem. The panic handler part i fixed by using the one used in dev-dependencies.