Refactor support for STM32Duino // Resolve #9

This commit is contained in:
Ivan Kravets 2016-10-12 01:36:48 +03:00
parent 012d7eb939
commit 3f6dbd1b74
10 changed files with 161 additions and 189 deletions

View File

@ -1,28 +1,28 @@
{ {
"build": { "build": {
"core": "maple", "core": "maple",
"cpu": "cortex-m3", "cpu": "cortex-m3",
"extra_flags": "-DMCU_STM32F103C8", "extra_flags": "-DARDUINO_GENERIC_STM32F103C -DMCU_STM32F103C8",
"f_cpu": "72000000L", "f_cpu": "72000000L",
"hwids": [ "hwids": [
["0x1EAF", "0x0003"], ["0x1EAF", "0x0003"],
["0x1EAF", "0x0004"] ["0x1EAF", "0x0004"]
], ],
"ldscript": "jtag_c8.ld", "ldscript": "jtag_c8.ld",
"mcu": "stm32f103c8", "mcu": "stm32f103c8",
"variant": "generic_stm32f103c" "variant": "generic_stm32f103c"
}, },
"frameworks": ["arduino"], "frameworks": ["arduino"],
"name": "STM32F103C8 (20k RAM. 64k Flash)", "name": "STM32F103C8 (20k RAM. 64k Flash)",
"upload": { "upload": {
"disable_flushing": false, "disable_flushing": false,
"maximum_ram_size": 20480, "maximum_ram_size": 20480,
"maximum_size": 65536, "maximum_size": 65536,
"protocol": "maple_serial", "protocol": "serial",
"require_upload_port": true, "require_upload_port": true,
"use_1200bps_touch": false, "use_1200bps_touch": false,
"wait_for_upload_port": false "wait_for_upload_port": false
}, },
"url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103c8.html", "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103c8.html",
"vendor": "Generic" "vendor": "Generic"
} }

View File

@ -1,28 +1,28 @@
{ {
"build": { "build": {
"core": "maple", "core": "maple",
"cpu": "cortex-m3", "cpu": "cortex-m3",
"extra_flags": "-DMCU_STM32F103CB", "extra_flags": "-DARDUINO_GENERIC_STM32F103C -DMCU_STM32F103CB",
"f_cpu": "72000000L", "f_cpu": "72000000L",
"hwids": [ "hwids": [
["0x1EAF", "0x0003"], ["0x1EAF", "0x0003"],
["0x1EAF", "0x0004"] ["0x1EAF", "0x0004"]
], ],
"ldscript": "jtag.ld", "ldscript": "jtag.ld",
"mcu": "stm32f103cb", "mcu": "stm32f103cb",
"variant": "generic_stm32f103c" "variant": "generic_stm32f103c"
}, },
"frameworks": ["arduino"], "frameworks": ["arduino"],
"name": "STM32F103CB (20k RAM. 128k Flash)", "name": "STM32F103CB (20k RAM. 128k Flash)",
"upload": { "upload": {
"disable_flushing": false, "disable_flushing": false,
"maximum_ram_size": 20480, "maximum_ram_size": 20480,
"maximum_size": 131072, "maximum_size": 131072,
"protocol": "maple_serial", "protocol": "serial",
"require_upload_port": true, "require_upload_port": true,
"use_1200bps_touch": false, "use_1200bps_touch": false,
"wait_for_upload_port": false "wait_for_upload_port": false
}, },
"url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103cb.html", "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103cb.html",
"vendor": "Generic" "vendor": "Generic"
} }

View File

@ -1,28 +1,28 @@
{ {
"build": { "build": {
"core": "maple", "core": "maple",
"cpu": "cortex-m3", "cpu": "cortex-m3",
"extra_flags": "-DMCU_STM32F103R8", "extra_flags": "-DARDUINO_GENERIC_STM32F103R -DMCU_STM32F103R8",
"f_cpu": "72000000L", "f_cpu": "72000000L",
"hwids": [ "hwids": [
["0x1EAF", "0x0003"], ["0x1EAF", "0x0003"],
["0x1EAF", "0x0004"] ["0x1EAF", "0x0004"]
], ],
"ldscript": "stm32f103r8.ld", "ldscript": "stm32f103r8.ld",
"mcu": "stm32f103r8", "mcu": "stm32f103r8",
"variant": "generic_stm32f103r8" "variant": "generic_stm32f103r8"
}, },
"frameworks": ["arduino"], "frameworks": ["arduino"],
"name": "STM32F103R8 (20k RAM. 64 Flash)", "name": "STM32F103R8 (20k RAM. 64 Flash)",
"upload": { "upload": {
"disable_flushing": false, "disable_flushing": false,
"maximum_ram_size": 20480, "maximum_ram_size": 20480,
"maximum_size": 65536, "maximum_size": 65536,
"protocol": "maple_serial", "protocol": "serial",
"require_upload_port": true, "require_upload_port": true,
"use_1200bps_touch": false, "use_1200bps_touch": false,
"wait_for_upload_port": false "wait_for_upload_port": false
}, },
"url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103r8.html", "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103r8.html",
"vendor": "Generic" "vendor": "Generic"
} }

View File

@ -1,28 +1,28 @@
{ {
"build": { "build": {
"core": "maple", "core": "maple",
"cpu": "cortex-m3", "cpu": "cortex-m3",
"extra_flags": "-DMCU_STM32F103RB", "extra_flags": "-DARDUINO_GENERIC_STM32F103R -DMCU_STM32F103RB",
"f_cpu": "72000000L", "f_cpu": "72000000L",
"hwids": [ "hwids": [
["0x1EAF", "0x0003"], ["0x1EAF", "0x0003"],
["0x1EAF", "0x0004"] ["0x1EAF", "0x0004"]
], ],
"ldscript": "stm32f103rb.ld", "ldscript": "stm32f103rb.ld",
"mcu": "stm32f103rb", "mcu": "stm32f103rb",
"variant": "generic_stm32f103r8" "variant": "generic_stm32f103r8"
}, },
"frameworks": ["arduino"], "frameworks": ["arduino"],
"name": "STM32F103RB (20k RAM. 128k Flash)", "name": "STM32F103RB (20k RAM. 128k Flash)",
"upload": { "upload": {
"disable_flushing": false, "disable_flushing": false,
"maximum_ram_size": 20480, "maximum_ram_size": 20480,
"maximum_size": 131072, "maximum_size": 131072,
"protocol": "maple_serial", "protocol": "serial",
"require_upload_port": true, "require_upload_port": true,
"use_1200bps_touch": false, "use_1200bps_touch": false,
"wait_for_upload_port": false "wait_for_upload_port": false
}, },
"url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103rb.html", "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103rb.html",
"vendor": "Generic" "vendor": "Generic"
} }

View File

@ -1,28 +1,28 @@
{ {
"build": { "build": {
"core": "maple", "core": "maple",
"cpu": "cortex-m3", "cpu": "cortex-m3",
"extra_flags": "-DMCU_STM32F103RC", "extra_flags": "-DARDUINO_GENERIC_STM32F103R -DMCU_STM32F103RC",
"f_cpu": "72000000L", "f_cpu": "72000000L",
"hwids": [ "hwids": [
["0x1EAF", "0x0003"], ["0x1EAF", "0x0003"],
["0x1EAF", "0x0004"] ["0x1EAF", "0x0004"]
], ],
"ldscript": "stm32f103rc.ld", "ldscript": "stm32f103rc.ld",
"mcu": "stm32f103rc", "mcu": "stm32f103rc",
"variant": "generic_stm32f103r" "variant": "generic_stm32f103r"
}, },
"frameworks": ["arduino"], "frameworks": ["arduino"],
"name": "STM32F103RC (48k RAM. 256k Flash)", "name": "STM32F103RC (48k RAM. 256k Flash)",
"upload": { "upload": {
"disable_flushing": false, "disable_flushing": false,
"maximum_ram_size": 49152, "maximum_ram_size": 49152,
"maximum_size": 262144, "maximum_size": 262144,
"protocol": "maple_serial", "protocol": "serial",
"require_upload_port": true, "require_upload_port": true,
"use_1200bps_touch": false, "use_1200bps_touch": false,
"wait_for_upload_port": false "wait_for_upload_port": false
}, },
"url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103rc.html", "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103rc.html",
"vendor": "Generic" "vendor": "Generic"
} }

View File

@ -1,28 +1,28 @@
{ {
"build": { "build": {
"core": "maple", "core": "maple",
"cpu": "cortex-m3", "cpu": "cortex-m3",
"extra_flags": "-DMCU_STM32F103RE", "extra_flags": "-DARDUINO_GENERIC_STM32F103R -DMCU_STM32F103RE",
"f_cpu": "72000000L", "f_cpu": "72000000L",
"hwids": [ "hwids": [
["0x1EAF", "0x0003"], ["0x1EAF", "0x0003"],
["0x1EAF", "0x0004"] ["0x1EAF", "0x0004"]
], ],
"ldscript": "stm32f103re.ld", "ldscript": "stm32f103re.ld",
"mcu": "stm32f103re", "mcu": "stm32f103re",
"variant": "generic_stm32f103r" "variant": "generic_stm32f103r"
}, },
"frameworks": ["arduino"], "frameworks": ["arduino"],
"name": "STM32F103RE (64k RAM. 512k Flash)", "name": "STM32F103RE (64k RAM. 512k Flash)",
"upload": { "upload": {
"disable_flushing": false, "disable_flushing": false,
"maximum_ram_size": 65536, "maximum_ram_size": 65536,
"maximum_size": 524288, "maximum_size": 524288,
"protocol": "maple_serial", "protocol": "serial",
"require_upload_port": true, "require_upload_port": true,
"use_1200bps_touch": false, "use_1200bps_touch": false,
"wait_for_upload_port": false "wait_for_upload_port": false
}, },
"url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103re.html", "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103re.html",
"vendor": "Generic" "vendor": "Generic"
} }

View File

@ -1,28 +1,28 @@
{ {
"build": { "build": {
"core": "maple", "core": "maple",
"cpu": "cortex-m3", "cpu": "cortex-m3",
"extra_flags": "-DMCU_STM32F103RB", "extra_flags": "-DARDUINO_MAPLE_REV3 -DMCU_STM32F103RB",
"f_cpu": "72000000L", "f_cpu": "72000000L",
"hwids": [ "hwids": [
["0x1EAF", "0x0003"], ["0x1EAF", "0x0003"],
["0x1EAF", "0x0004"] ["0x1EAF", "0x0004"]
], ],
"ldscript": "flash.ld", "ldscript": "flash.ld",
"mcu": "stm32f103rb_maple", "mcu": "stm32f103rb_maple",
"variant": "maple" "variant": "maple"
}, },
"frameworks": ["arduino"], "frameworks": ["arduino"],
"name": "Olimexino STM32", "name": "Olimexino STM32",
"upload": { "upload": {
"disable_flushing": false, "disable_flushing": false,
"maximum_ram_size": 17000, "maximum_ram_size": 17000,
"maximum_size": 108000, "maximum_size": 108000,
"protocol": "dfu", "protocol": "dfu",
"require_upload_port": true, "require_upload_port": true,
"use_1200bps_touch": false, "use_1200bps_touch": false,
"wait_for_upload_port": false "wait_for_upload_port": false
}, },
"url": "https://www.olimex.com/Products/Duino/STM32/OLIMEXINO-STM32/", "url": "https://www.olimex.com/Products/Duino/STM32/OLIMEXINO-STM32/",
"vendor": "Olimex" "vendor": "Olimex"
} }

View File

@ -35,38 +35,30 @@ if board.id == "bluepill_f103c8":
env['LDSCRIPT_PATH'] = board.get("build.ldscript") env['LDSCRIPT_PATH'] = board.get("build.ldscript")
env.ProcessFlags(board.get("build.extra_flags")) env.ProcessFlags(board.get("build.extra_flags"))
if "stm32f103" in board.get("build.mcu", ""):
FRAMEWORK_DIR = join(platform.get_package_dir(
"framework-arduinoststm32"), "STM32F1")
env.Append(
CPPDEFINES=[
"ERROR_LED_PORT=GPIOB",
"ERROR_LED_PIN=1",
"ARDUINO_ARCH_STM32F1"
]
)
if "stm32f103r8" or "stm32f103rb" in board.get(
"build.mcu", ""):
env.Append(CPPDEFINES=[
"BOARD_generic_stm32f103r8", "ARDUINO_GENERIC_STM32F103R"])
elif "stm32f103rc" or "stm32f103re" in board.get(
"build.mcu", ""):
env.Append(CPPDEFINES=[
"BOARD_generic_stm32f103r", "ARDUINO_GENERIC_STM32F103R"])
elif "stm32f103c" in board.get("build.mcu", ""):
env.Append(CPPDEFINES=[
"BOARD_generic_stm32f103c", "ARDUINO_GENERIC_STM32F103C"])
elif "stm32f103rb_maple" in board.get("build.mcu", ""):
env.Append(CPPDEFINES=["BOARD_maple", "ARDUINO_MAPLE_REV3"])
FRAMEWORK_DIR = join(platform.get_package_dir(
"framework-arduinoststm32"), "STM32F1")
FRAMEWORK_VERSION = platform.get_package_version("framework-arduinoststm32") FRAMEWORK_VERSION = platform.get_package_version("framework-arduinoststm32")
assert isdir(FRAMEWORK_DIR) assert isdir(FRAMEWORK_DIR)
ARDUINO_VERSION = int(FRAMEWORK_VERSION.replace(".", "").strip()) env.Replace(
LIBS=["m", "gcc"]
)
env.Append( env.Append(
CCFLAGS=[
"--param", "max-inline-insns-single=500",
"-march=armv7-m"
],
CPPDEFINES=[ CPPDEFINES=[
"ARDUINO=%s" % FRAMEWORK_VERSION.split(".")[1] "ARDUINO=10611",
"BOARD_%s" % board.get("build.variant"),
"ERROR_LED_PORT=GPIOB",
"ERROR_LED_PIN=1",
"DEBUG_LEVEL=DEBUG_NONE",
"__STM32F1__",
"ARDUINO_ARCH_STM32F1"
], ],
CPPPATH=[ CPPPATH=[
@ -80,10 +72,7 @@ env.Append(
LIBPATH=[ LIBPATH=[
join(FRAMEWORK_DIR, "variants", join(FRAMEWORK_DIR, "variants",
board.get("build.variant"), "ld") board.get("build.variant"), "ld")
], ]
# hook for https://github.com/platformio/platform-ststm32/issues/10
LIBS=["c"]
) )
for item in ("-nostartfiles", "-nostdlib"): for item in ("-nostartfiles", "-nostdlib"):

View File

@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from os.path import isfile, join from os.path import basename, isfile, join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment) DefaultEnvironment)
from platformio import util
env = DefaultEnvironment() env = DefaultEnvironment()
@ -139,34 +138,18 @@ if env.subst("$UPLOAD_PROTOCOL") == "gdb":
) )
if "arduino" in env.subst("$PIOFRAMEWORK"): if "arduino" in env.subst("$PIOFRAMEWORK"):
uploadProtocol = "" _upload_tool = "serial_upload"
uploadParams = "" _upload_flags = ["{upload.altID}", "{upload.usbID}"]
if "linux" in util.get_systype(): if "dfu" in env.subst("$UPLOAD_PROTOCOL"):
uploadPlatform = "linux" _upload_tool = "maple_upload"
elif "darwin" in util.get_systype(): _usbids = env.BoardConfig().get("build.hwids")
uploadPlatform = "macosx" _upload_flags = ["2", "%s:%s" % (_usbids[0][0][2:], _usbids[0][1][2:])]
else:
uploadPlatform = "win"
if env.subst("$UPLOAD_PROTOCOL") == "dfu":
uploadProtocol = "maple_upload"
usbids = env.BoardConfig().get("build.hwids")
usbid = '2 %s:%s' % (usbids[0][0], usbids[0][1])
env.Replace(UPLOADERFLAGS=usbid)
uploadParams = usbid
else:
uploadProtocol = "serial_upload"
uploadParams = "{upload.altID} {upload.usbID} $PROJECT_DIR/$SOURCES"
env.Replace( env.Replace(
UPLOADER=join( UPLOADER=_upload_tool,
env.PioPlatform().get_package_dir( UPLOADERFLAGS=["$UPLOAD_PORT"] + _upload_flags,
"framework-arduinoststm32") or "",
"tools", uploadPlatform, uploadProtocol),
UPLOADERFLAGS=["$UPLOAD_PORT"],
UPLOADERPARAMS=uploadParams,
UPLOADCMD=( UPLOADCMD=(
'$UPLOADER $UPLOADERFLAGS $UPLOADERPARAMS $PROJECT_DIR/$SOURCES')) '$UPLOADER $UPLOADERFLAGS $PROJECT_DIR/$SOURCES'))
# #
# Target: Build executable and linkable firmware # Target: Build executable and linkable firmware
@ -202,9 +185,14 @@ if "mbed" in env.subst("$PIOFRAMEWORK") and not env.subst("$UPLOAD_PROTOCOL"):
"Looking for upload disk..."), "Looking for upload disk..."),
env.VerboseAction(env.UploadToDisk, "Uploading $SOURCE")]) env.VerboseAction(env.UploadToDisk, "Uploading $SOURCE")])
elif "arduino" in env.subst("$PIOFRAMEWORK"): elif "arduino" in env.subst("$PIOFRAMEWORK"):
def BeforeUpload(target, source, env):
env.AutodetectUploadPort()
env.Replace(UPLOAD_PORT=basename(env.subst("$UPLOAD_PORT")))
target_upload = env.Alias( target_upload = env.Alias(
"upload", target_firm, "upload", target_firm,
[env.VerboseAction(env.AutodetectUploadPort, [env.VerboseAction(BeforeUpload,
"Looking for upload disk..."), "Looking for upload disk..."),
env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]) env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")])
else: else:

View File

@ -13,21 +13,11 @@
"type": "git", "type": "git",
"url": "https://github.com/platformio/platform-ststm32.git" "url": "https://github.com/platformio/platform-ststm32.git"
}, },
"version": "1.2.0", "version": "1.3.0-alpha1",
"packageRepositories": [ "packageRepositories": [
"https://dl.bintray.com/platformio/dl-packages/manifest.json", "https://dl.bintray.com/platformio/dl-packages/manifest.json",
"https://sourceforge.net/projects/platformio-storage/files/packages/manifest.json/download", "https://sourceforge.net/projects/platformio-storage/files/packages/manifest.json/download",
"http://dl.platformio.org/packages/manifest.json", "http://dl.platformio.org/packages/manifest.json"
{
"framework-arduinoststm32": [
{
"url": "https://github.com/ubis/Arduino_STM32/archive/v1.0.0.tar.gz",
"sha1": "36f26069b70ef6b7ceae2a91e3c23be74cc79337",
"version": "1.0.0",
"system": "*"
}
]
}
], ],
"frameworks": { "frameworks": {
"mbed": { "mbed": {
@ -79,12 +69,17 @@
"framework-arduinoststm32": { "framework-arduinoststm32": {
"type": "framework", "type": "framework",
"optional": true, "optional": true,
"version": "~1.0.0" "version": "~2.0.0"
}, },
"tool-stlink": { "tool-stlink": {
"type": "uploader", "type": "uploader",
"optional": true, "optional": true,
"version": "~1.10200.0" "version": "~1.10200.0"
},
"tool-stm32duino": {
"type": "uploader",
"optional": true,
"version": "~1.0.0"
} }
} }
} }