2018-09-05 02:39:50 +02:00
|
|
|
# check some environment variables first
|
|
|
|
|
2019-10-18 17:45:40 +02:00
|
|
|
ifndef ESP8266_RTOS_SDK_DIR
|
|
|
|
$(info ESP8266_RTOS_SDK_DIR should be defined as /path/to/sdk directory)
|
|
|
|
$(info ESP8266_RTOS_SDK_DIR is set by default to /opt/esp/ESP8266-RTOS-SDK)
|
|
|
|
export ESP8266_RTOS_SDK_DIR=/opt/esp/ESP8266-RTOS-SDK
|
2018-09-05 02:39:50 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Options to control the compilation
|
|
|
|
|
|
|
|
ifeq ($(ENABLE_GDB), 1)
|
|
|
|
USEMODULE += esp_gdb
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(ENABLE_GDBSTUB), 1)
|
|
|
|
USEMODULE += esp_gdbstub
|
2018-12-26 16:03:38 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
# SPECIAL module dependencies
|
|
|
|
# cannot be done in Makefile.dep since Makefile.dep is included too late
|
|
|
|
|
2019-11-23 12:10:57 +01:00
|
|
|
ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
|
2019-12-26 19:01:58 +01:00
|
|
|
ifneq (,$(filter lwip,$(USEMODULE)))
|
|
|
|
# for lwip, use esp_wifi as default netdev if no other netdev is enabled
|
|
|
|
USEMODULE += esp_wifi
|
|
|
|
else
|
|
|
|
# otherwise use esp_now as default netdev if no other netdev is enabled
|
|
|
|
ifeq (,$(filter esp_wifi esp_eth,$(USEMODULE)))
|
|
|
|
USEMODULE += esp_now
|
|
|
|
endif
|
2019-11-23 12:10:57 +01:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq (, $(filter esp_wifi, $(USEMODULE)))
|
|
|
|
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
|
|
|
|
USEMODULE += esp_wifi_any
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq (, $(filter esp_now, $(USEMODULE)))
|
2019-01-16 19:30:59 +01:00
|
|
|
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
|
2019-09-05 13:35:58 +02:00
|
|
|
USEMODULE += esp_wifi_any
|
2019-11-23 12:10:57 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq (, $(filter esp_wifi_any, $(USEMODULE)))
|
|
|
|
CFLAGS += -DSCHED_PRIO_LEVELS=32
|
2019-01-16 19:30:59 +01:00
|
|
|
USEMODULE += netopt
|
2019-09-05 13:35:58 +02:00
|
|
|
USEMODULE += xtimer
|
2019-01-16 19:30:59 +01:00
|
|
|
endif
|
|
|
|
|
2018-12-26 16:03:38 +01:00
|
|
|
ifneq (, $(filter esp_gdbstub, $(USEMODULE)))
|
2018-09-05 02:39:50 +02:00
|
|
|
USEMODULE += esp_gdb
|
|
|
|
endif
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
ifneq (, $(filter spiffs, $(USEMODULE)))
|
2019-12-06 11:29:44 +01:00
|
|
|
export RIOT_TEST_TIMEOUT = 200
|
2019-09-05 13:35:58 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq (, $(filter littlefs, $(USEMODULE)))
|
2019-12-06 11:29:44 +01:00
|
|
|
export RIOT_TEST_TIMEOUT = 200
|
2019-09-05 13:35:58 +02:00
|
|
|
endif
|
|
|
|
|
2019-12-06 18:56:04 +01:00
|
|
|
ifneq (,$(filter log_color,$(USEMODULE)))
|
|
|
|
USEMODULE += esp_log_colored
|
|
|
|
endif
|
|
|
|
|
2019-12-06 18:56:47 +01:00
|
|
|
ifneq (,$(filter 4 5,$(LOG_LEVEL)))
|
|
|
|
USEMODULE += esp_log_startup
|
|
|
|
endif
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
# regular Makefile
|
|
|
|
|
2019-10-18 19:06:35 +02:00
|
|
|
export TARGET_ARCH ?= xtensa-esp8266-elf
|
2018-09-05 02:39:50 +02:00
|
|
|
|
|
|
|
# ESP8266 pseudomodules
|
|
|
|
PSEUDOMODULES += esp_gdb
|
2019-09-05 13:35:58 +02:00
|
|
|
PSEUDOMODULES += esp_log_colored
|
|
|
|
PSEUDOMODULES += esp_log_tagged
|
2019-12-06 18:56:04 +01:00
|
|
|
PSEUDOMODULES += esp_log_startup
|
2019-09-05 13:35:58 +02:00
|
|
|
PSEUDOMODULES += esp_qemu
|
2018-09-05 02:39:50 +02:00
|
|
|
PSEUDOMODULES += esp_sw_timer
|
|
|
|
PSEUDOMODULES += esp_spiffs
|
2019-09-05 13:35:58 +02:00
|
|
|
PSEUDOMODULES += esp_wifi_any
|
2018-09-05 02:39:50 +02:00
|
|
|
|
2019-12-20 16:22:21 +01:00
|
|
|
USEMODULE += esp_common
|
2019-09-05 13:17:47 +02:00
|
|
|
USEMODULE += esp_freertos
|
2019-09-05 13:21:38 +02:00
|
|
|
USEMODULE += esp_idf
|
|
|
|
USEMODULE += esp_idf_esp8266
|
|
|
|
USEMODULE += esp_idf_nvs_flash
|
|
|
|
USEMODULE += esp_idf_spi_flash
|
|
|
|
USEMODULE += esp_idf_util
|
|
|
|
USEMODULE += esp_idf_wpa_supplicant_crypto
|
2019-09-05 13:35:58 +02:00
|
|
|
USEMODULE += esp_sdk
|
|
|
|
USEMODULE += log
|
2018-12-26 16:03:38 +01:00
|
|
|
USEMODULE += mtd
|
2019-08-31 13:29:21 +02:00
|
|
|
USEMODULE += newlib
|
|
|
|
USEMODULE += newlib_syscalls_default
|
2018-12-26 16:03:38 +01:00
|
|
|
USEMODULE += periph
|
2019-09-05 13:35:58 +02:00
|
|
|
USEMODULE += periph_common
|
|
|
|
USEMODULE += periph_hrng
|
|
|
|
USEMODULE += periph_flash
|
|
|
|
USEMODULE += periph_uart
|
2018-12-26 16:03:38 +01:00
|
|
|
USEMODULE += ps
|
|
|
|
USEMODULE += random
|
2019-08-31 13:29:21 +02:00
|
|
|
USEMODULE += stdio_uart
|
2018-12-26 16:03:38 +01:00
|
|
|
USEMODULE += xtensa
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
INCLUDES += -I$(RIOTBOARD)/common/$(CPU)/include
|
2019-01-27 14:39:10 +01:00
|
|
|
INCLUDES += -I$(RIOTCPU)/esp_common/vendor/
|
2018-09-05 02:39:50 +02:00
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)
|
2019-09-05 13:35:58 +02:00
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/include
|
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/include/freertos
|
2018-09-05 02:39:50 +02:00
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor
|
2019-09-05 13:35:58 +02:00
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/
|
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/bootloader_support/include
|
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/esp8266/include
|
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/esp8266/include/esp8266
|
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/heap/include
|
|
|
|
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/log/include
|
2019-10-18 17:45:40 +02:00
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/
|
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/bootloader_support/include/
|
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/esp8266/include
|
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/esp8266/include/esp8266
|
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/heap/include
|
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/heap/port/esp8266/include
|
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/nvs_flash/include
|
|
|
|
INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/spi_flash/include
|
2019-09-05 13:35:58 +02:00
|
|
|
|
2019-10-22 18:57:39 +02:00
|
|
|
CFLAGS += -D__ESP_FILE__=__FILE__
|
2018-09-05 02:39:50 +02:00
|
|
|
CFLAGS += -Wno-unused-parameter -Wformat=0
|
2019-09-05 13:35:58 +02:00
|
|
|
CFLAGS += -mlongcalls -mtext-section-literals -fstrict-volatile-bitfields
|
|
|
|
CFLAGS += -fdata-sections -ffunction-sections -fzero-initialized-in-bss
|
|
|
|
|
|
|
|
OPTIONAL_CFLAGS_BLACKLIST += -fdiagnostics-color
|
|
|
|
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
|
|
|
|
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation
|
|
|
|
OPTIONAL_CFLAGS_BLACKLIST += -gz
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
ASFLAGS += --longcalls --text-section-literals
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
# thin archives trigger a reboot loop - see #12258, #12035, #12346
|
|
|
|
ARFLAGS = rcs
|
2018-09-05 02:39:50 +02:00
|
|
|
|
2019-12-14 15:03:12 +01:00
|
|
|
ifneq (,$(filter lwip,$(USEMODULE)))
|
|
|
|
# The threads for handling the ESP hardware have the priorities from 2 to 4.
|
|
|
|
# The priority of lwIP TCPIP thread should be lower than these priorities.
|
|
|
|
CFLAGS += -DTCPIP_THREAD_PRIO=5
|
|
|
|
endif
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
ifneq (, $(filter esp_gdbstub, $(USEMODULE)))
|
|
|
|
GDBSTUB_DIR ?= $(RIOTCPU)/$(CPU)/vendor/esp-gdbstub
|
2019-09-05 13:35:58 +02:00
|
|
|
CFLAGS += -DGDBSTUB_BREAK_ON_INIT=1
|
2018-09-05 02:39:50 +02:00
|
|
|
INCLUDES += -I$(GDBSTUB_DIR)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq (, $(filter esp_gdb, $(USEMODULE)))
|
2019-09-05 13:35:58 +02:00
|
|
|
CFLAGS_OPT ?= -Og -ggdb -g3
|
2018-09-05 02:39:50 +02:00
|
|
|
else
|
2019-09-05 13:35:58 +02:00
|
|
|
# TODO should be -Os
|
|
|
|
# With -Os char arrays have not to be 32-bit word aligned. This leads to
|
|
|
|
# an alignment exception when the address of an char array is assigned to
|
|
|
|
# an uint32_t pointer and the pointer is used for the access.
|
|
|
|
CFLAGS_OPT ?= -O2
|
2018-09-05 02:39:50 +02:00
|
|
|
endif
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
CFLAGS += $(CFLAGS_OPT)
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
ifeq ($(QEMU), 1)
|
2019-09-05 13:35:58 +02:00
|
|
|
USEMODULE += esp_qemu
|
2018-09-05 02:39:50 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(FLASH_MODE), qio)
|
|
|
|
CFLAGS += -DFLASH_MODE_QIO
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(FLASH_MODE), qout)
|
|
|
|
CFLAGS += -DFLASH_MODE_QOUT
|
|
|
|
endif
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
LINKFLAGS += -L$(ESP8266_RTOS_SDK_DIR)/components/esp8266/lib
|
|
|
|
LINKFLAGS += $(CFLAGS_OPT)
|
2018-09-05 02:39:50 +02:00
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
BASELIBS += -lc -lgcc -lwpa -lcore -lnet80211 -lphy -lpp -lhal -lstdc++
|
|
|
|
|
|
|
|
ifneq (, $(filter esp_now, $(USEMODULE)))
|
|
|
|
BASELIBS += -lespnow
|
2018-09-05 02:39:50 +02:00
|
|
|
endif
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
LINKFLAGS += -u _malloc_r
|
|
|
|
LINKFLAGS += -nostdlib -Wl,-gc-sections -Wl,-static # -Wl,--print-gc-sections
|
|
|
|
|
|
|
|
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.rom.ld
|
|
|
|
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.riot-os.ld
|
|
|
|
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.peripherals.ld
|
|
|
|
|
2019-10-23 00:54:04 +02:00
|
|
|
LINKFLAGS += -Wl,-wrap=pp_attach
|
|
|
|
LINKFLAGS += -Wl,-wrap=pm_attach
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
ifneq (, $(filter esp_idf_heap, $(USEMODULE)))
|
|
|
|
LINKFLAGS += -Wl,-wrap=_malloc_r
|
|
|
|
LINKFLAGS += -Wl,-wrap=_calloc_r
|
|
|
|
LINKFLAGS += -Wl,-wrap=_free_r
|
|
|
|
LINKFLAGS += -Wl,-wrap=_realloc_r
|
|
|
|
endif
|
2018-09-05 02:39:50 +02:00
|
|
|
|
2018-12-19 17:45:41 +01:00
|
|
|
# The ELFFILE is the base one used for flashing
|
|
|
|
FLASHFILE ?= $(ELFFILE)
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
# configure preflasher to convert .elf to .bin before flashing
|
2019-09-05 13:35:58 +02:00
|
|
|
FLASH_MODE = dout # FIX configuration, DO NOT CHANGE
|
|
|
|
FLASH_FREQ = 26m # FIX configuration, DO NOT CHANGE
|
|
|
|
FLASH_SIZE ?= 1MB
|
2019-06-05 11:53:00 +02:00
|
|
|
FLASHDEPS += preflash
|
2018-09-05 02:39:50 +02:00
|
|
|
|
2019-11-12 09:31:46 +01:00
|
|
|
PREFLASHER ?= $(RIOTTOOLS)/esptool/esptool.py
|
2019-09-05 13:35:58 +02:00
|
|
|
PREFFLAGS = --chip esp8266 elf2image
|
|
|
|
PREFFLAGS += --flash_mode $(FLASH_MODE) --flash_size $(FLASH_SIZE)
|
|
|
|
PREFFLAGS += --flash_freq $(FLASH_FREQ) --version 3
|
|
|
|
PREFFLAGS += -o $(FLASHFILE).bin $(FLASHFILE);
|
2019-12-01 14:36:42 +01:00
|
|
|
PREFFLAGS += printf "\n" > $(BINDIR)/partitions.csv;
|
|
|
|
PREFFLAGS += printf "nvs, data, nvs, 0x9000, 0x6000\n" >> $(BINDIR)/partitions.csv;
|
|
|
|
PREFFLAGS += printf "phy_init, data, phy, 0xf000, 0x1000\n" >> $(BINDIR)/partitions.csv;
|
|
|
|
PREFFLAGS += printf "factory, app, factory, 0x10000, " >> $(BINDIR)/partitions.csv;
|
2019-09-05 13:35:58 +02:00
|
|
|
PREFFLAGS += ls -l $(FLASHFILE).bin | awk '{ print $$5 }' >> $(BINDIR)/partitions.csv;
|
|
|
|
|
|
|
|
PREFFLAGS += python $(RIOTCPU)/$(CPU)/vendor/esp-idf/partition_table/gen_esp32part.py
|
|
|
|
PREFFLAGS += --verify $(BINDIR)/partitions.csv $(BINDIR)/partitions.bin
|
|
|
|
|
2019-12-06 18:56:04 +01:00
|
|
|
ifneq (,$(filter esp_log_colored,$(USEMODULE)))
|
|
|
|
BOOTLOADER_COLOR = _colors
|
2019-09-05 13:35:58 +02:00
|
|
|
endif
|
|
|
|
|
2019-12-06 18:56:04 +01:00
|
|
|
ifneq (,$(filter esp_log_startup,$(USEMODULE)))
|
|
|
|
BOOTLOADER_INFO = _info
|
|
|
|
endif
|
|
|
|
|
|
|
|
BOOTLOADER_BIN = bootloader$(BOOTLOADER_COLOR)$(BOOTLOADER_INFO).bin
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
ifneq (, $(filter esp_qemu, $(USEMODULE)))
|
|
|
|
FLASHER = dd
|
|
|
|
FFLAGS += if=/dev/zero bs=1M count=1 | tr "\\000" "\\377" > tmp.bin &&
|
2019-12-06 18:56:04 +01:00
|
|
|
FFLAGS += cat $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER_BIN) tmp.bin |
|
2019-09-05 13:35:58 +02:00
|
|
|
FFLAGS += head -c $$((0x8000)) |
|
|
|
|
FFLAGS += cat - $(BINDIR)/partitions.bin tmp.bin |
|
|
|
|
FFLAGS += head -c $$((0x10000)) |
|
|
|
|
FFLAGS += cat - $(FLASHFILE).bin tmp.bin |
|
|
|
|
FFLAGS += head -c $$((0xfc000)) |
|
|
|
|
FFLAGS += cat - $(RIOTCPU)/$(CPU)/bin/esp_init_data_default.bin tmp.bin |
|
|
|
|
FFLAGS += head -c $$((0x100000)) > $(BINDIR)/esp8266flash.bin && rm tmp.bin
|
2018-09-05 02:39:50 +02:00
|
|
|
else
|
|
|
|
export PROGRAMMER_SPEED ?= 460800
|
2019-10-25 11:47:30 +02:00
|
|
|
FLASHER = $(RIOTBASE)/dist/tools/esptool/esptool.py
|
|
|
|
FFLAGS += --chip esp8266 --port $(PROG_DEV) --baud $(PROGRAMMER_SPEED)
|
2019-11-12 09:31:46 +01:00
|
|
|
FFLAGS += --before default_reset write_flash -z
|
2019-09-05 13:35:58 +02:00
|
|
|
FFLAGS += --flash_size detect
|
|
|
|
FFLAGS += --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ)
|
2019-12-06 18:56:04 +01:00
|
|
|
FFLAGS += 0x0000 $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER_BIN)
|
2019-09-05 13:35:58 +02:00
|
|
|
FFLAGS += 0x8000 $(BINDIR)/partitions.bin
|
|
|
|
FFLAGS += 0x10000 $(FLASHFILE).bin
|
2018-09-05 02:39:50 +02:00
|
|
|
endif
|