circuitpython/ports/esp32s2/Makefile

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

344 lines
14 KiB
Makefile
Raw Normal View History

# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
2020-06-03 18:40:05 -04:00
# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
#
# 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.
# Select the board to build for.
ifeq ($(BOARD),)
$(error You must provide a BOARD parameter)
else
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif
endif
# If the flash PORT is not given, use the default /dev/tty.SLAB_USBtoUART.
PORT ?= /dev/tty.SLAB_USBtoUART
# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)
include ../../py/mkenv.mk
# Board-specific
include boards/$(BOARD)/mpconfigboard.mk
# Port-specific
include mpconfigport.mk
# CircuitPython-specific
include $(TOP)/py/circuitpy_mpconfig.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
# include py core make definitions
include $(TOP)/py/py.mk
include $(TOP)/supervisor/supervisor.mk
# Include make rules and variables common across CircuitPython builds.
include $(TOP)/py/circuitpy_defns.mk
CROSS_COMPILE = xtensa-esp32s2-elf-
#######################################
# CFLAGS
#######################################
INC += -I.
INC += -I../..
INC += -I$(BUILD)
INC += -I$(BUILD)/genhdr
INC += -I./boards
INC += -I./boards/$(BOARD)
INC += -I./peripherals
INC += -I../../lib/mp-readline
INC += -I../../lib/tinyusb/src
INC += -I../../supervisor/shared/usb
2020-09-28 18:59:29 -04:00
INC += -isystem esp-idf
INC += -isystem esp-idf/components/driver/include
2020-09-28 12:11:08 -04:00
INC += -isystem esp-idf/components/freertos/include/freertos
INC += -isystem esp-idf/components/freertos/xtensa/include
INC += -isystem esp-idf/components/esp32s2/include
INC += -isystem esp-idf/components/xtensa/esp32s2/include
INC += -isystem esp-idf/components/esp_common/include
INC += -isystem esp-idf/components/esp_event/include
INC += -isystem esp-idf/components/esp_netif/include
INC += -isystem esp-idf/components/esp_ringbuf/include
INC += -isystem esp-idf/components/esp_rom/include
INC += -isystem esp-idf/components/esp_wifi/include
INC += -isystem esp-idf/components/xtensa/include
INC += -isystem esp-idf/components/esp_timer/include
INC += -isystem esp-idf/components/mbedtls/mbedtls/include
INC += -isystem esp-idf/components/mbedtls/port/include/
INC += -isystem esp-idf/components/newlib/platform_include
INC += -isystem esp-idf/components/lwip/lwip/src/include
INC += -isystem esp-idf/components/lwip/port/esp32/include
INC += -isystem esp-idf/components/lwip/include/apps/sntp
2020-09-28 18:59:29 -04:00
INC += -isystem esp-idf/components/hal/include
2020-10-01 13:19:54 -04:00
INC += -isystem esp-idf/components/hal/esp32s2/include
INC += -isystem esp-idf/components/log/include/
2020-10-01 17:14:12 -04:00
INC += -isystem esp-idf/components/driver/esp32s2/include
2020-09-28 12:11:08 -04:00
INC += -isystem esp-idf/components/soc/include
INC += -isystem esp-idf/components/soc/src/esp32s2/include
INC += -isystem esp-idf/components/soc/soc/include
INC += -isystem esp-idf/components/soc/soc/esp32s2/include
INC += -isystem esp-idf/components/heap/include
INC += -isystem esp-idf/components/esp_system/include
2020-11-11 12:41:12 -05:00
INC += -isystem esp-idf/components/spi_flash/include
INC += -isystem esp-idf/components/nvs_flash/include
2020-12-08 01:15:00 -05:00
INC += -isystem esp-idf/components/app_update/include
INC += -isystem esp-idf/components/bootloader_support/include
INC += -I$(BUILD)/esp-idf/config
CFLAGS += -DHAVE_CONFIG_H \
-DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" \
-DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX
# Make our canary value match FreeRTOS's
# This define is in FreeRTOS as tskSTACK_FILL_BYTE 0xa5U which we expand out to a full word.
CFLAGS += -DSTACK_CANARY_VALUE=0xa5a5a5a5
#Debugging/Optimization
ifeq ($(DEBUG), 1)
2020-12-11 16:11:39 -05:00
CFLAGS += -DDEBUG -ggdb
2020-07-23 20:27:02 -04:00
OPTIMIZATION_FLAGS ?= -Og
# You may want to enable these flags to make setting breakpoints easier.
# CFLAGS += -fno-inline -fno-ipa-sra
else
2020-07-23 20:27:02 -04:00
CFLAGS += -DNDEBUG -ggdb3
OPTIMIZATION_FLAGS ?= -O2
# TODO: Test with -flto
### CFLAGS += -flto
endif
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
2020-07-23 20:27:02 -04:00
CFLAGS += $(OPTIMIZATION_FLAGS)
CFLAGS += $(INC) -Werror -Wall -mlongcalls -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
2020-09-02 11:27:42 -04:00
LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref -Wl,--undefined=uxTopUsedPriority
LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp32s2 \
-Tesp32s2_out.ld \
-L$(BUILD)/esp-idf/esp-idf/esp32s2/ld \
-Tesp32s2.project.ld \
-Lesp-idf/components/esp32s2/ld \
-Tesp32s2.peripherals.ld \
-Lesp-idf/components/esp_rom/esp32s2/ld \
-Tesp32s2.rom.ld \
-Tesp32s2.rom.libgcc.ld \
-Tesp32s2.rom.newlib-data.ld \
-Tesp32s2.rom.newlib-funcs.ld \
-Tesp32s2.rom.spiflash.ld
2020-07-28 21:23:33 -04:00
LIBS := -lgcc -lc -lstdc++
#
LDFLAGS += -Wl,-Bstatic \
-Wl,--no-warn-mismatch \
-Wl,--build-id=none \
-fno-rtti
# Use toolchain libm if we're not using our own.
ifndef INTERNAL_LIBM
LIBS += -lm
endif
# TinyUSB defines
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S2 -DCFG_TUSB_OS=OPT_OS_FREERTOS -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024
CFLAGS += -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128
CFLAGS += -DCFG_TUD_VENDOR_RX_BUFSIZE=128 -DCFG_TUD_VENDOR_TX_BUFSIZE=128
######################################
# source
######################################
SRC_C += \
background.c \
fatfs_port.c \
mphalport.c \
2020-08-14 18:56:01 -04:00
bindings/espidf/__init__.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
modules/$(CIRCUITPY_MODULE).c \
lib/netutils/netutils.c \
2020-11-18 01:46:14 -05:00
peripherals/timer.c \
2020-12-19 02:26:34 -05:00
peripherals/touch.c \
2020-11-04 23:40:39 -05:00
peripherals/pcnt.c \
peripherals/pins.c \
peripherals/rmt.c
ifneq ($(CIRCUITPY_USB),0)
SRC_C += lib/tinyusb/src/portable/espressif/esp32s2/dcd_esp32s2.c
endif
SRC_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))
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_EXPANDED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_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 +=
# IDF build commands
IDF_PATH = $(realpath ./esp-idf)
# create the directory
$(BUILD)/esp-idf:
$(Q)$(MKDIR) -p $@
2020-09-17 19:01:23 -04:00
FLASH_SDKCONFIG = esp-idf-config/sdkconfig-$(CIRCUITPY_ESP_FLASH_SIZE).defaults
ifeq ($(DEBUG), 1)
DEBUG_SDKCONFIG = esp-idf-config/sdkconfig-debug.defaults
else
DEBUG_SDKCONFIG = esp-idf-config/sdkconfig-opt.defaults
endif
SDKCONFIGS = esp-idf-config/sdkconfig.defaults;$(DEBUG_SDKCONFIG);$(FLASH_SDKCONFIG);boards/$(BOARD)/sdkconfig
# create the config headers
$(BUILD)/esp-idf/config/sdkconfig.h: boards/$(BOARD)/sdkconfig | $(BUILD)/esp-idf
2020-09-17 19:01:23 -04:00
IDF_PATH=$(IDF_PATH) cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-esp32s2.cmake -DIDF_TARGET=esp32s2 -GNinja
# build a lib
# Adding -d explain -j 1 -v to the ninja line will output debug info
#$(BUILD)/esp-idf/esp-idf/%.a: $(BUILD)/esp-idf/config/sdkconfig.h
# ninja -C $(BUILD)/esp-idf esp-idf/$*.a
$(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld: $(BUILD)/esp-idf/config/sdkconfig.h
ninja -C $(BUILD)/esp-idf esp-idf/esp32s2/esp32s2_out.ld
$(BUILD)/esp-idf/esp-idf/esp32s2/ld/esp32s2.project.ld: $(BUILD)/esp-idf/config/sdkconfig.h
ninja -C $(BUILD)/esp-idf esp-idf/esp32s2/ld/esp32s2.project.ld
$(BUILD)/esp-idf/partition_table/partition-table.bin: $(BUILD)/esp-idf/config/sdkconfig.h
IDF_PATH=$(IDF_PATH) ninja -C $(BUILD)/esp-idf partition_table/partition-table.bin
2020-09-17 19:01:23 -04:00
# run menuconfig and then remove standard settings
menuconfig: $(BUILD)/esp-idf/config
2020-07-28 21:23:33 -04:00
$(Q)ninja -C $(BUILD)/esp-idf menuconfig
2020-09-17 19:01:23 -04:00
$(Q)diff --old-line-format= --unchanged-line-format= esp-idf-config/sdkconfig.defaults $(BUILD)/esp-idf/sdkconfig > $(BUILD)/sdkconfig.diff || true
2020-09-28 18:10:12 -04:00
$(Q)grep -Fvxf $(DEBUG_SDKCONFIG) -f $(FLASH_SDKCONFIG) $(BUILD)/sdkconfig.diff > boards/$(BOARD)/sdkconfig
# qstr builds include headers so we need to make sure they are up to date
$(HEADER_BUILD)/qstr.split: | $(BUILD)/esp-idf/config/sdkconfig.h
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp_adc_cal esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf esp_wifi esp_event wpa_supplicant mbedtls efuse nvs_flash esp_netif lwip esp-tls
ESP_IDF_COMPONENTS_INCLUDE = driver freertos log soc
2020-09-28 12:11:08 -04:00
INC += $(foreach component, $(ESP_IDF_COMPONENTS_INCLUDE), -isystem esp-idf/components/$(component)/include)
ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
2020-07-28 21:23:33 -04:00
ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
MBEDTLS_COMPONENTS_LINK = crypto tls x509
MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a)
BINARY_BLOBS = esp-idf/components/xtensa/esp32s2/libhal.a
BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a librtc.a libsmartconfig.a libphy.a
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/esp32s2/, $(BINARY_WIFI_BLOBS))
ESP_IDF_COMPONENTS_EXPANDED += $(BUILD)/esp-idf/esp-idf/soc/soc/esp32s2/libsoc_esp32s2.a
ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld $(BUILD)/esp-idf/esp-idf/esp32s2/ld/esp32s2.project.ld
FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE)
ESPTOOL_FLAGS ?= -b 460800 --before=default_reset --after=no_reset
2020-06-17 13:57:52 -04:00
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
.PHONY: esp-idf-stamp
esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
2020-07-28 21:23:33 -04:00
$(Q)ninja -C $(BUILD)/esp-idf \
bootloader/bootloader.bin \
esp-idf/bootloader_support/libbootloader_support.a \
2020-08-12 19:57:39 -04:00
esp-idf/esp-tls/libesp-tls.a \
esp-idf/esp32s2/ld/esp32s2.project.ld \
2020-07-28 21:23:33 -04:00
esp-idf/esp_event/libesp_event.a \
esp-idf/esp_netif/libesp_netif.a \
esp-idf/esp_system/libesp_system.a \
2020-07-28 21:23:33 -04:00
esp-idf/esp_wifi/libesp_wifi.a \
esp-idf/lwip/liblwip.a \
2020-07-28 21:23:33 -04:00
esp-idf/nvs_flash/libnvs_flash.a \
esp-idf/wpa_supplicant/libwpa_supplicant.a \
esp-idf/mbedtls/libmbedtls.a \
esp-idf/freertos/libfreertos.a \
esp-idf/log/liblog.a \
esp-idf/xtensa/libxtensa.a
$(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp
$(STEPECHO) "LINK $@"
2020-07-28 21:23:33 -04:00
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group build-$(BOARD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf | tools/build_memory_info.py
$(STEPECHO) "Create $@"
$(Q)esptool.py --chip esp32s2 elf2image $(FLASH_FLAGS) --elf-sha256-offset 0xb0 -o $@ $^
$(Q)$(PYTHON3) tools/build_memory_info.py $< $(BUILD)/esp-idf/sdkconfig $@
$(BUILD)/firmware.bin: $(BUILD)/circuitpython-firmware.bin | esp-idf-stamp
$(Q)$(PYTHON) ../../tools/join_bins.py $@ 0x1000 $(BUILD)/esp-idf/bootloader/bootloader.bin 0x8000 $(BUILD)/esp-idf/partition_table/partition-table.bin 0x10000 $(BUILD)/circuitpython-firmware.bin
2020-06-17 13:57:52 -04:00
$(BUILD)/firmware.uf2: $(BUILD)/circuitpython-firmware.bin
$(STEPECHO) "Create $@"
$(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xbfdd4eee -b 0x0000 -c -o $@ $^
flash: $(BUILD)/firmware.bin
esptool.py --chip esp32s2 -p $(PORT) $(ESPTOOL_FLAGS) write_flash $(FLASH_FLAGS) 0x0000 $^
flash-circuitpython-only: $(BUILD)/circuitpython-firmware.bin
esptool.py --chip esp32s2 -p $(PORT) $(ESPTOOL_FLAGS) write_flash $(FLASH_FLAGS) 0x10000 $^
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 $* = $($*)