Skip to content

Commit

Permalink
fix build with iar for some stm32 family
Browse files Browse the repository at this point in the history
enable --only-one to build 1 board per family, also skip family if board specified in -b also present
  • Loading branch information
hathach committed May 13, 2024
1 parent 6f47746 commit 72224a6
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .github/actions/setup_toolchain/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ runs:
- name: Download Toolchain
if: >-
inputs.toolchain != 'arm-gcc' &&
inputs.toolchain != 'arm-iar' &&
inputs.toolchain != 'esp-idf'
uses: ./.github/actions/setup_toolchain/download
with:
Expand All @@ -44,6 +45,8 @@ runs:
BUILD_OPTION=""
if [[ "${{ inputs.toolchain }}" == *"clang"* ]]; then
BUILD_OPTION="--toolchain clang"
elif [[ "${{ inputs.toolchain }}" == "arm-iar" ]]; then
BUILD_OPTION="--toolchain iar"
fi
echo "build_option=$BUILD_OPTION"
echo "build_option=$BUILD_OPTION" >> $GITHUB_OUTPUT
Expand Down
33 changes: 32 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- 'msp430-gcc'
- 'riscv-gcc'
if: >-
matrix.toolchain != 'arm-clang' ||
${{ matrix.toolchain }} != 'arm-clang' ||
github.event_name == 'pull_request' ||
(github.event_name == 'push' && github.ref == 'refs/heads/master')
with:
Expand Down Expand Up @@ -134,3 +134,34 @@ jobs:
toolchain: 'esp-idf'
toolchain_url: 'v5.1.1'
build-args: '["-b${{ matrix.board }}"]'

# ---------------------------------------
# Build IAR on HFP self-hosted
# ---------------------------------------
arm-iar:
if: github.repository_owner == 'hathach'
runs-on: [self-hosted, Linux, X64, hifiphile]
env:
BUILD_ARGS: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)['arm-iar'].family) }}
steps:
- name: Clean workspace
run: |
echo "Cleaning up previous run"
rm -rf "${{ github.workspace }}"
mkdir -p "${{ github.workspace }}"
- name: Checkout TinyUSB
uses: actions/checkout@v4

- name: Get Dependencies
run: python3 tools/get_deps.py $BUILD_ARGS

- name: Build
run: python3 tools/build.py --toolchain iar $BUILD_ARGS

- name: Test on actual hardware (hardware in the loop)
if: >-
github.event_name == 'pull_request' ||
(github.event_name == 'push' && github.ref == 'refs/heads/master')
run: |
python3 test/hil/hil_test.py hfp.json
24 changes: 18 additions & 6 deletions .github/workflows/ci_set_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
toolchain_list = {
"aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz",
"arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-17.0.1/LLVMEmbeddedToolchainForArm-17.0.1-Linux-x86_64.tar.xz",
"arm-iar": "",
"arm-gcc": "",
"msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2",
"riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/releases/download/v10.1.0-1.1/xpack-riscv-none-embed-gcc-10.1.0-1.1-linux-x64.tar.gz",
Expand All @@ -28,12 +29,12 @@
"rp2040": ["arm-gcc"],
"samd11 samd21 saml2x": ["arm-gcc", "arm-clang"],
"samd5x_e5x samg": ["arm-gcc", "arm-clang"],
"stm32f0 stm32f1 stm32f2 stm32f3": ["arm-gcc", "arm-clang"],
"stm32f4": ["arm-gcc", "arm-clang"],
"stm32f7": ["arm-gcc", "arm-clang"],
"stm32g0 stm32g4 stm32h5": ["arm-gcc", "arm-clang"],
"stm32h7": ["arm-gcc", "arm-clang"],
"stm32l4 stm32u5 stm32wb": ["arm-gcc", "arm-clang"],
"stm32f0 stm32f1 stm32f2 stm32f3": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32f4": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32f7": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32g0 stm32g4 stm32h5": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32h7": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32l4 stm32u5 stm32wb": ["arm-gcc", "arm-clang", "arm-iar"],
"xmc4000": ["arm-gcc"],
}

Expand All @@ -43,7 +44,18 @@ def set_matrix_json():
for toolchain in toolchain_list.keys():
filtered_families = [family for family, supported_toolchain in family_list.items() if
toolchain in supported_toolchain]

# always add board in hfp.json for arm-iar
if toolchain == 'arm-iar':
with open('test/hil/hfp.json') as f:
hfp_data = json.load(f)
hfp_boards = [f"-b{board['name']}" for board in hfp_data['boards']]
filtered_families = filtered_families + hfp_boards
print(hfp_boards)
print(filtered_families)

matrix[toolchain] = {"family": filtered_families, "toolchain_url": toolchain_list[toolchain]}

print(json.dumps(matrix))


Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/stm32f0/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void board_init(void) {
//--------------------------------------------------------------------+

void board_led_write(bool state) {
GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/stm32f1/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void board_init(void) {
//--------------------------------------------------------------------+

void board_led_write(bool state) {
GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

Expand Down
3 changes: 2 additions & 1 deletion hw/bsp/stm32f2/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ void board_init(void) {
//--------------------------------------------------------------------+

void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

uint32_t board_button_read(void) {
Expand Down
5 changes: 3 additions & 2 deletions hw/bsp/stm32f3/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ void board_init(void) {
//--------------------------------------------------------------------+

void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

uint32_t board_button_read(void) {
Expand Down Expand Up @@ -142,7 +143,7 @@ uint32_t board_millis(void) {
#endif

void HardFault_Handler(void) {
asm("bkpt");
asm("bkpt 0");
}

// Required by __libc_init_array in startup code if we are compiling using
Expand Down
3 changes: 2 additions & 1 deletion hw/bsp/stm32u5/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ void board_init(void) {
//--------------------------------------------------------------------+

void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

uint32_t board_button_read(void) {
Expand Down
5 changes: 3 additions & 2 deletions hw/bsp/stm32wb/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ void board_init(void) {
//--------------------------------------------------------------------+

void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

uint32_t board_button_read(void) {
Expand Down Expand Up @@ -174,7 +175,7 @@ uint32_t board_millis(void) {
#endif

void HardFault_Handler(void) {
asm("bkpt");
asm("bkpt 1");
}

// Required by __libc_init_array in startup code if we are compiling using
Expand Down
86 changes: 48 additions & 38 deletions tools/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import random
import os
import sys
import time
Expand Down Expand Up @@ -96,15 +97,24 @@ def build_board_cmake(board, toolchain):
return ret


def build_family(family, toolchain, build_system):
def build_family(family, toolchain, build_system, only_one, boards):
all_boards = []
for entry in os.scandir(f"hw/bsp/{family}/boards"):
if entry.is_dir() and entry.name != 'pico_sdk':
all_boards.append(entry.name)
all_boards.sort()

# success, failed, skipped
ret = [0, 0, 0]

# If only-one flag is set, select one random board
if only_one:
for b in boards:
# skip if -b already specify one in this family
if find_family(b) == family:
return ret
all_boards = [random.choice(all_boards)]

# success, failed, skipped
if build_system == 'cmake':
for board in all_boards:
if build_board_cmake(board, toolchain):
Expand All @@ -131,12 +141,14 @@ def main():
parser.add_argument('-b', '--board', action='append', default=[], help='Boards to build')
parser.add_argument('-t', '--toolchain', default='gcc', help='Toolchain to use, default is gcc')
parser.add_argument('-s', '--build-system', default='cmake', help='Build system to use, default is cmake')
parser.add_argument('-1', '--only-one', action='store_true', default=False, help='Build only one random board inside a family')
args = parser.parse_args()

families = args.families
boards = args.board
toolchain = args.toolchain
build_system = args.build_system
only_one = args.only_one

if len(families) == 0 and len(boards) == 0:
print("Please specify families or board to build")
Expand All @@ -147,42 +159,40 @@ def main():
total_time = time.monotonic()
total_result = [0, 0, 0]

# build families: cmake, make
if families is not None:
all_families = []
if 'all' in families:
for entry in os.scandir("hw/bsp"):
if entry.is_dir() and entry.name != 'espressif' and os.path.isfile(entry.path + "/family.cmake"):
all_families.append(entry.name)
else:
all_families = list(families)
all_families.sort()

# succeeded, failed
for f in all_families:
fret = build_family(f, toolchain, build_system)
total_result[0] += fret[0]
total_result[1] += fret[1]
total_result[2] += fret[2]

# build board (only cmake)
if boards is not None:
for b in boards:
if build_system == 'cmake':
r = build_board_cmake(b, toolchain)
total_result[0] += r[0]
total_result[1] += r[1]
total_result[2] += r[2]
elif build_system == 'make':
all_examples = get_examples(find_family(b))
with Pool(processes=os.cpu_count()) as pool:
pool_args = list((map(lambda e, bb=b, o=f"TOOLCHAIN={toolchain}": [e, bb, o], all_examples)))
r = pool.starmap(build_utils.build_example, pool_args)
# sum all element of same index (column sum)
rsum = list(map(sum, list(zip(*r))))
total_result[0] += rsum[0]
total_result[1] += rsum[1]
total_result[2] += rsum[2]
# build families
all_families = []
if 'all' in families:
for entry in os.scandir("hw/bsp"):
if entry.is_dir() and entry.name != 'espressif' and os.path.isfile(entry.path + "/family.cmake"):
all_families.append(entry.name)
else:
all_families = list(families)
all_families.sort()

# succeeded, failed
for f in all_families:
fret = build_family(f, toolchain, build_system, only_one, boards)
total_result[0] += fret[0]
total_result[1] += fret[1]
total_result[2] += fret[2]

# build boards
for b in boards:
if build_system == 'cmake':
r = build_board_cmake(b, toolchain)
total_result[0] += r[0]
total_result[1] += r[1]
total_result[2] += r[2]
elif build_system == 'make':
all_examples = get_examples(find_family(b))
with Pool(processes=os.cpu_count()) as pool:
pool_args = list((map(lambda e, bb=b, o=f"TOOLCHAIN={toolchain}": [e, bb, o], all_examples)))
r = pool.starmap(build_utils.build_example, pool_args)
# sum all element of same index (column sum)
rsum = list(map(sum, list(zip(*r))))
total_result[0] += rsum[0]
total_result[1] += rsum[1]
total_result[2] += rsum[2]

total_time = time.monotonic() - total_time
print(build_separator)
Expand Down

0 comments on commit 72224a6

Please sign in to comment.