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
npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a claude-codeWhat 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
printfconsole output through the_writesyscall - 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
_writeimplementation 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-code2Manually: put the files in place
~/.claude/skills/uart-serial-baremetal/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/uart-serial-baremetal/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a codex2Manually: put the files in place
.agents/skills/uart-serial-baremetal/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a cursor2Manually: put the files in place
.cursor/skills/uart-serial-baremetal/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install mohitmishra786/low-level-dev-skills skills/baremetal/uart-serial-baremetal2Manually: put the files in place
.github/skills/uart-serial-baremetal/SKILL.md1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a gemini-cli2Platform CLI
gemini skills install https://github.com/mohitmishra786/low-level-dev-skills --path skills/baremetal/uart-serial-baremetalManually: put the files in place
.devin/skills/uart-serial-baremetal/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill uart-serial-baremetal -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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