diff --git a/boards/afroflight_f103cb.json b/boards/afroflight_f103cb.json index d0a9c9dea..c03acaf39 100644 --- a/boards/afroflight_f103cb.json +++ b/boards/afroflight_f103cb.json @@ -20,7 +20,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "AfroFlight Rev5 (8MHz)", "upload": { diff --git a/boards/blackpill_f103c8.json b/boards/blackpill_f103c8.json index aed52e882..ef04a13e2 100644 --- a/boards/blackpill_f103c8.json +++ b/boards/blackpill_f103c8.json @@ -40,6 +40,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube", "zephyr" ], diff --git a/boards/blackpill_f103c8_128.json b/boards/blackpill_f103c8_128.json index 6788c1007..9c1e9822f 100644 --- a/boards/blackpill_f103c8_128.json +++ b/boards/blackpill_f103c8_128.json @@ -40,6 +40,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube", "zephyr" ], diff --git a/boards/bluepill_f103c6.json b/boards/bluepill_f103c6.json index 46a459d07..03e9fe912 100644 --- a/boards/bluepill_f103c6.json +++ b/boards/bluepill_f103c6.json @@ -34,7 +34,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "BluePill F103C6", "upload": { diff --git a/boards/bluepill_f103c8.json b/boards/bluepill_f103c8.json index 70d5081ea..2fdad5e9d 100644 --- a/boards/bluepill_f103c8.json +++ b/boards/bluepill_f103c8.json @@ -40,8 +40,10 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube", - "zephyr" + "zephyr", + "spl" ], "name": "BluePill F103C8", "upload": { diff --git a/boards/bluepill_f103c8_128k.json b/boards/bluepill_f103c8_128k.json index 086b266b8..2beff74e5 100644 --- a/boards/bluepill_f103c8_128k.json +++ b/boards/bluepill_f103c8_128k.json @@ -40,6 +40,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube", "zephyr" ], diff --git a/boards/disco_f100rb.json b/boards/disco_f100rb.json index baacf5dd8..00aab9ef4 100644 --- a/boards/disco_f100rb.json +++ b/boards/disco_f100rb.json @@ -1,6 +1,7 @@ { "build": { "cpu": "cortex-m3", + "core": "stm32", "extra_flags": "-DSTM32F1 -DSTM32F100xB", "f_cpu": "24000000L", "mcu": "stm32f100rbt6", @@ -22,6 +23,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "ST STM32VLDISCOVERY", diff --git a/boards/eval_f107vc.json b/boards/eval_f107vc.json index 86dab99f5..0c7e7e6f7 100644 --- a/boards/eval_f107vc.json +++ b/boards/eval_f107vc.json @@ -18,6 +18,7 @@ "cmsis", "stm32cube", "libopencm3", + "spl", "zephyr" ], "name": "STM3210C-EVAL", diff --git a/boards/genericSTM32F103C4.json b/boards/genericSTM32F103C4.json index 03f866aad..95c0a0365 100644 --- a/boards/genericSTM32F103C4.json +++ b/boards/genericSTM32F103C4.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103C4 (6k RAM. 16k Flash)", "upload": { diff --git a/boards/genericSTM32F103C6.json b/boards/genericSTM32F103C6.json index f278e4cb8..27e74d940 100644 --- a/boards/genericSTM32F103C6.json +++ b/boards/genericSTM32F103C6.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103C6 (10k RAM. 32k Flash)", "upload": { diff --git a/boards/genericSTM32F103C8.json b/boards/genericSTM32F103C8.json index cbaf4fa41..75ecf2497 100644 --- a/boards/genericSTM32F103C8.json +++ b/boards/genericSTM32F103C8.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103C8 (20k RAM. 64k Flash)", diff --git a/boards/genericSTM32F103CB.json b/boards/genericSTM32F103CB.json index 1b921befb..56ba100b2 100644 --- a/boards/genericSTM32F103CB.json +++ b/boards/genericSTM32F103CB.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103CB (20k RAM. 128k Flash)", diff --git a/boards/genericSTM32F103R4.json b/boards/genericSTM32F103R4.json index 2672cc39d..29664778e 100644 --- a/boards/genericSTM32F103R4.json +++ b/boards/genericSTM32F103R4.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103R4 (6k RAM. 16k Flash)", "upload": { diff --git a/boards/genericSTM32F103R6.json b/boards/genericSTM32F103R6.json index 69f6f3b82..eafc200b5 100644 --- a/boards/genericSTM32F103R6.json +++ b/boards/genericSTM32F103R6.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103R6 (10k RAM. 32k Flash)", "upload": { diff --git a/boards/genericSTM32F103R8.json b/boards/genericSTM32F103R8.json index e034d4255..8fa693189 100644 --- a/boards/genericSTM32F103R8.json +++ b/boards/genericSTM32F103R8.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103R8 (20k RAM. 64 Flash)", diff --git a/boards/genericSTM32F103RB.json b/boards/genericSTM32F103RB.json index 8da84b469..a09f1e401 100644 --- a/boards/genericSTM32F103RB.json +++ b/boards/genericSTM32F103RB.json @@ -28,6 +28,7 @@ "cmsis", "mbed", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103RB (20k RAM. 128k Flash)", diff --git a/boards/genericSTM32F103RC.json b/boards/genericSTM32F103RC.json index 9ac22c454..962146728 100644 --- a/boards/genericSTM32F103RC.json +++ b/boards/genericSTM32F103RC.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103RC (48k RAM. 256k Flash)", diff --git a/boards/genericSTM32F103RD.json b/boards/genericSTM32F103RD.json index e20407106..8ef33f554 100644 --- a/boards/genericSTM32F103RD.json +++ b/boards/genericSTM32F103RD.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103RD (64k RAM. 384k Flash)", "upload": { diff --git a/boards/genericSTM32F103RE.json b/boards/genericSTM32F103RE.json index 11591f437..504ab3227 100644 --- a/boards/genericSTM32F103RE.json +++ b/boards/genericSTM32F103RE.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103RE (64k RAM. 512k Flash)", diff --git a/boards/genericSTM32F103RF.json b/boards/genericSTM32F103RF.json index 410a0a8a6..172860734 100644 --- a/boards/genericSTM32F103RF.json +++ b/boards/genericSTM32F103RF.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103RF (96k RAM. 768k Flash)", "upload": { diff --git a/boards/genericSTM32F103RG.json b/boards/genericSTM32F103RG.json index 34f0e714b..2d0b69eb8 100644 --- a/boards/genericSTM32F103RG.json +++ b/boards/genericSTM32F103RG.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103RG (96k RAM. 1024k Flash)", "upload": { diff --git a/boards/genericSTM32F103T4.json b/boards/genericSTM32F103T4.json index 4c5db7fbc..aa2e170e3 100644 --- a/boards/genericSTM32F103T4.json +++ b/boards/genericSTM32F103T4.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103T4 (6k RAM. 16k Flash)", "upload": { diff --git a/boards/genericSTM32F103T6.json b/boards/genericSTM32F103T6.json index d26153233..1d5d3320d 100644 --- a/boards/genericSTM32F103T6.json +++ b/boards/genericSTM32F103T6.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103T6 (10k RAM. 32k Flash)", "upload": { diff --git a/boards/genericSTM32F103T8.json b/boards/genericSTM32F103T8.json index 70a34a03c..6059824cc 100644 --- a/boards/genericSTM32F103T8.json +++ b/boards/genericSTM32F103T8.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103T8 (20k RAM. 64k Flash)", diff --git a/boards/genericSTM32F103TB.json b/boards/genericSTM32F103TB.json index 69a9bf3fd..9b8a00aad 100644 --- a/boards/genericSTM32F103TB.json +++ b/boards/genericSTM32F103TB.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103TB (20k RAM. 128k Flash)", diff --git a/boards/genericSTM32F103V8.json b/boards/genericSTM32F103V8.json index e1a452b6c..fba71a2d9 100644 --- a/boards/genericSTM32F103V8.json +++ b/boards/genericSTM32F103V8.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103V8 (20k RAM. 64k Flash)", "upload": { diff --git a/boards/genericSTM32F103VB.json b/boards/genericSTM32F103VB.json index 9919aba97..d3b2381ac 100644 --- a/boards/genericSTM32F103VB.json +++ b/boards/genericSTM32F103VB.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103VB (20k RAM. 128k Flash)", diff --git a/boards/genericSTM32F103VC.json b/boards/genericSTM32F103VC.json index dac37589c..98ec24b3b 100644 --- a/boards/genericSTM32F103VC.json +++ b/boards/genericSTM32F103VC.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103VC (48k RAM. 256k Flash)", diff --git a/boards/genericSTM32F103VD.json b/boards/genericSTM32F103VD.json index 3c73d65bd..820a091ae 100644 --- a/boards/genericSTM32F103VD.json +++ b/boards/genericSTM32F103VD.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103VD (64k RAM. 384k Flash)", diff --git a/boards/genericSTM32F103VE.json b/boards/genericSTM32F103VE.json index 8ce9b5395..b4dd3d4e7 100644 --- a/boards/genericSTM32F103VE.json +++ b/boards/genericSTM32F103VE.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103VE (64k RAM. 512k Flash)", diff --git a/boards/genericSTM32F103VF.json b/boards/genericSTM32F103VF.json index a7c3bf253..d615dfa4b 100644 --- a/boards/genericSTM32F103VF.json +++ b/boards/genericSTM32F103VF.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103VF (96k RAM. 768k Flash)", "upload": { diff --git a/boards/genericSTM32F103VG.json b/boards/genericSTM32F103VG.json index 4f8305a6f..483485be2 100644 --- a/boards/genericSTM32F103VG.json +++ b/boards/genericSTM32F103VG.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103VG (96k RAM. 1024k Flash)", "upload": { diff --git a/boards/genericSTM32F103ZC.json b/boards/genericSTM32F103ZC.json index c29e96c5b..29d4ddd9e 100644 --- a/boards/genericSTM32F103ZC.json +++ b/boards/genericSTM32F103ZC.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103ZC (48k RAM. 256k Flash)", diff --git a/boards/genericSTM32F103ZD.json b/boards/genericSTM32F103ZD.json index b02f97827..576517a32 100644 --- a/boards/genericSTM32F103ZD.json +++ b/boards/genericSTM32F103ZD.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103ZD (64k RAM. 384k Flash)", diff --git a/boards/genericSTM32F103ZE.json b/boards/genericSTM32F103ZE.json index f46d5904a..d164bb8b7 100644 --- a/boards/genericSTM32F103ZE.json +++ b/boards/genericSTM32F103ZE.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STM32F103ZE (64k RAM. 512k Flash)", diff --git a/boards/genericSTM32F103ZF.json b/boards/genericSTM32F103ZF.json index 49d1855a3..c2bd7da2c 100644 --- a/boards/genericSTM32F103ZF.json +++ b/boards/genericSTM32F103ZF.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103ZF (96k RAM. 768k Flash)", "upload": { diff --git a/boards/genericSTM32F103ZG.json b/boards/genericSTM32F103ZG.json index 41a27bdaa..7f90958dc 100644 --- a/boards/genericSTM32F103ZG.json +++ b/boards/genericSTM32F103ZG.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "STM32F103ZG (96k RAM. 1024k Flash)", "upload": { diff --git a/boards/hy_tinystm103tb.json b/boards/hy_tinystm103tb.json index 80a66aae4..ccc614448 100644 --- a/boards/hy_tinystm103tb.json +++ b/boards/hy_tinystm103tb.json @@ -27,7 +27,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "Tiny STM103T", "upload": { diff --git a/boards/malyanm200_f070cb.json b/boards/malyanm200_f070cb.json index c0a649614..113fb2c34 100644 --- a/boards/malyanm200_f070cb.json +++ b/boards/malyanm200_f070cb.json @@ -12,7 +12,7 @@ "arduino": "-DCUSTOM_STARTUP_FILE" }, "mcu": "stm32f070cbt6", - "product_line": "STM32F103xB", + "product_line": "STM32F070xB", "variant": "STM32F0xx/F070CBT" }, "debug": { diff --git a/boards/malyanm200_f103cb.json b/boards/malyanm200_f103cb.json index fed978ccb..0a2c05ef4 100644 --- a/boards/malyanm200_f103cb.json +++ b/boards/malyanm200_f103cb.json @@ -31,7 +31,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "Malyan M200 V1", "upload": { diff --git a/boards/maple.json b/boards/maple.json index c0c80d33a..59add00f7 100644 --- a/boards/maple.json +++ b/boards/maple.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "Maple", diff --git a/boards/maple_mini_b20.json b/boards/maple_mini_b20.json index 41f342be0..a566cf6f4 100644 --- a/boards/maple_mini_b20.json +++ b/boards/maple_mini_b20.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "Maple Mini Bootloader 2.0", diff --git a/boards/maple_mini_origin.json b/boards/maple_mini_origin.json index c6365c8cb..31bafbcdb 100644 --- a/boards/maple_mini_origin.json +++ b/boards/maple_mini_origin.json @@ -30,6 +30,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "Maple Mini Original", diff --git a/boards/maple_ret6.json b/boards/maple_ret6.json index be3b56b18..715420706 100644 --- a/boards/maple_ret6.json +++ b/boards/maple_ret6.json @@ -27,6 +27,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "Maple (RET6)", diff --git a/boards/microduino32_flash.json b/boards/microduino32_flash.json index 1581dc9be..f6ef91dc1 100644 --- a/boards/microduino32_flash.json +++ b/boards/microduino32_flash.json @@ -27,7 +27,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "Microduino Core STM32 to Flash", "upload": { diff --git a/boards/nucleo_f103rb.json b/boards/nucleo_f103rb.json index 0f89f66b9..9d9d5df4a 100644 --- a/boards/nucleo_f103rb.json +++ b/boards/nucleo_f103rb.json @@ -25,6 +25,7 @@ "cmsis", "mbed", "libopencm3", + "spl", "stm32cube", "zephyr" ], diff --git a/boards/olimex_f103.json b/boards/olimex_f103.json index 06a02c9f4..7f11f6394 100644 --- a/boards/olimex_f103.json +++ b/boards/olimex_f103.json @@ -21,6 +21,7 @@ "cmsis", "mbed", "libopencm3", + "spl", "stm32cube" ], "name": "Olimex STM32-H103", diff --git a/boards/olimexino.json b/boards/olimexino.json index 4ccdd6fa5..ab457f8dd 100644 --- a/boards/olimexino.json +++ b/boards/olimexino.json @@ -20,6 +20,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube", "zephyr" ], diff --git a/boards/storm32_v1_31_rc.json b/boards/storm32_v1_31_rc.json index c0b038ef8..ea669ba69 100644 --- a/boards/storm32_v1_31_rc.json +++ b/boards/storm32_v1_31_rc.json @@ -20,6 +20,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "STorM32 BGC v1.31 RC", diff --git a/boards/vccgnd_f103zet6.json b/boards/vccgnd_f103zet6.json index 98aab5a45..ed591b9f3 100644 --- a/boards/vccgnd_f103zet6.json +++ b/boards/vccgnd_f103zet6.json @@ -17,7 +17,8 @@ "arduino", "cmsis", "stm32cube", - "libopencm3" + "libopencm3", + "spl" ], "name": "VCCGND F103ZET6 Mini", "upload": { diff --git a/boards/waveshare_open103z.json b/boards/waveshare_open103z.json index bd5cd583c..596a67740 100644 --- a/boards/waveshare_open103z.json +++ b/boards/waveshare_open103z.json @@ -17,6 +17,7 @@ "arduino", "cmsis", "libopencm3", + "spl", "stm32cube" ], "name": "Waveshare Open103Z", diff --git a/builder/frameworks/spl.py b/builder/frameworks/spl.py index 4348d9f8d..836e968b4 100644 --- a/builder/frameworks/spl.py +++ b/builder/frameworks/spl.py @@ -22,7 +22,7 @@ http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743?sc=stm32embeddedsoftware """ - +import sys from os.path import isdir, isfile, join from string import Template @@ -37,6 +37,7 @@ FRAMEWORK_DIR = platform.get_package_dir("framework-spl") assert isdir(FRAMEWORK_DIR) +mcu = board.get("build.mcu").lower() def get_linker_script(mcu): ldscript = join(FRAMEWORK_DIR, "platformio", @@ -75,13 +76,13 @@ def get_linker_script(mcu): env.Append( CPPPATH=[ - join(FRAMEWORK_DIR, board.get("build.core"), - "cmsis", "cores", board.get("build.core")), - join(FRAMEWORK_DIR, board.get("build.core"), "cmsis", + join(FRAMEWORK_DIR, board.get("build.mcu")[0:5], + "cmsis", "cores", board.get("build.mcu")[0:5]), + join(FRAMEWORK_DIR, board.get("build.mcu")[0:5], "cmsis", "variants", board.get("build.mcu")[0:7]), - join(FRAMEWORK_DIR, board.get("build.core"), "spl", + join(FRAMEWORK_DIR, board.get("build.mcu")[0:5], "spl", "variants", board.get("build.mcu")[0:7], "inc"), - join(FRAMEWORK_DIR, board.get("build.core"), "spl", + join(FRAMEWORK_DIR, board.get("build.mcu")[0:5], "spl", "variants", board.get("build.mcu")[0:7], "src") ], LINKFLAGS=[ @@ -105,6 +106,7 @@ def get_linker_script(mcu): extra_flags = board.get("build.extra_flags", "") src_filter_patterns = ["+<*>"] +cmsis_variant_filter_patterns = ["+<*>"] if "STM32F40_41xxx" in extra_flags: src_filter_patterns += ["-"] if "STM32F427_437xx" in extra_flags: @@ -114,19 +116,75 @@ def get_linker_script(mcu): elif "STM32L1XX_MD" in extra_flags: src_filter_patterns += ["-"] +# generate filer expression for F10x startup file +if mcu.startswith("stm32f10"): + # stm32f10x SPL has 8 possible startup files + # depending on the series (connectivity, low/high/medium/extra-large density or + # "value-line"). + # we only want to assemble and link the correct one. + # we automatically deduce the correct startup file and identifying macro based + # on MCU name and flash size, which saves us from adapting tons of boards files. + # for details see page 90 of reference manual and stm32f10x.h. + # https://www.st.com/resource/en/reference_manual/cd00171190-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf + flash_mem = board.get("upload.maximum_size") // 1024 + family = mcu[0:9] # only get the chip family as e.g. stm32f103 + startup_file, series_macro = (None, None) + # give user the possibility to give the startup file themselves as a fallback + # then the identifying macro is also expected to be given. + startup_file = board.get("build.spl_startup_file", "") + if startup_file == "": + if family in ("stm32f101", "stm32f102", "stm32f103") and flash_mem >= 16 and flash_mem <= 32: + startup_file, series_macro = ("startup_stm32f10x_ld.S", "STM32F10X_LD") # low density + if family in ("stm32f100") and flash_mem >= 16 and flash_mem <= 32: + startup_file, series_macro = ("startup_stm32f10x_ld_vl.S", "STM32F10X_LD_VL") # low density value + elif family in ("stm32f101", "stm32f102", "stm32f103") and flash_mem >= 64 and flash_mem <= 128: + startup_file, series_macro = ("startup_stm32f10x_md.S", "STM32F10X_MD") # medium density + elif family in ("stm32f100") and flash_mem >= 64 and flash_mem <= 128: + startup_file, series_macro = ("startup_stm32f10x_md_vl.S", "STM32F10X_MD_VL") # medium density value + elif family in ("stm32f101", "stm32f103") and flash_mem >= 256 and flash_mem <= 512: + startup_file, series_macro = ("startup_stm32f10x_hd.S", "STM32F10X_HD") # high density + elif family in ("stm32f100") and flash_mem >= 256 and flash_mem <= 512: + startup_file, series_macro = ("startup_stm32f10x_hd_vl.S", "STM32F10X_HD_VL") # high density + elif family in ("stm32f101", "stm32f103") and flash_mem >= 768 and flash_mem <= 1024: + startup_file, series_macro = ("startup_stm32f10x_xl.S", "STM32F10X_XL") # xtra-large density + elif family in ("stm32f105", "stm32f107"): + startup_file, series_macro = ("startup_stm32f10x_cl.S", "STM32F10X_CL") # connectivity line + + if startup_file == "": + sys.stderr.write("Failed to find startup file for board '%s'.\n" % board.id) + env.Exit(-1) + # exclude all startup files via wildcard, add back the one we want + cmsis_variant_filter_patterns += ["-", "+<%s>" % startup_file] + if series_macro is not None: + env.Append(CPPDEFINES=[series_macro]) + libs = [] libs.append(env.BuildLibrary( join("$BUILD_DIR", "FrameworkCMSISVariant"), join( - FRAMEWORK_DIR, board.get("build.core"), "cmsis", + FRAMEWORK_DIR, board.get("build.mcu")[0:5], "cmsis", "variants", board.get("build.mcu")[0:7] - ) + ), + src_filter=cmsis_variant_filter_patterns )) +# STM32F1 SPL introduced updated core_cm3.c that needs +# to be compiled for Cortex-M3 cores. +if board.get("build.cpu") == "cortex-m3": + libs.append(env.BuildLibrary( + join("$BUILD_DIR", "FrameworkCMSISCore"), + join( + FRAMEWORK_DIR, board.get("build.mcu")[0:5], "cmsis", + "cores", "stm32" + ), + src_filter="+" + )) + + libs.append(env.BuildLibrary( join("$BUILD_DIR", "FrameworkSPL"), - join(FRAMEWORK_DIR, board.get("build.core"), + join(FRAMEWORK_DIR, board.get("build.mcu")[0:5], "spl", "variants", board.get("build.mcu")[0:7], "src"), src_filter=" ".join(src_filter_patterns) diff --git a/examples/spl-blink/platformio.ini b/examples/spl-blink/platformio.ini index 610363d67..9459a3e6b 100644 --- a/examples/spl-blink/platformio.ini +++ b/examples/spl-blink/platformio.ini @@ -21,3 +21,20 @@ board = disco_l152rb platform = ststm32 framework = spl board = disco_f303vc + +[env:bluepill_f103c8] +platform = ststm32 +framework = spl +board = bluepill_f103c8 + +[env:maple] +platform = ststm32 +framework = spl +board = maple +build_flags = -DSTM32F1 + +[env:nucleo_f103rb] +platform = ststm32 +framework = spl +board = nucleo_f103rb +build_flags = -DSTM32F1 -DNUCLEO_F103RB -DPIO_FRAMEWORK_SPL_HSE_IN_BYPASS_MODE diff --git a/examples/spl-blink/src/main.c b/examples/spl-blink/src/main.c index 089cc39ad..c5cc86518 100644 --- a/examples/spl-blink/src/main.c +++ b/examples/spl-blink/src/main.c @@ -1,4 +1,17 @@ -#ifdef STM32L1 +#ifdef STM32F1 + #include + #include + #if NUCLEO_F103RB + /* default on-board LED */ + #define LEDPORT (GPIOA) + #define LEDPIN (GPIO_Pin_5) + #define ENABLE_GPIO_CLOCK (RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE)) + #else + #define LEDPORT (GPIOC) + #define LEDPIN (GPIO_Pin_13) + #define ENABLE_GPIO_CLOCK (RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE)) + #endif +#elif STM32L1 #include #include #define LEDPORT (GPIOB) @@ -16,32 +29,53 @@ #define LEDPORT (GPIOD) #define LEDPIN (GPIO_Pin_12) #define ENABLE_GPIO_CLOCK (RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE)) +#else + #error "Please define one of the macros STM32F1, STM32L1, STM32F3 or STM32F4." #endif -/* timing is not guaranteed :) */ -void simple_delay(uint32_t us) -{ - /* simple delay loop */ - while (us--) { - asm volatile ("nop"); +/* wanted blink time in milliseconds */ +#define DELAY_TIME_MILLIS 1000 + +/* variable keeps track of timing delay */ +static __IO uint32_t TimingDelay; + +void Delay(__IO uint32_t nTime) { + TimingDelay = nTime; + /* wait until variable is decreased to 0 through ISR calls */ + while (TimingDelay != 0); +} + +void TimingDelay_Decrement(void) { + /* called in systick ISR */ + if (TimingDelay != 0x00) { + TimingDelay--; } } /* system entry point */ int main(void) { + //setup SysTick for 1 millisecond interrupts + if (SysTick_Config(SystemCoreClock / 1000)) { + /* Capture error */ + while (1); + } /* gpio init struct */ GPIO_InitTypeDef gpio; - /* reset rcc */ - RCC_DeInit(); /* enable clock GPIO */ ENABLE_GPIO_CLOCK; /* use LED pin */ gpio.GPIO_Pin = LEDPIN; + gpio.GPIO_Speed = GPIO_Speed_2MHz; + /* set pin to push-pull output depending on the SPL variant */ +#if STM32F1 + gpio.GPIO_Mode = GPIO_Mode_Out_PP; +#else /* mode: output */ gpio.GPIO_Mode = GPIO_Mode_OUT; /* output type: push-pull */ gpio.GPIO_OType = GPIO_OType_PP; +#endif /* apply configuration */ GPIO_Init(LEDPORT, &gpio); /* main program loop */ @@ -49,13 +83,18 @@ int main(void) /* set led on */ GPIO_SetBits(LEDPORT, LEDPIN); /* delay */ - simple_delay(100000); + Delay(DELAY_TIME_MILLIS); /* clear led */ GPIO_ResetBits(LEDPORT, LEDPIN); /* delay */ - simple_delay(100000); + Delay(DELAY_TIME_MILLIS); } /* never reached */ return 0; -} \ No newline at end of file +} + +/* SysTick interrupt every millisecond */ +void SysTick_Handler(void) { + TimingDelay_Decrement(); +} diff --git a/platform.json b/platform.json index fe4acb411..5a589cc86 100644 --- a/platform.json +++ b/platform.json @@ -178,7 +178,7 @@ "type": "framework", "optional": true, "owner": "platformio", - "version": "~2.10201.0" + "version": "https://github.com/maxgerhardt/pio-framework-spl-stm32.git" }, "framework-libopencm3": { "type": "framework",