Thursday, June 06, 2019

Sleepy Bee to MSP430 to STM32L031... Woeful complexity

I need a simple very, very low power MCU to form the basis of coin cell sized IoT sensor monitoring.
Here is what it needs to do:

  1. Control the Semtech SX1276 LoRa chip via SPI
  2. Talk to an accelerometer via I2C
  3. Spend a lot of time sleeping waiting for accelerometer events.
  4. Wake up, send a LoRa command and go back to sleep
  5. Wash, rinse, repeat.

(If you read this blog you'll know that C and pre-written Arduino or STM32Cube or whatever frameworks are not the answer for me.  I'm old and tired of learning your new (potentially half baked) frameworks. I've got spec sheets on the peripheral chips and know how to use them....)

So, I need to choose...

Sigh... the C8051 (Silabs SleepyBee) is just too low level. I've got enough 16 bit math and string manipulation to do that it simply doesn't make much sense to go this low.

MSP430 is long in the tooth. Sure, the specs are still there and the chips are available but they seem overpriced for what I need (basically 1KB RAM and maybe 32K Flash).  I'm not nickle-and-diming it, but it just feels wrong to pay $3-4 for such an old design.  I've got Forth Inc SwiftX MSP430 code and there is always Mecrisp too, so from a development perspective the MSP430 has what I need.  But, the chip availability is spotty and pricey...

What about ARM Cortex?  It's hard to beat the ARM Cortex these days. Size, power, diversity: It has that in spades.  I'm well versed with the STM32L496 and STM32L432 but those M4 beasts are overkill for my needs.  They are very complex chips.

So I stumble upon the STM32L031 and I am blown away by the datasheet specs. It's a Cortex M0+ with MSP430-like low power specs. Heck, it blows away most MSP430s. And is cheaper... given 8KB RAM and 32KB Flash.

A couple of years ago I ported Forth Inc's SwiftX ARM compiler to the STM32L432. It took a little effort, but it worked.  I think I used an STM32F411 as the basis for the port.  I'm not looking forward to porting to the STM32L031.  But wait, it looks like there is a Mecrisp-stellaris port for that chip. Hurrah!  But, wait again... its a bare port. No systick, no CMSIS mappings, etc.  Okay. I like bare metal stuff... but... I have this thing I want to build and I need something working soon.  Maybe I don't want to bite off the effort.  Let's see... there is already a systick interface in Mecrisp for another STM32 part, maybe I can start there.  But then I have to deal with sleep transitions.  On the MSP430 (and Sleepy Bee) it is dead easy. The STM32L  has always been a bear.  Is the L031 sleep code the same as the L432?  I hope so.. otherwise I have a lot of reading to do.

I download the L031 reference manual...  it's around 900 pages. Okay, I know I don't need to consume it all, but I'll need to do the laborious register bit hunt and the requisite ten thousand clocking options.

What am I doing here?  I need a simple low power microcontroller with an RTC sleep mode less than a couple of uA and run mode less than 5mA.  I want it with enough memory that I can get my stuff done.

To add to this dilemma, the STM32L072 (which should be very close to th STM32L031 I mentioned above) is now the darling of "module" embeds.  Well, "darling" may be overselling it, but there is a rather nice LoRa module I'm looking at that embeds this MCU. If (a big IF) I get the L031 working it should be a simple port to the L072.

But... I'm stuck on the overall complexity of the STM32L.  I've been there before (the L496), but I was paid to work with that chip for 9 months. Nine months living and breathing the nearly 2000 pages of reference manual.  Tweaking. Tuning.

Maybe MSP430 isn't dead to me after all. The MSP430F2274 (1KB RAM + 32KB Flash) is more than adequate.  I've got a SPI driver written. I've got a development environment. 
But at $6 (https://octopart.com/search?q=MSP430F2274)  it's insanely pricey.  The STM32L031 (which has more memory, features, smaller sizes and uses less power) is only around $2.50.

Honestly, I am not making millions of devices so a few dollars here and there doesn't really matter.

But I have to ask myself... is it worth the complexity?

3 comments:

  1. Is it worth the complexity?

    I say not only yes, but HELL YES!

    Once in our ancient prehistory a tribe of Neanderthals were busy making fire hardened points on their arrows when a few guys from the newly arrived Homo-sapiens dropped by. The Homo-sapiens showed off their flint arrow heads demonstrating how hard and sharp they were and how this new technology had replaced all their old fire hardened wooden arrowheads. Initially the Neanderthals were very keen but soon decided that given how long the skills to make these new arrowheads took to learn, plus lengthy and dangerous journeys to distant volcanic areas for the special material, they decided that the old ways were just fine and did the job. They all parted as friends.
    A hundred thousand years later archaeologists were digging in that same area and uncovered a small tribe of Neanderthals in a mass grave, and were surprised that every skull had a small hole in it and when shaken, something hard could be heard rattling around inside.

    Are you fighting the inevitable ? We know the C8051 and MSP430 are old 16 bitters even if the MSP430 is nicely designed, a pleasure to assemble code for but pricey.

    The STML32's are insanely complex, so is a F35 fighter, it's a function of their capability, you can't have insanely capable and simple, just because!

    I bought some 64 pin STM32L162RDY6TR's with 384KB Flash, 48KB RAM etc (overstock from Arrow.com) the other week, for $0.90 AUD each. These things are insane and in a WLPCSP64 body, metal on silicon, no plastic. One of the most awesomely pretty chips I've ever seen and probably the most fragile.

    Cortex-M is the future, so cheap, so fast, so capable, just accept your fate and give up all hope, I find it's easier after that:)

    I can supply a complete memmap and bitfield Forth file derived from CMSIS-SVD for the STM32L0x1 and Mecrisp-Stellaris, just give me a email address if you want them? They will save you about 50 years compared to typing them by hand :)

    ReplyDelete
  2. Not to nitpick, but the 8051 is an 8-bit processor (and way older than the MSP430).

    I get your point though. For me, if I were designing a real product to be sold in large quantities, I'd have to agree with your assessment. But for hobby projects where parts cost isn't as much of an issue, I prefer a processor I can more easily wrap my head around, like the MSP430.

    This same attitude is what draws me to Forth over other languages, especially for hardware product development. Forth is the only programming language I can reasonably claim to truly understand most of the ins and outs of.

    Maybe someday I'll have to "accept fate and give up all hope", but I'm not there yet!

    ReplyDelete
  3. Frogman, oops, apologies for my inaccurate writing, and thank you for the correction. I know the 8051 is a 8 bitter having started my embedded journey with the National PACE 16 bitter around 1976, about 4 years before the 8051 came out.

    I was trying to convey my attitude that they are both old, but you're right, the 8051 is ancient, and the MSP430 well integrated and easy to use.

    I loved the 6800 and find the MSP430 similar with its orthogonal instruction set but the STM32F and L just have too many goodies, speed, flash and ram, and such low prices I'm attracted to them like a moth to a candle flame.

    Besides, Forth does make quick work of even the most feature-full MCUS, it's the great-leveler, not that a bit of CMSIS-SVD doesn't hurt when it comes to memory mapping all the STM32 Words.

    I'm a electronics tech first and foremost so the more capable the MCU the better it is from my POV. I love the STM32 hardware and the tech manuals.

    I started learning Forth only in 2014 and some of more complex aspects are still a mystery to me but that makes it tantalizing and still a lot of fun.

    ReplyDelete