Page 1 of 1

Introducing Sduino for the STM8

Posted: Wed Oct 11, 2017 4:06 pm
by tenbaht

last year I adopted the Arduino environment as closely as possible for the STM8. Now user Kenjutsu suggested to link the STM8 board of this forum from my project website as a place for general discussions about my project. I hope that is ok? So far I didn't post any links.


Re: Introducing Sduino for the STM8

Posted: Wed Oct 11, 2017 8:49 pm
by RogerClark

I know several other people were investigating how Arduino could be run on the STM8.

AFIK no one has written a complete core that is C++ compatible for the STM8, but I think work is still ongoing

Or perhaps the best that is achievable is a C based system, with workarounds for classes

Re: Introducing Sduino for the STM8

Posted: Wed Oct 11, 2017 9:20 pm
by tenbaht
Hi Roger!
Yes, that's what I did. Use pure C, but thanks to some preprocessor magic it almost looks like C++. In many cases you get away with a simple search-and-replace to exchange all class-dots with underscores. Converting an existing Arduino library is harder, though.
It would be great if somebody would find a way to use SDCC for real C++ input. There are some ideas around, but AFAIK none is working so far.

Re: Introducing Sduino for the STM8

Posted: Wed Oct 11, 2017 9:37 pm
by RogerClark

Is you system integrated into the IDE ?

I looked at the github link, and it looks like its standalone.

We are a bit luckly with the SM32 because the ARM compiler gets installed if you install the Arduino Due or Zero, but I know that other compilers can be used with the IDE because the ESP8266 uses a completely different compiler.

So I presume it would be possible to integrate into the IDE

Re: Introducing Sduino for the STM8

Posted: Thu Oct 12, 2017 1:11 am
by RogerClark
Where do you get the compiler ?

Is it from here

Re: Introducing Sduino for the STM8

Posted: Thu Oct 12, 2017 7:15 am
by tenbaht
Yes, it's the SDCC.
I would love to integrate it into the IDE. I tried that at the beginning, but I never got it to work without having at least one C++ input file. I don't remember the full details anymore, but it was something about a hardwired assumption about filename extentions in this build program, that is distributed as an exe only.
If somebody would find a way to make it work with C only would be great! Right now I am using a Makefile based on the makefile
That works great on Linux and MacOS and is my favorite working style, but unfortunately, windows is not suited very well for this and things get slow there. Really slow. This happens because make heavenly relies on forking the current process which is not supported on Windows and is internally emulated by starting new processes from scratch. And that takes time. A lot of time. Compiling-the-blink-example-takes-40-seconds kind of time. Time wasted just to needlessly starting and killing subprocesses. I guess this is why the Arduino guys came up with their proprietary build system in the first place.
Somebody came up with a python implementation of a simple build system. That might be an improvement, but using the stock Arduino one would be the best.

Re: Introducing Sduino for the STM8

Posted: Thu Oct 12, 2017 8:58 am
by RogerClark

No worries

I have looked at the directory structure and its similar to Arduino STM32 but not quite the same

I'm also not sure how the Arduino IDE creates the list of files it needs to send to the compiler.

Re: Introducing Sduino for the STM8

Posted: Sun Oct 15, 2017 7:55 pm
by dannyf
tenbaht: welcome. your sduino port is a valuable option for users of STM8.

On the use of SPL: when I ported STM8Sduino, I actually used a middle layer (of mine) that is built on SPL. The overhead is about 2kb (using IAR). As my target was small STM8s (STM8S003F), I thought that was too costly and went to a middle layer that doesn't rely on the SPL and then completely wrote out the middle layer - the overhead now is about 0.5 - 0.75kb.

It may be helpful if you look into your code and see which functions are taking up the most space and gradually replace them with your own code to save space.

Just my 2cents.

Re: Introducing Sduino for the STM8

Posted: Mon Oct 16, 2017 8:27 am
by tenbaht
Hi danny,

Yes, the SPL is a memory hog and quite complicated to use. The only advantage I can see in using it would be to be prepared for an easier migration to the STM32.

That's why I don't use it for Sduino anymore. It is still part of the source code, but the only function still used is the serial initialization code - and this is on it's way out as well. But so far I am still planning to keep the SPL related to Sduino to allow for easy integration of SPL-based example programs by the user.

To avoid the 2kB penalty of linking dead code I wrote a Makefile that breaks up the SPL source files into single-function source files and compiles them separately. This way only the functions that are actually used get linked into the project and no dead code is left. So it is possible to use SPL, but it doesn't cost anything if you don't.