mohitmishra786/low-level-dev-skills

uart-serial-baremetal

Bare-metal UART skill for serial console and debug.

Ver código-fonte

Como usar

  1. Copie o comando e verifique o pacote antes de instalar no seu ambiente de agente.
  2. Consulte no original as ferramentas, credenciais e ambientes necessários.
  3. Descreva os dados de entrada e a entrega esperada; confira a saída com as fontes.
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal

Antes de começar

  • A instalação não inclui assinatura de modelo, franquia API ou acesso aos seus arquivos.
  • Estrelas e instalações indicam atividade, não um teste independente de qualidade ou segurança.
Documento original do Skill

Renderizado do repositório de origem, preservando títulos, exemplos, código, tabelas, links e imagens.

UART Serial (Bare-Metal)

Purpose

Implement UART/USART for debug console and device communication: baud rate calculation, 8N1 framing, polling and interrupt-driven I/O, overrun handling, and optional DMA basics.

When to Use

  • First printf/log output on new hardware
  • Serial protocol to sensor/module
  • Replacing blocking HAL_UART with minimal driver
  • Fixing garbled or missing characters

Workflow

1. Baud rate (STM32)

BRR = pclk / (16 * baud)   /* oversampling by 16 — check RM for USART */
c
void usart2_init(uint32_t pclk, uint32_t baud) {
    RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
    /* GPIO PA2/PA3 AF — see gpio-baremetal */

    USART2->BRR = pclk / baud;  /* simplified — RM has fractional formula */
    USART2->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
}

Verify pclk from actual clock tree (SystemCoreClock, APB prescaler).

2. Polling TX/RX

c
void uart_putc(USART_TypeDef *u, char c) {
    while (!(u->SR & USART_SR_TXE))
        ;
    u->DR = (uint8_t)c;
}

char uart_getc(USART_TypeDef *u) {
    while (!(u->SR & USART_SR_RXNE))
        ;
    return (uint8_t)u->DR;
}

3. Interrupt-driven RX ring buffer

c
void USART2_IRQHandler(void) {
    if (USART2->SR & USART_SR_RXNE) {
        uint8_t b = USART2->DR;
        rb_push(&rx_rb, b);
    }
    if (USART2->SR & USART_SR_ORE) {
        (void)USART2->DR;  /* clear overrun — required on STM32 */
    }
}

4. retarget printf (newlib)

c
int _write(int fd, char *ptr, int len) {
    (void)fd;
    for (int i = 0; i < len; i++)
        uart_putc(USART2, ptr[i]);
    return len;
}

Link with --specs=nosys.specs or provide full syscalls.

5. Agent usage

/uart-serial-baremetal Calculate USART BRR for 115200 at 84 MHz PCLK

Common Problems

SymptomCauseFix
Garbage charsWrong baud/PCLKRecompute BRR; check APB divider
Lost bytesORE not clearedRead DR on ORE; use IRQ + ringbuf
No outputTX pin not AFGPIO alternate function
printf hangs_write missingImplement retarget

Related Skills

  • skills/baremetal/gpio-baremetal — TX/RX pin mux
  • skills/baremetal/interrupts-and-exceptions-baremetal — USART IRQ
  • skills/baremetal/dma-baremetal — UART RX DMA
  • skills/embedded/openocd-jtag — semihosting alternative

Relacionados por tarefa

do mesmo repositório

Mais Skills

Todos os Skills
mohitmishra786
Comunidade

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.
mohitmishra786
Comunidade

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.
mohitmishra786
Comunidade

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.
mohitmishra786
Comunidade

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.