diff --git a/boards/esp32thing.json b/boards/esp32thing.json new file mode 100644 index 0000000..b5d5753 --- /dev/null +++ b/boards/esp32thing.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_ESP32_DEV", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "esp32" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "SparkFun ESP32 Thing", + "upload": { + "maximum_ram_size": 114688, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "https://www.sparkfun.com/products/13907", + "vendor": "SparkFun Electronics" +} diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 67bb3fd..a35c257 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -30,13 +30,11 @@ env = DefaultEnvironment() platform = env.PioPlatform() FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") -FRAMEWORK_VERSION = platform.get_package_version( - "framework-arduinoespressif32") assert isdir(FRAMEWORK_DIR) env.Prepend( CPPDEFINES=[ - "ARDUINO=%s" % FRAMEWORK_VERSION.split(".")[1], + "ARDUINO=10600", "ARDUINO_ARCH_ESP32" ], diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 39c49b5..6596cfd 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -37,42 +37,47 @@ FRAMEWORK_VERSION = platform.get_package_version( assert isdir(FRAMEWORK_DIR) -def generate_ld_script(): - if not isdir(env.subst("$BUILD_DIR")): - makedirs(env.subst("$BUILD_DIR")) - result = exec_command([ - join(platform.get_package_dir("toolchain-xtensa32") - or "", "bin", env.subst("$CC")), - "-I", env.subst("$PROJECTSRC_DIR"), - "-C", "-P", "-x", "c", "-E", - join(env.subst("$ESPIDF_DIR"), "components", - "esp32", "ld", "esp32.ld"), - "-o", join(env.subst("$BUILD_DIR"), "esp32_out.ld") - ]) +def build_espidf_bootloader(): + envsafe = env.Clone() + framework_dir = env.subst("$ESPIDF_DIR") + envsafe.Replace( + CPPDEFINES=["ESP_PLATFORM", "BOOTLOADER_BUILD=1"], - if result['returncode'] != 0: - sys.stderr.write( - "Cannot create linker script! %s" % result['err']) - env.Exit(1) + LIBPATH=[ + join(framework_dir, "components", "esp32", "ld"), + join(framework_dir, "components", "bootloader", "src", "main") + ], + LINKFLAGS=[ + "-Os", + "-nostdlib", + "-Wl,-static", + "-u", "call_user_start_cpu0", + "-Wl,-static", + "-Wl,--gc-sections", + "-T", "esp32.bootloader.ld", + "-T", "esp32.rom.ld" + ] + ), -def generate_ptable(): - if not isdir(env.subst("$BUILD_DIR")): - makedirs(env.subst("$BUILD_DIR")) + envsafe.Append(CCFLAGS=["-fstrict-volatile-bitfields"]) - result = exec_command([ - env.subst("$PYTHONEXE"), - join(env.subst("$ESPIDF_DIR"), "components", - "partition_table", "gen_esp32part.py"), - "-q", join(env.subst("$ESPIDF_DIR"), "components", - "partition_table", "partitions_singleapp.csv"), - join(env.subst("$BUILD_DIR"), "partitions_table.bin"), - ]) + envsafe.Replace( + LIBS=[ + envsafe.BuildLibrary( + join("$BUILD_DIR", "bootloaderLog"), + join(framework_dir, "components", "log") + ), "gcc" + ] + ) - if result['returncode'] != 0: - sys.stderr.write( - "Cannot create partition table! %s" % result['err']) - env.Exit(1) + return envsafe.Program( + join("$BUILD_DIR", "bootloader.elf"), + envsafe.CollectBuildFiles( + join("$BUILD_DIR", "bootloader"), + join(framework_dir, "components", "bootloader", "src", "main") + ) + ) env.Prepend( CPPPATH=[ @@ -128,11 +133,38 @@ env.Append( ) # -# Generate a specific linker script +# Generate partition table # -generate_ld_script() -generate_ptable() +partition_table = env.Command( + join(env.subst("$BUILD_DIR"), "partitions_table.bin"), + join("$ESPIDF_DIR", "components", + "partition_table", "partitions_singleapp.csv"), + '"$PYTHONEXE" %s -q $SOURCE $TARGET' % join( + "$ESPIDF_DIR", "components", "partition_table", "gen_esp32part.py") +) + +env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table) + + +# +# Generate linker script +# + +linker_script = env.Command( + join("$BUILD_DIR", "esp32_out.ld"), + join("$ESPIDF_DIR", "components", "esp32", "ld", "esp32.ld"), + "$CC -I$PROJECTSRC_DIR -C -P -x c -E $SOURCE -o $TARGET" +) + +env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script) + +# +# Compile bootloader +# + +env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", env.ElfToBin( + join("$BUILD_DIR", "bootloader"), build_espidf_bootloader())) # # Target: Build Core Library diff --git a/builder/main.py b/builder/main.py index d81318b..5f92ffb 100644 --- a/builder/main.py +++ b/builder/main.py @@ -23,49 +23,6 @@ def _get_board_f_flash(env): return str(int(int(frequency) / 1000000)) + "m" -def build_espidf_bootloader(): - envsafe = env.Clone() - framework_dir = env.subst("$ESPIDF_DIR") - envsafe.Replace( - CPPDEFINES=["ESP_PLATFORM", "BOOTLOADER_BUILD=1"], - - LIBPATH=[ - join(framework_dir, "components", "esp32", "ld"), - join(framework_dir, "components", "bootloader", "src", "main") - ], - - LINKFLAGS=[ - "-Os", - "-nostdlib", - "-Wl,-static", - "-u", "call_user_start_cpu0", - "-Wl,-static", - "-Wl,--gc-sections", - "-T", "esp32.bootloader.ld", - "-T", "esp32.rom.ld" - ] - ), - - envsafe.Append(CCFLAGS=["-fstrict-volatile-bitfields"]) - - envsafe.Replace( - LIBS=[ - envsafe.BuildLibrary( - join("$BUILD_DIR", "bootloaderLog"), - join(framework_dir, "components", "log") - ), "gcc" - ] - ) - - return envsafe.Program( - join("$BUILD_DIR", "bootloader.elf"), - envsafe.CollectBuildFiles( - join("$BUILD_DIR", "bootloader"), - join(framework_dir, "components", "bootloader", "src", "main") - ) - ) - - env = DefaultEnvironment() platform = env.PioPlatform() @@ -214,11 +171,6 @@ target_elf = env.BuildProgram() if "PIOFRAMEWORK" in env: target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) -if "espidf" in env.subst("$PIOFRAMEWORK"): - target_boot = env.ElfToBin( - join("$BUILD_DIR", "bootloader"), build_espidf_bootloader()) - env.Depends(target_firm, target_boot) - target_buildprog = env.Alias("buildprog", target_firm, target_firm) diff --git a/platform.json b/platform.json index e5d803e..90138d6 100644 --- a/platform.json +++ b/platform.json @@ -13,7 +13,7 @@ "type": "git", "url": "https://github.com/platformio/platform-espressif32.git" }, - "version": "0.1.0", + "version": "0.1.1", "packageRepositories": [ "https://dl.bintray.com/platformio/dl-packages/manifest.json", "https://sourceforge.net/projects/platformio-storage/files/packages/manifest.json/download",