Introducing Sduino for the STM8

Arduino on the STM8 (8 bit processor)
tenbaht
Posts: 12
Joined: Wed Oct 11, 2017 3:10 pm

Re: Introducing Sduino for the STM8

Post by tenbaht » Fri Jan 05, 2018 1:42 pm

Jimmus wrote:
Thu Jan 04, 2018 9:33 pm
It did take me about 20 minutes to figure out how to get my STLink gadget working. And figuring out which pins to connect to the serial adapter, and how to convert the Serial.print() to Serial_print_s() calls took a little bit longer. I wish there were a couple of sample programs somewhere I could have looked at. They could have saved me some time.
I am happy to hear that this project helped you a little bit!
A step-by-step beginner tutorial clearly would be a useful addition to the project website. Unfortunatly, I am pretty busy right now and won't be able to push things forward until April or May. Would you maybe willing to summarize your steps and add some useful pictures? I would be very happy to add it to the documentation.
https://github.com/tenbaht/sduino - Programming the STM8 the Arduino way

MarkB
Posts: 10
Joined: Sun Oct 02, 2016 11:40 pm

Re: Introducing Sduino for the STM8

Post by MarkB » Fri Jan 05, 2018 5:11 pm

mrburnette wrote:
Fri Jan 05, 2018 12:56 am
Just curious as I used to get some kicks from the ATtiny85... (cheap, used to buy 'em in 25x qty.)

I get the $1 each approx. board price, but can you share your use cases for the STM8?
Minor point, but for cost comparison the STM8s103f3p6 minimum development boards can be found on AliExpress for around $0.70 shipped.

Because absolutely minimizing recurring cost matter more to volume manufacturing than it does to electronic hobbyists, the various STM8-based products that can be hacked for one's own purposes are arguably more compelling than the simple development boards and some are available very inexpensively.
https://github.com/TG9541/stm8ef/wiki/S ... ne-Gadgets

For example the W1209 thermostat as a "development board" is under $2.00 complete with 3 digit display, 3 user defined buttons, a relay, a NTC sensor, and STLink programming pins brought out on the PCB (through holes to the left of the display in this case).
Image
https://www.ebay.com/itm/1PCS-Red-W1209 ... Sw8zdaAeff

Cheap STM8 products tend to use the STM8S003f3p6 device which is identical to the STM8S103F3P6 except for less EEPROM (128 vs 640 bytes) and a lower guaranteed number of flash cycles. As with the STM32 EEPROM, the 003 devices actually have more EEPROM than specified more often than not.

The obvious downside of STM8 at the hobbyist level is that entry level support is severely lacking compared to Arduino. tenbaht's efforts toward a near Arduino environment are a big step in lowering this barrier to entry. I think Roger has mentioned that ST is working on Arduino support for STM8 as well. The STM8 eForth project from the link above is also very well done, though one will likely be cracking open the programming manual sooner to use peripherals in that environment. The eForth project has work arounds (one (multiplexed in/out) and two pin software serial ) for the fact that many of the STM8 based devices use the serial pins.

User avatar
RogerClark
Posts: 7541
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Introducing Sduino for the STM8

Post by RogerClark » Fri Jan 05, 2018 8:05 pm

I have noticed that the STM8 is used in at least 2 devices I own.

A lot if those USB current / voltage metering dongles with OLED display, seem to use the STM8
Also I have a panel mounted 4 digit, voltage and current meter , which also uses an STM8

I bought the panel mounted meter with the intention of reflashing it, and writing my own firmware, but have never got around to it.

There are probably STM8s embedded in more consumer devices around the house that I am not aware of.

So I agree with Mark, that the “use case” for these devices, as not to build projects from scratch using those cheap dev boards, but to hack/repurpose/enhance existing devices

Jimmus
Posts: 15
Joined: Tue Nov 28, 2017 4:08 am

Re: Introducing Sduino for the STM8

Post by Jimmus » Sat Jan 06, 2018 5:00 am

SonOfAGun! MarkB, that temperature controller was going to be my second project! Maybe I'll just buy that thing. Except for the 12V, it's pretty much what I wanted, with the addition of 7-segment readout and buttons and such.

I recently got into Sous Vide cooking. The commercial devices you can get at Walmart for like $65, and they let you connect with your cell phone and control and monitor the cooking. I don't need that, but I did want to try it out. I pulled out my old crock pot and wired up my Arduino Uno to a DS1B20 temperature sensor and a sugar cube relay board, and ran some tests. I wondered what kind of temperature accuracy I could get. I was pleasantly surprised. I thought I might have to do some sort of PID algorithm or hysteresis, but with just a simple "< threshold turn on, > threshold turn off" algorithm it kept the water within 1.5 degrees F. That was good enough for me, so I seasoned up some steaks, stuck them in ziploc bags, and tossed them into the water. Oh my GOSH! It was almost trivial to cook that way, and it was some of the best steak I've eaten ever. I'm not even a connoisseur of fine steak, but I'm sold! I liked it so much I have cooked similar stuff several times a week for the last few weeks, and I don't see myself cutting back anytime soon. It's hogging my Arduino Uno, and I want it back. I need to figure out how to do oneWire on the STM8, and then build a circuit with an opto-isolator and triac instead of the relay board, and I'll be good to go.

The project I'm currently working on is a mailbox door open detector. It simply signals me when the mailman comes. Eventually I plan to have it actually alert me via text or Wifi or something, but phase one is just an LED on the mailbox pointed at my house that blinks after the mailman has come. The STM8 board is perfect because it will be battery powered, and spend the vast majority of the time in Low Power mode. I had planned to use an Arduino Pro Mini, and build a circuit with a couple of MOSFETs that would power me up when the switch was activated and allow me to power down from software after sending the signal. But I have already ripped the voltage regulator and power indicator LED off one of my STM8 boards and tested it, and it will work fine just in Low Power mode.

Ray, I find that the vast majority of my projects don't need even 32KB of flash. I have done projects with AtTiny85s, or even AtTiny13s that are still in use. I even did one with an AtTiny9. But I got tired of how inconvenient it was to write in Assembler and hook up the wires to download the programs. I expect there will be some learning curve with each new sensor and actuator but since I have already found where the core files are hidden, it won't be as bad. Grep is my friend. I also found the example sketches, by the way. It would have been nice to know they existed. And where to find them.

Jimmus
Posts: 15
Joined: Tue Nov 28, 2017 4:08 am

Re: Introducing Sduino for the STM8

Post by Jimmus » Sat Jan 06, 2018 5:47 am

Tenbaht, I don't remember exactly the steps I had to go through, but I think I can remember the couple of things I had problems with...

First, when I plugged my STLink device in, somehow Linux didn't recognize it. I don't know why, because I was messing with it and watching dmesg, and it started working. I think unplugging it and plugging it back in may have done it. Anyway, I had to mess with it a little bit.

Second, there was a link on the installation page that said something about a flash program. The link was broken, but I looked up the stm8flash program and downloaded it and built it anyway. My Arduino IDE wasn't downloading correctly at that point, but it successfully built a .hex file, which I was able to flash using the stm8flash program from the command line. I had to use sudo. I didn't know if this was how I was going to have to do it all the time. Thankfully, I eventually got the IDE to flash using its copy of the stm8flash program.

I had to mess with the IDE in order to get it to flash. I remember getting a strange error that I fixed by going into preferences and unchecking the "aggressively cache compiled core" box. The STLink V2 device never showed up on any menu or anything in the IDE. It just worked.

The hardware serial pins are D5 and D6. I had to make sure my serial device had the right permissions.

It's pretty easy to see how to use the Serial_begin() and Serial_print_s() sort of functions by looking at the defines in HardwareSerial.h. Once you find that the cores and stuff are in a subdirectory of hidden folder .arduino15 which is in the ~/ directory.

The example sketches are somewhere in the .arduino15 branch as well. ~/.arduino15/packages/sduino/hardware/stm8/0.3.3/libraries/Generic_Examples/examples

User avatar
mrburnette
Posts: 2028
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Introducing Sduino for the STM8

Post by mrburnette » Sat Jan 06, 2018 3:09 pm

MarkB wrote:
Fri Jan 05, 2018 5:11 pm
<...>
the various STM8-based products that can be hacked for one's own purposes are arguably more compelling than the simple development boards and some are available very inexpensively.
https://github.com/TG9541/stm8ef/wiki/S ... ne-Gadgets
Makes sense from a hacking perspective; especially for some uncommon devices.

Ray

tenbaht
Posts: 12
Joined: Wed Oct 11, 2017 3:10 pm

Re: Introducing Sduino for the STM8

Post by tenbaht » Sat Jan 06, 2018 4:44 pm

Jimmus wrote:
Sat Jan 06, 2018 5:47 am
First, when I plugged my STLink device in, somehow Linux didn't recognize it. I don't know why, because I was messing with it and watching dmesg, and it started working. I think unplugging it and plugging it back in may have done it. Anyway, I had to mess with it a little bit.

Second, there was a link on the installation page that said something about a flash program. The link was broken, but I looked up the stm8flash program and downloaded it and built it anyway. My Arduino IDE wasn't downloading correctly at that point, but it successfully built a .hex file, which I was able to flash using the stm8flash program from the command line. I had to use sudo. I didn't know if this was how I was going to have to do it all the time. Thankfully, I eventually got the IDE to flash using its copy of the stm8flash program.
There is something about the needed permissions and the well known driver problem with the ST-Link/v1 interface on the STM8S-Discovery boards on https://tenbaht.github.io/sduino/hardware/flashtool/ Maybe a better link on the start page?
Jimmus wrote:
Sat Jan 06, 2018 5:47 am
I had to mess with the IDE in order to get it to flash. I remember getting a strange error that I fixed by going into preferences and unchecking the "aggressively cache compiled core" box. The STLink V2 device never showed up on any menu or anything in the IDE. It just worked.
Thank for that feedback! That's all problems that wouldn't happen here, because I already set it up a long time ago. But of cause this is important to know for a first time user. I added this to my todo list:
  • A menu entry for the ST-Link devices is on my todo-list.
  • mention that you still need to grant permissions manually, even for an automatic install.
  • explain how to set permissions for the serial device
  • a brief tutorial mentioning at least some of the print "methods" like print_s, print_u etc.
But it will take a while before I will be able to find time to work on this.
https://github.com/tenbaht/sduino - Programming the STM8 the Arduino way

Post Reply