Skip to content

Commit 1669c56

Browse files
authored
Merge pull request #7833 from SiliconLabs/main
Silabs xG24 devkits ports
2 parents 3cd6dff + 40bc6aa commit 1669c56

File tree

118 files changed

+9255
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+9255
-1
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,7 @@
324324
path = ports/broadcom/peripherals
325325
url = https://github.com/adafruit/broadcom-peripherals.git
326326
branch = main-build
327+
[submodule "ports/silabs/gecko_sdk"]
328+
path = ports/silabs/gecko_sdk
329+
url = https://github.com/SiliconLabs/gecko_sdk.git
330+
branch = v4.2.1

conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def autoapi_prepare_jinja_env(jinja_env):
216216
"ports/nrf/usb",
217217
"ports/raspberrypi/sdk",
218218
"ports/raspberrypi/lib",
219+
"ports/silabs",
219220
"ports/stm/st_driver",
220221
"ports/stm/packages",
221222
"ports/stm/peripherals",

data/nvm.toml

docs/shared_bindings_matrix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"mimxrt10xx",
4141
"nrf",
4242
"raspberrypi",
43+
"silabs",
4344
"stm",
4445
]
4546

ports/silabs/Makefile

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# This file is part of Adafruit for EFR32 project
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright 2023 Silicon Laboratories Inc. www.silabs.com
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
#
25+
26+
.SUFFIXES: # ignore builtin rules
27+
.PHONY: all clean slc-clean slc-generate dependents
28+
# Values set by the initial generation
29+
PROJECTNAME = circuitpython_efr32
30+
# If the build directory is not given, make it reflect the board name.
31+
SILABS_BUILD = build-$(BOARD)
32+
# Build dir for CircuitPython
33+
BUILD ?= $(SILABS_BUILD)
34+
# Override Build Directories
35+
OUTPUT_DIR = $(SILABS_BUILD)
36+
# Python script to generate pins and pins functionalities code
37+
PY_GEN_PINS_SRC ?= tools/make_pins.py
38+
# SLC tool path
39+
SLC_PATH = $(realpath $(CURDIR))/tools/build-tools/slc_cli
40+
41+
BUILD_VERBOSE ?= 1
42+
43+
CFLAGS = $(INCLUDES) $(C_DEFS) $(C_FLAGS) \
44+
-Wno-expansion-to-defined \
45+
-Wno-unused-parameter \
46+
-Wno-missing-field-initializers \
47+
-Wno-type-limits
48+
49+
ASMFLAGS = $(INCLUDES) $(ASM_DEFS) $(ASM_FLAGS) $(DEPFLAGS)
50+
51+
include ../../py/circuitpy_mkenv.mk
52+
53+
CROSS_COMPILE = arm-none-eabi-
54+
55+
MCU_SERIES_LOWER = $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]')
56+
MCU_VARIANT_LOWER = $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]')
57+
58+
# Header files folders include
59+
INC += -I.
60+
INC += -I../..
61+
INC += -I$(BUILD)
62+
INC += -I$(BUILD)/genhdr
63+
INC += -I$(SILABS_BUILD)/autogen
64+
INC += -I$(SILABS_BUILD)/config
65+
INC += -I./boards
66+
INC += -I./peripherals
67+
INC += -I../../lib/mp-readline
68+
69+
#Debugging/Optimization
70+
ifeq ($(DEBUG), 1)
71+
CFLAGS += -g3
72+
# You may want to enable these flags to make setting breakpoints easier.
73+
CFLAGS += -fno-inline -fno-ipa-sra -Og
74+
else
75+
CFLAGS += -DNDEBUG
76+
OPTIMIZATION_FLAGS ?= -Os -fno-inline-functions
77+
CFLAGS += -g
78+
endif
79+
80+
# to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
81+
CFLAGS += $(OPTIMIZATION_FLAGS)
82+
CFLAGS += $(INC) $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
83+
CFLAGS += -DEFR32_SERIES_LOWER='"$(MCU_VARIANT)"'
84+
CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align -Wno-nested-externs -Wno-strict-prototypes
85+
86+
SRC_C += \
87+
background.c \
88+
mphalport.c \
89+
$(SILABS_BUILD)/pins.c\
90+
91+
ifeq ('$(BOARD)','brd2601b')
92+
SRC_C += boards/$(BOARD)/sensor.c
93+
endif
94+
95+
SRC_S = boards/mp_efr32xg24_gchelper.s
96+
97+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
98+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
99+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
100+
101+
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
102+
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
103+
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
104+
105+
# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED,
106+
# because a few modules have files both in common-hal/ and shared-module/.
107+
# Doing a $(sort ...) removes duplicates as part of sorting.
108+
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))
109+
110+
ifneq ($(FROZEN_MPY_DIR),)
111+
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
112+
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
113+
endif
114+
115+
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
116+
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
117+
ifeq ($(INTERNAL_LIBM),1)
118+
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
119+
endif
120+
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
121+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
122+
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
123+
124+
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
125+
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
126+
127+
# List of sources for qstr extraction
128+
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
129+
# Sources that only hold QSTRs after pre-processing.
130+
SRC_QSTR_PREPROCESSOR +=
131+
132+
MCU_SECTIONS = $^ $@
133+
134+
# Include sub-makefiles
135+
-include $(SILABS_BUILD)/$(PROJECTNAME).project.mak
136+
137+
# Default goal
138+
all: $(OUTPUT_DIR)/firmware.bin
139+
140+
$(OUTPUT_DIR)/firmware.bin: $(SILABS_BUILD)/$(PROJECTNAME).Makefile $(OUTPUT_DIR)/firmware.hex
141+
+@$(MAKE) --no-print-directory $(OUTPUT_DIR)/firmware.out
142+
143+
$(SILABS_BUILD)/$(PROJECTNAME).Makefile:
144+
+@$(MAKE) --no-print-directory slc-generate
145+
146+
$(OUTPUT_DIR)/firmware.out: $(SILABS_BUILD)/pin_functions.h $(SILABS_BUILD)/pins.c $(OBJ) $(OBJS) $(LIB_FILES)
147+
@echo 'Linking $(OUTPUT_DIR)/firmware.out'
148+
@echo "$(OBJS) $(OBJ)" > $(OUTPUT_DIR)/linker_objs
149+
$(CC) $(LD_FLAGS) @$(OUTPUT_DIR)/linker_objs $(LIBS) -o $(OUTPUT_DIR)/firmware.out
150+
$(OBJCOPY) $(OUTPUT_DIR)/firmware.out -O binary $(OUTPUT_DIR)/firmware.bin
151+
@echo 'Done.'
152+
153+
$(OUTPUT_DIR)/firmware.hex:
154+
155+
$(SILABS_BUILD)/pin_functions.h:
156+
$(STEPECHO) "GEN $@"
157+
$(Q)$(PYTHON) $(PY_GEN_PINS_SRC) -e $@ boards/$(BOARD)/pins.csv boards/$(BOARD)/pin_functions.csv
158+
@-$(RM) pins.c
159+
160+
$(SILABS_BUILD)/pins.c:
161+
$(STEPECHO) "GEN $@"
162+
$(Q)$(PYTHON) $(PY_GEN_PINS_SRC) -s $@ boards/$(BOARD)/pins.csv boards/$(BOARD)/pin_functions.csv
163+
@-$(RM) pin_functions.h
164+
165+
slc-generate:
166+
+@$(MAKE) -C tools all
167+
ifeq (,$(wildcard $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/jinja2))
168+
-@ln -s $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/site-packages/jinja2 \
169+
$(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/jinja2
170+
-@ln -s $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/site-packages/markupsafe \
171+
$(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/markupsafe
172+
endif
173+
@echo 'SLC generates project'
174+
@$(SLC_PATH)/slc configuration --sdk gecko_sdk
175+
@$(SLC_PATH)/slc signature trust -extpath cp_efr32_extension
176+
@$(SLC_PATH)/slc signature trust --sdk gecko_sdk
177+
@$(SLC_PATH)/slc generate -name=$(PROJECTNAME) $(PROJECTNAME).slcp --sdk gecko_sdk --with $(BOARD_BRD) -tlcn gcc -d=$(SILABS_BUILD)
178+
@sed -i 's/ autogen\// $(SILABS_BUILD)\/autogen\//g' $(SILABS_BUILD)/circuitpython_efr32.project.mak
179+
@sed -i 's/-T"autogen\//-T"$(SILABS_BUILD)\/autogen\//g' $(SILABS_BUILD)/circuitpython_efr32.project.mak
180+
181+
slc-clean:
182+
@echo 'SLC cleaning'
183+
$(RM) -fr $(SILABS_BUILD)
184+
$(RM) -fr ./tools/build-tools
185+
186+
#Override ECHO
187+
$(OBJS): ECHO =
188+
$(OBJS):
189+
190+
$(OUTPUT_DIR)/%.o: %.c
191+
@echo 'Building $<'
192+
@$(MKDIR_P) $(@D)
193+
$(ECHO)$(CC) $(CFLAGS) -c -o $@ $<
194+
195+
$(OUTPUT_DIR)/%.o: %.cpp
196+
@echo 'Building $<'
197+
@$(MKDIR_P) $(@D)
198+
$(ECHO)$(CXX) $(CXXFLAGS) -c -o $@ $<
199+
200+
$(OUTPUT_DIR)/%.o: %.cc
201+
@echo 'Building $<'
202+
@$(MKDIR_P) $(@D)
203+
$(ECHO)$(CXX) $(CXXFLAGS) -c -o $@ $<
204+
205+
$(OUTPUT_DIR)/%.o: %.s
206+
@echo 'Building $<'
207+
@$(MKDIR_P) $(@D)
208+
$(ECHO)$(CC) $(ASMFLAGS) -c -o $@ $<
209+
210+
$(OUTPUT_DIR)/%.o: %.S
211+
@echo 'Building $<'
212+
@$(MKDIR_P) $(@D)
213+
$(ECHO)$(CC) $(ASMFLAGS) -c -o $@ $<
214+
215+
include $(TOP)/py/mkrules.mk
216+
217+
# Print out the value of a make variable.
218+
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
219+
print-%:
220+
@echo $* = $($*)

ports/silabs/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Circuitpython on EFR32 #
2+
![GitHub](https://img.shields.io/badge/Technology-Bluetooth_BLE-green)
3+
![GitHub](https://img.shields.io/badge/CircuitPython-8.1.0--beta.0-green)
4+
![GitHub](https://img.shields.io/badge/GSDK-v4.2.1-green)
5+
![GitHub](https://img.shields.io/badge/SLC-5.6.3.0-green)
6+
![GitHub](https://img.shields.io/badge/License-MIT-green)
7+
![GitHub](https://img.shields.io/badge/GCC_build-passing-green)
8+
9+
This port brings the Silicon Labs EFR32 series of MCUs to Circuitpython.
10+
11+
Refer to **mpconfigport.mk** for a full list of enabled modules sorted by family.
12+
13+
## How this port is organized: ##
14+
15+
- **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.
16+
- **common-hal/** contains the port-specific module implementations, used by shared-module and shared-bindings.
17+
- **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/**.
18+
- **supervisor/** contains port-specific implementations of internal flash and serial, as well as the **port.c** file, which initializes the port at startup.
19+
- **tools/** contains Silicon Labs configurator (SLC) tool, python scripts for generating peripheral and pin mapping files in **peripherals/** and **board/**.
20+
21+
At the root level, refer to **mpconfigboard.h** and **mpconfigport.mk** for port specific settings and a list of enabled modules.
22+
23+
## Prerequisites ##
24+
Please ensure you set up your build environment appropriately, as per the guide. You will need:
25+
26+
- Linux: https://learn.adafruit.com/building-circuitpython/linux
27+
- Windows Subsystem for Linux (WSL): https://learn.adafruit.com/building-circuitpython/windows-subsystem-for-linux
28+
- MacOS: Not supported yet
29+
30+
Install necessary packages
31+
32+
$ sudo apt install default-jre gcc-arm-none-eabi wget python3 python3-pip git gettext uncrustify
33+
$ sudo python -m pip install --upgrade pip
34+
35+
## Board supported ##
36+
37+
| Board | Code | Build CMD |
38+
| --------------------------- | ------------ | ------------------------------------------ |
39+
| xG24 Dev Kit | brd2601b | devkit_xg24_brd2601b |
40+
| xG24 Explorer Kit | brd2703a | explorerkit_xg24_brd2703a |
41+
| Sparkfun Thing Plus MGM240P | brd2704a | sparkfun_thingplus_matter_mgm240p_brd2704a |
42+
43+
## Build instructions ##
44+
45+
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`.
46+
47+
Clone the source code of CircuitPython from Github:
48+
49+
$ git clone https://github.com/SiliconLabs/circuitpython.git
50+
$ cd circuitpython
51+
$ make fetch-submodules
52+
53+
Checkout the branch or tag you want to build. For example:
54+
55+
$ git checkout main
56+
57+
Following the guideline below to install required packages for SLC tool:
58+
https://www.silabs.com/documents/public/user-guides/ug520-software-project-generation-configuration-with-slc-cli.pdf
59+
60+
Once the one-time build tasks are complete, you can build at any time by navigating to the port directory:
61+
62+
$ make BOARD=explorerkit_xg24_brd2703a V=2
63+
64+
You may also build with certain flags available in the makefile, depending on your board and development goals:
65+
66+
$ make BOARD=explorerkit_xg24_brd2703a DEBUG=1
67+
68+
Clean project by using:
69+
70+
$ make BOARD=explorerkit_xg24_brd2703a clean
71+
72+
Clean project and SLC generated files:
73+
74+
$ make BOARD=explorerkit_xg24_brd2703a slc-clean
75+
76+
## Bring-up on the board ##
77+
78+
### Getting a REPL prompt ###
79+
80+
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.
81+
82+
#### Windows ####
83+
84+
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.
85+
86+
#### Linux ####
87+
88+
Open a terminal and issue the following command: 
89+
90+
$ ls /dev/ttyACM*
91+
92+
Then note down the correct name and substitute com-port-name in the following command with it: 
93+
94+
$ screen /dev/'com-port-name'
95+
96+
### Using the REPL prompt ###
97+
98+
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).
99+
100+
You can now type in simple commands such as: 
101+
102+
```sh
103+
>>> print("Hello world!") 
104+
105+
Hello world
106+
```
107+
108+
If something goes wrong with the board, you can reset it. Pressing CTRL+D when the prompt is open performs a soft reset.
109+
110+
### Recommended editors ###
111+
112+
**Thonny** is a simple code editor that works with the Adafruit CircuitPython boards. 
113+
114+
Config serial: Tools > Options > Interpreter > Select MicroPython > Select Port Jlink CDC UART Port
115+
116+
### Running CircuitPython scripts ###
117+
118+
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.  
119+
120+
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.
121+
122+
![Thony](./res/Thony.png)
123+
124+
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.
125+
126+
Refer to the guideline below for installing the **Ampy** tool: 
127+
128+
https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy
129+
130+
## Modules supported ##
131+
132+
| Board | Modules Available|
133+
| --------------------------- | ---------------- |
134+
| 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 |
135+
| 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 |
136+
| 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 |

0 commit comments

Comments
 (0)