sample_pc
Profile STM32 firmware while the core runs by sampling the program counter over SWD with DWT; get a symbolized hot-spot histogram to find time-heavy functions or stuck loops.
Instructions
Statistical PC profiler: enables DWT and samples the program counter while the core RUNS (non-intrusive, over SWD — no SWO pin or firmware change). Returns a symbolized hot-spot histogram (top functions by %), not raw hex — the fast way to find where firmware spends time or what loop it is stuck in. A high 'unsampleable' count means the core is halted/asleep; a high 'zero_samples' count means nothing was profiled at all. Leave enable=true: GDB cannot write the enable bit while the core runs, so this halts briefly to set it and resumes, and only when it is not already set. Note some links cannot serve memory reads while the core runs at all (measured: OpenOCD + ST-Link + STM32L1) — there PC sampling is unavailable and the result says so rather than inventing a hot spot.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of samples (default 128; more = better statistics, slower). | |
| enable | No | Enable DWT trace before sampling (default true). With false, a target whose trace unit is off yields nothing. | |
| session | No | Optional debug-session name. Omit for the default target. |