Skip to content

Commit

Permalink
Add an example app for the EFR32 (#321)
Browse files Browse the repository at this point in the history
* Add an example app for the efr32

* Fix clang format for some source files

* Remove unused header file

* Remove commented code

* Remove more commented out code

* Remove unnecessary LED init in main

* Address review comment

* Make sure all available LEDs are flashed during a reset

* EFR32 does not support more than 2 LEDs

* Fix formatting in FreeRTOSConfig.h

* Add a new line at the end of env.sh

* Fix double space in Readme

* Fix hyperlink

* Remove env.sh and migrate it into the Makefile

* Remove unnecessary variable checks in the Makefile

* Cleanup context after requesting a software update

* Cleanup Makefile and add a link to CHIP's root

* Add fatal error if timers fail
  • Loading branch information
sagar-apple authored Apr 14, 2020
1 parent 076237f commit 3085be9
Show file tree
Hide file tree
Showing 27 changed files with 4,010 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Makefile.in
aclocal.m4
autom4te.cache
output/
build/*
build/
!build/README.md
!build/autoconf/m4/chip_check_project_config_includes.m4
!build/autoconf/m4/nl_with_lwip.m4
Expand Down
195 changes: 195 additions & 0 deletions examples/lock-app/efr32/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#
#
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2019 Google LLC.
#
# 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
# Makefile for building the CHIP SiLabs EFR32 Lock Example Application.
#

#
# Differentiate between boards
#
# MG12
# - BRD4304A / SLWSTK6000B / MGM12P Module / 2.4GHz@19dBm
# - BRD4161A / SLWSTK6000B / Wireless Starter Kit / 2.4GHz@19dBm
# - BRD4166A / SLTB004A / Thunderboard Sense 2 / 2.4GHz@10dBm
# - BRD4170A / SLWSTK6000B / Multiband Wireless Starter Kit / 2.4GHz@19dBm, 915MHz@19dBm
#
# MG21
# - BRD4180A / SLWSTK6006A / Wireless Starter Kit / 2.4GHz@20dBm

PROJECT_ROOT := $(realpath .)

#
# Location of the EFR32 SDK
#
ifndef EFR32_SDK_ROOT
$(error ENVIRONMENT ERROR: EFR32_SDK_ROOT not set)
endif

CHIP_ROOT ?= $(realpath $(PROJECT_ROOT)/third_party/connectedhomeip)
EFR32_TOOLS_ROOT ?= $(realpath $(EFR32_SDK_ROOT)/../../../..)
FREERTOS_ROOT ?= $(realpath $(EFR32_SDK_ROOT)/util/third_party/freertos)

# Do not enable -Wconversion for Silicon Labs SDK sources
override CFLAGS := $(filter-out -Wconversion,$(CFLAGS))
override CXXFLAGS := $(filter-out -Wconversion,$(CXXFLAGS))

# Do not enable -pedantic-errors for Silicon Labs SDK sources
override CFLAGS := $(filter-out -pedantic-errors,$(CFLAGS))
override CXXFLAGS := $(filter-out -pedantic-errors,$(CXXFLAGS))

# Do not enable -Wshadow for Silicon Labs SDK sources
override CFLAGS := $(filter-out -Wshadow,$(CFLAGS))
override CXXFLAGS := $(filter-out -Wshadow,$(CXXFLAGS))

# Do not enable -Wundef for Silicon Labs SDK sources
override CFLAGS := $(filter-out -Wundef,$(CFLAGS))
override CXXFLAGS := $(filter-out -Wundef,$(CXXFLAGS))

FREERTOSCONFIG_DIR := $(PROJECT_ROOT)/include

GECKO_SDK_SUITE_DIR := $(EFR32_SDK_ROOT)/..

all : |

BUILD_SUPPORT_DIR := $(CHIP_ROOT)/build/efr32

include $(BUILD_SUPPORT_DIR)/efr32-app.mk
include $(BUILD_SUPPORT_DIR)/efr32-chip.mk
include $(BUILD_SUPPORT_DIR)/efr32-freertos.mk

APP = efr32-lock-example

SRCS = \
$(PROJECT_ROOT)/src/main.cpp \
$(PROJECT_ROOT)/src/LEDWidget.cpp \
$(PROJECT_ROOT)/src/AppTask.cpp \
$(PROJECT_ROOT)/src/ButtonHandler.cpp \
$(PROJECT_ROOT)/src/init_mcu.c \
$(PROJECT_ROOT)/src/init_board.c \
$(EFR32_SDK_ROOT)/hardware/kit/common/bsp/bsp_bcc.c \
$(EFR32_SDK_ROOT)/hardware/kit/common/bsp/bsp_init.c \
$(EFR32_SDK_ROOT)/hardware/kit/common/bsp/bsp_stk.c \
$(EFR32_SDK_ROOT)/hardware/kit/common/bsp/bsp_stk_leds.c \
$(EFR32_SDK_ROOT)/platform/emdrv/dmadrv/src/dmadrv.c \
$(EFR32_SDK_ROOT)/platform/emdrv/gpiointerrupt/src/gpiointerrupt.c \
$(EFR32_SDK_ROOT)/platform/emdrv/uartdrv/src/uartdrv.c \
$(EFR32_SDK_ROOT)/platform/emdrv/ustimer/src/ustimer.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_adc.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_cmu.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_core.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_crypto.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_emu.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_gpio.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_ldma.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_leuart.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_msc.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_rmu.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_rtcc.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_system.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_timer.c \
$(EFR32_SDK_ROOT)/platform/emlib/src/em_usart.c \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/hal/efr32/hal_efr.c \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/hal/hal_common.c \
$(EFR32_SDK_ROOT)/platform/service/mpu/src/sl_mpu.c \
$(EFR32_SDK_ROOT)/platform/service/sleeptimer/src/sl_sleeptimer.c \
$(EFR32_SDK_ROOT)/platform/service/sleeptimer/src/sl_sleeptimer_hal_rtcc.c \
$(EFR32_SDK_ROOT)/platform/Device/SiliconLabs/EFR32MG12P/Source/system_efr32mg12p.c \
$(EFR32_SDK_ROOT)/platform/Device/SiliconLabs/EFR32MG12P/Source/GCC/startup_efr32mg12p.c \
$(EFR32_SDK_ROOT)/hardware/kit/common/drivers/mx25flash_spi.c \
$(EFR32_SDK_ROOT)/hardware/kit/common/drivers/retargetio.c \
$(EFR32_SDK_ROOT)/hardware/kit/common/drivers/retargetserial.c \



INC_DIRS = \
$(PROJECT_ROOT) \
$(PROJECT_ROOT)/include \
$(PROJECT_ROOT)/traits/include \
$(PROJECT_ROOT)/schema/include \
$(CHIP_ROOT)/src/include/ \
$(CHIP_ROOT)/src/lib \
$(CHIP_ROOT)/src/ \
$(CHIP_ROOT)/src/system \
$(EFR32_SDK_ROOT) \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/common \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/chip/efr32 \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/protocol/ieee802154 \
$(EFR32_SDK_ROOT)/platform/radio/rail_lib/chip/efr32/rf/common/cortex \
$(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)/hardware/kit/common/bsp \
$(EFR32_SDK_ROOT)/platform/CMSIS/Include \
$(EFR32_SDK_ROOT)/platform/emdrv/common/inc \
$(EFR32_SDK_ROOT)/platform/emdrv/gpiointerrupt/inc \
$(EFR32_SDK_ROOT)/platform/emdrv/uartdrv/inc \
$(EFR32_SDK_ROOT)/platform/emdrv/uartdrv/config \
$(EFR32_SDK_ROOT)/platform/emdrv/ustimer/inc \
$(EFR32_SDK_ROOT)/platform/emdrv/dmadrv/inc \
$(EFR32_SDK_ROOT)/platform/emdrv/dmadrv/config \
$(EFR32_SDK_ROOT)/platform/emlib/inc \
$(EFR32_SDK_ROOT)/platform/halconfig/inc/hal-config \
$(EFR32_SDK_ROOT)/platform/common/inc \
$(EFR32_SDK_ROOT)/platform/service/mpu/inc \
$(EFR32_SDK_ROOT)/platform/service/sleeptimer/inc \
$(EFR32_SDK_ROOT)/platform/service/sleeptimer/config \
$(EFR32_SDK_ROOT)/util/plugin/plugin-common/fem-control \
$(EFR32_SDK_ROOT)/hardware/kit/EFR32MG12_$(BOARD)/config \
$(EFR32_SDK_ROOT)/platform/Device/SiliconLabs/EFR32MG12P/Include \
$(EFR32_SDK_ROOT)/hardware/kit/EFR32MG12_BRD4161A \
$(EFR32_SDK_ROOT)/hardware/kit/common/drivers/ \
$(EFR32_SDK_ROOT)/hardware/kit/common/halconfig/ \


ifeq ($(EFR32FAMILY), efr32mg12)
LINKER_SCRIPT=./ldscripts/$(APP)-MG12P.ld
else
ifeq ($(EFR32FAMILY), efr32mg21)
LINKER_SCRIPT=./ldscripts/$(APP)-MG21.ld
endif
endif

DEFINES = \
HARD_FAULT_LOG_ENABLE \
RETARGET_VCOM \
RETARGET_USART0 \
PLATFORM_HEADER='<hal/micro/cortexm3/compiler/gcc.h>' \
CORTEXM3_EFM32_MICRO \
CHIP_ERROR_LOGGING=1 \
CHIP_PROGRESS_LOGGING=1 \
CHIP_DETAIL_LOGGING=1 \
EFR32_LOG_ENABLED=1 \
NVM3_DEFAULT_NVM_SIZE=40960

CFLAGS = \
-specs=nano.specs

LDFLAGS = \
-specs=nano.specs

ifdef DEVICE_FIRMWARE_REVISION
DEFINES += \
CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION=\"$(DEVICE_FIRMWARE_REVISION)\"
endif

CHIP_PROJECT_CONFIG = $(PROJECT_ROOT)/include/CHIPProjectConfig.h

clean ::

$(call GenerateBuildRules)
159 changes: 159 additions & 0 deletions examples/lock-app/efr32/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# CHIP EFR32 Lock Example

An example showing the use of CHIP on the Silicon Labs EFR32 MG12.

<hr>

- [CHIP EFR32 Lock Example](#chip-efr32-lock-example)
- [Introduction](#introduction)
- [Building](#building)
- [Initializing the EFR32 module](#initializing-the-efr32-module)
- [Flashing the Application](#flashing-the-application)
- [Viewing Logging Output](#viewing-logging-output)

<hr>

<a name="intro"></a>

## Introduction

The EFR32 lock example provides a baseline demonstration of a door lock device, built using CHIP and the Silicon Labs gecko SDK. The example is currently very basic and only supports responding
to button presses to indicate the state of the lock and view logging from the device.

The lock example is intended to serve both as a means to explore the workings of CHIP as well as a template for creating real products based on the Silicon Labs platform.

A top-level Makefile orchestrates the entire build process, including building CHIP,
FreeRTOS, and select files from the Silicon Labs SDK. The resultant image file can be flashed directly onto the Silicon Labs WSTK kit hardware.


<a name="building"></a>

## Building

* Download and install the [Silicon Labs Simplicity Studio and SDK for Thread and Zigbee version v2.7](https://www.silabs.com/products/development-tools/software/simplicity-studio)

Install SimplicityStudio or extract the SimplicityStudio archive to where you want to install Simplicity Studio and follow the instructions in README.txt found within the extracted archive to complete installation.

On OSX, be sure to rename `/Applications/Simplicity Studio.app/` to something without a "space". For example, rename it to `/Applications/Simplicity_Studio.app/`

In Simplicity Studio from the Launcher perspective click on the "Update Software" button. The Package Manager window will Open. Ensure that the following SDKs are installed (as of January 2020).

* Bluetooth 2.13.0.0
* Flex 2.7.0.0

* Download and install a suitable ARM gcc tool chain: [GNU Arm Embedded Toolchain 9-2019-q4-major](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)

* Install some additional tools(likely already present for CHIP developers):

# Linux
$ sudo apt-get install git make automake libtool ccache

# Mac OS X
$ brew install automake libtool ccache

* To build for an MG21 part make the following changes to the platform/CMSIS/Include/core_cm33.h file within the Silicon Labs SDK.
Copy the following lines to the top of the core_cm33.h file.

```cpp
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
```

* Supported hardware:

MG12 boards:

- BRD4161A / SLWSTK6000B / Wireless Starter Kit / 2.4GHz@19dBm
- BRD4166A / SLTB004A / Thunderboard Sense 2 / 2.4GHz@10dBm
- BRD4170A / SLWSTK6000B / Multiband Wireless Starter Kit / 2.4GHz@19dBm, 915MHz@19dBm
- BRD4304A / SLWSTK6000B / MGM12P Module / 2.4GHz@19dBm

MG21 boards:

- BRD4180A / SLWSTK6006A / Wireless Starter Kit / 2.4GHz@20dBm


* Build the example application:

$ export EFR32_SDK_ROOT=<path-to-silabs-sdk-v2.7>
$ make BOARD=BRD4161A


* To delete generated executable, libraries and object files use:

$ make BOARD=BRD4161A clean


<a name="initializing"></a>

## Initializing the EFR32 module

The example application is designed to run on the Silicon Labs SDK development kit. Prior to installing the application, the device's flash memory should be erased.

* Connect the host machine to the J-Link Interface MCU USB connector on the EFR32 WSTK.

* Use the Makefile to erase the flash:

$ make BOARD=BRD4161A erase

* To erase a specific device using its serial number:

$ make BOARD=BRD4161A SERIALNO=440113717 erase


<a name="flashing"></a>

## Flashing the Application

* To rebuild the image and flash the example app:

$ make BOARD=BRD4161A flash

* To rebuild the image and flash a specific device using its serial number:

$ make BOARD=BRD4161A SERIALNO=440113717 flash

* To flash an existing image without rebuilding:

$ make BOARD=BRD4161A flash-app


<a name="view-logging"></a>

## Viewing Logging Output

The example application is built to use the SEGGER Real Time Transfer (RTT) facility for log output. RTT is a feature built-in to the J-Link Interface MCU on the WSTK development board. It allows bi-directional communication with an embedded application without the need for a dedicated UART.

Using the RTT facility requires downloading and installing the *SEGGER J-Link Software and Documentation Pack* ([web site](https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack)). Alternatively the *SEGGER Ozone - J-Link Debugger* can be used to view RTT logs.

* Download the J-Link installer by navigating to the appropriate URL and agreeing to the license agreement.

* [JLink_Linux_x86_64.deb](https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb)
* [JLink_MacOSX.pkg](https://www.segger.com/downloads/jlink/JLink_MacOSX.pkg)


* Install the J-Link software

$ cd ~/Downloads
$ sudo dpkg -i JLink_Linux_V*_x86_64.deb

* In Linux, grant the logged in user the ability to talk to the development hardware via the linux tty device (/dev/ttyACMx) by adding them to the dialout group.

$ sudo usermod -a -G dialout ${USER}

Once the above is complete, log output can be viewed using the JLinkExe tool in combination with JLinkRTTClient as follows:

* Run the JLinkExe tool with arguments to autoconnect to the WSTK board:

For MG12 use:

$ JLinkExe -device EFR32MG12PXXXF1024 -if JTAG -speed 4000 -autoconnect 1

For MG21 use:

$ JLinkExe -device EFR32MG21AXXXF1024 -if SWD -speed 4000 -autoconnect 1

* In a second terminal, run the JLinkRTTClient to view logs:

$ JLinkRTTClient
Loading

0 comments on commit 3085be9

Please sign in to comment.