Electronic – How does program execution happen in firmware

asiccpufirmware

I have heard from people working in firmware domain, that there is no Operating system controlling firmware (eg firmware in a USB drive). There is just a single thread running in a while loop waiting for an external command, and this is the start point for an interrupt to happen, followed by a ISR and the control flowing all the way till the hardware. But fundamentally what is that part of hardware that is executing the firmware code ? Is there a CPU or is it ASIC based code which is triggered as long the device is powered. I fail to understand the paradigm shift from a regular CPU-OS based system to a firmware.

Best Answer

There is no paradigm shift; in both cases a CPU is executing the software/firmware.

Firmware and software are the same thing; the only distinction is in how it's stored. Software is typically stored on a mass-storage device (e.g., disk drive) and loaded into volatile memory (e.g., DRAM) before being executed. It's easy to change software, by simply replacing the file containing it with a different one.

Firmware is typically stored in nonvolatile memory (e.g., FLASH) connected more-or-less directly to the CPU. It's harder to modify (hence the "firm") and it may or may not be transferred to a different memory for execution.

Really, the operation of a computer with an "operating system" is fundamentally no different from your description of firmware. Remember, the OS itself is just another piece of software — or more likely, a huge collection of mutually-dependent pieces of software. At the lowest level, the CPU is still sitting in a loop of some sort, waiting for things to do. It's just that that loop is buried inside the OS.