-
Notifications
You must be signed in to change notification settings - Fork 27
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 debug support using STLink(/V2) via OpenOCD #31
Comments
Ah, I was about to open this issue as well. I've played around a long time with this circa a month ago and had a good fight with sdcc, stm8-gdb and openocd; the first two to make them generate an ELF file with debug symbols that stm8-gdb can read, and the last one to figure out the correct command to program the chip, since it wouldn't except the usually used I'll talk about what I've expiermented with / found out / having problems with so that maybe other people can gloss over it, too. For SDCC to include debug information into the compiled files (or the I've experimented quite a bit with it and used advanced scripting to work around this bug by last-minute fixing the line-endings before feeding into SDCC. This does allow it to compile correctly with However, as a next blockade, reading the generated In any case, I'm also able to connect to my chip using OpenOCD. Using simliar commands per your I'll continue my journey to get this working further regarding:
And hopefully at the end, we have fully-featured development environment for STM8 chips with PlatformIO, beatiful and correctly working Intellisense for SDCC, and debugging with OpenOCD with the help of debug symbols generated by SDCC and read by stm8-gdb, plus register decoding as one can e.g. see here, as it already works for other PlatformIO platforms. Addendum: [env:stm8sblue]
;build_type = debug
platform = ststm8
board = stm8sblue
framework = arduino
;upload_protocol = stlinkv2
upload_protocol = custom
upload_flags =
-f
interface\stlink-dap.cfg
-c
transport select swim
-f
target\stm8s103.cfg
upload_command = $PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd $UPLOAD_FLAGS -c "init; reset halt; load_image {$SOURCE}; verify_image {$SOURCE}; reset; shutdown"
debug_tool = custom
; empty. You need to start openocd yourself with
; openocd -f interface\stlink-dap.cfg -f target\stm8s103.cfg
debug_server =
; $PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd
; -f
; interface\stlink-dap.cfg
; -f
; target\stm8s103.cfg
debug_port = localhost:3333
;debug_load_mode = manual
debug_init_break =
;tbreak setup
debug_init_cmds =
$INIT_BREAK
; monitor init
; monitor reset halt
debug_load_mode = manual
build_flags = --debug --fverbose-asm --verbose
debug_build_flags = --debug
extra_scripts = fix_debug_compile.py and the import shutil
Import("env")
def dos2unix(file_to_strip, output_file):
content = ''
outsize = 0
with open(file_to_strip, 'rb') as infile:
content = infile.read()
with open(output_file, 'wb') as output:
for line in content.splitlines():
outsize += len(line) + 1
output.write(line + b'\n')
def fix_elf(source, target, env):
# build our own
#print(env["LINKCOM"])
#env.Execute([env["LINKCOM"]])
pass
def fix_rel_file(source, target, env):
for src in source:
print("dos2unix fix: " + str(src))
dos2unix(str(src), str(src)+".fixed")
shutil.move(str(src)+".fixed", str(src))
# so that debug output ends up in the final ELF file
#env.Append(LINKFLAGS=["--debug"])
# hook pre-build actions of these files to workaround SDCC error:
# if .rel files compiled in --debug mode have Windows line endings, linking will fail.
env.AddPreAction("$BUILD_DIR/libFrameworkArduino.lib", fix_rel_file)
env.AddPreAction("$BUILD_DIR/libFrameworkArduinoVariant.lib", fix_rel_file)
env.AddPreAction("$BUILD_DIR/${PROGNAME}.elf", fix_rel_file)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", fix_elf)
env.Append(LINKFLAGS = ["--verbose", "--debug", "--fverbose-asm", "--no-peep"])
#env["OBJSUFFIX"] = ".o"
#env.Replace(LD="sdld")
#env["LINK"] = "stm8-ld"
##env["LINKFLAGS"] =[] |
Hi @maxgerhardt ! Following is my platformio.ini, and that's the only thing you need to change. I know, it'll be nice to have these on the python files, but it's a good starting point.
I'm using an STM8S003, with an STLinkV2 on a generic volt/amp meter chinese board. |
Oh wow thank you, this actually works for me too! :) I however wasn't able to even debug the [env:stm8sblue_debug]
platform = ststm8
board = stm8sblue
;framework = spl
build_type = debug
build_flags = --debug --out-fmt-elf
build_unflags = -Og -ggdb2 -g2
debug_tool = custom
debug_server =
$PLATFORMIO_CORE_DIR/packages/tool-openocd/bin/openocd
-f interface/stlink-dap.cfg
-f target/stm8s103.cfg
-c "init"
-c "reset halt" for my STM8S103 chip, and it works per above.
These come from the core as the default debug flags that get applied when using I might open an issue there to have this fixed. But this is really good. Once the fix that that the debug mode builds with the CC @valeros for-your-interest. |
Right, the flash usage is pretty high when you use SPL's code; hence I'm not using it. Also, in my example, the flash size and ram size are set for the stm8s003. About the addition of the "core debug flags", amazing! About OpenOCD, it should be already supported, it's just we're not passing the appropriate flags to the server on this particular platform. As you can see, everything that the package |
Great stuff! With help from @gicking, even peripheral registers decoding (see "Peripherals" panel) is on the way after creating nearly the correct SVD files. I plan to create and PR the GDB debugging support and SVD files directly into this platform soon so that it becomes a built-in thing :) |
Resolved in #38 |
Hi , I know the issue is closed and quite old but I am on platform io 6.1 and was trying to get debugging working for stm8s003f3p6 sadly i am getting a .pioinit:13 error. Any idea what could be causing this ? I hv tried uploading the code and that works fine , the upload and debug also do work fine for stm8s103f |
Well what's the log when you run |
I got the following output
Weirdly enough . I wrote a basic code to test stms103f3 and when I ran the same code on stms003f3 the debugger worked(although I need to do a clean before it starts working) now if I stop this debug session and retry to debug with old code it starts debugging although i dont think properly as none of the breakpoints are getting hit. |
So I disabled the IO operations on the swim lines and tried to debug the code again , this time I have a new error. and yes I hv read about DWARF error and how sdcc guys say they fixed it but it didn't actually get fixed and then this thread was a work around. BUT where do I stand now with this new error ? |
Yes the problems with SDCC were notorious. Is it possibly for you to upload your exact project files into a repo and link it here? Or at least a minimal version which makes that error appear. |
https://github.com/anshchawla521/b3603 I have the repo link here for now , but will try to put together a minimal version |
Are you able to debug a simple blinky project with the |
I cannot build the SPL blink example there was no entry to stm8s003f3 in platform.ini so I manually added it like I did in my project Also do i need to do |
Hi!
I'm currently porting an existing project I have from IAR to SDCC and Platformio. One thing I really need is the debug feature using the STLink/V2 probe I have. I found out that this platform on platformio doesn't support being debugged, although the STM8S105 from the ST8Discovery kit does allow it (even if that one also has an STLink embedded on it).
So I figured I could give that board a try, even if my MCU is different. It turns out that the openocd doesn't allow to use SWIM with the provided arguments, but it can use SWIM by changing the arguments you pass to it.
Then I managed to run OpenOCD with custom parameters, with the following code added to platformio.ini:
It's actually able to communicate with the board I have, but I don't have a complete running code to validate it actually works. Moreover, OpenOCD complains that the provided image doesn't contain debug symbols and I should specify them with the "file" command. I thought platformio would be creating an .elf file with debug symbols, but might not be the case? Or am I missing something?
Thanks!
The text was updated successfully, but these errors were encountered: