Skip to content

Commit 22ab167

Browse files
committed
psoc6: Added new port for Infineon PSOC6 MCUs.
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
1 parent 78ff170 commit 22ab167

63 files changed

Lines changed: 11999 additions & 0 deletions

Some content is hidden

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

ports/psoc6/Makefile

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
MTB_LIBS_DIR = ../../lib/mtb-psoc6-libs
2+
include mpconfigport.mk
3+
-include $(MTB_LIBS_DIR)/mtb-bsp-setup.mk
4+
5+
# The only target allowed to run without BOARD defined is 'submodules' or 'help'
6+
ifeq ($(BOARD),)
7+
ifneq ($(filter $(MAKECMDGOALS),submodules help),$(MAKECMDGOALS))
8+
$(error No active board is set. Run "make BOARD=<target-board>" to initialize the ModusToolbox libraries and set the active board. )
9+
endif
10+
endif
11+
12+
BUILD ?= build-$(BOARD)
13+
14+
# Files that are generated and needed before the QSTR build.
15+
QSTR_GENERATED_HEADERS =$(BUILD)/pins_qstr.h
16+
# qstr definitions (must come before including py.mk)
17+
QSTR_DEFS = qstrdefsport.h $(QSTR_GENERATED_HEADERS)
18+
QSTR_GLOBAL_DEPENDENCIES += $(BOARD_DIR)/mpconfigboard.h $(QSTR_GENERATED_HEADERS)
19+
20+
MICROPY_FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py
21+
FROZEN_MANIFEST = $(MICROPY_FROZEN_MANIFEST)
22+
23+
ifneq ($(FROZEN_MANIFEST),)
24+
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
25+
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY=1
26+
CFLAGS += -DMICROPY_MODULE_FROZEN_STR=1
27+
endif
28+
29+
30+
CROSS_COMPILE ?= arm-none-eabi-
31+
CONFIG ?= Debug
32+
33+
# include py core make definitions
34+
include ../../py/mkenv.mk
35+
-include $(BOARD_DIR)/mpconfigboard.mk
36+
include $(TOP)/py/py.mk
37+
include $(TOP)/extmod/extmod.mk
38+
39+
GIT_SUBMODULES += lib/mtb-psoc6-libs lib/mpy-test-ext
40+
41+
INC += -I.
42+
INC += -I$(TOP)
43+
INC += -I$(BUILD)
44+
45+
ifeq ($(MICROPY_PSOC6_LWIP),1)
46+
INC += -Ilwip_inc
47+
endif
48+
49+
LD = arm-none-eabi-gcc
50+
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -fsingle-precision-constant -Wdouble-promotion -Wfloat-conversion -UMICROPY_USE_INTERNAL_PRINTF -Wno-error=float-conversion
51+
52+
# std=c11 instead of std=c99 : provides "static_assert" (not available in c99)
53+
# -D_XOPEN_SOURCE=700 : makes sure the setenv/unsetenv headers are included
54+
CFLAGS += $(INC) -Wall -Werror -std=c11 $(CFLAGS_CORTEX_M4) $(COPT) -D_XOPEN_SOURCE=700
55+
CFLAGS += -Wno-error=double-promotion -Wno-error=overflow -Wno-error=analyzer-null-dereference -Wno-error=unused-local-typedefs -Wno-error=unused-function -Wno-error=maybe-uninitialized
56+
57+
ifeq ($(MICROPY_PSOC6_SSL_MBEDTLS),1)
58+
INC += -I$(TOP)/extmod/mbedtls
59+
CFLAGS += -DMBEDTLS_CONFIG_FILE=\"mbedtls/mbedtls_config.h\"
60+
CFLAGS += -DMICROPY_SSL_MBEDTLS=1
61+
endif
62+
63+
LDFLAGS += -Wl,--cref -Wl,--gc-sections
64+
LDFLAGS += -Wl,-Map,$(BUILD)/firmware.map -Wl,--start-group -Wl,--end-group -Wl,--print-memory-usage
65+
66+
67+
# Tune for Debugging or Optimization
68+
ifeq ($(CONFIG), Debug)
69+
CFLAGS += -O0 -ggdb
70+
MPY_MTB_CONFIG = Debug
71+
MICROPY_ROM_TEXT_COMPRESSION ?= 0
72+
else
73+
CFLAGS += -O3 -Os -DNDEBUG
74+
CFLAGS += -fdata-sections -ffunction-sections
75+
MPY_MTB_CONFIG = Release
76+
MICROPY_ROM_TEXT_COMPRESSION ?= 1
77+
endif
78+
79+
$(info Compiling in $(CONFIG) mode !)
80+
81+
#ToDo: Post adding af functionality, refactor to minimize dependent variables in py script if possible
82+
GEN_PINS_SRC := $(BUILD)/pins_$(BOARD).c
83+
HEADER_BUILD := $(BUILD)/genhdr
84+
GEN_PINS_HDR := $(BUILD)/genhdr/pins.h
85+
GEN_PINS_QSTR := $(BUILD)/pins_qstr.h
86+
87+
GENERATED_PINS = $(GEN_PINS_SRC) $(GEN_PINS_HDR) $(GEN_PINS_QSTR)
88+
89+
$(GENERATED_PINS):
90+
@echo "Generating $@"
91+
$(MKDIR) -p $(BUILD)/genhdr
92+
$(PYTHON) boards/make-pins.py --gen-pin-for $(PIN_PACKAGE_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC)
93+
94+
# Flags for optional C++ source code
95+
CXXFLAGS += $(filter-out -std=c99,$(CFLAGS))
96+
CXXFLAGS += $(CXXFLAGS_MOD)
97+
98+
LDFLAGS += $(LDFLAGS_MOD)
99+
100+
LIBS +=
101+
102+
SHARED_SRC_C += $(addprefix shared/,\
103+
readline/readline.c \
104+
\
105+
runtime/gchelper_native.c \
106+
runtime/interrupt_char.c \
107+
runtime/pyexec.c \
108+
runtime/mpirq.c\
109+
runtime/stdout_helpers.c \
110+
runtime/sys_stdio_mphal.c \
111+
timeutils/timeutils.c \
112+
)
113+
114+
ifeq ($(MICROPY_PSOC6_LWIP),1)
115+
SHARED_SRC_C += $(addprefix shared/,\
116+
netutils/dhcpserver.c \
117+
netutils/netutils.c \
118+
netutils/trace.c \
119+
)
120+
MOD_SRC_C += modsocket.c
121+
endif
122+
123+
DRIVERS_SRC_C += $(addprefix drivers/,\
124+
bus/softspi.c \
125+
)
126+
127+
MOD_SRC_C += \
128+
modgc.c \
129+
\
130+
machine_i2c.c \
131+
machine_pin_phy.c \
132+
machine_pin.c \
133+
machine_rtc.c \
134+
machine_spi.c \
135+
machine_timer.c \
136+
machine_adc.c \
137+
machine_adcblock.c \
138+
machine_bitstream.c\
139+
machine_pdm_pcm.c\
140+
\
141+
modpsoc6.c \
142+
psoc6_fatfs.c \
143+
psoc6_flash.c
144+
145+
ifeq ($(MICROPY_PY_EXT_FLASH),1)
146+
CFLAGS += -DMICROPY_ENABLE_EXT_QSPI_FLASH=1
147+
MOD_SRC_C += psoc6_qspi_flash.c
148+
endif
149+
150+
ifeq ($(MICROPY_PY_SD_CARD),1)
151+
CFLAGS += -DMICROPY_ENABLE_SD_CARD=1
152+
MOD_SRC_C += machine_sdcard.c
153+
endif
154+
155+
ifeq ($(MICROPY_PY_NETWORK_IFX_WCM),1)
156+
CFLAGS += -DMICROPY_PY_NETWORK=1 -DMICROPY_PY_NETWORK_IFX_WCM=1 -Wno-stringop-truncation
157+
MOD_SRC_C += network_ifx_wcm.c
158+
endif
159+
160+
SRC_C = help.c \
161+
main.c \
162+
mphalport.c \
163+
frozen_content.c \
164+
pins_$(BOARD).c
165+
166+
SRC_ASM += shared/runtime/gchelper_thumb1.s
167+
168+
SRC_QSTR += $(SHARED_SRC_C) $(MOD_SRC_C)
169+
170+
OBJ += $(PY_O)
171+
OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o))
172+
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
173+
OBJ += $(addprefix $(BUILD)/, $(MOD_SRC_C:.c=.o))
174+
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
175+
OBJ += $(addprefix $(BUILD)/, $(SRC_ASM:.s=.o))
176+
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
177+
178+
# switch for debug mode, also added to mpconfigport.h
179+
# TODO: keep the more suitable one, delete the other
180+
MP_LOGGER_DEBUG ?= 0
181+
182+
ifeq ($(MP_LOGGER_DEBUG), 1)
183+
CFLAGS += -DMICROPY_LOGGER_DEBUG=1
184+
endif
185+
186+
-include $(TOP)/lib/mtb-psoc6-libs/mtb-makefile.mk
187+
188+
$(BUILD)/firmware.elf: $(OBJ) $(LIBS)
189+
$(info Linking $@ $^ $(LIBS) ...)
190+
$(Q) $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
191+
$(info Linking $@ done.)
192+
$(Q) $(SIZE) $@ -A
193+
$(info )
194+
195+
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
196+
$(Q) $(OBJCOPY) -O ihex $^ $@
197+
198+
mpy_build: $(BUILD)/firmware.hex
199+
200+
MPY_CROSS_FLAGS += -march=armv7m
201+
202+
all: mtb_init mtb_get_build_flags mpy_build
203+
204+
clean: mtb_clean
205+
206+
rebuild: clean all
207+
208+
qdeploy: mtb_program
209+
deploy: all mtb_program
210+
211+
# When multiple types of boards are connected, a devs file needs to be provided.
212+
# When working locally, if a "local-devs.yml" file is placed in "tools/psoc6"
213+
# it will be used
214+
ifneq ($(DEVS_FILE),)
215+
MULTI_BOARD_DEVS_OPTS = -f name=$(BOARD) --devs-yml $(DEVS_FILE)
216+
else
217+
DFLT_LOCAL_DEVS_FILE_NAME = local-devs.yml
218+
LOCAL_DEVS_FILE=$(TOP)/tools/psoc6/$(DFLT_LOCAL_DEVS_FILE_NAME)
219+
ifneq (,$(wildcard $(LOCAL_DEVS_FILE)))
220+
MULTI_BOARD_DEVS_OPTS = -f name=$(BOARD) --devs-yml $(LOCAL_DEVS_FILE)
221+
endif
222+
endif
223+
224+
attached_devs:
225+
@:
226+
$(eval ATTACHED_TARGET_LIST = $(shell etdevs-query serial_number $(MULTI_BOARD_DEVS_OPTS)))
227+
$(eval ATTACHED_TARGETS_NUMBER = $(words $(ATTACHED_TARGET_LIST)))
228+
$(info Number of attached targets : $(ATTACHED_TARGETS_NUMBER))
229+
$(info List of attached targets : $(ATTACHED_TARGET_LIST))
230+
231+
qdeploy_multi: attached_devs
232+
$(foreach ATTACHED_TARGET, $(ATTACHED_TARGET_LIST), $(MAKE) qdeploy DEV_SERIAL_NUMBER=$(ATTACHED_TARGET);)
233+
234+
deploy_multi: all qdeploy_multi
235+
236+
TESTS ?=-d psoc6
237+
DEV0 ?= /dev/ttyACM0
238+
DEV1 ?= /dev/ttyACM1
239+
240+
test:
241+
@:
242+
$(info )
243+
$(info Running PSoC6 tests)
244+
$(Q) cd ../../tests ; ./run-tests.py --target psoc6 --device $(DEV0) $(TESTS)
245+
246+
MULTI_TESTS ?= $(shell cd ../../tests; find ./psoc6/multi/ -type f -name "*.py")
247+
248+
test_multi:
249+
@:
250+
$(info )
251+
$(info Running PSoC6 multi tests)
252+
253+
$(Q) cd ../../tests ; ./run-multitests.py -i pyb:$(DEV0) -i pyb:$(DEV1) $(MULTI_TESTS)
254+
255+
port_help:
256+
@:
257+
$(info )
258+
$(info Available commands:)
259+
$(info )
260+
$(info make submodules Initialize port required submodules.)
261+
$(info make BOARD=<board_name> Build the project for the specified board.)
262+
$(info .. The board name needs to be specified only the first time.)
263+
$(info .. Then simply run "make" to build for the same board.)
264+
$(info make rebuild Build the project after cleaning previous build.)
265+
$(info make deploy Build and deploy the project to the specified board.)
266+
$(info make qdeploy Deploy the project to the specified board without rebuilding.)
267+
$(info make deploy_multi Deploy the project to multiple boards.)
268+
$(info make qdeploy_multi Deploy the project to multiple boards without rebuilding.)
269+
$(info make clean Clean the build files.)
270+
$(info make test Run the on-target test in tests/psoc6 folder. Uses /dev/ttyACM0.)
271+
$(info .. Optionally, pass TESTS variable for change the tests set. )
272+
$(info make test_multi Run multi-instance tests on-target test in tests/psoc6/multi folder.)
273+
$(info .. Uses /dev/ttyACM0 and /dev/ttyACM1.)
274+
$(info .. Optionally, pass MULTI_TESTS variable for change the tests set. )
275+
$(info make help Show this help.)
276+
$(info )
277+
$(info Options: )
278+
$(info EXT_HEX_FILE An external .hex file can be provided to the deploy targets, instead of building from the sources.)
279+
$(info )
280+
281+
help: port_help mtb_bsp_help mtb_build_help
282+
.DEFAULT_GOAL := all
283+
284+
.PHONY: all clean rebuild deploy qdeploy deploy_multi qdeploy_multi test test_multi help
285+
286+
# include py core make definitions
287+
include $(TOP)/py/mkrules.mk

ports/psoc6/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# PSoC6 port
2+
3+
This port is intended to run on Infineon PSoC™ 6 microcontrollers.
4+
5+
## Pre-requisites
6+
7+
The following port is using Infineon ModusToolbox™ to resolve the specific PSoC™ board resources and building flags. Before working with micropython:
8+
9+
1. Install [ModusToolbox](https://softwaretools.infineon.com/tools/com.ifx.tb.tool.modustoolbox). **The required version is 3.0**. The version is currently fixed as some future versions are incompatible.
10+
11+
2. Run the following script from MicroPython repository root to add the required tools to the system PATH, and install the udev rules:
12+
13+
source tools/psoc6/dev-setup.sh && toolchain_setup
14+
15+
If the ModusToolbox™ has not been installed in the default path (`~/ModusToolbox`), add the path as positional argument of the `toolchain_setup` function:
16+
17+
source tools/psoc6/dev-setup.sh && toolchain_setup [mtb_path]
18+
19+
### MacOS
20+
21+
> [!NOTE]
22+
> If you are using MacOS, you need to install GNU make. The default make on Mac OS is BSD make, which is not compatible with the Makefile used in this port. Remember to add GNU make to the system path PATH.
23+
24+
## Building and running Linux version
25+
26+
As we are working on the ports-psoc6-main branch (for now), first checkout that branch after cloning this repo:
27+
28+
git checkout --track origin/ports-psoc6-main
29+
30+
Retrieve submodules:
31+
32+
make submodules
33+
34+
Build the firmware:
35+
36+
make BOARD=CY8CKIT_062S2_AI
37+
38+
> [!NOTE]
39+
> The first time we call `make` the board needs to be specified with
40+
> `BOARD=<board>`. This is required as the ModusToolbox libraries need to be
41+
> initialized for the selected board.
42+
> This board will then be set as the default board for subsequent builds, you
43+
> can just call `make` without the `BOARD=` argument.
44+
45+
And flash it to the board:
46+
47+
make deploy
48+
49+
> [!NOTE]
50+
> This will also build the firmware if it has not been built yet.
51+
> Use `deploy` target to avoid rebuilding the firmware.
52+
53+
Find more information about the available makefile targets:
54+
55+
make help
56+
57+
# Run micropython
58+
59+
Use any serial terminal (putty, minicom..) and establish a session with your device with 115200 bauds and 8-N-1 configuration.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"asset-name": "cat1cm0p",
4+
"locked-commit": "release-v1.7.0"
5+
},
6+
{
7+
"asset-name": "cmsis",
8+
"locked-commit": "release-v5.8.1"
9+
},
10+
{
11+
"asset-name": "core-lib",
12+
"locked-commit": "release-v1.4.2"
13+
},
14+
{
15+
"asset-name": "core-make",
16+
"locked-commit": "release-v3.3.1"
17+
},
18+
{
19+
"asset-name": "device-db",
20+
"locked-commit": "release-v4.18.0"
21+
},
22+
{
23+
"asset-name": "mtb-hal-cat1",
24+
"locked-commit": "release-v2.6.1"
25+
},
26+
{
27+
"asset-name": "mtb-pdl-cat1",
28+
"locked-commit": "release-v3.12.0"
29+
},
30+
{
31+
"asset-name": "recipe-make-cat1a",
32+
"locked-commit": "release-v2.2.1"
33+
}
34+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
freeze("$(PORT_DIR)/freeze")
2+
include("$(MPY_DIR)/extmod/asyncio")
3+
require("bundle-networking")

0 commit comments

Comments
 (0)