Timing Example

SysTick UART

Use the millisecond SysTick to schedule periodic serial reports without a busy delay loop.

Board LPCXpresso51U68 EVB OM40005
Status Verified

Run It

Use these commands from the COS workspace when the board and serial adapter are attached.

make -C firmware/lpc51u68_systick_uart clean allmake -C firmware/lpc51u68_systick_uart flashpython3 tools/uart_viewer.py --device <serial-device> --baud 9600

What To Look For

  • The core timer interrupt is configured correctly.
  • The foreground loop can sleep with WFI between reports.
  • The timing model is ready for RTOS ticks.
#include "cos_lpc51u68_bsp.h"

int main(void)
{
    uint32_t next_report_ms = 1000u;
    uint32_t report_count = 0u;

    cos_lpc51u68_uart0_init_9600_8n1();
    cos_lpc51u68_systick_init_1ms();

    cos_lpc51u68_uart0_puts("\r\nCOS LPC51U68 SysTick UART smoke test\r\n");

    for (;;) {
        uint32_t now = cos_lpc51u68_systick_ms();
        if ((int32_t)(now - next_report_ms) >= 0) {
            cos_lpc51u68_uart0_puts("systick ms ");
            cos_lpc51u68_uart0_put_hex32(now);
            cos_lpc51u68_uart0_puts(" report ");
            cos_lpc51u68_uart0_put_hex32(report_count++);
            cos_lpc51u68_uart0_puts("\r\n");
            next_report_ms += 1000u;
        }
        __asm volatile("wfi");
    }
}