AnsweredAssumed Answered

Using Eclipse and STVD with Cosmic

Question asked by HaJo on Sep 29, 2016

Due to the CDT debugging issue this is a fair workaround for productivity (convenience due to Eclipse, issue tracking, git handling, doxygen (eclox) etc.)

Google always helps, so I gathered all info I found and tested this.

Of course one could use a rather modern IDE like Raisonance Ride7 or IAR or free tools like code::blocks with SDCC and so on. I prefer Eclipse...and COSMIC. It is not limited to 32k anymore, so try it. I sticked to this since 2004 with a ST72F321 and the old CodeWarrior IDE...
STVD is o.k, I like it more than IAR and Ride.

In STVD: Export Makefile in menu Project. Rename *.mak to makefile
I would try to compile the code in the commandline to be sure it works. It does not always due to the path issue (spaces in the path...)
I had to use quotation marks like this
ToolsetBin="C:\Program Files (x86)\Cosmic\CXSTM8"
So I started with gmake all CFG=Debug. In case the code has been compiled in STVD before, force gmake to compile all stuff again. Delete all object files with gmake clean first.

Eclipse: Import C/C++ Existing Code as makefile project and choose the path to your project.
Set Properties
 C/C++ Build Builder Settings Build Command to  c:\Program Files (x86)\STMicroelectronics\st_toolset\stvd\gmake.exe  (you can use parameters here).
Add C/C++ General Symbols _COSMIC_ to see the valid COSMIC sections in your code. The compiler uses __CSMC__ to trigger the section define in stm8s.h.

In your defines.h or similar file included in all files use the workaround for the Eclipse @-parser-issue (@tiny, @interrrupt etc. shown as Bad characters sequence encountered:@).
The parser is not able to resolve these variables.
#ifndef __CDT_PARSER__  //in Eclipse: suppress @tiny @...
 #define _at(n) @n  //compiler sees @tiny @far...
 #define _at(n) //CDT sees nothing, so no warning
BTW: Do not use any old ## concatination tokens in your macros. It is not needed and generates warning messages.

Then replace all @xxx by _at(xxx) in your code.

I also recommend to add or link the Source Location of ..COSMIC/Hstm8 in properties. 

Delete all warnings and rebuild the C/C++ Index

In case you use GNU make instead of gmake.exe or use a different shell (git bash or sh), you have to change the paths to / instead of \ in the makefile. Always getting caught by the ugly naming conventions...

I recommend to change the wording in the makefile ("build" instead of "all"):
build : $(OutputPath) $(ProjectSFile).elf

Then Create Make Target for your project: for build and flash
build builds the files needed for the debugger (no need to trigger build in STVD)
flash flashes the code if you like to test without debugging

Modify your makefile for flash:
Device=STM8S207SX - according to your type

flash : 
 $(FlashTool) -BoardName=ST-LINK -Device=$(Device) -Port=USB -ProgMode=SWIM -no_loop -no_log -no_verif -verbose -FileProg=$(OutputPath)\$(TargetSName).s19

"Build Automatically" starts compiling on filechanges.

I recommend to use doxygen and the eclox plugin (also combines Graphviz and mscgen) for documentation.

After compiling switch to STVD, set your breakpoint and start debugging. Changes inside STVD will be reflected in Eclipse and vice versa.

In case a source file opened in STVD changes in Eclipse, a message will appear asking to reload the file(s) ("Save Externally Modified Files"), use a autohotkey script to close it automatically (Yes To All) or press ALT+a.

Now, Eclipse is the editor, STVD the debugger only.

Best of both worlds... as long as ST does not create a working GDB for STM8 or someone else builds a SWIM debugger supported by Eclipse plugins.

Best regards,