The challenge

You are now well armed to face a challenge! Your task will be to implement the application I showedyou at the beginning of this chapter.

Here’s the GIF again:

The challenge - 图1

Also, this may help:

The challenge - 图2

This is a timing diagram. It indicates which LED is on at any given instant of time and for how longeach LED should be on. On the X axis we have the time in milliseconds. The timing diagram shows asingle period. This pattern will repeat itself every 800 ms. The Y axis labels each LED with acardinal point: North, East, etc. As part of the challenge you’ll have to figure out how eachelement in the Leds array maps to these cardinal points (hint: cargo doc --open ;-)).

Before you attempt this challenge, let me give you one last tip. Our GDB sessions always involveentering the same commands at the beginning. We can use a .gdb file to execute some commandsright after GDB is started. This way you can save yourself the effort of having to enter themmanually on each GDB session.

Place this openocd.gdb file in the root of the Cargo project, right next to the Cargo.toml:

  1. $ cat openocd.gdb
  1. target remote :3333
  2. load
  3. break main
  4. continue

Then modify the second line of the .cargo/config file:

  1. $ cat .cargo/config
  1. [target.thumbv7em-none-eabihf]
  2. runner = "arm-none-eabi-gdb -q -x openocd.gdb" # <-
  3. rustflags = [
  4. "-C", "link-arg=-Tlink.x",
  5. ]

With that in place, you should now be able to start a gdb session that will automatically flashthe program and jump to the beginning of main:

  1. $ cargo run --target thumbv7em-none-eabihf
  2. Running `arm-none-eabi-gdb -q -x openocd.gdb target/thumbv7em-none-eabihf/debug/led-roulette`
  3. Reading symbols from target/thumbv7em-none-eabihf/debug/led-roulette...done.
  4. (..)
  5. Loading section .vector_table, size 0x188 lma 0x8000000
  6. Loading section .text, size 0x3b20 lma 0x8000188
  7. Loading section .rodata, size 0xb0c lma 0x8003cc0
  8. Start address 0x8003b1c, load size 18356
  9. Transfer rate: 20 KB/sec, 6118 bytes/write.
  10. Breakpoint 1 at 0x800018c: file src/05-led-roulette/src/main.rs, line 9.
  11. Note: automatically using hardware breakpoints for read-only addresses.
  12. Breakpoint 1, main () at src/05-led-roulette/src/main.rs:9
  13. 9 let (mut delay, mut leds): (Delay, Leds) = aux5::init();
  14. (gdb)