Showing posts with label UsingHwTools. Show all posts
Showing posts with label UsingHwTools. Show all posts

Saturday, September 22, 2018

So You Want To Be An Embedded Systems Developer

Then listen now to what I say.
Just get an electric guitar
and take some time and learn how to play.

Oh, wait, that's a song by the Byrds. But the strategy is the same. Get some information and tools and learn how to use them. No need to sell your soul to the company.

The items I've listed below are sufficient to get you started on a career as an embedded systems developer. There are of course many additional resources out there. But these will arm you with enough knowledge to begin.

I own or have watched every resource and piece of hardware listed on this page. I've either gone through them entirely, or am in the process of doing so. I can vouch for their usefulness in getting you up to speed. It's a firehose of learning.

My personal learning method is to bounce around between multiple books and videos in progress, while spending time hands-on with the hardware. This is similar to a college student juggling multiple classes with labs (without tests, term papers, or due dates!).

Your method may be different. Feel free to approach things in a different order. I offer this in the spirit of sodoto.

What's An Embedded System?

It's a computer that's embedded inside another product, like a car, a microwave, a robot, an aircraft, or a giant industrial machine in a factory; or an IoT device like an Amazon Echo, a Sonos speaker, or a SimpliSafe home security system. You think of the thing as the end product, not as a computer. The computer happens to be one of the things inside that makes it work.

The fascinating thing about embedded systems is that you get to have your hands in the guts of things. The code you write makes a physical object interact with the real world. It's a direct control feedback loop. Working on them is incredibly seductive.

Embedded systems are a multi-disciplinary endeavor. At a minimum they require a mix of electronics and software knowledge. Depending on the particular application (the end product you're building), they may also require some combination of mechanical, materials science, physics, chemical, biological, medical, or advanced mathematical knowledge.

Hobbyist vs. Professional Hardware

There's a wide range of hardware available to learn on, at very reasonable prices. Most of the microcontrollers and boards were originally aimed at the professional community, but advances in technology and falling prices have made them accessible to the hobbyist and educational communities.

Meanwhile, those same advances have enabled hardware aimed directly at the hobbyist and educational communities. Some of that hardware has advanced to the point that it is used in the professional community. So the lines have been blurred.

All of the boards covered here have a variety of hardware interfaces and connectors that allow you to connect up other hardware devices. These are the various sensors, indicators, and actuators that allow an embedded system to interact with the real world.

Two hobbyist/educational platforms are Arduino and Raspberry Pi. For a beginner, these offer a great way to start out. There's an enormous amount of information available on using them from the hobbyist, educational, and maker communities.

I've listed a few books on them below in the Primary Resources, and there are a great many more, as well as free videos and websites. These books tend to be written at a more beginner level than books aimed at professionals.

Arduino is a bare-metal platform, meaning it doesn't run an operating system. An IDE (Integrated Development Environment) is available for free, for writing and running programs on it. You program it with the C and C++ programming languages.

Many of the low-level details are taken care of for you. That's both the strength and the weakness of Arduino.

It's a strength because it offers a quick streamlined path to getting something running. That makes it a great platform for exploring new concepts and new hardware.

It's a weakness because it isolates you too much from the critical low-level details that you need to understand in order to progress beyond the level of beginner.

Those low-level details are the difference between success in the real world and dangerous mediocrity. Dangerous as in you can actually get people killed, so if you want to do this professionally, you need to understand the responsibility you're taking on.

My attitude is to take advantage of that streamlined path whenever needed, and use it to boost yourself into the more demanding work. There are always going to be new pieces of hardware to hook up to an Arduino. I'll always start out at the beginner level learning about them.

In that context, Arduino makes a great prototyping and experimentation platform, without having to worry so much about the low-level details. Then, every bit of knowledge I pick up that way can be carried over to more complex platforms. Meanwhile, Arduino is a perfectly capable platform in its own right.

Raspberry Pi is a Linux platform, meaning it is a single-board computer running the Linux operating system. In some ways it is similar to Arduino, in that many low-level details are taken care of for you.

But it is more capable due to more hardware interfaces and the Linux environment. It can operate as a full desktop computer in the palm of your hand. You program it with the Python, C, and C++ programming languages, as well as others. The Linux capability opens up lots of possibilities.

Many of the same arguments for and against Arduino apply to Raspberry Pi. It also offers a great way to learn Linux and its application to embedded systems. It can be used at the beginner level, but also offers greater range to go beyond that.

Professional hardware, aimed at commercial and industrial use, offers the classic embedded systems development experience. This is where you need to be able to dig down to the low levels. These platforms run both bare-metal and with operating systems.

The operating systems tend to be specialized, especially when the application requires true hard real-time behavior, but also include embedded Linux.

Hard real-time means the system must respond to real-world stimulus on short, fixed deadlines, reliably, every time, or the system fails. For instance, an aircraft flight control system that must respond to a sensor input within 100ms, or the plane crashes. Or a chemical plant process control system that must respond to a sensor within 100ms, or the plant blows up and spews a cloud of toxic chemicals over the neighboring city. Or a rocket nozzle control system that must respond to guidance computer input within 50ms or it goes off course and has to be destroyed, obliterating $800 million worth of satellite and launch vehicle.

Those are what system failure can mean, showing the responsibilities. There are hard real-time systems with less severe consequences of failure, as well as soft real-time systems with looser deadlines and allowable failure cases (such as a smart speaker losing its input stream after 200ms and failing to play music), but it's important to keep in mind what can be at stake.

If your goal is to work professionally as an embedded systems developer, you need to be able to work with the professional hardware. But don't hesitate to use the hobbyist hardware to give you a leg up learning new things. The broad range of experience from working with all of them will give you great versatility and adaptability.

The Primary Resources

The items listed below are all excellent resources that provide the minimum required knowledge for a beginner, progressing up to more advanced levels. If you already have some knowledge and experience, they'll fill in the gaps.

These are well-written, very practical guides. There's some overlap and duplication among them, but each author has a different perspective and presentation, helping to build a more complete picture.

They also have links and recommendations for further study. Once you've gone through them, you'll have the background knowledge to tackle more advanced resources.

The most important thing you can do is to practice the things covered. This material requires hands-on work to really get it down, understand it, and be able to put it to use, especially if you're using it to get a job.

Whether you practice as you read along or read through a whole book first, invest the time and effort to actually do what it says. That's how you build the skills and experience that will help you in the real world.

Expect to spend a few days to a few weeks on each of these resources, plus a few months additional. While they're mostly introductory, some assume more background knowledge than others, such as information on binary and hexadecimal numbers. You can find additional information on these topics online by searching on some of the keywords.

Some of the material can be very dense at first, so don't be afraid to go through it more than once. Also, coming back to something after having gone through other things helps break through difficulties.

Looking at this list, it may seem like a lot. Indeed, it is an investment in time and money, some items more than others. But if you think of each one as roughly equivalent to half a semester of a college course once you put in the time to practice the material, this adds up to about two years worth of focused college education.

That's on par with an Associate degree, or half of a Bachelor's degree. And it will leave you with practical skills that you can put to use on a real job.

These are in a roughly recommended order, but you can go through the software and electronics materials in parallel. You might also find it useful to jump around between different sections of different books based on your knowledge level at the time. Note that inexpensive hardware is listed in the next part of this post, including some of the boards these use.

If you find some of the material too difficult, never fear, back off to the beginner resources. If you find some too simple, never fear, it gets deep. Eventually, it all starts to coalesce, like a star forming deep in space, until it ignites and burns brightly in your mind.

The resources:
You can learn Arduino in 15 minutes.: This is a nice short video that talks about the basics of Arduino microcontroller systems. It helps to start breaking down the terminology and show some of the things involved. That makes it a good introduction to more involved topics. You can also dive down the rabbit hole of endless videos on Arduino, microcontrollers, and electronics from here. This guy's channel alone offers lots of good information.
Hacking Electronics: Learning Electronics with Arduino and Raspberry Pi, 2nd Edition, 2017, by Simon Monk. This is a great beginner-level hands-on book that covers just enough of a wide range of hardware and software topics to allow you to get things up and running, starting from zero knowledge.
Programming the Raspberry Pi: Getting Started with Python, 2nd Edition, 2016, by Simon Monk. This is a nice practical guide to Python on the Raspberry Pi, with much more detail on programming than his Hacking Electronics above. Meanwhile it has less beginner information on hardware. So the two books complement each other nicely.
Programming Arduino: Getting Started with Sketches, 2nd Edition, 2016, by Simon Monk. Similar to his book on Python, but for C on Arduino, also a nice complement to his Hacking Electronics.
Embedded Software Engineering 101: This is a fantastic blog series by Christopher Svec, Senior Principal Software Engineer at iRobot. What I really like about it is that he goes through things at very fine beginner steps, including a spectacular introduction to microcontroller assembly language.
Modern Embedded Systems Programming: This is a breathtakingly spectacular series of short videos by Miro Samek that take you from the ground up programming embedded systems. They're fast paced, covering lots of material at once, including the C programming language, but he does a great job of breaking things down. He uses an inexpensive microcontroller evaluation kit (see hardware below) and the free size-limited evaluation version of the IAR development software suite. He also has a page of additional resource notes. What I really like about this is that in addition to covering a comprehensive set of information with many subtle details, he shows exactly how the C code translates to data and assembly instructions in microcontroller memory and registers. In contrast to Arduino, this is all the low-level details. You will know how things work under the hood after this course (currently 27 videos). Along the way you'll pick up all kinds of practical design, coding, and debugging skills that would normally take years to acquire. Did I mention this course is freakin' awesome?
RoboGrok: This is an amazing complete online 2-semester college robotics video course by Angela Sodemann at Arizona State University, available to the public. Start with the preliminaries page. In addition to some of the basics of embedded systems, it covers kinematics and machine vision, doing hands-on motor and sensor control through a PSoC (Programmable System on a Chip) board. She sells a parts kit, listed below. This is a great example of applied embedded systems.
C Programming Language, 2nd Edition, 1988, by Brian W. Kernighan and Dennis M. Ritchie: C is the primary language used for embedded systems software, though C++ is starting to become common. This is the seminal book on C, extremely well-written, that influenced a generation of programming style and other programming books. The resources listed above all include some basics of C, and this will complete the coverage.
Embedded C Coding Standard, 2018 (BARR-C:2018), by Michael Barr: This will put you on the right track to writing clean, readable, maintainable code with fewer bugs. It's a free downloadable PDF, which you can also order as an inexpensive paperback. Coding standards are an important part of being a disciplined developer. When you see ugly, hard to read code, you'll appreciate this.
Programming Embedded Systems: in C and C++, 1999, by Michael Barr: Even though this is now 20 years old, it's a great technical introduction and remains very relevant. Similar in many respects to Samek's video series, it takes a beginner through the process of familiarizing yourself with the processor and its peripherals, and introduces embedded operating system concepts. There is a later edition available, but this one is available used at reasonable prices. 
Programming Arduino Next Steps: Going Further with Sketches, 2nd Edition, 2019, by Simon Monk. This goes deeper into Arduino, covering more advanced programming and interfacing topics. It also includes information on the wide array of third-party non-Arduino boards that you can program with the IDE. This starts to get past the argument that Arduino is just for beginners doing little toy projects.
Making Embedded Systems: Design Patterns for Great Software, 2011, by Elecia White. This is an excellent book on the software for small embedded systems that don't use operating systems (known as bare-metal, hard-loop, or superloop systems), introducing a broad range of topics essential to all types of embedded systems. And yes, the topic of design patterns is applicable to embedded systems in C. It's not just for non-embedded systems in object-oriented languages. The details of implementation are just different. 
Exploring Raspberry Pi: Interfacing to the Real World with Embedded Linux, 2016, by Derek Molloy. This goes into significantly more depth on the Raspberry Pi and embedded Linux. It's quite extensive, so is best approached by dividing it into beginner, intermediate, and advanced topics, based on your knowledge level at the moment. Spread out your reading accordingly. It has great information on hardware as well as software, including many details of the Linux environment. Two particularly fascinating areas are using other microcontrollers such as Arduino as slave real-time controllers, and creating Linux Kernel Modules (LKMs).
Make: Electronics: Learning Through Discovery, 2nd Edition, 2015, by Charles Platt. This is hands down the best book on introductory electronics I've ever seen. Platt focuses primarily on other components rather than microcontrollers, covering what all those other random parts on a board do. See Review: Make: Electronics and Make:More Electronics for more information on this and the next book, and Learning About Electronics And Microcontrollers for additional resources.
Make: More Electronics: Journey Deep Into the World of Logic Chips, Amplifiers, Sensors, and Randomicity, 2014, by Charles Platt. More components that appear in embedded systems.
Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems, 2006, David J. Agans. By now you've found many ways to get into trouble with code and hardware. This is a fantastic book for learning how to get out of trouble. It's a simple read that outlines a set of very practical rules that are universally applicable to many situations, then elaborates on them with real-life examples. 
Real-Time Concepts for Embedded Systems, 2003, by Qing Li and Caroline Yao. This is an introduction to the general concurrency control mechanisms in embedded operating systems (and larger-scale systems).
Reusable Firmware Development: A Practical Approach to APIs, HALs, and Drivers, 2017, by Jacob Beningo. This covers how to write well-structured low-level device driver code in a way that you can use on multiple projects. Embedded systems are notorious for having non-reusable low-level code, written in a way that's very specific to a specific hardware design, which can often ripple up to higher levels. That means you have to rewrite everything every time for every project. Good Hardware Abstraction Layers (HALs) and Application Programming Interfaces (APIs) provide a disciplined, coherent approach that allows you to reuse code across projects, saving you enormous amounts of time in development and testing. This also helps you become a better designer, because it encourages you to think in a modular way, starting to think in terms of broader architecture in a strategic manner, not just how to deal with the immediate problem at hand in a tactical manner.
Embedded Systems Architecture, 2018, by Daniele Lacamera. This is a very up-to-date book that uses the popular ARM Cortex-M microcontroller family as its reference platform. That makes it a great complement to Samek's video series, since the TI TIVA C that he uses is an ARM Cortex-M processor. This also goes into more detail on areas  such as the toolchain (including debugging with OpenOCD), bootloading, and memory management. It briefly uses the ST STM32F746 Discovery board as an example.
Embedded Systems Fundamentals with Arm Cortex-M based Microcontrollers: A Practical Approach, 2017, by Alexander G. Dean. As the name indicates, this is another detailed book on ARM Cortex-M, intended as a college-level textbook. Among other good practical details, it includes a nice chapter on analog interfacing. It uses the inexpensive NXP FRDM-KL25Z development board for hands-on examples.
TI Tiva ARM Programming For Embedded Systems: Programming ARM Cortex-M4 TM4C123G with C, 2016, by Muhammad Ali Mazidi, Shujen Chen, Sarmad Naimi, and Sepehr Naimi. This is a detailed book that uses the exact same Tiva C board as Samek's video series. 
Designing Embedded Hardware: Create New Computers and Devices, 2nd Edition, 2005, by John Catsoulis. This covers the hardware side of things, an excellent complement to White's book. It provides the microcontroller information to complement Platt's books.
Test Driven Development for Embedded C, 2011, by James Grenning. This is a spectacular book on designing and writing high quality code for embedded systems. See Review: Test Driven Development for Embedded C, James W. Grenning for full details. Just as White's book applies concepts from the OO world to embedded systems, Grenning applies Robert C. Martin's "Clean Code" concepts that are typically associated with OO to embedded systems. We'll all be better off for it.
Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better, 2013, by Jeff Langr. This is an equally spectacular book on software development. It reinforces and goes into additional detail on the topics covered in Grenning's book, so the two complement each other well. Even if you don't know C++, it's generally easy enough to follow and the material still applies.
Taming Embedded C (part 1), 2016, by Joe Drzewiecki. This YouTube video is part of the Microchip MASTERs conference series. It covers some of the things that can be risky in embedded code and some methods for avoiding them. This gets into the characteristics that make embedded systems more challenging. I like to watch videos like this at 2X speed initially. Then I go back through sections at normal speed if I need to watch them more carefully.
Interrupt and Task Scheduling - No RTOS Required, 2016, by Chris Tucker. Another MASTERs video, this covers a critical set of topics for working in embedded systems.
Some Advanced Resources

Ready to dig in further and deeper?
MC/OS the Real-Time Kernel, 1992, by Jean Labrosse. Labrosse decided to write his own real-time operating system when he had trouble getting support for a commercial one he was using. The rest is history. You can hear some of that history in this podcast interview with him, "How Hard Could It Be?". This not only explains how things work under the hood, it gives you the source code.
MC/OS III, The Real-Time Kernel for the Texas Instruments Stellaris MCUs, 2010, by Jean Labrosse. This covers the 3rd generation of MC/OS, as well as details on the Stellaris microcontroller covered in Samek's video series. You can also download a free PDF version of this, as well as companion software. The MC/OS II and other books are also available there. The value in getting multiple versions is to see how the software evolved over time.
Software Engineering for Embedded Systems: Methods, Practical Techniques, and Applications, 2nd edition, 2019, edited by Robert Oshana and Mark Kraeling. This is a broad survey of topics by various authors (Labrosse wrote the chapter on real-time operating systems).
Some Hardware

The items listed below include some of the inexpensive boards and evaluation kits used in the resources above. There are a bazillion microcontroller boards out there that are useful for learning how to work on embedded systems. It's worth getting some from different vendors so you can learn their different microcontrollers, different capabilities, and different toolchains.

That also helps you appreciate the importance of abstracting low-level hardware differences in writing your code. Each vendor provides a range of support tools as part of the package.

Note that large vendor websites can be a pain, because they want you to create an account with profile, asking questions like your company name (call it "Independent"), what your application is, how many zillion parts you expect to order, when you expect to ship your product, etc. They're setup for industrial use, not hobbyist/individual use. They also may work through distributors like Mouser or Digi-Key for shipping and orders. Just roll with it!

The hardware:
Arduino Uno - R3, $22.95. This is the board used in the Arduino video listed above. There's also a wide array of "shields" available, external devices that connect directly to the board. Exploring these is one of the great educational values that Arduino offers. Remember that because Arduino takes care of many of the details for you, you can be up and learning about new devices faster. Then you can take that knowledge and apply it to other boards. You can also download the Arduino IDE there.
Raspberry Pi 3 - Model B+, $35. This is an updated version of the boards used in Simon Monk's books above. You will also need the 5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable, $7.50, and the 8GB Card With full PIXEL desktop NOOBS -  v2.8. You may also want the Mini HDMI to HDMI Cable - 5 Feet, $5.95, and the Ethernet Hub and USB Hub w/ Micro USB OTG Connector, $14.95. These are sufficient to connect it to a monitor, keyboard, and mouse, and use it as a desktop Linux computer.
Texas Instruments MSP430F5529 USB LaunchPad Evaluation Kit, $12.99 (16-bit microcontroller). An evaluation kit is a complete ready-to-use microcontroller board for general experimentation. Christopher Svec uses this kit in his blog series above, where he also covers using the free downloadable development software. If you buy directly from the TI site, register as an "Independent Designer".
Texas Instruments Stellaris LaunchPad Evaluation Kit, was $12.99 (32-bit microcontroller). This is the kit Miro Samek started out with in lesson 0 of his video series above. However, as he points out at the start of lesson 10, TI no longer sells it, and has replaced it with the Tiva C LaunchPad, which is an acceptable replacement (see next item below). 
You might be able to find the Stellaris offered by third-party suppliers. But you have to be careful that you're actually going to get that, and not the Tiva C kit, even though they list it as Stellaris. I now have two Tiva C boards because of that, one that I order directly from TI, and one that was shipped when I specifically ordered a Stellaris from another vendor.
Fortunately, that doesn't matter for this course, but it highlights one of the problems you run into with embedded systems, that vendors change their product lines and substitute products (sometimes it's just rebranding existing products with new names, which appears to be what TI did here). That can be confusing and annoying at the least, and panic-inducing at the worst, if something you did in your project absolutely depends on a hardware feature of the original product that's not available on the replacement.
One of the design lessons you should learn is to future-proof your projects and try to isolate hardware-specific features so that you can adapt to the newer product when necessary.
Texas Instruments Tiva C TM4C123G LaunchPad Evaluation Kit, $12.99 (32-bit microcontroller). This is TI's replacement for the Stellaris LaunchPad, that you can use with Miro Samek's video series. Samek addresses the replacement issue at the beginning of lesson 10. The good news is that he says the Tiva C is equivalent to the Stellaris (apparently all TI did was rename the product), so it's usable for the course. You'll notice that some parts of the toolchain (the software you use to develop the software for the board, in this case the IAR EWARM size-limited evaluation version) still refer to it as TI Stellaris. 
The specific TI device on the board is the TM4C123GH6PM, so when you set the EWARM Project->Options->General Options->Device, you can select TexasInstruments->TM4C->TexasInstruments TM4C123GH6PM, not theLM4F120H5QR that's on the Stellaris board. However, Samek shows that you can continue to use the toolchain configured for Stellaris.
That's one of those details that can be maddening when vendors swap parts around on you. Getting it wrong can produce subtle problems, because some things may work fine (you selected a device variant very similar to the one you need), but others won't. Welcome to the world of embedded development! Small details matter. The alphabet soup and sea of numbers in the product names can also drive you batty and be a source of mistakes. PAY CLOSE ATTENTION!
A related detail: the file lm4f120h5qr.h that Samek supplies in his projects for working with the Stellaris board's processor also works with the Tiva C board's processor. However, there is also a TM4C123GH6PM.h file for the Tiva processor. Both files are in the directory C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\inc\TexasInstruments (or whichever version of EWARM you have).
You can copy them to your project directory, or have the compiler use that directory as an additional include directory by selecting Project->Options->C/C++ Compiler and clicking the ... button next to the "Additional include directories:" box.
STMicroelectronics STM32F746 Discovery Board, $54 (ARM Cortex-M7 microcontroller). This is used briefly in Daniele Lacamera's book above. It's relatively expensive compared to the other evaluation kits here, but includes a 4.3" LCD capacitive touch screen and other hardware elements, making it a much more capable platform, and still an outstanding value.
NXP Semiconductor FRDM-KL25Z Freedom Development Board, $15 (ARM Cortex-M0+ microcontroller). This is the board that Alexander Dean uses in his book above.
uC32: Arduino-programmable PIC32 Microcontroller Board, $34 (Microchip PIC32 32-bit processor). This isn't covered specifically by any of the resources above, but the PIC32 microcontroller is a popular family that offers a different hardware environment. This is programmable using the Arduino IDE, and can also be programmed using Microchip's MPLAB IDE.
Adafruit Parts Pal, $19.95. This is a small general parts kit for working with the various boards above. It includes LEDs, switches, resistors, capacitors, simple sensors, a small breadboard, and jumper wires for interconnecting things, plus a few other interesting items.
RoboGrok parts kit, $395. This is the parts kit for Angela Sodemann's course above. While you can gather the parts yourself for less, she saves you all the work of doing that, and buying her kit is a nice way of compensating her. 
Extech EX330 Autoranging Mini Multimeter, $58. There are also a bazillion multimeters out there. This is one reasonable mid-range model. The multimeter is a vital tool for checking things on boards.
One of the following logic analyzers. A logic analyzer is an incredibly valuable tool that allows you to see complex signals in action on a board. They used to cost thousands of dollars and need a cart to roll them around. These are miraculously miniaturized versions that fit in your pocket, at a price that makes them a practical, must-have personal tool. They plug into your USB port and are controlled via free downloadable software you run on your computer:
Saleae Logic 8 Logic Analyzer, 8 D/A Inputs, 100 MS/s, $199 with awesome "enthusiast/student" discount of $200, using a discount code that you can request and apply to your cart when checking out, thanks guys! This is also covered briefly in Svec's blog series. You can play with the software in simulation mode if you don't have an analyzer yet.
Digilent Analog Discovery 2, 100MS/s USB Oscilloscope, Logic Analyzer and Variable Power Supply, Pro Bundle, $299. As amazing as the Saleae is, this one adds oscilloscope, power supply, and signal generator functions, combining a number of pieces of equipment into one tiny package. They also have academic discounts for those who qualify (36% discount on the base unit).
For a full shopping list to equip a personal electronics lab, see the Shopping List heading at Limor Fried Is My New Hero. That page also has many links to resources on how to use the tools.

Glossaries

It can be a bit maddening as you learn the vocabulary, with lots of terms, jargon, and acronyms being thrown around as if you completely understood them. As you get through the resources, the accumulation of knowledge starts to clarify things. Sometimes you'll need to go back and reread something once you get a little more information.
Other Links

These sites have articles and links useful for beginners through advanced developers.
Final Thought

Our society is becoming more and more dependent on embedded systems and the various backend and support systems they interact with. It's our responsibility as developers to build security in to make sure that we're not creating a house of cards ready to collapse at any moment. Because people's lives can depend on it.

If you think I'm overstating that, see Bruce Schneier's new book. We are the ones on the front lines.

Saturday, April 14, 2018

First Use Of New Tools


Using my new tools to fix my Droid MAXX, lying open front and center.

Sometimes life just amazes me. Three days after receiving my Adafruit tools, I needed them. Twice.

This isn't the first time that I've learned something completely new out of the blue, and almost immediately needed it. It's just incredibly serendipitous.

First Problem

Yesterday, Friday, I worked from home. The project I'm working on is embedded system firmware to control a daughter board. The main smart chip on the board was shutting down unexpectedly, which I could tell initially from the timeouts reading responses from it, and then from its status output LED going off.

There's a power enable line for the chip in the cable pigtail that I control via software, and scouring through my code assured me that no code path should be shutting it off during the scenario I was exercising.

Yet the LED was going off and the chip was unresponsive. Maybe it was a bug in the chip, and my commands to it were triggering the shutdown.

Or maybe something besides my code was affecting the power enable. So I pulled out my new meter, opened up the cable to the daughter card, and clipped the meter into the ground and enable lines, switched to VDC.

With the code in the state where power was enabled, the LED was on, the chip was responsive, and the meter showed 3.2V. With the code in the state where power was disabled, the LED was off, the chip was unresponsive, and the meter showed 0.0V. Ok, good, correct setup.

Running my tests, with additional debug logging verifying the code was NOT running through the parts that shutoff power, I saw the LED go off and the meter drop from 3.2 to 0. So something unrelated was indeed dropping the power enable.

After more testing, I noticed a pattern in the logging, unrelated to my code, that correlated with the shutoff. Now, correlation does not imply causation. But it's a hint about where to look.

So running a couple more debug commands that didn't exercise my code path at all, I was able to confirm that the correlated activity did indeed result in disabling power to the chip.

Yes! Phew, it's not the chip crashing on me, and it's not a problem in the code I just wrote.

Monday, I'll get together with the hardware guys and chase the problem down. First, I'll try it with another unit.

For all I know, my unit is damaged, since it's all pulled apart on my desk to connect the daughter board. Open frame hardware is always vulnerable.

That's an example of diagnosing a problem and ruling out two large potential root cause areas.
Monday update: Another unit showed the same problem. So it wasn't damage in my unit. 
I discussed the evidence in the logging with the hardware engineer. We identified some register accesses used to control GPIO (General Purpose Input/Output) pins on the processor that were affecting more pins than intended. These were causing the GPIO pin controlling the power enable to be cleared.
This shows one of the challenges inherent in embedded systems. You're working at a much lower, more direct level in the hardware, with lots of opportunities to create strange conflicts between different parts of the system. 
Second Problem

Today, Saturday, I was down in the basement, and as I put my phone in my pocket, it slipped and fell flat on its face on the concrete floor with a sharp thud. DOHH!

It's a Droid Maxx in a case that goes in a holster. The case protected the screen and phone from overall damage, but the power had shut off (yeah, another power problem). I held the power button in, but it wouldn't power on, even after several attempts.

I plugged the charger cord in. The display came on, showing 0% power. It tried to boot, then quickly shutoff. It just repeated this cycle continuously. So there was some level of system function, but no power.

The shock of impact had apparently knocked something loose inside, which I figured was most probably the battery connection. Dead phone. Stupid reason. Words were said.

And this is a sealed phone, not a removable battery like older models. More words were said.

I emailed my wife who was visiting some friends that my phone was dead. Ugh. I look forward to going to the cell phone store the way I look forward to going to a used car lot (although I'm being unfair, my last several experiences with them have been excellent).

But Internet to the rescue, I Googled "access battery in droid maxx" and found a page showing how to do it, plus someone in the comments had pointed to a YouTube video they liked better.

I read the page and watched the video. Yep, I can do that. Worst case, the phone is already dead, I can't make it any worse.

Since I didn't have a spudger or plastic pry tool as shown in the tutorials, I improvised one from a piece of 1/8" thick padauk, which is a very hard tropical wood. I split off a strip about 1/2" wide and beveled the end of it with a block plane.

Between that and a small flat screwdriver, I was able to get the case open. The metal driver tip did break a couple bits of plastic off the edge of the back, but no major damage.

This also shows why I ordered multiple tool sets (I've added an iFixit set to the shopping list on my Adafruit post, because it has pry tools). I used the smallest flat screwdriver from one set for lifting tabs, the T5 from another set to remove most of the screws, and the even tinier flat tip from a third set to get into the points of a T4 screw.

I used the compartments in the base of my Panavise to hold all the loose parts.

With all the screws removed, I separated the board from the display, and sure enough, I could see immediately that the tiny connector on the flat battery cable was loose on the back of the board. This wasn't the first time I had dropped it, so it probably loosened up progressively. Everything inside the phone is secured in place pretty tightly.

I pressed on it and it clicked positively into place. I pulled it back off to look at it, then clicked it back in. So I was confident that it was secure.

As I was handling the phone with everything folded together loosely, I accidentally held the power button in. I noticed the display come on, so I let it continue. It booted up (SIM removed), so power appeared to be restored.

I shut it down and reassembled the phone. The tweezers were a big help dropping the tiny screws back into their holes.

Popped the case back together, reinserted the SIM, and held the power button in. Voila! It powered on, connected to the network, and I was back in business, with a couple of quick tests to verify that things were working right and it was staying on. I texted my wife that I had fixed it.

That's an example of digging in and not being afraid to play around and see what's going on. It's all a learning experience!

Sunday, April 8, 2018

Limor Fried Is My New Hero

 
Meet Limor Fried, founder of Adafruit.

I'm cross-posting this to both my woodworking blog www.CloseGrain.com and my software engineering blog FlinkAndBlink.blogspot.com (under the LearnToCode label), because even though there's no woodworking in it, this is all about building stuff, so it bridges the worlds. It's the maker ethos.

If you're interested in learning to code, and actually building the stuff that you're coding on, this is for you. This is all about working on embedded systems, from the hobby level to the professional.

In Which I Find Out About Limor Fried

Allow me a moment of self-indulgent gushing admiration here. Or you can skip down to the real information that starts at the Electronics Learning Resources heading.

I admit to instant and total nerd-crush. Limor Fried, who goes by the name Ladyada online (for Lady Ada Lovelace, The First Programmer) is the founder of Adafruit.

Adafruit is a small electronics manufacturing company in Manhattan, NY, that focuses on teaching electronics to makers of all ages. You can read about them here.

Electronics is another of those hobbies that I wanted to pursue as a teenager, but never could due to lack of funds. Fortunately I've advanced beyond that impecunious stage of life, and seeing this has fired instant obsession (hence the shopping list below!).

I'm familiar with that feeling of obsession settling on my shoulders. It propelled me into hand tool woodworking, turning into a book. It propelled me into violinmaking. It propelled me into boatbuilding.

Each time, the pattern is the same. I buy a bunch of books, watch a bunch of videos, dig through a bunch of blogs and forums, then buy a bunch of tools and start playing. Last year it propelled me into small engine repair and oxy-acetylene welding after I found Taryl Dactyl (yes, blog posts will be forthcoming).

Now, in my copious free time (that's a joke, son), I'll finally be realizing that dream to get my hands dirty with electronics.

I owe this to Matt Pandina, whom we recently hired at work. It quickly turned out that Matt is a maker and likes sharing information. He has some nice stuff on Google Groups under the moniker artcfox (in fact, one of his articles was coincidentally the answer to the embedded systems programming problem I use when interviewing candidates!).

He made a comment about how Adafruit is doing manufacturing in Manhattan, and I asked, "Who's Adafruit?". That was all it took. Thanks, Matt!

I was tickled to read Fried's favorite quote in the Entrepreneur Magazine article about her:
“We are what we celebrate.” —entrepreneur and inventor Dean Kamen.
Kamen is one of my other heroes. She whose hero is my hero is my hero!

I managed to score his autograph at the 2015 MassMEDIC conference. I was at the 2015 Embedded Systems Conference (ESC Boston), which was being held concurrently at the Boston Convention Center.


When I saw Kamen listed as keynote speaker, I scooted down early and got a chance to talk to him and tell him I wanted to work for him (he probably gets a lot of stalker geeks like that!). Came close the following year, but logistics didn't work out.

Electronics Learning Resources

On the business side, Adafruit sells kits, parts, tools, and books. That's pretty cool (along with being able to pull off a manufacturing operation in Manhattan). But what's truly spectacular about them is their online learning resources.

Fried is a big proponent of open source, sharing the knowledge. So the Adafruit website is chock full of information. There's also an extensive YouTube channel.

You'll also finds lots of cross-pollination with others in the maker community. There are magazines, blogs, and videos by the score, by independent makers like Matt, and by larger organizations.

I've just barely begun to scratch the surface. This is great, because I know how to program embedded systems, but I don't know much about the components that go into them and connect to them. It's the combination of hardware and software that really makes something work.

Pretty much everything I know about digital electronics I owe to Forrest M. Mims and George Young 35 years ago. Now, after that brief hiatus, I can take the next step.

Basic Electronics Lab Skills


Step into Collin's lab!

Among the resources is a series of very accessible quick guides and videos by Collin Cunningham. Of particular interest to the electronics beginner such as myself is this set of basic electronics lab skills (you can scan through all these for quick grok of the big picture by setting the speed in the YouTube window settings (the gear icon) to 2x, then come back and watch at normal speed for a second pass):
  • Soldering and Desoldering: how to solder components together properly, and how to pull them apart for salvage and rework.
  • Surface Mount Soldering: how to solder surface-mount components.
  • Multimeters: how to use a meter for basic measurements.
  • Oscilloscopes: how to use an oscilloscope for advanced measurements and waveforms.
  • Hand Tools: the basic hand tools used for assembling and disassembling electronics.
  • Schematics: how to read schematics (no, they're not Greek!).
  • Breadboards and Perfboards: how to combine the parts on a schematic into a functioning circuit.
  • Ohm's Law: understanding the relationship between voltage, current, and resistance.
Once you have these skills, you are unleashed. Just like hand tool woodworking, it takes a little investment in tools and equipment, and a little time practicing with them.

These form the basis of the shopping list below. And of course they lead to lots of other interesting videos, like Collin's videos on the basics of various components:
There are also a number of other introductory Adafruit written guides by various contributors (as well as oceans of more specialized and advanced guides, check them out!):
Shopping List

These are the tools, equipment, supplies, and books to do the work. With the exception of the oscilloscope and logic analyzer, these are all links to the Adafruit shopping pages. Prices as of April 8, 2018.

Tools and equipment:
Consumable supplies:
Books:
Finally, here are some additional random useful items that they don't carry, all via Amazon:
Total cost: $1567 for everything (I ordered 2 spools leaded solder and 1 leaded Chip Quik, no lead-free items, 10 DC barrel jacks, and all the screwdriver/tool sets, since you never know which tips and shanks will fit, and some cases need special access tools to open), with free shipping from both Adafruit and Amazon, $10 for Saleae. Plus Adafruit threw in a free half-size breadboard and a Circuit Playground Express.

Back in my teenage days, $10 was a major expenditure, and $100 was simply inconcievable. This is starting to add up to some real money, but it will leave you armed with the tools, knowledge, and skills sufficient to launch a career.

The really nice thing is that Adafruit provides a curated list of things to choose from, so you're getting the benefit of their experience and recommendations, all guided by that maker ethos. That was a big plus for me.


Bridging three centuries of maker technology in my workshop.

You can read about my first use of these tools, since I needed them almost immediately.

For a review of the outstanding Charles Platt books listed above, see Review: Make: Electronics and Make:More Electronics.

For a useful set of resources to help you learn electronics, see Learning About Electronics And Microcontrollers.