/uart-serial-baremetal
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.
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/uart-serial-baremetal
Context preview
The summary Claude sees to decide when to auto-load this skill.
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.
SKILL.md
uart-serial-baremetal.SKILL.mdname: 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 */
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
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
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)
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
Read more
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 */
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
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
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)
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
A curated suite of AI agent skills for systems and low-level programming — C/C++, Rust, Zig, GPU, bare-metal firmware, Linux kernel/driver development, computer architecture, compiler internals, HPC, and more.
Repo: mohitmishra786/low-level-dev-skills
Other skills on low-level-dev-skills.
- /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,
Open skill - /numa-programming
NUMA programming skill for multi-socket memory locality. Use when detecting NUMA topology, binding processes with numactl, using libnuma API, building NUMA-aware data structures, or measuring remote access penalties. Activates on queries about numactl, libnuma, NUMA topology,
Open skill - /af-xdp
AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring UMEM and XSK rings, XDP_REDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AF_XDP, xsk_umem, XDP_REDIRECT, libbpf xsk, or zero-copy XDP.
Open skill - /dpdk
DPDK skill for userspace packet I/O. Use when initializing EAL, configuring PMD drivers, using mbuf pools and rte_ring, setting up huge pages, RSS, or testpmd validation. Activates on queries about DPDK, EAL, rte_eth_rx_burst, hugepages, PMD, or testpmd.
Open skill - /io-uring
io_uring skill for Linux async I/O. Use when building high-performance servers with liburing, multi-shot operations, provided buffers, fixed files, zero-copy send, or tokio-uring. Activates on queries about io_uring, SQE/CQE, liburing, IORING_OP_PROVIDE_BUFFERS, or io_uring vs
Open skill - /adc-dac-baremetal
Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC, calibration, or DAC output on MCUs. Activates on queries about ADC bare-metal, sampling time, DMA ADC, or DAC channel setup.
Open skill

