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

0 Members and 1 Guest are viewing this topic.

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1432
  • 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

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1482
  • 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

Offline 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.
 

Online tszaboo

  • Super Contributor
  • ***
  • Posts: 7392
  • 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: 8657
  • 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: 1432
  • 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

Offline 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: 3713
  • 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.

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1482
  • 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: 1432
  • 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: 80
  • 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: 3369
  • 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: 1432
  • 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: 1432
  • 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: 1432
  • 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.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3713
  • Country: nl
Re: Experimenting with a STM8 MCU
« Reply #25 on: April 10, 2024, 10:20:34 am »
Yep you still have lots to learn. Not very efficient and prone to errors.

Look at your if statements and you will see that "== 1" is there twice.  >:D

For the checks you do 0, 1, 2, 3, 4, 5, 6, 1, 8, 9.

Look into the C "switch" statement to see how it can be done differently.

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1432
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #26 on: April 11, 2024, 12:02:32 am »
Ok thanks I missed that, I proof read some of it, but not that. I had some issues getting negative numbers too. At the start of the loop, I write all BJT's to off, and set all decimal digit values digX back to zero. I need to go through the if and for/increment statements, closer, and how that works with the >. Before I changed some > values like 9 to 10, and now 99 to 100 and 999 to 1000, I could have 3729mV read out as 3731mV iirc, and get negative numbers like 4699mV would get turned into 4_7_0_-1 mV( it might still be doing that one). I'm setting some remainder's to zero at the start of each loop, and then when digX increments or not, and subtraction happens, I can get negatives.

Now I have mostly correct serial output for the calculated decimal digits, but there are still common cathode's turning on at the wrong time, and DP problems. I should have a look with the scope too. I added 10ms delays between turning off 1 cathode, and turning on the next. So it my code that's not doing what I expect.


I downloaded Visual Studio software, for trying some C++ code in it, but yeah I'm pretty new to all that too.

Now I have the switching working. I used the switch...case commands, and added some pulldown resistors to the bases of the cathode drivers. But to fix the display issue I just had to drop some 'if > 1000) type statements. I was trying to use them as a shortcut.
2112575-0
« Last Edit: April 11, 2024, 04:37:44 am by MathWizard »
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3713
  • Country: nl
Re: Experimenting with a STM8 MCU
« Reply #27 on: April 11, 2024, 05:44:42 am »
Another handy C operator is % (modulo). Converting a value to digits can be optimized with that. Use "/ 10" and "% 10" to get the digits.

To make your DMM work better you can separate the tasks and use interrupts to have it perform faster. You wrote that you have the LED displays in a matrix, and for this an interrupt based on a timer is ideal to have it run independently.

A timer interrupt that runs every 100ms or so. It reads the digits from some memory marked as "volatile" (search for this) and outputs them one by one to the displays. Depending on how the connections are made, writing directly to the IO port instead of using digital write can make a huge speed difference. Look into how a binary to 7 segment display driver works. It can be done in a similar way in C.

The code for reading the ADC and converting it to the digits can be done in the main loop or also in another interrupt to make it more deterministic.

Have fun.

Peter

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 825
  • Country: es
Re: Experimenting with a STM8 MCU
« Reply #28 on: April 11, 2024, 07:28:26 am »
Answering the original question: yes, it is possible to halt the CPU and access all peripheral registers over SWIM, but I’m not sure is there a nice tool for that (some IDE with periph. regs visualization?). We did that from a Python script once ago: https://github.com/etransport/PySWIM - this tool halts an STM8, displays it’s GPIO states, communicates over bitbanged I2C with a battery monitor frontend IC attached to STM8 and dumps it’s regs. All being based on SWIM “read byte” and “write byte” ops.
 
The following users thanked this post: MathWizard

Online tszaboo

  • Super Contributor
  • ***
  • Posts: 7392
  • Country: nl
  • Current job: ATEX product design
Re: Experimenting with a STM8 MCU
« Reply #29 on: April 11, 2024, 09:21:24 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
Could you post link a guide on how to set up a compiler and an IDE to work with this compiler?
 

Offline prosper

  • Regular Contributor
  • *
  • Posts: 80
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #30 on: April 11, 2024, 06:57:58 pm »
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
Could you post link a guide on how to set up a compiler and an IDE to work with this compiler?

Here's my VS Code configurations for STM8 projects. Allows for breakpoint debugging, syntax completion, etc. Also shows the state of all the peripherals in the peripheral viewer when the cpu is halted

https://github.com/prosper00/STM8-VSCode
« Last Edit: April 12, 2024, 03:19:34 am by prosper »
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1432
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #31 on: April 12, 2024, 04:24:20 am »
Well I found some blank MCU's I bought ages ago, they are STM32F103C8T6. And it turns out I have a pre-built STM32uino, it's also a STM32F103C8T6, on a blue PCB, so maybe it's a "BluePill" ?.

And I have one of those DSO138 Oscopes, that I've damaged traces on, and the MCU's pins, which is the same as above.

So if I understand it, the ST-link is just a PCB w/ a USB jack, and another STM32 w/ an oscillator, and a 3V3 regulator for the Vdd of the chip. So when people say you need a ST-link, is a lot of that just so you have another chip using 1V8 or 3V3 logic levels ?

I found a few pages of people making ST-link's, I have all the hardware, but I'd want to put it all on through-hole protoboards. Or just order a ST-link clone. Or maybe if I get the STM32unio running, it can do all the ST-link would do.


For the STM32unio, I'm not sure if it's already programmed with anything. I've read about using Arduino's IDE with the STM32unio, and I found I need some files.

So I finally downloaded GitHub desktop. I didn't sign up or use any name or email yet, IDK if that matters....nevermind, it was stuck for 20minutes saying "compressing objects", while I'm trying to "clone" some "BoardManagerFiles" for STM8 and STM32.


One thing I would like to do, is copy some oscilloscope scope program, onto a blank MCU and get that handheld DSO138 working again. I would also like to try and read what's on the original chip with the damaged pins, if it's still working.

I have notepad++, and some datasheet on hardware level setup of these MCU's. I want to try some of that directly, without the IDE, but I think I need to upload some code to another blank STM32 1st, to use as the ST-link, to talk to another blank STM32 ??
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1432
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #32 on: April 12, 2024, 01:54:30 pm »
Ok when I 1st hooked up the STM32unio over USB, windows detected it and said it installed "maple", or called it maple, and installed something and it seemed to be connected on COM5. So it must have some bootloader or something on it.

But I don't see anything I recognize in the device manager. My regular Arduino shows up as something, whose name I recognize easily...

I got it on amazon 2-3 years ago, and the item was sold by a store called Canaduino, but it's amazonpage is gone, so I can't read what others did with it. But it looks like a common BluePill
https://www.instructables.com/Programming-STM32-Blue-Pill-Via-USB/


So from reading around, it might be a Maple mini clone, or just some common Blue Pill (but I'm new to all this crap and it's getting annoying).

So far, in Arduino's IDE, I've gone into boardmanger, and installed 2 or 3 things they list on this guide, like the using the github link for "package_stmicroelectronics_index.json", and installing the STM32 and STM8 stuff.
https://github.com/stm32duino/Arduino_Core_STM32/wiki/Getting-Started

Also in windows10, I installed STM32CubeProgramer, but not to the default place. Then in Arduino 2.3.2 IDE, I'd select COM5 and a GENERIC STM32F1 series board, IDK if that's right.

Then when I would try to upload something, it would say it can't find some STM32 programmer_CLI. I probably had the wrong output mode too, like SWD. I tried serial too, but I'm connected over USB, maybe it doesn't work that way.

Now I read elsewhere I should install STMCubeProg in the default location. I had a hard time uninstalling the program. I tried this with the 2.16.0 version #, and still in the end I had to delete it all by hand.
https://community.st.com/t5/stm32cubeprogrammer-mcus/can-t-uninstall-stm32cube-programmer-v2-5-0-from-windows-10/td-p/191635

I've rebooted the PC, reinstalled both Arduino IDE and STM32CubeProgrammer, to C:\Program Files.

But now when I hook up the BluePill/STM32uino, the USB makes the connect then disconnect sound. And I don't see it in device manger, under any name I can recognize.

So now what ????

I found a MP232EC chip, I think it's a TI MAX232. Can that be used for level shifting between a 3V3 STM32F103C8T6, and a 5V ATMEGA328 or ??
https://www.ti.com/lit/ds/symlink/max3232e.pdf?ts=1712907708973&ref_url=https%253A%252F%252Fwww.google.com%252F


There must be some way, to talk to this BluePill/chip, I have other logic chips, and 3V3 voltage regulators.
« Last Edit: April 12, 2024, 02:01:37 pm by MathWizard »
 

Offline prosper

  • Regular Contributor
  • *
  • Posts: 80
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #33 on: April 12, 2024, 07:05:42 pm »
i generally stick to the stlink and dont bother with the bootloader - it uses a comically absurd amount of your flash
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1432
  • Country: ca
Re: Experimenting with a STM8 MCU
« Reply #34 on: April 14, 2024, 09:23:28 am »
Yeah I noticed the memory %, but I don't have any idea how much code things need. I'll copy and paste my DMM digit reader code a bunch of times like I have a lot more digits to display, and see how big that gets.


The STM32F103 Blue Pill I have, I remembered I have a Bus Pirate, and using a terminal, I can talk to the BP with USB, and the BP sends UART to the STM32. And I got it doing something, and finally in STM32CubeProgrammer, it connects and sees I guess the bootloader or whatever it's called, in the memory from 0x08000000 down to 0x080003F0. Maybe there's more, but that's almost the whole 1st kbyte in main memory it seems.

SO I need to figure out what that is, and if I need to upload more code to it, to use it as a STM32duino.

So far with Arduino IDE, I couldn't upload a test sketch, IDK if everything that needs to be on the chip is on there, or if I need some other thing on windows. I'm new to STMCubeProg too, so IDK what it can do.


But Idid order a ST-Link clone, and now I have my sights set on something like a XGecu T48 universal programmer. They aren't that expensive, and the more all-in-one type thing I can get, for my hobby MCU projects/hacking, the better.
« Last Edit: April 14, 2024, 09:26:41 am by MathWizard »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf