Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

私の解答

どのような解答になりましたか?

私のものは次のとおりです:

#![deny(unsafe_code)]
#![no_main]
#![no_std]

use aux5::{Delay, DelayMs, LedArray, OutputSwitch, entry};

#[entry]
fn main() -> ! {
    let (mut delay, mut leds): (Delay, LedArray) = aux5::init();

    let ms = 50_u8;
    loop {
        for curr in 0..8 {
            let next = (curr + 1) % 8;

            leds[next].on().ok();
            delay.delay_ms(ms);
            leds[curr].off().ok();
            delay.delay_ms(ms);
        }
    }
}

もう 1 つあります!あなたの解答が "release" モードでコンパイルした場合にも動作することを確認してください:

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

次の gdb コマンドでテストできます:

$ # または、単に cargo run --target thumbv7em-none-eabihf --release を実行してもかまいません
$ arm-none-eabi-gdb target/thumbv7em-none-eabihf/release/led-roulette
$ #                                              ~~~~~~~

バイナリサイズは常に気にかけておくべきものです!あなたの解答はどれくらいの大きさですか? それは release バイナリに対して size コマンドを実行することで確認できます:

$ # size target/thumbv7em-none-eabihf/debug/led-roulette と同等
$ cargo size --target thumbv7em-none-eabihf --bin led-roulette -- -A
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
led-roulette  :
section               size        addr
.vector_table          404   0x8000000
.text                21144   0x8000194
.rodata               3144   0x800542c
.data                    0  0x20000000
.bss                     4  0x20000000
.uninit                  0  0x20000004
.debug_abbrev        19160         0x0
.debug_info         471239         0x0
.debug_aranges       18376         0x0
.debug_ranges       102536         0x0
.debug_str          508618         0x0
.debug_pubnames      76975         0x0
.debug_pubtypes     112797         0x0
.ARM.attributes         58         0x0
.debug_frame         55848         0x0
.debug_line         282067         0x0
.debug_loc             845         0x0
.comment               147         0x0
Total              1673362


$ cargo size --target thumbv7em-none-eabihf --bin led-roulette --release -- -A
    Finished release [optimized + debuginfo] target(s) in 0.03s
led-roulette  :
section              size        addr
.vector_table         404   0x8000000
.text                5380   0x8000194
.rodata               564   0x8001698
.data                   0  0x20000000
.bss                    4  0x20000000
.uninit                 0  0x20000004
.debug_loc           9994         0x0
.debug_abbrev        1821         0x0
.debug_info         74974         0x0
.debug_aranges        600         0x0
.debug_ranges        6848         0x0
.debug_str          52828         0x0
.debug_pubnames     20821         0x0
.debug_pubtypes     18891         0x0
.ARM.attributes        58         0x0
.debug_frame         1088         0x0
.debug_line         15307         0x0
.comment               19         0x0
Total              209601

Cargo プロジェクトは、LTO を使って release バイナリをビルドするように、すでに設定されています。

この出力の読み方はわかりますか? text セクションにはプログラムの命令が含まれています。私の 場合は約 5.25KB です。一方、data セクションと bss セクションには、RAM に静的に割り当てられる 変数(static 変数)が含まれています。aux5::init では static 変数が使われているため、bss が 4 バイト表示されています。

最後にもう 1 つ!これまでプログラムは GDB の中から実行してきましたが、プログラム自体は GDB にまったく依存していません。これを確認するには、GDB と OpenOCD の両方を終了してから、 ボード上の黒いボタンを押してボードをリセットしてください。LED ルーレットアプリケーションは GDB の介入 なしで動作します。