Skip to content

Silabs xG24 devkits ports #7833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2ac5a20
Initial commit for xg24
silabs-ChatNguyen Mar 28, 2023
87c407d
Fix SLC issue
silabs-ChatNguyen Mar 28, 2023
454219e
Fix SLC extract fail
silabs-ChatNguyen Mar 29, 2023
0cdd001
Change board's name
silabs-ChatNguyen Apr 3, 2023
f6c0c16
Correct spelling of code
silabs-ChatNguyen Apr 4, 2023
181a93f
Remove VID and PID
silabs-ChatNguyen Apr 4, 2023
70d9a2e
Change creator and creation id
silabs-ChatNguyen Apr 5, 2023
8181c5f
Apply new creator_id and creation_id
silabs-ChatNguyen Apr 5, 2023
a337d20
Update makefile, error message, mcu_processor function
silabs-ChatNguyen Apr 11, 2023
187fafe
Update mpconfigboard.mk
silabs-ChatNguyen Apr 11, 2023
c7897d5
Update Board extensions, PORT_DEPS
silabs-ChatNguyen Apr 11, 2023
8f3b3d5
Update makefile
silabs-ChatNguyen Apr 11, 2023
bf99e06
Add exclude_patterns
silabs-ChatNguyen Apr 11, 2023
fd80a62
Show java, jinja2 version
silabs-ChatNguyen Apr 11, 2023
5148dab
Show path for debugging CI
silabs-ChatNguyen Apr 12, 2023
50d82ef
Add requirements-dev for slc
silabs-ChatNguyen Apr 12, 2023
dfa7570
Add PATH slc_cli
silabs-ChatNguyen Apr 13, 2023
2d7886a
Merge branch 'adafruit:main' into main
silabs-ChatNguyen Apr 13, 2023
28bdd38
Update background function
silabs-ChatNguyen Apr 13, 2023
256f7b0
Add jinja2 PATH
silabs-ChatNguyen Apr 13, 2023
7e04ea6
Show PATH
silabs-ChatNguyen Apr 13, 2023
2626e1a
Update jinja2 path
silabs-ChatNguyen Apr 13, 2023
439c674
Update jinja2 path
silabs-ChatNguyen Apr 13, 2023
9df750f
Update jinja2 path
silabs-ChatNguyen Apr 13, 2023
82d7c57
Update jinja2 path
silabs-ChatNguyen Apr 13, 2023
87a498e
Change slc folder
silabs-ChatNguyen Apr 13, 2023
4f3bd4b
Change markupsafe folder
silabs-ChatNguyen Apr 13, 2023
5c4dfcf
Add symbolic link for slc
silabs-ChatNguyen Apr 13, 2023
f387673
Update makefile
silabs-ChatNguyen Apr 14, 2023
118e698
Update makefile
silabs-ChatNguyen Apr 14, 2023
38c6005
Update MX25R3235F.toml from submodule nvm.toml
silabs-ChatNguyen Apr 17, 2023
40bc6aa
alphabetize the list
silabs-ChatNguyen Apr 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,7 @@
path = ports/broadcom/peripherals
url = https://github.com/adafruit/broadcom-peripherals.git
branch = main-build
[submodule "ports/silabs/gecko_sdk"]
path = ports/silabs/gecko_sdk
url = https://github.com/SiliconLabs/gecko_sdk.git
branch = v4.2.1
1 change: 1 addition & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def autoapi_prepare_jinja_env(jinja_env):
"ports/nrf/usb",
"ports/raspberrypi/sdk",
"ports/raspberrypi/lib",
"ports/silabs",
"ports/stm/st_driver",
"ports/stm/packages",
"ports/stm/peripherals",
Expand Down
2 changes: 1 addition & 1 deletion data/nvm.toml
1 change: 1 addition & 0 deletions docs/shared_bindings_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"mimxrt10xx",
"nrf",
"raspberrypi",
"silabs",
"stm",
]

Expand Down
220 changes: 220 additions & 0 deletions ports/silabs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# This file is part of Adafruit for EFR32 project
#
# The MIT License (MIT)
#
# Copyright 2023 Silicon Laboratories Inc. www.silabs.com
#
# 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.
#

.SUFFIXES: # ignore builtin rules
.PHONY: all clean slc-clean slc-generate dependents
# Values set by the initial generation
PROJECTNAME = circuitpython_efr32
# If the build directory is not given, make it reflect the board name.
SILABS_BUILD = build-$(BOARD)
# Build dir for CircuitPython
BUILD ?= $(SILABS_BUILD)
# Override Build Directories
OUTPUT_DIR = $(SILABS_BUILD)
# Python script to generate pins and pins functionalities code
PY_GEN_PINS_SRC ?= tools/make_pins.py
# SLC tool path
SLC_PATH = $(realpath $(CURDIR))/tools/build-tools/slc_cli

BUILD_VERBOSE ?= 1

CFLAGS = $(INCLUDES) $(C_DEFS) $(C_FLAGS) \
-Wno-expansion-to-defined \
-Wno-unused-parameter \
-Wno-missing-field-initializers \
-Wno-type-limits

ASMFLAGS = $(INCLUDES) $(ASM_DEFS) $(ASM_FLAGS) $(DEPFLAGS)

include ../../py/circuitpy_mkenv.mk

CROSS_COMPILE = arm-none-eabi-

MCU_SERIES_LOWER = $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]')
MCU_VARIANT_LOWER = $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]')

# Header files folders include
INC += -I.
INC += -I../..
INC += -I$(BUILD)
INC += -I$(BUILD)/genhdr
INC += -I$(SILABS_BUILD)/autogen
INC += -I$(SILABS_BUILD)/config
INC += -I./boards
INC += -I./peripherals
INC += -I../../lib/mp-readline

#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g3
# You may want to enable these flags to make setting breakpoints easier.
CFLAGS += -fno-inline -fno-ipa-sra -Og
else
CFLAGS += -DNDEBUG
OPTIMIZATION_FLAGS ?= -Os -fno-inline-functions
CFLAGS += -g
endif

# to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
CFLAGS += $(OPTIMIZATION_FLAGS)
CFLAGS += $(INC) $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
CFLAGS += -DEFR32_SERIES_LOWER='"$(MCU_VARIANT)"'
CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align -Wno-nested-externs -Wno-strict-prototypes

SRC_C += \
background.c \
mphalport.c \
$(SILABS_BUILD)/pins.c\

ifeq ('$(BOARD)','brd2601b')
SRC_C += boards/$(BOARD)/sensor.c
endif

SRC_S = boards/mp_efr32xg24_gchelper.s

SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
$(addprefix common-hal/, $(SRC_COMMON_HAL))

SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))

# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED,
# because a few modules have files both in common-hal/ and shared-module/.
# Doing a $(sort ...) removes duplicates as part of sorting.
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))

ifneq ($(FROZEN_MPY_DIR),)
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
endif

OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
ifeq ($(INTERNAL_LIBM),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
endif
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))

$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os

# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
# Sources that only hold QSTRs after pre-processing.
SRC_QSTR_PREPROCESSOR +=

MCU_SECTIONS = $^ $@

# Include sub-makefiles
-include $(SILABS_BUILD)/$(PROJECTNAME).project.mak

# Default goal
all: $(OUTPUT_DIR)/firmware.bin

$(OUTPUT_DIR)/firmware.bin: $(SILABS_BUILD)/$(PROJECTNAME).Makefile $(OUTPUT_DIR)/firmware.hex
+@$(MAKE) --no-print-directory $(OUTPUT_DIR)/firmware.out

$(SILABS_BUILD)/$(PROJECTNAME).Makefile:
+@$(MAKE) --no-print-directory slc-generate

$(OUTPUT_DIR)/firmware.out: $(SILABS_BUILD)/pin_functions.h $(SILABS_BUILD)/pins.c $(OBJ) $(OBJS) $(LIB_FILES)
@echo 'Linking $(OUTPUT_DIR)/firmware.out'
@echo "$(OBJS) $(OBJ)" > $(OUTPUT_DIR)/linker_objs
$(CC) $(LD_FLAGS) @$(OUTPUT_DIR)/linker_objs $(LIBS) -o $(OUTPUT_DIR)/firmware.out
$(OBJCOPY) $(OUTPUT_DIR)/firmware.out -O binary $(OUTPUT_DIR)/firmware.bin
@echo 'Done.'

$(OUTPUT_DIR)/firmware.hex:

$(SILABS_BUILD)/pin_functions.h:
$(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_GEN_PINS_SRC) -e $@ boards/$(BOARD)/pins.csv boards/$(BOARD)/pin_functions.csv
@-$(RM) pins.c

$(SILABS_BUILD)/pins.c:
$(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_GEN_PINS_SRC) -s $@ boards/$(BOARD)/pins.csv boards/$(BOARD)/pin_functions.csv
@-$(RM) pin_functions.h

slc-generate:
+@$(MAKE) -C tools all
ifeq (,$(wildcard $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/jinja2))
-@ln -s $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/site-packages/jinja2 \
$(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/jinja2
-@ln -s $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/site-packages/markupsafe \
$(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/markupsafe
endif
@echo 'SLC generates project'
@$(SLC_PATH)/slc configuration --sdk gecko_sdk
@$(SLC_PATH)/slc signature trust -extpath cp_efr32_extension
@$(SLC_PATH)/slc signature trust --sdk gecko_sdk
@$(SLC_PATH)/slc generate -name=$(PROJECTNAME) $(PROJECTNAME).slcp --sdk gecko_sdk --with $(BOARD_BRD) -tlcn gcc -d=$(SILABS_BUILD)
@sed -i 's/ autogen\// $(SILABS_BUILD)\/autogen\//g' $(SILABS_BUILD)/circuitpython_efr32.project.mak
@sed -i 's/-T"autogen\//-T"$(SILABS_BUILD)\/autogen\//g' $(SILABS_BUILD)/circuitpython_efr32.project.mak

slc-clean:
@echo 'SLC cleaning'
$(RM) -fr $(SILABS_BUILD)
$(RM) -fr ./tools/build-tools

#Override ECHO
$(OBJS): ECHO =
$(OBJS):

$(OUTPUT_DIR)/%.o: %.c
@echo 'Building $<'
@$(MKDIR_P) $(@D)
$(ECHO)$(CC) $(CFLAGS) -c -o $@ $<

$(OUTPUT_DIR)/%.o: %.cpp
@echo 'Building $<'
@$(MKDIR_P) $(@D)
$(ECHO)$(CXX) $(CXXFLAGS) -c -o $@ $<

$(OUTPUT_DIR)/%.o: %.cc
@echo 'Building $<'
@$(MKDIR_P) $(@D)
$(ECHO)$(CXX) $(CXXFLAGS) -c -o $@ $<

$(OUTPUT_DIR)/%.o: %.s
@echo 'Building $<'
@$(MKDIR_P) $(@D)
$(ECHO)$(CC) $(ASMFLAGS) -c -o $@ $<

$(OUTPUT_DIR)/%.o: %.S
@echo 'Building $<'
@$(MKDIR_P) $(@D)
$(ECHO)$(CC) $(ASMFLAGS) -c -o $@ $<

include $(TOP)/py/mkrules.mk

# Print out the value of a make variable.
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
@echo $* = $($*)
136 changes: 136 additions & 0 deletions ports/silabs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Circuitpython on EFR32 #
![GitHub](https://img.shields.io/badge/Technology-Bluetooth_BLE-green)
![GitHub](https://img.shields.io/badge/CircuitPython-8.1.0--beta.0-green)
![GitHub](https://img.shields.io/badge/GSDK-v4.2.1-green)
![GitHub](https://img.shields.io/badge/SLC-5.6.3.0-green)
![GitHub](https://img.shields.io/badge/License-MIT-green)
![GitHub](https://img.shields.io/badge/GCC_build-passing-green)

This port brings the Silicon Labs EFR32 series of MCUs to Circuitpython.

Refer to **mpconfigport.mk** for a full list of enabled modules sorted by family.

## How this port is organized: ##

- **boards/** contains the configuration files for each development board and breakout available on the port, as well as system files and both shared and SoC-specific linker files. Board configuration includes a pin mapping of the board, oscillator information, board-specific build flags, and setup for some other peripheral where applicable.
- **common-hal/** contains the port-specific module implementations, used by shared-module and shared-bindings.
- **peripherals/** contains peripheral setup files and peripheral mapping information, sorted by family and sub-variant. Most files in this directory can be generated with the python scripts in **tools/**.
- **supervisor/** contains port-specific implementations of internal flash and serial, as well as the **port.c** file, which initializes the port at startup.
- **tools/** contains Silicon Labs configurator (SLC) tool, python scripts for generating peripheral and pin mapping files in **peripherals/** and **board/**.

At the root level, refer to **mpconfigboard.h** and **mpconfigport.mk** for port specific settings and a list of enabled modules.

## Prerequisites ##
Please ensure you set up your build environment appropriately, as per the guide. You will need:

- Linux: https://learn.adafruit.com/building-circuitpython/linux
- Windows Subsystem for Linux (WSL): https://learn.adafruit.com/building-circuitpython/windows-subsystem-for-linux
- MacOS: Not supported yet

Install necessary packages

$ sudo apt install default-jre gcc-arm-none-eabi wget python3 python3-pip git gettext uncrustify
$ sudo python -m pip install --upgrade pip

## Board supported ##

| Board | Code | Build CMD |
| --------------------------- | ------------ | ------------------------------------------ |
| xG24 Dev Kit | brd2601b | devkit_xg24_brd2601b |
| xG24 Explorer Kit | brd2703a | explorerkit_xg24_brd2703a |
| Sparkfun Thing Plus MGM240P | brd2704a | sparkfun_thingplus_matter_mgm240p_brd2704a |

## Build instructions ##

Ensure your clone of Circuitpython is ready to build by following the [guide on the Adafruit Website](https://learn.adafruit.com/building-circuitpython/build-circuitpython). This includes installing the toolchain, synchronizing submodules, and running `mpy-cross`.

Clone the source code of CircuitPython from Github:

$ git clone https://github.com/SiliconLabs/circuitpython.git
$ cd circuitpython
$ make fetch-submodules

Checkout the branch or tag you want to build. For example:

$ git checkout main

Following the guideline below to install required packages for SLC tool:
https://www.silabs.com/documents/public/user-guides/ug520-software-project-generation-configuration-with-slc-cli.pdf

Once the one-time build tasks are complete, you can build at any time by navigating to the port directory:

$ make BOARD=explorerkit_xg24_brd2703a V=2

You may also build with certain flags available in the makefile, depending on your board and development goals:

$ make BOARD=explorerkit_xg24_brd2703a DEBUG=1

Clean project by using:

$ make BOARD=explorerkit_xg24_brd2703a clean

Clean project and SLC generated files:

$ make BOARD=explorerkit_xg24_brd2703a slc-clean

## Bring-up on the board ##

### Getting a REPL prompt ###

Connect the devkit to the PC via the USB cable. The board uses serial for REPL access and debugging because the EFR32 chips has no USB support.

#### Windows ####

On Windows, we need to install a serial console e.g., PuTTY, MobaXterm. The JLink CDC UART Port can be found in the Device Manager.

#### Linux ####

Open a terminal and issue the following command: 

$ ls /dev/ttyACM*

Then note down the correct name and substitute com-port-name in the following command with it: 

$ screen /dev/'com-port-name'

### Using the REPL prompt ###

After flashing the firmware to the board, at your first connecting to the board, you might see a blank screen. Press enter and you should be presented with a Circuitpython prompt, >>>. If not, try to reset the board (see instructions below).

You can now type in simple commands such as: 

```sh
>>> print("Hello world!") 

Hello world
```

If something goes wrong with the board, you can reset it. Pressing CTRL+D when the prompt is open performs a soft reset.

### Recommended editors ###

**Thonny** is a simple code editor that works with the Adafruit CircuitPython boards. 

Config serial: Tools > Options > Interpreter > Select MicroPython > Select Port Jlink CDC UART Port

### Running CircuitPython scripts ###

At the boot stage, two scripts will be run (if not booting in safe mode). First, the file  boot.py  will be executed. The file **boot.py** can be used to perform the initial setup. Then, after boot.py has been completed, the file **code.py** will be executed.  

After code.py has finished executing, a REPL prompt will be presented on the serial port. Other files can also be executed by using the **Thonny** editors or using **Ampy** tool.

![Thony](./res/Thony.png)

With the boards which support USB mass storage, we can drag the files to the board file system. However, because the EFR32 boards don’t support USB mass storage, we need to use a tool like **Ampy** to copy the file to the board. You can use the latest version of **Ampy** and its  command to copy the module directories to the board.

Refer to the guideline below for installing the **Ampy** tool: 

https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy  

## Modules supported ##

| Board | Modules Available|
| --------------------------- | ---------------- |
| xG24 Dev Kit | _asyncio, _bleio, _pixelmap, adafruit_ble, adafruit_bus_device, adafruit_pixelbuf, adafruit_register, aesio,analogio, array, atexit, binascii, bitmaptools, board, builtins, busio, collections, digitalio, displayio,errno, fontio, framebufferio, gc, getpass, gifio, json, math, microcontroller, micropython, msgpack, nvm, onewireio, os, pwmio, rainbowio, random, re, rtc, select, sharpdisplay, storage, struct, supervisor, sys, terminalio, time, traceback, ulab, uselect, vectorio, watchdog, zlib |
| xG24 Explorer Kit | _asyncio, _bleio, _pixelmap, adafruit_ble, adafruit_bus_device, adafruit_pixelbuf, adafruit_register, aesio,analogio, array, atexit, binascii, bitmaptools, board, builtins, busio, collections, digitalio, displayio,errno, fontio, framebufferio, gc, getpass, gifio, json, math, microcontroller, micropython, msgpack, nvm, onewireio, os, pwmio, rainbowio, random, re, rtc, sdcardio, select, sharpdisplay, storage, struct, supervisor, sys, terminalio, time, traceback, ulab, uselect, vectorio, watchdog, zlib |
| Sparkfun Thing Plus MGM240P | _asyncio, _bleio, _pixelmap, adafruit_ble, adafruit_bus_device, adafruit_pixelbuf, adafruit_register, aesio,analogio, array, atexit, binascii, bitmaptools, board, builtins, busio, collections, digitalio, displayio,errno, fontio, framebufferio, gc, getpass, gifio, json, math, microcontroller, micropython, msgpack, nvm, onewireio, os, pwmio, rainbowio, random, re, rtc, sdcardio, select, sharpdisplay, storage, struct, supervisor, sys, terminalio, time, traceback, ulab, uselect, vectorio, watchdog, zlib |
Loading