Skip to content

Commit

Permalink
Add two Nucleo boards, GDB debugging and SVD files for all boards (#38)
Browse files Browse the repository at this point in the history
* Added Nucleo-8S207K8 and Nucleo-8S208RB
* Added SVD files

This PR also sets stm8-objcopy as the main tool for HEX file generation as it's more convenient and flexible.
  • Loading branch information
maxgerhardt authored Mar 22, 2021
1 parent 5bb1a69 commit 3dd7514
Show file tree
Hide file tree
Showing 18 changed files with 50,573 additions and 20 deletions.
4 changes: 4 additions & 0 deletions boards/mb208.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"arduino",
"spl"
],
"debug": {
"svd_path": "STM8S208MB.svd",
"openocd_target": "stm8s"
},
"upload": {
"maximum_ram_size": 6144,
"maximum_size": 131072,
Expand Down
35 changes: 35 additions & 0 deletions boards/nucleo_8s207k8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"build": {
"core": "sduino",
"extra_flags": "-DSTM8S_NUCLEO_207K8 -DSTM8S207",
"f_cpu": "16000000L",
"cpu": "stm8",
"mcu": "stm8s207k8t6"
},
"debug": {
"svd_path": "STM8S207K8.svd",
"openocd_target": "stm8s",
"default_tools": [
"stlink"
],
"onboard_tools": [
"stlink"
]
},
"frameworks": [
"spl"
],
"upload": {
"maximum_ram_size": 6144,
"maximum_size": 65536,
"protocol": "stlinkv21",
"protocols": [
"stlinkv21",
"serial"
],
"stm8flash_target": "stm8s207k8"
},
"name": "NUCLEO-8S207K8",
"url": "https://www.st.com/en/evaluation-tools/nucleo-8s207k8.html",
"vendor": "STMicroelectronics"
}
34 changes: 34 additions & 0 deletions boards/nucleo_8s208rb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"build": {
"core": "sduino",
"extra_flags": "-DSTM8S_NUCLEO_208RB -DSTM8S208",
"f_cpu": "16000000L",
"cpu": "stm8",
"mcu": "stm8s208rbt6"
},
"debug": {
"svd_path": "STM8S208RB.svd",
"openocd_target": "stm8s",
"default_tools": [
"stlink"
],
"onboard_tools": [
"stlink"
]
},
"frameworks": [
"spl"
],
"upload": {
"maximum_ram_size": 6144,
"maximum_size": 131072,
"protocol": "stlinkv21",
"protocols": [
"stlinkv21",
"serial"
]
},
"name": "NUCLEO-8S208RB",
"url": "https://www.st.com/en/evaluation-tools/nucleo-8s208rb.html",
"vendor": "STMicroelectronics"
}
4 changes: 4 additions & 0 deletions boards/s8uno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"mcu": "stm8s105k6t6",
"variant": "s8uno"
},
"debug": {
"svd_path": "STM8S105K6.svd",
"openocd_target": "stm8s105"
},
"frameworks": [
"arduino",
"spl"
Expand Down
4 changes: 4 additions & 0 deletions boards/stm8sblack.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"mcu": "stm8s105k4t6",
"variant": "stm8sblack"
},
"debug": {
"svd_path": "STM8S105K4.svd",
"openocd_target": "stm8s105"
},
"frameworks": [
"arduino",
"spl"
Expand Down
4 changes: 4 additions & 0 deletions boards/stm8sblue.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"arduino",
"spl"
],
"debug": {
"svd_path": "STM8S103F3.svd",
"openocd_target": "stm8s103"
},
"upload": {
"maximum_ram_size": 1024,
"maximum_size": 8192,
Expand Down
23 changes: 7 additions & 16 deletions boards/stm8sdisco.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,14 @@
"variant": "stm8sdisco"
},
"debug": {
"svd_path": "STM8S105C6.svd",
"openocd_target": "stm8s",
"tools": {
"stlink": {
"default": true,
"server": {
"arguments": [
"-f",
"scripts/interface/stlink.cfg",
"-f",
"scripts/target/stm8s.cfg"
],
"executable": "bin/openocd",
"package": "tool-openocd"
},
"onboard": true
}
}
"default_tools": [
"stlink"
],
"onboard_tools": [
"stlink"
]
},
"frameworks": [
"arduino",
Expand Down
35 changes: 31 additions & 4 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
GDB="stm8-gdb",
LD="sdldstm8",
RANLIB="sdranlib",
OBJCOPY="sdobjcopy",
OBJCOPY="stm8-objcopy",
SIZETOOL="stm8-size",
OBJSUFFIX=".rel",
LIBSUFFIX=".lib",
Expand Down Expand Up @@ -89,6 +89,15 @@ def _ldflags_for_hex(env, ldflags):
if env.get("PROGNAME", "program") == "program":
env.Replace(PROGNAME="firmware")

#
# Automatically remove flags which are incompatible with SDCC
# in debug mode
if env.GetBuildType() == "debug":
# inject build unflags and unflags that will be
# processed later.
env.Append(BUILD_UNFLAGS=["-Og","-g2", "-ggdb2"])
env.Append(BUILD_FLAGS=["--debug", "--out-fmt-elf"])

#
# Target: Build executable and linkable firmware
#
Expand All @@ -99,10 +108,25 @@ def _ldflags_for_hex(env, ldflags):
target_firm = join("$BUILD_DIR", "${PROGNAME}.ihx")
else:
target_elf = env.BuildProgram()
# convert elf to hex not via sdcc but via stm8-objcopy.
# otherwise the resulting ihex file has the debug sections (if --debug --out-fmt-elf is enabled)
# in it and it fails to flash
# also remove sections which are put into SRAM (starting at 0x0) and cause upload failure.
# maybe it would be better to just copy the sections which end up in flash?
# (HOME, GSINIT, GSFINAL, INITIALIZER, CODE and others?)
target_firm = env.Command(
join("$BUILD_DIR", "${PROGNAME}.ihx"),
env['PIOBUILDFILES'],
env['LINKCOM'].replace("$LINKFLAGS", "$ldflags_for_hex")
join("$BUILD_DIR", "${PROGNAME}.elf"),
" ".join(
["$OBJCOPY",
"-O",
"ihex",
"$SOURCES",
"--remove-section=\".debug*\"",
"--remove-section=SSEG",
"--remove-section=INITIALIZED",
"--remove-section=DATA",
"$TARGET"])
)
env.Depends(target_firm, target_elf)

Expand Down Expand Up @@ -148,11 +172,14 @@ def _ldflags_for_hex(env, ldflags):

elif "stlink" in upload_protocol:
mcu = board_config.get("build.mcu")
# either derive value for the "part" switch from MCU name, or use the value
# in the board manifest, in cases in which the derivation would be wrong.
flash_target = board_config.get("upload.stm8flash_target", mcu[:8] + "?" + mcu[9])
env.Replace(
UPLOADER="stm8flash",
UPLOADERFLAGS=[
"-c", "$UPLOAD_PROTOCOL",
"-p", "%s" % mcu[:8] + "?" + mcu[9],
"-p", flash_target,
"-s", "flash", "-w"
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCE'
Expand Down
10 changes: 10 additions & 0 deletions examples/spl-blink/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ board = s8uno
platform = ststm8
framework = spl
board = mb208

[env:nucleo_8s207k8]
platform = ststm8
board = nucleo_8s207k8
framework = spl

[env:nucleo_8s208rb]
platform = ststm8
board = nucleo_8s208rb
framework = spl
6 changes: 6 additions & 0 deletions examples/spl-blink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@
/* Private define ------------------------------------------------------------*/
/* Evalboard I/Os configuration */

/* automatically use built-in LED for known nucleo boards */
#if defined(STM8S_NUCLEO_208RB) || defined(STM8S_NUCLEO_207K8)
#define LED_GPIO_PORT (GPIOC)
#define LED_GPIO_PINS (GPIO_PIN_5)
#else
#define LED_GPIO_PORT (GPIOG)
#define LED_GPIO_PINS (GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0)
#endif

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
Expand Down
Loading

0 comments on commit 3dd7514

Please sign in to comment.