Chapter 2 code sample fixes

These fixes get code samples to compile without warnings. Other changes
include:
* Fix the SysTick code snippet on the "Memory Mapped Registers" page so
  that it:
  * Compiles without errors/warnings.
  * Sets up the SysTick peripheral correctly for counting down 1000
    ticks.
* Added a reminder in the "Semihosting" section about how to enable
  semihosting in openOCD.
This commit is contained in:
Adam Green
2018-11-17 00:07:51 -08:00
parent c5caa3b72d
commit 98dbe9989b
3 changed files with 12 additions and 5 deletions

View File

@@ -81,7 +81,7 @@ use cortex_m_rt::entry;
fn main() -> ! {
let xs = [0, 1, 2];
let i = xs.len() + 1;
let y = xs[i]; // out of bounds access
let _y = xs[i]; // out of bounds access
loop {}
}

View File

@@ -26,15 +26,18 @@ use cortex_m::peripheral::{syst, Peripherals};
use cortex_m_rt::entry;
#[entry]
fn main() {
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let mut systick = peripherals.SYST;
systick.set_clock_source(syst::SystClkSource::Core);
systick.set_reload(1_000);
systick.clear_current();
systick.enable_counter();
while systick.get_current() < 1_000 {
while !systick.has_wrapped() {
// Loop
}
loop {}
}
```

View File

@@ -18,8 +18,6 @@ world!":
extern crate panic_halt;
use core::fmt::Write;
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
@@ -41,6 +39,12 @@ Hello, world!
(..)
```
You do need to enable semihosting in OpenOCD from GDB first:
``` console
(gdb) monitor arm semihosting enable
semihosting is enabled
```
QEMU understands semihosting operations so the above program will also work with
`qemu-system-arm` without having to start a debug session. Note that you'll
need to pass the `-semihosting-config` flag to QEMU to enable semihosting