Skip to main content
skill CX Codex

uart-serial-baremetal — Claude Code skill: setup and usage

uart-serial-baremetal configures bare-metal UART and USART drivers for serial debug consoles, baud calculation, and interrupt I/O.

MIT 391 installs ★ 298 updated 2026-06-27

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a claude-code
Open on GitHub

What uart-serial-baremetal does

This skill guides the implementation of low-level UART drivers without relying on blocking HAL layers. It provides formulas for calculating the BRR register based on the peripheral bus clock (PCLK), 8N1 framing setup, and polling loops for TXE and RXNE flags.

It covers interrupt-driven reception into ring buffers and newlib printf retargeting via custom _write implementations. For bare-metal toolchains, linking requires the --specs=nosys.specs flag to satisfy missing system calls.

The skill also troubleshoots typical register-level issues. It addresses overrun flags by reading DR to clear ORE, incorrect baud rate calculations, and missing GPIO alternate function mappings.

What it helps with

  • calculate USART BRR register values for target baud rates and PCLK clocks
  • implement interrupt-driven serial reception with ring buffers
  • retarget standard printf console output through the _write syscall
  • resolve overrun errors by properly clearing ORE flags

Example prompts for the agent

  • /uart-serial-baremetal Calculate USART BRR for 115200 at 84 MHz PCLK
  • Write a bare-metal _write implementation to direct printf output to USART2
  • Create a USART2_IRQHandler snippet that clears ORE and stores bytes in a ring buffer

How to install uart-serial-baremetal

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a claude-code

2Manually: put the files in place

~/.claude/skills/uart-serial-baremetal/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/uart-serial-baremetal/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about uart-serial-baremetal

How to install uart-serial-baremetal in Claude Code?

Run npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a claude-code in your terminal.

What does uart-serial-baremetal do?

It helps write direct register-level UART drivers for microcontrollers, handling baud registers, polling routines, RX interrupts, and debug output.

What linker flag is needed for printf retargeting?

When retargeting newlib printf via _write, link the firmware using --specs=nosys.specs.

Source text

SKILL.md · MIT
---
name: uart-serial-baremetal
description: Bare-metal UART skill for serial console and debug. Use when configuring baud rate, polling or IRQ-driven TX/RX, or integrating DMA with UART. Activates on queries about UART bare-metal, baud BRR, serial printf, or USART interrupt.
---

# 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

| Symptom | Cause | Fix |
|---------|-------|-----|
| Garbage chars | Wrong baud/PCLK | Recompute BRR; check APB divider |
| Lost bytes | ORE not cleared | Read DR on ORE; use IRQ + ringbuf |
| No output | TX pin not AF | GPIO alternate function |
| `printf` hangs | `_write` missing | Implement 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

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Programming languages →

From the same set140

The whole set →
baremetal-startup baremetal-startup is a Claude Code skill that guides coding agents through Cortex-M and RISC-V initialization from reset to main(). CX Codex +1 394installs mmio-and-bit-manipulation mmio-and-bit-manipulation — a skill for safe peripheral memory access: volatile semantics, read-modify-write patterns, bit masks, and alignment. Essential when writing bare-metal drivers without a HAL. CX Codex +1 392installs dma-baremetal dma-baremetal is a Claude Code skill that assists with register-level DMA setup for bare-metal microcontrollers, moving UART, SPI, or ADC data away from the CPU. CX Codex +1 392installs bus-drivers-i2c-spi bus-drivers-i2c-spi walks an agent through Linux client drivers for I2C and SPI sensors and PMICs: registration, regmap, device tree binding. CX Codex +1 392installs kernel-concurrency kernel-concurrency is a Claude Code skill that helps select a Linux kernel synchronization primitive: spinlock, mutex, RCU, seqlock, or completion. CX Codex +1 391installs gpu-memory-model gpu-memory-model explains GPU execution and memory hierarchy under SIMT. Helps debug warp divergence, bank conflicts, and coalescing issues in compute kernels. CX Codex +1 391installs compiler-frontend A skill for building compiler frontends, from tokenization and parsing to type checks and LLVM IR generation. Useful for a language, DSL, or interpreter. CX Codex +1 390installs qemu-embedded-simulation The qemu-embedded-simulation skill guides QEMU runs of bare-metal ARM and RISC-V firmware and GDB sessions. Use it to test firmware without a board. CX Codex +1 389installs

Project sponsors

Companies that keep this analytics open