Author Topic: Experimenting with a STM8 MCU  (Read 2809 times)

0 Members and 1 Guest are viewing this topic.

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1438
  • Country: ca
Experimenting with a STM8 MCU
« on: April 05, 2024, 12:54:20 pm »
I'm getting more familiar with MCU's on the hardware level, and today I have a STM8S003F3P6 on a breakout board. It was from an ebay temperature sensor. There was no external memory.


For now I don't want to try using some IDE to talk to it, or even with Arduino and it's IDE, I'm pretty new to all that too.

I have a few STM8 pdf's and links open, but I feel pretty lost.

I just want to put it in some reset state, using hardware on a breadboard, so it's not running it's internal code, and just try sending it simple op-codes, just for simple things like to read some memory address, or some status register. Just so they feel real.

IDK if that means I have to send commands over I2C from Arduino, or with Bus pirate. Or can I do it with an 8bit shift register and 555 timer circuits I have made up that could send bits to some port. ??

Maybe this is what SWIM is for? Single wire interface module (SWIM) and debug
module (DM). Or UART ??

Or maybe this is a bad MCU to try doing anything by hand ?? (I don't mean UART or anything complicated....I mainly just what to read from some memory addresses)
« Last Edit: April 05, 2024, 12:56:30 pm by MathWizard »
 
The following users thanked this post: oasis2020

Online HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1488
  • Country: gb
Re: Experimenting with a STM8 MCU
« Reply #1 on: April 05, 2024, 01:28:22 pm »
You can't "send" it op-codes. It has internal flash memory for program storage - it doesn't use external memory, there is no external bus. Your code needs to be programmed (via the SWIM interface) to flash before it will execute anything. If it's a pre-programmed chip salvaged from an existing board, unless you erase it and re-program it, it will simply execute the code it already has in flash.

(Technically speaking, seeing as the STM8 can execute code from RAM, you could write code to RAM via SWIM debugger and tell it to jump to and run that, but that would be a complicated exercise.)

Do you have an ST-Link programmer device? If not, you need one to program the chip. A cheap $5 clone ST-Link/V2 from eBay/Amazon/AliExpress should suffice (although I should mention I've heard STM8 support on the clones is sometimes hit-and-miss). Unfortunately the STM8S003 does not have a built-in UART bootloader ROM, so you can't program it via UART like you can with other chips in the range (see the stm8gal utility for that).

Do you want to program it in assembly or C? Either way, a good place to start is with the SDCC compiler. It includes an assembler too. The assembly instruction set is pretty easy - very similar to the old Motorola 6809.

If you are trying to run the bare chip on a breadboard, note that you need to connect a 1uF capacitor between the VCAP pin 8 and ground.
« Last Edit: April 05, 2024, 01:35:56 pm by HwAoRrDk »
 
The following users thanked this post: MathWizard

Online ksjh

  • Contributor
  • Posts: 18
  • Country: de
Re: Experimenting with a STM8 MCU
« Reply #2 on: April 05, 2024, 01:50:44 pm »
When I started to experiment with STM8 devices, I followed this blog post:
https://lujji.github.io/blog/bare-metal-programming-stm8/
I found it quite easy to follow, even when you have never been working with this architecture before.
 

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7401
  • Country: nl
  • Current job: ATEX product design
Re: Experimenting with a STM8 MCU
« Reply #3 on: April 05, 2024, 02:50:50 pm »
I tried it a year ago. You need to request a time limited, computer locked license from a French company in an email to get started. Then there are no examples whatsoever online, so figure out everything yourself.
I just put the eval boards to a cabinet, and decided to used something that is easier to program.
 

Offline rhodges

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
  • Available for embedded projects.
    • My public libraries, code samples, and projects for STM8.
Re: Experimenting with a STM8 MCU
« Reply #4 on: April 05, 2024, 03:25:31 pm »
You can use my STM8 libraries and example programs to get started:
https://github.com/unfrozen

If your board is the W1209 temperature sensor, I have a library for the LEDs, keys, and relay. ("lib_w1209.c")
Currently developing STM8 and STM32. Past includes 6809, Z80, 8086, PIC, MIPS, PNX1302, and some 8748 and 6805. Check out my public code on github. https://github.com/unfrozen
 

Online coppice

  • Super Contributor
  • ***
  • Posts: 8671
  • Country: gb
Re: Experimenting with a STM8 MCU
« Reply #5 on: April 05, 2024, 03:34:53 pm »
I tried it a year ago. You need to request a time limited, computer locked license from a French company in an email to get started. Then there are no examples whatsoever online, so figure out everything yourself.
I just put the eval boards to a cabinet, and decided to used something that is easier to program.
The STM8 was built mainly for the Chinese market, where it was doing pretty well at one time. I have no idea if it still does. Perhaps they only bothered with proper support in Chinese.
 

Offline rhodges

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
  • Available for embedded projects.
    • My public libraries, code samples, and projects for STM8.
Re: Experimenting with a STM8 MCU
« Reply #6 on: April 05, 2024, 03:42:33 pm »
I think the documentation for STM8 is quite good.
One really nice feature is that Flash and EEPROM are super easy. Just unlock and write bytes.
Currently developing STM8 and STM32. Past includes 6809, Z80, 8086, PIC, MIPS, PNX1302, and some 8748 and 6805. Check out my public code on github. https://github.com/unfrozen
 

Offline prosper

  • Regular Contributor
  • *
  • Posts: 80
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #7 on: April 05, 2024, 04:05:44 pm »
I like the STM8 overall, as a cheap and useful 'small' mcu. Although these days, it really doesn't make much sense to spend the mental capital to learn and build a toolchain and ecosystem for it. There are a bunch of more modern mcus out now that compete in the same price band, and are all much more 'open' - inasmuch as the tooling is much more standardized and more thoroughly developed and used (i.e. arm-gcc and co). And the STM8 is officially 'not recommended for new designs,' although ST will continue producing them for 7 or 8 more years at least.

It's a de-facto standard in China. There are a *ton* of random TSSOP-20 mcu's from China now that all magically use a compatible pinout to the venerable STM8. There's a thread here somewhere about the HK32F030M, for example, which is a 15ยข cortex M0+ that's electrically compatible with the STM8s003. Heck even the ch32v003 naming nomenclature is reminiscent of the stm8s003

It's a decent enough MCU - about half the effective cpu speed as an AVR, but with a really decent set of peripherals. SDCC is an adequate (free) compiler, though much more suited to bare metal register-based programming instead of HAL libraries (SDCC doesn't support GCC-style sections, for pruning out unused code and functions, so, including lots of abstraction libraries makes things really bloated really fast). Although there *are* various projects out there to adapt the SPL hal library to work with SDCC. Do a search on github for 'STM8' - there actually is a reasonable amount of templates and projects published to get you going.

You need a ST-Link probe to program it. Those $2 ST-Link clones are hit-and-miss whether they'll properly work with STM8 or not.

There is a GDB / binutils patch set that supports STM8, so that you can do debugging on it - which is a really handy feature.
« Last Edit: April 05, 2024, 04:08:43 pm by prosper »
 

Offline prosper

  • Regular Contributor
  • *
  • Posts: 80
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #8 on: April 05, 2024, 04:20:11 pm »
also, from the way to phrase your question, it seems like you're confusing a microcontroller with a microprocessor - the address and memory bus, for example, are all completely internal to the mcu, and are not electrically accessible to the user. You can't just tack it to a breadboard and attach a parallel SRAM chip and watch what's happening on the bus.

I'd suggest looking at Ben Eater's video series of the 6502 breadboard computer if that's the sort of thing you want to learn. For an MCU - especially one that's younger than about 40 years old - all of that peripheral stuff is completely internal to the chip.
 
The following users thanked this post: MathWizard

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1438
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #9 on: April 05, 2024, 04:33:36 pm »
Ok thanks, so I would have to download some ST tools like the IDE. I was reading that bare-metal guide before, up until they jump right in with the IDE. But I see it's C++, so I've done a little bit with that in Arduino's IDE. And I know people can use Arduino to mess with these STM8, that's what I'd have to try then, in order to communicate with the PC over USB.

Yeah this MCU is just a random one I have, from a cheap 3 or 4 digit temp sensor, so I just wanted something to fool around with. I might have 1 or 2 un-programmed MCU's, any other's I have are salvaged, like on a DVD VFD display I was playing with lately. That uses a Toshiba TLCS-870 family IC, sort of like a Z80, but there's not much info on those. I used a logic analyzer to capture the data sent to the VFD display, but yeah I can't tell what it means, and so far can;t understand the datasheet good enough either.

I read that if you learn the basics of 1 ARM type MCU, it's easy to learn the other ARM models. But yeah I just want to learn more basics of MCU's, besides just Arduino, and try "hacking" something. IDK which ones are better to spend time on, but yeah probably cheap ones.
« Last Edit: April 05, 2024, 04:38:49 pm by MathWizard »
 

Offline prosper

  • Regular Contributor
  • *
  • Posts: 80
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #10 on: April 05, 2024, 05:22:18 pm »
no, you don't need st tools. I've never used their STM8 IDE. absolute bare minimum, you could get things going with a text editor and SDCC, as well as a ST-link probe and stm8flash (or openocd, if you prefer pain).
 
The following users thanked this post: MathWizard

Online ksjh

  • Contributor
  • Posts: 18
  • Country: de
Re: Experimenting with a STM8 MCU
« Reply #11 on: April 05, 2024, 05:56:03 pm »
I was reading that bare-metal guide before, up until they jump right in with the IDE. .

Do you mean the one I mentioned? No, they do not use an IDE, and they do not use any code from ST. I think the goal of the blog post was to show how to use commonly available tools like SDCC and text editors (in this case, under Linux) to get the STM8 working without any vendor stuff. Everything is open-source. But they use C as a programming language (not assembly language), so you need at least some C compiler toolchain (e.g., SDCC). The beauty of this approach is that they teach how to just use the documentation to access peripherals (UART, timers, counters, ADC, I2C, ...) with your own code. This is why you can call this a "bare metal" approach.
 
The following users thanked this post: MathWizard

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3735
  • Country: nl
Re: Experimenting with a STM8 MCU
« Reply #12 on: April 05, 2024, 07:09:08 pm »
Bare metal basically means that you start from reset with your own code and no operating system to support your programs.

The STM8 looks just as simple as the ATmega MCU's used on a lot of the Arduino boards. But if you have a hard time understanding datasheets and reference manuals than it won't be easy to do bare metal things on your own. It all starts with the manuals. Settings for the peripheral control registers need to be looked up to be able to do something useful with it. Otherwise you are stuck to libraries other people wrote.

The one MCU from your DVD player is not that hard, like you wrote it is a lot like a Z80, but without the ability to read the mask ROM that is in there it it very hard to tell what it does, and it has no use without being able to reprogram it. That is the beauty of MCU's with a FLASH or an external memory bus, they can be repurposed.

If you want to play with MCU's to learn more about them, I would suggest to stick with the Arduino environment for a while and learn from playing with the examples that are all over the net. You can use it with STM32 based boards if you want a bit more processing power. Check things against the manuals to see if you understand what things mean or do.

also, from the way to phrase your question, it seems like you're confusing a microcontroller with a microprocessor - the address and memory bus, for example, are all completely internal to the mcu, and are not electrically accessible to the user. You can't just tack it to a breadboard and attach a parallel SRAM chip and watch what's happening on the bus.

Not necessarily. True that most smaller modern microcontrollers (MCU's) have no external busses, but they do exist, even ARM based. For instance the F1C100 has no real useful internal memory but does have a lot of peripherals embedded in it. So it is a microcontroller and not a microprocessor.

Online HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1488
  • Country: gb
Re: Experimenting with a STM8 MCU
« Reply #13 on: April 05, 2024, 08:14:36 pm »
The STM8 looks just as simple as the ATmega MCU's used on a lot of the Arduino boards.

Indeed. There is nothing more complicated in an STM8 than a typical ATmega. In fact, it's simpler than most AVRs1, because all I/O, peripherals, and flash are memory-mapped in the same address space - none of this separate address spaces for peripherals and flash like an AVR. That is one annoying thing when programming AVRs - even with Arduino - having to use pgm_read_* functions to read data resident in flash2.

(1. Yes, I know modern 0- and 1-series AVRs are different.
2. Well, there's also the __flash named address space you can attribute variables with, but no-one seems to use that.)
 
The following users thanked this post: MathWizard

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1438
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #14 on: April 05, 2024, 11:29:23 pm »
Ok I've left the STM8 alone for another day. I should get 1 of those early MCU kits, made with more discrete parts, for understanding the hardware better.

But I have some 4 digit LED blocks, so I made a breadboard circuit with 8 PNP drivers and 4 NPN sinks. So with Arduino, I'll cycle the NPN's 1 after another, with the PWM pins, and get some numbers to display. I guess I could try to make a digital temperature sensor, just using a thermistor, maybe for use on my DIY PSU. Or make a daylight sensor/meter, that guesses the time.

IDK how hard that will be, but i want to try without just copying an example.

Or I'd like to try sending it data, like from 1 of my DMM's, whose LCD screen I want to upgrade to something much brighter/illuminated. I've seen pages on here where people added a MCU to the DMM to decode the LCD instructions.

The VFD display I salvaged, is too small, and it's hard and noisy to drive it, with much wider voltages needed. My DMM can't do that.
 

Offline Atlan

  • Frequent Contributor
  • **
  • Posts: 334
  • Country: sk
Re: Experimenting with a STM8 MCU
« Reply #15 on: April 07, 2024, 04:00:48 am »
Unsolder Stm8, buy ch32v003 and solder it.  There are many examples for ch32v003.  IDE It's free.
FNIRSI 1013D Always provide a picture or video with the problem where the parameters of the oscilloscope are visible, and a picture of the diagnostic screen with the values.
 

Offline Sacodepatatas

  • Regular Contributor
  • *
  • Posts: 83
  • Country: es
Re: Experimenting with a STM8 MCU
« Reply #16 on: April 07, 2024, 04:31:47 am »
If your board is the W1209 temperature sensor, I have a library for the LEDs, keys, and relay. ("lib_w1209.c")

I thought that W1209 modules with STM8 MCU are extinct nowadays. The new ones that i've got, all of them have the Freemon FT61E143 in SOP16. In a near future I'm planning to get some Puyas PY32F002BW15S that have the same pinout and most peripherals are on the correct pins, so i can repurpose these modules for something more useful.
« Last Edit: April 07, 2024, 05:00:07 am by Sacodepatatas »
 

Offline rhodges

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
  • Available for embedded projects.
    • My public libraries, code samples, and projects for STM8.
Re: Experimenting with a STM8 MCU
« Reply #17 on: April 07, 2024, 01:58:10 pm »
I thought that W1209 modules with STM8 MCU are extinct nowadays.
That might be. When I was working with them, Nuvotron was starting to take over. The example I bought recently has a SOP16 MCU in it (but not the CH32V003).
Currently developing STM8 and STM32. Past includes 6809, Z80, 8086, PIC, MIPS, PNX1302, and some 8748 and 6805. Check out my public code on github. https://github.com/unfrozen
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3375
  • Country: nl
Re: Experimenting with a STM8 MCU
« Reply #18 on: April 08, 2024, 04:24:38 am »
I bought a bunch (around 30) STM8 Ic/s & breakout boards recently, because I thought they were nice chips:

* Quite cheap.
* Upto 6.5V power (runs directly of Li-Ion without voltage regulator).
* Onboard EEPROM.
* Peripherals look a lot like STM32 (Which I'm also fiddling with).
* Less complexity then STM32.

After I took them out of the letterbox, I discovered there is no GCC support for them. This probably means they will end up into some drawer or a waste bin without me ever using them.
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1438
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #19 on: April 08, 2024, 08:45:11 am »
I need to check my parts inventory, and see if I ever ordered any MCU's. But sometime soon I'll have to research what I'd want, and start using them in projects. I was making a Curve Tracer for awhile, using a MCU with that would be nice.

So far today, with Arduino, I've got a 4digit LED display, that will basically be a volt meter, once it's done. Right now though, it just samples a ramp voltage, made from a PWM pin and an RC filter, and just decides how many digits to light up, so 0.000, or 0.00 or 0.0 or  0.   based on if the integer # of mVolts, is less than 1000, 100, 10.

But now I need to decode each mV integer, and light each digit in sequence, and repeat. I could get a lib file or whatever they are called, but I need to learn more basics.
« Last Edit: April 08, 2024, 08:49:34 am by MathWizard »
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 322
  • Country: au
Re: Experimenting with a STM8 MCU
« Reply #20 on: April 08, 2024, 10:01:26 am »
I did a bit of tinkering with STM8 around a year ago to reprogram a wireless doorbell chime based on a STM8S003F3. I tested my code initially on a cheap breakout board. I already had several stlinks from working on STM32.  I used ST Visual Develop and the "special edition" Cosmic compiler and those were fine for what I needed to do.
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1438
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #21 on: April 08, 2024, 10:13:11 am »
So can those programs read and alter the program that's already in it ? I think someone said I can erase it at least, and reuse the MCU. I know some types of IC's can have encryption or have physical access cut off.

I'll have to try those programs real soon.
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 322
  • Country: au
Re: Experimenting with a STM8 MCU
« Reply #22 on: April 08, 2024, 11:04:21 am »
I was expecting it to be protected from being read, but was a bit surprised to discover, that that was not the case, so I was able to grab a back up copy of the original code before I erased and reprogrammed it. It could have been protected, but for whatever reason the maker had not done that.

Edit: I should have mentioned, but actually had forgotten, that I also used ST Visual Programmer (STVP) programming software as well.
« Last Edit: April 08, 2024, 11:17:53 am by ozcar »
 
The following users thanked this post: MathWizard

Offline prosper

  • Regular Contributor
  • *
  • Posts: 80
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #23 on: April 09, 2024, 04:30:09 am »
I bought a bunch (around 30) STM8 Ic/s & breakout boards recently, because I thought they were nice chips:

* Quite cheap.
* Upto 6.5V power (runs directly of Li-Ion without voltage regulator).
* Onboard EEPROM.
* Peripherals look a lot like STM32 (Which I'm also fiddling with).
* Less complexity then STM32.

After I took them out of the letterbox, I discovered there is no GCC support for them. This probably means they will end up into some drawer or a waste bin without me ever using them.

SDCC is a competent compiler that supports STM8. And theres a patched binutils that gets you GDB for stm8. I'd recommend avoiding ST's SPL functions, though, and just use the register definitions.

I really like STM8, and used it as my go to small/cheap mcu for quite a while. And Ive still got a tray of L151s kicking around. Nowadays, though, you can find M0's and RISCV mcus that outperform stm8 on all fronts, for less money
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1438
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #24 on: April 10, 2024, 09:38:09 am »
Hey I got my 4digit Arduino DMM working, almost. It reads from the 10-bit ADC on one of the pins, converts it to mV, then does some math I came up with that works, to get each decimal. I know there's quicker ways for the math, but that's ok for now.

Once it has a decimal segment calulated, it just uses 10 if statements, each time, to choose which decimal digit segments to light up. Then it waits 100ms, and calculates the next digit.

But it slows up a bit, and I've seen numbers getting stuck, and more than 2 digits lit up at the same time, even tho that should not be allowable, I turn all the cathodes off at the start of the loop. And after each cathode is turned on for it's 100ms, I turn it off.

And for some reason, the decimal place's aren't working, probably a breadboard issue.


You can see the serial print out, the 4 digit number, and the  broken up, and some remainders I used to get the digits.


The IDE really makes it feel like cheating tho, since IDK how all these things get done behind the scenes. I want to try some 4 or 8-bit only, MCU/CPU simulator, and see how they do all the math operations.

But that was fun.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf