I have been working with STM8S (-003, -103, -105) for a while, and recently got interested in the low power STM8L051. So I bought 10 on ebay. (First mistake? They look legit.)
My first task was "blinky". Just set up the GPIO pins and turn an LED on and off, with two simple for() loops for delay. I got that working.
Next is to bring in my "board" libary, which does the CPU frequency setup, GPIO, and a generic LED on/off function. I tested it for the CPU frequencies from 16mhz down to 125khz. So far, so good, the LED blink times seem to go with CPU frequency.
Then I want to bring in my TIMER4 clock library from STM8S, which uses an interrupt and gives millisecond and 1/10 second callbacks. Now I want to test the frequencies again. And that looks good.
Next, I want to start working with the Low Speed External oscillator. I grab an unmarked resonator that "looks" like a 32.768khz...
And after many tries with the register settings, I give up for a bit to do something else.
Around that point, my blinking CPU starts acting strangely. The blinking changes, sometimes going extremely fast, sometimes off for random periods. I tried flashing a "known working" image, but now STM8FLASH program gives me errors. I can read back, or write to the option bytes.
Interesting note: Before I could write to the CPU, I had to clear the read/write protection using "stm8flash -u". The datasheet says that the protection is disabled by factory default. Did I get already programmed and protected chips?
I give up on this CPU and solder a new one on a breakout board. This is my first time at soldering 0.65 pitch TSSOP, so maybe my first soldering job was "almost good enough"?
The new CPU seems fine. For a while. Then it starts acting badly. And it gives errors when trying to program the flash almost all the time. But not always. But the chip will not behave properly any more.
I have never had any serious flash problem with the STM8S103, and they advertise 10,000 cycles, so I have no problem re-writing new code constantly to them. Is the STM8L051 any different? On the first page of the datasheet, they make no claim about the flash endurance. So down in 8.3.5 "memory characteristics", I see...
100 cycles.
Damn.
"history | grep stm8flash | less" gives me hundreds, in the two days I have been playing with these chips. Damn. This is my typical workflow... I guess I should buy a lot of spares if they are going to die on me after a hundred cycles.
I soldered my third chip on a breakout board, flashed "blinky" on it, and it has been working perfectly for more than a day. It is in front of my monitor, so I get to watch it a lot.
Question #1: Do the failures I saw point to a problem with flash endurance? Or should I keep looking for another explanation?
Question #2: Should I start exploring the idea of putting only stable code in flash, and create a special area of RAM for my current code? I would probably have to make a special loader for the RAM code.
Question #3: Has anyone come up with a better solution?

Thanks!