by ohazi · 6y ago · 0 comments
Don't get me wrong, boards like this (and ESP/Realtek boards with WiFi) are great for hacky prototypes. But if you're building an embedded device that will be deployed in any sort of volume, a small application processor running Linux will make your life dramatically easier. You can keep it asleep most of the time if your power budget is tight.
The hard part is not cramming in an Ethernet PHY or a 2.4 GHz radio, it's the mountain of software that you need to run on top of it to get the kind of reliable, secure communications channels that we've come to expect. Bare metal networking stacks like LwIP have a reputation for being buggy, and are nowhere near as battle-tested as the Linux/BSD networking stacks security-wise. Some of the more memory constrained devices can barely fit a complete certificate chain. Are you really prepared to roll out updates on a system like this when the next Heartbleed comes along?
Also, the layers tend to pile on, so while you might get away with a bare-bones wire protocol initially, you'll be starting your project close to the limits of what is practical. Somebody will eventually ask you if you can connect to a websocket. I know buildroot and yocto look a little scary at first, but they're better than designing yourself into a corner before you even get off the ground.
If you don't know jack about network programming, then of course you can retreat to Linux. But Linux is not an edge / IoT platform by any stretch of the imagination. Micro RTOS is closer, but still overkill for embedded Wi-Fi.
Specifically for Wi-Fi, LWIP is -the- stack to use for embedded TCP/IP. It is under 30K with full TCP/IP and offers everything you need. Then there is COAP or MQTT, which are miniscule compared to HTTP. mbedTLS adds another 80K for full TLS compatibility on 40MHz processors. On top of this every major wifi vendor has an SDK that fits nicely into LWIP (some even ship it), some are small (CC5000) some are larger (like the WF200), but the APIs are pretty straightforward. Now, leaving TCP/IP and 802.11 will add headaches (BLE, ZigBee, Zwave) due to additional learning curves, but only because most people in embedded networking already understand TCP/IP and 802.11 phy.
If you want to play in the embedded space, you gotta learn about it. Running back to linux might work in some cases, but not constrained IoT space.
EDIT: I had my #s reversed, LWIP is under 30K, mbedTLS is around 80K, TLS is most of that (esp. RSA stuff, I could have disabled everything I didn't need [mbed has highly granular config] based on the ciphersuite and shrunk it considerably since ECC is smaller and faster than RSA). Just checked my map file, and I was in -O0 optimization mode.
EDIT2: On second thought: if people want to complain that they need linux to do networking on the edge, please complain! I'll interview after you and demonstrate MQTT with TLS v1.3 running off an MCU with a 2032 coincell for months (eh, I'm weirdflexing a little, but still...)
To illustrate, let's say we build the embedded device your way. Six months later, we get a support request from a customer that needs to get the device onto the captive portal at a hotel. The portal is a javascript monstrosity full of CORS failures.
What is your immediate response?
a) Oh, shit, I didn't think of that. I can probably come up with a workaround, but I'll need at least a month, and it'll end up being a huge hack that involves tethering with a phone or laptop (but not via WiFi, since the radio we're using can't do AP and STA modes simultaneously), and the UI will be such a disaster that the customer is immediately going to want to find a better product.
or
b) This is an industrial CNC controller... WTF are you doing on a hotel WiFi network?
If your answer is (a), then your approach is almost certainly the wrong one. If your answer is (b), your approach might be reasonable, but there are still other factors to consider.
It's possible to know everything there is to know about network programming but still not want to debug or re-implement 30 years worth of accumulated cruft around firewalls, MTU sizes, MS-CHAPv2 bugs, malformed packet crashes, anything IPv6, etc. And that's just the table stakes... leaky abstractions mean that sooner or later, everything connected to the internet is going to need to do something higher up the stack that's just barely out of reach for your microcontroller, even one that's beefy enough to run Windows 95. What are you going to do when there's some new web standard where the only implementation is in the Chrome source code as of three months ago?
You'll be able to make it work, but it'll take thousands of person-hours to make it work well. Or you can just "run back to Linux."
Separately, if you're running a company that builds embedded devices, do you want to pay your engineers to fix network stack bugs that were solved in 1999, or do you want to pay them to develop your company's value-add? Weirdflex all you like, it's still (usually) a terrible business decision. I don't think pennypinching on the BOM is a valid justification when things like [1] exist.
[1] https://www.seeedstudio.com/MT7688AN-BIT3-1-Module-p-4011.ht...
I don't really know where to start, you clearly want to defend your comfort zone. So I will be supportive: go work on projects that require Linux. It will be much more rewarding to you than working on constrained edge devices that are more challenging due to resource constraints.
You're also free to pretend that you can just swap in platform that requires watts of power in a scenario that requires an edge device to last a year on a battery.
Expectations around what an internet connected device should look like and be capable of changed permanently with the launch of the iPhone in 2007. There will always be special cases like yours, but they are increasingly (sadly?) relegated to smaller corners of the internet.
I did it your way for years. Every company I've ever worked for that started off with a microcontroller based networking solution eventually migrated to an application processor because users and non-technical management kept demanding iPhone-like behavior that was either too difficult or too time consuming to deliver any other way. People expect a lot more functionality than just TCP sockets and web interfaces nowadays.
With the caveat that it's not a one-way trade-off of "better" vs. "good enough for the expectations". If your customer calls you and says "My industrial CNC controller crashed and ruined a $20k prototype, is this my fault or yours? Here are the logs." and your answer is "the browser was running bad javascript that locked up too many threads for too long so it stopped counting the encoder for 20 ms", they're going to tell you that a servo amplifier has no business doing any of that stuff.
Some devices do need to be on the Internet and should therefore be running general-purpose operating systems. They may need to interact with other devices that run real-time operating systems (or bare metal, like the Teensy). Some IoT devices try to bridge the gap. Knowing and deciding which side you're on is critical.
And I think the best answer to pennypinching on the BOM is to separate your concerns into separate devices/apps. Make the CNC HMI handle the Internet connectivity. Give it one NIC that hooks up to the Wifi, let it run whatever Javascript you want. On a separate NIC, talk whatever flavor of industrial protocol you prefer on the machine. Do not bridge the two. In the servo amp, use a bare-metal/RTOS microcontroller. That device doesn't need to be burdened with Linux, and in fact is made worse by it: Let it be what it is and no more. In 20 years, it should still run reliably, regardless of whatever newfangled holographic VR HMI is loading in motion profiles.
FPGAs and microcontrollers are really good for meeting (and verifying that you're meeting) hard real-time constraints.
Network connectivity (by definition) can't be real-time, so you wouldn't want to run a network stack on the real-time core anyway, even if you could.
Instead of adding another non-real-time microcontroller for networking and making it sweat, go with an application processor and just treat it like a dumb modem that happens to know how to handle VPN traffic without exploding.
There are application processors like the i.MX7 and the STM32MP1 that combine a Cortex-M4 and a Cortex-A7 on the same die for precisely this reason (and similar FPGA fabric + PowerPC / ARM Cortex-A? products from Xilinx and Altera for even longer).
As a web & backend developer who likes to tinker with Arduino/Teensy style projects, I've always been curious what all would be involved in actually getting some units manufactured, like for a small kickstarter run or something. It seems pretty doable these days to get pcb boards printed and even assembled once you have a final design. What I haven't been able to find much of, is advice along the lines of going from a prototype board like an Arduino or Teensy system, to a productionalized system in terms of both the software and hardware - what platform is easiest to build on (like this advice to use a Linux-based system if you need any networking), how to hook up a bootloader, how to build a system that allows users to update firmware for future bugfixes or features, etc. plus I'm sure there are a million other unknown unknowns I would never even think of.
If you're looking at broader focus on building hardware, Contextual Electronics helps to fill out some of the other elements you're looking to do. As luck would have it, I just started a new course today (no joke) where I'm showing how I'm designing a Raspberry Pi HAT with cellular and Bluetooth capabilities, which I'll be selling and using as a reference design for my hardware design consulting business.
As for KiCad, the most recent release (5.1.x) have been really stable and introduced a ton of features over the series 4 release. Like anything, once you're used to the methods, it's hard to get an objective look on how things work but I can tell you that I use KiCad for all of my professional design work and it has served me very well.
One thing I continue to be excited for is the extensibility of KiCad, since Python scripting is a main feature of KiCad (though the program is written in C++). This has developed a wide range of user plugins and scripts that have opened up some awesome new features.
One of my favorites is the Interactive BOM plugin, it's really quite amazing. Here's a user showcasing it on twitter: https://twitter.com/arturo182/status/1254376168322670593
The boards themselves are quite nice. It's an Arduino-like stack and you can always code in C++ if you need the STM32 capability underneath. The main stack is also open source I think.
Doesn't really cover much on the mechanical side, e.g. enclosure design. That's a whole different game and that's where people lose a lot of money - if you mess up an injection mold for example.
It was basically the same process as looperhacks: hook stuff up on a breadboard, turn that into a prototype PCB design, iterate on prototypes if there are problems, then just put 100 on the order form instead of 5 when you send it to the manufacturer.
You asked in the other comment about flashing and that depends. For me, my project was basically just a motherboard for an ESP32 dev board, which would serve as the logic controller. Since it has a micro-USB port and there were only 100 of them, I just flashed it from my laptop the same as any dev board.
For larger scale manufacturing, you can have the flash written in advance, before manufacture or put some exposed contacts on your board that can be reached with pogo pins and write your flash through those pins.
You can also outsource all of this to a contract manufacturer like Seeedstudio [0].
As for updates, the ESP32's software has built in OTA functionality that you can configure however you please. My boards are connected with MQTT over WiFi anyway so I added a simple "update now please" command that triggers the OTA. Aside from that you could add a USB port or stream the OTA over bluetooth from a smartphone.
It mostly comes down to reading the documentation for the specific microcontroller that you're using.
No association with the company, just a satisfied user.
Don't such things solve most of these issues?
https://access.redhat.com/documentation/en-us/red_hat_enterp...
https://www.ni.com/en-us/innovations/white-papers/13/introdu...
I mean there seem to be the market so clearly there are some people who need it, I just would like to learn more about where is it really needed.
Lots of time they are just a giant C library that goes into the same a.out, that for devs look close enough to let himself pretend there will be an OS running his code.
What I find interesting about the situation is the Arduino environment. The Teensy originated as an "Arduino" type dedicated controller board. The Arduino environment originated on something that had 32K of flash memory and 2K of RAM. (Think Altair 8800 or IMSAI 8080).
It was designed so that people new to embedded controllers could get something running quickly on a very simple processor.
The Cortex-M architecture (which the Teensy uses, as does the STM32 parts) is somewhere between the 68000 and the 80286 in terms of its capability (no MMU though).
On at $30 dev-board (STM32F429-DISCO) from ST-Micro I've run a full shell/loadable program environment with networking based on a FreeRTOS kernel and a shell of my own devising.
It is the Arduino environment that cripples these things, if they ran the equivalent of MS-DOS none of these complaints would make any sense at all. (and they are very capable of running that level of OS)
Can you name some? I think of most embedded network stacks as being easier than raw socket APIs on Linux or Windows.
Programming network on Linux only looks that easy because of megatons of ready to use abstraction libraries available.
While you can get M4 for under a 1$ having all built in and very power efficient.
Also no need to hustle with linux deployment and update rollouts.
For example Raspberry Pi has the Compute Module, ESP32 comes as a solderable module and for the Teensy I suspect you'd just put a IMXRT1062 in your design.
Implying that embedded systems get updated...
Have you looked into PJON?
Although I'll add that Linux has it's fair share of networking bugs and quirks (less now than before, but still plenty.)