diff --git a/.travis.yml b/.travis.yml index a326089..47ef0a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,7 @@ python: - "2.7" env: - # - PLATFORMIO_PROJECT_DIR=examples/arduino-blink - # - PLATFORMIO_PROJECT_DIR=examples/arduino-external-libs - # - PLATFORMIO_PROJECT_DIR=examples/arduino-internal-libs - # - PLATFORMIO_PROJECT_DIR=examples/arduino-own-src_dir - # - PLATFORMIO_PROJECT_DIR=examples/digitstump-mouse - # - PLATFORMIO_PROJECT_DIR=examples/engduino-magnetometer - # - PLATFORMIO_PROJECT_DIR=examples/native-blink - # - PLATFORMIO_PROJECT_DIR=examples/simba-blink + - PLATFORMIO_PROJECT_DIR=examples/native-blink install: - pip install -U https://github.com/platformio/platformio/archive/develop.zip @@ -22,8 +15,8 @@ script: notifications: email: false - # slack: - # rooms: - # secure: JZsFjgJTcERjMOY5NnVUOrVWK2nfnGKmDNhmblWMGGnF/OpkhgTtScuM6ZJtmI8FOjWmgLy0iV6JSMZLtiKFuaUbIKkJvGU7X1H4ctQNter179ZEPjch4taiUOAZf2Jpa5vpVbBNPsafSxnvuBhFX2iXMghnWED910G2zji8gvepDjKEHUl39pIR05Hx6rlMYd+FAI325ACjnAWX0DVLbCoWI2ho4IhBYko8pEA5Uuy9FQFSchFlI9FfYQOx60/F8zAAyLbf77X6mZj7f7Z0/Y4Y5pwW6oVHZ8/Ok1BpBaOQlI1bCJAoRM2NxQjLhg7KnWD/Mp0WtybCD5oWlZsOxieZfa8Fb5OQSNC3eIbw6EQtrez+6Ug+RsvO05//4IKatGQhSlECoBCR6ImNF5PDCa1nPbmDJ+vgE4LIS8FzgAsOfGXrtAujthnVAq6jzVJ6C/i2qBRXowmYFv7epfkP+c+evjOOtWg0OZIDbdSOPSYt2JdA42mEmH3kYF5t46m6934Im0nwVsd3MEEnmuGbPQIf1S8Fq+QOS+rB8+tF4cD626+0FJpLpZTI8oCDglABP+kdV6CG5yl/zHO2n+4POeuG8h+f/WHvUotnZY4q/5PmwpjWYl7A8qG5Qp51opc5B15aCMf1HD4aCFNFXGuQM6VNfgXMGgntu7isFe/kTUg= - # on_failure: always - # on_success: change + slack: + rooms: + secure: rj5uPo81WQHQ6o5hNkIwvptlQezVY6jjsdedqsTAPzRxDGGa3M8NdXJyPLmR2MgN7wDF0UctJC+btiedAcW1G1Szbi7YNTGPhEvUDcJAhTmDVBbNlviHO0xL77wQLXWmEZBLAIiHGGaVoE0wbCryVqCf7pHfK5q7FkgJ1t2tM2QtzBn8IZdAi05RqSuiq6rOZlevg3txUMji6kNaAu3OiqQQmQzDuTyELEi3G/nkqJ5Wze5KoY3ILxYhqCSplodptksZfE+b1o9rMgutNR0QlTORmzP2FM71TtlU9b68XB24Gc1nv49wHdhiZ/EnqAZfyDdFa4IoHPk+GleY0Nm2eCOTSdkbmMagtp8ZhZS9okHsWLhKHkJTNjGawUOHRy99jti1kEWf/Uici1rkqi4CJHbxr83cEFOjGYZYI4SQWBBKyYAB0uqAfRK6QUAQKwutjiyOSwtfzncWtVpP4bSLE2n8prt1Vhbphy8w9etyy+DjjqSgAj4Mr13k/HlaVxfm9OwU2qHtx/TkzA76tNe0af5DNsmDGl8nEV3sMmtT0SselSUkE5DWTag/RiEVM8fX/K+/gw8PnCmxiY28I9F0EisGlitUS19NbUA0nLIO/3V6E8heilzAhMxe3FYPil/0FdQQE/vT4tefofrg4fEV4l9mP3AFNB3yomGIx1h6Bfs= + on_failure: always + on_success: change diff --git a/README.md b/README.md index 2e3f5c6..ccdc109 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,35 @@ -# platform-mcs51 -MCS51: development platform for PlatformIO https://github.com/platformio/platform-mcs51/wiki +# Intel MCS-51 (8051): development platform for [PlatformIO](http://platformio.org) +[![Build Status](https://travis-ci.org/platformio/platform-intel_mcs51.svg?branch=develop)](https://travis-ci.org/platformio/platform-intel_mcs51) +[![Build status](https://ci.appveyor.com/api/projects/status/0207sb475heyoaxa/branch/develop?svg=true)](https://ci.appveyor.com/project/ivankravets/platform-intel-mcs51/branch/develop) -**This platform is EXPERIMENTAL, expect things to fail.** +The Intel MCS-51 (commonly termed 8051) is an internally Harvard architecture, complex instruction set computer (CISC) instruction set, single chip microcontroller (µC) series developed by Intel in 1980 for use in embedded systems. -# HOWTO (Setup Platform.io for MCS-51) +* [Home](http://platformio.org/platforms/intel_mcs51) (home page in PlatformIO Registry) +* [Documentation](http://docs.platformio.org/page/platforms/intel_mcs51.html) (advanced usage, packages, boards, frameworks, etc.) -You only need one magic command: +# Usage -- `$ platformio platforms install https://github.com/platformio/platform-mcs51.git` +1. [Install PlatformIO](http://platformio.org) +2. Create PlatformIO project and configure a platform option in [platformio.ini](http://docs.platformio.org/page/projectconf.html) file: -# HOWTO (Setup your MCS-51 project) -## The simple way: +## Stable version -1. PlatformIO -> Initialize or Update PlatformIO Project -2. Select Board -> Nuvoton -> n79e85x -3. Choose a directory -4. Process! +```ini +[env:stable] +platform = intel_mcs51 +board = ... +... +``` -## The manual way: +## Development version -1. Add your project folder -2. move your project into PlatformIO layout (that is, source codes in `/src`, and library files in `/lib`) -3. create `platformio.ini`, and put in the following content: -``` -[env:n79e85x] -platform = mcs51 -board = n79e85x ; -framework = naked +```ini +[env:development] +platform = https://github.com/platformio/platform-intel_mcs51.git +board = ... +... ``` -## mcu support -### Nuvoton -* n79e85x -### STC -(Experimental!) -* STC15F204EA (Ram: 256, Flash: 4k) -* STC15W404AS (Ram: 256 + 256, Flash: 4k) -* STC15W408AS (Ram: 256 + 256, Flash: 8k) +# Configuration -example: -``` -board = stc15w408as -upload_protocol = stcgal -upload_port = /dev/ttyUSB0 -``` +Please navigate to [documentation](http://docs.platformio.org/page/platforms/intel_mcs51.html). diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..52aea67 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,22 @@ +build: off +environment: + + matrix: + - PLATFORMIO_PROJECT_DIR: "examples/native-blink" + +install: +- cmd: git submodule update --init --recursive +- cmd: SET PATH=%PATH%;C:\Python27\Scripts +- cmd: pip install -U https://github.com/platformio/platformio/archive/develop.zip +- cmd: platformio platform install file://. + +test_script: +- cmd: platformio run -d %PLATFORMIO_PROJECT_DIR% + +notifications: + - provider: Slack + incoming_webhook: + secure: E9H0SU0Ju7WLDvgxsV8cs3J62T3nTTX7QkEjsczN0Sto/c9hWkVfhc5gGWUkxhlD975cokHByKGJIdwYwCewqOI+7BrcT8U+nlga4Uau7J8= + on_build_success: false + on_build_failure: true + on_build_status_changed: true diff --git a/boards/n79e8432.json b/boards/n79e8432.json index 4b1d5e5..d8bdafa 100644 --- a/boards/n79e8432.json +++ b/boards/n79e8432.json @@ -1,25 +1,22 @@ { "build": { "core": "naked", - "extra_flags": [ - "-DN79E84X", "-DN79E8432", "-DNAKED_ARCH_MCS51", "-DNAKED_MCS51_N79E84X" - ], + "extra_flags": "-DN79E84X -DN79E8432 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E84X", "f_cpu": "22118400L", "size_iram": 256, "size_xram": 256, "size_code": 4096, "size_heap": 128, - "mcu": "mcs51", + "mcu": "n79e8432", + "cpu": "mcs51", "variant": "n79e84x" }, - "frameworks": [ - "naked" - ], + "frameworks": [], "upload": { "maximum_ram_size": 512, "maximum_size": 4096 }, - "name": "n79e8432", + "name": "Generic N79E8432", "url": "http://www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e8432/", "vendor": "Nuvoton" } diff --git a/boards/n79e844.json b/boards/n79e844.json index 1555c75..f8ceeff 100644 --- a/boards/n79e844.json +++ b/boards/n79e844.json @@ -1,22 +1,21 @@ { "build": { "core": "naked", - "extra_flags": "-DN79E84X -DN79E844 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E84X --iram-size 256 --xram-size 256 --code-size 8192 --stack-size 128", + "extra_flags": "-DN79E84X -DN79E844 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E84X", "f_cpu": "22118400L", "size_iram": 256, "size_xram": 256, "size_code": 8192, - "mcu": "mcs51", + "mcu": "n79e844", + "cpu": "mcs51", "variant": "n79e84x" }, - "frameworks": [ - "naked" - ], + "frameworks": [], "upload": { "maximum_ram_size": 512, "maximum_size": 8192 }, - "name": "n79e844", - "url": "www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e844/", + "name": "Generic N79E844", + "url": "http://www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e844/", "vendor": "Nuvoton" } diff --git a/boards/n79e845.json b/boards/n79e845.json index 97b0ca8..3394a36 100644 --- a/boards/n79e845.json +++ b/boards/n79e845.json @@ -1,22 +1,21 @@ { "build": { "core": "naked", - "extra_flags": "-DN79E84X -DN79E845 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E84X --iram-size 256 --xram-size 256 --code-size 16384 --stack-size 128", + "extra_flags": "-DN79E84X -DN79E845 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E84X", "f_cpu": "22118400L", "size_iram": 256, "size_xram": 256, "size_code": 16384, - "mcu": "mcs51", + "mcu": "n79e845", + "cpu": "mcs51", "variant": "n79e84x" }, - "frameworks": [ - "naked" - ], + "frameworks": [], "upload": { "maximum_ram_size": 512, "maximum_size": 16384 }, - "name": "n79e845", - "url": "www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e845/", + "name": "Generic N79E845", + "url": "http://www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e845/", "vendor": "Nuvoton" } diff --git a/boards/n79e854.json b/boards/n79e854.json index 5e89da5..deea215 100644 --- a/boards/n79e854.json +++ b/boards/n79e854.json @@ -1,22 +1,21 @@ { "build": { "core": "naked", - "extra_flags": "-DN79E85X -DN79E854 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E85X --iram-size 256 --xram-size 256 --code-size 8192 --stack-size 128", + "extra_flags": "-DN79E85X -DN79E854 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E85X", "f_cpu": "22118400L", "size_iram": 256, "size_xram": 256, "size_code": 8192, - "mcu": "mcs51", + "mcu": "n79e854", + "cpu": "mcs51", "variant": "n79e85x" }, - "frameworks": [ - "naked" - ], + "frameworks": [], "upload": { "maximum_ram_size": 512, "maximum_size": 8192 }, - "name": "n79e854", - "url": "www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e854/", + "name": "Generic N79E854", + "url": "http://www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e854/", "vendor": "Nuvoton" } diff --git a/boards/n79e855.json b/boards/n79e855.json index c471eb5..c1bd518 100644 --- a/boards/n79e855.json +++ b/boards/n79e855.json @@ -1,25 +1,22 @@ { "build": { "core": "naked", - "extra_flags": [ - "-DN79E85X", "-DN79E855", "-DNAKED_ARCH_MCS51", "-DNAKED_MCS51_N79E85X" - ], + "extra_flags": "-DN79E85X -DN79E855 -DNAKED_ARCH_MCS51 -DNAKED_MCS51_N79E85X", "f_cpu": "22118400L", "size_iram": 256, "size_xram": 256, "size_code": 16384, "size_heap": 128, - "mcu": "mcs51", + "mcu": "n79e855", + "cpu": "mcs51", "variant": "n79e85x" }, - "frameworks": [ - "naked" - ], + "frameworks": [], "upload": { "maximum_ram_size": 512, "maximum_size": 16384 }, - "name": "n79e855", - "url": "www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e855/", + "name": "Generic N79E855", + "url": "http://www.nuvoton.com/hq/products/microcontrollers/8bit-8051-mcus/low-pin-count-8051-series/n79e855/", "vendor": "Nuvoton" } diff --git a/boards/stc15f204ea.json b/boards/stc15f204ea.json index f107dfa..48de104 100644 --- a/boards/stc15f204ea.json +++ b/boards/stc15f204ea.json @@ -1,24 +1,23 @@ { "build": { - "extra_flags": [ - "" - ], "f_cpu": "11059200", "size_iram": 256, "size_xram": 0, "size_code": 4096, "size_heap": 64, - "mcu": "mcs51", - "cpu": "8051", - "variant": "stc15f204ea" + "mcu": "stc15f204ea", + "cpu": "mcs51" }, - "frameworks": [ - ], + "frameworks": [], "upload": { "maximum_ram_size": 256, - "maximum_size": 4096 + "maximum_size": 4096, + "protocol": "stcgal", + "protocols": [ + "stcgal" + ] }, - "name": "stc15f204ea", + "name": "Generic STC15F204EA", "url": "https://www.stcmicro.com/STC/STC15F204EA.html", "vendor": "STC" } diff --git a/boards/stc15w404as.json b/boards/stc15w404as.json index 5446fea..6a72c7e 100644 --- a/boards/stc15w404as.json +++ b/boards/stc15w404as.json @@ -1,24 +1,23 @@ { "build": { - "extra_flags": [ - "" - ], "f_cpu": "11059200", "size_iram": 256, "size_xram": 256, "size_code": 4096, "size_heap": 128, - "mcu": "mcs51", - "cpu": "8051", - "variant": "stc15w404as" + "mcu": "stc15w408as", + "cpu": "mcs51" }, - "frameworks": [ - ], + "frameworks": [], "upload": { "maximum_ram_size": 512, - "maximum_size": 4096 + "maximum_size": 4096, + "protocol": "stcgal", + "protocols": [ + "stcgal" + ] }, - "name": "stc15w404as", + "name": "Generic STC15W408AS", "url": "https://www.stcmicro.com/STC/STC15W408AS.html", "vendor": "STC" } diff --git a/boards/stc15w408as.json b/boards/stc15w408as.json index 6a7c010..075bb4b 100644 --- a/boards/stc15w408as.json +++ b/boards/stc15w408as.json @@ -1,24 +1,23 @@ { "build": { - "extra_flags": [ - "" - ], "f_cpu": "11059200", "size_iram": 256, "size_xram": 256, "size_code": 8192, "size_heap": 128, - "mcu": "mcs51", - "cpu": "8051", - "variant": "stc15w408as" + "mcu": "stc15w408as", + "cpu": "mcs51" }, - "frameworks": [ - ], + "frameworks": [], "upload": { "maximum_ram_size": 512, - "maximum_size": 8192 + "maximum_size": 8192, + "protocol": "stcgal", + "protocols": [ + "stcgal" + ] }, - "name": "stc15w408as", + "name": "Generic STC15W408AS", "url": "https://www.stcmicro.com/STC/STC15W408AS.html", "vendor": "STC" } diff --git a/builder/frameworks/naked.py b/builder/frameworks/naked.py deleted file mode 100644 index bc687f1..0000000 --- a/builder/frameworks/naked.py +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2014-present PlatformIO -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -Naked - -Naked framework for MCS-51, barely nothing but make things compiles. -""" - -from os.path import isdir, join - -from SCons.Script import DefaultEnvironment - -env = DefaultEnvironment() -platform = env.PioPlatform() - -FRAMEWORK_DIR = platform.get_package_dir("framework-nakedmcs51") -FRAMEWORK_VERSION = platform.get_package_version("framework-nakedmcs51") -assert isdir(FRAMEWORK_DIR) - -env.Append( - CPPPATH=[ - join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) - ] -) - -# -# Lookup for specific core's libraries -# - -BOARD_CORELIBDIRNAME = env.BoardConfig().get("build.core", "") -env.Append( - LIBSOURCE_DIRS=[ - join(FRAMEWORK_DIR, "libraries", "__cores__", BOARD_CORELIBDIRNAME), - join(FRAMEWORK_DIR, "libraries") - ] -) - -# -# Target: Build Core Library -# - -libs = [] - -if "build.variant" in env.BoardConfig(): - env.Append( - CPPPATH=[ - join(FRAMEWORK_DIR, "variants", - env.BoardConfig().get("build.variant")) - ] - ) - libs.append(env.BuildLibrary( - join("$BUILD_DIR", "FrameworkNakedVariant"), - join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant")) - )) - -envsafe = env.Clone() - -libs.append(envsafe.BuildLibrary( - join("$BUILD_DIR", "FrameworkNaked"), - join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) -)) - -env.Prepend(LIBS=libs) diff --git a/builder/main.py b/builder/main.py index 95465ce..ca0274a 100644 --- a/builder/main.py +++ b/builder/main.py @@ -12,46 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" - Builder for MCS-51 series of microcontrollers -""" - +import sys from os.path import join -from time import sleep - -from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild, - Builder, Default, DefaultEnvironment) - -from platformio.util import get_serialports - - -def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 - - if "program" in COMMAND_LINE_TARGETS: - return - - upload_options = {} - if "BOARD" in env: - upload_options = env.BoardConfig().get("upload", {}) - - # Deprecated: compatibility with old projects. Use `program` instead - if "usb" in env.subst("$UPLOAD_PROTOCOL"): - upload_options['require_upload_port'] = False - env.Replace(UPLOAD_SPEED=None) - - if env.subst("$UPLOAD_SPEED"): - env.Append(UPLOADERFLAGS=["-b", "$UPLOAD_SPEED"]) - - if upload_options and not upload_options.get("require_upload_port", False): - return - env.AutodetectUploadPort() - env.Append(UPLOADERFLAGS=["-P", '"$UPLOAD_PORT"']) - - if not upload_options.get("disable_flushing", False): - env.FlushSerialBuffer("$UPLOAD_PORT") - - before_ports = get_serialports() +from SCons.Script import ARGUMENTS, AlwaysBuild, Default, DefaultEnvironment def __getSize(size_type, env): @@ -66,7 +30,28 @@ def __getSize(size_type, env): })[size_type]) +def _parseSdccFlags(flags): + assert flags + if isinstance(flags, list): + flags = " ".join(flags) + flags = str(flags) + parsed_flags = [] + unparsed_flags = [] + prev_token = "" + for token in flags.split(" "): + if prev_token.startswith("--") and not token.startswith("-"): + parsed_flags.extend([prev_token, token]) + prev_token = "" + continue + if prev_token: + unparsed_flags.append(prev_token) + prev_token = token + unparsed_flags.append(prev_token) + return (parsed_flags, unparsed_flags) + + env = DefaultEnvironment() +board_config = env.BoardConfig() env.Replace( AR="sdar", @@ -77,6 +62,18 @@ def __getSize(size_type, env): OBJCOPY="sdobjcopy", OBJSUFFIX=".rel", LIBSUFFIX=".lib", + SIZETOOL=join(env.PioPlatform().get_dir(), "builder", "size.py"), + + SIZECHECKCMD='$PYTHONEXE $SIZETOOL $SOURCES', + SIZEPRINTCMD='"$PYTHONEXE" $SIZETOOL $SOURCES', + SIZEPROGREGEXP=r"^ROM/EPROM/FLASH\s+[a-fx\d]+\s+[a-fx\d]+\s+(\d+).*", + + PROGNAME="firmware", + PROGSUFFIX=".hex" +) + +env.Append( + ASFLAGS=env.get("CCFLAGS", [])[:], CFLAGS=[ "--std-sdcc11" @@ -85,7 +82,7 @@ def __getSize(size_type, env): CCFLAGS=[ "--opt-code-size", # optimize for size "--peep-return", # peephole optimization for return instructions - "-m$BOARD_MCU" + "-m%s" % board_config.get("build.cpu") ], CPPDEFINES=[ @@ -94,106 +91,84 @@ def __getSize(size_type, env): ], LINKFLAGS=[ - "-m$BOARD_MCU", + "-m%s" % board_config.get("build.cpu"), "--iram-size", __getSize("size_iram", env), "--xram-size", __getSize("size_xram", env), "--code-size", __getSize("size_code", env), - "$BUILD_FLAGS", - "--out-fmt-ihx", - ], - - # LIBS=["m"], - - # SIZEPRINTCMD='$SIZETOOL --mcu=$BOARD_MCU -C -d $SOURCES', - - PROGNAME="firmware", - PROGSUFFIX=".ihx" -) - -env.Append( - ASFLAGS=env.get("CCFLAGS", [])[:], - - BUILDERS=dict( - ElfToEep=Builder( - action=env.VerboseAction(" ".join([ - "$OBJCOPY", - "-O", - "ihex", - "-j", - ".eeprom", - '--set-section-flags=.eeprom="alloc,load"', - "--no-change-warnings", - "--change-section-lma", - ".eeprom=0", - "$SOURCES", - "$TARGET" - ]), "Building $TARGET"), - suffix=".eep" - ), - - ElfToHex=Builder( - action=env.VerboseAction(" ".join([ - "$OBJCOPY", - "-O", - "ihex", - "-R", - ".eeprom", - "$SOURCES", - "$TARGET" - ]), "Building $TARGET"), - suffix=".hex" - ) - ) + "--out-fmt-ihx" + ] ) if int(ARGUMENTS.get("PIOVERBOSE", 0)): env.Prepend(UPLOADERFLAGS=["-v"]) +# parse manually SDCC flags +if env.get("BUILD_FLAGS"): + _parsed, _unparsed = _parseSdccFlags(env.get("BUILD_FLAGS")) + env.Append(CCFLAGS=_parsed) + env['BUILD_FLAGS'] = _unparsed + +project_sdcc_flags = None +if env.get("SRC_BUILD_FLAGS"): + project_sdcc_flags, _unparsed = _parseSdccFlags(env.get("SRC_BUILD_FLAGS")) + env['SRC_BUILD_FLAGS'] = _unparsed + # # Target: Build executable and linkable firmware # target_firm = env.BuildProgram() +if project_sdcc_flags: + env.Import("projenv") + projenv.Append(CCFLAGS=project_sdcc_flags) + +AlwaysBuild(env.Alias("nobuild", target_firm)) +target_buildprog = env.Alias("buildprog", target_firm, target_firm) + # -# Target: Upload by default .hex file +# Target: Print binary size # -# options for stcgal uploader tool -# https://github.com/grigorig/stcgal - -if env.subst("$UPLOAD_PROTOCOL") == "stcgal": - if "BOARD" in env and env.BoardConfig().get("vendor") == "STC": - f_cpu_khz = int(env.BoardConfig().get("build.f_cpu")) / 1000 - env.Replace( - UPLOAD_OPTIONS = [ - "-p", "$UPLOAD_PORT", - "-t", int(f_cpu_khz), - "-a" - ], - STCGALCMD="stcgal", - UPLOADHEXCMD = "$STCGALCMD $UPLOAD_OPTIONS $UPLOAD_FLAGS $SOURCE" - ) - -upload = env.Alias( - ["upload"], target_firm, - [env.VerboseAction(BeforeUpload, "Looking for upload port..."), - env.VerboseAction("$UPLOADHEXCMD", "Uploading $SOURCE")]) -AlwaysBuild(upload) +target_size = env.Alias( + "size", target_firm, + env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE")) +AlwaysBuild(target_size) # -# Target: Upload firmware using external programmer +# Target: Upload firmware # -program = env.Alias( - "program", target_firm, - [env.VerboseAction(BeforeUpload, "Looking for upload port..."), - env.VerboseAction("$PROGRAMHEXCMD", "Programming $SOURCE")]) +upload_protocol = env.subst("$UPLOAD_PROTOCOL") +upload_actions = [] + +if upload_protocol == "stcgal": + f_cpu_khz = int(board_config.get("build.f_cpu")) / 1000 + env.Replace( + UPLOADERFLAGS=[ + "-p", "$UPLOAD_PORT", + "-t", int(f_cpu_khz), + "-a" + ], + UPLOADCMD="python3 stcgal.py $UPLOADERFLAGS $SOURCE") + + upload_actions = [ + env.VerboseAction(env.AutodetectUploadPort, + "Looking for upload port..."), + env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") + ] + +# custom upload tool +elif "UPLOADCMD" in env: + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] + +else: + sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol) -AlwaysBuild(program) +AlwaysBuild(env.Alias("upload", target_firm, upload_actions)) # # Setup default targets # -Default([target_firm]) +Default([target_buildprog, target_size]) diff --git a/platform.py b/builder/size.py similarity index 53% rename from platform.py rename to builder/size.py index 0d26638..19e0f81 100644 --- a/platform.py +++ b/builder/size.py @@ -1,3 +1,5 @@ +from __future__ import print_function + # Copyright 2014-present PlatformIO # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,20 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from platformio.managers.platform import PlatformBase - - -class Mcs51Platform(PlatformBase): - - def configure_default_packages(self, variables, targets): - if variables.get("board"): - board_config = self.board_config(variables.get("board")) +import sys +from os.path import isfile - return PlatformBase.configure_default_packages( - self, variables, targets) - def on_run_err(self, line): # pylint: disable=R0201 - if "avrdude" in line: - self.on_run_out(line) - else: - PlatformBase.on_run_err(self, line) +firmware_hex = sys.argv[1] +assert isfile(firmware_hex) +firmware_mem = firmware_hex[0:-3] + "mem" +with open(firmware_mem) as fp: + print(fp.read()) diff --git a/examples/native-blink/.gitignore b/examples/native-blink/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/native-blink/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/native-blink/.travis.yml b/examples/native-blink/.travis.yml new file mode 100644 index 0000000..a54a28c --- /dev/null +++ b/examples/native-blink/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/native-blink/README.rst b/examples/native-blink/README.rst new file mode 100644 index 0000000..ab5e1c3 --- /dev/null +++ b/examples/native-blink/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-intel_mcs51/examples/native-blink + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e stc15f204ea + + # Upload firmware for the specific environment + > platformio run -e stc15f204ea --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/native-blink/lib/readme.txt b/examples/native-blink/lib/readme.txt new file mode 100644 index 0000000..a7f5971 --- /dev/null +++ b/examples/native-blink/lib/readme.txt @@ -0,0 +1,41 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- readme.txt --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/native-blink/platformio.ini b/examples/native-blink/platformio.ini new file mode 100644 index 0000000..1419e4b --- /dev/null +++ b/examples/native-blink/platformio.ini @@ -0,0 +1,20 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:stc15f204ea] +platform = intel_mcs51 +board = stc15f204ea + +[env:stc15w404as] +platform = intel_mcs51 +board = stc15w404as + +[env:stc15w408as] +platform = intel_mcs51 +board = stc15w408as diff --git a/examples/native-blink/src/blinky.c b/examples/native-blink/src/blinky.c new file mode 100755 index 0000000..4abe513 --- /dev/null +++ b/examples/native-blink/src/blinky.c @@ -0,0 +1,74 @@ +// +// STC15F204EA blinky example +// inspired by http://jjmz.free.fr/?p=179 http://jjmz.free.fr/?p=191 +// and stc15f204ea datasheet +// + +#include +#include +#include + +/* ------------------------------------------------------------------------- */ +/* Printing functions */ +/* ------------------------------------------------------------------------- */ + +//#include "./soft_serial/serial.h" +#include "serial.h" +#define printf printf_small // see sdcc user guide + +// P0.1 called P5.5 on my board? +#define LED P1_6 + +/* ------------------------------------------------------------------------- */ + +// counter +int temp = 100; + +void _delay_ms(unsigned char ms) +{ + // i,j selected for fosc 11.0592MHz, using oscilloscope + // the stc-isp tool gives inaccurate values (perhaps for C51 vs sdcc?) + // max 255 ms + unsigned char i, j; + do { + i = 4; + j = 200; + do + { + while (--j); + } while (--i); + } while (--ms); +} + +const char* startstring = "\nSTC15F204EA starting up...\n"; + +int main() +{ + /* init the software uart */ + UART_INIT(); + + /* simple greeting message */ + printf("%s", startstring); + + LED = 1; + + while(1) + { + LED = 0; + _delay_ms(250); + + //LED = 1; + //_delay_ms(100); + //LED = 0; + //_delay_ms(100); + + LED = 1; + _delay_ms(250); + _delay_ms(250); + _delay_ms(250); + printf("counter: %d \n", temp); + temp++; + WDT_CONTR |= 1 << 4; // clear wdt + } +} +/* ------------------------------------------------------------------------- */ diff --git a/examples/native-blink/src/serial.c b/examples/native-blink/src/serial.c new file mode 100755 index 0000000..7e2a76d --- /dev/null +++ b/examples/native-blink/src/serial.c @@ -0,0 +1,160 @@ +/*--------------------------------------------------------------------------------*/ +/* --- STC MCU International Limited -----------------------------------*/ +/* --- STC 15 Series I/O simulate serial port ----------------------------*/ +/* --- Web: www.STCMCU.com -----------------------------------------*/ +/* If you want to use the program or the program referenced in the */ +/* article, please specify in which data and procedures from STC */ +/*-------------------------------------------------------------------------------*/ +#include +#define SYSCLOCK 11059200 +#define BAUDRATE 9600 +#define BAUDTMR ((0 - (SYSCLOCK / 3 / BAUDRATE)) & 0xFFFF) +//#define BAUDTMR 0xFE80 // 9600bps @ 11.0592MHz + + +#define RXB P3_0 +#define _RXB _P3_0 +#define TXB P3_1 +#define _TXB _P3_1 + +//define UART TX/RX port +typedef __bit BOOL; +typedef unsigned char BYTE; +typedef unsigned int WORD; + +__data __at 0x08 volatile BYTE TBUF; +__data __at 0x09 volatile BYTE RBUF; +__data __at 0x0A volatile BYTE TDAT; +__data __at 0x0B volatile BYTE RDAT; +__data __at 0x0C volatile BYTE TCNT; +__data __at 0x0D volatile BYTE RCNT; +__data __at 0x0E volatile BYTE TBIT; +__data __at 0x0F volatile BYTE RBIT; + +volatile BOOL TING,RING; +volatile BOOL TEND,REND; + +void UART_INIT(); + +void putchar(unsigned char c) +{ + while (!TEND) ; + TBUF=c; TEND=0; TING=1; +} + +#ifdef UART_TEST +BYTE t, r; +BYTE buf[16]; + +void uart_printf(const unsigned char *str) +{ + while (*str) putchar(*str++); +} + +void main() +{ + UART_INIT(); + + uart_printf("Testing UART :\n"); + + while (1) + { + //user's function + if (REND) + { + REND = 0; + buf[r++ & 0x0f] = RBUF; + } + + if (TEND) + { + if (t != r) + { + TEND = 0; + TBUF = buf[t++ & 0x0f]; + TING = 1; + } + } + + } +} +#endif + +//----------------------------------------- +//Timer interrupt routine for UART +//__data __at 0x08 BYTE TBUF; => ar0 +//__data __at 0x09 BYTE RBUF; +//__data __at 0x0A BYTE TDAT; +//__data __at 0x0B BYTE RDAT; +//__data __at 0x0C BYTE TCNT; +//__data __at 0x0D BYTE RCNT; +//__data __at 0x0E BYTE TBIT; +//__data __at 0x0F BYTE RBIT; => ar7 +void _tm1() __interrupt 3 __using 1 +{ + __asm + jb _RING,00002$ + jb _RXB,00000$ + setb _RING + mov r5,#4 + mov r7,#9 + sjmp 00000$ + 00002$: + djnz r5, 00000$ ; if (--RCNT==0) + mov r5,#3 ; RCNT=3 + djnz r7, 00001$ ; if (--RBIT==0) + mov _RBUF,r3 ; RBUF <= r3 (RDAT) + clr _RING + setb _REND + sjmp 00000$ + 00001$: + mov a,r3 ; r3=RDAT + mov C,_RXB ; (C+RDAT)>>1 + rrc a + mov r3,a + 00000$: + __endasm; + + __asm + djnz r4,00010$ + mov r4,#3 + jnb _TING, 00010$ + mov a, r6 + jnz 00011$ + clr _TXB + mov _TDAT,r0 ; TDAT=r2 <= r0=TBUF + mov r6,#9 + sjmp 00010$ + 00011$: + mov a,r2 + setb c + rrc a + mov r2,a + mov _TXB,c + djnz r6, 00010$ + clr _TING + setb _TEND + 00010$: + __endasm; +} + +//----------------------------------------- +//initial UART module variable +void UART_INIT() +{ + TING = 0; + RING = 0; + TEND = 1; + REND = 0; + TCNT = 0; + RCNT = 0; + TMOD &= 0x0F; // Timer1 Mode 0 + AUXR |= 0x40; // T1x12 + TL1 = BAUDTMR & 0xFF; + TH1 = (BAUDTMR & 0xFF00) >> 8; + TR1 = 1; + ET1 = 1; + PT1 = 1; + EA = 1; +} + diff --git a/examples/native-blink/src/serial.h b/examples/native-blink/src/serial.h new file mode 100755 index 0000000..227229a --- /dev/null +++ b/examples/native-blink/src/serial.h @@ -0,0 +1,15 @@ +/*--------------------------------------------------------------------------------*/ +/* --- STC MCU International Limited -----------------------------------*/ +/* --- STC 15 Series I/O simulate serial port ----------------------------*/ +/* --- Web: www.STCMCU.com -----------------------------------------*/ +/* If you want to use the program or the program referenced in the */ +/* article, please specify in which data and procedures from STC */ +/*-------------------------------------------------------------------------------*/ + +void UART_INIT(void); +void _tm1() __interrupt 3 __using 1; +#ifndef PLATFORMIO +void putchar(unsigned char); +#endif +#define uart_put_char putchar +#define _putchar putchar diff --git a/platform.json b/platform.json index f81d464..017cf54 100644 --- a/platform.json +++ b/platform.json @@ -1,45 +1,30 @@ { - "name": "mcs51", - "title": "MCS 8051/8052", - "description": "Intel 8051/8052 8-bit and 3rd party compatible MCUs those which are used almost everywhere.", + "name": "intel_mcs51", + "title": "Intel MCS-51 (8051)", + "description": "The Intel MCS-51 (commonly termed 8051) is an internally Harvard architecture, complex instruction set computer (CISC) instruction set, single chip microcontroller (uC) series developed by Intel in 1980 for use in embedded systems.", "url": "https://en.wikipedia.org/wiki/Intel_MCS-51", - "homepage": "https://github.com/platformio/platform-mcs51", + "homepage": "https://github.com/platformio/platform-intel_mcs51", "license": "Apache-2.0", "engines": { - "platformio": "^3.0.0", - "scons": ">=2.3.0,<2.6.0" + "platformio": "^3.0.0" }, "repository": { "type": "git", - "url": "https://github.com/platformio/platform-mcs51.git" + "url": "https://github.com/platformio/platform-intel_mcs51.git" }, - "version": "0.0.2", + "version": "1.0.0", "packageRepositories": [ "https://dl.bintray.com/platformio/dl-packages/manifest.json", - "https://sourceforge.net/projects/platformio-storage/files/packages/manifest.json/download", - "http://dl.platformio.org/packages/manifest.json", - "https://dl.bintray.com/palatis/platformio-dl-packages/manifest.json" + "http://dl.platformio.org/packages/manifest.json" ], - "frameworks": { - "naked": { - "package": "framework-nakedmcs51", - "script": "builder/frameworks/naked.py" - } - }, "packages": { "toolchain-sdcc": { "type": "toolchain", - "version": "~1.30603" - }, - "framework-nakedmcs51": { - "type": "framework", - "optional": true, - "version": "~0.0.1" + "version": "~1.30603.0" }, - "tool-sreccat": { + "tool-stcgal": { "type": "uploader", - "optional": "true", - "version": "~1.164" + "version": "~1.104.0" } } }