1- # Vairables for project configuration
1+ # Makefile for running unit tests and handling Arduino builds
2+ # Variables for project configuration
23FQBN ?=
34PORT ?=
45TESTS ?=
@@ -10,6 +11,74 @@ ENABLE_SYNC ?= 1
1011
1112.PHONY : print_args clean check_unity_path unity flash compile upload monitor
1213
14+ # Default target: Show help when no target is specified
15+ .DEFAULT_GOAL := help
16+
17+ help :
18+ @echo " ============================================================================================================"
19+ @echo " Makefile Usage Guide"
20+ @echo " ============================================================================================================"
21+ @echo " "
22+ @echo " Usage:"
23+ @echo " make [TARGET] [VARIABLES]"
24+ @echo " "
25+ @echo " Available Targets:"
26+ @echo " help Show this help guide and documentation"
27+ @echo " list_tests List all available test targets"
28+ @echo " print_args Print current configuration variables for debugging"
29+ @echo " clean Clean the build directory (removes all intermediate files)"
30+ @echo " prepare_test_environment Prepare the environment by copying common, test-specific files"
31+ @echo " compile Compile the sketch for the specified board"
32+ @echo " upload Upload the compiled sketch to the board via the specified port"
33+ @echo " flash Perform both 'compile' and 'upload' in one go"
34+ @echo " monitor Open the serial monitor for the given board and port"
35+ @echo " "
36+ @echo " Test Targets:"
37+ @echo " test_<test_name> Runs a specific test by preparing the test environment, compiling, uploading the firmware,"
38+ @echo " and running it on the target board."
39+ @echo " Example: test_digitalio_single or test_wifi_sta"
40+ @echo " "
41+ @echo " Variables:"
42+ @echo " FQBN=<board_name> Fully Qualified Board Name (default: empty). Used to specify the microcontroller board."
43+ @echo " Example: infineon:psoc6:cy8ckit_062s2_ai"
44+ @echo " "
45+ @echo " PORT=<serial_port> Serial port to connect to the board (default: empty)."
46+ @echo " Examples: /dev/ttyUSB0"
47+ @echo " "
48+ @echo " ENABLE_SYNC=<0|1> Enable (1) or disable (0) synchronization for multi boards (default: 1)."
49+ @echo " This is primarily used in CI/CD HIL checks."
50+ @echo " "
51+ @echo " BAUD_RATE=<rate> Baud rate for serial communication (default: 115200)."
52+ @echo " Example: BAUD_RATE=9600"
53+ @echo " "
54+ @echo " SERIAL=<serial_number> Optional serial number for advanced port identification (default: empty)."
55+ @echo " Example: SERIAL=123456789ABC"
56+ @echo " "
57+ @echo " Examples:"
58+ @echo " 1. Prepare the test environment:"
59+ @echo " make prepare_test_environment"
60+ @echo " "
61+ @echo " 2. Run a specific test for DigitalIO with board and port:"
62+ @echo " make FQBN=infineon:psoc6:cy8ckit_062s2_ai PORT=/dev/ttyUSB0 test_digitalio_single"
63+ @echo " "
64+ @echo " 3. Run a test with synchronization disabled:"
65+ @echo " make FQBN=infineon:psoc6:cy8ckit_062s2_ai PORT=/dev/ttyUSB0 test_digitalio_single ENABLE_SYNC=0"
66+ @echo " "
67+ @echo " 4. Open the serial monitor with a specific port:"
68+ @echo " make PORT=/dev/ttyUSB0 monitor"
69+ @echo " "
70+ @echo " 5. Combine running a test and opening the serial monitor:"
71+ @echo " make FQBN=infineon:psoc6:cy8ckit_062s2_ai PORT=/dev/ttyUSB0 test_digitalio_single monitor"
72+ @echo " "
73+ @echo " ============================================================================================================"
74+ @echo " "
75+
76+ list_tests :
77+ @echo " Available Test Targets:"
78+ @echo " "
79+ @grep -E ' ^test_[a-zA-Z0-9_]+:' $(MAKEFILE_LIST ) | cut -d' :' -f1 | sort
80+ @echo " "
81+
1382print_args :
1483# @:
1584# Info for debugging
@@ -24,33 +93,27 @@ print_args:
2493 $(info ----------------------------------)
2594 $(info )
2695
27-
2896# Clean and create build directory for arduino compilation
2997clean :
3098 $(Q ) -rm -rf build/*
3199 $(Q ) mkdir -p build
32100
33-
34-
35101# Check if UNITY_PATH variable is set
36102check_unity_path :
37103ifndef UNITY_PATH
38- $(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests!")
104+ $(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests!")
39105endif
40106
41107# Copy common files and test-specific files to build directory
42- unity : print_args clean check_unity_path
108+ prepare_test_environment : print_args clean check_unity_path
43109 $(Q ) find $(UNITY_PATH ) -name ' *.[hc]' \( -path ' *extras*' -a -path ' *src*' -or -path ' *src*' -a \! -path ' *example*' \) -exec \c p {} build \;
44110 $(Q ) find src/utils -name ' *.[hc]*' -exec \c p {} build \;
45111 $(Q ) find src -maxdepth 1 -name ' *.[hc]*' -exec \c p {} build \;
46- $(Q ) find ../../tests -maxdepth 1 -name ' test_config. *' -exec \c p {} build \;
112+ $(Q ) find ../../tests -maxdepth 1 -name ' *.[hc] *' -exec \c p {} build \;
47113 $(Q ) cp src/test_main.ino build/build.ino
48114
49- # Helper to extract the second word from the target name
50- CATEGORY = $(word 2, $(subst _, ,$@ ) )
51-
52115# Test target example
53- test_% : unity
116+ test_% : prepare_test_environment
54117 $(eval CATEGORY := $(word 2, $(subst _, ,$@ ) ) )
55118 $(Q ) cp src/corelibs/$(CATEGORY ) /$@ .cpp build 2> /dev/null || true
56119 @if [ -z " $( TESTS) " ]; then \
@@ -92,6 +155,7 @@ test_can_single: TESTS=-DTEST_CAN_SINGLE
92155test_can_connected2_node1 : TESTS=-DTEST_CAN_CONNECTED2_NODE1
93156test_can_connected2_node2 : TESTS=-DTEST_CAN_CONNECTED2_NODE2
94157
158+ # # Wire tests targets
95159test_wire_connected1_pingpong : TESTS=-DTEST_WIRE_CONNECTED1_PINGPONG
96160test_wire_connected2_masterpingpong : TESTS=-DTEST_WIRE_CONNECTED2_MASTERPINGPONG
97161test_wire_connected2_slavepingpong : TESTS=-DTEST_WIRE_CONNECTED2_SLAVEPINGPONG
@@ -123,30 +187,20 @@ test_onewire_DS18x20: TESTS=-DTEST_ONEWIRE_DS18x20
123187
124188compile :
125189ifeq ($(FQBN ) ,)
126- $(error "Must set variable FQBN in order to be able to compile Arduino sketches !")
190+ $(error "Error: FQBN must be set to compile Arduino sketches!")
127191else
128192 arduino-cli compile --clean --log --warnings all --fqbn $(FQBN) \
129- --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
193+ --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
130194 --build-property compiler.cpp.extra_flags="$(TESTS) $(if $(filter 1,$(ENABLE_SYNC)),-DENABLE_SYNC,)" \
131195 build
132-
133-
134- # --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
135-
136- # --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\" -I/myLocalWorkingDir/extras/arduino-core-api -I/myLocalWorkingDir/extras/arduino-core-api/api" \
137- # --build-property compiler.cpp.extra_flags="$(TESTS) -I/myLocalWorkingDir/extras/arduino-core-api -I/myLocalWorkingDir/extras/arduino-core-api/api" \
138- # --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
139- # --build-property compiler.cpp.extra_flags="$(TESTS)" \
140-
141196endif
142197
143-
144198upload : compile
145199ifeq ($(PORT ) ,)
146- $(error "Must set variable PORT (Windows port naming convention, ie COM16) in order to be able to flash Arduino sketches !")
200+ $(error "Error: PORT must be set to upload Arduino sketches!")
147201endif
148202ifeq ($(FQBN ) ,)
149- $(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
203+ $(error "Error: FQBN must be set to upload Arduino sketches!")
150204else
151205ifeq ($(SERIAL ) ,)
152206 arduino-cli upload --log --log-level info -v -p $(PORT) --fqbn $(FQBN) build
@@ -155,12 +209,10 @@ else
155209endif
156210endif
157211
158-
159212flash : compile upload
160213
161-
162214monitor :
163215ifeq ($(PORT ) ,)
164- $(error "Must set variable PORT (Windows port naming convention, ie COM16) in order to be able to flash Arduino sketches !")
216+ $(error "Error: PORT must be set to open the serial monitor !")
165217endif
166- arduino-cli monitor -c baudrate=115200 -p $(PORT)
218+ arduino-cli monitor -c baudrate=$(BAUD_RATE) -p $(PORT)
0 commit comments