Skip to content

Commit

Permalink
Merge pull request #1938 from hathach/update-build
Browse files Browse the repository at this point in the history
Fix build on windows and macos
  • Loading branch information
hathach committed Mar 6, 2023
2 parents a83cef5 + ec8c292 commit 66da95a
Show file tree
Hide file tree
Showing 46 changed files with 166 additions and 113 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build_win_mac.yml
@@ -0,0 +1,56 @@
name: Build Windows/MacOS

on:
push:
paths:
- 'src/**'
- 'examples/**'
- 'lib/**'
- 'hw/**'
- '.github/workflows/build_win_mac.yml'
pull_request:
branches: [ master ]
paths:
- 'src/**'
- 'examples/**'
- 'lib/**'
- 'hw/**'
- '.github/workflows/build_win_mac.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# ---------------------------------------
# Build ARM family
# ---------------------------------------
build-arm:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install ARM GCC
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '10.3-2021.10'

- name: Checkout TinyUSB
uses: actions/checkout@v3

- name: Checkout common submodules in lib
run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip

- name: Get Dependencies
run: python3 tools/get_dependencies.py stm32f4

- name: Build
run: python3 tools/build_family.py stm32f4 stm32f411disco
1 change: 0 additions & 1 deletion examples/device/audio_4_channel_mic/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/audio_test/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/audio_test_multi_rate/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/board_test/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/cdc_dual_ports/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/cdc_msc/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/cdc_msc_freertos/Makefile
@@ -1,6 +1,5 @@
DEPS_SUBMODULES += lib/FreeRTOS-Kernel

include ../../../tools/top.mk
include ../../make.mk

FREERTOS_SRC = lib/FreeRTOS-Kernel
Expand Down
1 change: 0 additions & 1 deletion examples/device/dfu/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/dfu_runtime/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/dynamic_configuration/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/hid_boot_interface/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/hid_composite/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/hid_composite_freertos/Makefile
@@ -1,6 +1,5 @@
DEPS_SUBMODULES += lib/FreeRTOS-Kernel

include ../../../tools/top.mk
include ../../make.mk

FREERTOS_SRC = lib/FreeRTOS-Kernel
Expand Down
1 change: 0 additions & 1 deletion examples/device/hid_generic_inout/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/hid_multiple_interface/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/midi_test/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/msc_dual_lun/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/net_lwip_webserver/Makefile
@@ -1,6 +1,5 @@
DEPS_SUBMODULES += lib/lwip

include ../../../tools/top.mk
include ../../make.mk

# suppress warning caused by lwip
Expand Down
1 change: 0 additions & 1 deletion examples/device/uac2_headset/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/usbtmc/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/device/video_capture/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

ifeq ($(DISABLE_MJPEG),1)
Expand Down
1 change: 0 additions & 1 deletion examples/device/webusb_serial/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/dual/host_hid_to_device_cdc/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/host/bare_api/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/host/cdc_msc_hid/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/host/hid_controller/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

INC += \
Expand Down
1 change: 0 additions & 1 deletion examples/host/msc_file_explorer/Makefile
@@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk

FATFS_PATH = lib/fatfs/source
Expand Down
45 changes: 36 additions & 9 deletions examples/make.mk
Expand Up @@ -2,6 +2,35 @@
# Common make definition for all examples
# ---------------------------------------

#-------------- TOP and CURRENT_PATH ------------

# Set TOP to be the path to get from the current directory (where make was
# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
# the name of this makefile relative to where make was invoked.
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))

# strip off /tools/top.mk to get for example ../../..
# and Set TOP to an absolute path
TOP = $(abspath $(subst make.mk,..,$(THIS_MAKEFILE)))

# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos
CURRENT_PATH = $(subst $(TOP)/,,$(abspath .))

# Detect whether shell style is windows or not
# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
ifeq '$(findstring ;,$(PATH))' ';'
# PATH contains semicolon - so we're definitely on Windows.
CMDEXE := 1

# makefile shell commands should use syntax for DOS CMD, not unix sh
# Unfortunately, SHELL may point to sh or bash, which can't accept DOS syntax.
# We can't just use sh, because while sh and/or bash shell may be available,
# many Windows environments won't have utilities like realpath used below, so...
# Force DOS command shell on Windows.
SHELL := cmd.exe
endif


# Build directory
BUILD := _build/$(BOARD)

Expand Down Expand Up @@ -45,14 +74,10 @@ else
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
endif


#-------------- Cross Compiler ------------
# Can be set by board, default to ARM GCC
CROSS_COMPILE ?= arm-none-eabi-

# Allow for -Os to be changed by board makefiles in case -Os is not allowed
CFLAGS_OPTIMIZED ?= -Os

ifeq ($(CC),iccarm)
USE_IAR = 1
endif
Expand All @@ -61,29 +86,28 @@ ifdef USE_IAR
AS = iasmarm
LD = ilinkarm
OBJCOPY = ielftool
SIZE = echo "size not available for IAR"
SIZE = size

else
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
AS = $(CC) -x assembler-with-cpp
LD = $(CC)

GDB = $(CROSS_COMPILE)gdb
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
endif

MKDIR = mkdir

ifeq ($(CMDEXE),1)
CP = copy
RM = del
MKDIR = mkdir
PYTHON = python
else
SED = sed
CP = cp
RM = rm
MKDIR = mkdir
PYTHON = python3
endif

Expand All @@ -95,6 +119,9 @@ SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))

INC += $(TOP)/$(FAMILY_PATH)

# Allow for -Os to be changed by board makefiles in case -Os is not allowed
CFLAGS_OPTIMIZED ?= -Os

# GCC Compiler Flags
GCC_CFLAGS += \
-ggdb \
Expand Down
26 changes: 15 additions & 11 deletions examples/rules.mk
Expand Up @@ -112,7 +112,7 @@ OBJ_DIRS = $(sort $(dir $(OBJ)))
$(OBJ): | $(OBJ_DIRS)
$(OBJ_DIRS):
ifeq ($(CMDEXE),1)
@$(MKDIR) $(subst /,\,$@)
-@$(MKDIR) $(subst /,\,$@)
else
@$(MKDIR) -p $@
endif
Expand All @@ -139,34 +139,34 @@ $(BUILD)/obj/%_asm.o: %.S
@echo AS $(notdir $@)
@$(AS) $(ASFLAGS) -c -o $@ $<

ifndef USE_IAR
# GCC based compiler
ifdef USE_IAR
# IAR Compiler
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) -O binary $^ $@
@$(OBJCOPY) --silent --bin $^ $@

$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) -O ihex $^ $@
@$(OBJCOPY) --silent --ihex $^ $@

$(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(LD) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
@$(LD) -o $@ $(IAR_LDFLAGS) $^

else

# IAR Compiler
# GCC based compiler
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --silent --bin $^ $@
@$(OBJCOPY) -O binary $^ $@

$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --silent --ihex $^ $@
@$(OBJCOPY) -O ihex $^ $@

$(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(LD) -o $@ $(IAR_LDFLAGS) $^
@$(LD) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group

endif

# UF2 generation, iMXRT need to strip to text only before conversion
Expand Down Expand Up @@ -265,7 +265,11 @@ debug-bmp: $(BUILD)/$(PROJECT).elf

# Create binary directory
$(BIN):
ifeq ($(CMDEXE),1)
@$(MKDIR) $(subst /,\,$@)
else
@$(MKDIR) -p $@
endif

# Copy binaries .elf, .bin, .hex, .uf2 to BIN for upload
# due to large size of combined artifacts, only uf2 is uploaded for now
Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/stm32f0/family.c
Expand Up @@ -165,7 +165,7 @@ void HardFault_Handler (void)
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
void assert_failed(const char* file, uint32_t line)
{
(void) file; (void) line;
/* USER CODE BEGIN 6 */
Expand Down
6 changes: 4 additions & 2 deletions hw/bsp/stm32f0/family.mk
Expand Up @@ -24,7 +24,7 @@ GCC_CFLAGS += \
-nostdlib -nostartfiles \

# suppress warning caused by vendor mcu driver
GCC_CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual
GCC_CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align

# IAR Flags
IAR_CFLAGS += --cpu cortex-m0
Expand All @@ -42,7 +42,9 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_dma.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart_ex.c

INC += \
$(TOP)/$(BOARD_PATH) \
Expand Down
4 changes: 2 additions & 2 deletions hw/bsp/stm32f0/stm32f0xx_hal_conf.h
Expand Up @@ -303,9 +303,9 @@
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
#define assert_param(expr) ((expr) ? (void)0U : assert_failed(__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
void assert_failed(const char* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
Expand Down

0 comments on commit 66da95a

Please sign in to comment.