Question

recently i'm working on some project with arm but no OS in it.
Now when i compile it, i must open keil.
but keil is weak in edit, so i'm considering to write a script to execute complier of keil, to build the project.
but i know little about keil, so i want to know if it is possble, for avoiding useless work.

thanks for any help.

Was it helpful?

Solution

As mentioned by artless noise you can call armcc directly on the command line or integrate it into a build system like make, scons, etc . A good starting point is letting Keil uVision create a batch file for you: CREATING A PROJECT BATCH FILE. Another possibility is to call Keil from the command line with the project file as command line parameter with options to build the project.Keil uV4 command line. BTW I use this command line options also for automated unit testing in the simulator and for flash download.

OTHER TIPS

Edit 2021:

Revisited this answer as Kiel still hasn't improved their command-line tools.

  • Corrected a small typo in the script.
  • Fixed the link to the Kiel command line documentation.
  • Added the script to a Github gist, so it can easier be forked.

Original 2019 answer:

Here's my attempt at scripting the Keil uVision4 compiler.

Keil's Commandline interface basically hasn't changed since at least 2011, and it's very limited - especially for using the compiler on a build server.

Additionally, the Keil uVision4 compiler is very strange, not least when it comes to creating output, but in theory supports two methods - however sometimes none, only one, the other, or both output files are created. This batch script attempts to handle all of these situations.

Another issue is when the Flex license server is in use. This script allows you to define the number of times you want to retry a build and to set the interval between attempted builds. It also successfully recover if the license is suddenly withdrawn during a build.

If you have additions to this script, please post them here.

@echo off
setlocal
:: KeiluVisionBuilder.cmd
:: Written by Flemming Steffensen, 2019.
:: Free for use and abuse by anyone.

:: ======================
:: Configuration
::     
set WaitForLicenseTimeout=60
set BuildAttemptsMax=10

set "ProjectFileName=bootloader.uvprojx"
set "ProjectPath=MyProject\bootloader\"
set "Compiler=C:\Keil_v5\UV4\UV4.exe"
set "OutFolder=OutputFolderDefinedIn_MyProject\"
::
:: ======================
:: Do not edit below this line
set BuildAttempt=0

pushd %ProjectPath%

:PerformBuild
echo:
echo:Performing Keil Build...

if exist build.log                del build.log
if exist %OutFolder%*.build_log.htm  del %OutFolder%*.build_log.htm

start /wait %Compiler% -j0 -b %ProjectFileName% -o build.log
set ReportedError=%ERRORLEVEL%

:: Scan build.log to determine if the license is locked.
find /c "Error: *** All Flex licenses are in use! ***" build.log  >nul
if %errorlevel% equ 0 (
    set /a BuildAttempt=%BuildAttempt% + 1 
    echo:Error: *** All Flex licenses are in use!
    if %BuildAttempt% equ %BuildAttemptsMax% goto NoLicenseAvailable
    echo:Retrying ^(%BuildAttempt% of %BuildAttemptsMax%^) in %WaitForLicenseTimeout% seconds
    waitfor SignalNeverComming /T %WaitForLicenseTimeout% >nul 2>&1
    goto PerformBuild
) 
:: Scan alternative build.log to determine if the license is locked.
find /c "Failed to check out a license" %OutFolder%*.build_log.htm >nul
if %errorlevel% equ 0 (
    set /a BuildAttempt=%BuildAttempt% + 1 
    echo:Error: Failed to check out a license
    if %BuildAttempt% equ %BuildAttemptsMax% goto NoLicenseAvailable
    echo:Retrying ^(%BuildAttempt% of %BuildAttemptsMax%^) in %WaitForLicenseTimeout% seconds
    waitfor SignalNeverComming /T %WaitForLicenseTimeout% >nul 2>&1
    goto PerformBuild
)
goto NoLicenseProblem


:NoLicenseAvailable
echo:Error: After %BuildAttempt% attempts, the Flex license still appear to be unavailable. Failing the build!
echo:
popd
exit /b 1

:NoLicenseProblem
:: Parse exit codes
set KnownErrors=0 1 2 3 11 12 13 15 20 41

echo:Kiel compiler exited with error code %ReportedError%

for %%a in (%KnownErrors%) do (
   if [%ReportedError%] equ [%%a] goto Error%ReportedError%
)
goto UnknownError

:Error0
   echo Compilation successful
   goto ExitButContinueJob

:Error1
   echo Warnings were found
   goto ExitButContinueJob

:Error2 
   echo Errors were found
   goto ExitCritical

:Error3
   echo Error 3 = Fatal Errors
   goto ExitCritical

:Error11
   echo Error 11 = Cannot open project file for writing
   goto ExitCritical

:Error12
   echo Error 12 = Device with given name in not found in database
   goto ExitCritical

:Error13
   echo Error 13 = Error writing project file
   goto ExitCritical

:Error15
   echo Error 15 = Error reading import XML file
   goto ExitCritical

:Error20
   echo Error 20 = Can not convert the project file.
   goto ExitCritical

:Error41
   echo Error 41 = Can not create the logfile requested using the -l switch.
   goto ExitCritical

:UnknownError
   echo Error %ReportedError% = Unknown error 
   goto ExitCritical

:ExitCritical
echo:
if [%ReportedError%] neq 0 exit /b %ReportedError% 

:ExitButContinueJob
echo:
popd
exit /b 0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top