Automated Compilation Script for Keil

Follow+Star Public Account, don’t miss exciting content

Automated Compilation Script for Keil

Source | Gitee

Author | DinoHaw

Although Keil development for microcontrollers is often criticized by many developers, it must be acknowledged that Keil is still one of the preferred tools for many microcontroller developers.

Today, I will share an open-source automated compilation script for Keil.

1. Source of Demand

Some companies with restrictions on the development process separate development from compilation (the submitted code version) and require that the compilation process involve as little human participation as possible, necessitating the implementation of automated compilation in the program. This script was developed based on this demand.Automated Compilation Script for Keil

2. Introduction

This is an automated compilation script for Keil that can be called by other scripts or programs, receiving parameters and compiling the Keil project according to those parameters without needing to open the Keil software, thus achieving automation in the program. The script mainly implements the following functions:
  1. Automatically search for all Keil projects in the directory where the script is located
  • When multiple Keil projects are found, if none is specified, the last found Keil project will be selected by default
  • When specifying a Keil project, both relative and absolute paths are supported
  • Can choose <span>Keil_v4</span> or <span>Keil_v5</span> for compilation
    • If left empty, it defaults to using <span>Keil_v5</span>, specify <span>Keil_v4</span> by inputting <span>4</span>
    • Supports fuzzy input, such as: <span>K4</span>, <span>Keil4</span>, <span>Keilv4</span>, <span>Keil_4</span>, etc.
    • Supports specifying different paths for Keil software, such as: <span>C:\Keil_v5\UV4\UV4.exe</span>
    • When the installation path of Keil is different from the one in this case <span>D:\Keil_v5\UV4\UV4.exe</span>, unless the code is modified and recompiled into a new <span>.exe</span>, the path of the Keil software must be specified
  • Can choose <span>project target</span>
    • If left empty, it defaults to the last selected <span>project target</span>
    • Supports illegal character recognition and error reporting
  • After compilation, automatically copy the <span>.bin</span> and <span>.hex</span> files to the same directory as the script
    • Only copies the <span>.bin</span> and <span>.hex</span> files generated by the selected Keil project

    3. What Parameters Are Available

    Automated Compilation Script for Keil

    Note: All parameters of this script can be input in any order, and leaving them empty indicates default selection, but parameters must be separated by spaces.

    4. I Want to Use It Directly

    1. This script only supports <span>windows</span> systems and requires that Keil software is already installed

    2. Download the runnable <span>.exe</span> from the release

    3. Place the <span>.exe</span> script in the same directory as the Keil project to be compiled (hereafter referred to as Directory A)

    4. Open <span>powershell</span> or <span>cmd</span> and navigate to Directory A

    • If using <span>powershell</span>, you can right-click in an empty space in Directory A while holding the <span>shift</span> key and select to open <span>powershell</span>, which will automatically navigate to Directory A

  • Execute the script

    .\
  • Leave a Comment