Getting started with STM8S - Page 1
Forum section: electronics / general

author: Mustey
author_rank: Contributor
timestamp: June 25, 2020, 04:50:07 pm
content: It's a weird story but the gist of it is that I am trying to save the fledgling business of my friend.This requires me to help him with programming a little on the stm8s003f3.I just received today my STLINK-V3SET and I should be receiving a few eval boards soon.I started looking into the software toolchain but I am already scared that I might not be able to find all the "API" calls to actually compose code for that chip to run.I don't even know if these should be referred to as API calls, methods, routines?I guess I will be installing a library specific to that chip with those calls but is there a resource that describes the library and how to use it?Ideally with some examples on reading/writing from/to i2c devices?

author: ebclr
author_rank: Super Contributor
timestamp: June 25, 2020, 05:24:03 pm
content: Did you tried this ?https://www.st.com/en/development-tools/stvp-stm8.html

author: Mustey
author_rank: Contributor
timestamp: June 25, 2020, 06:12:19 pm
content: I have just installed it and it doesn't work ("side-by-side configuration")... Nevermind, let's say I get it to work - I had a look at the provided docs and it looks even scarier. This C look a lot less nice than the C I learned when I was programming on a windows machine!I guess you are going to say that it's not something a novice can pick up in a couple of weeks?

author: OZ1LQB
author_rank: Regular Contributor
timestamp: June 25, 2020, 06:24:00 pm
content: Hi ..This is what godt me startedCosmic and STVDand this very good and free bookhttp://embedded-lab.com/blog/wp-content/uploads/2018/01/Starting-STM8-Microcontrollers.pdfgood luck and have fun

author: OZ1LQB
author_rank: Regular Contributor
timestamp: June 25, 2020, 06:47:31 pm
content: Hi Again..dont forget to downlod the example code herehttps://libstock.mikroe.com/projects/view/2056/stm8-microcontroller-tutorials?fbclid=IwAR0zaLO_adAyDuZYPn2mU-nwnglXibxcJXHEMrYNyvKbi68R_D1_PZncO_8

author: Mustey
author_rank: Contributor
timestamp: June 25, 2020, 07:37:45 pm
content: I just skimmed that resource and I feel like I need to give the guy some donation or help him maintain/update this document.A serious body of work that looks also pretty accessible.I did forget to mention I dug everywhere on google and found some stuff like E. Marinoni's site but mostly it looks like people who may know what they are talking about but have no idea how to transfer their knowledge effectively.I didn't find this document but now you showed it to me - thanks!

author: rhodges
author_rank: Frequent Contributor
timestamp: June 25, 2020, 10:05:08 pm
content: I use the free SDCC (small device C compiler) and ST-LINK V2 and stm8flash to program the chips.I have a nice ecosystem of STM8 libraries, sample/example programs, and projects on github. Most of it is for STM8S103 or STM8S105, but the STM8S003 is so close, they will work fine.The libraries have support for many input and output devices, such as keypads, LCD, and LED modules, binary/decimal conversion, PWM/servo control, ultrasonic rangefinding, UART. It also has a support library for the STM8S003 W1209 thermostat, which has three buttons, a 3-digit display, a temperature probe, and a relay.https://github.com/unfrozen/stm8_libs/wikiHere are some test and example programs, ready to compile with the libaries and write to flash:https://github.com/unfrozen/stm8_tests/wikiHere is a PWM controller project for a motor:https://github.com/unfrozen/pwm_pump/wikiHere is a water tank level sensor using ultrasonic rangefinder:https://github.com/unfrozen/pwm_pump/wikiFeel free to browse the code, and use whatever you like.

author: soFPG
author_rank: Frequent Contributor
timestamp: June 26, 2020, 08:15:33 am
content: I can recommend the IAR environment for STM8, it allows debugging, probably has the best compiler for performance and code size.As far as I know they also offer header files with register and bit definitions.But for commercial use you may have to buy the software from them. Probably several thousand dollars.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: June 26, 2020, 09:01:45 am
content: If you want to use ST's SPL but not use proprietary toolchain, their device headers have been open-sourced and there is a patch to make SPL compile with SDCC.https://github.com/gicking/STM8_headershttps://github.com/gicking/STM8-SPL_SDCC_patch

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 26, 2020, 10:53:05 pm
content: Quote from: Mustey on June 25, 2020, 04:50:07 pmWhat does he have already working ? Are PCBs already designed ?Usually, with a new micro you are best to take the most traveled path, initially.That means buying Eval Boards (more than 1 is useful, as you can A-B compare different code versions ) - they are so cheap, it is useful to have spares.One detail to keep in mind, is the smaller ST8M packages have few code-size choices.If size is not an absolute must, and the board is not done yet, you could consider TQFP32 package, as that has larger code size options.If you are new to MCUs, & the requirements morph, spare code capacity can be gold

author: HwAoRrDk
author_rank: Super Contributor
timestamp: June 27, 2020, 09:05:09 am
content: Quote from: PCB.Wiz on June 26, 2020, 10:53:05 pmAlthough bear in mind that once you get to chips with more than 32KB of flash, you have to jump through a few hoops to properly utilise the extra space (the compiler needs to be able to handle 24-bit 'far' addresses).I believe the free version of Cosmic is restricted to 32KB.

author: OZ1LQB
author_rank: Regular Contributor
timestamp: June 27, 2020, 12:49:08 pm
content: Hi.HwAoRrDk it is not restricted anymore.here is what it says on hompage of cosmicSTM8 free tools with no limitsThe popular STM8 compiler, with no technical limitations.

author: Mustey
author_rank: Contributor
timestamp: July 06, 2020, 08:39:25 am
content: Spent 9 hours yesterday (20:00 - 05:00am!) trying to get started. I followed the 'embedded-lab' guide which looks a little better than it actually is. It's amazing how low level it gets sometimes and then just totally skips over stuff. Also code is full of typos, which is nearly fatal for someone who isn't an embedded-c developer like me...Once I got something that builds fine, I tried to flash it into the chip. Tried both STVD-lite-programmer and STVP - both complained about not being able to communicate with the application (pretty sure this means the chip) via SWIM.I found an application installed with STVD that's supposed to "upgrade" (update?) my LINK with the latest firmware - it said the data on my link is corrupted... Although not sure if that program is designed to work with the V3SET in the first place...Now, I will be starting the SDCC route. Unfortunately, all the examples I can find are on linux. I know a little linux so I know what they mean and how to do it on Win10, but would be more confident to see a real example - I don't reckon any of you SDCC users are on windows and can tell me which compiler and build tool you used (for preparing STCC)?

author: soFPG
author_rank: Frequent Contributor
timestamp: July 06, 2020, 09:00:35 am
content: Maybe you can get some help from the man himself:Even though he is using the Padauk backend I think there might still be some information in there.But I don't know how switching to a different compiler will help you with not being able to communicate with your uC. I didn't find this information in your comments, but: which board are you using? How is your setup?

author: Mustey
author_rank: Contributor
timestamp: July 06, 2020, 09:58:36 am
content: I know it's a little unrelated - the STVD itself has an option to choose the compiler (I don't remember if SDCC is there)...I was just looking at it from a tactical point of view: much easier to find worked-out examples of SDCC+stm8flash or STVD+STVP but much less common to see a mixture of them... And I think STVD is the offending member of my system, which is:Win10 > STVD > Cosmic > STVP > STLINK-V3SET > stm8s003f3Yeah, I just saw this vid as a recommendation when I was searching for music this morning, lolHave not had the time yet to take a look!

author: soFPG
author_rank: Frequent Contributor
timestamp: July 06, 2020, 10:17:13 am
content: I am going back to my recommendation: In order to verify that you have a working setup you might still want to try IAR's STM8 workbench (which you can get for free, with code size restrictions though) which is an all-in-one package.After you have verified that everything works you can still switch to an open source toolchain.

author: Mustey
author_rank: Contributor
timestamp: July 06, 2020, 11:42:50 am
content: Yeah, I am definitely up for trying different things... Just it all takes time!Anyway, I have another direction to go to. I got some support from the manufacturer and what they say is interesting. I think it may benefit others, should they be in my very particular situation, to know the following:https://community.st.com/s/question/0D53W00000BrKYsSAN/stlinkv3set-cannot-communicate-with-target-over-swim-or-doesnt-work-at-all-with-stvdstvp(TL;DR: Apparently there's missing info in the manual and when downloading drivers. JP3 also needs to be closed and a different driver than what they initially say, needs to be used)