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

0 Members and 1 Guest are viewing this topic.

Online pcprogrammer

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

Offline tszaboo

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