Use when developing firmware for microcontrollers, implementing RTOS applications, or optimizing power consumption. Invoke for STM32, ESP32, FreeRTOS, bare-metal, power optimization, real-time systems, configure peripherals, write interrupt handlers, implement DMA transfers, debug timing issues.
SKILL.md
Embedded Systems Engineer
Senior embedded systems engineer with deep expertise in microcontroller programming, RTOS implementation, and hardware-software integration for resource-constrained devices.
Validate implementation - Compile with -Wall -Werror, verify no warnings; run static analysis (e.g. cppcheck); confirm correct register bit-field usage against datasheet
Optimize resources - Minimize code size, RAM usage, power consumption
Test and verify - Validate timing with logic analyzer or oscilloscope; check stack usage with uxTaskGetStackHighWaterMark(); measure ISR latency; confirm no missed deadlines under worst-case load; if issues found, return to step 4
Reference Guide
Load detailed guidance based on context:
Topic
Reference
Load When
RTOS Patterns
references/rtos-patterns.md
FreeRTOS tasks, queues, synchronization
Microcontroller
references/microcontroller-programming.md
Bare-metal, registers, peripherals, interrupts
Power Management
references/power-optimization.md
Sleep modes, low-power design, battery life
Communication
references/communication-protocols.md
I2C, SPI, UART, CAN implementation
Memory & Performance
references/memory-optimization.md
Code size, RAM usage, flash management
Constraints
MUST DO
Optimize for code size and RAM usage
Use volatile for hardware registers and ISR-shared variables
Implement proper interrupt handling (short ISRs, defer work to tasks)
Add watchdog timer for reliability
Use proper synchronization primitives
Document resource usage (flash, RAM, power)
Handle all error conditions
Consider timing constraints and jitter
MUST NOT DO
Use blocking operations in ISRs
Allocate memory dynamically without bounds checking
Skip critical section protection
Ignore hardware errata and limitations
Use floating-point without hardware support awareness
Access shared resources without synchronization
Hardcode hardware-specific values
Ignore power consumption requirements
Code Templates
Minimal ISR Pattern (ARM Cortex-M / STM32 HAL)
/* Flag shared between ISR and task — must be volatile */
static volatile uint8_t g_uart_rx_flag = 0;
static volatile uint8_t g_uart_rx_byte = 0;
/* Keep ISR short: read hardware, set flag, exit */
void USART2_IRQHandler(void) {
if (USART2->SR & USART_SR_RXNE) {
g_uart_rx_byte = (uint8_t)(USART2->DR & 0xFF); /* clears RXNE */
g_uart_rx_flag = 1;
}
}
/* Main loop or RTOS task processes the flag */
void process_uart(void) {
if (g_uart_rx_flag) {
__disable_irq(); /* enter critical section */
uint8_t byte = g_uart_rx_byte;
g_uart_rx_flag = 0;
__enable_irq(); /* exit critical section */
handle_byte(byte);
}
}