Skip to content

Commit

Permalink
Fix CHIP DeviceLayer Build and Link for EFR32 (project-chip#278)
Browse files Browse the repository at this point in the history
* Add efr32-freertos.mk to build libfreertos

* Add SystemEventSupport and SystemTimerSupport

* Add globals

* Update helper Makefiles

* Update .gitignore

* Update DeviceLayer library and fix logging support

* Remove "with-openssl=no" from efr32-chip.mk

* Remove functionality from InitChipStack

* Fix RTT Logs by using a more recent version

* Remove commented out code and leave TODOs instead

* Remove commented code
  • Loading branch information
sagar-apple authored Apr 9, 2020
1 parent 64c02a6 commit e6c95b0
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 74 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Build System
.deps
.dirstamp
.DS_Store
.local-version
Makefile.in
aclocal.m4
Expand All @@ -20,10 +21,8 @@ build/*
!build/config/standalone/SystemProjectConfig.h
!build/config/standalone/darwin/CHIPProjectConfig.h
!build/config/standalone/no-openssl/CHIPProjectConfig.h
!build/efr32/efr32-app.mk
!build/efr32/efr32-chip.mk
!build/nrf5/nrf5-app.mk
!build/nrf5/nrf5-chip.mk
!build/efr32/
!build/nrf5/
!build/scripts/gen-chip-version
config.log
config.status
Expand Down
41 changes: 29 additions & 12 deletions build/efr32/efr32-app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ifndef FREERTOS_ROOT
$(error ENVIRONMENT ERROR: FREERTOS_ROOT not set)
endif


uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')

# Differentiate between boards
# - BRD4304A / SLWSTK6000B / MGM12P Module / 2.4GHz@19dBm
Expand Down Expand Up @@ -119,15 +119,10 @@ EXTRA_SRCS += \
$(EFR32_SDK_ROOT)/platform/emdrv/nvm3/src/nvm3_default.c \
$(EFR32_SDK_ROOT)/platform/emdrv/nvm3/src/nvm3_hal_flash.c \
$(EFR32_SDK_ROOT)/platform/emdrv/sleep/src/sleep.c \
$(EFR32_SDK_ROOT)/util/third_party/segger/systemview/SEGGER/SEGGER_RTT.c

STD_INC_DIRS += \
$(CHIP_ROOT)/src/include/platform/EFR32 \
$(OPENTHREAD_ROOT)/output/include \
$(OPENTHREAD_ROOT)/src/core/ \
$(OPENTHREAD_ROOT)/third_party/jlink/SEGGER_RTT_V640/RTT \
$(OPENTHREAD_ROOT)/third_party/mbedtls \
$(OPENTHREAD_ROOT)/third_party/mbedtls/repo/include \
$(OPENTHREAD_ROOT)/third_party/mbedtls/repo/include/mbedtls \
$(FREERTOS_ROOT)/Source/include \
$(FREERTOS_ROOT)/Source/portable/GCC/ARM_CM3 \
$(EFR32_SDK_ROOT) \
Expand Down Expand Up @@ -159,11 +154,10 @@ STD_INC_DIRS += \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/hal \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/hal/efr32 \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/plugin/pa-conversions \
$(EFR32_SDK_ROOT)/util/third_party/segger/systemview/SEGGER \
$(EFR32_SDK_ROOT)/util/third_party/segger/systemview/Config/ \
$(EFR32_SDK_ROOT)/util/plugin/plugin-common/fem-control \
$(EFR32_SDK_ROOT)/util/third_party/mbedtls/sl_crypto/include \
$(OPENTHREAD_ROOT)/examples/platforms/$(EFR32FAMILY)/ \
$(OPENTHREAD_ROOT)/examples/platforms/$(EFR32FAMILY)/$(BOARD_LC) \
$(OPENTHREAD_ROOT)/examples/platforms/$(EFR32FAMILY)/crypto
$(EFR32_SDK_ROOT)/util/third_party/mbedtls/sl_crypto/include

ifeq ($(EFR32FAMILY), efr32mg12)
STD_INC_DIRS += \
Expand Down Expand Up @@ -244,6 +238,8 @@ STD_LDFLAGS = \
-ffunction-sections \
-Wl,--gc-sections \
-specs=nosys.specs \
$(foreach dir,$(LINKER_SCRIPT_INC_DIRS),-L$(dir)) \
-T$(LINKER_SCRIPT)

ifeq ($(EFR32FAMILY), efr32mg21)
STD_LDFLAGS += \
Expand All @@ -253,12 +249,14 @@ endif
STD_LIBS = \
-lc \
-lstdc++ \
-lfreertos \
-lnosys \
-lm

ifeq ($(EFR32FAMILY), efr32mg12)
STD_LIBS += \
$(EFR32_SDK_ROOT)/protocol/bluetooth/lib/EFR32MG12P/GCC/libbluetooth.a \
$(EFR32_SDK_ROOT)/protocol/bluetooth/lib/EFR32MG12P/GCC/libmbedtls.a \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/autogen/librail_release/librail_multiprotocol_efr32xg12_gcc_release.a \
$(EFR32_SDK_ROOT)/platform/emdrv/nvm3/lib/libnvm3_CM4_gcc.a
else
Expand All @@ -277,12 +275,28 @@ STD_DEFINES = \

STD_COMPILE_PREREQUISITES =

STD_LINK_PREREQUISITES += $(OUTPUT_DIR)/freertos/libfreertos.a

DEFINE_FLAGS = $(foreach def,$(STD_DEFINES) $(DEFINES),-D$(def))

INC_FLAGS = $(foreach dir,$(INC_DIRS) $(STD_INC_DIRS),-I$(dir))

LINKER_SCRIPT_INC_DIRS = $(PROJECT_ROOT) $(OUTPUT_DIR)/freertos

# Default EFR32 linker script defines a section at top of Flash for NVM3 support.
ifeq ($(EFR32FAMILY), efr32mg12)
ifndef LINKER_SCRIPT
LINKER_SCRIPT = $(APP)-MG12P.ld
endif
else
ifeq ($(EFR32FAMILY), efr32mg21)
ifndef LINKER_SCRIPT
LINKER_SCRIPT = $(APP)-MG21.ld
endif
endif
endif


# ==================================================
# Toolchain and external utilities / files
# ==================================================
Expand All @@ -308,8 +322,11 @@ ifneq (, $(shell which ccache))
CCACHE = ccache
endif

ifeq ($(uname_S),Darwin)
COMMANDER = $(EFR32_TOOLS_ROOT)/developer/adapter_packs/commander/Commander.app/Contents/MacOS/commander
else
COMMANDER = $(EFR32_TOOLS_ROOT)/developer/adapter_packs/commander/commander

endif

# ==================================================
# Build options
Expand Down
5 changes: 2 additions & 3 deletions build/efr32/efr32-chip.mk
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ CHIP_CONFIGURE_OPTIONS = \
--with-lwip=internal \
--with-lwip-target=efr32 \
--with-inet-endpoint="tcp udp" \
--with-openssl=no \
--with-logging-style=external \
--with-chip-project-includes=$(CHIP_PROJECT_CONFIG) \
--with-chip-system-project-includes=$(CHIP_PROJECT_CONFIG) \
Expand Down Expand Up @@ -153,7 +152,7 @@ STD_LDFLAGS += -L$(CHIP_OUTPUT_DIR)/lib
# Add CHIP libraries to standard libraries list.
STD_LIBS += \
-lDeviceLayer \
-lchip \
-lCHIP \
-lInetLayer \
-lnlfaultinjection \
-lSystemLayer \
Expand All @@ -167,7 +166,7 @@ STD_COMPILE_PREREQUISITES += install-chip
# Add the CHIP libraries as prerequisites for linking the application.
STD_LINK_PREREQUISITES += \
$(CHIP_OUTPUT_DIR)/lib/libDeviceLayer.a \
$(CHIP_OUTPUT_DIR)/lib/libchip.a \
$(CHIP_OUTPUT_DIR)/lib/libCHIP.a \
$(CHIP_OUTPUT_DIR)/lib/libInetLayer.a \
$(CHIP_OUTPUT_DIR)/lib/libnlfaultinjection.a \
$(CHIP_OUTPUT_DIR)/lib/libSystemLayer.a \
Expand Down
152 changes: 152 additions & 0 deletions build/efr32/efr32-freertos.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2020 Google LLC.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# @file
# Component makefile for incorporating FreeRTOS into an EFR32
# application.
#

#
# This makefile is intended to work in conjunction with the efr32-app.mk
# makefile to build the OpenWeave example applications on Silicon Labs platforms.
# EFR32 applications should include this file in their top level Makefile
# along with the other makefiles in this directory. E.g.:
#
# PROJECT_ROOT = $(realpath .)
#
# BUILD_SUPPORT_DIR = $(PROJECT_ROOT)/third_party/openweave-core/build/efr32
#
# include $(BUILD_SUPPORT_DIR)/efr32-app.mk
# include $(BUILD_SUPPORT_DIR)/efr32-openweave.mk
# include $(BUILD_SUPPORT_DIR)/efr32-openthread.mk
# include $(BUILD_SUPPORT_DIR)/efr32-freertos.mk
#
# PROJECT_ROOT := $(realpath .)
#
# APP := openweave-efr32-bringup
#
# SRCS = \
# $(PROJECT_ROOT)/main.cpp \
# ...
#
# $(call GenerateBuildRules)
#

ifeq ($(EFR32FAMILY), efr32mg12)
FREERTOS_TARGET = ARM_CM3
else
ifeq ($(EFR32FAMILY), efr32mg21)
FREERTOS_TARGET = ARM_CM4F
endif
endif

FREERTOS_OUTPUT_DIR = $(OUTPUT_DIR)/freertos
FREERTOS_LIB_DIR = $(FREERTOS_OUTPUT_DIR)

STD_LDFLAGS += \
-L$(FREERTOS_LIB_DIR)

STD_INC_DIRS += \
$(FREERTOS_ROOT)/Source/include/

$(FREERTOS_OUTPUT_DIR)/croutine.c.o : $(FREERTOS_ROOT)/Source/croutine.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/croutine.c -o $(FREERTOS_OUTPUT_DIR)/croutine.c.o

$(FREERTOS_OUTPUT_DIR)/list.c.o : $(FREERTOS_ROOT)/Source/list.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/list.c -o $(FREERTOS_OUTPUT_DIR)/list.c.o

$(FREERTOS_OUTPUT_DIR)/queue.c.o : $(FREERTOS_ROOT)/Source/queue.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/queue.c -o $(FREERTOS_OUTPUT_DIR)/queue.c.o

$(FREERTOS_OUTPUT_DIR)/event_groups.c.o : $(FREERTOS_ROOT)/Source/event_groups.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/event_groups.c -o $(FREERTOS_OUTPUT_DIR)/event_groups.c.o

$(FREERTOS_OUTPUT_DIR)/tasks.c.o : $(FREERTOS_ROOT)/Source/tasks.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/tasks.c -o $(FREERTOS_OUTPUT_DIR)/tasks.c.o

$(FREERTOS_OUTPUT_DIR)/timers.c.o : $(FREERTOS_ROOT)/Source/timers.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/timers.c -o $(FREERTOS_OUTPUT_DIR)/timers.c.o

$(FREERTOS_OUTPUT_DIR)/port.c.o : $(FREERTOS_ROOT)/Source/portable/GCC/$(FREERTOS_TARGET)/port.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/portable/GCC/$(FREERTOS_TARGET)/port.c -o $(FREERTOS_OUTPUT_DIR)/port.c.o

$(FREERTOS_OUTPUT_DIR)/heap_3.c.o : $(FREERTOS_ROOT)/Source/portable/MemMang/heap_3.c $(FREERTOSCONFIG_DIR)/FreeRTOSConfig.h
$(NO_ECHO) $(CCACHE) $(CC) -c $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(INC_FLAGS) $(FREERTOS_ROOT)/Source/portable/MemMang/heap_3.c -o $(FREERTOS_OUTPUT_DIR)/heap_3.c.o

FREERTOS_OBJECTS := \
$(FREERTOS_OUTPUT_DIR)/croutine.c.o \
$(FREERTOS_OUTPUT_DIR)/list.c.o \
$(FREERTOS_OUTPUT_DIR)/queue.c.o \
$(FREERTOS_OUTPUT_DIR)/event_groups.c.o \
$(FREERTOS_OUTPUT_DIR)/tasks.c.o \
$(FREERTOS_OUTPUT_DIR)/timers.c.o \
$(FREERTOS_OUTPUT_DIR)/port.c.o \
$(FREERTOS_OUTPUT_DIR)/heap_3.c.o


# Add FreeRTOSBuildRules to the list of late-bound build rules that
# will be evaluated when GenerateBuildRules is called.
LATE_BOUND_RULES += FreeRTOSBuildRules

# Rules for configuring, building and installing FreeRTOS from source.
define FreeRTOSBuildRules

$(FREERTOS_LIB_DIR)/libfreertos.a : $(FREERTOS_OUTPUT_DIR) $(FREERTOS_LIB_DIR) $(FREERTOS_OBJECTS)
@echo "$(HDR_PREFIX)AR $(FREERTOS_LIB_DIR)/libfreertos.a"
$(NO_ECHO)$(AR) rcs $(FREERTOS_LIB_DIR)/libfreertos.a $(FREERTOS_OBJECTS)

.phony: $(FREERTOS_OUTPUT_DIR)
$(FREERTOS_OUTPUT_DIR) :
@echo "$(HDR_PREFIX)MKDIR $@"
$(NO_ECHO)mkdir -p $(FREERTOS_OUTPUT_DIR)

.phony: build-freertos
build-freertos : $(FREERTOS_LIB_DIR)/libfreertos.a

.phony: install-freertos
install-freertos : $(FREERTOS_OUTPUT_DIR)
@echo "$(HDR_PREFIX)CP $(FREERTOS_OUTPUT_DIR)"
$(NO_ECHO)cp -r $(FREERTOS_ROOT)/Source/include $(FREERTOS_OUTPUT_DIR)/

.phony: clean-freertos
clean-freertos :
@echo "$(HDR_PREFIX)RM $(FREERTOS_OUTPUT_DIR)"
$(NO_ECHO)rm -rf $(FREERTOS_OUTPUT_DIR)

endef


# ==================================================
# FreeRTOS-specific help definitions
# ==================================================

define TargetHelp +=

build-freertos Build the FreeRTOS library.

install-freertos Install FreeRTOS library and headers in
build output directory for use by application.

clean-freertos Clean all build outputs produced by the FreeRTOS
build process.
endef




1 change: 1 addition & 0 deletions src/include/platform/EFR32/freertos_bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2020 Google LLC.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit e6c95b0

Please sign in to comment.