From 3fee8b402e3efefc341a0c1ce0474deb748858b2 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 17 Jan 2023 16:20:04 +0700 Subject: [PATCH 01/23] update makefile to support iar build starting with stm32f070 --- examples/make.mk | 37 ++++-- examples/rules.mk | 124 +++++++++++++----- .../stm32f0/boards/stm32f070rbnucleo/board.mk | 6 +- hw/bsp/stm32f0/family.c | 2 +- hw/bsp/stm32f0/family.mk | 17 ++- 5 files changed, 135 insertions(+), 51 deletions(-) diff --git a/examples/make.mk b/examples/make.mk index 73a39a8fe..dd7a5cf4e 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -49,14 +49,31 @@ 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 -CC = $(CROSS_COMPILE)gcc -CXX = $(CROSS_COMPILE)g++ -GDB = $(CROSS_COMPILE)gdb -OBJCOPY = $(CROSS_COMPILE)objcopy -SIZE = $(CROSS_COMPILE)size +ifeq ($(CC),iccarm) +USE_IAR = 1 +endif + +ifdef USE_IAR + AS = iasmarm + LD = ilinkarm + OBJCOPY = ielftool + SIZE = echo "size not available for IAR" + +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) @@ -78,8 +95,8 @@ SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c)) INC += $(TOP)/$(FAMILY_PATH) -# Compiler Flags -CFLAGS += \ +# GCC Compiler Flags +GCC_CFLAGS += \ -ggdb \ -fdata-sections \ -ffunction-sections \ @@ -110,13 +127,13 @@ CFLAGS += \ # conversion is too strict for most mcu driver, may be disable sign/int/arith-conversion # -Wconversion - + # Debugging/Optimization ifeq ($(DEBUG), 1) - CFLAGS += -O0 + GCC_CFLAGS += -O0 NO_LTO = 1 else - CFLAGS += $(CFLAGS_OPTIMIZED) + GCC_CFLAGS += $(CFLAGS_OPTIMIZED) endif # Log level is mapped to TUSB DEBUG option diff --git a/examples/rules.mk b/examples/rules.mk index c3134056a..2c4df85ba 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -46,31 +46,34 @@ INC += $(TOP)/src CFLAGS += $(addprefix -I,$(INC)) +ifdef USE_IAR + +IAR_CFLAGS += $(CFLAGS) -e --debug +IAR_LDFLAGS += --config $(TOP)/$(IAR_LD_FILE) + +else + +CFLAGS += $(GCC_CFLAGS) + # LTO makes it difficult to analyze map file for optimizing size purpose # We will run this option in ci ifeq ($(NO_LTO),1) CFLAGS := $(filter-out -flto,$(CFLAGS)) endif -ifneq ($(LD_FILE),) -LDFLAGS_LD_FILE ?= -Wl,-T,$(TOP)/$(LD_FILE) +LDFLAGS += $(CFLAGS) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections + +ifdef LD_FILE +LDFLAGS += -Wl,-T,$(TOP)/$(LD_FILE) endif -LDFLAGS += $(CFLAGS) $(LDFLAGS_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections ifneq ($(SKIP_NANOLIB), 1) LDFLAGS += -specs=nosys.specs -specs=nano.specs endif ASFLAGS += $(CFLAGS) -# Assembly files can be name with upper case .S, convert it to .s -SRC_S := $(SRC_S:.S=.s) - -# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966 -# assembly file should be placed first in linking order -# '_asm' suffix is added to object of assembly file -OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=_asm.o)) -OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o)) +endif # Verbose mode ifeq ("$(V)","1") @@ -79,6 +82,21 @@ $(info LDFLAGS $(LDFLAGS)) $(info ) $(info ASFLAGS $(ASFLAGS)) $(info ) endif +# Assembly files can be name with upper case .S, convert it to .s +SRC_S := $(SRC_S:.S=.s) +IAR_SRC_S := $(IAR_SRC_S:.S=.s) + +# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966 +# assembly file should be placed first in linking order +# '_asm' suffix is added to object of assembly file +ifdef USE_IAR +OBJ += $(addprefix $(BUILD)/obj/, $(IAR_SRC_S:.s=_asm.o)) +else +OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=_asm.o)) +endif + +OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o)) + # --------------------------------------- # Rules # --------------------------------------- @@ -96,9 +114,15 @@ else @$(MKDIR) -p $@ endif -$(BUILD)/$(PROJECT).elf: $(OBJ) - @echo LINK $@ - @$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group +# We set vpath to point to the top of the tree so that the source files +# can be located. By following this scheme, it allows a single build rule +# to be used to compile all .c files. +vpath %.c . $(TOP) +vpath %.s . $(TOP) +vpath %.S . $(TOP) + +ifndef USE_IAR +# GCC based compiler $(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf @echo CREATE $@ @@ -108,6 +132,56 @@ $(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf @echo CREATE $@ @$(OBJCOPY) -O ihex $^ $@ +$(BUILD)/$(PROJECT).elf: $(OBJ) + @echo LINK $@ + @$(LD) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group + +$(BUILD)/obj/%.o: %.c + @echo CC $(notdir $@) + @$(CC) $(CFLAGS) -c -MD -o $@ $< + +# ASM sources lower case .s +$(BUILD)/obj/%_asm.o: %.s + @echo AS $(notdir $@) + @$(AS) $(ASFLAGS) -c -o $@ $< + +# ASM sources upper case .S +$(BUILD)/obj/%_asm.o: %.S + @echo AS $(notdir $@) + @$(AS) $(ASFLAGS) -c -o $@ $< + +else + +# IAR Compiler + +$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf + @echo CREATE $@ + @$(OBJCOPY) --bin $^ $@ + +$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf + @echo CREATE $@ + @$(OBJCOPY) --ihex $^ $@ + +$(BUILD)/$(PROJECT).elf: $(OBJ) + @echo LINK $@ + @$(LD) $(IAR_LDFLAGS) $^ -o $@ + +$(BUILD)/obj/%.o: %.c + @echo CC $(notdir $@) + @$(CC) $(IAR_CFLAGS) -c -o $@ $< + +# ASM sources lower case .s +$(BUILD)/obj/%_asm.o: %.s + @echo AS $(notdir $@) + @$(AS) $(IAR_ASFLAGS) -c -o $@ $< + +# ASM sources upper case .S +$(BUILD)/obj/%_asm.o: %.S + @echo AS $(notdir $@) + @$(AS) $(IAR_ASFLAGS) -c -o $@ $< + +endif + # UF2 generation, iMXRT need to strip to text only before conversion ifeq ($(FAMILY),imxrt) $(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).elf @@ -122,27 +196,8 @@ endif copy-artifact: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex $(BUILD)/$(PROJECT).uf2 -# We set vpath to point to the top of the tree so that the source files -# can be located. By following this scheme, it allows a single build rule -# to be used to compile all .c files. -vpath %.c . $(TOP) -$(BUILD)/obj/%.o: %.c - @echo CC $(notdir $@) - @$(CC) $(CFLAGS) -c -MD -o $@ $< - -# ASM sources lower case .s -vpath %.s . $(TOP) -$(BUILD)/obj/%_asm.o: %.s - @echo AS $(notdir $@) - @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< - -# ASM sources upper case .S -vpath %.S . $(TOP) -$(BUILD)/obj/%_asm.o: %.S - @echo AS $(notdir $@) - @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< - endif +# ---------------- GNU Make End ----------------------- .PHONY: clean clean: @@ -151,7 +206,6 @@ ifeq ($(CMDEXE),1) else $(RM) -rf $(BUILD) endif -# ---------------- GNU Make End ----------------------- # get depenecies .PHONY: get-deps diff --git a/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk b/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk index 7c0ee40b6..242b5a034 100644 --- a/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk @@ -1,11 +1,13 @@ CFLAGS += -DSTM32F070xB -DCFG_EXAMPLE_VIDEO_READONLY +SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f070xb.s LD_FILE = $(BOARD_PATH)/stm32F070rbtx_flash.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f070xb.s +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f070xb.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f070xb_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f070rb # flash target using on-board stlink -flash: flash-stlink +flash: flash-stlink \ No newline at end of file diff --git a/hw/bsp/stm32f0/family.c b/hw/bsp/stm32f0/family.c index 8de3147e2..806c4af51 100644 --- a/hw/bsp/stm32f0/family.c +++ b/hw/bsp/stm32f0/family.c @@ -153,7 +153,7 @@ uint32_t board_millis(void) void HardFault_Handler (void) { - asm("bkpt"); + __asm("BKPT #0\n"); } #ifdef USE_FULL_ASSERT diff --git a/hw/bsp/stm32f0/family.mk b/hw/bsp/stm32f0/family.mk index 39831e154..a81ab426f 100644 --- a/hw/bsp/stm32f0/family.mk +++ b/hw/bsp/stm32f0/family.mk @@ -8,17 +8,28 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk CFLAGS += \ + -DCFG_EXAMPLE_MSC_READONLY \ + -DCFG_TUSB_MCU=OPT_MCU_STM32F0 + +# -------------- +# GCC Flags +# -------------- +GCC_CFLAGS += \ -flto \ -mthumb \ -mabi=aapcs \ -mcpu=cortex-m0 \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ - -DCFG_EXAMPLE_MSC_READONLY \ - -DCFG_TUSB_MCU=OPT_MCU_STM32F0 # suppress warning caused by vendor mcu driver -CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual +GCC_CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual + +# -------------- +# IAR Flags +# -------------- +IAR_CFLAGS += --cpu cortex-m0 +IAR_ASFLAGS += --cpu cortex-m0 SRC_C += \ src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \ From c414cc650e995c9136afcb291434c3af99abd178 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 17 Jan 2023 16:30:33 +0700 Subject: [PATCH 02/23] try running iar build with self-host --- .github/workflows/build_iar_arm.yml | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/build_iar_arm.yml diff --git a/.github/workflows/build_iar_arm.yml b/.github/workflows/build_iar_arm.yml new file mode 100644 index 000000000..65ab6e5c8 --- /dev/null +++ b/.github/workflows/build_iar_arm.yml @@ -0,0 +1,54 @@ +name: Build IAR for ARM + +on: + push: + paths: + - 'src/**' + - 'examples/**' + - 'lib/**' + - 'hw/**' + pull_request: + branches: [ master ] + paths: + - 'src/**' + - 'examples/**' + - 'lib/**' + - 'hw/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + build-arm: + runs-on: [self-hosted, Linux, X64, hifiphile] + strategy: + fail-fast: false + matrix: + family: + # Alphabetical order + - 'stm32f0' + steps: + - name: Clean workspace + run: | + echo "Cleaning up previous run" + rm -rf "${{ github.workspace }}" + mkdir -p "${{ github.workspace }}" + + - name: Checkout TinyUSB + uses: actions/checkout@v3 + + - name: Checkout submodules and dependencies + run: | + git submodule update --init lib/FreeRTOS-Kernel lib/lwip lib/sct_neopixel + python3 tools/get_dependencies.py ${{ matrix.family }} + + - name: Checkout pico-sdk for rp2040 + if: matrix.family == 'rp2040' + run: | + git clone --depth 1 -b develop https://github.com/raspberrypi/pico-sdk ~/pico-sdk + echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk + + - name: Build + #run: python3 tools/build_family.py ${{ matrix.family }} + run: make -j -C examples/device/cdc_msc BOARD=stm32f070rbnucleo CC=iccarm all From 1891802f081e586ad5e992a4e498a069d28f529e Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 17 Jan 2023 16:38:02 +0700 Subject: [PATCH 03/23] update all f0 board to build with iar --- .github/workflows/build_iar_arm.yml | 5 ++++- hw/bsp/stm32f0/boards/stm32f072disco/board.mk | 4 +++- hw/bsp/stm32f0/boards/stm32f072eval/board.mk | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_iar_arm.yml b/.github/workflows/build_iar_arm.yml index 65ab6e5c8..ed75eca5b 100644 --- a/.github/workflows/build_iar_arm.yml +++ b/.github/workflows/build_iar_arm.yml @@ -51,4 +51,7 @@ jobs: - name: Build #run: python3 tools/build_family.py ${{ matrix.family }} - run: make -j -C examples/device/cdc_msc BOARD=stm32f070rbnucleo CC=iccarm all + run: | + make -j -C examples/device/cdc_msc BOARD=stm32f070rbnucleo CC=iccarm all + make -j -C examples/device/cdc_msc BOARD=stm32f072disco CC=iccarm all + make -j -C examples/device/cdc_msc BOARD=stm32f072eval CC=iccarm all diff --git a/hw/bsp/stm32f0/boards/stm32f072disco/board.mk b/hw/bsp/stm32f0/boards/stm32f072disco/board.mk index 7c72d8f4c..1003be553 100644 --- a/hw/bsp/stm32f0/boards/stm32f072disco/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f072disco/board.mk @@ -1,8 +1,10 @@ CFLAGS += -DSTM32F072xB -DCFG_EXAMPLE_VIDEO_READONLY +SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s LD_FILE = $(BOARD_PATH)/STM32F072RBTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f072xb.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f072xb_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f072rb diff --git a/hw/bsp/stm32f0/boards/stm32f072eval/board.mk b/hw/bsp/stm32f0/boards/stm32f072eval/board.mk index b625c3ebd..4134c1f45 100644 --- a/hw/bsp/stm32f0/boards/stm32f072eval/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f072eval/board.mk @@ -1,8 +1,10 @@ CFLAGS += -DSTM32F072xB -DLSI_VALUE=40000 -DCFG_EXAMPLE_VIDEO_READONLY +SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s LD_FILE = $(BOARD_PATH)/STM32F072VBTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f072xb.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f072xb_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f072vb From c86e628a4c199a39f8317a0d4b5dd96e9692e544 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 17 Jan 2023 23:37:00 +0700 Subject: [PATCH 04/23] update build script to support iar with CC=iccarm option --- .github/workflows/build_iar_arm.yml | 2 +- tools/build_board.py | 2 +- tools/build_family.py | 11 ++++++++--- tools/build_utils.py | 6 +++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_iar_arm.yml b/.github/workflows/build_iar_arm.yml index ed75eca5b..bcf560024 100644 --- a/.github/workflows/build_iar_arm.yml +++ b/.github/workflows/build_iar_arm.yml @@ -1,4 +1,4 @@ -name: Build IAR for ARM +name: Build ARM with IAR on: push: diff --git a/tools/build_board.py b/tools/build_board.py index 8d10ef820..4593dafa5 100644 --- a/tools/build_board.py +++ b/tools/build_board.py @@ -52,7 +52,7 @@ if __name__ == '__main__': for example in all_examples: print(build_separator) with Pool(processes=os.cpu_count()) as pool: - pool_args = list((map(lambda b, e=example: [e, b], all_boards))) + pool_args = list((map(lambda b, e=example, o='': [e, b, o], all_boards))) result = pool.starmap(build_utils.build_example, pool_args) # sum all element of same index (column sum) result = list(map(sum, list(zip(*result)))) diff --git a/tools/build_family.py b/tools/build_family.py index c6c64d2b3..cdc099691 100644 --- a/tools/build_family.py +++ b/tools/build_family.py @@ -11,6 +11,7 @@ SKIPPED = "\033[33mskipped\033[0m" build_separator = '-' * 106 +make_iar_option = 'CC=iccarm' def filter_with_input(mylist): if len(sys.argv) > 1: @@ -19,7 +20,7 @@ def filter_with_input(mylist): mylist[:] = input_args -def build_family(example, family): +def build_family(example, family, make_option): all_boards = [] for entry in os.scandir("hw/bsp/{}/boards".format(family)): if entry.is_dir() and entry.name != 'pico_sdk': @@ -28,13 +29,17 @@ def build_family(example, family): all_boards.sort() with Pool(processes=os.cpu_count()) as pool: - pool_args = list((map(lambda b, e=example: [e, b], all_boards))) + pool_args = list((map(lambda b, e=example, o=make_option: [e, b, o], all_boards))) result = pool.starmap(build_utils.build_example, pool_args) # sum all element of same index (column sum) return list(map(sum, list(zip(*result)))) if __name__ == '__main__': + # IAR CC + if make_iar_option not in sys.argv: + make_iar_option = '' + # If examples are not specified in arguments, build all all_examples = [] for dir1 in os.scandir("examples"): @@ -62,7 +67,7 @@ if __name__ == '__main__': for example in all_examples: print(build_separator) for family in all_families: - fret = build_family(example, family) + fret = build_family(example, family, make_iar_option) total_result = list(map(lambda x, y: x + y, total_result, fret)) total_time = time.monotonic() - total_time diff --git a/tools/build_utils.py b/tools/build_utils.py index f457c7986..ad1daf8c7 100644 --- a/tools/build_utils.py +++ b/tools/build_utils.py @@ -77,7 +77,7 @@ def skip_example(example, board): return False -def build_example(example, board): +def build_example(example, board, make_option): start_time = time.monotonic() flash_size = "-" sram_size = "-" @@ -91,14 +91,14 @@ def build_example(example, board): ret[2] = 1 print(build_format.format(example, board, status, '-', flash_size, sram_size)) else: - build_result = subprocess.run("make -j -C examples/{} BOARD={} all".format(example, board), shell=True, + build_result = subprocess.run("make -j -C examples/{} BOARD={} {} all".format(example, board, make_option), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if build_result.returncode == 0: status = SUCCEEDED ret[0] = 1 (flash_size, sram_size) = build_size(example, board) - subprocess.run("make -j -C examples/{} BOARD={} copy-artifact".format(example, board), shell=True, + subprocess.run("make -j -C examples/{} BOARD={} {} copy-artifact".format(example, board, make_option), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) else: status = FAILED From 8df2fd1916d5e69cfaad7516399a8d7da5060f57 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 17 Jan 2023 23:38:10 +0700 Subject: [PATCH 05/23] update freertos example to build with iar --- examples/device/cdc_msc_freertos/Makefile | 12 ++++++++---- .../src/FreeRTOSConfig/FreeRTOSConfig.h | 7 ++++++- .../device/hid_composite_freertos/Makefile | 12 ++++++++---- .../src/FreeRTOSConfig/FreeRTOSConfig.h | 7 ++++++- examples/rules.mk | 19 +++++++++---------- .../stm32f0/boards/stm32f070rbnucleo/board.mk | 2 +- hw/bsp/stm32f0/boards/stm32f072disco/board.mk | 2 +- hw/bsp/stm32f0/boards/stm32f072eval/board.mk | 2 +- 8 files changed, 40 insertions(+), 23 deletions(-) diff --git a/examples/device/cdc_msc_freertos/Makefile b/examples/device/cdc_msc_freertos/Makefile index ff4b41108..4ee816880 100644 --- a/examples/device/cdc_msc_freertos/Makefile +++ b/examples/device/cdc_msc_freertos/Makefile @@ -4,13 +4,14 @@ include ../../../tools/top.mk include ../../make.mk FREERTOS_SRC = lib/FreeRTOS-Kernel +FREERTOS_PORTABLE_SRC= $(FREERTOS_SRC)/portable/$(if $(USE_IAR),IAR,GCC)/$(FREERTOS_PORT) INC += \ src \ src/FreeRTOSConfig \ $(TOP)/hw \ $(TOP)/$(FREERTOS_SRC)/include \ - $(TOP)/$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT) + $(TOP)/$(FREERTOS_PORTABLE_SRC) # Example source EXAMPLE_SOURCE = \ @@ -27,17 +28,20 @@ SRC_C += \ $(FREERTOS_SRC)/queue.c \ $(FREERTOS_SRC)/tasks.c \ $(FREERTOS_SRC)/timers.c \ - $(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c)) + $(subst ../../../,,$(wildcard ../../../$(FREERTOS_PORTABLE_SRC)/*.c)) + +SRC_S += \ + $(subst ../../../,,$(wildcard ../../../$(FREERTOS_PORTABLE_SRC)/*.s)) # include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1 # SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c # CFLAGS += -Wno-error=sign-compare # Suppress FreeRTOSConfig.h warnings -CFLAGS += -Wno-error=redundant-decls +GCC_CFLAGS += -Wno-error=redundant-decls # Suppress FreeRTOS source warnings -CFLAGS += -Wno-error=cast-qual +GCC_CFLAGS += -Wno-error=cast-qual # FreeRTOS (lto + Os) linker issue LDFLAGS += -Wl,--undefined=vTaskSwitchContext diff --git a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h index 968c59749..efd527ed2 100644 --- a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h +++ b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h @@ -42,6 +42,9 @@ * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ +// skip if is compiled with assembler +#if !defined(__ASSEMBLER__) && !defined(__IASMARM__) + // Include MCU header #include "bsp/board_mcu.h" @@ -57,6 +60,8 @@ extern uint32_t SystemCoreClock; #endif +#endif + /* Cortex M23/M33 port configuration. */ #define configENABLE_MPU 0 #define configENABLE_FPU 1 @@ -166,7 +171,7 @@ #elif defined(__ECLIC_INTCTLBITS) // RISC-V Bumblebee core from nuclei #define configPRIO_BITS __ECLIC_INTCTLBITS -#else +#elif !defined(__ASSEMBLER__) && !defined(__IASMARM__) #error "FreeRTOS configPRIO_BITS to be defined" #endif diff --git a/examples/device/hid_composite_freertos/Makefile b/examples/device/hid_composite_freertos/Makefile index 9c66b896d..a354a90b6 100644 --- a/examples/device/hid_composite_freertos/Makefile +++ b/examples/device/hid_composite_freertos/Makefile @@ -4,13 +4,14 @@ include ../../../tools/top.mk include ../../make.mk FREERTOS_SRC = lib/FreeRTOS-Kernel +FREERTOS_PORTABLE_SRC= $(FREERTOS_SRC)/portable/$(if $(USE_IAR),IAR,GCC)/$(FREERTOS_PORT) INC += \ src \ src/FreeRTOSConfig \ $(TOP)/hw \ $(TOP)/$(FREERTOS_SRC)/include \ - $(TOP)/$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT) + $(TOP)/$(FREERTOS_PORTABLE_SRC) # Example source EXAMPLE_SOURCE = \ @@ -26,17 +27,20 @@ SRC_C += \ $(FREERTOS_SRC)/queue.c \ $(FREERTOS_SRC)/tasks.c \ $(FREERTOS_SRC)/timers.c \ - $(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c)) + $(subst ../../../,,$(wildcard ../../../$(FREERTOS_PORTABLE_SRC)/*.c)) + +SRC_S += \ + $(subst ../../../,,$(wildcard ../../../$(FREERTOS_PORTABLE_SRC)/*.s)) # include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1 # SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c # CFLAGS += -Wno-error=sign-compare # Suppress FreeRTOSConfig.h warnings -CFLAGS += -Wno-error=redundant-decls +GCC_CFLAGS += -Wno-error=redundant-decls # Suppress FreeRTOS source warnings -CFLAGS += -Wno-error=cast-qual +GCC_CFLAGS += -Wno-error=cast-qual # FreeRTOS (lto + Os) linker issue LDFLAGS += -Wl,--undefined=vTaskSwitchContext diff --git a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h index 968c59749..efd527ed2 100644 --- a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h +++ b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h @@ -42,6 +42,9 @@ * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ +// skip if is compiled with assembler +#if !defined(__ASSEMBLER__) && !defined(__IASMARM__) + // Include MCU header #include "bsp/board_mcu.h" @@ -57,6 +60,8 @@ extern uint32_t SystemCoreClock; #endif +#endif + /* Cortex M23/M33 port configuration. */ #define configENABLE_MPU 0 #define configENABLE_FPU 1 @@ -166,7 +171,7 @@ #elif defined(__ECLIC_INTCTLBITS) // RISC-V Bumblebee core from nuclei #define configPRIO_BITS __ECLIC_INTCTLBITS -#else +#elif !defined(__ASSEMBLER__) && !defined(__IASMARM__) #error "FreeRTOS configPRIO_BITS to be defined" #endif diff --git a/examples/rules.mk b/examples/rules.mk index 2c4df85ba..c3b757eec 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -48,8 +48,11 @@ CFLAGS += $(addprefix -I,$(INC)) ifdef USE_IAR -IAR_CFLAGS += $(CFLAGS) -e --debug +IAR_CFLAGS += $(CFLAGS) -e --debug --silent IAR_LDFLAGS += --config $(TOP)/$(IAR_LD_FILE) +IAR_ASFLAGS += $(CFLAGS) -S + +SRC_S += $(IAR_SRC_S) else @@ -73,7 +76,9 @@ endif ASFLAGS += $(CFLAGS) -endif +SRC_S += $(GCC_SRC_S) + +endif # USE_IAR # Verbose mode ifeq ("$(V)","1") @@ -84,17 +89,11 @@ endif # Assembly files can be name with upper case .S, convert it to .s SRC_S := $(SRC_S:.S=.s) -IAR_SRC_S := $(IAR_SRC_S:.S=.s) # Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966 # assembly file should be placed first in linking order # '_asm' suffix is added to object of assembly file -ifdef USE_IAR -OBJ += $(addprefix $(BUILD)/obj/, $(IAR_SRC_S:.s=_asm.o)) -else OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=_asm.o)) -endif - OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o)) # --------------------------------------- @@ -156,11 +155,11 @@ else $(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf @echo CREATE $@ - @$(OBJCOPY) --bin $^ $@ + @$(OBJCOPY) --silent --bin $^ $@ $(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf @echo CREATE $@ - @$(OBJCOPY) --ihex $^ $@ + @$(OBJCOPY) --silent --ihex $^ $@ $(BUILD)/$(PROJECT).elf: $(OBJ) @echo LINK $@ diff --git a/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk b/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk index 242b5a034..f470b80f0 100644 --- a/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk @@ -1,6 +1,6 @@ CFLAGS += -DSTM32F070xB -DCFG_EXAMPLE_VIDEO_READONLY -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f070xb.s +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f070xb.s LD_FILE = $(BOARD_PATH)/stm32F070rbtx_flash.ld IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f070xb.s diff --git a/hw/bsp/stm32f0/boards/stm32f072disco/board.mk b/hw/bsp/stm32f0/boards/stm32f072disco/board.mk index 1003be553..edee9b0e8 100644 --- a/hw/bsp/stm32f0/boards/stm32f072disco/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f072disco/board.mk @@ -1,6 +1,6 @@ CFLAGS += -DSTM32F072xB -DCFG_EXAMPLE_VIDEO_READONLY -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s LD_FILE = $(BOARD_PATH)/STM32F072RBTx_FLASH.ld IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f072xb.s diff --git a/hw/bsp/stm32f0/boards/stm32f072eval/board.mk b/hw/bsp/stm32f0/boards/stm32f072eval/board.mk index 4134c1f45..6503d3273 100644 --- a/hw/bsp/stm32f0/boards/stm32f072eval/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f072eval/board.mk @@ -1,6 +1,6 @@ CFLAGS += -DSTM32F072xB -DLSI_VALUE=40000 -DCFG_EXAMPLE_VIDEO_READONLY -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s LD_FILE = $(BOARD_PATH)/STM32F072VBTx_FLASH.ld IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f072xb.s From ecfd57e6f12b16c1d7f8cfe2ff6b70e387b38119 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Jan 2023 10:31:00 +0700 Subject: [PATCH 06/23] get most examples build with iar --- examples/device/dfu/Makefile | 5 ++- examples/device/net_lwip_webserver/Makefile | 2 +- .../net_lwip_webserver/src/arch/bpstruct.h | 35 +++++++++++++++++++ .../net_lwip_webserver/src/arch/epstruct.h | 35 +++++++++++++++++++ examples/device/usbtmc/src/usbtmc_app.c | 2 +- hw/bsp/board.c | 6 ++-- 6 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 examples/device/net_lwip_webserver/src/arch/bpstruct.h create mode 100644 examples/device/net_lwip_webserver/src/arch/epstruct.h diff --git a/examples/device/dfu/Makefile b/examples/device/dfu/Makefile index 69b633fea..5148ed55a 100644 --- a/examples/device/dfu/Makefile +++ b/examples/device/dfu/Makefile @@ -6,7 +6,10 @@ INC += \ $(TOP)/hw \ # Example source -EXAMPLE_SOURCE += $(wildcard src/*.c) +EXAMPLE_SOURCE = \ + src/main.c \ + src/usb_descriptors.c + SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) include ../../rules.mk diff --git a/examples/device/net_lwip_webserver/Makefile b/examples/device/net_lwip_webserver/Makefile index 881866a56..55bd820bd 100644 --- a/examples/device/net_lwip_webserver/Makefile +++ b/examples/device/net_lwip_webserver/Makefile @@ -4,7 +4,7 @@ include ../../../tools/top.mk include ../../make.mk # suppress warning caused by lwip -CFLAGS += \ +GCC_CFLAGS += \ -Wno-error=null-dereference \ -Wno-error=unused-parameter \ -Wno-error=unused-variable diff --git a/examples/device/net_lwip_webserver/src/arch/bpstruct.h b/examples/device/net_lwip_webserver/src/arch/bpstruct.h new file mode 100644 index 000000000..74ead358f --- /dev/null +++ b/examples/device/net_lwip_webserver/src/arch/bpstruct.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +#if defined(__ICCARM__) +#pragma pack(1) +#endif diff --git a/examples/device/net_lwip_webserver/src/arch/epstruct.h b/examples/device/net_lwip_webserver/src/arch/epstruct.h new file mode 100644 index 000000000..f6390959e --- /dev/null +++ b/examples/device/net_lwip_webserver/src/arch/epstruct.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +#if defined(__ICCARM__) +#pragma pack() +#endif diff --git a/examples/device/usbtmc/src/usbtmc_app.c b/examples/device/usbtmc/src/usbtmc_app.c index 8f87a6dca..4700656cb 100644 --- a/examples/device/usbtmc/src/usbtmc_app.c +++ b/examples/device/usbtmc/src/usbtmc_app.c @@ -23,7 +23,7 @@ * */ -#include +#include #include /* atoi */ #include "tusb.h" #include "bsp/board.h" diff --git a/hw/bsp/board.c b/hw/bsp/board.c index 7e96735bd..14858c2b6 100644 --- a/hw/bsp/board.c +++ b/hw/bsp/board.c @@ -77,8 +77,10 @@ void board_led_task(void) //--------------------------------------------------------------------+ // newlib read()/write() retarget //--------------------------------------------------------------------+ - -#if defined(__MSP430__) || defined(__RX__) +#ifdef __ICCARM__ + #define sys_write __write + #define sys_read __read +#elif defined(__MSP430__) || defined(__RX__) #define sys_write write #define sys_read read #else From fb7122f07d2b6cc064e4898735fdb6c63f14df8e Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Jan 2023 10:33:26 +0700 Subject: [PATCH 07/23] update iar ci --- .github/workflows/{build_iar_arm.yml => build_iar.yml} | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) rename .github/workflows/{build_iar_arm.yml => build_iar.yml} (78%) diff --git a/.github/workflows/build_iar_arm.yml b/.github/workflows/build_iar.yml similarity index 78% rename from .github/workflows/build_iar_arm.yml rename to .github/workflows/build_iar.yml index bcf560024..4c43400ab 100644 --- a/.github/workflows/build_iar_arm.yml +++ b/.github/workflows/build_iar.yml @@ -1,4 +1,4 @@ -name: Build ARM with IAR +name: Build IAR on: push: @@ -50,8 +50,4 @@ jobs: echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk - name: Build - #run: python3 tools/build_family.py ${{ matrix.family }} - run: | - make -j -C examples/device/cdc_msc BOARD=stm32f070rbnucleo CC=iccarm all - make -j -C examples/device/cdc_msc BOARD=stm32f072disco CC=iccarm all - make -j -C examples/device/cdc_msc BOARD=stm32f072eval CC=iccarm all + run: python3 tools/build_family.py ${{ matrix.family }} CC=iccarm From 075095554aee6b72f7678c4db881162f533cbb13 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Jan 2023 11:47:24 +0700 Subject: [PATCH 08/23] dont use non-std strncasecmp --- examples/device/usbtmc/src/usbtmc_app.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/device/usbtmc/src/usbtmc_app.c b/examples/device/usbtmc/src/usbtmc_app.c index 4700656cb..503ee3071 100644 --- a/examples/device/usbtmc/src/usbtmc_app.c +++ b/examples/device/usbtmc/src/usbtmc_app.c @@ -148,11 +148,12 @@ bool tud_usbtmc_msg_data_cb(void *data, size_t len, bool transfer_complete) queryState = transfer_complete; idnQuery = 0; - if(transfer_complete && (len >=4) && !strncasecmp("*idn?",data,4)) + if ( transfer_complete && (len >= 4) && (!strncmp("*idn?", data, 4) || !strncmp("*IDN?", data, 4)) ) { idnQuery = 1; } - if(transfer_complete && !strncasecmp("delay ",data,5)) + + if ( transfer_complete && (!strncmp("delay ", data, 5) || !strncmp("DELAY ", data, 5)) ) { queryState = 0; int d = atoi((char*)data + 5); From 84be70baf5eaada4317c0483c33580bcde4116de Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Jan 2023 13:17:53 +0700 Subject: [PATCH 09/23] fix iar build with board_test --- examples/device/board_test/Makefile | 6 ------ examples/device/board_test/src/tusb_config.h | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/device/board_test/Makefile b/examples/device/board_test/Makefile index b65575ce6..5a455078e 100644 --- a/examples/device/board_test/Makefile +++ b/examples/device/board_test/Makefile @@ -9,10 +9,4 @@ INC += \ EXAMPLE_SOURCE += $(wildcard src/*.c) SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) -# board_test example is special example that doesn't enable device or host stack -# This can cause some TinyUSB API missing, this hack to allow us to fill those API -# to pass the compilation process -CFLAGS += \ - -D"tud_int_handler(x)= " \ - include ../../rules.mk diff --git a/examples/device/board_test/src/tusb_config.h b/examples/device/board_test/src/tusb_config.h index 5aea4fd2c..2c2eb5280 100644 --- a/examples/device/board_test/src/tusb_config.h +++ b/examples/device/board_test/src/tusb_config.h @@ -30,6 +30,11 @@ extern "C" { #endif +// board_test example is special example that doesn't enable device or host stack +// This can cause some TinyUSB API missing, this define hack to allow us to fill those API +// to pass the compilation process +#define tud_int_handler(x) + //-------------------------------------------------------------------- // COMMON CONFIGURATION //-------------------------------------------------------------------- From 3fd075b48bfe80ef7d7f61c1f6229c3aa413383e Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Jan 2023 15:29:23 +0700 Subject: [PATCH 10/23] fix warning --- examples/device/video_capture/src/usb_descriptors.c | 1 + hw/bsp/stm32f0/family.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/device/video_capture/src/usb_descriptors.c b/examples/device/video_capture/src/usb_descriptors.c index 499ee311c..0cf772010 100644 --- a/examples/device/video_capture/src/usb_descriptors.c +++ b/examples/device/video_capture/src/usb_descriptors.c @@ -99,6 +99,7 @@ uint8_t const desc_fs_configuration[] = { // Config number, interface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 500), + // IAD for Video Control #if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG) TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(4, EPNUM_VIDEO_IN, diff --git a/hw/bsp/stm32f0/family.c b/hw/bsp/stm32f0/family.c index 806c4af51..a7e914128 100644 --- a/hw/bsp/stm32f0/family.c +++ b/hw/bsp/stm32f0/family.c @@ -118,7 +118,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) From 074289caa31297b7261d9484f529f481d0fc9f06 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Jan 2023 15:30:24 +0700 Subject: [PATCH 11/23] add helper tu_desc_find/find2/find3 --- src/common/tusb_types.h | 13 +++++++++++++ src/tusb.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 32cdba450..82798a484 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -543,22 +543,35 @@ TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_type_str(tusb_xfer_type_ //--------------------------------------------------------------------+ // Descriptor helper //--------------------------------------------------------------------+ + +// return next descriptor TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) { uint8_t const* desc8 = (uint8_t const*) desc; return desc8 + desc8[DESC_OFFSET_LEN]; } +// get descriptor type TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_type(void const* desc) { return ((uint8_t const*) desc)[DESC_OFFSET_TYPE]; } +// get descriptor length TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_len(void const* desc) { return ((uint8_t const*) desc)[DESC_OFFSET_LEN]; } +// find descriptor that match byte1 (type) +uint8_t const * tu_desc_find(uint8_t const* desc, uint8_t const* end, uint8_t byte1); + +// find descriptor that match byte1 (type) and byte2 +uint8_t const * tu_desc_find2(uint8_t const* desc, uint8_t const* end, uint8_t byte1, uint8_t byte2); + +// find descriptor that match byte1 (type) and byte2 +uint8_t const * tu_desc_find3(uint8_t const* desc, uint8_t const* end, uint8_t byte1, uint8_t byte2, uint8_t byte3); + #ifdef __cplusplus } #endif diff --git a/src/tusb.c b/src/tusb.c index a5c820b8d..44b34b0e6 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -73,6 +73,41 @@ bool tusb_inited(void) return ret; } +//--------------------------------------------------------------------+ +// Descriptor helper +//--------------------------------------------------------------------+ + +uint8_t const * tu_desc_find(uint8_t const* desc, uint8_t const* end, uint8_t byte1) +{ + while(desc+1 < end) + { + if ( desc[1] == byte1 ) return desc; + desc += desc[DESC_OFFSET_LEN]; + } + return NULL; +} + +uint8_t const * tu_desc_find2(uint8_t const* desc, uint8_t const* end, uint8_t byte1, uint8_t byte2) +{ + while(desc+2 < end) + { + if ( desc[1] == byte1 && desc[2] == byte2) return desc; + desc += desc[DESC_OFFSET_LEN]; + } + return NULL; +} + +uint8_t const * tu_desc_find3(uint8_t const* desc, uint8_t const* end, uint8_t byte1, uint8_t byte2, uint8_t byte3) +{ + while(desc+3 < end) + { + if (desc[1] == byte1 && desc[2] == byte2 && desc[3] == byte3) return desc; + desc += desc[DESC_OFFSET_LEN]; + } + return NULL; +} + + //--------------------------------------------------------------------+ // Endpoint Helper for both Host and Device stack //--------------------------------------------------------------------+ From daec3c24d86682946aea5d9c38623b466851836e Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Jan 2023 15:30:45 +0700 Subject: [PATCH 12/23] fix warnings with arithmetic on void* pointer --- src/class/video/video_device.c | 51 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/class/video/video_device.c b/src/class/video/video_device.c index e17d0a90f..257285126 100644 --- a/src/class/video/video_device.c +++ b/src/class/video/video_device.c @@ -108,7 +108,7 @@ typedef struct TU_ATTR_PACKED { /* video control interface */ typedef struct TU_ATTR_PACKED { - void const *beg; /* The head of the first video control interface descriptor */ + uint8_t const *beg; /* The head of the first video control interface descriptor */ uint16_t len; /* Byte length of the descriptors */ uint16_t cur; /* offset for current video control interface */ uint8_t stm[CFG_TUD_VIDEO_STREAMING]; /* Indices of streaming interface */ @@ -174,7 +174,7 @@ static tusb_desc_vc_itf_t const* _get_desc_vc(videod_interface_t const *self) static tusb_desc_vs_itf_t const* _get_desc_vs(videod_streaming_interface_t const *self) { if (!self->desc.cur) return NULL; - void const *desc = _videod_itf[self->index_vc].beg; + uint8_t const *desc = _videod_itf[self->index_vc].beg; return (tusb_desc_vs_itf_t const*)(desc + self->desc.cur); } @@ -247,9 +247,9 @@ static void const* _next_desc_itf(void const *beg, void const *end) * * @return The pointer for interface descriptor. * @retval end did not found interface descriptor */ -static inline void const* _find_desc_itf(void const *beg, void const *end, uint_fast8_t itfnum, uint_fast8_t altnum) +static inline uint8_t const* _find_desc_itf(void const *beg, void const *end, uint_fast8_t itfnum, uint_fast8_t altnum) { - return _find_desc_3(beg, end, TUSB_DESC_INTERFACE, itfnum, altnum); + return (uint8_t const*) _find_desc_3(beg, end, TUSB_DESC_INTERFACE, itfnum, altnum); } /** Find the first endpoint descriptor belonging to the current interface descriptor. @@ -275,7 +275,7 @@ static void const* _find_desc_ep(void const *beg, void const *end) static inline void const* _end_of_control_descriptor(void const *desc) { tusb_desc_vc_itf_t const *vc = (tusb_desc_vc_itf_t const *)desc; - return desc + vc->std.bLength + vc->ctl.wTotalLength; + return ((uint8_t const*) desc) + vc->std.bLength + tu_le16toh(vc->ctl.wTotalLength); } /** Find the first entity descriptor with the entity ID @@ -305,7 +305,7 @@ static void const* _find_desc_entity(void const *desc, uint_fast8_t entityid) static inline void const* _end_of_streaming_descriptor(void const *desc) { tusb_desc_vs_itf_t const *vs = (tusb_desc_vs_itf_t const *)desc; - return desc + vs->std.bLength + vs->stm.wTotalLength; + return ((uint8_t const*) desc) + vs->std.bLength + tu_le16toh(vs->stm.wTotalLength); } /** Find the first format descriptor with the specified format number. */ @@ -581,8 +581,10 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const * static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self) { tusb_desc_vc_itf_t const *vc = _get_desc_vc(self); + /* The next descriptor after the class-specific VC interface header descriptor. */ - void const *cur = (void const*)vc + vc->std.bLength + vc->ctl.bLength; + void const *cur = (uint8_t const*)vc + vc->std.bLength + vc->ctl.bLength; + /* The end of the video control interface descriptor. */ void const *end = _end_of_control_descriptor(vc); if (vc->std.bNumEndpoints) { @@ -603,10 +605,11 @@ static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self) static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t altnum) { TU_LOG2(" open VC %d\n", altnum); - void const *beg = self->beg; - void const *end = beg + self->len; + uint8_t const *beg = self->beg; + uint8_t const *end = beg + self->len; + /* The first descriptor is a video control interface descriptor. */ - void const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum); + uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum); TU_LOG2(" cur %d\n", cur - beg); TU_VERIFY(cur < end); @@ -616,7 +619,8 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t TU_ASSERT(vc->ctl.bInCollection <= CFG_TUD_VIDEO_STREAMING); /* Update to point the end of the video control interface descriptor. */ - end = _end_of_control_descriptor(cur); + end = _end_of_control_descriptor(cur); + /* Advance to the next descriptor after the class-specific VC interface header descriptor. */ cur += vc->std.bLength + vc->ctl.bLength; TU_LOG2(" bNumEndpoints %d\n", vc->std.bNumEndpoints); @@ -631,7 +635,7 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t /* Open the notification endpoint */ TU_ASSERT(usbd_edpt_open(rhport, notif)); } - self->cur = (uint16_t) ((void const*)vc - beg); + self->cur = (uint16_t) ((uint8_t const*)vc - beg); return true; } @@ -643,7 +647,7 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint { uint_fast8_t i; TU_LOG2(" reopen VS %d\n", altnum); - void const *desc = _videod_itf[stm->index_vc].beg; + uint8_t const *desc = _videod_itf[stm->index_vc].beg; /* Close endpoints of previous settings. */ for (i = 0; i < TU_ARRAY_SIZE(stm->desc.ep); ++i) { @@ -654,16 +658,18 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint stm->desc.ep[i] = 0; TU_LOG2(" close EP%02x\n", ep_adr); } + /* clear transfer management information */ stm->buffer = NULL; stm->bufsize = 0; stm->offset = 0; /* Find a alternate interface */ - void const *beg = desc + stm->desc.beg; - void const *end = desc + stm->desc.end; - void const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum); + uint8_t const *beg = desc + stm->desc.beg; + uint8_t const *end = desc + stm->desc.end; + uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum); TU_VERIFY(cur < end); + uint_fast8_t numeps = ((tusb_desc_interface_t const *)cur)->bNumEndpoints; TU_ASSERT(numeps <= TU_ARRAY_SIZE(stm->desc.ep)); stm->desc.cur = (uint16_t) (cur - desc); /* Save the offset of the new settings */ @@ -1043,7 +1049,6 @@ static int handle_video_stm_req(uint8_t rhport, uint8_t stage, default: return VIDEO_ERROR_INVALID_REQUEST; } - return VIDEO_ERROR_UNKNOWN; } //--------------------------------------------------------------------+ @@ -1076,7 +1081,7 @@ bool tud_video_n_frame_xfer(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *bu if (!stm || !stm->desc.ep[0] || stm->buffer) return false; /* Find EP address */ - void const *desc = _videod_itf[stm->index_vc].beg; + uint8_t const *desc = _videod_itf[stm->index_vc].beg; uint8_t ep_addr = 0; for (uint_fast8_t i = 0; i < CFG_TUD_VIDEO_STREAMING; ++i) { uint_fast16_t ofs_ep = stm->desc.ep[i]; @@ -1143,13 +1148,15 @@ uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin } TU_ASSERT(ctl_idx < CFG_TUD_VIDEO, 0); - void const *end = (void const*)itf_desc + max_len; - self->beg = itf_desc; + uint8_t const *end = (uint8_t const*)itf_desc + max_len; + self->beg = (uint8_t const*) itf_desc; self->len = max_len; + /*------------- Video Control Interface -------------*/ TU_VERIFY(_open_vc_itf(rhport, self, 0), 0); tusb_desc_vc_itf_t const *vc = _get_desc_vc(self); uint_fast8_t bInCollection = vc->ctl.bInCollection; + /* Find the end of the video interface descriptor */ void const *cur = _next_desc_itf(itf_desc, end); for (uint8_t stm_idx = 0; stm_idx < bInCollection; ++stm_idx) { @@ -1200,7 +1207,7 @@ bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_ for (itf = 0; itf < CFG_TUD_VIDEO_STREAMING; ++itf) { videod_streaming_interface_t *stm = &_videod_streaming_itf[itf]; if (!stm->desc.beg) continue; - void const *desc = _videod_itf[stm->index_vc].beg; + uint8_t const *desc = _videod_itf[stm->index_vc].beg; if (itfnum == _desc_itfnum(desc + stm->desc.beg)) break; } @@ -1226,7 +1233,7 @@ bool videod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint3 uint_fast16_t const ep_ofs = stm->desc.ep[0]; if (!ep_ofs) continue; ctl = &_videod_itf[stm->index_vc]; - void const *desc = ctl->beg; + uint8_t const *desc = ctl->beg; if (ep_addr == _desc_ep_addr(desc + ep_ofs)) break; } From cb34cb2a9397eeeeff9bacd212914477c6e76ff9 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Jan 2023 15:56:32 +0700 Subject: [PATCH 13/23] slightly update rule.mk for IAR --- examples/rules.mk | 62 ++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/examples/rules.mk b/examples/rules.mk index c3b757eec..19ecbc9e1 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -48,15 +48,17 @@ CFLAGS += $(addprefix -I,$(INC)) ifdef USE_IAR -IAR_CFLAGS += $(CFLAGS) -e --debug --silent -IAR_LDFLAGS += --config $(TOP)/$(IAR_LD_FILE) -IAR_ASFLAGS += $(CFLAGS) -S - SRC_S += $(IAR_SRC_S) +ASFLAGS := $(CFLAGS) $(IAR_ASFLAGS) $(ASFLAGS) -S +IAR_LDFLAGS += --config $(TOP)/$(IAR_LD_FILE) +CFLAGS += $(IAR_CFLAGS) -e --debug --silent + else -CFLAGS += $(GCC_CFLAGS) +SRC_S += $(GCC_SRC_S) + +CFLAGS += $(GCC_CFLAGS) -MD # LTO makes it difficult to analyze map file for optimizing size purpose # We will run this option in ci @@ -76,8 +78,6 @@ endif ASFLAGS += $(CFLAGS) -SRC_S += $(GCC_SRC_S) - endif # USE_IAR # Verbose mode @@ -120,9 +120,23 @@ vpath %.c . $(TOP) vpath %.s . $(TOP) vpath %.S . $(TOP) +# Compile .c file +$(BUILD)/obj/%.o: %.c + @echo CC $(notdir $@) + @$(CC) $(CFLAGS) -c -o $@ $< + +# ASM sources lower case .s +$(BUILD)/obj/%_asm.o: %.s + @echo AS $(notdir $@) + @$(AS) $(ASFLAGS) -c -o $@ $< + +# ASM sources upper case .S +$(BUILD)/obj/%_asm.o: %.S + @echo AS $(notdir $@) + @$(AS) $(ASFLAGS) -c -o $@ $< + ifndef USE_IAR # GCC based compiler - $(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf @echo CREATE $@ @$(OBJCOPY) -O binary $^ $@ @@ -135,24 +149,9 @@ $(BUILD)/$(PROJECT).elf: $(OBJ) @echo LINK $@ @$(LD) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group -$(BUILD)/obj/%.o: %.c - @echo CC $(notdir $@) - @$(CC) $(CFLAGS) -c -MD -o $@ $< - -# ASM sources lower case .s -$(BUILD)/obj/%_asm.o: %.s - @echo AS $(notdir $@) - @$(AS) $(ASFLAGS) -c -o $@ $< - -# ASM sources upper case .S -$(BUILD)/obj/%_asm.o: %.S - @echo AS $(notdir $@) - @$(AS) $(ASFLAGS) -c -o $@ $< - else # IAR Compiler - $(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf @echo CREATE $@ @$(OBJCOPY) --silent --bin $^ $@ @@ -163,22 +162,7 @@ $(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf $(BUILD)/$(PROJECT).elf: $(OBJ) @echo LINK $@ - @$(LD) $(IAR_LDFLAGS) $^ -o $@ - -$(BUILD)/obj/%.o: %.c - @echo CC $(notdir $@) - @$(CC) $(IAR_CFLAGS) -c -o $@ $< - -# ASM sources lower case .s -$(BUILD)/obj/%_asm.o: %.s - @echo AS $(notdir $@) - @$(AS) $(IAR_ASFLAGS) -c -o $@ $< - -# ASM sources upper case .S -$(BUILD)/obj/%_asm.o: %.S - @echo AS $(notdir $@) - @$(AS) $(IAR_ASFLAGS) -c -o $@ $< - + @$(LD) -o $@ $(IAR_LDFLAGS) $^ endif # UF2 generation, iMXRT need to strip to text only before conversion From 1bbeb6ad79fa1e76c109592773e0834e1ec00a0c Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 21 Jan 2023 11:32:37 +0700 Subject: [PATCH 14/23] update stm32f1 to support iar build --- .github/workflows/build_iar.yml | 1 + examples/rules.mk | 4 +++ .../stm32f0/boards/stm32f070rbnucleo/board.mk | 4 ++- hw/bsp/stm32f0/boards/stm32f072disco/board.mk | 2 +- hw/bsp/stm32f0/boards/stm32f072eval/board.mk | 2 +- hw/bsp/stm32f0/family.mk | 11 ++++--- .../boards/stm32f103_bluepill/board.mk | 10 ++++-- .../stm32f103_bluepill/stm32f103x8_flash.icf | 31 +++++++++++++++++++ .../stm32f1/boards/stm32f103_mini_2/board.mk | 10 ++++-- hw/bsp/stm32f1/family.c | 5 +-- hw/bsp/stm32f1/family.mk | 15 +++++++-- src/common/tusb_compiler.h | 4 +-- 12 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 hw/bsp/stm32f1/boards/stm32f103_bluepill/stm32f103x8_flash.icf diff --git a/.github/workflows/build_iar.yml b/.github/workflows/build_iar.yml index 4c43400ab..40c7d7f26 100644 --- a/.github/workflows/build_iar.yml +++ b/.github/workflows/build_iar.yml @@ -28,6 +28,7 @@ jobs: family: # Alphabetical order - 'stm32f0' + - 'stm32f1' steps: - name: Clean workspace run: | diff --git a/examples/rules.mk b/examples/rules.mk index 19ecbc9e1..6a62288ce 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -72,6 +72,10 @@ ifdef LD_FILE LDFLAGS += -Wl,-T,$(TOP)/$(LD_FILE) endif +ifdef GCC_LD_FILE +LDFLAGS += -Wl,-T,$(TOP)/$(GCC_LD_FILE) +endif + ifneq ($(SKIP_NANOLIB), 1) LDFLAGS += -specs=nosys.specs -specs=nano.specs endif diff --git a/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk b/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk index f470b80f0..cf787a103 100644 --- a/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f070rbnucleo/board.mk @@ -1,8 +1,10 @@ CFLAGS += -DSTM32F070xB -DCFG_EXAMPLE_VIDEO_READONLY +# GCC GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f070xb.s -LD_FILE = $(BOARD_PATH)/stm32F070rbtx_flash.ld +GCC_LD_FILE = $(BOARD_PATH)/stm32F070rbtx_flash.ld +# IAR IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f070xb.s IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f070xb_flash.icf diff --git a/hw/bsp/stm32f0/boards/stm32f072disco/board.mk b/hw/bsp/stm32f0/boards/stm32f072disco/board.mk index edee9b0e8..4216ba186 100644 --- a/hw/bsp/stm32f0/boards/stm32f072disco/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f072disco/board.mk @@ -1,7 +1,7 @@ CFLAGS += -DSTM32F072xB -DCFG_EXAMPLE_VIDEO_READONLY GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s -LD_FILE = $(BOARD_PATH)/STM32F072RBTx_FLASH.ld +GCC_LD_FILE = $(BOARD_PATH)/STM32F072RBTx_FLASH.ld IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f072xb.s IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f072xb_flash.icf diff --git a/hw/bsp/stm32f0/boards/stm32f072eval/board.mk b/hw/bsp/stm32f0/boards/stm32f072eval/board.mk index 6503d3273..bb9cba22a 100644 --- a/hw/bsp/stm32f0/boards/stm32f072eval/board.mk +++ b/hw/bsp/stm32f0/boards/stm32f072eval/board.mk @@ -1,7 +1,7 @@ CFLAGS += -DSTM32F072xB -DLSI_VALUE=40000 -DCFG_EXAMPLE_VIDEO_READONLY GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f072xb.s -LD_FILE = $(BOARD_PATH)/STM32F072VBTx_FLASH.ld +GCC_LD_FILE = $(BOARD_PATH)/STM32F072VBTx_FLASH.ld IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f072xb.s IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f072xb_flash.icf diff --git a/hw/bsp/stm32f0/family.mk b/hw/bsp/stm32f0/family.mk index a81ab426f..2983af49e 100644 --- a/hw/bsp/stm32f0/family.mk +++ b/hw/bsp/stm32f0/family.mk @@ -7,13 +7,14 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk +# -------------- +# Compiler Flags +# -------------- CFLAGS += \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_STM32F0 -# -------------- # GCC Flags -# -------------- GCC_CFLAGS += \ -flto \ -mthumb \ @@ -25,12 +26,14 @@ GCC_CFLAGS += \ # suppress warning caused by vendor mcu driver GCC_CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual -# -------------- # IAR Flags -# -------------- IAR_CFLAGS += --cpu cortex-m0 IAR_ASFLAGS += --cpu cortex-m0 +# ------------------------ +# All source paths should be relative to the top level. +# ------------------------ + SRC_C += \ src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \ $(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \ diff --git a/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk b/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk index db64b3a3f..159b3ecb6 100644 --- a/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk +++ b/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F103xB -DHSE_VALUE=8000000U -DCFG_EXAMPLE_VIDEO_READONLY -# All source paths should be relative to the top level. -LD_FILE = $(BOARD_PATH)/STM32F103X8_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F103X8_FLASH.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f103xb.s +IAR_LD_FILE = $(BOARD_PATH)/stm32f103x8_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f103c8 diff --git a/hw/bsp/stm32f1/boards/stm32f103_bluepill/stm32f103x8_flash.icf b/hw/bsp/stm32f1/boards/stm32f103_bluepill/stm32f103x8_flash.icf new file mode 100644 index 000000000..07601c2e8 --- /dev/null +++ b/hw/bsp/stm32f1/boards/stm32f103_bluepill/stm32f103x8_flash.icf @@ -0,0 +1,31 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x08000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ; +define symbol __ICFEDIT_region_ROM_end__ = 0x0800FFFF; +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x20004FFF; +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x400; +define symbol __ICFEDIT_size_heap__ = 0x200; +/**** End of ICF editor section. ###ICF###*/ + + +define memory mem with size = 4G; +define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in ROM_region { readonly }; +place in RAM_region { readwrite, + block CSTACK, block HEAP }; diff --git a/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk b/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk index eeda87080..efea75be7 100644 --- a/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk +++ b/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F103xB -DHSE_VALUE=8000000U -# All source paths should be relative to the top level. -LD_FILE = $(BOARD_PATH)/STM32F103XC_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F103XC_FLASH.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f103xb.s +IAR_LD_FILE = $(BOARD_PATH)/stm32f103xc_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f103rc diff --git a/hw/bsp/stm32f1/family.c b/hw/bsp/stm32f1/family.c index 8fcf9ebd6..246d496c8 100644 --- a/hw/bsp/stm32f1/family.c +++ b/hw/bsp/stm32f1/family.c @@ -104,7 +104,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) @@ -139,7 +140,7 @@ uint32_t board_millis(void) void HardFault_Handler (void) { - asm("bkpt"); + __asm("BKPT #0\n"); } #ifdef USE_FULL_ASSERT diff --git a/hw/bsp/stm32f1/family.mk b/hw/bsp/stm32f1/family.mk index 3fb2e6e70..4327f1cf8 100644 --- a/hw/bsp/stm32f1/family.mk +++ b/hw/bsp/stm32f1/family.mk @@ -6,19 +6,28 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk +# -------------- +# Compiler Flags +# -------------- CFLAGS += \ + -DCFG_TUSB_MCU=OPT_MCU_STM32F1 + +# GCC Flags +GCC_CFLAGS += \ -flto \ -mthumb \ -mabi=aapcs \ -mcpu=cortex-m3 \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ - -DCFG_TUSB_MCU=OPT_MCU_STM32F1 -# mcu driver cause following warnings -#CFLAGS += -Wno-error=unused-parameter +# IAR Flags +IAR_CFLAGS += --cpu cortex-m3 +IAR_ASFLAGS += --cpu cortex-m3 +# ------------------------ # All source paths should be relative to the top level. +# ------------------------ SRC_C += \ src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \ $(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \ diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h index 2c30daf6f..a0a49d7ec 100644 --- a/src/common/tusb_compiler.h +++ b/src/common/tusb_compiler.h @@ -76,9 +76,9 @@ * - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma) *------------------------------------------------------------------*/ #if !defined(__CCRX__) -#define TU_ARGS_NUM(...) _TU_NARG(_0, ##__VA_ARGS__,_RSEQ_N()) +#define TU_ARGS_NUM(...) _TU_NARG(_0, ##__VA_ARGS__, _RSEQ_N()) #else -#define TU_ARGS_NUM(...) _TU_NARG(_0, __VA_ARGS__,_RSEQ_N()) +#define TU_ARGS_NUM(...) _TU_NARG(_0, __VA_ARGS__, _RSEQ_N()) #endif #define _TU_NARG(...) _GET_NTH_ARG(__VA_ARGS__) From 436cd5b9b841b37ab16f9d6d378475b2c12d48a5 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 21 Jan 2023 14:26:46 +0700 Subject: [PATCH 15/23] add icf for f1 mini2 --- .../stm32f103_mini_2/stm32f103xc_flash.icf | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 hw/bsp/stm32f1/boards/stm32f103_mini_2/stm32f103xc_flash.icf diff --git a/hw/bsp/stm32f1/boards/stm32f103_mini_2/stm32f103xc_flash.icf b/hw/bsp/stm32f1/boards/stm32f103_mini_2/stm32f103xc_flash.icf new file mode 100644 index 000000000..5f8a5ecad --- /dev/null +++ b/hw/bsp/stm32f1/boards/stm32f103_mini_2/stm32f103xc_flash.icf @@ -0,0 +1,31 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x08000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ; +define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF; +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x2000BFFF; +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x400; +define symbol __ICFEDIT_size_heap__ = 0x200; +/**** End of ICF editor section. ###ICF###*/ + + +define memory mem with size = 4G; +define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in ROM_region { readonly }; +place in RAM_region { readwrite, + block CSTACK, block HEAP }; From f4c3f0800d44e19ede428c4d5995910573cf6341 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 21 Jan 2023 17:47:40 +0700 Subject: [PATCH 16/23] add test_common_func.c --- test/unit-test/test/test_common_func.c | 82 ++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/unit-test/test/test_common_func.c diff --git a/test/unit-test/test/test_common_func.c b/test/unit-test/test/test_common_func.c new file mode 100644 index 000000000..981531dd7 --- /dev/null +++ b/test/unit-test/test/test_common_func.c @@ -0,0 +1,82 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#include +#include "unity.h" + +#include "tusb_common.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + + +//------------- IMPLEMENTATION -------------// + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_TU_ARGS_NUM(void) +{ + TEST_ASSERT_EQUAL( 0, TU_ARGS_NUM()); + TEST_ASSERT_EQUAL( 1, TU_ARGS_NUM(a1)); + TEST_ASSERT_EQUAL( 2, TU_ARGS_NUM(a1, a2)); + TEST_ASSERT_EQUAL( 3, TU_ARGS_NUM(a1, a2, a3)); + TEST_ASSERT_EQUAL( 4, TU_ARGS_NUM(a1, a2, a3, a4)); + TEST_ASSERT_EQUAL( 5, TU_ARGS_NUM(a1, a2, a3, a4, a5)); + TEST_ASSERT_EQUAL( 6, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6)); + TEST_ASSERT_EQUAL( 7, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7)); + TEST_ASSERT_EQUAL( 8, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8)); + TEST_ASSERT_EQUAL( 9, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9)); + TEST_ASSERT_EQUAL(10, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); + TEST_ASSERT_EQUAL(11, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)); + TEST_ASSERT_EQUAL(12, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)); + TEST_ASSERT_EQUAL(13, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)); + TEST_ASSERT_EQUAL(14, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)); + TEST_ASSERT_EQUAL(15, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)); + TEST_ASSERT_EQUAL(16, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16)); + TEST_ASSERT_EQUAL(17, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17)); + TEST_ASSERT_EQUAL(18, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18)); + TEST_ASSERT_EQUAL(19, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19)); + TEST_ASSERT_EQUAL(20, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)); + TEST_ASSERT_EQUAL(21, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21)); + TEST_ASSERT_EQUAL(22, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22)); + TEST_ASSERT_EQUAL(23, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23)); + TEST_ASSERT_EQUAL(24, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24)); + TEST_ASSERT_EQUAL(25, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25)); + TEST_ASSERT_EQUAL(26, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26)); + TEST_ASSERT_EQUAL(27, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27)); + TEST_ASSERT_EQUAL(28, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28)); + TEST_ASSERT_EQUAL(29, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29)); + TEST_ASSERT_EQUAL(30, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30)); + TEST_ASSERT_EQUAL(31, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31)); + TEST_ASSERT_EQUAL(32, TU_ARGS_NUM(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32)); +} From db36075721b266d40703e4f57683858acb4112fc Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 22 Jan 2023 11:56:50 +0700 Subject: [PATCH 17/23] update f4 to build with iar --- hw/bsp/stm32f4/boards/feather_stm32f405/board.mk | 8 ++++++-- hw/bsp/stm32f4/boards/pyboardv11/board.mk | 8 ++++++-- .../stm32f4/boards/stm32f401blackpill/board.mk | 8 ++++++-- hw/bsp/stm32f4/boards/stm32f407disco/board.mk | 9 +++++++-- .../stm32f4/boards/stm32f411blackpill/board.mk | 8 ++++++-- hw/bsp/stm32f4/boards/stm32f411disco/board.mk | 8 ++++++-- hw/bsp/stm32f4/boards/stm32f412disco/board.mk | 8 ++++++-- hw/bsp/stm32f4/boards/stm32f412nucleo/board.mk | 8 ++++++-- hw/bsp/stm32f4/boards/stm32f439nucleo/board.mk | 8 ++++++-- hw/bsp/stm32f4/family.c | 5 +++-- hw/bsp/stm32f4/family.mk | 16 +++++++++++++--- 11 files changed, 71 insertions(+), 23 deletions(-) diff --git a/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk b/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk index 1de56fe5a..1962dd9d8 100644 --- a/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk +++ b/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F405xx -LD_FILE = $(BOARD_PATH)/STM32F405RGTx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F405RGTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f405xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f405xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f405rg diff --git a/hw/bsp/stm32f4/boards/pyboardv11/board.mk b/hw/bsp/stm32f4/boards/pyboardv11/board.mk index 02dcd1219..0a9100e1e 100644 --- a/hw/bsp/stm32f4/boards/pyboardv11/board.mk +++ b/hw/bsp/stm32f4/boards/pyboardv11/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F405xx -LD_FILE = $(BOARD_PATH)/STM32F405RGTx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F405RGTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f405xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f405xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f405rg diff --git a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk index de0f3d4c7..11f9b81aa 100644 --- a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F401xC -LD_FILE = $(BOARD_PATH)/STM32F401VCTx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f401xc.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F401VCTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f401xc.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f401xc.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f401xc_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f401cc diff --git a/hw/bsp/stm32f4/boards/stm32f407disco/board.mk b/hw/bsp/stm32f4/boards/stm32f407disco/board.mk index 212b924b4..a184804d3 100644 --- a/hw/bsp/stm32f4/boards/stm32f407disco/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f407disco/board.mk @@ -1,8 +1,13 @@ CFLAGS += -DSTM32F407xx -LD_FILE = $(BOARD_PATH)/STM32F407VGTx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f407xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F407VGTx_FLASH.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f407xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f407xx_flash.icf -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f407xx.s # For flash-jlink target JLINK_DEVICE = stm32f407vg diff --git a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk index 78be4348a..ac15eaa5d 100644 --- a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F411xE -LD_FILE = $(BOARD_PATH)/STM32F411CEUx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f411xe.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F411CEUx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f411xe.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f411xe.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f411xe_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f411ce diff --git a/hw/bsp/stm32f4/boards/stm32f411disco/board.mk b/hw/bsp/stm32f4/boards/stm32f411disco/board.mk index 48272acff..c5736050c 100644 --- a/hw/bsp/stm32f4/boards/stm32f411disco/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f411disco/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F411xE -LD_FILE = $(BOARD_PATH)/STM32F411VETx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f411xe.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F411VETx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f411xe.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f411xe.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f411xe_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f411ve diff --git a/hw/bsp/stm32f4/boards/stm32f412disco/board.mk b/hw/bsp/stm32f4/boards/stm32f412disco/board.mk index 50973f737..7dc3699e0 100644 --- a/hw/bsp/stm32f4/boards/stm32f412disco/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f412disco/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F412Zx -LD_FILE = $(BOARD_PATH)/STM32F412ZGTx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f412zx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F412ZGTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f412zx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f412zx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f412zx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f412zg diff --git a/hw/bsp/stm32f4/boards/stm32f412nucleo/board.mk b/hw/bsp/stm32f4/boards/stm32f412nucleo/board.mk index 50973f737..7dc3699e0 100644 --- a/hw/bsp/stm32f4/boards/stm32f412nucleo/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f412nucleo/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F412Zx -LD_FILE = $(BOARD_PATH)/STM32F412ZGTx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f412zx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F412ZGTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f412zx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f412zx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f412zx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f412zg diff --git a/hw/bsp/stm32f4/boards/stm32f439nucleo/board.mk b/hw/bsp/stm32f4/boards/stm32f439nucleo/board.mk index b7b36a8a6..e1f337a7e 100644 --- a/hw/bsp/stm32f4/boards/stm32f439nucleo/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f439nucleo/board.mk @@ -1,8 +1,12 @@ CFLAGS += -DSTM32F439xx -LD_FILE = $(BOARD_PATH)/STM32F439ZITX_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f439xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F439ZITX_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f439xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f439xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f439xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f439zi diff --git a/hw/bsp/stm32f4/family.c b/hw/bsp/stm32f4/family.c index 82d4957e7..674058f50 100644 --- a/hw/bsp/stm32f4/family.c +++ b/hw/bsp/stm32f4/family.c @@ -150,7 +150,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) @@ -190,7 +191,7 @@ uint32_t board_millis(void) void HardFault_Handler (void) { - asm("bkpt"); + __asm("BKPT #0\n"); } // Required by __libc_init_array in startup code if we are compiling using diff --git a/hw/bsp/stm32f4/family.mk b/hw/bsp/stm32f4/family.mk index 9811d3371..333857499 100644 --- a/hw/bsp/stm32f4/family.mk +++ b/hw/bsp/stm32f4/family.mk @@ -7,18 +7,28 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk +# -------------- +# Compiler Flags +# -------------- CFLAGS += \ + -DCFG_TUSB_MCU=OPT_MCU_STM32F4 + +# GCC Flags +GCC_CFLAGS += \ -flto \ -mthumb \ -mabi=aapcs \ -mcpu=cortex-m4 \ -mfloat-abi=hard \ -mfpu=fpv4-sp-d16 \ - -nostdlib -nostartfiles \ - -DCFG_TUSB_MCU=OPT_MCU_STM32F4 + -nostdlib -nostartfiles # suppress warning caused by vendor mcu driver -CFLAGS += -Wno-error=cast-align +GCC_CFLAGS += -Wno-error=cast-align + +# IAR Flags +IAR_CFLAGS += --cpu cortex-m4 +IAR_ASFLAGS += --cpu cortex-m4 SRC_C += \ src/portable/synopsys/dwc2/dcd_dwc2.c \ From 0a4e611e3738189f00ec17ebd831436ed51e15ec Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 22 Jan 2023 12:10:27 +0700 Subject: [PATCH 18/23] update stm32f7 to build with iar --- .github/workflows/build_iar.yml | 2 ++ hw/bsp/stm32f4/family.mk | 4 +++ hw/bsp/stm32f7/boards/stlinkv3mini/board.mk | 10 +++++-- hw/bsp/stm32f7/boards/stm32f723disco/board.mk | 9 ++++-- hw/bsp/stm32f7/boards/stm32f746disco/board.mk | 9 ++++-- .../stm32f7/boards/stm32f746nucleo/board.mk | 9 ++++-- .../stm32f7/boards/stm32f767nucleo/board.mk | 9 ++++-- hw/bsp/stm32f7/boards/stm32f769disco/board.mk | 9 ++++-- hw/bsp/stm32f7/family.c | 5 ++-- hw/bsp/stm32f7/family.mk | 30 ++++++++++++++----- 10 files changed, 73 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build_iar.yml b/.github/workflows/build_iar.yml index 40c7d7f26..1facd8ab9 100644 --- a/.github/workflows/build_iar.yml +++ b/.github/workflows/build_iar.yml @@ -29,6 +29,8 @@ jobs: # Alphabetical order - 'stm32f0' - 'stm32f1' + - 'stm32f4' + - 'stm32f7' steps: - name: Clean workspace run: | diff --git a/hw/bsp/stm32f4/family.mk b/hw/bsp/stm32f4/family.mk index 333857499..3da4f7bf8 100644 --- a/hw/bsp/stm32f4/family.mk +++ b/hw/bsp/stm32f4/family.mk @@ -30,6 +30,10 @@ GCC_CFLAGS += -Wno-error=cast-align IAR_CFLAGS += --cpu cortex-m4 IAR_ASFLAGS += --cpu cortex-m4 +# ----------------- +# Sources & Include +# ----------------- + SRC_C += \ src/portable/synopsys/dwc2/dcd_dwc2.c \ $(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \ diff --git a/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk b/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk index a18b3231d..c28dae9bf 100644 --- a/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk +++ b/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk @@ -6,9 +6,13 @@ CFLAGS += \ -DSTM32F723xx \ -DHSE_VALUE=25000000 \ -# All source paths should be relative to the top level. -LD_FILE = $(BOARD_PATH)/STM32F723xE_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f723xx.s +# GCC +GCC_LD_FILE = $(BOARD_PATH)/STM32F723xE_FLASH.ld +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f723xx.s + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f723xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f723xx_flash.icf # flash target using on-board stlink flash: flash-stlink diff --git a/hw/bsp/stm32f7/boards/stm32f723disco/board.mk b/hw/bsp/stm32f7/boards/stm32f723disco/board.mk index 66d9ff8fb..6ddb727c7 100644 --- a/hw/bsp/stm32f7/boards/stm32f723disco/board.mk +++ b/hw/bsp/stm32f7/boards/stm32f723disco/board.mk @@ -5,8 +5,13 @@ CFLAGS += \ -DSTM32F723xx \ -DHSE_VALUE=25000000 \ -LD_FILE = $(BOARD_PATH)/STM32F723xE_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f723xx.s +# GCC +GCC_LD_FILE = $(BOARD_PATH)/STM32F723xE_FLASH.ld +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f723xx.s + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f723xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f723xx_flash.icf # flash target using on-board stlink flash: flash-stlink diff --git a/hw/bsp/stm32f7/boards/stm32f746disco/board.mk b/hw/bsp/stm32f7/boards/stm32f746disco/board.mk index 2ba59f67a..ba31baa16 100644 --- a/hw/bsp/stm32f7/boards/stm32f746disco/board.mk +++ b/hw/bsp/stm32f7/boards/stm32f746disco/board.mk @@ -5,8 +5,13 @@ CFLAGS += \ -DSTM32F746xx \ -DHSE_VALUE=25000000 -LD_FILE = $(BOARD_PATH)/STM32F746ZGTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f746xx.s +# GCC +GCC_LD_FILE = $(BOARD_PATH)/STM32F746ZGTx_FLASH.ld +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f746xx.s + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f746xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f746xx_flash.icf # flash target using on-board stlink flash: flash-stlink diff --git a/hw/bsp/stm32f7/boards/stm32f746nucleo/board.mk b/hw/bsp/stm32f7/boards/stm32f746nucleo/board.mk index 3dcf4817e..e4d31040e 100644 --- a/hw/bsp/stm32f7/boards/stm32f746nucleo/board.mk +++ b/hw/bsp/stm32f7/boards/stm32f746nucleo/board.mk @@ -5,8 +5,13 @@ CFLAGS += \ -DSTM32F746xx \ -DHSE_VALUE=8000000 -LD_FILE = $(BOARD_PATH)/STM32F746ZGTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f746xx.s +# GCC +GCC_LD_FILE = $(BOARD_PATH)/STM32F746ZGTx_FLASH.ld +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f746xx.s + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f746xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f746xx_flash.icf # flash target using on-board stlink flash: flash-stlink diff --git a/hw/bsp/stm32f7/boards/stm32f767nucleo/board.mk b/hw/bsp/stm32f7/boards/stm32f767nucleo/board.mk index 7710619e5..a460245b2 100644 --- a/hw/bsp/stm32f7/boards/stm32f767nucleo/board.mk +++ b/hw/bsp/stm32f7/boards/stm32f767nucleo/board.mk @@ -5,8 +5,13 @@ CFLAGS += \ -DSTM32F767xx \ -DHSE_VALUE=8000000 \ -LD_FILE = $(BOARD_PATH)/STM32F767ZITx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f767xx.s +# GCC +GCC_LD_FILE = $(BOARD_PATH)/STM32F767ZITx_FLASH.ld +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f767xx.s + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f767xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f767xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32f767zi diff --git a/hw/bsp/stm32f7/boards/stm32f769disco/board.mk b/hw/bsp/stm32f7/boards/stm32f769disco/board.mk index 45b4a78c7..18f59e8b2 100644 --- a/hw/bsp/stm32f7/boards/stm32f769disco/board.mk +++ b/hw/bsp/stm32f7/boards/stm32f769disco/board.mk @@ -6,8 +6,13 @@ CFLAGS += \ -DSTM32F769xx \ -DHSE_VALUE=25000000 \ -LD_FILE = $(BOARD_PATH)/STM32F769ZITx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f769xx.s +# GCC +GCC_LD_FILE = $(BOARD_PATH)/STM32F769ZITx_FLASH.ld +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f769xx.s + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f769xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f769xx_flash.icf # flash target using on-board stlink flash: flash-stlink diff --git a/hw/bsp/stm32f7/family.c b/hw/bsp/stm32f7/family.c index 425e6e1bc..536eb0554 100644 --- a/hw/bsp/stm32f7/family.c +++ b/hw/bsp/stm32f7/family.c @@ -268,7 +268,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) @@ -303,7 +304,7 @@ uint32_t board_millis(void) void HardFault_Handler (void) { - asm("bkpt"); + __asm("BKPT #0\n"); } // Required by __libc_init_array in startup code if we are compiling using diff --git a/hw/bsp/stm32f7/family.mk b/hw/bsp/stm32f7/family.mk index b8a5d7ead..733769d8b 100644 --- a/hw/bsp/stm32f7/family.mk +++ b/hw/bsp/stm32f7/family.mk @@ -7,14 +7,10 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk +# -------------- +# Compiler Flags +# -------------- CFLAGS += \ - -flto \ - -mthumb \ - -mabi=aapcs \ - -mcpu=cortex-m7 \ - -mfloat-abi=hard \ - -mfpu=fpv5-d16 \ - -nostdlib -nostartfiles \ -DCFG_TUSB_MCU=OPT_MCU_STM32F7 \ -DBOARD_TUD_RHPORT=$(PORT) @@ -30,8 +26,26 @@ else $(info "Using OTG_FS") endif +# GCC Flags +GCC_CFLAGS += \ + -flto \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m7 \ + -mfloat-abi=hard \ + -mfpu=fpv5-d16 \ + -nostdlib -nostartfiles + # mcu driver cause following warnings -CFLAGS += -Wno-error=shadow -Wno-error=cast-align +GCC_CFLAGS += -Wno-error=shadow -Wno-error=cast-align + +# IAR Flags +IAR_CFLAGS += --cpu cortex-m7 +IAR_ASFLAGS += --cpu cortex-m7 + +# ----------------- +# Sources & Include +# ----------------- SRC_C += \ src/portable/synopsys/dwc2/dcd_dwc2.c \ From df2ebe5d1a5da6b232704c2b6a35e66823f4127d Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Jan 2023 12:57:07 +0700 Subject: [PATCH 19/23] add iar --fpu option --- hw/bsp/stm32f4/family.mk | 4 ++-- hw/bsp/stm32f7/family.mk | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/bsp/stm32f4/family.mk b/hw/bsp/stm32f4/family.mk index 3da4f7bf8..e8352bad7 100644 --- a/hw/bsp/stm32f4/family.mk +++ b/hw/bsp/stm32f4/family.mk @@ -27,8 +27,8 @@ GCC_CFLAGS += \ GCC_CFLAGS += -Wno-error=cast-align # IAR Flags -IAR_CFLAGS += --cpu cortex-m4 -IAR_ASFLAGS += --cpu cortex-m4 +IAR_CFLAGS += --cpu cortex-m4 --fpu VFPv4 +IAR_ASFLAGS += --cpu cortex-m4 --fpu VFPv4 # ----------------- # Sources & Include diff --git a/hw/bsp/stm32f7/family.mk b/hw/bsp/stm32f7/family.mk index 733769d8b..781b8bb18 100644 --- a/hw/bsp/stm32f7/family.mk +++ b/hw/bsp/stm32f7/family.mk @@ -40,8 +40,8 @@ GCC_CFLAGS += \ GCC_CFLAGS += -Wno-error=shadow -Wno-error=cast-align # IAR Flags -IAR_CFLAGS += --cpu cortex-m7 -IAR_ASFLAGS += --cpu cortex-m7 +IAR_CFLAGS += --cpu cortex-m7 --fpu VFPv5_D16 +IAR_ASFLAGS += --cpu cortex-m7 --fpu VFPv5_D16 # ----------------- # Sources & Include From cc1878447990aa01a99351cafe8bd899bd37b4e0 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 30 Jan 2023 16:42:56 +0700 Subject: [PATCH 20/23] hardcoded configPRIO_BITS for IAR build to pass CI --- .../src/FreeRTOSConfig/FreeRTOSConfig.h | 23 +++++++++++++------ .../src/FreeRTOSConfig/FreeRTOSConfig.h | 23 +++++++++++++------ src/tusb_option.h | 6 ++--- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h index efd527ed2..9bef9bbbf 100644 --- a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h +++ b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h @@ -42,8 +42,8 @@ * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -// skip if is compiled with assembler -#if !defined(__ASSEMBLER__) && !defined(__IASMARM__) +// skip if included from IAR assembler +#ifndef __IASMARM__ // Include MCU header #include "bsp/board_mcu.h" @@ -149,10 +149,10 @@ #ifdef __RX__ /* Renesas RX series */ -#define vSoftwareInterruptISR INT_Excep_ICU_SWINT -#define vTickISR INT_Excep_CMT0_CMI0 -#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2) -#define configKERNEL_INTERRUPT_PRIORITY 1 +#define vSoftwareInterruptISR INT_Excep_ICU_SWINT +#define vTickISR INT_Excep_CMT0_CMI0 +#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2) +#define configKERNEL_INTERRUPT_PRIORITY 1 #define configMAX_SYSCALL_INTERRUPT_PRIORITY 4 #else @@ -168,10 +168,19 @@ #if defined(__NVIC_PRIO_BITS) // For Cortex-M specific: __NVIC_PRIO_BITS is defined in core_cmx.h #define configPRIO_BITS __NVIC_PRIO_BITS + #elif defined(__ECLIC_INTCTLBITS) // RISC-V Bumblebee core from nuclei #define configPRIO_BITS __ECLIC_INTCTLBITS -#elif !defined(__ASSEMBLER__) && !defined(__IASMARM__) + +#elif defined(__IASMARM__) + // FIXME: IAR Assembler cannot include mcu header directly to get __NVIC_PRIO_BITS. + // Therefore we will hard coded it to minimum value of 2 to get pass ci build. + // IAR user must update this to correct value of the target MCU + #message "configPRIO_BITS is hard coded to 2 to pass IAR build only. User should update it per MCU" + #define configPRIO_BITS 2 + +#else #error "FreeRTOS configPRIO_BITS to be defined" #endif diff --git a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h index efd527ed2..9bef9bbbf 100644 --- a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h +++ b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h @@ -42,8 +42,8 @@ * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -// skip if is compiled with assembler -#if !defined(__ASSEMBLER__) && !defined(__IASMARM__) +// skip if included from IAR assembler +#ifndef __IASMARM__ // Include MCU header #include "bsp/board_mcu.h" @@ -149,10 +149,10 @@ #ifdef __RX__ /* Renesas RX series */ -#define vSoftwareInterruptISR INT_Excep_ICU_SWINT -#define vTickISR INT_Excep_CMT0_CMI0 -#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2) -#define configKERNEL_INTERRUPT_PRIORITY 1 +#define vSoftwareInterruptISR INT_Excep_ICU_SWINT +#define vTickISR INT_Excep_CMT0_CMI0 +#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2) +#define configKERNEL_INTERRUPT_PRIORITY 1 #define configMAX_SYSCALL_INTERRUPT_PRIORITY 4 #else @@ -168,10 +168,19 @@ #if defined(__NVIC_PRIO_BITS) // For Cortex-M specific: __NVIC_PRIO_BITS is defined in core_cmx.h #define configPRIO_BITS __NVIC_PRIO_BITS + #elif defined(__ECLIC_INTCTLBITS) // RISC-V Bumblebee core from nuclei #define configPRIO_BITS __ECLIC_INTCTLBITS -#elif !defined(__ASSEMBLER__) && !defined(__IASMARM__) + +#elif defined(__IASMARM__) + // FIXME: IAR Assembler cannot include mcu header directly to get __NVIC_PRIO_BITS. + // Therefore we will hard coded it to minimum value of 2 to get pass ci build. + // IAR user must update this to correct value of the target MCU + #message "configPRIO_BITS is hard coded to 2 to pass IAR build only. User should update it per MCU" + #define configPRIO_BITS 2 + +#else #error "FreeRTOS configPRIO_BITS to be defined" #endif diff --git a/src/tusb_option.h b/src/tusb_option.h index 67377b7ec..cf5b21c9c 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -27,9 +27,6 @@ #ifndef _TUSB_OPTION_H_ #define _TUSB_OPTION_H_ -// To avoid GCC compiler warnings when -pedantic option is used (strict ISO C) -typedef int make_iso_compilers_happy; - #include "common/tusb_compiler.h" #define TUSB_VERSION_MAJOR 0 @@ -435,6 +432,9 @@ typedef int make_iso_compilers_happy; #error Control Endpoint Max Packet Size cannot be larger than 64 #endif +// To avoid GCC compiler warnings when -pedantic option is used (strict ISO C) +typedef int make_iso_compilers_happy; + #endif /* _TUSB_OPTION_H_ */ /** @} */ From b464f91a6e6e6cc4975b4acd442133422482daf1 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 30 Jan 2023 17:04:39 +0700 Subject: [PATCH 21/23] iar h7 --- .github/workflows/build_iar.yml | 1 + hw/bsp/stm32f7/boards/stlinkv3mini/board.mk | 2 +- hw/bsp/stm32h7/boards/daisyseed/board.mk | 9 ++++-- .../stm32h7/boards/stm32h723nucleo/board.mk | 9 ++++-- hw/bsp/stm32h7/boards/stm32h743eval/board.mk | 9 ++++-- .../stm32h7/boards/stm32h743nucleo/board.mk | 9 ++++-- hw/bsp/stm32h7/boards/stm32h745disco/board.mk | 9 ++++-- .../boards/waveshare_openh743i/board.h | 4 +-- .../boards/waveshare_openh743i/board.mk | 11 +++++-- hw/bsp/stm32h7/family.c | 5 +-- hw/bsp/stm32h7/family.mk | 32 +++++++++++++------ 11 files changed, 72 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build_iar.yml b/.github/workflows/build_iar.yml index 1facd8ab9..e4b449528 100644 --- a/.github/workflows/build_iar.yml +++ b/.github/workflows/build_iar.yml @@ -31,6 +31,7 @@ jobs: - 'stm32f1' - 'stm32f4' - 'stm32f7' + - 'stm32h7' steps: - name: Clean workspace run: | diff --git a/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk b/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk index c28dae9bf..e1d352cc9 100644 --- a/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk +++ b/hw/bsp/stm32f7/boards/stlinkv3mini/board.mk @@ -7,8 +7,8 @@ CFLAGS += \ -DHSE_VALUE=25000000 \ # GCC -GCC_LD_FILE = $(BOARD_PATH)/STM32F723xE_FLASH.ld GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f723xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32F723xE_FLASH.ld # IAR IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f723xx.s diff --git a/hw/bsp/stm32h7/boards/daisyseed/board.mk b/hw/bsp/stm32h7/boards/daisyseed/board.mk index 68c62968e..4d718f04e 100644 --- a/hw/bsp/stm32h7/boards/daisyseed/board.mk +++ b/hw/bsp/stm32h7/boards/daisyseed/board.mk @@ -3,8 +3,13 @@ CFLAGS += -DSTM32H750xx -DCORE_CM7 -DHSE_VALUE=16000000 # Default is FulSpeed port PORT ?= 0 -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h750xx.s -LD_FILE = $(BOARD_PATH)/stm32h750ibkx_flash.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h750xx.s +GCC_LD_FILE = $(BOARD_PATH)/stm32h750ibkx_flash.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h750xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h750xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32h750ibk6_m7 diff --git a/hw/bsp/stm32h7/boards/stm32h723nucleo/board.mk b/hw/bsp/stm32h7/boards/stm32h723nucleo/board.mk index bbd0a0e58..57dfb7e64 100644 --- a/hw/bsp/stm32h7/boards/stm32h723nucleo/board.mk +++ b/hw/bsp/stm32h7/boards/stm32h723nucleo/board.mk @@ -3,8 +3,13 @@ CFLAGS += -DSTM32H723xx -DHSE_VALUE=8000000 # Default is FulSpeed port PORT ?= 0 -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h723xx.s -LD_FILE = $(BOARD_PATH)/stm32h723xx_flash.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h723xx.s +GCC_LD_FILE = $(BOARD_PATH)/stm32h723xx_flash.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h723xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h723xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32h723zg diff --git a/hw/bsp/stm32h7/boards/stm32h743eval/board.mk b/hw/bsp/stm32h7/boards/stm32h743eval/board.mk index b768a0ee6..78ff47c09 100644 --- a/hw/bsp/stm32h7/boards/stm32h743eval/board.mk +++ b/hw/bsp/stm32h7/boards/stm32h743eval/board.mk @@ -4,8 +4,13 @@ CFLAGS += -DSTM32H743xx -DHSE_VALUE=25000000 PORT ?= 1 SPEED ?= high -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s -LD_FILE = $(BOARD_PATH)/stm32h743xx_flash.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s +GCC_LD_FILE = $(BOARD_PATH)/stm32h743xx_flash.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h743xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h743xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32h743xi diff --git a/hw/bsp/stm32h7/boards/stm32h743nucleo/board.mk b/hw/bsp/stm32h7/boards/stm32h743nucleo/board.mk index fc670fe76..4bdd5b6a8 100644 --- a/hw/bsp/stm32h7/boards/stm32h743nucleo/board.mk +++ b/hw/bsp/stm32h7/boards/stm32h743nucleo/board.mk @@ -3,8 +3,13 @@ CFLAGS += -DSTM32H743xx -DHSE_VALUE=8000000 # Default is FulSpeed port PORT ?= 0 -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s -LD_FILE = $(BOARD_PATH)/stm32h743xx_flash.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s +GCC_LD_FILE = $(BOARD_PATH)/stm32h743xx_flash.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h743xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h743xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32h743zi diff --git a/hw/bsp/stm32h7/boards/stm32h745disco/board.mk b/hw/bsp/stm32h7/boards/stm32h745disco/board.mk index 384065bde..b51b109f6 100644 --- a/hw/bsp/stm32h7/boards/stm32h745disco/board.mk +++ b/hw/bsp/stm32h7/boards/stm32h745disco/board.mk @@ -6,8 +6,13 @@ CFLAGS += -DSTM32H745xx -DCORE_CM7 -DHSE_VALUE=25000000 # Default is FulSpeed port PORT ?= 0 -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h745xx.s -LD_FILE = $(ST_CMSIS)/Source/Templates/gcc/linker/stm32h745xx_flash_CM7.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h745xx.s +GCC_LD_FILE = $(ST_CMSIS)/Source/Templates/gcc/linker/stm32h745xx_flash_CM7.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h745xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h745xx_flash_CM7.icf # For flash-jlink target JLINK_DEVICE = stm32h745xi_m7 diff --git a/hw/bsp/stm32h7/boards/waveshare_openh743i/board.h b/hw/bsp/stm32h7/boards/waveshare_openh743i/board.h index 2b072e07c..cf6ad762e 100644 --- a/hw/bsp/stm32h7/boards/waveshare_openh743i/board.h +++ b/hw/bsp/stm32h7/boards/waveshare_openh743i/board.h @@ -212,9 +212,9 @@ static inline void board_stm32h7_post_init(void) // Reset PHY, change the delays as you see fit timer_board_delay(&tim2Handle, 5U); - HAL_GPIO_WritePin(ULPI_RST_PORT, ULPI_RST_PIN, 1U); + HAL_GPIO_WritePin(ULPI_RST_PORT, ULPI_RST_PIN, GPIO_PIN_SET); timer_board_delay(&tim2Handle, 20U); - HAL_GPIO_WritePin(ULPI_RST_PORT, ULPI_RST_PIN, 0U); + HAL_GPIO_WritePin(ULPI_RST_PORT, ULPI_RST_PIN, GPIO_PIN_RESET); timer_board_delay(&tim2Handle, 20U); //Disable the timer used for delays diff --git a/hw/bsp/stm32h7/boards/waveshare_openh743i/board.mk b/hw/bsp/stm32h7/boards/waveshare_openh743i/board.mk index 4dfcc1cac..fbf4b55c6 100644 --- a/hw/bsp/stm32h7/boards/waveshare_openh743i/board.mk +++ b/hw/bsp/stm32h7/boards/waveshare_openh743i/board.mk @@ -3,15 +3,20 @@ CFLAGS += -DSTM32H743xx -DHSE_VALUE=8000000 # Default is HS port PORT ?= 1 -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s -LD_FILE = $(BOARD_PATH)/STM32H743IITX_FLASH.ld - # Use Timer module for ULPI PHY reset CFLAGS += -DHAL_TIM_MODULE_ENABLED SRC_C += \ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_tim.c \ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_tim_ex.c +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32H743IITX_FLASH.ld + +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h743xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h743xx_flash.icf + # For flash-jlink target JLINK_DEVICE = stm32h743ii diff --git a/hw/bsp/stm32h7/family.c b/hw/bsp/stm32h7/family.c index 0aa8fe47f..28a2568fa 100644 --- a/hw/bsp/stm32h7/family.c +++ b/hw/bsp/stm32h7/family.c @@ -225,7 +225,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) @@ -261,7 +262,7 @@ uint32_t board_millis(void) void HardFault_Handler(void) { - asm("bkpt"); + __asm("BKPT #0\n"); } // Required by __libc_init_array in startup code if we are compiling using diff --git a/hw/bsp/stm32h7/family.mk b/hw/bsp/stm32h7/family.mk index a1cd93b27..834347b4b 100644 --- a/hw/bsp/stm32h7/family.mk +++ b/hw/bsp/stm32h7/family.mk @@ -7,14 +7,10 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk +# -------------- +# Compiler Flags +# -------------- CFLAGS += \ - -flto \ - -mthumb \ - -mabi=aapcs \ - -mcpu=cortex-m7 \ - -mfloat-abi=hard \ - -mfpu=fpv5-d16 \ - -nostdlib -nostartfiles \ -DCFG_TUSB_MCU=OPT_MCU_STM32H7 \ -DBOARD_TUD_RHPORT=$(PORT) @@ -30,10 +26,26 @@ else $(info "Using OTG_FS") endif -# suppress warning caused by vendor mcu driver -CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=cast-align +# GCC Flags +GCC_CFLAGS += \ + -flto \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m7 \ + -mfloat-abi=hard \ + -mfpu=fpv5-d16 \ + -nostdlib -nostartfiles -# All source paths should be relative to the top level. +# suppress warning caused by vendor mcu driver +GCC_CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=cast-align + +# IAR Flags +IAR_CFLAGS += --cpu cortex-m7 --fpu VFPv5_D16 +IAR_ASFLAGS += --cpu cortex-m7 --fpu VFPv5_D16 + +# ----------------- +# Sources & Include +# ----------------- SRC_C += \ src/portable/synopsys/dwc2/dcd_dwc2.c \ From 63a6fd36890f01ba8e1ed559c53ce2bdd2042475 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 30 Jan 2023 17:07:06 +0700 Subject: [PATCH 22/23] iar g4 --- .github/workflows/build_iar.yml | 1 + hw/bsp/stm32g4/boards/stm32g474nucleo/board.mk | 8 ++++++-- hw/bsp/stm32g4/family.c | 5 +++-- hw/bsp/stm32g4/family.mk | 18 ++++++++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_iar.yml b/.github/workflows/build_iar.yml index e4b449528..c948b5d8d 100644 --- a/.github/workflows/build_iar.yml +++ b/.github/workflows/build_iar.yml @@ -31,6 +31,7 @@ jobs: - 'stm32f1' - 'stm32f4' - 'stm32f7' + - 'stm32g4' - 'stm32h7' steps: - name: Clean workspace diff --git a/hw/bsp/stm32g4/boards/stm32g474nucleo/board.mk b/hw/bsp/stm32g4/boards/stm32g474nucleo/board.mk index e41edd3b7..2f6ec0ed6 100644 --- a/hw/bsp/stm32g4/boards/stm32g474nucleo/board.mk +++ b/hw/bsp/stm32g4/boards/stm32g474nucleo/board.mk @@ -2,9 +2,13 @@ CFLAGS += \ -DSTM32G474xx \ -DHSE_VALUE=24000000 -LD_FILE = $(BOARD_PATH)/STM32G474RETx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32g474xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32G474RETx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32g474xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32g474xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32g474xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32g474re diff --git a/hw/bsp/stm32g4/family.c b/hw/bsp/stm32g4/family.c index a2312b0d8..32c46b7d8 100644 --- a/hw/bsp/stm32g4/family.c +++ b/hw/bsp/stm32g4/family.c @@ -137,7 +137,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) @@ -177,7 +178,7 @@ uint32_t board_millis(void) void HardFault_Handler (void) { - asm("bkpt"); + __asm("BKPT #0\n"); } // Required by __libc_init_array in startup code if we are compiling using diff --git a/hw/bsp/stm32g4/family.mk b/hw/bsp/stm32g4/family.mk index 04222f3bb..79defac56 100644 --- a/hw/bsp/stm32g4/family.mk +++ b/hw/bsp/stm32g4/family.mk @@ -7,7 +7,14 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk +# -------------- +# Compiler Flags +# -------------- CFLAGS += \ + -DCFG_TUSB_MCU=OPT_MCU_STM32G4 + +# GCC Flags +GCC_CFLAGS += \ -flto \ -mthumb \ -mabi=aapcs \ @@ -15,10 +22,17 @@ CFLAGS += \ -mfloat-abi=hard \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ - -DCFG_TUSB_MCU=OPT_MCU_STM32G4 # suppress warning caused by vendor mcu driver -CFLAGS += -Wno-error=cast-align +GCC_CFLAGS += -Wno-error=cast-align + +# IAR Flags +IAR_CFLAGS += --cpu cortex-m4 --fpu VFPv4 +IAR_ASFLAGS += --cpu cortex-m4 --fpu VFPv4 + +# ----------------- +# Sources & Include +# ----------------- SRC_C += \ src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \ From 25603c7269172f64b1dfe55e1224964cc20529ec Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 30 Jan 2023 20:11:59 +0700 Subject: [PATCH 23/23] iar L4 --- .github/workflows/build_iar.yml | 1 + .../stm32l4/boards/stm32l412nucleo/board.mk | 9 +++++--- hw/bsp/stm32l4/boards/stm32l476disco/board.mk | 9 +++++--- .../stm32l4/boards/stm32l4p5nucleo/board.mk | 9 +++++--- .../stm32l4/boards/stm32l4r5nucleo/board.mk | 9 +++++--- hw/bsp/stm32l4/family.c | 5 ++-- hw/bsp/stm32l4/family.mk | 23 +++++++++++++++---- 7 files changed, 46 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build_iar.yml b/.github/workflows/build_iar.yml index c948b5d8d..9c1bfa18a 100644 --- a/.github/workflows/build_iar.yml +++ b/.github/workflows/build_iar.yml @@ -33,6 +33,7 @@ jobs: - 'stm32f7' - 'stm32g4' - 'stm32h7' + - 'stm32l4' steps: - name: Clean workspace run: | diff --git a/hw/bsp/stm32l4/boards/stm32l412nucleo/board.mk b/hw/bsp/stm32l4/boards/stm32l412nucleo/board.mk index 841ee4948..854397fc8 100644 --- a/hw/bsp/stm32l4/boards/stm32l412nucleo/board.mk +++ b/hw/bsp/stm32l4/boards/stm32l412nucleo/board.mk @@ -1,10 +1,13 @@ CFLAGS += \ -DSTM32L412xx \ -# All source paths should be relative to the top level. -LD_FILE = $(BOARD_PATH)/STM32L412KBUx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l412xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32L412KBUx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l412xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32l412xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32l412xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32l412kb diff --git a/hw/bsp/stm32l4/boards/stm32l476disco/board.mk b/hw/bsp/stm32l4/boards/stm32l476disco/board.mk index e7b8557a5..125f1f106 100644 --- a/hw/bsp/stm32l4/boards/stm32l476disco/board.mk +++ b/hw/bsp/stm32l4/boards/stm32l476disco/board.mk @@ -1,10 +1,13 @@ CFLAGS += \ -DSTM32L476xx \ -# All source paths should be relative to the top level. -LD_FILE = $(BOARD_PATH)/STM32L476VGTx_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l476xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32L476VGTx_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l476xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32l476xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32l476xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32l476vg diff --git a/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.mk b/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.mk index 8252dd838..11edcd9a8 100644 --- a/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.mk +++ b/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.mk @@ -1,10 +1,13 @@ CFLAGS += \ -DSTM32L4P5xx \ -# All source paths should be relative to the top level. -LD_FILE = $(BOARD_PATH)/STM32L4P5ZGTX_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l4p5xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32L4P5ZGTX_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l4p5xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32l4p5xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32l4p5xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32l4p5zg diff --git a/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.mk b/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.mk index 3d7fa227b..6dca88a8b 100644 --- a/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.mk +++ b/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.mk @@ -2,10 +2,13 @@ CFLAGS += \ -DHSE_VALUE=8000000 \ -DSTM32L4R5xx \ -# All source paths should be relative to the top level. -LD_FILE = $(BOARD_PATH)/STM32L4RXxI_FLASH.ld +# GCC +GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l4r5xx.s +GCC_LD_FILE = $(BOARD_PATH)/STM32L4RXxI_FLASH.ld -SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l4r5xx.s +# IAR +IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32l4r5xx.s +IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32l4r5xx_flash.icf # For flash-jlink target JLINK_DEVICE = stm32l4r5zi diff --git a/hw/bsp/stm32l4/family.c b/hw/bsp/stm32l4/family.c index 0b1443aa0..19b84c086 100644 --- a/hw/bsp/stm32l4/family.c +++ b/hw/bsp/stm32l4/family.c @@ -179,7 +179,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) @@ -214,7 +215,7 @@ uint32_t board_millis(void) void HardFault_Handler (void) { - asm("bkpt 0x10"); + __asm("BKPT #0\n"); } // Required by __libc_init_array in startup code if we are compiling using diff --git a/hw/bsp/stm32l4/family.mk b/hw/bsp/stm32l4/family.mk index 1361e184c..4fab7dc0d 100644 --- a/hw/bsp/stm32l4/family.mk +++ b/hw/bsp/stm32l4/family.mk @@ -6,23 +6,36 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver include $(TOP)/$(BOARD_PATH)/board.mk +# -------------- +# Compiler Flags +# -------------- CFLAGS += \ + -DCFG_TUSB_MCU=OPT_MCU_STM32L4 + +# GCC Flags +GCC_CFLAGS += \ -flto \ -mthumb \ -mabi=aapcs \ -mcpu=cortex-m4 \ -mfloat-abi=hard \ -mfpu=fpv4-sp-d16 \ - -nostdlib -nostartfiles \ - -DCFG_TUSB_MCU=OPT_MCU_STM32L4 + -nostdlib -nostartfiles # suppress warning caused by vendor mcu driver -CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=cast-align +GCC_CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=cast-align + +# IAR Flags +IAR_CFLAGS += --cpu cortex-m4 --fpu VFPv4 +IAR_ASFLAGS += --cpu cortex-m4 --fpu VFPv4 + +# ----------------- +# Sources & Include +# ----------------- -#src/portable/st/synopsys/dcd_synopsys.c SRC_C += \ src/portable/synopsys/dwc2/dcd_dwc2.c \ - src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \ + src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \ $(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal.c \ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_cortex.c \