Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two Nucleo boards, GDB debugging and SVD files for all boards #38

Merged
merged 16 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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