rp-rs / rp2040-project-template

A basic rp2040-hal project with blinky and rtt logging example code. With this you can quickly get started on a new rp2040 project
480 stars 98 forks source link

Is it possible to use the alloc crate? #63

Closed colossalchicken closed 1 year ago

colossalchicken commented 1 year ago

Is it possible to use the alloc crate on the RP2040?

jannic commented 1 year ago

Yes, that should be possible. But you need to add and initialize a global allocator, otherwise you'll get the following error message:

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

One global allocator you could use is embedded-alloc. The example given in https://github.com/rust-embedded/embedded-alloc/blob/master/examples/global_alloc.rs shows what you need to add to your main function to make it work.

colossalchicken commented 1 year ago

Thanks!