Logo: Keil Mdk Build

Keil Mdk Build

Communautéit
AmethystLuna
keil-mdk-build

Use when building, flashing, or packaging firmware with Keil MDK (UV4 CLI, ARMCLANG), analyzing .map files for ROM/RAM optimization and memory budget, or diagnosing Keil-specific build failures. NOT for non-Keil build systems (Makefile, CMake, IAR, GCC-only). For crash triage see hardfault-triage.

Iwwersiicht

EditeurAmethystLuna
Repositoryembedded-workbench
Skill-Nummkeil-mdk-build
Stären
32
Forks
3
Matgeliwwert Dateien
Nëmmen Instruktiounen
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    AmethystLuna huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Keil Mdk Build an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/AmethystLuna/embedded-workbench/tree/master/skills/keil-mdk-build
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/AmethystLuna/embedded-workbench.git /tmp/embedded-workbench
mkdir -p .claude/skills
cp -r /tmp/embedded-workbench/skills/keil-mdk-build .claude/skills/keil-mdk-build
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Keil Mdk Build an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Keil Mdk Build automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Keil Mdk Build net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Keil MDK Build

Patterns for building embedded firmware with Keil MDK. Covers both ARM Compiler 5 (armcc) and ARM Compiler 6 (armclang).

UV4 CLI Build (Authoritative)

UV4.exe batch mode is the canonical build path. A CI reimplementation is possible but may miss include paths.

powershell
<Keil>\UV4\UV4.exe -b project.uvprojx -t TargetName -j0 -o <log_path>

Replace <Keil> with the Keil install root. Auto-discover by checking common locations or ask the user when unknown.

Flags:

FlagMeaning
-bBatch mode (no GUI)
-t <target>Target name within the multi-target project
-j0Auto-parallelism (use all cores)
-o <path>Log output file

Exit codes:

CodeMeaning
0Success (no errors, no warnings)
1Warnings but no errors
2Errors
3Errors (when <StopOnExitCode>3</StopOnExitCode> is set in uvprojx)

Critical: Log path resolution — The -o path is resolved relative to the .uvprojx file's directory, not the current working directory. Always use an absolute path or a path under a known-existing subdirectory (e.g., objects\) of the project directory.

Recommended invocation — UV4 produces no stdout; use Start-Process with -Wait -PassThru and check ExitCode:

powershell
$keil = "<Keil_install_root>"  # Ask user or auto-discover
$log = Join-Path (Get-Location) "build.log"
$p = Start-Process -FilePath "$keil\UV4\UV4.exe" `
    -ArgumentList "-b project.uvprojx -t Target -j0 -o $log" `
    -Wait -PassThru -NoNewWindow
if ($p.ExitCode -ne 0) { throw "Build failed (exit $($p.ExitCode))" }

Compiler Selection

Keil MDK supports two compiler generations. Identify which one the project uses before generating commands.

CompilerKeil NameBinaryInstall PathCheck Version
ARM Compiler 5AC5armcc<Keil>\ARM\ARMCCarmcc --vsn
ARM Compiler 6AC6armclang<Keil>\ARM\ARMCLANG*armclang --version

How to identify: Check the .uvprojx XML for <ARMCC> (AC5) or <ARMCLANG> (AC6) sections. A project can mix both — check per-file or per-group settings.

ARM Compiler 5 (armcc)

Legacy compiler, still common in long-lived projects. Uses its own flag syntax, incompatible with AC6.

Detection: Installed at <Keil>\ARM\ARMCC. Run armcc --vsn to verify.

Optimization levels — AC5 has two orthogonal axes: optimization level (-On) and optimization goal (-Ospace vs -Otime). Keil's UI combines them into a single dropdown:

Keil LevelAC5 Flags (actual)Effect
0-O0Minimum optimization, best debug view
1-O1Restricted optimization, good debug view
2-O2High optimization (AC5 default)
3-O3Maximum optimization
4-O3 -OtimeMax optimization + favor speed over size

-Ospace is the default goal at levels 0-3 (favor smaller code). -Otime swaps to favor speed. These are separate from the -On level.

Sources: ARM Compiler v5.06 User Guide (DUI0472M), §3.154-3.159.

Key flags:

  • --cpu Cortex-M4 (adjust to target MCU; use --cpu=list to see supported targets)
  • --c99 or --c11 (language standard; C90 is the AC5 default)
  • --gnu (enable GNU extensions if project relies on them)
  • --apcs=/interwork (ARM/Thumb interworking)
  • -c (compile only, no link)
  • --split_sections (equivalent to -ffunction-sections -fdata-sections)

Warning control: --diag_suppress=<id> to suppress specific warnings; --diag_error=<id> to promote to error.

ARM Compiler 6 (armclang)

LLVM-based, current generation. Installed at <Keil>\ARM\ARMCLANG*.

Detection: Search common install roots for directories matching ARMCLANG*. Validate with armclang --version. If detection fails, ask the user.

Optimization levels:

Keil LevelAC6 Flag
0-O0
1-O1
2-O2
3-O3
4-Os
5-Ofast

Key flags for Cortex-M:

  • --target=arm-arm-none-eabi -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard (adjust MCU/FPU to target)
  • -c (compile only, no link)
  • -ffunction-sections -fdata-sections (enable linker garbage collection)
  • -fshort-enums -fshort-wchar (common embedded defaults)

AC5 to AC6 Migration Traps

Projects migrating from AC5 to AC6 commonly hit these issues. Sources: ARM Compiler Migration Guide (DUI0742), Arm Compiler for Embedded FuSa Migration Guide.

AC5AC6Trap
__packed struct { ... }struct __attribute__((packed, aligned(1))) { ... }AC5 keyword silently ignored by AC6; struct layout changes. aligned(1) ensures no implicit alignment.
__irq void Handler()void Handler(void) __attribute__((interrupt))AC5 attribute not recognized; ISR stack frame broken. Alternatively use CMSIS IRQn_Type.
__asm { ... }__asm volatile ("..." : : : )Inline assembly switches from armasm syntax to GAS (GNU assembler) syntax with GCC-style operand constraints.
--c99-std=c99Flag syntax differs; AC6 defaults to gnu11
--gnu-fgnu89-inlineGNU inline semantics differ between compilers
--diag_suppress=<n>-Wno-<name>Warning names differ; numbers don't map 1:1. Use AC6 -Weverything to list available warnings.
#pragma diag_suppress#pragma clang diagnostic ignored "-Wname"Pragma syntax differs
char unsigned by default-funsigned-charAC5 defaulted to unsigned char; AC6 defaults to signed. Add flag to preserve behavior.

Migration verification: After switching compiler, compare .map file sizes and symbol lists. Unexpected size changes often indicate a packing or inlining difference.

Build Lifecycle

A full Keil build has 5 stages:

  1. Pre-build — Version header generation, manifest updates
  2. Compile — .c/.cpp/.s → .o via armcc (AC5) or armclang (AC6)
  3. Link — armlink --via=<response>.lnp → .axf
  4. Post-build (fromelf) — fromelf --bin objects/app.axf → application.bin
  5. Post-build (merge) — Merge application BIN + filesystem + bootloader into flash image

If bypassing UV4 (CI build), all 5 stages must be replicated explicitly.

Merge / Packaging

Embedded firmware packages typically merge multiple components into a single flash image.

Bootloader Selection (Parity Rule)

A common pattern: use version.build parity to select development vs. production bootloader.

  • Parse version.build as hexadecimal (not decimal)
  • Odd → production bootloader
  • Even → development bootloader

This is the most common source of confusion — 0x10 (hex) is even, even though "16" as a decimal number looks like it could be interpreted differently.

Manifest Structure

Merged firmware images include a manifest at a fixed address with:

  • Version fields (major, minor, patch, build)
  • Component sizes (firmware, filesystem)
  • CRC32 checksums for each component
  • Magic number for validation

Components are typically padded to alignment boundaries before CRC calculation.

Non-Standard CRC32

Embedded firmware CRC32 often differs from the standard zlib/crc32 implementation:

  • Byte-swapped within each word (MCU word order)
  • No reflection (forward bit order)
  • No final XOR
  • Polynomial: 0x104C11DB7

Verify the CRC implementation against a known-good reference before trusting any reimplementation.

Common Build Failures

FailureCauseFix
UV4 log written to wrong location-o path is relative to uvprojx directoryUse absolute path
CLI build: missing CMSIS headersPack directory detection incompleteUse UV4 CLI (UV4.exe -b) for authoritative builds
CLI build: no compile entries.dep file stale or from different targetRun Keil IDE build first to regenerate
merge: input file not foundfromelf step didn't produce application.binCheck after-build hooks; ensure fromelf completed
Wrong bootloader selectedversion.build parsed as decimal instead of hexAlways parse build number as hexadecimal
"file not found" for OTA componentFilesystem image not generatedBuild filesystem assets before merge step
AC6: struct layout differs from AC5__packed ignored by AC6Replace with __attribute__((packed))
AC6: ISR crashes after migration__irq attribute not recognizedUse __attribute__((interrupt)) or CMSIS IRQn_Type
AC6: inline asm syntax errorsAC5 __asm { } in sourcesRewrite as __asm volatile ("...")
Linker: "No section matches selector"Scatter file syntax differs between AC5/AC6Check scatter file against compiler docs; AC5 uses different section naming

MAP File Analysis

The .map file (at <listings>/<target>.map) is the linker's memory blueprint. Make it a habit to review after each build.

Key Sections

SectionWhat It Tells You
Image component sizesPer-file Code / RO Data / RW Data / ZI Data breakdown. Find the bloat.
Memory Map of the imageFlash and RAM layout: load regions, execution regions, stack, heap
Global SymbolsEvery function/variable address and size — essential for HardFault analysis
Removing unused sectionsWhat the linker eliminated. Check for unexpected removals.
Cross ReferencesWhich .o calls which. Trace startup and verify call graphs.

Size Optimization Workflow

  1. Sort Image component sizes by Code + RO Data. Focus on the top 5 files.
  2. In Global Symbols, find functions with large Size values. Consider splitting or rewriting.
  3. Check .constdata / .rodata for debug strings — guard with #if or move to runtime generation.
  4. In Memory Map, look for PAD entries — these are alignment waste. Reorder struct members to minimize.
  5. Verify MicroLIB is enabled; check that no accidental printf/sprintf/malloc drags in heavy library code.
  6. Keep an optimization log: ROM/RAM before and after each change.

Memory Budget Verification

From the Memory Map section:

  • Load Region LR_IROM1 size = total Flash used (Code + RO + RW initial values)
  • Execution Region RW_IRAM1 = total RAM used (RW data + ZI data + Stack + Heap)
  • RW Data consumes BOTH Flash and RAM — initial values stored in Flash, copied to RAM at startup
  • ZI Data consumes RAM only — zero-initialized at startup

Check that Stack + Heap sizes match the worst-case call chains (from .htm call graph) plus margin.

HardFault / Exception Triage

For crash analysis — fault registers, stack-frame capture, PC-to-source resolution, root-cause classification — load Skill("hardfault-triage"). The .map file sections described above (Global Symbols, Memory Map) are the bridge between the two skills: build the .map here, debug the crash there.

Heefeg gestallte Froen

Wat mécht de KI-Skill Keil Mdk Build?

Use when building, flashing, or packaging firmware with Keil MDK (UV4 CLI, ARMCLANG), analyzing .map files for ROM/RAM optimization and memory budget, or diagnosing Keil-specific build failures. NOT for non-Keil build systems (Makefile, CMake, IAR, GCC-only). For crash triage see hardfault-triage.

Firwat Keil Mdk Build op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Keil Mdk Build besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Keil Mdk Build an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/AmethystLuna/embedded-workbench/tree/master/skills/keil-mdk-build an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Keil Mdk Build benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Keil Mdk Build benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Keil Mdk Build domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Keil Mdk Build gratis?

Jo. AmethystLuna huet de Skill ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇