File tree Expand file tree Collapse file tree 4 files changed +52
-50
lines changed Expand file tree Collapse file tree 4 files changed +52
-50
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ description = "A heap allocator for Cortex-M processors"
9
9
repository = " https://github.com/rust-embedded/alloc-cortex-m"
10
10
documentation = " https://docs.rs/alloc-cortex-m"
11
11
readme = " README.md"
12
+ edition = " 2018"
12
13
13
14
keywords = [
14
15
" allocator" ,
@@ -25,3 +26,6 @@ cortex-m = "0.1.5"
25
26
[dependencies .linked_list_allocator ]
26
27
default-features = false
27
28
version = " 0.8.1"
29
+
30
+ [dev-dependencies ]
31
+ cortex-m-rt = " 0.6.12"
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
1
3
set -euxo pipefail
2
4
3
5
main () {
4
- cargo check --target $TARGET
6
+ cargo check --target " $TARGET "
7
+
8
+ if [ " $TARGET " != x86_64-unknown-linux-gnu ]; then
9
+ cargo build --target " $TARGET " --examples
10
+ fi
5
11
}
6
12
7
13
main
Original file line number Diff line number Diff line change
1
+ #![ no_std]
2
+ #![ no_main]
3
+ #![ feature( alloc_error_handler) ]
4
+
5
+ extern crate alloc;
6
+
7
+ use core:: panic:: PanicInfo ;
8
+ use core:: alloc:: Layout ;
9
+ use alloc:: vec:: Vec ;
10
+ use alloc_cortex_m:: CortexMHeap ;
11
+ use cortex_m_rt:: entry;
12
+
13
+ #[ global_allocator]
14
+ static ALLOCATOR : CortexMHeap = CortexMHeap :: empty ( ) ;
15
+
16
+ #[ entry]
17
+ fn main ( ) -> ! {
18
+ // Initialize the allocator BEFORE you use it
19
+ let start = cortex_m_rt:: heap_start ( ) as usize ;
20
+ let size = 1024 ; // in bytes
21
+ unsafe { ALLOCATOR . init ( start, size) }
22
+
23
+ let mut xs = Vec :: new ( ) ;
24
+ xs. push ( 1 ) ;
25
+
26
+ loop { /* .. */ }
27
+ }
28
+
29
+ #[ alloc_error_handler]
30
+ fn oom ( _: Layout ) -> ! {
31
+ loop { }
32
+ }
33
+
34
+ #[ panic_handler]
35
+ fn panic ( _: & PanicInfo ) -> ! {
36
+ loop { }
37
+ }
Original file line number Diff line number Diff line change 1
- //! A heap allocator for Cortex-M processors
1
+ //! A heap allocator for Cortex-M processors.
2
2
//!
3
- //! # Example
4
- //!
5
- //! ```
6
- //! #![feature(alloc)]
7
- //! #![feature(global_allocator)]
8
- //! #![feature(lang_items)]
9
- //!
10
- //! // Plug in the allocator crate
11
- //! extern crate alloc;
12
- //! extern crate alloc_cortex_m;
13
- //! #[macro_use]
14
- //! extern crate cortex_m_rt as rt; // v0.5.x
15
- //!
16
- //! use alloc::Vec;
17
- //! use alloc_cortex_m::CortexMHeap;
18
- //!
19
- //! #[global_allocator]
20
- //! static ALLOCATOR: CortexMHeap = CortexMHeap::empty();
21
- //!
22
- //! entry!(main);
23
- //!
24
- //! fn main() -> ! {
25
- //! // Initialize the allocator BEFORE you use it
26
- //! let start = rt::heap_start() as usize;
27
- //! let size = 1024; // in bytes
28
- //! unsafe { ALLOCATOR.init(start, size) }
29
- //!
30
- //! let mut xs = Vec::new();
31
- //! xs.push(1);
32
- //!
33
- //! loop { /* .. */ }
34
- //! }
35
- //!
36
- //! // required: define how Out Of Memory (OOM) conditions should be handled
37
- //! // *if* no other crate has already defined `oom`
38
- //! #[lang = "oom"]
39
- //! #[no_mangle]
40
- //! pub fn rust_oom() -> ! {
41
- //! // ..
42
- //! }
3
+ //! Note that using this as your global allocator requires nightly Rust.
43
4
//!
5
+ //! # Example
44
6
//!
45
- //! // omitted: exception handlers
46
- //! ```
7
+ //! For a usage example, see `examples/global_alloc.rs`.
47
8
48
- #![ feature( allocator_api) ]
49
- #![ feature( const_fn) ]
50
9
#![ no_std]
51
10
52
- extern crate alloc;
53
- extern crate cortex_m;
54
- extern crate linked_list_allocator;
55
-
56
11
use core:: alloc:: { GlobalAlloc , Layout } ;
57
12
use core:: ptr:: NonNull ;
58
13
You can’t perform that action at this time.
0 commit comments