|
16 | 16 | //!
|
17 | 17 | //! - An opt-in linker script (`"linker-script"` Cargo feature) that encodes
|
18 | 18 | //! the memory layout of a generic Cortex-M microcontroller. This linker
|
19 |
| -//! script is missing the definition of the FLASH and RAM memory regions of |
20 |
| -//! the device. This missing information must be supplied through a `memory.x` |
21 |
| -//! linker script of the form: |
22 |
| -//! |
23 |
| -//! ``` text |
24 |
| -//! MEMORY |
25 |
| -//! { |
26 |
| -//! FLASH : ORIGIN = 0x08000000, LENGTH = 128K |
27 |
| -//! RAM : ORIGIN = 0x20000000, LENGTH = 8K |
28 |
| -//! } |
29 |
| -//! ``` |
| 19 | +//! script is missing the definitions of the FLASH and RAM memory regions of |
| 20 | +//! the device and of the `_stack_start` symbol (address where the call stack |
| 21 | +//! is allocated). This missing information must be supplied through a |
| 22 | +//! `memory.x` file (see example below). |
30 | 23 | //!
|
31 | 24 | //! - A default exception handler tailored for debugging and that provides
|
32 | 25 | //! access to the stacked registers under the debugger. By default, all
|
|
77 | 70 | //!
|
78 | 71 | //! $ cargo add cortex-m cortex-m-rt
|
79 | 72 | //!
|
80 |
| -//! $ cat Xargo.toml |
| 73 | +//! $ edit Xargo.toml && cat $_ |
81 | 74 | //! ```
|
82 | 75 | //!
|
83 | 76 | //! ``` text
|
|
90 | 83 | //! ```
|
91 | 84 | //!
|
92 | 85 | //! ``` text
|
93 |
| -//! $ cat memory.x |
| 86 | +//! $ edit memory.x && cat $_ |
94 | 87 | //! ```
|
95 | 88 | //!
|
96 | 89 | //! ``` text
|
|
99 | 92 | //! FLASH : ORIGIN = 0x08000000, LENGTH = 128K
|
100 | 93 | //! RAM : ORIGIN = 0x20000000, LENGTH = 8K
|
101 | 94 | //! }
|
| 95 | +//! |
| 96 | +//! /* This is where the call stack will be allocated */ |
| 97 | +//! _stack_start = ORIGIN(RAM) + LENGTH(RAM); |
102 | 98 | //! ```
|
103 | 99 | //!
|
104 | 100 | //! ``` text
|
105 |
| -//! $ cat src/main.rs |
| 101 | +//! $ edit src/main.rs && cat $_ |
106 | 102 | //! ```
|
107 | 103 | //!
|
108 | 104 | //! ``` ignore,no_run
|
|
113 | 109 | //! extern crate cortex_m;
|
114 | 110 | //! extern crate cortex_m_rt;
|
115 | 111 | //!
|
| 112 | +//! use cortex_m::asm; |
| 113 | +//! |
116 | 114 | //! fn main() {
|
117 | 115 | //! hprintln!("Hello, world!");
|
118 | 116 | //! }
|
119 | 117 | //!
|
| 118 | +//! // As we are not using interrupts, we just register a dummy catch all handler |
120 | 119 | //! #[allow(dead_code)]
|
121 | 120 | //! #[link_section = ".rodata.interrupts"]
|
122 | 121 | //! #[used]
|
123 |
| -//! static INTERRUPTS: [u32; 240] = [0; 240]; |
| 122 | +//! static INTERRUPTS: [extern "C" fn(); 240] = [default_handler; 240]; |
| 123 | +//! |
| 124 | +//! extern "C" fn default_handler() { |
| 125 | +//! asm::bkpt(); |
| 126 | +//! } |
124 | 127 | //! ```
|
125 | 128 | //!
|
126 | 129 | //! ``` text
|
127 |
| -//! $ xargo rustc --target thumbv7m-none-eabi -- -C link-args='-Tlink.x -nostartfiles' |
| 130 | +//! $ cargo install xargo |
| 131 | +//! |
| 132 | +//! $ xargo rustc --target thumbv7m-none-eabi -- \ |
| 133 | +//! -C link-arg=-Tlink.x -C linker=arm-none-eabi-ld -Z linker-flavor=ld |
128 | 134 | //!
|
129 | 135 | //! $ arm-none-eabi-objdump -Cd $(find target -name app) | less
|
130 | 136 | //! 08000000 <_VECTOR_TABLE>:
|
131 | 137 | //! 8000000: 20002000 .word 0x20002000
|
132 | 138 | //!
|
133 | 139 | //! 08000004 <cortex_m_rt::RESET_HANDLER>:
|
134 |
| -//! 8000004: 08000671 q... |
| 140 | +//! 8000004: 0800065f _... |
135 | 141 | //!
|
136 | 142 | //! 08000008 <cortex_m_rt::EXCEPTIONS>:
|
137 |
| -//! 8000008: 080005a5 080005bd 08000569 08000599 ........i....... |
138 |
| -//! 8000018: 08000581 00000000 00000000 00000000 ................ |
139 |
| -//! 8000028: 00000000 080005b1 00000000 00000000 ................ |
140 |
| -//! 8000038: 0800058d 08000575 ....u... |
| 143 | +//! 8000008: 08000585 0800058f 080005a3 08000571 ............q... |
| 144 | +//! 8000018: 0800057b 00000000 00000000 00000000 {............... |
| 145 | +//! 8000028: 00000000 08000567 00000000 00000000 ....g........... |
| 146 | +//! 8000038: 080005ad 08000599 ........ |
141 | 147 | //! ```
|
142 | 148 |
|
143 | 149 | #![deny(missing_docs)]
|
|
0 commit comments