From 184b91cc4ce49dd528b647dcd084c6e0d7cfd3fc Mon Sep 17 00:00:00 2001 From: Rui Wang Date: Sat, 7 Jan 2023 20:12:48 -0500 Subject: [PATCH 1/5] initial checkin of 2.2.0 minor revision 2, adding support for OS 3.3 that uses W5500 wired ethernet --- Arduino.mk | 1600 ---------------------------------------- Common.mk | 87 --- OpenSprinkler.cpp | 20 +- OpenSprinkler.h | 1 + defines.h | 3 +- main.cpp | 4 +- make.lin302 | 34 - make.lin32 | 33 - make.os23 | 15 - makeEspArduino.mk | 569 -------------- tools/board_op.pl | 60 -- tools/crash_tool.pl | 90 --- tools/find_src.pl | 131 ---- tools/mem_use.pl | 27 - tools/obj_info.pl | 40 - tools/parse_arduino.pl | 161 ---- tools/py_wrap.py | 31 - tools/vscode.pl | 165 ----- 18 files changed, 17 insertions(+), 3054 deletions(-) delete mode 100644 Arduino.mk delete mode 100644 Common.mk delete mode 100644 make.lin302 delete mode 100644 make.lin32 delete mode 100644 make.os23 delete mode 100644 makeEspArduino.mk delete mode 100644 tools/board_op.pl delete mode 100644 tools/crash_tool.pl delete mode 100644 tools/find_src.pl delete mode 100644 tools/mem_use.pl delete mode 100644 tools/obj_info.pl delete mode 100644 tools/parse_arduino.pl delete mode 100644 tools/py_wrap.py delete mode 100644 tools/vscode.pl diff --git a/Arduino.mk b/Arduino.mk deleted file mode 100644 index 79f119cc..00000000 --- a/Arduino.mk +++ /dev/null @@ -1,1600 +0,0 @@ -######################################################################## -# -# Makefile for compiling Arduino sketches from command line -# System part (i.e. project independent) -# -# Copyright (C) 2012 Sudar , based on -# M J Oldfield work: https://github.com/mjoldfield/Arduino-Makefile -# -# Copyright (C) 2010,2011,2012 Martin Oldfield , based on -# work that is copyright Nicholas Zambetti, David A. Mellis & Hernando -# Barragan. -# -# This file is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as -# published by the Free Software Foundation; either version 2.1 of the -# License, or (at your option) any later version. -# -# Adapted from Arduino 0011 Makefile by M J Oldfield -# -# Original Arduino adaptation by mellis, eighthave, oli.keller -# -# Current version: 1.5.2 -# -# Refer to HISTORY.md file for complete history of changes -# -######################################################################## -# -# PATHS YOU NEED TO SET UP -# -# We need to worry about three different sorts of files: -# -# 1. The directory where the *.mk files are stored -# => ARDMK_DIR -# -# 2. Things which are always in the Arduino distribution e.g. -# boards.txt, libraries, etc. -# => ARDUINO_DIR -# -# 3. Things which might be bundled with the Arduino distribution, but -# might come from the system. Most of the toolchain is like this: -# on Linux it is supplied by the system. -# => AVR_TOOLS_DIR -# -# Having set these three variables, we can work out the rest assuming -# that things are canonically arranged beneath the directories defined -# above. -# -# On the Mac with IDE 1.0 you might want to set: -# -# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java -# ARDMK_DIR = /usr/local -# -# On the Mac with IDE 1.5+ you might want to set: -# -# ARDUINO_DIR = /Applications/Arduino.app/Contents/Java -# ARDMK_DIR = /usr/local -# -# On Linux, you might prefer: -# -# ARDUINO_DIR = /usr/share/arduino -# ARDMK_DIR = /usr/share/arduino -# AVR_TOOLS_DIR = /usr -# -# On Windows declare this environmental variables using the windows -# configuration options. Control Panel > System > Advanced system settings -# Also take into account that when you set them you have to add '\' on -# all spaces and special characters. -# ARDUINO_DIR and AVR_TOOLS_DIR have to be relative and not absolute. -# This are just examples, you have to adapt this variables accordingly to -# your system. -# -# ARDUINO_DIR =../../../../../Arduino -# AVR_TOOLS_DIR =../../../../../Arduino/hardware/tools/avr -# ARDMK_DIR = /cygdrive/c/Users/"YourUser"/Arduino-Makefile -# -# On Windows it is highly recommended that you create a symbolic link directory -# for avoiding using the normal directories name of windows such as -# c:\Program Files (x86)\Arduino -# For this use the command mklink on the console. -# -# -# You can either set these up in the Makefile, or put them in your -# environment e.g. in your .bashrc -# -# If you don't specify these, we can try to guess, but that might not work -# or work the way you want it to. -# -# If you'd rather not see the configuration output, define ARDUINO_QUIET. -# -######################################################################## -# -# DEPENDENCIES -# -# to reset a board the (python) pySerial program is used. -# please install it prior to continue. -# -######################################################################## -# -# STANDARD ARDUINO WORKFLOW -# -# Given a normal sketch directory, all you need to do is to create -# a small Makefile which defines a few things, and then includes this one. -# -# For example: -# -# ARDUINO_LIBS = Ethernet SPI -# BOARD_TAG = uno -# MONITOR_PORT = /dev/cu.usb* -# -# include /usr/share/arduino/Arduino.mk -# -# Hopefully these will be self-explanatory but in case they're not: -# -# ARDUINO_LIBS - A list of any libraries used by the sketch (we -# assume these are in $(ARDUINO_DIR)/hardware/libraries -# or your sketchbook's libraries directory) -# -# MONITOR_PORT - The port where the Arduino can be found (only needed -# when uploading) -# -# BOARD_TAG - The tag for the board e.g. uno or mega -# 'make show_boards' shows a list -# -# If you have your additional libraries relative to your source, rather -# than in your "sketchbook", also set USER_LIB_PATH, like this example: -# -# USER_LIB_PATH := $(realpath ../../libraries) -# -# If you've added the Arduino-Makefile repository to your git repo as a -# submodule (or other similar arrangement), you might have lines like this -# in your Makefile: -# -# ARDMK_DIR := $(realpath ../../tools/Arduino-Makefile) -# include $(ARDMK_DIR)/Arduino.mk -# -# In any case, once this file has been created the typical workflow is just -# -# $ make upload -# -# All of the object files are created in the build-{BOARD_TAG} subdirectory -# All sources should be in the current directory and can include: -# - at most one .pde or .ino file which will be treated as C++ after -# the standard Arduino header and footer have been affixed. -# - any number of .c, .cpp, .s and .h files -# -# Included libraries are built in the build-{BOARD_TAG}/libs subdirectory. -# -# Besides make upload, there are a couple of other targets that are available. -# Do make help to get the complete list of targets and their description -# -######################################################################## -# -# SERIAL MONITOR -# -# The serial monitor just invokes the GNU screen program with suitable -# options. For more information see screen (1) and search for -# 'character special device'. -# -# The really useful thing to know is that ^A-k gets you out! -# -# The fairly useful thing to know is that you can bind another key to -# escape too, by creating $HOME{.screenrc} containing e.g. -# -# bindkey ^C kill -# -# If you want to change the baudrate, just set MONITOR_BAUDRATE. If you -# don't set it, it tries to read from the sketch. If it couldn't read -# from the sketch, then it defaults to 9600 baud. -# -######################################################################## -# -# ARDUINO WITH ISP -# -# You need to specify some details of your ISP programmer and might -# also need to specify the fuse values: -# -# ISP_PROG = stk500v2 -# ISP_PORT = /dev/ttyACM0 -# -# You might also need to set the fuse bits, but typically they'll be -# read from boards.txt, based on the BOARD_TAG variable: -# -# ISP_LOCK_FUSE_PRE = 0x3f -# ISP_LOCK_FUSE_POST = 0xcf -# ISP_HIGH_FUSE = 0xdf -# ISP_LOW_FUSE = 0xff -# ISP_EXT_FUSE = 0x01 -# -# You can specify to also upload the EEPROM file: -# ISP_EEPROM = 1 -# -# I think the fuses here are fine for uploading to the ATmega168 -# without bootloader. -# -# To actually do this upload use the ispload target: -# -# make ispload -# -# -######################################################################## -# -# ALTERNATIVE CORES -# -# To use alternative cores for platforms such as ATtiny, you need to -# specify a few more variables, depending on the core in use. -# -# The HLT (attiny-master) core can be used just by specifying -# ALTERNATE_CORE, assuming your core is in your ~/sketchbook/hardware -# directory. For example: -# -# ISP_PORT = /dev/ttyACM0 -# BOARD_TAG = attiny85 -# ALTERNATE_CORE = attiny-master -# -# To use the more complex arduino-tiny and TinyCore2 cores, you must -# also set ARDUINO_CORE_PATH and ARDUINO_VAR_PATH to the core -# directory, as these cores essentially replace the main Arduino core. -# For example: -# -# ISP_PORT = /dev/ttyACM0 -# BOARD_TAG = attiny85at8 -# ALTERNATE_CORE = arduino-tiny -# ARDUINO_VAR_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny -# ARDUINO_CORE_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny -# -# or.... -# -# ISP_PORT = /dev/ttyACM0 -# BOARD_TAG = attiny861at8 -# ALTERNATE_CORE = tiny2 -# ARDUINO_VAR_PATH = ~/sketchbook/hardware/tiny2/cores/tiny -# ARDUINO_CORE_PATH = ~/sketchbook/hardware/tiny2/cores/tiny -# -######################################################################## - -arduino_output = -# When output is not suppressed and we're in the top-level makefile, -# running for the first time (i.e., not after a restart after -# regenerating the dependency file), then output the configuration. -ifndef ARDUINO_QUIET - ifeq ($(MAKE_RESTARTS),) - ifeq ($(MAKELEVEL),0) - arduino_output = $(info $(1)) - endif - endif -endif - -######################################################################## -# Makefile distribution path - -ifndef ARDMK_DIR - # presume it's the same path to our own file - ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST))))) -else - # show_config_variable macro is defined in Common.mk file and is not available yet. - # Let's define a variable to know that user specified ARDMK_DIR - ARDMK_DIR_MSG = USER -endif - -# include Common.mk now we know where it is -include $(ARDMK_DIR)/Common.mk - -# show_config_variable macro is available now. So let's print config details for ARDMK_DIR -ifndef ARDMK_DIR_MSG - $(call show_config_variable,ARDMK_DIR,[COMPUTED],(relative to $(notdir $(lastword $(MAKEFILE_LIST))))) -else - $(call show_config_variable,ARDMK_DIR,[USER]) -endif - -######################################################################## -# Default TARGET to pwd (ex Daniele Vergini) - -ifndef TARGET - space := - space += - TARGET = $(notdir $(subst $(space),_,$(CURDIR))) -endif - -######################################################################## -# Arduino version number - -ifndef ARDUINO_VERSION - # Remove all the decimals, remove anything before/including ":", remove anything after/including "+" and finally grab the last 5 bytes. - # Works for 1.0 and 1.0.1 and 1.6.10 and debian-style 2:1.0.5+dfsg2-4 - VERSION_FILE := $(ARDUINO_DIR)/lib/version.txt - AUTO_ARDUINO_VERSION := $(shell [ -e $(VERSION_FILE) ] && cat $(VERSION_FILE) | sed -e 's/^[0-9]://g' -e 's/[.]//g' -e 's/\+.*//g' | head -c5) - ifdef AUTO_ARDUINO_VERSION - ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION) - $(call show_config_variable,ARDUINO_VERSION,[AUTODETECTED]) - else - ARDUINO_VERSION = 100 - $(call show_config_variable,ARDUINO_VERSION,[DEFAULT]) - endif -else - $(call show_config_variable,ARDUINO_VERSION,[USER]) -endif - -######################################################################## -# 1.5.x architecture - avr or sam for arduino vendor -ifndef ARCHITECTURE - ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) - # default to avr for 1.5 - ARCHITECTURE = avr - ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR - else - # unset for 1.0 - ARCHITECTURE = - endif - $(call show_config_variable,ARCHITECTURE,[DEFAULT]) -else - $(call show_config_variable,ARCHITECTURE,[USER]) - - #avoid using shell for known architectures - ifeq ($(ARCHITECTURE),avr) - ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR - else - ifeq ($(ARCHITECTURE),sam) - ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_SAM - else - ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]') - endif - endif -endif - -######################################################################## -# 1.5.x vendor - defaults to arduino -ifndef ARDMK_VENDOR - ARDMK_VENDOR = arduino - $(call show_config_variable,ARDMK_VENDOR,[DEFAULT]) -else - $(call show_config_variable,ARDMK_VENDOR,[USER]) -endif - -######################################################################## -# Arduino Sketchbook folder - -ifndef ARDUINO_SKETCHBOOK - ifndef ARDUINO_PREFERENCES_PATH - ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) - AUTO_ARDUINO_PREFERENCES := $(firstword \ - $(call dir_if_exists,$(HOME)/.arduino15/preferences.txt) \ - $(call dir_if_exists,$(HOME)/Library/Arduino15/preferences.txt) ) - else - AUTO_ARDUINO_PREFERENCES := $(firstword \ - $(call dir_if_exists,$(HOME)/.arduino/preferences.txt) \ - $(call dir_if_exists,$(HOME)/Library/Arduino/preferences.txt) ) - endif - - ifdef AUTO_ARDUINO_PREFERENCES - ARDUINO_PREFERENCES_PATH = $(AUTO_ARDUINO_PREFERENCES) - $(call show_config_variable,ARDUINO_PREFERENCES_PATH,[AUTODETECTED]) - endif - - else - $(call show_config_variable,ARDUINO_PREFERENCES_PATH,[USER]) - endif - - ifneq ($(ARDUINO_PREFERENCES_PATH),) - ARDUINO_SKETCHBOOK := $(shell grep --max-count=1 --regexp='sketchbook.path=' \ - $(ARDUINO_PREFERENCES_PATH) | \ - sed -e 's/sketchbook.path=//' ) - endif - - ifneq ($(ARDUINO_SKETCHBOOK),) - $(call show_config_variable,ARDUINO_SKETCHBOOK,[AUTODETECTED],(from arduino preferences file)) - else - ARDUINO_SKETCHBOOK := $(firstword \ - $(call dir_if_exists,$(HOME)/sketchbook) \ - $(call dir_if_exists,$(HOME)/Documents/Arduino) ) - $(call show_config_variable,ARDUINO_SKETCHBOOK,[DEFAULT]) - endif -else - $(call show_config_variable,ARDUINO_SKETCHBOOK,[USER]) -endif - -######################################################################## -# Arduino and system paths - -ifndef CC_NAME -CC_NAME = avr-gcc -endif - -ifndef CXX_NAME -CXX_NAME = avr-g++ -endif - -ifndef OBJCOPY_NAME -OBJCOPY_NAME = avr-objcopy -endif - -ifndef OBJDUMP_NAME -OBJDUMP_NAME = avr-objdump -endif - -ifndef SIZE_NAME -SIZE_NAME = avr-size -endif - -ifndef NM_NAME -NM_NAME = avr-nm -endif - -ifndef AVR_TOOLS_DIR - - BUNDLED_AVR_TOOLS_DIR := $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/avr) - - ifdef BUNDLED_AVR_TOOLS_DIR - AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR) - $(call show_config_variable,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) - - # In Linux distribution of Arduino, the path to avrdude and avrdude.conf are different - # More details at https://github.com/sudar/Arduino-Makefile/issues/48 and - # https://groups.google.com/a/arduino.cc/d/msg/developers/D_m97jGr8Xs/uQTt28KO_8oJ - ifeq ($(CURRENT_OS),LINUX) - - ifndef AVRDUDE - ifeq ($(shell expr $(ARDUINO_VERSION) '>' 157), 1) - # 1.5.8 has different location than all prior versions! - AVRDUDE = $(AVR_TOOLS_DIR)/bin/avrdude - else - AVRDUDE = $(AVR_TOOLS_DIR)/../avrdude - endif - endif - - ifndef AVRDUDE_CONF - ifeq ($(shell expr $(ARDUINO_VERSION) '>' 157), 1) - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf - else - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/../avrdude.conf - endif - endif - - else - - ifndef AVRDUDE_CONF - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf - endif - - endif - - else - - SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(CC_NAME)))/..)) - ifdef SYSTEMPATH_AVR_TOOLS_DIR - AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) - $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) - else - echo $(error No AVR tools directory found) - endif # SYSTEMPATH_AVR_TOOLS_DIR - - endif # BUNDLED_AVR_TOOLS_DIR - -else - $(call show_config_variable,AVR_TOOLS_DIR,[USER]) - - # ensure we can still find avrdude.conf - ifndef AVRDUDE_CONF - ifeq ($(shell expr $(ARDUINO_VERSION) '>' 157), 1) - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf - else - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/../avrdude.conf - endif - endif - -endif #ndef AVR_TOOLS_DIR - -ifndef AVR_TOOLS_PATH - AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin -endif - -ifndef ARDUINO_LIB_PATH - ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries - $(call show_config_variable,ARDUINO_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) -else - $(call show_config_variable,ARDUINO_LIB_PATH,[USER]) -endif - -# 1.5.x platform dependent libs path -ifndef ARDUINO_PLATFORM_LIB_PATH - ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) - # only for 1.5 - ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/libraries - $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) - endif -else - $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[USER]) -endif - -# Third party hardware and core like ATtiny or ATmega 16 -ifdef ALTERNATE_CORE - $(call show_config_variable,ALTERNATE_CORE,[USER]) - - ifndef ALTERNATE_CORE_PATH - ALTERNATE_CORE_PATH = $(ARDUINO_SKETCHBOOK)/hardware/$(ALTERNATE_CORE)/$(ARCHITECTURE) - endif -endif - -ifdef ALTERNATE_CORE_PATH - - ifdef ALTERNATE_CORE - $(call show_config_variable,ALTERNATE_CORE_PATH,[COMPUTED], (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE)) - else - $(call show_config_variable,ALTERNATE_CORE_PATH,[USER]) - endif - - ifndef ARDUINO_VAR_PATH - ARDUINO_VAR_PATH = $(ALTERNATE_CORE_PATH)/variants - $(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH)) - endif - - ifndef BOARDS_TXT - BOARDS_TXT = $(ALTERNATE_CORE_PATH)/boards.txt - $(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ALTERNATE_CORE_PATH)) - endif - -else - - ifndef ARDUINO_VAR_PATH - ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/variants - $(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ARDUINO_DIR)) - else - $(call show_config_variable,ARDUINO_VAR_PATH,[USER]) - endif - - ifndef BOARDS_TXT - BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/boards.txt - $(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ARDUINO_DIR)) - else - $(call show_config_variable,BOARDS_TXT,[USER]) - endif - -endif - -######################################################################## -# Miscellaneous - -ifndef USER_LIB_PATH - USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries - $(call show_config_variable,USER_LIB_PATH,[DEFAULT],(in user sketchbook)) -else - $(call show_config_variable,USER_LIB_PATH,[USER]) -endif - -ifndef PRE_BUILD_HOOK - PRE_BUILD_HOOK = pre-build-hook.sh - $(call show_config_variable,PRE_BUILD_HOOK,[DEFAULT]) -else - $(call show_config_variable,PRE_BUILD_HOOK,[USER]) -endif - -######################################################################## -# boards.txt parsing - -ifdef BOARD_SUB - BOARD_SUB := $(strip $(BOARD_SUB)) - $(call show_config_variable,BOARD_SUB,[USER]) -endif - -ifndef BOARD_TAG - BOARD_TAG = uno - $(call show_config_variable,BOARD_TAG,[DEFAULT]) -else - # Strip the board tag of any extra whitespace, since it was causing the makefile to fail - # https://github.com/sudar/Arduino-Makefile/issues/57 - BOARD_TAG := $(strip $(BOARD_TAG)) - $(call show_config_variable,BOARD_TAG,[USER]) -endif - -ifndef PARSE_BOARD - # result = $(call READ_BOARD_TXT, 'boardname', 'parameter') - PARSE_BOARD = $(shell grep -Ev '^\#' $(BOARDS_TXT) | grep -E "^[ \t]*$(1).$(2)=" | cut -d = -f 2 | cut -d : -f 2) -endif - -# If NO_CORE is set, then we don't have to parse boards.txt file -# But the user might have to define MCU, F_CPU etc -ifeq ($(strip $(NO_CORE)),) - - # Select a core from the 'cores' directory. Two main values: 'arduino' or - # 'robot', but can also hold 'tiny', for example, if using - # https://code.google.com/p/arduino-tiny alternate core. - ifndef CORE - CORE = $(call PARSE_BOARD,$(BOARD_TAG),build.core) - $(call show_config_variable,CORE,[COMPUTED],(from build.core)) - else - $(call show_config_variable,CORE,[USER]) - endif - - # Which variant ? This affects the include path - ifndef VARIANT - VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.variant) - ifndef VARIANT - VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),build.variant) - endif - $(call show_config_variable,VARIANT,[COMPUTED],(from build.variant)) - else - $(call show_config_variable,VARIANT,[USER]) - endif - - # see if we are a caterina device like leonardo or micro - CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file)) - ifndef CATERINA - # 1.5+ method if not a submenu - CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.file)) - endif - ifndef CATERINA - # 1.0 method uses deprecated bootloader.path - CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.path)) - endif - - # processor stuff - ifndef MCU - MCU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.mcu) - ifndef MCU - MCU := $(call PARSE_BOARD,$(BOARD_TAG),build.mcu) - endif - endif - - ifndef F_CPU - F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.f_cpu) - ifndef F_CPU - F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),build.f_cpu) - endif - endif - - ifneq ($(CATERINA),) - # USB IDs for the caterina devices like leonardo or micro - ifndef USB_VID - USB_VID = $(call PARSE_BOARD,$(BOARD_TAG),build.vid) - endif - - ifndef USB_PID - USB_PID = $(call PARSE_BOARD,$(BOARD_TAG),build.pid) - endif - endif - - # normal programming info - ifndef AVRDUDE_ARD_PROGRAMMER - AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.protocol) - ifndef AVRDUDE_ARD_PROGRAMMER - AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),upload.protocol) - endif - endif - - ifndef AVRDUDE_ARD_BAUDRATE - AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.speed) - ifndef AVRDUDE_ARD_BAUDRATE - AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),upload.speed) - endif - endif - - # fuses if you're using e.g. ISP - ifndef ISP_LOCK_FUSE_PRE - ISP_LOCK_FUSE_PRE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.unlock_bits) - endif - - ifndef ISP_HIGH_FUSE - ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.high_fuses) - ifndef ISP_HIGH_FUSE - ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.high_fuses) - endif - endif - - ifndef ISP_LOW_FUSE - ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.low_fuses) - ifndef ISP_LOW_FUSE - ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.low_fuses) - endif - endif - - ifndef ISP_EXT_FUSE - ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.extended_fuses) - ifndef ISP_EXT_FUSE - ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.extended_fuses) - endif - endif - - ifndef BOOTLOADER_PATH - BOOTLOADER_PATH = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.path) - endif - - ifndef BOOTLOADER_FILE - BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file) - ifndef BOOTLOADER_FILE - BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.file) - endif - endif - - ifndef ISP_LOCK_FUSE_POST - ISP_LOCK_FUSE_POST = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.lock_bits) - endif - - ifndef HEX_MAXIMUM_SIZE - HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.maximum_size) - ifndef HEX_MAXIMUM_SIZE - HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),upload.maximum_size) - endif - endif - -endif - -# Everything gets built in here (include BOARD_TAG now) -ifndef OBJDIR - OBJDIR = build-$(BOARD_TAG) - ifdef BOARD_SUB - OBJDIR = build-$(BOARD_TAG)-$(BOARD_SUB) - endif - $(call show_config_variable,OBJDIR,[COMPUTED],(from BOARD_TAG)) -else - $(call show_config_variable,OBJDIR,[USER]) -endif - -# Now that we have ARDUINO_DIR, ARDMK_VENDOR, ARCHITECTURE and CORE, -# we can set ARDUINO_CORE_PATH. -ifndef ARDUINO_CORE_PATH - ifeq ($(strip $(CORE)),) - ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/cores/arduino - $(call show_config_variable,ARDUINO_CORE_PATH,[DEFAULT]) - else - ARDUINO_CORE_PATH = $(ALTERNATE_CORE_PATH)/cores/$(CORE) - ifeq ($(wildcard $(ARDUINO_CORE_PATH)),) - ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/cores/$(CORE) - $(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ARDUINO_DIR, BOARD_TAG and boards.txt)) - else - $(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH, BOARD_TAG and boards.txt)) - endif - endif -else - $(call show_config_variable,ARDUINO_CORE_PATH,[USER]) -endif - -######################################################################## -# Reset - -ifndef RESET_CMD - ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null) - ifndef ARD_RESET_ARDUINO - # same level as *.mk in bin directory when checked out from git - # or in $PATH when packaged - ARD_RESET_ARDUINO = $(ARDMK_DIR)/bin/ard-reset-arduino - endif - ifneq ($(CATERINA),) - ifneq (,$(findstring CYGWIN,$(shell uname -s))) - RESET_CMD = $(ARD_RESET_ARDUINO) --caterina $(ARD_RESET_OPTS) $(DEVICE_PATH) - else - RESET_CMD = $(ARD_RESET_ARDUINO) --caterina $(ARD_RESET_OPTS) $(call get_monitor_port) - endif - else - ifneq (,$(findstring CYGWIN,$(shell uname -s))) - RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(DEVICE_PATH) - else - RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port) - endif - endif -endif - -ifneq ($(CATERINA),) - ERROR_ON_CATERINA = $(error On $(BOARD_TAG), raw_xxx operation is not supported) -else - ERROR_ON_CATERINA = -endif - -######################################################################## -# Local sources - -LOCAL_C_SRCS ?= $(wildcard *.c) -LOCAL_CPP_SRCS ?= $(wildcard *.cpp) -LOCAL_CC_SRCS ?= $(wildcard *.cc) -LOCAL_PDE_SRCS ?= $(wildcard *.pde) -LOCAL_INO_SRCS ?= $(wildcard *.ino) -LOCAL_AS_SRCS ?= $(wildcard *.S) -LOCAL_SRCS = $(LOCAL_C_SRCS) $(LOCAL_CPP_SRCS) \ - $(LOCAL_CC_SRCS) $(LOCAL_PDE_SRCS) \ - $(LOCAL_INO_SRCS) $(LOCAL_AS_SRCS) -LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.c.o) $(LOCAL_CPP_SRCS:.cpp=.cpp.o) \ - $(LOCAL_CC_SRCS:.cc=.cc.o) $(LOCAL_PDE_SRCS:.pde=.pde.o) \ - $(LOCAL_INO_SRCS:.ino=.ino.o) $(LOCAL_AS_SRCS:.S=.S.o) -LOCAL_OBJS = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES)) - -ifeq ($(words $(LOCAL_SRCS)), 0) - $(error At least one source file (*.ino, *.pde, *.cpp, *c, *cc, *.S) is needed) -endif - -# CHK_SOURCES is used by flymake -# flymake creates a tmp file in the same directory as the file under edition -# we must skip the verification in this particular case -ifeq ($(strip $(CHK_SOURCES)),) - ifeq ($(strip $(NO_CORE)),) - - # Ideally, this should just check if there are more than one file - ifneq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 1) - ifeq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 0) - $(call show_config_info,No .pde or .ino files found. If you are compiling .c or .cpp files then you need to explicitly include Arduino header files) - else - #TODO: Support more than one file. https://github.com/sudar/Arduino-Makefile/issues/49 - $(error Need exactly one .pde or .ino file. This makefile doesn't support multiple .ino/.pde files yet) - endif - endif - - endif -endif - -# core sources -ifeq ($(strip $(NO_CORE)),) - ifdef ARDUINO_CORE_PATH - CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c) - CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/avr-libc/*.c) - CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp) - CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.S) - - ifneq ($(strip $(NO_CORE_MAIN_CPP)),) - CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS)) - $(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL]) - endif - - CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.c.o) $(CORE_CPP_SRCS:.cpp=.cpp.o) $(CORE_AS_SRCS:.S=.S.o) - CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, \ - $(OBJDIR)/core/%,$(CORE_OBJ_FILES)) - endif -else - $(call show_config_info,NO_CORE set so core library will not be built,[MANUAL]) -endif - - -######################################################################## -# Determine ARDUINO_LIBS automatically - -ifndef ARDUINO_LIBS - # automatically determine included libraries - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_DIR)/libraries/*)), \ - $(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS))) - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_SKETCHBOOK)/libraries/*)), \ - $(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS))) - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(USER_LIB_PATH)/*)), \ - $(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS))) - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_PLATFORM_LIB_PATH)/*)), \ - $(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS))) -endif - -######################################################################## -# Serial monitor (just a screen wrapper) - -# Quite how to construct the monitor command seems intimately tied -# to the command we're using (here screen). So, read the screen docs -# for more information (search for 'character special device'). - -ifeq ($(strip $(NO_CORE)),) - ifndef MONITOR_BAUDRATE - ifeq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 1) - SPEED = $(shell egrep -h 'Serial.begin *\([0-9]+\)' $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS) | sed -e 's/[^0-9]//g'| head -n1) - MONITOR_BAUDRATE = $(findstring $(SPEED),300 1200 2400 4800 9600 14400 19200 28800 38400 57600 115200) - endif - - ifeq ($(MONITOR_BAUDRATE),) - MONITOR_BAUDRATE = 9600 - $(call show_config_variable,MONITOR_BAUDRATE,[ASSUMED]) - else - $(call show_config_variable,MONITOR_BAUDRATE,[DETECTED], (in sketch)) - endif - else - $(call show_config_variable,MONITOR_BAUDRATE, [USER]) - endif - - ifndef MONITOR_CMD - MONITOR_CMD = screen - endif -endif - -######################################################################## -# Include Arduino Header file - -ifndef ARDUINO_HEADER - # We should check for Arduino version, not just the file extension - # because, a .pde file can be used in Arduino 1.0 as well - ifeq ($(shell expr $(ARDUINO_VERSION) '<' 100), 1) - ARDUINO_HEADER=WProgram.h - else - ARDUINO_HEADER=Arduino.h - endif -endif - -######################################################################## -# Rules for making stuff - -# The name of the main targets -TARGET_HEX = $(OBJDIR)/$(TARGET).hex -TARGET_ELF = $(OBJDIR)/$(TARGET).elf -TARGET_EEP = $(OBJDIR)/$(TARGET).eep -CORE_LIB = $(OBJDIR)/libcore.a - -# Names of executables - chipKIT needs to override all to set paths to PIC32 -# tools, and we can't use "?=" assignment because these are already implicitly -# defined by Make (e.g. $(CC) == cc). -ifndef OVERRIDE_EXECUTABLES - CC = $(AVR_TOOLS_PATH)/$(CC_NAME) - CXX = $(AVR_TOOLS_PATH)/$(CXX_NAME) - AS = $(AVR_TOOLS_PATH)/$(AS_NAME) - OBJCOPY = $(AVR_TOOLS_PATH)/$(OBJCOPY_NAME) - OBJDUMP = $(AVR_TOOLS_PATH)/$(OBJDUMP_NAME) - AR = $(AVR_TOOLS_PATH)/$(AR_NAME) - SIZE = $(AVR_TOOLS_PATH)/$(SIZE_NAME) - NM = $(AVR_TOOLS_PATH)/$(NM_NAME) -endif - -REMOVE = rm -rf -MV = mv -f -CAT = cat -ECHO = printf -MKDIR = mkdir -p - -# recursive wildcard function, call with params: -# - start directory (finished with /) or empty string for current dir -# - glob pattern -# (taken from http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html) -rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) - -# functions used to determine various properties of library -# called with library path. Needed because of differences between library -# layouts in arduino 1.0.x and 1.5.x. -# Assuming new 1.5.x layout when there is "src" subdirectory in main directory -# and library.properties file - -# Gets include flags for library -get_library_includes = $(if $(and $(wildcard $(1)/src), $(wildcard $(1)/library.properties)), \ - -I$(1)/src, \ - $(addprefix -I,$(1) $(wildcard $(1)/utility))) - -# Gets all sources with given extension (param2) for library (path = param1) -# for old (1.0.x) layout looks in . and "utility" directories -# for new (1.5.x) layout looks in src and recursively its subdirectories -get_library_files = $(if $(and $(wildcard $(1)/src), $(wildcard $(1)/library.properties)), \ - $(call rwildcard,$(1)/src/,*.$(2)), \ - $(wildcard $(1)/*.$(2) $(1)/utility/*.$(2))) - -# General arguments -USER_LIBS := $(sort $(wildcard $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS)))) -USER_LIB_NAMES := $(patsubst $(USER_LIB_PATH)/%,%,$(USER_LIBS)) - -# Let user libraries override system ones. -SYS_LIBS := $(sort $(wildcard $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(filter-out $(USER_LIB_NAMES),$(ARDUINO_LIBS))))) -SYS_LIB_NAMES := $(patsubst $(ARDUINO_LIB_PATH)/%,%,$(SYS_LIBS)) - -ifdef ARDUINO_PLATFORM_LIB_PATH - PLATFORM_LIBS := $(sort $(wildcard $(patsubst %,$(ARDUINO_PLATFORM_LIB_PATH)/%,$(filter-out $(USER_LIB_NAMES),$(ARDUINO_LIBS))))) - PLATFORM_LIB_NAMES := $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%,%,$(PLATFORM_LIBS)) -endif - - -# Error here if any are missing. -LIBS_NOT_FOUND = $(filter-out $(USER_LIB_NAMES) $(SYS_LIB_NAMES) $(PLATFORM_LIB_NAMES),$(ARDUINO_LIBS)) -ifneq (,$(strip $(LIBS_NOT_FOUND))) - ifdef ARDUINO_PLATFORM_LIB_PATH - $(error The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH, ARDUINO_LIB_PATH and ARDUINO_PLATFORM_LIB_PATH): $(LIBS_NOT_FOUND)) - else - $(error The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH and ARDUINO_LIB_PATH): $(LIBS_NOT_FOUND)) - endif -endif - -SYS_INCLUDES := $(foreach lib, $(SYS_LIBS), $(call get_library_includes,$(lib))) -USER_INCLUDES := $(foreach lib, $(USER_LIBS), $(call get_library_includes,$(lib))) -LIB_C_SRCS := $(foreach lib, $(SYS_LIBS), $(call get_library_files,$(lib),c)) -LIB_CPP_SRCS := $(foreach lib, $(SYS_LIBS), $(call get_library_files,$(lib),cpp)) -LIB_AS_SRCS := $(foreach lib, $(SYS_LIBS), $(call get_library_files,$(lib),S)) -USER_LIB_CPP_SRCS := $(foreach lib, $(USER_LIBS), $(call get_library_files,$(lib),cpp)) -USER_LIB_C_SRCS := $(foreach lib, $(USER_LIBS), $(call get_library_files,$(lib),c)) -USER_LIB_AS_SRCS := $(foreach lib, $(USER_LIBS), $(call get_library_files,$(lib),S)) -LIB_OBJS = $(patsubst $(ARDUINO_LIB_PATH)/%.c,$(OBJDIR)/libs/%.c.o,$(LIB_C_SRCS)) \ - $(patsubst $(ARDUINO_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.cpp.o,$(LIB_CPP_SRCS)) \ - $(patsubst $(ARDUINO_LIB_PATH)/%.S,$(OBJDIR)/libs/%.S.o,$(LIB_AS_SRCS)) -USER_LIB_OBJS = $(patsubst $(USER_LIB_PATH)/%.cpp,$(OBJDIR)/userlibs/%.cpp.o,$(USER_LIB_CPP_SRCS)) \ - $(patsubst $(USER_LIB_PATH)/%.c,$(OBJDIR)/userlibs/%.c.o,$(USER_LIB_C_SRCS)) \ - $(patsubst $(USER_LIB_PATH)/%.S,$(OBJDIR)/userlibs/%.S.o,$(USER_LIB_AS_SRCS)) - -ifdef ARDUINO_PLATFORM_LIB_PATH - PLATFORM_INCLUDES := $(foreach lib, $(PLATFORM_LIBS), $(call get_library_includes,$(lib))) - PLATFORM_LIB_CPP_SRCS := $(foreach lib, $(PLATFORM_LIBS), $(call get_library_files,$(lib),cpp)) - PLATFORM_LIB_C_SRCS := $(foreach lib, $(PLATFORM_LIBS), $(call get_library_files,$(lib),c)) - PLATFORM_LIB_AS_SRCS := $(foreach lib, $(PLATFORM_LIBS), $(call get_library_files,$(lib),S)) - PLATFORM_LIB_OBJS := $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.cpp,$(OBJDIR)/platformlibs/%.cpp.o,$(PLATFORM_LIB_CPP_SRCS)) \ - $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.c,$(OBJDIR)/platformlibs/%.c.o,$(PLATFORM_LIB_C_SRCS)) \ - $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.S,$(OBJDIR)/platformlibs/%.S.o,$(PLATFORM_LIB_AS_SRCS)) - -endif - -# Dependency files -DEPS = $(LOCAL_OBJS:.o=.d) $(LIB_OBJS:.o=.d) $(PLATFORM_OBJS:.o=.d) $(USER_LIB_OBJS:.o=.d) $(CORE_OBJS:.o=.d) - -# Optimization level for the compiler. -# You can get the list of options at http://www.nongnu.org/avr-libc/user-manual/using_tools.html#gcc_optO -# Also read http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_optflags -ifndef OPTIMIZATION_LEVEL - OPTIMIZATION_LEVEL=s - $(call show_config_variable,OPTIMIZATION_LEVEL,[DEFAULT]) -else - $(call show_config_variable,OPTIMIZATION_LEVEL,[USER]) -endif - -ifndef DEBUG_FLAGS - DEBUG_FLAGS = -O0 -g -endif - -# SoftwareSerial requires -Os (some delays are tuned for this optimization level) -%SoftwareSerial.cpp.o : OPTIMIZATION_FLAGS = -Os - -ifndef MCU_FLAG_NAME - MCU_FLAG_NAME = mmcu - $(call show_config_variable,MCU_FLAG_NAME,[DEFAULT]) -else - $(call show_config_variable,MCU_FLAG_NAME,[USER]) -endif - -# Using += instead of =, so that CPPFLAGS can be set per sketch level -CPPFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION) $(ARDUINO_ARCH_FLAG) -D__PROG_TYPES_COMPAT__ \ - -I$(ARDUINO_CORE_PATH) -I$(ARDUINO_VAR_PATH)/$(VARIANT) \ - $(SYS_INCLUDES) $(PLATFORM_INCLUDES) $(USER_INCLUDES) -Wall -ffunction-sections \ - -fdata-sections - -ifdef DEBUG -OPTIMIZATION_FLAGS= $(DEBUG_FLAGS) -else -OPTIMIZATION_FLAGS = -O$(OPTIMIZATION_LEVEL) -endif - -CPPFLAGS += $(OPTIMIZATION_FLAGS) - -# USB IDs for the Caterina devices like leonardo or micro -ifneq ($(CATERINA),) - CPPFLAGS += -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID) -endif - -# avr-gcc version that we can do maths on -CC_VERNUM = $(shell $(CC) -dumpversion | sed 's/\.//g') - -# moved from above so we can find version-dependant ar -ifndef AR_NAME - ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - AR_NAME = avr-gcc-ar - else - AR_NAME = avr-ar - endif -endif - -ifndef CFLAGS_STD - ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - CFLAGS_STD = -std=gnu11 -flto -fno-fat-lto-objects - else - CFLAGS_STD = - endif - $(call show_config_variable,CFLAGS_STD,[DEFAULT]) -else - $(call show_config_variable,CFLAGS_STD,[USER]) -endif - -ifndef CXXFLAGS_STD - ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics -flto - else - CXXFLAGS_STD = - endif - $(call show_config_variable,CXXFLAGS_STD,[DEFAULT]) -else - $(call show_config_variable,CXXFLAGS_STD,[USER]) -endif - -CFLAGS += $(CFLAGS_STD) -CXXFLAGS += -fpermissive -fno-exceptions $(CXXFLAGS_STD) -ASFLAGS += -x assembler-with-cpp -ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - ASFLAGS += -flto -endif -LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL) -ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - LDFLAGS += -flto -fuse-linker-plugin -endif -SIZEFLAGS ?= --mcu=$(MCU) -C - -# for backwards compatibility, grab ARDUINO_PORT if the user has it set -# instead of MONITOR_PORT -MONITOR_PORT ?= $(ARDUINO_PORT) - -ifneq ($(strip $(MONITOR_PORT)),) - ifeq ($(CURRENT_OS), WINDOWS) - # Expect MONITOR_PORT to be '1' or 'com1' for COM1 in Windows. Split it up - # into the two styles required: /dev/ttyS* for ard-reset-arduino and com* - # for avrdude. This also could work with /dev/com* device names and be more - # consistent, but the /dev/com* is not recommended by Cygwin and doesn't - # always show up. - COM_PORT_ID = $(subst com,,$(MONITOR_PORT)) - COM_STYLE_MONITOR_PORT = com$(COM_PORT_ID) - DEVICE_PATH = /dev/ttyS$(shell awk 'BEGIN{ print $(COM_PORT_ID) - 1 }') - else - # set DEVICE_PATH based on user-defined MONITOR_PORT or ARDUINO_PORT - DEVICE_PATH = $(MONITOR_PORT) - endif - $(call show_config_variable,DEVICE_PATH,[COMPUTED],(from MONITOR_PORT)) -else - # If no port is specified, try to guess it from wildcards. - # Will only work if the Arduino is the only/first device matched. - DEVICE_PATH = $(firstword $(wildcard \ - /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem* /dev/tty.wchusbserial*)) - $(call show_config_variable,DEVICE_PATH,[AUTODETECTED]) -endif - -ifndef FORCE_MONITOR_PORT - $(call show_config_variable,FORCE_MONITOR_PORT,[DEFAULT]) -else - $(call show_config_variable,FORCE_MONITOR_PORT,[USER]) -endif - -ifdef FORCE_MONITOR_PORT - # Skips the DEVICE_PATH existance check. - get_monitor_port = $(DEVICE_PATH) -else - # Returns the Arduino port (first wildcard expansion) if it exists, otherwise it errors. - ifeq ($(CURRENT_OS), WINDOWS) - get_monitor_port = $(COM_STYLE_MONITOR_PORT) - else - get_monitor_port = $(if $(wildcard $(DEVICE_PATH)),$(firstword $(wildcard $(DEVICE_PATH))),$(error Arduino port $(DEVICE_PATH) not found!)) - endif -endif - -# Returns the ISP port (first wildcard expansion) if it exists, otherwise it errors. -get_isp_port = $(if $(wildcard $(ISP_PORT)),$(firstword $(wildcard $(ISP_PORT))),$(if $(findstring Xusb,X$(ISP_PORT)),$(ISP_PORT),$(error ISP port $(ISP_PORT) not found!))) - -# Command for avr_size: do $(call avr_size,elffile,hexfile) -ifneq (,$(findstring AVR,$(shell $(SIZE) --help))) - # We have a patched version of binutils that mentions AVR - pass the MCU - # and the elf to get nice output. - avr_size = $(SIZE) $(SIZEFLAGS) --format=avr $(1) - $(call show_config_info,Size utility: AVR-aware for enhanced output,[AUTODETECTED]) -else - # We have a plain-old binutils version - just give it the hex. - avr_size = $(SIZE) $(2) - $(call show_config_info,Size utility: Basic (not AVR-aware),[AUTODETECTED]) -endif - -ifneq (,$(strip $(ARDUINO_LIBS))) - $(call arduino_output,-) - $(call show_config_info,ARDUINO_LIBS =) -endif - -ifneq (,$(strip $(USER_LIB_NAMES))) - $(foreach lib,$(USER_LIB_NAMES),$(call show_config_info, $(lib),[USER])) -endif - -ifneq (,$(strip $(SYS_LIB_NAMES))) - $(foreach lib,$(SYS_LIB_NAMES),$(call show_config_info, $(lib),[SYSTEM])) -endif - -ifneq (,$(strip $(PLATFORM_LIB_NAMES))) - $(foreach lib,$(PLATFORM_LIB_NAMES),$(call show_config_info, $(lib),[PLATFORM])) -endif - -# either calculate parent dir from arduino dir, or user-defined path -ifndef BOOTLOADER_PARENT - BOOTLOADER_PARENT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/bootloaders - $(call show_config_variable,BOOTLOADER_PARENT,[COMPUTED],(from ARDUINO_DIR)) -else - $(call show_config_variable,BOOTLOADER_PARENT,[USER]) -endif - -######################################################################## -# Tools version info -ARDMK_VERSION = 1.5 -$(call show_config_variable,ARDMK_VERSION,[COMPUTED]) - -CC_VERSION := $(shell $(CC) -dumpversion) -$(call show_config_variable,CC_VERSION,[COMPUTED],($(CC_NAME))) - -# end of config output -$(call show_separator) - -# Implicit rules for building everything (needed to get everything in -# the right directory) -# -# Rather than mess around with VPATH there are quasi-duplicate rules -# here for building e.g. a system C++ file and a local C++ -# file. Besides making things simpler now, this would also make it -# easy to change the build options in future - -# library sources -$(OBJDIR)/libs/%.c.o: $(ARDUINO_LIB_PATH)/%.c - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -$(OBJDIR)/libs/%.cpp.o: $(ARDUINO_LIB_PATH)/%.cpp - @$(MKDIR) $(dir $@) - $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/libs/%.S.o: $(ARDUINO_LIB_PATH)/%.S - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ - -$(OBJDIR)/platformlibs/%.c.o: $(ARDUINO_PLATFORM_LIB_PATH)/%.c - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -$(OBJDIR)/platformlibs/%.cpp.o: $(ARDUINO_PLATFORM_LIB_PATH)/%.cpp - @$(MKDIR) $(dir $@) - $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/platformlibs/%.S.o: $(ARDUINO_PLATFORM_LIB_PATH)/%.S - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ - -$(OBJDIR)/userlibs/%.cpp.o: $(USER_LIB_PATH)/%.cpp - @$(MKDIR) $(dir $@) - $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/userlibs/%.c.o: $(USER_LIB_PATH)/%.c - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -$(OBJDIR)/userlibs/%.S.o: $(USER_LIB_PATH)/%.S - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ - -ifdef COMMON_DEPS - COMMON_DEPS := $(COMMON_DEPS) $(MAKEFILE_LIST) -else - COMMON_DEPS := $(MAKEFILE_LIST) -endif - -# normal local sources -$(OBJDIR)/%.c.o: %.c $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -$(OBJDIR)/%.cc.o: %.cc $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/%.cpp.o: %.cpp $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/%.S.o: %.S $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ - -$(OBJDIR)/%.s.o: %.s $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ - -# the pde -> o file -$(OBJDIR)/%.pde.o: %.pde $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -# the ino -> o file -$(OBJDIR)/%.ino.o: %.ino $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -# generated assembly -$(OBJDIR)/%.s: %.pde $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/%.s: %.ino $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/%.s: %.cpp $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -# core files -$(OBJDIR)/core/%.c.o: $(ARDUINO_CORE_PATH)/%.c $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -$(OBJDIR)/core/%.cpp.o: $(ARDUINO_CORE_PATH)/%.cpp $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -$(OBJDIR)/core/%.S.o: $(ARDUINO_CORE_PATH)/%.S $(COMMON_DEPS) | $(OBJDIR) - @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ - -# various object conversions -$(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(COMMON_DEPS) - @$(MKDIR) $(dir $@) - $(OBJCOPY) -O ihex -R .eeprom $< $@ - @$(ECHO) '\n' - $(call avr_size,$<,$@) -ifneq ($(strip $(HEX_MAXIMUM_SIZE)),) - @if [ `$(SIZE) $@ | awk 'FNR == 2 {print $$2}'` -le $(HEX_MAXIMUM_SIZE) ]; then touch $@.sizeok; fi -else - @$(ECHO) "Maximum flash memory of $(BOARD_TAG) is not specified. Make sure the size of $@ is less than $(BOARD_TAG)\'s flash memory" - @touch $@.sizeok -endif - -$(OBJDIR)/%.eep: $(OBJDIR)/%.elf $(COMMON_DEPS) - @$(MKDIR) $(dir $@) - -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom='alloc,load' \ - --no-change-warnings --change-section-lma .eeprom=0 -O ihex $< $@ - -$(OBJDIR)/%.lss: $(OBJDIR)/%.elf $(COMMON_DEPS) - @$(MKDIR) $(dir $@) - $(OBJDUMP) -h --source --demangle --wide $< > $@ - -$(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS) - @$(MKDIR) $(dir $@) - $(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@ - -######################################################################## -# Avrdude - -# If avrdude is installed separately, it can find its own config file -ifndef AVRDUDE - AVRDUDE = $(AVR_TOOLS_PATH)/avrdude -endif - -# Default avrdude options -# -V Do not verify -# -q - suppress progress output -ifndef AVRDUDE_OPTS - AVRDUDE_OPTS = -q -V -endif - -# Decouple the mcu between the compiler options (-mmcu) and the avrdude options (-p). -# This is needed to be able to compile for attiny84a but specify the upload mcu as attiny84. -# We default to picking the -mmcu flag, but you can override this by setting -# AVRDUDE_MCU in your makefile. -ifndef AVRDUDE_MCU - AVRDUDE_MCU = $(MCU) -endif - -AVRDUDE_COM_OPTS = $(AVRDUDE_OPTS) -p $(AVRDUDE_MCU) -ifdef AVRDUDE_CONF - AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF) -endif - -# -D - Disable auto erase for flash memory -# Note: -D is needed for Mega boards. -# (See https://github.com/sudar/Arduino-Makefile/issues/114#issuecomment-25011005) -AVRDUDE_ARD_OPTS = -D -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P -ifeq ($(CURRENT_OS), WINDOWS) - # get_monitor_port checks to see if the monitor port exists, assuming it is - # a file. In Windows, avrdude needs the port in the format 'com1' which is - # not a file, so we have to add the COM-style port directly. - AVRDUDE_ARD_OPTS += $(COM_STYLE_MONITOR_PORT) -else - AVRDUDE_ARD_OPTS += $(call get_monitor_port) -endif - -ifndef ISP_PROG - ifneq ($(strip $(AVRDUDE_ARD_PROGRAMMER)),) - ISP_PROG = $(AVRDUDE_ARD_PROGRAMMER) - else - ISP_PROG = stk500v1 - endif -endif - -ifndef AVRDUDE_ISP_BAUDRATE - ifneq ($(strip $(AVRDUDE_ARD_BAUDRATE)),) - AVRDUDE_ISP_BAUDRATE = $(AVRDUDE_ARD_BAUDRATE) - else - AVRDUDE_ISP_BAUDRATE = 19200 - endif -endif - -# Fuse settings copied from Arduino IDE. -# https://github.com/arduino/Arduino/blob/master/app/src/processing/app/debug/AvrdudeUploader.java#L254 - -# Pre fuse settings -ifndef AVRDUDE_ISP_FUSES_PRE - ifneq ($(strip $(ISP_LOCK_FUSE_PRE)),) - AVRDUDE_ISP_FUSES_PRE += -U lock:w:$(ISP_LOCK_FUSE_PRE):m - endif - - ifneq ($(strip $(ISP_EXT_FUSE)),) - AVRDUDE_ISP_FUSES_PRE += -U efuse:w:$(ISP_EXT_FUSE):m - endif - - ifneq ($(strip $(ISP_HIGH_FUSE)),) - AVRDUDE_ISP_FUSES_PRE += -U hfuse:w:$(ISP_HIGH_FUSE):m - endif - - ifneq ($(strip $(ISP_LOW_FUSE)),) - AVRDUDE_ISP_FUSES_PRE += -U lfuse:w:$(ISP_LOW_FUSE):m - endif -endif - -# Bootloader file settings -ifndef AVRDUDE_ISP_BURN_BOOTLOADER - ifneq ($(strip $(BOOTLOADER_FILE)),) - AVRDUDE_ISP_BURN_BOOTLOADER += -U flash:w:$(BOOTLOADER_PARENT)/$(BOOTLOADER_PATH)/$(BOOTLOADER_FILE):i - endif -endif - -# Post fuse settings -ifndef AVRDUDE_ISP_FUSES_POST - ifneq ($(strip $(ISP_LOCK_FUSE_POST)),) - AVRDUDE_ISP_FUSES_POST += -U lock:w:$(ISP_LOCK_FUSE_POST):m - endif -endif - -# Note: setting -D to disable flash erase before programming may cause issues -# with some boards like attiny84a, making the program not "take", -# so we do not set it by default. -AVRDUDE_ISP_OPTS = -c $(ISP_PROG) -b $(AVRDUDE_ISP_BAUDRATE) - -ifndef $(ISP_PORT) - ifneq ($(strip $(ISP_PROG)),$(filter $(ISP_PROG), usbasp usbtiny gpio linuxgpio avrispmkii dragon_isp dragon_dw)) - AVRDUDE_ISP_OPTS += -P $(call get_isp_port) - endif -else - AVRDUDE_ISP_OPTS += -P $(call get_isp_port) -endif - -ifndef ISP_EEPROM - ISP_EEPROM = 0 -endif - -AVRDUDE_UPLOAD_HEX = -U flash:w:$(TARGET_HEX):i -AVRDUDE_UPLOAD_EEP = -U eeprom:w:$(TARGET_EEP):i -AVRDUDE_ISPLOAD_OPTS = $(AVRDUDE_UPLOAD_HEX) - -ifneq ($(ISP_EEPROM), 0) - AVRDUDE_ISPLOAD_OPTS += $(AVRDUDE_UPLOAD_EEP) -endif - -######################################################################## -# Explicit targets start here - -all: $(TARGET_EEP) $(TARGET_HEX) - -# Rule to create $(OBJDIR) automatically. All rules with recipes that -# create a file within it, but do not already depend on a file within it -# should depend on this rule. They should use a "order-only -# prerequisite" (e.g., put "| $(OBJDIR)" at the end of the prerequisite -# list) to prevent remaking the target when any file in the directory -# changes. -$(OBJDIR): pre-build - $(MKDIR) $(OBJDIR) - -pre-build: - $(call runscript_if_exists,$(PRE_BUILD_HOOK)) - -$(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) - $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(OTHER_LIBS) -lc -lm $(LINKER_SCRIPTS) - -$(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS) - $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS) - -error_on_caterina: - $(ERROR_ON_CATERINA) - - -# Use submake so we can guarantee the reset happens -# before the upload, even with make -j -upload: $(TARGET_HEX) verify_size - $(MAKE) reset - $(MAKE) do_upload - -raw_upload: $(TARGET_HEX) verify_size - $(MAKE) error_on_caterina - $(MAKE) do_upload - -do_upload: - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ - $(AVRDUDE_UPLOAD_HEX) - -do_eeprom: $(TARGET_EEP) $(TARGET_HEX) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ - $(AVRDUDE_UPLOAD_EEP) - -eeprom: $(TARGET_HEX) verify_size - $(MAKE) reset - $(MAKE) do_eeprom - -raw_eeprom: $(TARGET_HEX) verify_size - $(MAKE) error_on_caterina - $(MAKE) do_eeprom - -reset: - $(call arduino_output,Resetting Arduino...) - $(RESET_CMD) - -# stty on MacOS likes -F, but on Debian it likes -f redirecting -# stdin/out appears to work but generates a spurious error on MacOS at -# least. Perhaps it would be better to just do it in perl ? -reset_stty: - for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \ - do $$STTYF /dev/tty >/dev/null 2>&1 && break ; \ - done ; \ - $$STTYF $(call get_monitor_port) hupcl ; \ - (sleep 0.1 2>/dev/null || sleep 1) ; \ - $$STTYF $(call get_monitor_port) -hupcl - -ispload: $(TARGET_EEP) $(TARGET_HEX) verify_size - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \ - $(AVRDUDE_ISPLOAD_OPTS) - -burn_bootloader: -ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE) -endif -ifneq ($(strip $(AVRDUDE_ISP_BURN_BOOTLOADER)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_BURN_BOOTLOADER) -endif -ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST) -endif - -set_fuses: -ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE) -endif -ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST) -endif - -clean:: - $(REMOVE) $(OBJDIR) - -size: $(TARGET_HEX) - $(call avr_size,$(TARGET_ELF),$(TARGET_HEX)) - -show_boards: - @$(CAT) $(BOARDS_TXT) | grep -E '^[a-zA-Z0-9_\-]+.name' | sort -uf | sed 's/.name=/:/' | column -s: -t - -show_submenu: - @$(CAT) $(BOARDS_TXT) | grep -E '[a-zA-Z0-9_\-]+.menu.(cpu|chip).[a-zA-Z0-9_\-]+=' | sort -uf | sed 's/.menu.(cpu|chip)./:/' | sed 's/=/:/' | column -s: -t - -monitor: -ifeq ($(MONITOR_CMD), 'putty') - ifneq ($(strip $(MONITOR_PARMS)),) - $(MONITOR_CMD) -serial -sercfg $(MONITOR_BAUDRATE),$(MONITOR_PARMS) $(call get_monitor_port) - else - $(MONITOR_CMD) -serial -sercfg $(MONITOR_BAUDRATE) $(call get_monitor_port) - endif -else ifeq ($(MONITOR_CMD), picocom) - $(MONITOR_CMD) -b $(MONITOR_BAUDRATE) $(MONITOR_PARAMS) $(call get_monitor_port) -else - $(MONITOR_CMD) $(call get_monitor_port) $(MONITOR_BAUDRATE) -endif - -disasm: $(OBJDIR)/$(TARGET).lss - @$(ECHO) "The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss\n\n" - -symbol_sizes: $(OBJDIR)/$(TARGET).sym - @$(ECHO) "A symbol listing sorted by their size have been dumped to $(OBJDIR)/$(TARGET).sym\n\n" - -verify_size: -ifeq ($(strip $(HEX_MAXIMUM_SIZE)),) - @$(ECHO) "\nMaximum flash memory of $(BOARD_TAG) is not specified. Make sure the size of $(TARGET_HEX) is less than $(BOARD_TAG)\'s flash memory\n\n" -endif - @if [ ! -f $(TARGET_HEX).sizeok ]; then echo >&2 "\nThe size of the compiled binary file is greater than the $(BOARD_TAG)'s flash memory. \ -See http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."; false; fi - -generate_assembly: $(OBJDIR)/$(TARGET).s - @$(ECHO) "Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s\n\n" - -generated_assembly: generate_assembly - @$(ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead\n\n" - -help_vars: - @$(CAT) $(ARDMK_DIR)/arduino-mk-vars.md - -help: - @$(ECHO) "\nAvailable targets:\n\ - make - compile the code\n\ - make upload - upload\n\ - make ispload - upload using an ISP\n\ - make raw_upload - upload without first resetting\n\ - make eeprom - upload the eep file\n\ - make raw_eeprom - upload the eep file without first resetting\n\ - make clean - remove all our dependencies\n\ - make depends - update dependencies\n\ - make reset - reset the Arduino by tickling DTR or changing baud\n\ - rate on the serial port.\n\ - make show_boards - list all the boards defined in boards.txt\n\ - make show_submenu - list all board submenus defined in boards.txt\n\ - make monitor - connect to the Arduino's serial port\n\ - make size - show the size of the compiled output (relative to\n\ - resources, if you have a patched avr-size).\n\ - make verify_size - verify that the size of the final file is less than\n\ - the capacity of the micro controller.\n\ - make symbol_sizes - generate a .sym file containing symbols and their\n\ - sizes.\n\ - make disasm - generate a .lss file that contains disassembly\n\ - of the compiled file interspersed with your\n\ - original source code.\n\ - make generate_assembly - generate a .s file containing the compiler\n\ - generated assembly of the main sketch.\n\ - make burn_bootloader - burn bootloader and fuses\n\ - make set_fuses - set fuses without burning bootloader\n\ - make help_vars - print all variables that can be overridden\n\ - make help - show this help\n\ -" - @$(ECHO) "Please refer to $(ARDMK_DIR)/Arduino.mk for more details.\n" - -.PHONY: all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \ - clean depends size show_boards monitor disasm symbol_sizes generated_assembly \ - generate_assembly verify_size burn_bootloader help pre-build - -# added - in the beginning, so that we don't get an error if the file is not present --include $(DEPS) diff --git a/Common.mk b/Common.mk deleted file mode 100644 index 7eda5ea1..00000000 --- a/Common.mk +++ /dev/null @@ -1,87 +0,0 @@ -# Useful functions -# Returns the first argument (typically a directory), if the file or directory -# named by concatenating the first and optionally second argument -# (directory and optional filename) exists -dir_if_exists = $(if $(wildcard $(1)$(2)),$(1)) - -# Run a shell script if it exists. Stops make on error. -runscript_if_exists = \ - $(if $(wildcard $(1)), \ - $(if $(findstring 0, \ - $(lastword $(shell $(abspath $(wildcard $(1))); echo $$?))), \ - $(info Info: $(1) success), \ - $(error ERROR: $(1) failed))) - -# For message printing: pad the right side of the first argument with spaces to -# the number of bytes indicated by the second argument. -space_pad_to = $(shell echo $(1) " " | head -c$(2)) - -# Call with some text, and a prefix tag if desired (like [AUTODETECTED]), -show_config_info = $(call arduino_output,- $(call space_pad_to,$(2),20) $(1)) - -# Call with the name of the variable, a prefix tag if desired (like [AUTODETECTED]), -# and an explanation if desired (like (found in $$PATH) -show_config_variable = $(call show_config_info,$(1) = $($(1)) $(3),$(2)) - -# Just a nice simple visual separator -show_separator = $(call arduino_output,-------------------------) - -$(call show_separator) -$(call arduino_output,Arduino.mk Configuration:) - -######################################################################## -# -# Detect OS -ifeq ($(OS),Windows_NT) - CURRENT_OS = WINDOWS -else - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - CURRENT_OS = LINUX - endif - ifeq ($(UNAME_S),Darwin) - CURRENT_OS = MAC - endif -endif -$(call show_config_variable,CURRENT_OS,[AUTODETECTED]) - -######################################################################## -# -# Travis-CI -ifneq ($(TEST),) - DEPENDENCIES_DIR = /var/tmp/Arduino-Makefile-testing-dependencies - - DEPENDENCIES_MPIDE_DIR = $(DEPENDENCIES_DIR)/mpide-0023-linux64-20130817-test - ifeq ($(MPIDE_DIR),) - MPIDE_DIR = $(DEPENDENCIES_MPIDE_DIR) - endif - - DEPENDENCIES_ARDUINO_DIR = $(DEPENDENCIES_DIR)/arduino-1.0.6 - ifeq ($(ARDUINO_DIR),) - ARDUINO_DIR = $(DEPENDENCIES_ARDUINO_DIR) - endif -endif - -######################################################################## -# Arduino Directory - -ifndef ARDUINO_DIR - AUTO_ARDUINO_DIR := $(firstword \ - $(call dir_if_exists,/usr/share/arduino) \ - $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) \ - $(call dir_if_exists,/Applications/Arduino.app/Contents/Java) ) - ifdef AUTO_ARDUINO_DIR - ARDUINO_DIR = $(AUTO_ARDUINO_DIR) - $(call show_config_variable,ARDUINO_DIR,[AUTODETECTED]) - else - echo $(error "ARDUINO_DIR is not defined") - endif -else - $(call show_config_variable,ARDUINO_DIR,[USER]) -endif - -ifeq ($(CURRENT_OS),WINDOWS) - ifneq ($(shell echo $(ARDUINO_DIR) | egrep '^(/|[a-zA-Z]:\\)'),) - echo $(error On Windows, ARDUINO_DIR must be a relative path) - endif -endif diff --git a/OpenSprinkler.cpp b/OpenSprinkler.cpp index fa290eac..f7a6ab29 100644 --- a/OpenSprinkler.cpp +++ b/OpenSprinkler.cpp @@ -783,8 +783,12 @@ void OpenSprinkler::begin() { PIN_SENSOR1 = V1_PIN_SENSOR1; PIN_SENSOR2 = V1_PIN_SENSOR2; } else { - // revision 2 - hw_rev = 2; + // revision 2 and 3 + if(detect_i2c(EEPROM_I2CADDR)) { // revision 3 has a I2C EEPROM + hw_rev = 3; + } else { + hw_rev = 2; + } mainio->i2c_write(NXP_CONFIG_REG, V2_IO_CONFIG); mainio->i2c_write(NXP_OUTPUT_REG, V2_IO_OUTPUT); @@ -1058,7 +1062,7 @@ void OpenSprinkler::latch_setzoneoutput_v2(byte sid, byte A, byte K) { * */ void OpenSprinkler::latch_open(byte sid) { - if(hw_rev==2) { + if(hw_rev>=2) { DEBUG_PRINTLN(F("latch_open_v2")); latch_disable_alloutputs_v2(); // disable all output pins latch_boost(); // generate boost voltage @@ -1081,7 +1085,7 @@ void OpenSprinkler::latch_open(byte sid) { } void OpenSprinkler::latch_close(byte sid) { - if(hw_rev==2) { + if(hw_rev>=2) { DEBUG_PRINTLN(F("latch_close_v2")); latch_disable_alloutputs_v2(); // disable all output pins latch_boost(); // generate boost voltage @@ -1248,7 +1252,7 @@ void OpenSprinkler::apply_all_station_bits() { void OpenSprinkler::detect_binarysensor_status(ulong curr_time) { // sensor_type: 0 if normally closed, 1 if normally open if(iopts[IOPT_SENSOR1_TYPE]==SENSOR_TYPE_RAIN || iopts[IOPT_SENSOR1_TYPE]==SENSOR_TYPE_SOIL) { - if(hw_rev==2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2 + if(hw_rev>=2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2 byte val = digitalReadExt(PIN_SENSOR1); status.sensor1 = (val == iopts[IOPT_SENSOR1_OPTION]) ? 0 : 1; if(status.sensor1) { @@ -1278,7 +1282,7 @@ void OpenSprinkler::detect_binarysensor_status(ulong curr_time) { // ESP8266 is guaranteed to have sensor 2 #if defined(ESP8266) || defined(PIN_SENSOR2) if(iopts[IOPT_SENSOR2_TYPE]==SENSOR_TYPE_RAIN || iopts[IOPT_SENSOR2_TYPE]==SENSOR_TYPE_SOIL) { - if(hw_rev==2) pinModeExt(PIN_SENSOR2, INPUT_PULLUP); // this seems necessary for OS 3.2 + if(hw_rev>=2) pinModeExt(PIN_SENSOR2, INPUT_PULLUP); // this seems necessary for OS 3.2 byte val = digitalReadExt(PIN_SENSOR2); status.sensor2 = (val == iopts[IOPT_SENSOR2_OPTION]) ? 0 : 1; if(status.sensor2) { @@ -1313,7 +1317,7 @@ byte OpenSprinkler::detect_programswitch_status(ulong curr_time) { byte ret = 0; if(iopts[IOPT_SENSOR1_TYPE]==SENSOR_TYPE_PSWITCH) { static byte sensor1_hist = 0; - if(hw_rev==2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2 + if(hw_rev>=2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2 status.sensor1 = (digitalReadExt(PIN_SENSOR1) != iopts[IOPT_SENSOR1_OPTION]); // is switch activated? sensor1_hist = (sensor1_hist<<1) | status.sensor1; // basic noise filtering: only trigger if sensor matches pattern: @@ -1325,7 +1329,7 @@ byte OpenSprinkler::detect_programswitch_status(ulong curr_time) { #if defined(ESP8266) || defined(PIN_SENSOR2) if(iopts[IOPT_SENSOR2_TYPE]==SENSOR_TYPE_PSWITCH) { static byte sensor2_hist = 0; - if(hw_rev==2) pinModeExt(PIN_SENSOR2, INPUT_PULLUP); // this seems necessary for OS 3.2 + if(hw_rev>=2) pinModeExt(PIN_SENSOR2, INPUT_PULLUP); // this seems necessary for OS 3.2 status.sensor2 = (digitalReadExt(PIN_SENSOR2) != iopts[IOPT_SENSOR2_OPTION]); // is sensor activated? sensor2_hist = (sensor2_hist<<1) | status.sensor2; if((sensor2_hist&0b1111) == 0b0011) { diff --git a/OpenSprinkler.h b/OpenSprinkler.h index f5d4771b..c4225b89 100644 --- a/OpenSprinkler.h +++ b/OpenSprinkler.h @@ -41,6 +41,7 @@ #include #include #include + #include #include #include #include diff --git a/defines.h b/defines.h index cb9758cf..577f4c6e 100755 --- a/defines.h +++ b/defines.h @@ -36,7 +36,7 @@ typedef unsigned long ulong; // if this number is different from the one stored in non-volatile memory // a device reset will be automatically triggered -#define OS_FW_MINOR 1 // Firmware minor version +#define OS_FW_MINOR 2 // Firmware minor version /** Hardware version base numbers */ #define OS_HW_VERSION_BASE 0x00 // OpenSprinkler @@ -332,6 +332,7 @@ enum { #define LADR_I2CADDR 0x23 // latch driver I2C address #define EXP_I2CADDR_BASE 0x24 // base of expander I2C address #define LCD_I2CADDR 0x3C // 128x64 OLED display I2C address + #define EEPROM_I2CADDR 0x50 // 24C02 EEPROM I2C address #define PIN_CURR_SENSE A0 #define PIN_FREE_LIST {} // no free GPIO pin at the moment diff --git a/main.cpp b/main.cpp index 32086901..3ce0abd5 100644 --- a/main.cpp +++ b/main.cpp @@ -89,7 +89,7 @@ uint32_t reboot_timer = 0; void flow_poll() { #if defined(ESP8266) - if(os.hw_rev == 2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2 + if(os.hw_rev>=2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2 #endif byte curr_flow_state = digitalReadExt(PIN_SENSOR1); if(!(prev_flow_state==HIGH && curr_flow_state==LOW)) { // only record on falling edge @@ -615,7 +615,7 @@ void do_loop() if (curr_time != last_time) { #if defined(ESP8266) - if(os.hw_rev==2) { + if(os.hw_rev>=2) { pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2 pinModeExt(PIN_SENSOR2, INPUT_PULLUP); } diff --git a/make.lin302 b/make.lin302 deleted file mode 100644 index 81501fdf..00000000 --- a/make.lin302 +++ /dev/null @@ -1,34 +0,0 @@ -SKETCH = ./mainArduino.ino -LIBS = . \ - $(ESP_LIBS)/Wire \ - $(ESP_LIBS)/SPI \ - $(ESP_LIBS)/ESP8266WiFi \ - $(ESP_LIBS)/ESP8266WebServer \ - $(ESP_LIBS)/ESP8266mDNS \ - $(ESP_LIBS)/LittleFS \ - $(ESP_LIBS)/lwIP_enc28j60 \ - $(ESP_LIBS)/Ticker \ - $(ESP_LIBS)/DNSServer \ - $(HOME)/Arduino/libraries/SSD1306 \ - $(HOME)/Arduino/libraries/rc-switch \ - $(HOME)/Arduino/libraries/pubsubclient \ - $(HOME)/Arduino/libraries/OTF-Controller-Library \ - $(HOME)/Arduino/libraries/WebSockets \ - -ESP_ROOT = $(HOME)/esp8266_3.0/ -ESPCORE_VERSION = 302 -BUILD_ROOT = /tmp/$(MAIN_NAME) - -UPLOAD_SPEED = 460800 -UPLOAD_VERB = -v - -FLASH_DEF = 4M2M -FLASH_MODE = dio -FLASH_SPEED = 80 -F_CPU = 160000000L - -BOARD = generic - -EXCLUDE_DIRS = ./build-1284 - -include ./makeEspArduino.mk diff --git a/make.lin32 b/make.lin32 deleted file mode 100644 index 26606dbd..00000000 --- a/make.lin32 +++ /dev/null @@ -1,33 +0,0 @@ -SKETCH = ./mainArduino.ino -LIBS = . \ - $(ESP_LIBS)/Wire \ - $(ESP_LIBS)/SPI \ - $(ESP_LIBS)/ESP8266WiFi \ - $(ESP_LIBS)/ESP8266WebServer \ - $(ESP_LIBS)/ESP8266mDNS \ - ~/Arduino/libraries/SSD1306 \ - ~/Arduino/libraries/rc-switch \ - ~/Arduino/libraries/UIPEthernet \ - ~/Arduino/libraries/pubsubclient \ - -ESP_ROOT = $(HOME)/esp8266_2.7.4/ -ESPCORE_VERSION = 274 -BUILD_ROOT = /tmp/$(MAIN_NAME) - -UPLOAD_SPEED = 460800 -UPLOAD_VERB = -v -# for OS3.0 revision 1: reset mode is nodemcu -#UPLOAD_RESET = nodemcu -# Uncomment the line below for OS3.0 revision 0: reset mode is ck -# UPLOAD_RESET = ck - -FLASH_DEF = 4M3M -FLASH_MODE = dio -FLASH_SPEED = 80 -F_CPU = 160000000L - -BOARD = generic - -EXCLUDE_DIRS = ./build-1284 - -include ./makeEspArduino.mk diff --git a/make.os23 b/make.os23 deleted file mode 100644 index 47c3673e..00000000 --- a/make.os23 +++ /dev/null @@ -1,15 +0,0 @@ -OFLAG = -Os -ARDMK_DIR = . -ARDUINO_DIR = $(HOME)/arduino-1.8.15 -ALTERNATE_CORE_PATH = $(HOME)/.arduino15/packages/MightyCore/hardware/avr/2.0.5 -# If compiling on macOS, use the following instead -#ARDUINO_DIR = $(HOME)/Documents/Arduino/libraries -#ALTERNATE_CORE_PATH = $(HOME)/Library/Arduino15/packages/MightyCore/hardware/avr/2.0.5 -BOARD_TAG = 1284 -MCU = atmega1284p -VARIANT = sanguino -F_CPU = 16000000L -ARDUINO_LIBS = UIPEthernet Wire SdFat SPI pubsubclient -MONITOR_PORT = /dev/ttyUSB0 -MONITOR_BAUDRATE = 115200 -include ./Arduino.mk diff --git a/makeEspArduino.mk b/makeEspArduino.mk deleted file mode 100644 index c494e603..00000000 --- a/makeEspArduino.mk +++ /dev/null @@ -1,569 +0,0 @@ -#==================================================================================== -# makeESPArduino -# -# A makefile for ESP8286 and ESP32 Arduino projects. -# -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2016-2021 Peter Lerup. All rights reserved. -# -#==================================================================================== - -START_TIME := $(shell date +%s) -__THIS_FILE := $(abspath $(lastword $(MAKEFILE_LIST))) -__TOOLS_DIR := $(dir $(__THIS_FILE))tools -OS ?= $(shell uname -s) - -# Include possible operating system specfic settings --include $(dir $(__THIS_FILE))/os/$(OS).mk - -# Include possible global user settings -CONFIG_ROOT ?= $(if $(XDG_CONFIG_HOME),$(XDG_CONFIG_HOME),$(HOME)/.config) --include $(CONFIG_ROOT)/makeEspArduino/config.mk - -# Include possible project specific settings --include $(firstword $(PROJ_CONF) $(dir $(SKETCH))config.mk) - -# Build threads, default is using all the PC cpus -BUILD_THREADS ?= $(shell nproc) -MAKEFLAGS += -j $(BUILD_THREADS) - -# Build verbosity, silent by default -ifndef VERBOSE - MAKEFLAGS += --silent -endif - -# ESP chip family type -CHIP ?= esp8266 -UC_CHIP := $(shell perl -e "print uc $(CHIP)") -IS_ESP32 := $(if $(filter-out esp32,$(CHIP)),,1) - -# Serial flashing parameters -UPLOAD_PORT_MATCH ?= /dev/ttyU* -UPLOAD_PORT ?= $(shell ls -1tr $(UPLOAD_PORT_MATCH) 2>/dev/null | tail -1) - -# Monitor definitions -MONITOR_SPEED ?= 115200 -MONITOR_PORT ?= $(UPLOAD_PORT) -MONITOR_PAR ?= --rts=0 --dtr=0 -MONITOR_COM ?= $(if $(NO_PY_WRAP),python3,$(PY_WRAP)) -m serial.tools.miniterm $(MONITOR_PAR) $(MONITOR_PORT) $(MONITOR_SPEED) - -# OTA parameters -OTA_ADDR ?= -OTA_PORT ?= $(if $(IS_ESP32),3232,8266) -OTA_PWD ?= -OTA_ARGS = --progress --ip="$(OTA_ADDR)" --port="$(OTA_PORT)" -ifneq ($(OTA_PWD),) - OTA_ARGS += --auth="$(OTA_PWD)" -endif - -# HTTP update parameters -HTTP_ADDR ?= -HTTP_URI ?= /update -HTTP_PWD ?= user -HTTP_USR ?= password -HTTP_OPT ?= --progress-bar -o /dev/null - -# Output directory -BUILD_ROOT ?= /tmp/mkESP -BUILD_DIR ?= $(BUILD_ROOT)/$(MAIN_NAME)_$(BOARD) - -# File system and corresponding disk directories -FS_TYPE ?= spiffs -FS_DIR ?= $(dir $(SKETCH))data -FS_RESTORE_DIR ?= $(BUILD_DIR)/file_system - -# Utility functions -git_description = $(shell git -C $(1) describe --tags --always --dirty 2>/dev/null || echo Unknown) -time_string = $(shell date +$(1)) -find_files = $(shell find $2 | awk '/.*\.($1)$$/') - -# ESP Arduino directories -ifndef ESP_ROOT - # Location not defined, find and use possible version in the Arduino IDE installation - ARDUINO_ROOT ?= $(HOME)/.arduino15 - ARDUINO_ESP_ROOT = $(ARDUINO_ROOT)/packages/$(CHIP) - ESP_ROOT := $(if $(ARDUINO_HW_ESP_ROOT),$(ARDUINO_HW_ESP_ROOT),$(lastword $(wildcard $(ARDUINO_ESP_ROOT)/hardware/$(CHIP)/*))) - ifeq ($(ESP_ROOT),) - $(error No installed version of $(CHIP) Arduino found) - endif - ARDUINO_LIBS ?= $(shell grep -o "sketchbook.path=.*" $(ARDUINO_ROOT)/preferences.txt 2>/dev/null | cut -f2- -d=)/libraries - ESP_ARDUINO_VERSION := $(notdir $(ESP_ROOT)) - # Find used version of compiler and tools - COMP_PATH := $(lastword $(wildcard $(ARDUINO_ESP_ROOT)/tools/xtensa-*/*)) - MK_FS_PATH := $(lastword $(wildcard $(ARDUINO_ESP_ROOT)/tools/mk$(FS_TYPE)/*/mk$(FS_TYPE))) - PYTHON3_PATH := $(lastword $(wildcard $(ARDUINO_ESP_ROOT)/tools/python3/*)) -else - # Location defined, assume that it is a git clone - ESP_ARDUINO_VERSION = $(call git_description,$(ESP_ROOT)) - MK_FS_PATH := $(lastword $(wildcard $(ESP_ROOT)/tools/mk$(FS_TYPE)/mk$(FS_TYPE))) - PYTHON3_PATH := $(wildcard $(ESP_ROOT)/tools/python3) -endif -ESP_LIBS = $(ESP_ROOT)/libraries -SDK_ROOT = $(ESP_ROOT)/tools/sdk -TOOLS_ROOT = $(ESP_ROOT)/tools - -# The esp8266 tools directory contains the python3 executable as well as some modules -# Use these to avoid additional python installation requirements here -PYTHON3_PATH := $(if $(PYTHON3_PATH),$(PYTHON3_PATH),$(dir $(shell which python3 2>/dev/null))) -PY_WRAP = $(PYTHON3_PATH)/python3 $(__TOOLS_DIR)/py_wrap.py $(TOOLS_ROOT) -NO_PY_WRAP ?= $(if $(IS_ESP32),1,) - -# Validate the selected version of ESP Arduino -ifeq ($(wildcard $(ESP_ROOT)/cores/$(CHIP)),) - $(error $(ESP_ROOT) is not a vaild directory for $(CHIP)) -endif - -# Set possible default board variant and validate -BOARD_OP = perl $(__TOOLS_DIR)/board_op.pl $(ESP_ROOT)/boards.txt "$(CPU)" -ifeq ($(BOARD),) - BOARD := $(if $(IS_ESP32),esp32,generic) -else ifeq ($(shell $(BOARD_OP) $(BOARD) check),) - $(error Invalid board: $(BOARD)) -endif - -# Handle esptool variants -ESPTOOL_EXT = $(if $(IS_ESP32),,.py) -ESPTOOL ?= $(if $(NO_PY_WRAP),$(ESP_ROOT)/tools/esptool/esptool$(ESPTOOL_EXT),$(PY_WRAP) esptool) -ESPTOOL_COM ?= $(ESPTOOL) --baud=$(UPLOAD_SPEED) --port $(UPLOAD_PORT) --chip $(CHIP) -ifeq ($(IS_ESP32),) - # esp8266, use esptool directly instead of via tools/upload.py in order to avoid speed restrictions currently implied there - UPLOAD_COM = $(ESPTOOL_COM) $(UPLOAD_RESET) write_flash 0x00000 $(BUILD_DIR)/$(MAIN_NAME).bin - FS_UPLOAD_COM = $(ESPTOOL_COM) $(UPLOAD_RESET) write_flash $(SPIFFS_START) $(FS_IMAGE) -endif - -# Detect if the specified goal involves building or not -GOALS := $(if $(MAKECMDGOALS),$(MAKECMDGOALS),all) -BUILDING := $(if $(filter $(GOALS), monitor list_boards list_flash_defs list_lwip set_git_version install help tools_dir preproc info),,1) - -# Sketch (main program) selection -ifeq ($(BUILDING),) - SKETCH = /dev/null -endif -ifdef DEMO - SKETCH := $(if $(IS_ESP32),$(ESP_LIBS)/WiFi/examples/WiFiScan/WiFiScan.ino,$(ESP_LIBS)/ESP8266WiFi/examples/WiFiScan/WiFiScan.ino) -endif -SKETCH ?= $(abspath $(wildcard *.ino *.pde)) -ifeq ($(SKETCH),) - $(error No sketch specified or found. Use "DEMO=1" for testing) -endif -ifeq ($(wildcard $(SKETCH)),) - $(error Sketch $(SKETCH) not found) -endif -SRC_GIT_VERSION := $(call git_description,$(dir $(SKETCH))) - -# Main output definitions -SKETCH_NAME := $(basename $(notdir $(SKETCH))) -MAIN_NAME ?= $(SKETCH_NAME) -MAIN_EXE ?= $(BUILD_DIR)/$(MAIN_NAME).bin -FS_IMAGE ?= $(BUILD_DIR)/FS.bin - -# Build file extensions -OBJ_EXT = .o -DEP_EXT = .d - -# Special tool definitions -OTA_TOOL ?= python $(TOOLS_ROOT)/espota.py -HTTP_TOOL ?= curl - -# Core source files -CORE_DIR = $(ESP_ROOT)/cores/$(CHIP) -CORE_SRC := $(call find_files,S|c|cpp,$(CORE_DIR)) -CORE_OBJ := $(patsubst %,$(BUILD_DIR)/%$(OBJ_EXT),$(notdir $(CORE_SRC))) -CORE_LIB = $(BUILD_DIR)/arduino.ar -USER_OBJ_LIB = $(BUILD_DIR)/user_obj.ar - -# Find project specific source files and include directories -SRC_LIST = $(BUILD_DIR)/src_list.mk -FIND_SRC_CMD = $(__TOOLS_DIR)/find_src.pl -$(SRC_LIST): $(MAKEFILE_LIST) $(FIND_SRC_CMD) | $(BUILD_DIR) - $(if $(BUILDING),echo "- Finding all involved files for the build ...",) - perl $(FIND_SRC_CMD) "$(EXCLUDE_DIRS)" $(SKETCH) "$(CUSTOM_LIBS)" "$(LIBS)" $(ESP_LIBS) $(ARDUINO_LIBS) >$(SRC_LIST) - --include $(SRC_LIST) - -# Use sketch copy with correct C++ extension -SKETCH_CPP = $(BUILD_DIR)/$(notdir $(SKETCH)).cpp -USER_SRC := $(subst $(SKETCH),$(SKETCH_CPP),$(USER_SRC)) - -USER_OBJ := $(patsubst %,$(BUILD_DIR)/%$(OBJ_EXT),$(notdir $(USER_SRC))) -USER_DIRS := $(sort $(dir $(USER_SRC))) - -# Use first flash definition for the board as default -FLASH_DEF ?= $(shell $(BOARD_OP) $(BOARD) first_flash) -# Same method for LwIPVariant -LWIP_VARIANT ?= $(shell $(BOARD_OP) $(BOARD) first_lwip) - -# Handle possible changed state i.e. make command line parameters or changed git versions -CMD_LINE ?= $(shell tr "\0" " " $(STATE_LOG)) -endif - -# The actual build commands are to be extracted from the Arduino description files -ARDUINO_MK = $(BUILD_DIR)/arduino.mk -OS_NAME ?= linux -ARDUINO_DESC := $(shell find -L $(ESP_ROOT) -maxdepth 1 -name "*.txt" | sort) -$(ARDUINO_MK): $(ARDUINO_DESC) $(MAKEFILE_LIST) $(__TOOLS_DIR)/parse_arduino.pl | $(BUILD_DIR) - $(if $(BUILDING),echo "- Parsing Arduino configuration files ...",) - perl $(__TOOLS_DIR)/parse_arduino.pl $(BOARD) '$(FLASH_DEF)' '$(OS_NAME)' '$(LWIP_VARIANT)' $(ARDUINO_EXTRA_DESC) $(ARDUINO_DESC) >$(ARDUINO_MK) - --include $(ARDUINO_MK) - -# Compilation directories and path -INCLUDE_DIRS += $(CORE_DIR) $(ESP_ROOT)/variants/$(INCLUDE_VARIANT) $(BUILD_DIR) -C_INCLUDES := $(foreach dir,$(INCLUDE_DIRS) $(USER_INC_DIRS),-I$(dir)) -VPATH += $(shell find $(CORE_DIR) -type d) $(USER_DIRS) - -# Automatically generated build information data source file -# Makes the build date and git descriptions at the time of actual build event -# available as string constants in the program -BUILD_INFO_H = $(BUILD_DIR)/buildinfo.h -BUILD_INFO_CPP = $(BUILD_DIR)/buildinfo.c++ -BUILD_INFO_OBJ = $(BUILD_INFO_CPP)$(OBJ_EXT) -BUILD_DATE = $(call time_string,"%Y-%m-%d") -BUILD_TIME = $(call time_string,"%H:%M:%S") - -$(BUILD_INFO_H): | $(BUILD_DIR) - @echo "typedef struct { const char *date, *time, *src_version, *env_version; } _tBuildInfo; extern _tBuildInfo _BuildInfo;" >$@ - -# Use ccache if it is available and not explicitly disabled (USE_CCACHE=0) -USE_CCACHE ?= $(if $(shell which ccache 2>/dev/null),1,0) -ifeq ($(USE_CCACHE),1) - C_COM_PREFIX = ccache - CPP_COM_PREFIX = $(C_COM_PREFIX) -endif - -# Generated header files -GEN_H_FILES += $(BUILD_INFO_H) - -# Build output root directory -$(BUILD_DIR): - mkdir -p $(BUILD_DIR) - -# Create a C++ file from the sketch -$(SKETCH_CPP): $(SKETCH) - echo "#include " >$@ - cat $(abspath $<) >>$@ - -# Build rules for the different source file types -$(BUILD_DIR)/%.cpp$(OBJ_EXT): %.cpp $(ARDUINO_MK) | $(GEN_H_FILES) - @echo $(' >$(BUILD_INFO_CPP) - @echo '_tBuildInfo _BuildInfo = {"$(BUILD_DATE)","$(BUILD_TIME)","$(SRC_GIT_VERSION)","$(ESP_ARDUINO_VERSION)"};' >>$(BUILD_INFO_CPP) - $(CPP_COM) $(BUILD_INFO_CPP) -o $(BUILD_INFO_OBJ) - $(LD_COM) $(LD_EXTRA) - $(GEN_PART_COM) - $(OBJCOPY) - $(SIZE_COM) | perl $(__TOOLS_DIR)/mem_use.pl "$(MEM_FLASH)" "$(MEM_RAM)" -ifneq ($(LWIP_INFO),) - @printf "LwIPVariant: $(LWIP_INFO)\n" -endif -ifneq ($(FLASH_INFO),) - @printf "Flash size: $(FLASH_INFO)\n\n" -endif - @perl -e 'print "Build complete. Elapsed time: ", time()-$(START_TIME), " seconds\n\n"' - -# Flashing operations -CHECK_PORT := $(if $(UPLOAD_PORT),\ - @echo === Using upload port: $(UPLOAD_PORT) @ $(UPLOAD_SPEED),\ - @echo "*** Upload port not found or defined" && exit 1) -upload flash: all - $(CHECK_PORT) - $(UPLOAD_COM) - -ota: all -ifeq ($(OTA_ADDR),) - @echo == Error: Address of device must be specified via OTA_ADDR - exit 1 -endif - $(OTA_PRE_COM) - $(OTA_TOOL) $(OTA_ARGS) --file="$(MAIN_EXE)" - -http: all -ifeq ($(HTTP_ADDR),) - @echo == Error: Address of device must be specified via HTTP_ADDR - exit 1 -endif - $(HTTP_TOOL) $(HTTP_OPT) -F image=@$(MAIN_EXE) --user $(HTTP_USR):$(HTTP_PWD) http://$(HTTP_ADDR)$(HTTP_URI) - @echo "\n" - -$(FS_IMAGE): $(ARDUINO_MK) $(shell find $(FS_DIR)/ 2>/dev/null) -ifeq ($(SPIFFS_SIZE),) - @echo == Error: No file system specified in FLASH_DEF - exit 1 -endif - @echo Generating file system image: $(FS_IMAGE) - $(MK_FS_COM) - -fs: $(FS_IMAGE) - -upload_fs flash_fs: $(FS_IMAGE) - $(CHECK_PORT) - $(FS_UPLOAD_COM) - -ota_fs: $(FS_IMAGE) -ifeq ($(OTA_ADDR),) - @echo == Error: Address of device must be specified via OTA_ADDR - exit 1 -endif - $(OTA_TOOL) $(OTA_ARGS) --spiffs --file="$(FS_IMAGE)" - -run: flash - $(MONITOR_COM) - -monitor: -ifeq ($(MONITOR_PORT),) - @echo "*** Monitor port not found or defined" && exit 1 -endif - $(MONITOR_COM) - -FLASH_FILE ?= $(BUILD_DIR)/esp_flash.bin -dump_flash: - $(CHECK_PORT) - @echo Dumping flash memory to file: $(FLASH_FILE) - $(ESPTOOL_COM) read_flash 0 $(shell perl -e 'shift =~ /(\d+)([MK])/ || die "Invalid memory size\n";$$mem_size=$$1*1024;$$mem_size*=1024 if $$2 eq "M";print $$mem_size;' $(FLASH_DEF)) $(FLASH_FILE) - -dump_fs: - $(CHECK_PORT) - @echo Dumping flash file system to directory: $(FS_RESTORE_DIR) - -$(ESPTOOL_COM) read_flash $(SPIFFS_START) $(SPIFFS_SIZE) $(FS_IMAGE) - mkdir -p $(FS_RESTORE_DIR) - @echo - @echo == Files == - $(RESTORE_FS_COM) - -restore_flash: - $(CHECK_PORT) - @echo Restoring flash memory from file: $(FLASH_FILE) - $(ESPTOOL_COM) -a soft_reset write_flash 0 $(FLASH_FILE) - -erase_flash: - $(CHECK_PORT) - $(ESPTOOL_COM) erase_flash - -# Building library instead of executable -LIB_OUT_FILE ?= $(BUILD_DIR)/$(MAIN_NAME).a -.PHONY: lib -lib: $(LIB_OUT_FILE) -$(LIB_OUT_FILE): $(filter-out $(BUILD_DIR)/$(MAIN_NAME).cpp$(OBJ_EXT),$(USER_OBJ)) - @echo Building library $(LIB_OUT_FILE) - rm -f $(LIB_OUT_FILE) - $(LIB_COM) cru $(LIB_OUT_FILE) $^ - -# Miscellaneous operations -clean: - @echo Removing all build files - rm -rf "$(BUILD_DIR)" $(FILES_TO_CLEAN) - -list_boards: - $(BOARD_OP) $(BOARD) list_names - -list_lib: $(SRC_LIST) - perl -e 'foreach (@ARGV) {print "$$_\n"}' "===== Include directories =====" $(USER_INC_DIRS) "===== Source files =====" $(USER_SRC) - -list_flash_defs: - $(BOARD_OP) $(BOARD) list_flash - -list_lwip: - $(BOARD_OP) $(BOARD) list_lwip - -# Update the git version of the esp Arduino repo -set_git_version: -ifeq ($(REQ_GIT_VERSION),) - @echo == Error: Version tag must be specified via REQ_GIT_VERSION - exit 1 -endif - @echo == Setting $(ESP_ROOT) to $(REQ_GIT_VERSION) ... - git -C $(ESP_ROOT) checkout -fq --recurse-submodules $(REQ_GIT_VERSION) - git -C $(ESP_ROOT) clean -fdxq -f - git -C $(ESP_ROOT) submodule update --init - git -C $(ESP_ROOT) submodule foreach -q --recursive git clean -xfd - cd $(ESP_ROOT)/tools; ./get.py -q - -# Generate a Visual Studio Code configuration and launch -BIN_DIR = /usr/local/bin -_MAKE_COM = make -f $(__THIS_FILE) ESP_ROOT=$(ESP_ROOT) -ifeq ($(CHIP),esp32) - _MAKE_COM += CHIP=esp32 - _SCRIPT = espmake32 -else - _SCRIPT = espmake -endif -vscode: all - perl $(__TOOLS_DIR)/vscode.pl -n $(MAIN_NAME) -m "$(_MAKE_COM)" -w "$(VS_CODE_DIR)" -i "$(VSCODE_INC_EXTRA)" -p "$(VSCODE_PROJ_NAME)" $(CPP_COM) - -# Create shortcut command for running this file -install: - @echo Creating command \"$(_SCRIPT)\" in $(BIN_DIR) - sudo sh -c 'echo $(_MAKE_COM) "\"\$$@\"" >$(BIN_DIR)/$(_SCRIPT)' - sudo chmod +x $(BIN_DIR)/$(_SCRIPT) - -# Just return the path of the tools directory (intended to be used to find vscode.pl above from othe makefiles) -tools_dir: - @echo $(__TOOLS_DIR) - -# Show ram memory usage per variable -ram_usage: $(MAIN_EXE) - $(shell find $(TOOLS_ROOT) | grep 'gcc-nm') -Clrtd --size-sort $(BUILD_DIR)/$(MAIN_NAME).elf | grep -i ' [b] ' - -# Show ram and flash usage per object files used in the build -OBJ_INFO_FORM ?= 0 -OBJ_INFO_SORT ?= 1 -obj_info: $(MAIN_EXE) - perl $(__TOOLS_DIR)/obj_info.pl "$(shell find $(TOOLS_ROOT) | grep 'elf-size$$')" "$(OBJ_INFO_FORM)" "$(OBJ_INFO_SORT)" $(BUILD_DIR)/*.o - -# Analyze crash log -crash: $(MAIN_EXE) - perl $(__TOOLS_DIR)/crash_tool.pl $(ESP_ROOT) $(BUILD_DIR)/$(MAIN_NAME).elf - -# Run compiler preprocessor to get full expanded source for a file -preproc: -ifeq ($(SRC_FILE),) - $(error SRC_FILE must be defined) -endif - $(CPP_COM) -E $(SRC_FILE) - -# Main default rule, build the executable -.PHONY: all -all: $(BUILD_DIR) $(ARDUINO_MK) prebuild $(MAIN_EXE) - -# Prebuild is currently only mandatory for esp32 -USE_PREBUILD ?= $(if $(IS_ESP32),1,) -prebuild: -ifneq ($(USE_PREBUILD),) - $(PREBUILD) -endif - -help: $(ARDUINO_MK) - @echo - @echo "Generic makefile for building Arduino esp8266 and esp32 projects" - @echo "This file can either be used directly or included from another makefile" - @echo "" - @echo "The following targets are available:" - @echo " all (default) Build the project application" - @echo " clean Remove all intermediate build files" - @echo " lib Build a library with all involved object files" - @echo " flash Build and and flash the project application" - @echo " flash_fs Build and and flash file system (when applicable)" - @echo " ota Build and and flash via OTA" - @echo " Params: OTA_ADDR, OTA_PORT and OTA_PWD" - @echo " ota_fs Build and and flash file system via OTA" - @echo " http Build and and flash via http (curl)" - @echo " Params: HTTP_ADDR, HTTP_URI, HTTP_PWD and HTTP_USR" - @echo " dump_flash Dump the whole board flash memory to a file" - @echo " restore_flash Restore flash memory from a previously dumped file" - @echo " dump_fs Extract all files from the flash file system" - @echo " Params: FS_DUMP_DIR" - @echo " erase_flash Erase the whole flash (use with care!)" - @echo " list_lib Show a list of used solurce files and include directories" - @echo " set_git_version Setup ESP Arduino git repo to a the tag version" - @echo " specified via REQ_GIT_VERSION" - @echo " install Create the commands \"espmake\" and \"espmake32\"" - @echo " vscode Create config file for Visual Studio Code and launch" - @echo " ram_usage Show global variables RAM usage" - @echo " obj_info Show memory usage per object file" - @echo " monitor Start serial monitor on the upload port" - @echo " run Build flash and start serial monitor" - @echo " crash Analyze stack trace from a crash" - @echo " preproc Run compiler preprocessor on source file" - @echo " specified via SRC_FILE" - @echo " info Show location and version of used esp Arduino" - @echo "Configurable parameters:" - @echo " SKETCH Main source file" - @echo " If not specified the first sketch in current" - @echo " directory will be used." - @echo " LIBS Use this variable to declare additional directories" - @echo " and/or files which should be included in the build" - @echo " CHIP Set to esp8266 or esp32. Default: '$(CHIP)'" - @echo " BOARD Name of the target board. Default: '$(BOARD)'" - @echo " Use 'list_boards' to get list of available ones" - @echo " FLASH_DEF Flash partitioning info. Default '$(FLASH_DEF)'" - @echo " Use 'list_flash_defs' to get list of available ones" - @echo " BUILD_DIR Directory for intermediate build files." - @echo " Default '$(BUILD_DIR)'" - @echo " BUILD_EXTRA_FLAGS Additional parameters for the compilation commands" - @echo " COMP_WARNINGS Compilation warning options. Default: $(COMP_WARNINGS)" - @echo " FS_TYPE File system type. Default: $(FS_TYPE)" - @echo " FS_DIR File system root directory" - @echo " UPLOAD_PORT Serial flashing port name. Default: '$(UPLOAD_PORT)'" - @echo " UPLOAD_SPEED Serial flashing baud rate. Default: '$(UPLOAD_SPEED)'" - @echo " MONITOR_SPEED Baud rate for the monitor. Default: '$(MONITOR_SPEED)'" - @echo " FLASH_FILE File name for dump and restore flash operations" - @echo " Default: '$(FLASH_FILE)'" - @echo " LWIP_VARIANT Use specified variant of the lwip library when applicable" - @echo " Use 'list_lwip' to get list of available ones" - @echo " Default: $(LWIP_VARIANT) ($(LWIP_INFO))" - @echo " VERBOSE Set to 1 to get full printout of the build" - @echo " BUILD_THREADS Number of parallel build threads" - @echo " Default: Maximum possible, based on number of CPUs" - @echo " USE_CCACHE Set to 0 to disable ccache when it is available" - @echo " NO_USER_OBJ_LIB Set to 1 to disable putting all object files into an archive" - @echo - -# Show installation information -info: - echo == Build info - echo " CHIP: $(CHIP)" - echo " ESP_ROOT: $(ESP_ROOT)" - echo " Version: $(ESP_ARDUINO_VERSION)" - echo " Threads: $(BUILD_THREADS)" - echo " Upload port: $(UPLOAD_PORT)" - -# Include all available dependencies from the previous compilation --include $(wildcard $(BUILD_DIR)/*$(DEP_EXT)) - -DEFAULT_GOAL ?= all -.DEFAULT_GOAL := $(DEFAULT_GOAL) - diff --git a/tools/board_op.pl b/tools/board_op.pl deleted file mode 100644 index 567c7cb3..00000000 --- a/tools/board_op.pl +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env perl -#==================================================================================== -# board_op.pl -# -# Performs search operations on the Arduino boards file -# -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2020 Peter Lerup. All rights reserved. -# -#==================================================================================== - -use strict; - - -my $file_name = shift; -my $cpu = shift; -my $board_name = shift; -my $op = shift; - -my $flash_def_match = $cpu eq "esp32" ? '\.build\.flash_size=(\S+)' : '\.menu\.(?:FlashSize|eesz)\.([^\.]+)=(.+)'; -my $lwip_def_match = '\.menu\.(?:LwIPVariant|ip)\.(\w+)=(.+)'; - -my $boards_file; -local($/); -open($boards_file, $file_name) || die "Failed to open: $file_name\n"; -my $board_conf = <$boards_file>; -close($boards_file); - -my $result; -if ($op eq "first") { - $result = $1 if $board_conf =~ /(\w+)\.name=/; -} elsif ($op eq "check") { - $result = $board_conf =~ /$board_name\.name/; -} elsif ($op eq "first_flash") { - $result = $1 if $board_conf =~ /$board_name$flash_def_match/; -} elsif ($op eq "first_lwip") { - $result = $1 if $board_conf =~ /$board_name$lwip_def_match/; -} elsif ($op eq "list_names") { - print "=== Available boards ===\n"; - foreach (split("\n", $board_conf)) { - print sprintf("%-20s %s\n", $1, $2) if /^([\w\-]+)\.name=(.+)/; - } -} elsif ($op eq "list_flash") { - print "=== Memory configurations for board: $board_name ===\n"; - foreach (split("\n", $board_conf)) { - print sprintf("%-10s %s\n", $1, $2) if /$board_name$flash_def_match/; - } -} elsif ($op eq "list_lwip") { - print "=== lwip configurations for board: $board_name ===\n"; - foreach (split("\n", $board_conf)) { - print sprintf("%-10s %s\n", $1, $2) if /$board_name$lwip_def_match/; - } -} - -print $result; \ No newline at end of file diff --git a/tools/crash_tool.pl b/tools/crash_tool.pl deleted file mode 100644 index a739e769..00000000 --- a/tools/crash_tool.pl +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env perl -#==================================================================================== -# crash_tool.pl -# -# Analyzes crash dumps for esp8266 and esp32 -# Completely based on the work in these two repos: -# https://github.com/me-no-dev/EspExceptionDecoder -# https://github.com/littleyoda/EspStackTraceDecoder -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2020 Peter Lerup. All rights reserved. -# -#==================================================================================== - -use strict; -use File::Find; -use Term::ANSIColor qw(:constants); -local $Term::ANSIColor::AUTORESET = 1; - -my $max_width = `tput cols`; - -my ($esp_root, $elf_file_name) = @ARGV; - -my $addr2line; -finddepth(sub { $addr2line = $File::Find::name if (/addr2line$/); }, $esp_root); -die("Failed to locate addr2line\n") unless $addr2line; - -my @exceptions = ( -"Illegal instruction", -"SYSCALL instruction", -"InstructionFetchError: Processor internal physical address or data error during instruction fetch", -"LoadStoreError: Processor internal physical address or data error during load or store", -"Level1Interrupt: Level-1 interrupt as indicated by set level-1 bits in the INTERRUPT register", -"Alloca: MOVSP instruction, if caller's registers are not in the register file", -"IntegerDivideByZero: QUOS, QUOU, REMS, or REMU divisor operand is zero", -"reserved", -"Privileged: Attempt to execute a privileged operation when CRING ? 0", -"LoadStoreAlignmentCause: Load or store to an unaligned address", -"reserved", -"reserved", -"InstrPIFDataError: PIF data error during instruction fetch", -"LoadStorePIFDataError: Synchronous PIF data error during LoadStore access", -"InstrPIFAddrError: PIF address error during instruction fetch", -"LoadStorePIFAddrError: Synchronous PIF address error during LoadStore access", -"InstTLBMiss: Error during Instruction TLB refill", -"InstTLBMultiHit: Multiple instruction TLB entries matched", -"InstFetchPrivilege: An instruction fetch referenced a virtual address at a ring level less than CRING", -"reserved", -"InstFetchProhibited: An instruction fetch referenced a page mapped with an attribute that does not permit instruction fetch", -"reserved", -"reserved", -"reserved", -"LoadStoreTLBMiss: Error during TLB refill for a load or store", -"LoadStoreTLBMultiHit: Multiple TLB entries matched for a load or store", -"LoadStorePrivilege: A load or store referenced a virtual address at a ring level less than CRING", -"reserved", -"LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads", -"StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores" -); - -print BOLD GREEN "Paste your stack trace here!\n\n"; -my @addr; -my $reason; -while () { - last if /<< $max_width-2; - print " $path\n"; -} -print "\n"; - - diff --git a/tools/find_src.pl b/tools/find_src.pl deleted file mode 100644 index a3d5bae8..00000000 --- a/tools/find_src.pl +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env perl -#==================================================================================== -# find_src.pl -# -# Search for source files and required header file directories -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2016-2020 Peter Lerup. All rights reserved. -# -#==================================================================================== - -use strict; -use File::Basename; - -my %src_files; -my %inc_dirs; -my %user_libs; -my @search_dirs; -my %src_dirs; -my %checked_files; - -sub uniq { - my %seen; - grep !$seen{$_}++, @_; -} - -#-------------------------------------------------------------------- - -sub find_inc { - # Recursively find include statements - my $file_name = shift; - open(my $f, $file_name) || return; - $inc_dirs{dirname($file_name)}++; - while (<$f>) { - next unless /^\s*\#include\s*[<"]([^>"]+)/; - my $match = $1; - next if $checked_files{$match}; - $checked_files{$match}++; - for (my $i = 0; $i < @search_dirs; $i++) { - my $inc_file = "$search_dirs[$i]/$match"; - next unless -f $inc_file; - find_inc($inc_file); - my $dir = dirname($inc_file); - if (!$src_dirs{$dir}) { - # Add all source files in this directory - # Can not only search for file with same name as sometimes - # the actual implementation of the header has another name - foreach my $src (glob("$dir/*.cpp $dir/*.c $dir/*.S")) { - $src_files{$src}++; - find_inc($src); - } - } - last; - } - } - close($f); -} - -#-------------------------------------------------------------------- - -my $exclude_match = shift; - -# Parameters are within quotes to delay possible wildcard file name expansions -my @libs = split(" ", "@ARGV"); - -if ($libs[0] =~ /(.+)\/examples\//) { - # The sketch is an example, add the corresponding src directory to the library list if it exists - my $src_dir = "$1/src"; - push(@libs, $src_dir) if -d $src_dir; -} - -# First find possible explicit library source or achive files from the the specified list -for (my $i = 0; $i < @libs; $i++ ) { - my $path = $libs[$i]; - if (!-d $path) { - # File specification - my $wildcard = $path =~ /\*/; - if (!-e $path && !$wildcard) { - print STDERR "* Warning: Ignoring non existing file specification $path\n"; - next; - } - $libs[$i] = dirname($path); - # Mark as known source directory, except for sketch directory - $src_dirs{$libs[$i]}++ if $i; - if ($path =~ /\.(a|lib)$/) { - # Library file - $user_libs{$path}++; - } elsif ($wildcard) { - # Wildcard source files - foreach my $src (glob($path)) { - $src_files{$src}++; - } - } else { - # Single source file - $src_files{$path}++; - } - } -} -@libs = uniq(@libs); - -# Expand all sub directories of the specified library directories -# Keep the original order, hence stored in array and not hash -# These directories will be included in the search for used header files -my $dir_spec = join(" ", @libs); -foreach (`find $dir_spec -type d 2>/dev/null`) { - chomp; - s/\/$//; - next if /LittleFS\/lib/; # Fix for now - push(@search_dirs, $_) unless $exclude_match && /$exclude_match/; -} -@search_dirs = uniq(@search_dirs); - -# Search for used header files in all the specified source files -my @spec_src = keys %src_files; -foreach (@spec_src) { - find_inc($_); -} - -# Print the result as makefile variable definitions -print "USER_INC_DIRS = "; -# Keep order -foreach (@search_dirs) { - print "$_ " if $inc_dirs{$_}; -} -print "\n"; -print "USER_SRC = ", join(" ", sort(keys %src_files)), "\n"; -print "USER_LIBS = ", join(" ", keys %user_libs), "\n" diff --git a/tools/mem_use.pl b/tools/mem_use.pl deleted file mode 100644 index 7bbcdbea..00000000 --- a/tools/mem_use.pl +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env perl -#==================================================================================== -# mem_use.pl -# -# Shows summary of flash and RAM memory -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2016-2021 Peter Lerup. All rights reserved. -# -#==================================================================================== - -use strict; - -my $flash_sections = shift; -my $ram_sections = shift; -my $flash_tot = 0; -my $ram_tot = 0; -while (<>) { - $flash_tot += $1 if /$flash_sections/; - $ram_tot += $1 if /$ram_sections/; -} -print "\nMemory summary\n"; -print sprintf(" %-6s %6d bytes\n" x 2 ."\n", "RAM:", $ram_tot, "Flash:", $flash_tot); diff --git a/tools/obj_info.pl b/tools/obj_info.pl deleted file mode 100644 index ba0df968..00000000 --- a/tools/obj_info.pl +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env perl -#==================================================================================== -# obj_info.pl -# -# Show memory usage for object files -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2021 Peter Lerup. All rights reserved. -# -#==================================================================================== - -use strict; - -my $elf_size = shift; -my $form = shift == "1" ? "%s\t%s\t%s\t%s\t%s\t%s\n" : "%-38.38s %7s %7s %7s %7s %7s\n"; -my $sort_index = shift; -print sprintf($form, "File", "Flash", "RAM", "data", "rodata", "bss"); -print "-" x 78, "\n" unless $form =~ /\t/; - -my %info; -while (my $obj_file = shift) { - next unless $obj_file =~ /.+\/([\w\.]+)\.o$/; - my $name = $1; - for (my $i = 0; $i < 5; $i++) { $info{$name}[$i] = 0; } - foreach (split("\n", `$elf_size -A $obj_file`)) { - $info{$name}[0] += $1 if /(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata)\S*\s+([0-9]+).*/; - $info{$name}[2] += $1 if /^.data\S*\s+([0-9]+).*/; - $info{$name}[3] += $1 if /^.rodata\S*\s+([0-9]+).*/; - $info{$name}[4] += $1 if /^.bss\S*\s+([0-9]+).*/; - } - $info{$name}[1] = $info{$name}[2] + $info{$name}[3] + $info{$name}[4]; -} -foreach (sort { $info{$b}[$sort_index] <=> $info{$a}[$sort_index] or $info{$b}[0] <=> $info{$a}[0] } keys %info) { - print sprintf($form, $_, $info{$_}[0], $info{$_}[1], $info{$_}[2], $info{$_}[3], $info{$_}[4]); -} - diff --git a/tools/parse_arduino.pl b/tools/parse_arduino.pl deleted file mode 100644 index 2355e7cc..00000000 --- a/tools/parse_arduino.pl +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env perl -#==================================================================================== -# parse_arduino.pl -# -# Parses Arduino configuration files and writes the content -# of a corresponding makefile -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2016-2021 Peter Lerup. All rights reserved. -# -#==================================================================================== - -use strict; - -my $board = shift; -my $flashSize = shift; -my $os = shift; -my $lwipvariant = shift; -my %vars; - -sub def_var { - my ($name, $var) = @_; - print "$var ?= $vars{$name}\n"; - $vars{$name} = "\$($var)"; -} - -sub multi_com { - my ($match ) = @_; - my @result; - foreach my $name (sort keys %vars) { - push(@result, $vars{$name}) if $name =~ /^$match$/; - } - return join(" && \\\n", @result); -} - -# Some defaults -$vars{'runtime.platform.path'} = '$(ESP_ROOT)'; -$vars{'includes'} = '$(C_INCLUDES)'; -$vars{'runtime.ide.version'} = '10605'; -$vars{'build.arch'} = '$(UC_CHIP)'; -$vars{'build.project_name'} = '$(MAIN_NAME)'; -$vars{'build.path'} = '$(BUILD_DIR)'; -$vars{'object_files'} = '$^ $(BUILD_INFO_OBJ)'; -$vars{'archive_file_path'} = '$(CORE_LIB)'; -$vars{'build.sslflags'} = '$(SSL_FLAGS)'; -$vars{'build.mmuflags'} = '$(MMU_FLAGS)'; -$vars{'build.vtable_flags'} = '$(VTABLE_FLAGS)'; -$vars{'build.source.path'} = '$(dir $(SKETCH))'; - -# Parse the files and define the corresponsing variables -my $board_defined; -foreach my $fn (@ARGV) { - my $f; - open($f, $fn) || die "Failed to open: $fn\n"; - while (<$f>) { - s/\s+$//; - s/\.esptool_py\./.esptool./g; - next unless /^(\w[\w\-\.]+)=(.*)/; - my ($key, $val) =($1, $2); - $board_defined = 1 if $key eq "$board.name"; - # Truncation of some variable names is needed - $key =~ s/$board\.menu\.(?:FlashSize|eesz)\.$flashSize\.//; - $key =~ s/$board\.menu\.CpuFrequency\.[^\.]+\.//; - $key =~ s/$board\.menu\.(?:FlashFreq|xtal)\.[^\.]+\.//; - $key =~ s/$board\.menu\.UploadSpeed\.[^\.]+\.//; - $key =~ s/$board\.menu\.baud\.[^\.]+\.//; - $key =~ s/$board\.menu\.ResetMethod\.[^\.]+\.//; - $key =~ s/$board\.menu\.FlashMode\.[^\.]+\.//; - $key =~ s/$board\.menu\.(?:LwIPVariant|ip)\.$lwipvariant\.//; - $key =~ s/^$board\.//; - $vars{$key} ||= $val; - $vars{$1} = $vars{$key} if $key =~ /(.+)\.$os$/; - } - close($f); -} -# Some additional defaults may be needed -$vars{'runtime.tools.xtensa-lx106-elf-gcc.path'} ||= '$(COMP_PATH)'; -$vars{'runtime.tools.xtensa-esp32-elf-gcc.path'} ||= '$(COMP_PATH)'; -$vars{'runtime.tools.python3.path'} ||= '$(PYTHON3_PATH)'; - -die "* Unknown board $board\n" unless $board_defined; -print "# Board definitions\n"; -def_var('build.code_debug', 'CORE_DEBUG_LEVEL'); -def_var('build.f_cpu', 'F_CPU'); -def_var('build.flash_mode', 'FLASH_MODE'); -def_var('build.flash_freq', 'FLASH_SPEED'); -def_var('upload.resetmethod', 'UPLOAD_RESET'); -def_var('upload.speed', 'UPLOAD_SPEED'); -def_var('compiler.warning_flags', 'COMP_WARNINGS'); -$vars{'serial.port'} = '$(UPLOAD_PORT)'; -$vars{'tools.esptool.upload.pattern'} =~ s/\{(cmd|path)\}/\{tools.esptool.$1\}/g; -$vars{'compiler.cpreprocessor.flags'} .= " \$(C_PRE_PROC_FLAGS)"; -$vars{'build.extra_flags'} .= " \$(BUILD_EXTRA_FLAGS)"; - -# Some additional replacements -foreach my $key (sort keys %vars) { - while ($vars{$key} =~/\{/) { - $vars{$key} =~ s/\{([\w\-\.]+)\}/$vars{$1}/; - $vars{$key} =~ s/""//; - } - $vars{$key} =~ s/ -o\s+$//; - $vars{$key} =~ s/(-D\w+=)"([^"]+)"/$1\\"$2\\"/g; -} - -# Print the makefile content -my $val; -print "INCLUDE_VARIANT = $vars{'build.variant'}\n"; -print "VTABLE_FLAGS?=-DVTABLES_IN_FLASH\n"; -print "MMU_FLAGS?=-DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000\n"; -print "SSL_FLAGS?=\n"; -print "BOOT_LOADER?=\$(ESP_ROOT)/bootloaders/eboot/eboot.elf\n"; -print "# Commands\n"; -print "C_COM=\$(C_COM_PREFIX) $vars{'recipe.c.o.pattern'}\n"; -print "CPP_COM=\$(CPP_COM_PREFIX) $vars{'recipe.cpp.o.pattern'}\n"; -print "S_COM=$vars{'recipe.S.o.pattern'}\n"; -print "LIB_COM=\"$vars{'compiler.path'}$vars{'compiler.ar.cmd'}\"\n"; -print "CORE_LIB_COM=$vars{'recipe.ar.pattern'}\n"; -print "LD_COM=$vars{'recipe.c.combine.pattern'}\n"; -print "PART_FILE?=\$(ESP_ROOT)/tools/partitions/default.csv\n"; -$val = $vars{'recipe.objcopy.eep.pattern'} || $vars{'recipe.objcopy.partitions.bin.pattern'}; -$val =~ s/\"([^\"]+\.csv)\"/\$(PART_FILE)/; -print "GEN_PART_COM=$val\n"; -($val = multi_com('recipe\.objcopy\.hex.*\.pattern')) =~ s/[^"]+\/bootloaders\/eboot\/eboot.elf/\$(BOOT_LOADER)/; -$val ||= multi_com('recipe\.objcopy\.bin.*\.pattern'); -print "OBJCOPY=$val\n"; -print "SIZE_COM=$vars{'recipe.size.pattern'}\n"; -print "UPLOAD_COM?=$vars{'tools.esptool.upload.pattern'} $vars{'tools.esptool.upload.pattern_args'}\n"; - -if ($vars{'build.spiffs_start'}) { - print "SPIFFS_START?=$vars{'build.spiffs_start'}\n"; - my $spiffs_size = sprintf("0x%X", hex($vars{'build.spiffs_end'})-hex($vars{'build.spiffs_start'})); - print "SPIFFS_SIZE?=$spiffs_size\n"; -} elsif ($vars{'build.partitions'}) { - print "COMMA=,\n"; - print "SPIFFS_SPEC:=\$(subst \$(COMMA), ,\$(shell grep spiffs \$(PART_FILE)))\n"; - print "SPIFFS_START:=\$(word 4,\$(SPIFFS_SPEC))\n"; - print "SPIFFS_SIZE:=\$(word 5,\$(SPIFFS_SPEC))\n"; -} -$vars{'build.spiffs_blocksize'} ||= "4096"; -print "SPIFFS_BLOCK_SIZE?=$vars{'build.spiffs_blocksize'}\n"; -print "MK_FS_COM?=\"\$(MK_FS_PATH)\" -b \$(SPIFFS_BLOCK_SIZE) -s \$(SPIFFS_SIZE) -c \$(FS_DIR) \$(FS_IMAGE)\n"; -print "RESTORE_FS_COM?=\"\$(MK_FS_PATH)\" -b \$(SPIFFS_BLOCK_SIZE) -s \$(SPIFFS_SIZE) -u \$(FS_RESTORE_DIR) \$(FS_IMAGE)\n"; - -my $fs_upload_com = $vars{'tools.esptool.upload.pattern'} . " $vars{'tools.esptool.upload.pattern_args'}"; -$fs_upload_com =~ s/(.+ -ca) .+/$1 \$(SPIFFS_START) -cf \$(FS_IMAGE)/; -$fs_upload_com =~ s/(.+ --flash_size detect) .+/$1 \$(SPIFFS_START) \$(FS_IMAGE)/; -print "FS_UPLOAD_COM?=$fs_upload_com\n"; -$val = multi_com('recipe\.hooks*\.prebuild.*\.pattern'); -$val =~ s/bash -c "(.+)"/$1/g; -$val =~ s/(#define .+0x)(\`)/"\\$1\"$2/; -print "PREBUILD=$val\n"; -print "PRELINK=", multi_com('recipe\.hooks\.linking\.prelink.*\.pattern'), "\n"; -print "MEM_FLASH=$vars{'recipe.size.regex'}\n"; -print "MEM_RAM=$vars{'recipe.size.regex.data'}\n"; -my $flash_info = $vars{'menu.FlashSize.' . $flashSize} || $vars{'menu.eesz.' . $flashSize}; -print "FLASH_INFO=$flash_info\n"; -print "LWIP_INFO=", $vars{'menu.LwIPVariant.' . $lwipvariant} || $vars{'menu.ip.' . $lwipvariant}, "\n"; diff --git a/tools/py_wrap.py b/tools/py_wrap.py deleted file mode 100644 index 77da724e..00000000 --- a/tools/py_wrap.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 -#==================================================================================== -# py_wrap.pl -# -# Wrapper for python scripts in the esp8266 Arduino tools directory -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2021 Peter Lerup. All rights reserved. -# -#==================================================================================== - -import sys -import os - -sys.argv.pop(0) -root_dir = sys.argv.pop(0) -is_module = sys.argv[0] == "-m" -if is_module: - sys.argv.pop(0) -script = sys.argv[0] -# Include the required module directories to the path -sys.path.insert(0, root_dir + "/pyserial") -sys.path.insert(0, root_dir + "/esptool") -exec("import " + script) -if not is_module: - sys.argv.pop(0) -exec(script + ".main(sys.argv)") diff --git a/tools/vscode.pl b/tools/vscode.pl deleted file mode 100644 index 791f9c1f..00000000 --- a/tools/vscode.pl +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/env perl -#==================================================================================== -# vscode.pl -# -# Generates Visual Studio Code properties and task config files -# based on the compile command line and then starts VS Code -# -# This file is part of makeESPArduino -# License: LGPL 2.1 -# General and full license information is available at: -# https://github.com/plerup/makeEspArduino -# -# Copyright (c) 2020 Peter Lerup. All rights reserved. -# -#==================================================================================== - -use strict; -use Cwd; -use JSON::PP; -use Getopt::Std; -use File::Basename; - -sub file_to_string { - local($/); - my $f; - open($f, $_[0]) || return ""; - my $res = <$f>; - close($f); - return $res; -} - -#-------------------------------------------------------------------- - -sub string_to_file { - my $f; - open($f, ">$_[0]") || return 0; - print $f $_[1]; - close($f); - return 1; -} - -#-------------------------------------------------------------------- - -sub find_dir_upwards { - my $match = $_[0]; - my $dir = Cwd::abs_path("."); - while ($dir ne "/" && $dir ne $ENV{'HOME'}) { - my $test = $dir . "/$match"; - return $test if -e $test; - $dir = dirname($dir); - } - return Cwd::abs_path(".") . "/$match"; -} - -#-------------------------------------------------------------------- - -sub make_portable { - # Use variables in paths when possible - $_[0] =~ s/$_[1]/\$\{workspaceFolder\}/g; - $_[0] =~ s/$ENV{'HOME'}/\$\{env:HOME\}/g; -} - -#-------------------------------------------------------------------- - -# Parameters -my %opts; -getopts('n:m:w:d:i:p:', \%opts); -my $name = $opts{n} || "Linux"; -my $make_com = $opts{m} || "espmake"; -my $workspace_dir = $opts{w}; -my $proj_file = $opts{p}; -my $cwd = $opts{d} || getcwd; -my $comp_path = shift; -$comp_path = shift if $comp_path eq "ccache"; - -my $config_dir_name = ".vscode"; -$workspace_dir ||= dirname(find_dir_upwards($config_dir_name)); -$proj_file ||= (glob("$workspace_dir/*.code-workspace"))[0]; -my $config_dir = "$workspace_dir/$config_dir_name"; -mkdir($config_dir); - -# == C & C++ configuration -my @defines; -my @includes; -my $prop_file_name = "$config_dir/c_cpp_properties.json"; -my $prop_json = file_to_string($prop_file_name) || '{"version": 4, "configurations": []}'; - -# Build this configuration from command line defines and includes -while ($_ = shift) { - $_ .= shift if ($_ eq "-D"); - if (/-D\s*(\S+)/) { - # May be a quoted value - my $def = $1; - $def =~ s/\"/\\\"/g; - push(@defines, "\"$def\"") - } - push(@includes, "\"" . Cwd::abs_path($1) . "\"") if /-I\s*(\S+)/ && -e $1; -} -# Optional additional include directories -foreach (split(" ", $opts{i})) { - push(@includes, "\"$_\""); -} - -# Build corresponding json -my $def = join(',', @defines); -my $inc = join(',', @includes); -my $this_prop_json = <<"EOT"; -{ - "name": "$name", - "includePath": [$inc], - "defines": [$def], - "compilerPath": "$comp_path" -} -EOT -make_portable($this_prop_json, $workspace_dir); - -# Insert or replace this configuration -my $json_ref = decode_json($prop_json); -my $configs = $$json_ref{'configurations'}; -my $ind = 0; -foreach my $conf (@$configs) { - last if $$conf{'name'} eq $name; - $ind++; -} -$$configs[$ind] = decode_json($this_prop_json); -string_to_file($prop_file_name, JSON::PP->new->pretty->encode(\%$json_ref)); - -# == Add a task with the current name -my $this_task_json = <<"EOT"; -{ - "label": "$name", - "type": "shell", - "command": "$make_com", - "options": {"cwd": "$cwd"}, - "problemMatcher": ["\$gcc"], - "group": "build" -} -EOT -make_portable($this_task_json, $workspace_dir); -my $this_task = decode_json($this_task_json); -my $task_file_name = "$config_dir/tasks.json"; -my $task_json = file_to_string($task_file_name) || '{"version": "2.0.0", "tasks": []}'; -$json_ref = decode_json($task_json); -my $tasks = $$json_ref{'tasks'}; -my $found; -for (my $i = 0; !$found && $i < scalar(@$tasks); $i++) { - if ($$tasks[$i]{'label'} eq $name) { - # A task with this name exists, make sure that possible default build setting is kept - $found = 1; - $$this_task{'group'} = $$tasks[$i]{'group'}; - $$tasks[$i] = $this_task; - } -} -push(@$tasks, $this_task) if !$found; -string_to_file($task_file_name, JSON::PP->new->pretty->encode(\%$json_ref)); - - -# Launch Visual Studio Code -$proj_file ||= $workspace_dir; -print "Starting VS Code - $proj_file ...\n"; -# Remove all MAKE variables to avoid conflict when building inside VS Code -foreach my $var (keys %ENV) { - $ENV{$var} = undef if $var =~ /^MAKE/; -} -system("code $proj_file"); From 8b748b624c79c17cd873e49ccc719bcb36f0821f Mon Sep 17 00:00:00 2001 From: Rui Wang Date: Sun, 8 Jan 2023 11:03:30 -0500 Subject: [PATCH 2/5] add capability to detect w5500 by replicating its soft reset code. without this eth.begin can cause a crash if the ethernet module is not present --- OpenSprinkler.cpp | 32 +++++++++++++++++++++++++++++++- OpenSprinkler.h | 32 +++++++++++++++++++++++++++++++- README.txt | 10 +++++++--- defines.h | 2 +- main.cpp | 4 +++- opensprinkler_server.cpp | 13 ++++++++++--- 6 files changed, 83 insertions(+), 10 deletions(-) diff --git a/OpenSprinkler.cpp b/OpenSprinkler.cpp index f7a6ab29..dfc8c3c2 100644 --- a/OpenSprinkler.cpp +++ b/OpenSprinkler.cpp @@ -500,13 +500,43 @@ byte OpenSprinkler::start_network() { byte OpenSprinkler::start_ether() { #if defined(ESP8266) - if(hw_rev<2) return 0; // ethernet capability is only available after hw_rev 2 + if(hw_rev<2) return 0; // ethernet capability is only available when hw_rev>=2 + eth.isW5500 = (hw_rev==2)?false:true; // os 3.2 uses enc28j60 and 3.3 uses w5500 SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); SPI.setFrequency(4000000); + if(eth.isW5500) { + DEBUG_PRINTLN(F("check W5500")); + /* this is copied from w5500.cpp */ + /* perform a software reset and see if we get a response */ + static const uint8_t AccessModeRead = (0x00 << 2); + static const uint8_t AccessModeWrite = (0x01 << 2); + static const uint8_t BlockSelectCReg = (0x00 << 3); + pinMode(PIN_ETHER_CS, OUTPUT); + digitalWrite(PIN_ETHER_CS, LOW); + SPI.transfer((0x00 & 0xFF00) >> 8); + SPI.transfer((0x00 & 0x00FF) >> 0); + SPI.transfer(BlockSelectCReg | AccessModeWrite); + SPI.transfer(0x80); + digitalWrite(PIN_ETHER_CS, HIGH); + + uint8_t ret; + digitalWrite(PIN_ETHER_CS, LOW); + SPI.transfer((0x00 & 0xFF00) >> 8); + SPI.transfer((0x00 & 0x00FF) >> 0); + SPI.transfer(BlockSelectCReg | AccessModeRead); + ret = SPI.transfer(0); + digitalWrite(PIN_ETHER_CS, HIGH); + if(ret!=0) return 0; // ret is expected to be 0 + } else { + /* this is from */ + /* get erevid and see if we get a response */ + DEBUG_PRINTLN(F("check ENC28J60")); + } + load_hardware_mac((uint8_t*)tmp_buffer, true); if (iopts[IOPT_USE_DHCP]==0) { // config static IP before calling eth.begin IPAddress staticip(iopts+IOPT_STATIC_IP1); diff --git a/OpenSprinkler.h b/OpenSprinkler.h index c4225b89..bcf46113 100644 --- a/OpenSprinkler.h +++ b/OpenSprinkler.h @@ -48,6 +48,7 @@ #include #include "SSD1306Display.h" #include "espconnect.h" + #include #else // for AVR #include #include @@ -67,7 +68,36 @@ #if defined(ESP8266) extern ESP8266WebServer *update_server; extern OTF::OpenThingsFramework *otf; - extern ENC28J60lwIP eth; + extern ENC28J60lwIP enc28j60; + extern Wiznet5500lwIP w5500; + struct lwipEth { + bool isW5500 = false; + inline boolean config(const IPAddress& local_ip, const IPAddress& arg1, const IPAddress& arg2, const IPAddress& arg3 = IPADDR_NONE, const IPAddress& dns2 = IPADDR_NONE) { + return (isW5500)?w5500.config(local_ip, arg1, arg2, arg3, dns2) : enc28j60.config(local_ip, arg1, arg2, arg3, dns2); + } + inline boolean begin(const uint8_t *macAddress = nullptr) { + return (isW5500)?w5500.begin(macAddress):enc28j60.begin(macAddress); + } + inline IPAddress localIP() { + return (isW5500)?w5500.localIP():enc28j60.localIP(); + } + inline IPAddress subnetMask() { + return (isW5500)?w5500.subnetMask():enc28j60.subnetMask(); + } + inline IPAddress gatewayIP() { + return (isW5500)?w5500.gatewayIP():enc28j60.gatewayIP(); + } + inline void setDefault() { + (isW5500)?w5500.setDefault():enc28j60.setDefault(); + } + inline bool connected() { + return (isW5500)?w5500.connected():enc28j60.connected(); + } + inline wl_status_t status() { + return (isW5500)?w5500.status():enc28j60.status(); + } + }; + extern lwipEth eth; #else extern EthernetServer *m_server; #endif diff --git a/README.txt b/README.txt index db30fc39..e379f91d 100755 --- a/README.txt +++ b/README.txt @@ -4,11 +4,15 @@ This is a unified OpenSprinkler firmware for Arduino, and Linux-based OpenSprinklers such as OpenSprinkler Pi. -For OS (Arduino-based OpenSprinkler) 2.x: -https://openthings.freshdesk.com/support/solutions/articles/5000165132-how-to-compile-opensprinkler-firmware +Compilation instructions for OS (Arduino-based OpenSprinkler) 2.3 and 3.x: +* Install VS Code +* Launch VS Code, search and install the platformio extension. +* Download and unzip the OpenSprinkler firmware repository, open the folder in VS Code, at the bottom of the screen, click PlatformIO:Build. The firmware repository contains platformio.ini which has all the information needed for PlatformIO to build the firmware. +Additional details: +https://openthings.freshdesk.com/support/solutions/articles/5000165132 For OSPi/OSBO or other Linux-based OpenSprinkler: -https://openthings.freshdesk.com/support/solutions/articles/5000631599-installing-and-updating-the-unified-firmware +https://openthings.freshdesk.com/support/solutions/articles/5000631599 ============================================ Questions and comments: diff --git a/defines.h b/defines.h index 577f4c6e..f48a6c8f 100755 --- a/defines.h +++ b/defines.h @@ -24,7 +24,7 @@ #ifndef _DEFINES_H #define _DEFINES_H -//#define ENABLE_DEBUG // enable serial debug +#define ENABLE_DEBUG // enable serial debug typedef unsigned char byte; typedef unsigned long ulong; diff --git a/main.cpp b/main.cpp index 3ce0abd5..74963615 100644 --- a/main.cpp +++ b/main.cpp @@ -34,7 +34,9 @@ ESP8266WebServer *update_server = NULL; OTF::OpenThingsFramework *otf = NULL; DNSServer *dns = NULL; - ENC28J60lwIP eth(PIN_ETHER_CS); // ENC28J60 lwip for wired Ether + ENC28J60lwIP enc28j60(PIN_ETHER_CS); // ENC28J60 lwip for wired Ether + Wiznet5500lwIP w5500(PIN_ETHER_CS); // W5500 lwip for wired Ether + lwipEth eth; bool useEth = false; // tracks whether we are using WiFi or wired Ether connection static uint16_t led_blink_ms = LED_FAST_BLINK; #else diff --git a/opensprinkler_server.cpp b/opensprinkler_server.cpp index 3494a289..d0fd4ccc 100644 --- a/opensprinkler_server.cpp +++ b/opensprinkler_server.cpp @@ -38,7 +38,9 @@ extern ESP8266WebServer *update_server; extern OTF::OpenThingsFramework *otf; - extern ENC28J60lwIP eth; + extern ENC28J60lwIP enc28j60; + extern Wiznet5500lwIP w5500; + extern lwipEth eth; #define OTF_PARAMS_DEF const OTF::Request &req,OTF::Response &res #define OTF_PARAMS req,res #define FKV_SOURCE req @@ -1909,8 +1911,13 @@ void server_json_debug(OTF_PARAMS_DEF) { (uint16_t)ESP.getFreeHeap()); FSInfo fs_info; LittleFS.info(fs_info); - bfill.emit_p(PSTR(",\"flash\":$D,\"used\":$D,\"rssi\":$D,\"bssid\":\"$S\",\"bssidchl\":\"$O\"}"), - fs_info.totalBytes, fs_info.usedBytes, WiFi.RSSI(), WiFi.BSSIDstr().c_str(), SOPT_STA_BSSID_CHL); + bfill.emit_p(PSTR(",\"flash\":$D,\"used\":$D,"), fs_info.totalBytes, fs_info.usedBytes); + if(useEth) { + bfill.emit_p(PSTR("\"isW5500\":$D}"), eth.isW5500); + } else { + bfill.emit_p(PSTR("\"rssi\":$D,\"bssid\":\"$S\",\"bssidchl\":\"$O\"}"), + WiFi.RSSI(), WiFi.BSSIDstr().c_str(), SOPT_STA_BSSID_CHL); + } /* // print out all log files and all files in the main folder with file sizes From 63acd6a9f6c18f780c4f6223654805cc8b3b3c40 Mon Sep 17 00:00:00 2001 From: Rui Wang Date: Sun, 8 Jan 2023 14:19:36 -0500 Subject: [PATCH 3/5] add low-level code to check existence of w5500; without this, eth.begin will cause a crash --- OpenSprinkler.cpp | 42 ++++++++++++++++++++++++++++++++++++------ OpenSprinkler.h | 1 - defines.h | 2 +- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/OpenSprinkler.cpp b/OpenSprinkler.cpp index dfc8c3c2..7c11170b 100644 --- a/OpenSprinkler.cpp +++ b/OpenSprinkler.cpp @@ -509,13 +509,18 @@ byte OpenSprinkler::start_ether() { SPI.setFrequency(4000000); if(eth.isW5500) { - DEBUG_PRINTLN(F("check W5500")); - /* this is copied from w5500.cpp */ - /* perform a software reset and see if we get a response */ + DEBUG_PRINTLN(F("detect existence of W5500")); + /* this is copied from w5500.cpp wizchip_sw_reset + * perform a software reset and see if we get a correct response + * without this, eth.begin will crash if W5500 is not connected + * ideally wizchip_sw_reset should return a value but since it doesn't + * we have to extract it code here + * */ static const uint8_t AccessModeRead = (0x00 << 2); static const uint8_t AccessModeWrite = (0x01 << 2); static const uint8_t BlockSelectCReg = (0x00 << 3); pinMode(PIN_ETHER_CS, OUTPUT); + // ==> setMR(MR_RST) digitalWrite(PIN_ETHER_CS, LOW); SPI.transfer((0x00 & 0xFF00) >> 8); SPI.transfer((0x00 & 0x00FF) >> 0); @@ -523,6 +528,7 @@ byte OpenSprinkler::start_ether() { SPI.transfer(0x80); digitalWrite(PIN_ETHER_CS, HIGH); + // ==> ret = getMR() uint8_t ret; digitalWrite(PIN_ETHER_CS, LOW); SPI.transfer((0x00 & 0xFF00) >> 8); @@ -532,9 +538,33 @@ byte OpenSprinkler::start_ether() { digitalWrite(PIN_ETHER_CS, HIGH); if(ret!=0) return 0; // ret is expected to be 0 } else { - /* this is from */ - /* get erevid and see if we get a response */ - DEBUG_PRINTLN(F("check ENC28J60")); + /* this is copied from enc28j60.cpp geterevid + * check to see if the hardware revision number if expected + * */ + DEBUG_PRINTLN(F("detect existence of ENC28J60")); + #define MAADRX_BANK 0x03 + #define EREVID 0x12 + #define ECON1 0x1f + + // ==> setregbank(MAADRX_BANK); + pinMode(PIN_ETHER_CS, OUTPUT); + uint8_t r; + digitalWrite(PIN_ETHER_CS, LOW); + SPI.transfer(0x00 | (ECON1 & 0x1f)); + r = SPI.transfer(0); + digitalWrite(PIN_ETHER_CS, HIGH); + + digitalWrite(PIN_ETHER_CS, LOW); + SPI.transfer(0x40 | (ECON1 & 0x1f)); + SPI.transfer((r & 0xfc) | (MAADRX_BANK & 0x03)); + digitalWrite(PIN_ETHER_CS, HIGH); + + // ==> r = readreg(EREVID); + digitalWrite(PIN_ETHER_CS, LOW); + SPI.transfer(0x00 | (EREVID & 0x1f)); + r = SPI.transfer(0); + digitalWrite(PIN_ETHER_CS, HIGH); + if(r==0 || r==255) return 0; // r is expected to be a non-255 revision number } load_hardware_mac((uint8_t*)tmp_buffer, true); diff --git a/OpenSprinkler.h b/OpenSprinkler.h index bcf46113..06b60321 100644 --- a/OpenSprinkler.h +++ b/OpenSprinkler.h @@ -48,7 +48,6 @@ #include #include "SSD1306Display.h" #include "espconnect.h" - #include #else // for AVR #include #include diff --git a/defines.h b/defines.h index f48a6c8f..577f4c6e 100755 --- a/defines.h +++ b/defines.h @@ -24,7 +24,7 @@ #ifndef _DEFINES_H #define _DEFINES_H -#define ENABLE_DEBUG // enable serial debug +//#define ENABLE_DEBUG // enable serial debug typedef unsigned char byte; typedef unsigned long ulong; From cc0b0887ef1c4d2f1ef3386120b824c9fe71de47 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 5 Jul 2023 16:33:40 -0400 Subject: [PATCH 4/5] 1) add display msg to show wired ethernet module type; 2) bump minor revision number; 3) fix rain delay display issue on 64-bit arm OS; 4) change platformio to use Arduino ESP8266 core 3.1.2 --- OpenSprinkler.cpp | 3 ++- defines.h | 2 +- opensprinkler_server.h | 3 ++- platformio.ini | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenSprinkler.cpp b/OpenSprinkler.cpp index e2c977ad..0637f50f 100644 --- a/OpenSprinkler.cpp +++ b/OpenSprinkler.cpp @@ -578,7 +578,8 @@ byte OpenSprinkler::start_ether() { eth.setDefault(); if(!eth.begin((uint8_t*)tmp_buffer)) return 0; lcd_print_line_clear_pgm(PSTR("Start wired link"), 1); - + lcd_print_line_clear_pgm(eth.isW5500 ? PSTR(" (w5500) ") : PSTR(" (enc28j60) "), 2); + ulong timeout = millis()+30000; // 30 seconds time out while (!eth.connected()) { DEBUG_PRINT("."); diff --git a/defines.h b/defines.h index 577f4c6e..d131ed45 100755 --- a/defines.h +++ b/defines.h @@ -36,7 +36,7 @@ typedef unsigned long ulong; // if this number is different from the one stored in non-volatile memory // a device reset will be automatically triggered -#define OS_FW_MINOR 2 // Firmware minor version +#define OS_FW_MINOR 3 // Firmware minor version /** Hardware version base numbers */ #define OS_HW_VERSION_BASE 0x00 // OpenSprinkler diff --git a/opensprinkler_server.h b/opensprinkler_server.h index b40d2ab5..fc005ca1 100644 --- a/opensprinkler_server.h +++ b/opensprinkler_server.h @@ -56,7 +56,8 @@ class BufferFiller { break; case 'L': //ltoa(va_arg(ap, long), (char*) ptr, 10); - ultoa(va_arg(ap, long), (char*) ptr, 10); // ray + //ultoa(va_arg(ap, long), (char*) ptr, 10); // ray + sprintf((char*) ptr, "%lu", va_arg(ap, long)); break; case 'S': strcpy((char*) ptr, va_arg(ap, const char*)); diff --git a/platformio.ini b/platformio.ini index 8dc1175d..82ad5dd3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,7 +16,7 @@ src_dir = . include_dir = . [env:d1_mini] -platform = espressif8266@3.2.0 +platform = espressif8266@4.2.0 board = d1_mini framework = arduino lib_ldf_mode = deep From 9d8f8b087ef7b84794cd9a91369a9085d3076b9b Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 27 Jul 2023 10:10:34 -0400 Subject: [PATCH 5/5] second try to fix arm64 rain delay display issue --- build.sh | 6 +++--- opensprinkler_server.h | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index 8c5df9f5..a221645b 100755 --- a/build.sh +++ b/build.sh @@ -14,12 +14,12 @@ if [ "$1" == "demo" ]; then echo "Installing required libraries..." apt-get install -y libmosquitto-dev echo "Compiling firmware..." - g++ -o OpenSprinkler -DDEMO -std=c++14 -m32 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto + g++ -o OpenSprinkler -DDEMO -std=c++14 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto elif [ "$1" == "osbo" ]; then echo "Installing required libraries..." apt-get install -y libmosquitto-dev echo "Compiling firmware..." - g++ -o OpenSprinkler -DOSBO main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto + g++ -o OpenSprinkler -DOSBO -std=c++14 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto else echo "Installing required libraries..." apt-get update @@ -31,7 +31,7 @@ else exit 0 fi echo "Compiling firmware..." - g++ -o OpenSprinkler -DOSPI main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto + g++ -o OpenSprinkler -DOSPI -std=c++14 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto fi if [ ! "$SILENT" = true ] && [ -f OpenSprinkler.launch ] && [ ! -f /etc/init.d/OpenSprinkler.sh ]; then diff --git a/opensprinkler_server.h b/opensprinkler_server.h index fc005ca1..1778cee0 100644 --- a/opensprinkler_server.h +++ b/opensprinkler_server.h @@ -51,13 +51,11 @@ class BufferFiller { c = pgm_read_byte(fmt++); switch (c) { case 'D': - //wtoa(va_arg(ap, uint16_t), (char*) ptr); itoa(va_arg(ap, int), (char*) ptr, 10); // ray break; case 'L': - //ltoa(va_arg(ap, long), (char*) ptr, 10); - //ultoa(va_arg(ap, long), (char*) ptr, 10); // ray - sprintf((char*) ptr, "%lu", va_arg(ap, long)); + ultoa(va_arg(ap, uint32_t), (char*) ptr, 10); + //sprintf((char*) ptr, "%lu", va_arg(ap, uint32_t)); break; case 'S': strcpy((char*) ptr, va_arg(ap, const char*));