$npx -y skills add easyzoom/aix-skills --skill 8051-mcu-debugUse when debugging 8051-compatible microcontrollers, 51 MCU firmware, STC download issues, Keil C51 projects, interrupts, timers, UART, or startup failures
| 1 | # 8051 MCU Debug |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill to debug 8051-compatible microcontrollers and 51 MCU firmware systematically. Start by identifying the exact chip family, clock source, download method, toolchain, and failure phase, then prefer observable checks such as reset behavior, UART logs, GPIO toggles, interrupts, and SFR state before changing fuses or boot settings. |
| 6 | |
| 7 | ## When To Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - The target is an 8051-compatible MCU, such as STC 89/90/12/15/8 series, Nuvoton N76/N79, Silicon Labs C8051, AT89, WCH 8051-like parts, or classic MCS-51 derivatives. |
| 12 | - The user mentions 51 单片机, 8051, Keil C51, SDCC, STC-ISP, ISP/IAP, UART download, `REG52.H`, `intrins.h`, SFR, interrupt vectors, timers, or serial debugging. |
| 13 | - Firmware cannot download, does not run after reset, has no serial output, timer/interrupt behavior is wrong, or peripherals do not respond. |
| 14 | |
| 15 | Do not use this skill when: |
| 16 | |
| 17 | - The target is Cortex-M, RISC-V, AVR, ESP32, embedded Linux, or another non-8051 architecture. |
| 18 | - The task is only generic C syntax cleanup and does not depend on MCU behavior. |
| 19 | - The user wants to change lock bits, fuses, clock source, or boot configuration before collecting baseline evidence. |
| 20 | |
| 21 | ## First Questions |
| 22 | |
| 23 | Ask for the minimum context needed: |
| 24 | |
| 25 | - Exact MCU model and board name. |
| 26 | - Toolchain: Keil C51, SDCC, IAR, vendor IDE, or other. |
| 27 | - Download tool: STC-ISP, Nu-Link, C2 debugger, USB programmer, UART bootloader, or ISP adapter. |
| 28 | - Current symptom: cannot download, no boot, no UART output, timer wrong, interrupt not entered, reset loop, or peripheral failure. |
| 29 | - Clock source and frequency: internal RC, external crystal, PLL, divider, or unknown. |
| 30 | - Power voltage and whether reset, crystal, and UART pins are accessible. |
| 31 | - Available artifacts: source, HEX/IHX, MAP/M51 file, schematic, UART log, programmer output, or logic analyzer capture. |
| 32 | |
| 33 | ## Workflow |
| 34 | |
| 35 | 1. Identify the chip family. |
| 36 | 8051 derivatives differ heavily. Confirm the exact part number before assuming SFR names, memory model, bootloader behavior, or download protocol. |
| 37 | |
| 38 | 1. Classify the failure phase. |
| 39 | Use these buckets: download failure, reset/startup failure, no observable output, timing error, interrupt error, peripheral error, or memory/model error. |
| 40 | |
| 41 | 1. Confirm power, reset, and clock. |
| 42 | Check supply voltage, reset pin state, crystal/clock source, and whether the selected clock matches code assumptions. |
| 43 | |
| 44 | 1. Establish the safest observation point. |
| 45 | Prefer UART boot log, GPIO heartbeat, programmer verify, simulator trace, or logic analyzer evidence before changing configuration bytes. |
| 46 | |
| 47 | 1. Check build artifacts. |
| 48 | Confirm the generated HEX/IHX belongs to the current source, target model, memory model, and clock assumptions. |
| 49 | |
| 50 | 1. Inspect only the narrowest next layer. |
| 51 | For no boot, check reset vector and minimal GPIO toggle before debugging application logic. For timer issues, check oscillator and reload math before rewriting ISR code. |
| 52 | |
| 53 | 1. Ask before risky operations. |
| 54 | Lock bits, security bits, config bytes, ISP/IAP settings, erase-all operations, and bootloader changes require explicit user approval. |
| 55 | |
| 56 | ## Download And Programming Checks |
| 57 | |
| 58 | For STC and UART bootloader download issues, check: |
| 59 | |
| 60 | - Correct chip model and series selected in the programmer. |
| 61 | - Correct serial port and USB-to-UART driver. |
| 62 | - TX/RX crossed correctly and common ground connected. |
| 63 | - Boot sequence required by the chip, often power-cycle or reset after clicking download. |
| 64 | - Baud rate and auto-baud behavior. |
| 65 | - Whether P3.0/P3.1 or alternate UART pins are shared with other circuits. |
| 66 | - Whether reset, EA, PSEN, BOOT, or vendor-specific boot pins are in the required state. |
| 67 | - Whether the HEX file was rebuilt after source changes. |
| 68 | |
| 69 | For adapter/debugger based chips, check: |
| 70 | |
| 71 | - Probe driver and target voltage. |
| 72 | - Correct debug protocol, such as C2, ICP, ISP, or vendor-specific interface. |
| 73 | - Whether security or lock bits block read/debug access. |
| 74 | - Whether mass erase is needed and whether the user approves it. |
| 75 | |
| 76 | Safe command/tool guidance: |
| 77 | |
| 78 | ```text |
| 79 | 1. Rebuild the project. |
| 80 | 1. Confirm the output HEX/IHX path and timestamp. |
| 81 | 1. Select the exact MCU model in the programming tool. |
| 82 | 1. Try erase/program/verify separately if the tool supports it. |
| 83 | 1. Preserve the programmer log for comparison. |
| 84 | ``` |
| 85 | |
| 86 | ## Reset And Startup Checks |
| 87 | |
| 88 | If firmware downloads but does not run: |
| 89 | |
| 90 | - Confirm code is linked for the expected reset vector at `0x0000`. |
| 91 | - Confirm startup code initializes stack pointer as expected. |
| 92 | - Confirm watchdog is disabled or serviced during early boot. |
| 93 | - Add a minimal GPIO toggle at the start of `main()` to prove execution reaches C code. |
| 94 | - Add an early UART byte only after confirming clock and baud-rate math. |
| 95 | - Check whether the chip boots from application flash, bootloader, or external memory. |
| 96 | - Confirm |