├── .gitignore ├── Makefile ├── Platforms └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # File: Makefile for all mbed supported platforms (ARM GCC) 3 | # 4 | # Copyright (c) 10.2013, 0xc0170 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | # SUPPORTED PLATFORMS GCC_ARM 19 | # KL05Z 20 | # KL25Z 21 | # KL46Z 22 | # LPC1768 23 | # LPC11U24 24 | # LPC11U24_301 25 | # LPC1347 26 | # LPC1114 27 | # LPC11C24 28 | # LPC11U35_401 29 | # STM32F407 30 | BOARD = KL25Z 31 | include Platforms 32 | 33 | # path to the mbed library 34 | MBED_DIR = mbed 35 | 36 | # toolchain specific 37 | TOOLCHAIN = arm-none-eabi- 38 | CC = $(TOOLCHAIN)gcc 39 | CXX = $(TOOLCHAIN)g++ 40 | AS = $(TOOLCHAIN)gcc -x assembler-with-cpp 41 | LD = $(TOOLCHAIN)gcc 42 | OBJCP = $(TOOLCHAIN)objcopy 43 | AR = $(TOOLCHAIN)ar 44 | 45 | # application specific 46 | INSTRUCTION_MODE = thumb 47 | TARGET = mbed 48 | TARGET_EXT = elf 49 | LD_SCRIPT = $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/$(LINKER_NAME).ld 50 | 51 | CC_SYMBOLS = -D$(TARGET_BOARD) -DTOOLCHAIN_GCC_ARM -DNDEBUG 52 | 53 | LIB_DIRS = $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM 54 | LIBS = -lmbed -lstdc++ -lsupc++ -lm -lgcc -lc -lnosys 55 | 56 | MBED_OBJ = $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/board.o 57 | MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/cmsis_nvic.o 58 | MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/$(STARTUP_NAME).o 59 | MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/retarget.o 60 | MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/$(SYSTEM_NAME).o 61 | ifneq ("$(wildcard $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/mbed_overrides.o)","") 62 | MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/mbed_overrides.o 63 | endif 64 | 65 | # directories 66 | INC_DIRS = $(MBED_DIR) $(MBED_DIR)/$(TARGET_BOARD) $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM 67 | INC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY) 68 | INC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY)/$(TARGET_SPECIFIC) 69 | # app headers directories (remove comment and add more files) 70 | #INC_DIRS += 71 | 72 | SRC_DIRS = $(MBED_DIR) $(MBED_DIR)/$(TARGET_BOARD) $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM . 73 | SRC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY) 74 | SRC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY)/$(TARGET_SPECIFIC) 75 | # app source directories (remove comment and add more files) 76 | #SRC_DIRS += 77 | 78 | OUT_DIR = build 79 | 80 | INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS)) 81 | 82 | ifeq ($(strip $(OUT_DIR)), ) 83 | OBJ_FOLDER = 84 | else 85 | OBJ_FOLDER = $(strip $(OUT_DIR))/ 86 | endif 87 | 88 | COMPILER_OPTIONS = -g -ggdb -Os -Wall -fno-strict-aliasing -fno-rtti 89 | COMPILER_OPTIONS += -ffunction-sections -fdata-sections -fno-exceptions -fno-delete-null-pointer-checks 90 | COMPILER_OPTIONS += -fmessage-length=0 -fno-builtin -m$(INSTRUCTION_MODE) 91 | COMPILER_OPTIONS += -mcpu=$(CPU) -MMD -MP $(CC_SYMBOLS) 92 | 93 | DEPEND_OPTS = -MF $(OBJ_FOLDER)$(@F:.o=.d) 94 | 95 | # Flags 96 | CFLAGS = $(COMPILER_OPTIONS) $(DEPEND_OPTS) $(INC_DIRS_F) -std=gnu99 -c 97 | 98 | CXXFLAGS = $(COMPILER_OPTIONS) $(DEPEND_OPTS) $(INC_DIRS_F) -std=gnu++98 -c 99 | 100 | ASFLAGS = $(COMPILER_OPTIONS) $(INC_DIRS_F) -c 101 | 102 | # Linker options 103 | LD_OPTIONS = -mcpu=$(CPU) -m$(INSTRUCTION_MODE) -Os -L $(LIB_DIRS) -T $(LD_SCRIPT) $(INC_DIRS_F) 104 | LD_OPTIONS += -specs=nano.specs 105 | #use this if %f is used, by default it's commented 106 | #LD_OPTIONS += -u _printf_float -u _scanf_float 107 | LD_OPTIONS += -Wl,-Map=$(OBJ_FOLDER)$(TARGET).map,--gc-sections 108 | 109 | OBJCPFLAGS = -O ihex 110 | 111 | ARFLAGS = cr 112 | 113 | RM = rm -rf 114 | 115 | USER_OBJS = 116 | C_SRCS = 117 | S_SRCS = 118 | C_OBJS = 119 | S_OBJS = 120 | 121 | # All source/object files inside SRC_DIRS 122 | C_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) 123 | C_OBJS := $(patsubst %.c,$(OBJ_FOLDER)%.o,$(notdir $(C_SRCS))) 124 | 125 | CPP_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp)) 126 | CPP_OBJS := $(patsubst %.cpp,$(OBJ_FOLDER)%.o,$(notdir $(CPP_SRCS))) 127 | 128 | S_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s)) 129 | S_OBJS := $(patsubst %.s,$(OBJ_FOLDER)%.o,$(notdir $(S_SRCS))) 130 | 131 | VPATH := $(SRC_DIRS) 132 | 133 | $(OBJ_FOLDER)%.o : %.c 134 | @echo 'Building file: $(@F)' 135 | @echo 'Invoking: MCU C Compiler' 136 | $(CC) $(CFLAGS) $< -o $@ 137 | @echo 'Finished building: $(@F)' 138 | @echo ' ' 139 | 140 | $(OBJ_FOLDER)%.o : %.cpp 141 | @echo 'Building file: $(@F)' 142 | @echo 'Invoking: MCU C++ Compiler' 143 | $(CXX) $(CXXFLAGS) $< -o $@ 144 | @echo 'Finished building: $(@F)' 145 | @echo ' ' 146 | 147 | $(OBJ_FOLDER)%.o : %.s 148 | @echo 'Building file: $(@F)' 149 | @echo 'Invoking: MCU Assembler' 150 | $(AS) $(ASFLAGS) $< -o $@ 151 | @echo 'Finished building: $(@F)' 152 | @echo ' ' 153 | 154 | all: create_outputdir $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) print_info 155 | 156 | create_outputdir: 157 | $(shell mkdir $(OBJ_FOLDER) 2>/dev/null) 158 | 159 | # Tool invocations 160 | $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT): $(LD_SCRIPT) $(C_OBJS) $(CPP_OBJS) $(S_OBJS) $(MBED_OBJ) 161 | @echo 'Building target: $@' 162 | @echo 'Invoking: MCU Linker' 163 | $(LD) $(LD_OPTIONS) $(CPP_OBJS) $(C_OBJS) $(S_OBJS) $(MBED_OBJ) $(LIBS) -o $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) 164 | @echo 'Finished building target: $@' 165 | @echo ' ' 166 | 167 | # Other Targets 168 | clean: 169 | @echo 'Removing entire out directory' 170 | $(RM) $(TARGET).$(TARGET_EXT) $(TARGET).bin $(TARGET).map $(OBJ_FOLDER)*.* $(OBJ_FOLDER) 171 | @echo ' ' 172 | 173 | print_info: 174 | @echo 'Printing size' 175 | arm-none-eabi-size --totals $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) 176 | arm-none-eabi-objcopy -O srec $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) $(OBJ_FOLDER)$(TARGET).s19 177 | arm-none-eabi-objcopy -O binary -v $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) $(OBJ_FOLDER)$(TARGET).bin 178 | arm-none-eabi-objdump -D $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) > $(OBJ_FOLDER)$(TARGET).lst 179 | arm-none-eabi-nm $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) > $(OBJ_FOLDER)$(TARGET)-symbol-table.txt 180 | @echo ' ' 181 | 182 | .PHONY: all clean print_info 183 | -------------------------------------------------------------------------------- /Platforms: -------------------------------------------------------------------------------- 1 | # Copyright (c) 10.2013, 0xc0170 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # PLATFORM SELECTION 16 | 17 | # KINETIS PLATFORM 18 | ifeq ($(BOARD), KL05Z) 19 | LINKER_NAME = MKL05Z4 20 | STARTUP_NAME = startup_MKL05Z4 21 | SYSTEM_NAME = system_MKL05Z4 22 | TARGET_BOARD = TARGET_KL05Z 23 | TARGET_VENDOR = TARGET_Freescale 24 | TARGET_FAMILY = TARGET_KLXX 25 | TARGET_SPECIFIC = TARGET_KL05Z 26 | CPU = cortex-m0 27 | else ifeq ($(BOARD), KL25Z) 28 | LINKER_NAME = MKL25Z4 29 | STARTUP_NAME = startup_MKL25Z4 30 | SYSTEM_NAME = system_MKL25Z4 31 | TARGET_BOARD = TARGET_KL25Z 32 | TARGET_VENDOR = TARGET_Freescale 33 | TARGET_FAMILY = TARGET_KLXX 34 | TARGET_SPECIFIC = TARGET_KL25Z 35 | CPU = cortex-m0 36 | else ifeq ($(BOARD), KL46Z) 37 | LINKER_NAME = MKL46Z4 38 | STARTUP_NAME = startup_MKL46Z4 39 | SYSTEM_NAME = system_MKL46Z4 40 | TARGET_BOARD = TARGET_KL46Z 41 | TARGET_VENDOR = TARGET_Freescale 42 | TARGET_FAMILY = TARGET_KLXX 43 | TARGET_SPECIFIC = TARGET_KL46Z 44 | CPU = cortex-m0 45 | 46 | # NXP PLATFORM 47 | else ifeq ($(BOARD), LPC1768) 48 | LINKER_NAME = LPC1768 49 | STARTUP_NAME = startup_LPC17xx 50 | SYSTEM_NAME = system_LPC17xx 51 | TARGET_BOARD = TARGET_LPC1768 52 | TARGET_VENDOR = TARGET_NXP 53 | TARGET_FAMILY = TARGET_LPC176X 54 | TARGET_SPECIFIC = TARGET_MBED_LPC1768 55 | CPU = cortex-m3 56 | else ifeq ($(BOARD), LPC11U24) 57 | LINKER_NAME = LPC11U24 58 | STARTUP_NAME = startup_LPC11xx 59 | SYSTEM_NAME = system_LPC11Uxx 60 | TARGET_BOARD = TARGET_LPC11U24 61 | TARGET_VENDOR = TARGET_NXP 62 | TARGET_FAMILY = TARGET_LPC11UXX 63 | TARGET_SPECIFIC = TARGET_LPC11U24_401 64 | CPU = cortex-m0 65 | else ifeq ($(BOARD), LPC11U24_301) 66 | LINKER_NAME = LPC11U24 67 | STARTUP_NAME = startup_LPC11xx 68 | SYSTEM_NAME = system_LPC11Uxx 69 | TARGET_BOARD = TARGET_LPC11U24_301 70 | TARGET_VENDOR = TARGET_NXP 71 | TARGET_FAMILY = TARGET_LPC11UXX 72 | TARGET_SPECIFIC = TARGET_LPC11U24_301 73 | CPU = cortex-m0 74 | else ifeq ($(BOARD), LPC1347) 75 | LINKER_NAME = LPC1347 76 | STARTUP_NAME = startup_LPC13xx 77 | SYSTEM_NAME = system_LPC13Uxx 78 | TARGET_BOARD = TARGET_LPC1347 79 | TARGET_VENDOR = TARGET_NXP 80 | TARGET_FAMILY = TARGET_LPC13XX 81 | TARGET_SPECIFIC = . 82 | CPU = cortex-m3 83 | else ifeq ($(BOARD), LPC1114) 84 | LINKER_NAME = LPC1114 85 | STARTUP_NAME = startup_LPC11xx 86 | SYSTEM_NAME = system_LPC11xx 87 | TARGET_BOARD = TARGET_LPC1114 88 | TARGET_VENDOR = TARGET_NXP 89 | TARGET_FAMILY = TARGET_LPC11XX_11CXX 90 | TARGET_SPECIFIC = TARGET_LPC11XX 91 | CPU = cortex-m0 92 | else ifeq ($(BOARD), LPC11C24) 93 | LINKER_NAME = LPC11C24 94 | STARTUP_NAME = startup_LPC11xx 95 | SYSTEM_NAME = system_LPC11xx 96 | TARGET_BOARD = TARGET_LPC11C24 97 | TARGET_VENDOR = TARGET_NXP 98 | TARGET_FAMILY = TARGET_LPC11XX_11CXX 99 | TARGET_SPECIFIC = TARGET_LPC11CXX 100 | CPU = cortex-m0 101 | else ifeq ($(BOARD), LPC11U35_401) 102 | LINKER_NAME = LPC11U35 103 | STARTUP_NAME = startup_LPC11xx 104 | SYSTEM_NAME = system_LPC11Uxx 105 | TARGET_BOARD = TARGET_LPC11U35_401 106 | TARGET_VENDOR = TARGET_NXP 107 | TARGET_FAMILY = TARGET_LPC11UXX 108 | TARGET_SPECIFIC = TARGET_LPC11U35_401 109 | CPU = cortex-m0 110 | 111 | # STM platform 112 | else ifeq ($(BOARD), STM32F407) 113 | LINKER_NAME = STM32F407 114 | STARTUP_NAME = startup_STM32F40x 115 | SYSTEM_NAME = system_stm32f4xx 116 | TARGET_BOARD = TARGET_STM32F407 117 | TARGET_VENDOR = TARGET_STM 118 | TARGET_FAMILY = TARGET_STM32F4XX 119 | TARGET_SPECIFIC = . 120 | CPU = cortex-m4 121 | endif 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mbed GCC Makefile 2 | 3 | Note: This is old Makefile (few years old). There were plenty of changes in mbed (currently Mbed OS) tree. Therefore this might not build anymore. 4 | Use mbed-cli to build Mbed OS or export (supports exporting to Makefiles for various toolchains). This repo serves as a good example 5 | how to write a simple makefile to build a project with mbed or similar SDK. 6 | 7 | ### SUPPORTED PLATFORMS GCC_ARM 8 | * KL05Z 9 | * KL25Z 10 | * KL46Z 11 | * LPC1768 12 | * LPC11U24 13 | * LPC11U24_301 14 | * LPC1347 15 | * LPC1114 16 | * LPC11C24 17 | * LPC11U35_401 18 | * STM32F407 19 | 20 | If a board is missing, please send a pull request adding it, to keep this up to date. Thanks. 21 | 22 | How to use this makefile? I wrote a simple step guide how to create an eclipse project for mbed, used FRDM-KL25Z board: [mbed GCC with eclipse for KL25Z](http://0xc0170.github.io/mbed/2013/08/05/mbed-gcc-with-eclipse-kl25z-part-1/) 23 | 24 | If there's an issue, or any improvements can be made, report it in the [issues](https://github.com/0xc0170/mbed_gcc_makefile/issues). 25 | 26 | ## License 27 | Apache License, Version 2.0 28 | 29 | EnjoY! 30 | --------------------------------------------------------------------------------