SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32

Auto generate build/version number

Does anyone know of a way to auto generate an incrementing firmware build or version number in System Workbench?


You may, for example, create a file named makefile.targets at the root of your project, with the following content:
all: ../build_number.h

		if [ ! -r ../build.number ]; then \
			echo build_number=1 > ../build.number; \

		source ../build.number; \
		echo "build_number=$$((build_number + 1))" > ../build.number

.PHONY: bump.build.number
post-build: bump.build.number

../build_number.h: ../build.number
		source ../build.number; \
		echo "#define BUILD_NUMBER $$build_number" > $@
Be careful: the backslashes at the end of some lines must really be the last character of the line, with no spaces after, or this will not work (you can also put everything on one line but it’s far less readable).

Then include build_number.h in the file in which you need the build number; this file will define a macro named BUILD_NUMBER which will be bumped at each successful build.

Beware that each time you will launch a build, even if nothing else has changed, the program will be updated as th ebuild number has changed... Only bumping the build number when something has effectively changed (and not for each successful build) will need quite a few more logic...

Also you may have to slightly edit this makefile fragment if you want the generated files elsewhere in your project (although makefile.targets must stay at the root of the project).

Note also that this will only work if you use the external builder (make), not the internal one.This is one of the advantages of the external builder.

Bernard (Ac6)


I can’t make it to work with my project.
After I have the project built the console log shows:

source ../build.number; \
echo “#define BUILD_NUMBER $build_number” > ../build_number.h
/bin/sh: 1: source: not found

However, I see 2 new files - build.number and build_number.h
build.number contains: build_number=1
build_number.h contains: #define BUILD_NUMBER (with no build.number value)

Will you please help me to resolve the issue?
I use AC6 sw-stm32.


I am answering myself because I found a solution.
On Windows dautrevaux’s code works flawlessly.
On Linux you have to swap “source” with “.”.

source ../build.number; \ -----> . ../build.number; \


I know it is very old topic, but I would like to make it works in my project, could be very usefull. The problem is my knoledge about makefiles is zero :-)

I import this script and it works ony first time, create files build.number and build.number.h, but every next build those files stay the smae, I am using STM32CubeIDE, latest version.

Could you please help me?

Best regards.

Thanks, I will give this a try.

One other question - what do I need to do if I want to reset the build number?

So does the build number just get stored in the .h file, so it could be edited there?

I tried adding this to my project. Initially there was an issue because the editor converted the tabs to spaces. I fixed that and have copied your sample code verbatim, but I am getting an error:

make all 
if [ ! -r ../build.number ]; then \
			echo build_number=1 > ../build.number; \
! was unexpected at this time.
make: *** [../build.number] Error 255


To reset the build number you should just have to delete the build.number file at the top of your project.

Regarding the error you have, could you check there is spaces around the brackets and exclamation marks? Also why are you using the ‘-r’ option when starting make?

Which version of System Workbench for STM32 are you using?

I’ve tested this on a v2.0 install and it works correctly.

Bernard (Ac6)


I was using 1.13 so I upgraded to 2.1. The build number generation now works.

I use the make -r option to speed up the build time. I am building the project from a network drive, so the file I/O is slower. If I do a build with no changes, it takes 40 seconds to respond with the nothing to do message without the -r option. With the -r option it completes in 2 seconds.

However, since upgrading to 2.1, now every time I do a build it first says it is generating the make files for all the source folders before starting the build. This takes more than 60 seconds before it even starts the build. Do you know why this is?



Newest Forum Posts

  1. SW4STM32 installation on Ubuntu 20.04 LTS by mahnac72, 2022-01-17 09:12
  2. STM32G0B1 support by Nevada, 2022-01-14 18:47
  3. compiling date/time by yang@omniverter.com, 2022-01-13 20:07
  4. compiling date/time by tang, 2022-01-13 10:51
  5. compiling date/time by yang@omniverter.com, 2022-01-12 19:19
  6. STM32429 Discovery board Linux problem by llcheng, 2022-01-10 10:38
  7. STM32F030K6T6 Pa7 Question by jobhunter, 2022-01-07 10:20
  8. System workbench how to configure openocd debug by gxz, 2022-01-03 15:49
  9. Auto generate build/version number by katarcza, 2022-01-01 11:00
  10. Charger firmware by kacio, 2021-12-30 09:04

Last-Modified Blogs