Next Example
Stack Safety Telemetry
Fill task stacks with a known pattern, measure high-water marks, and report margin over serial.
Run It
Use these commands from the COS workspace when the board and serial adapter are attached.
make -C firmware/lpc51u68_cleveros_stack_demo clean allmake -C firmware/lpc51u68_cleveros_stack_demo flashpython3 tools/uart_viewer.py --device <serial-device> --baud 9600
What To Look For
- Stack fill pattern is initialized before scheduling.
- Telemetry prints once per second.
- A warning appears when margin drops below the configured threshold.
typedef struct {
const char *name;
uint32_t stack_words;
uint32_t high_water_words;
} stack_report_t;
static void task_stack_report(void)
{
for (;;) {
stack_report_t report = rtos_stack_report_current();
cos_lpc51u68_uart0_puts("stack ");
cos_lpc51u68_uart0_puts(report.name);
cos_lpc51u68_uart0_puts(" free ");
cos_lpc51u68_uart0_put_hex32(report.stack_words - report.high_water_words);
cos_lpc51u68_uart0_puts("\r\n");
rtos_delay_ticks(1000u);
}
}