My solution

What solution did you come up with?

Here’s mine:

  1. #![deny(unsafe_code)]
  2. #![no_main]
  3. #![no_std]
  4. use aux5::{entry, prelude::*, Delay, Leds};
  5. #[entry]
  6. fn main() -> ! {
  7. let (mut delay, mut leds): (Delay, Leds) = aux5::init();
  8. let ms = 50_u8;
  9. loop {
  10. for curr in 0..8 {
  11. let next = (curr + 1) % 8;
  12. leds[next].on();
  13. delay.delay_ms(ms);
  14. leds[curr].off();
  15. delay.delay_ms(ms);
  16. }
  17. }
  18. }

One more thing! Check that your solution also works when compiled in “release” mode:

  1. $ cargo build --target thumbv7em-none-eabihf --release

You can test it with this gdb command:

  1. $ # or, you could simply call `cargo run --target thumbv7em-none-eabihf --release`
  2. $ arm-none-eabi-gdb target/thumbv7em-none-eabihf/release/led-roulette
  3. $ # ~~~~~~~

Binary size is something we should always keep an eye on! How big is your solution? You can checkthat using the size command on the release binary:

  1. $ # equivalent to size target/thumbv7em-none-eabihf/debug/led-roulette
  2. $ cargo size --target thumbv7em-none-eabihf --bin led-roulette -- -A
  3. led-roulette :
  4. section size addr
  5. .vector_table 392 0x8000000
  6. .text 16404 0x8000188
  7. .rodata 2924 0x80041a0
  8. .data 0 0x20000000
  9. .bss 4 0x20000000
  10. .debug_str 602185 0x0
  11. .debug_abbrev 24134 0x0
  12. .debug_info 553143 0x0
  13. .debug_ranges 112744 0x0
  14. .debug_macinfo 86 0x0
  15. .debug_pubnames 56467 0x0
  16. .debug_pubtypes 94866 0x0
  17. .ARM.attributes 58 0x0
  18. .debug_frame 174812 0x0
  19. .debug_line 354866 0x0
  20. .debug_loc 534 0x0
  21. .comment 75 0x0
  22. Total 1993694
  23. $ cargo size --target thumbv7em-none-eabihf --bin led-roulette --release -- -A
  24. led-roulette :
  25. section size addr
  26. .vector_table 392 0x8000000
  27. .text 1826 0x8000188
  28. .rodata 84 0x80008ac
  29. .data 0 0x20000000
  30. .bss 4 0x20000000
  31. .debug_str 23334 0x0
  32. .debug_loc 6964 0x0
  33. .debug_abbrev 1337 0x0
  34. .debug_info 40582 0x0
  35. .debug_ranges 2936 0x0
  36. .debug_macinfo 1 0x0
  37. .debug_pubnames 5470 0x0
  38. .debug_pubtypes 10016 0x0
  39. .ARM.attributes 58 0x0
  40. .debug_frame 164 0x0
  41. .debug_line 9081 0x0
  42. .comment 18 0x0
  43. Total 102267

NOTE The Cargo project is already configured to build the release binary using LTO.

Know how to read this output? The text section contains the program instructions. It’s around 2KBin my case. On the other hand, the data and bss sections contain variables statically allocatedin RAM (static variables). A static variable is being used in aux5::init; that’s why it shows 4bytes of bss.

One final thing! We have been running our programs from within GDB but our programs don’t depend onGDB at all. You can confirm this be closing both GDB and OpenOCD and then resetting the board bypressing the black button on the board. The LED roulette application will run without interventionof GDB.