$npx -y skills add easyzoom/aix-skills --skill freertos-kernel-debugUse when debugging FreeRTOS kernel behavior, task scheduling, priorities, stacks, heap schemes, tick interrupts, ISR APIs, queues, semaphores, timers, or deadlocks
| 1 | # FreeRTOS Kernel Debug |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill to debug FreeRTOS by proving tick, scheduler state, task stacks, |
| 6 | heap, ISR boundaries, and synchronization ownership. Many FreeRTOS failures are |
| 7 | contract violations around interrupt priority or blocking context. |
| 8 | |
| 9 | ## When To Use |
| 10 | |
| 11 | Use this skill when: |
| 12 | |
| 13 | - The user is debugging FreeRTOS tasks, queues, semaphores, mutexes, timers, |
| 14 | event groups, streams, or task notifications. |
| 15 | - The issue involves hard faults, hangs, missed ticks, watchdog resets, stack |
| 16 | overflow, heap exhaustion, priority inversion, or ISR API misuse. |
| 17 | - The target uses vendor HAL callbacks, Cortex-M interrupt priorities, trace |
| 18 | tools, or multiple heap implementations. |
| 19 | |
| 20 | Do not use this skill for RTOS-agnostic firmware architecture questions. Use |
| 21 | `rtos-debug` for broader RTOS triage. |
| 22 | |
| 23 | ## First Questions |
| 24 | |
| 25 | Ask for: |
| 26 | |
| 27 | - FreeRTOS version, port, MCU, tick rate, heap implementation, and config file. |
| 28 | - Task list with priorities, stack sizes, states, and high-water marks. |
| 29 | - Interrupt priorities, `configMAX_SYSCALL_INTERRUPT_PRIORITY`, and ISR APIs. |
| 30 | - Current symptom, fault dump, watchdog reason, trace, or scheduler snapshot. |
| 31 | - Whether assertions, stack overflow hook, malloc failed hook, and trace are on. |
| 32 | |
| 33 | ## Debug Workflow |
| 34 | |
| 35 | 1. Enable kernel evidence. |
| 36 | Turn on `configASSERT`, stack overflow checks, malloc failed hook, and |
| 37 | trace-friendly task names where possible. |
| 38 | |
| 39 | 1. Prove the tick and scheduler. |
| 40 | Confirm SysTick/timer setup, interrupt priority, scheduler start, and idle |
| 41 | task execution. |
| 42 | |
| 43 | 1. Audit task resources. |
| 44 | Check priority, stack high-water mark, blocking calls, and CPU hogging loops. |
| 45 | |
| 46 | 1. Audit ISR boundaries. |
| 47 | Match every ISR call to the `FromISR` API and verify interrupt priority is |
| 48 | allowed to call the kernel. |
| 49 | |
| 50 | 1. Inspect synchronization. |
| 51 | Identify queue ownership, mutex holders, priority inheritance, timeouts, and |
| 52 | event group semantics. |
| 53 | |
| 54 | 1. Validate heap and timers. |
| 55 | Confirm selected heap scheme, fragmentation risk, timer task priority, and |
| 56 | timer command queue length. |
| 57 | |
| 58 | ## Common Failures |
| 59 | |
| 60 | - An ISR above `configMAX_SYSCALL_INTERRUPT_PRIORITY` calls a FreeRTOS API. |
| 61 | - A normal API is called from an ISR instead of the `FromISR` variant. |
| 62 | - A task stack is sized for the happy path but not logging or TLS. |
| 63 | - A high-priority task spins and starves lower-priority work. |
| 64 | - Timer callbacks block or perform long operations. |
| 65 | - Heap implementation does not match allocation/free patterns. |
| 66 | |
| 67 | ## Verification |
| 68 | |
| 69 | Before claiming FreeRTOS behavior is fixed: |
| 70 | |
| 71 | - State kernel version, port, tick source, heap scheme, and key config symbols. |
| 72 | - Confirm assertions/hooks are enabled or explain why they cannot be. |
| 73 | - Show task state, stack margin, heap margin, and interrupt priority evidence. |
| 74 | - Confirm the original hang/fault/deadlock scenario no longer reproduces. |
| 75 | |
| 76 | ## Example |
| 77 | |
| 78 | User: |
| 79 | |
| 80 | ```text |
| 81 | FreeRTOS 跑一会儿随机卡死。 |
| 82 | ``` |
| 83 | |
| 84 | Agent: |
| 85 | |
| 86 | 1. Enables `configASSERT`, stack overflow, and malloc failed hooks. |
| 87 | 1. Captures task states, stacks, heap, and interrupt priorities. |
| 88 | 1. Checks ISR API usage and blocking calls before changing task priorities. |