デバッグと統合
導入済み
7:37
マイクロプロセッサと組込みシステム
The digital logic course built gates and flip-flops; this course builds the machine that runs programs. Embedded work is verified from three directions.…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| firmware/ˈfɜːmweə/ | Software stored in a device to control its hardware and basic operation. |
| breakpoint/ˈbreɪkpɔɪnt/ | |
| probe/prəʊb/ | |
| instruction/ɪnˈstrʌkʃn/ | |
| watchdog/ˈwɒtʃdɒɡ/ | ウォッチドッグ |
| debounce/ˈdebaʊns/ | デバウンス |
| sample/ˈsæmpl/ |
"It froze twice last night"
- Every firmware 固件 bug starts as a vague report. Firmware is tested on the exact hardware it ships on, and the fault rarely appears when someone is watching.
- Without a method you often only move a bug instead of fixing it. This lesson gives that method.
The debug loop
- Reproduce the fault with the smallest input. Isolate it at a boundary with an LED, a breakpoint 断点 or one UART print.
- Fix one thing, then re-verify. Two changes at once leave you unsure which one helped.

デバッグループを正しい順序に並べ替えよ。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
再現性が得られない場合、修正が有効かどうかを判断できません。複数の箇所に同時に対応すると、どの修正が効いたか判別できなくなります。
Bisection
- Put a probe 探针 in the middle of the suspect code. Whether the probe fires before the fault tells you which half holds the bug.
- Each probe halves the range, so $\log_{2}(n)$ probes find one instruction among $n$: ten for 1024.
二分探索は512の怪しい命令を検索します。最大で何回のプローブが必要ですか?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
各プローブで範囲を半分にするため、$\log_{2} 512 = 9$です。
怪しい領域に4096の命令が含まれています。このうち不良品を見つけるには、何回の二分探索が必要です?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$2^{12} = 4096$なので、12回の実行で十分です。コードを倍にしても追加されるのは1回のみです。
The watchdog
- A watchdog 看门狗 is a counter that resets the chip if it runs out. The firmware must "kick" it (restart the count) regularly.
- A hung system then reboots by design instead of freezing. Kick it only from the main loop, never from an ISR.
ISR内でウォッチドッグをリセットする why が間違っている理由は何ですか?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
ISRでウォッチドッグをリセットすると、割り込みが継続して供給し続けるためメインループがハングしてもリセットが発生しません。
Debounce
- A pressed button bounces: its contact opens and closes for a few milliseconds. Debounce 消抖 accepts a new state only after N equal readings in a row.
- It combines a timer tick, a GPIO read and a state decision: the whole course in one routine.
Worked example: a debounce trace
- Samples 采样值 every 10 ms read 1, 0, 0, 1. Rule: two equal readings in a row.
- At 10 ms there is one 0; at 20 ms a second 0, so a stable 0 is declared. The 1 at 30 ms is a single sample and is ignored.
One contrary reading does not erase the qualified state
$N\text{ equal sampled readings span }(N-1)\Delta t$
Step through the worked 1,0,0,1 trace at 10 ms intervals with two equal readings required. The first qualified 0 appears at 20 ms; the later single 1 does not reverse it. Edit samples, compare a one-sample pulse and an alternating input, and change N to distinguish input chatter from accepted output changes. Startup remains unqualified until a state earns enough consecutive readings.
サンプル1, 0, 0, 1が10msごとに0msから開始されます。2連続ルールを用いる場合、安定状態はいつ宣言されますか?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
At 10 ms there is one 0 and no verdict; at 20 ms the second 0 makes a stable 0. The 1 at 30 ms is a single sample.
The rule needs three equal readings in a row, sampled every 5 ms from 0 ms. The readings are 0, 1, 0, 1, 1, 1. At what time, in ms, is a stable 1 declared?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
The 1s at 15, 20 and 25 ms are the first three in a row, so the verdict comes at 25 ms.
Worked example: bisecting the freeze
- The suspect region is 1024 instructions 指令. Make instruction 512 light the LED: dark at the freeze means the first half; lit means the second.
- Each run halves the region: 512, 256, 128 … after ten runs, one instruction is left, because $2^{10} = 1024$.
Three common slips
- Fixing two things at once. One helps, one breaks something else, and now there are three bugs.
- Testing on another board. Debug on the same board revision that failed.
- Turning off the watchdog "for now". The field failure it would have survived is exactly the one that ships.
デバッグ中はウォッチドッグを無効にし、バグが修正された後も無効のままにしておくのが良い慣習です。
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
ウォッチドッグ機能のない製品を現場に配送すると、再起動せずフリーズします。セッション中にオフにする必要がある場合は、リリース前に再電源投入してください。
Recap
- Reproduce, bisect, fix one thing, re-verify.
- $\log_{2}(n)$ probes find the fault among $n$ instructions:
| Instructions $n$ | 1024 | about 1 million |
|---|---|---|
| Probes | 10 | 20 |
- Debounce 消抖 needs N equal readings in a row; kick the watchdog from the main loop only.
何が問題でしたか?この内容はサイトの運営チームだけが確認します。