-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathglobal_alloc.rs
More file actions
41 lines (30 loc) · 917 Bytes
/
global_alloc.rs
File metadata and controls
41 lines (30 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#![no_std]
#![no_main]
extern crate alloc;
use cortex_m as _;
use cortex_m_rt::entry;
use defmt_semihosting as _;
use core::panic::PanicInfo;
// Linked-List First Fit Heap allocator (feature = "llff")
use embedded_alloc::LlffHeap as Heap;
// Two-Level Segregated Fit Heap allocator (feature = "tlsf")
// use embedded_alloc::TlsfHeap as Heap;
#[global_allocator]
static HEAP: Heap = Heap::empty();
#[entry]
fn main() -> ! {
// Initialize the allocator BEFORE you use it
unsafe {
embedded_alloc::init!(HEAP, 1024);
}
let vec = alloc::vec![1];
defmt::info!("Allocated vector: {:?}", vec.as_slice());
let string = alloc::string::String::from("Hello, world!");
defmt::info!("Allocated string: {:?}", string.as_str());
semihosting::process::exit(0);
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
defmt::error!("{}", info);
semihosting::process::exit(-1);
}