1
\$\begingroup\$

Conceptually, I understand a microcontroller to be a very limited computer that can only run "one process". A microcontroller is what one would use when they want to interface with other electronics with strict timing requirements. This is because it lacks the timing overhead of an operating system scheduling tasks and it lacks the space overhead of all the libraries and utilities one gets with an operating system.

I understand the differences between a computer and a microcontroller, but I also know one can write an operating-system for a microcontroller.

But what about the other way around? Rather than loading an operating system on a Rasbperry Pi (or other computer), why can't I use it as a very powerful microcontroller? Is there anything stopping me other than a lack of library support?

My questions, specifically, are these:

  1. Is there a semantic difference between a microcontroller and a SBC? Or am I correct that they exist on a "spectrum" of hardware specs?
  2. Can one use a Raspberry Pi as a microcontroller (i.e. without an operating system?)

(I specify Raspberry Pi because it is very well supported and known in the SBC space. Tangentially, if yes to question part 2, I am curious if there is already library support here.)

\$\endgroup\$
12
  • 8
    \$\begingroup\$ Just do it, then ask here with any specific problems you encounter ;) \$\endgroup\$ Aug 18 at 18:53
  • 1
    \$\begingroup\$ intel.com/content/www/us/en/programmable/documentation/… \$\endgroup\$ Aug 18 at 19:01
  • 1
    \$\begingroup\$ @ AndrewMorton: But I don't know if it is even possible. I've only written assembly for a nice, friendly interpreter, and I've never put it onto "real hardware". @ Abel @ DamienD Yes! I'm just wondering if my intuition is correct, that an SBC is just a big microcontroller, and that one could (with effort) use an SBC as a microcontroller. @ Chris Knudsen thank you! It seems "bare metal" was the word I am looking for, and a quick search shows me others considering this "microcontroller behavior" \$\endgroup\$
    – lynn
    Aug 18 at 19:03
  • 1
    \$\begingroup\$ Ya, 'Bare Metal' is a term that makes sense only after one is familiar with the concept. ;-) \$\endgroup\$ Aug 18 at 19:16
  • 2
    \$\begingroup\$ A microcontroller is a chip. If you want to run baremetal on a RasPi you can (although some of the hardware is undocumented so good luck), but that doesn't make it a microcontroller. \$\endgroup\$
    – hobbs
    Aug 18 at 19:23
2
\$\begingroup\$

There are a couple of important considerations to think about.

First is cost. a microcontroller is a chip, and a Single Board Computer is a board. They have different price points, dictating that their use is in two different types of applications.

Next is peripherals, and what you need to use in your system. A microcontroller can do just about anything a SBC could do, but it means finding and using the libraries and making them work. If you're using many devices, you need to make sure none of them conflict with each other. At some point, you'll find yourself building an OS on a microcontroller, and that's just not a very effective use of time and resources.

Let's say I have an application where I will need a file system, support for a USB thumb drive, USB mastering for a joystick, a keyboard, and a VGA small VGA display. I could work to build all of this into a microcontroller, or I could run it on a SBC with an OS that supports all of this already. My programming would involve system calls instead of building everything from the ground up. The OS is going to handle all the necessary multitasking, and the USB stack. It would take a reasonable chunk of skill to build this on a microcontroller, but it would be a much more manageable project on a SBC.

Now, this does come with drawbacks. For example (leaving aside the lack of A/D on a RPi), if I'm trying to do hard real time, it's easier to use a timer interrupt to drive timing on a microcontroller in many cases than to try to make my task work nicely in an OS.

I guess long story short, as the complexity of your build is starting to look like a full computer, at some point it becomes more efficient to use a SBC.

As to whether you can use a RPi as a microcontroller, that can get tricky. The OS is sitting between your program and your peripherals, and that can get in the way. Sometimes, you might even be better off using a microprocessor in communication with a SBC. There are SBC's, like the BeagleBone Black, that have microcontrollers sharing memory with the main processor to make some tasks easier.

\$\endgroup\$
1
\$\begingroup\$

In theory, it's possible to run a simpler OS (or even a single thread) on a Raspberry Pi. The issue is that to exploit all the power that device has to offer, you will need libraries and drivers. This is much, much easier if you use a known OS that's been ported to it.

Here's one list of various OS ports - 20 to choose from: https://www.fossmint.com/operating-systems-for-raspberry-pi/

Another (21 to choose from): https://tutorials-raspberrypi.com/top-21-os-for-the-raspberry-pi-for-your-project-overview/

Some R-pi RTOSs to choose from: https://all3dp.com/2/rtos-raspberry-pi-real-time-os/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.