From 98dbe9989bf8029ce06996d234cdb6eb2c6c0bb0 Mon Sep 17 00:00:00 2001 From: Adam Green Date: Sat, 17 Nov 2018 00:07:51 -0800 Subject: [PATCH] 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. --- src/start/panicking.md | 2 +- src/start/registers.md | 7 +++++-- src/start/semihosting.md | 8 ++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/start/panicking.md b/src/start/panicking.md index 139d09f..9e7626b 100644 --- a/src/start/panicking.md +++ b/src/start/panicking.md @@ -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 {} } diff --git a/src/start/registers.md b/src/start/registers.md index c963154..b909b31 100644 --- a/src/start/registers.md +++ b/src/start/registers.md @@ -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 {} } ``` diff --git a/src/start/semihosting.md b/src/start/semihosting.md index 6ebf25e..3a7d6dd 100644 --- a/src/start/semihosting.md +++ b/src/start/semihosting.md @@ -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