When would you use bare-metal firmware versus an RTOS?
What the interviewer wants to hear
- Bare-metal: super loop with interrupts, simple and small
- RTOS: tasks, priorities, scheduling, synchronisation
- RTOS helps with many concurrent activities and timing needs
- Costs: RAM, complexity, learning curve
- Connectivity stacks often need an RTOS
Model answer
Bare-metal firmware usually means a super loop in main that checks flags and calls functions, plus interrupts for time-critical events. It is small, easy to understand and has no extra overhead, so I use it for simple devices like a temperature controller or a remote with a few inputs. An RTOS like FreeRTOS or Zephyr adds tasks with priorities, a preemptive scheduler, queues, semaphores and timers. It becomes worth it when the device does many things at once with different timing needs, such as reading sensors, running a BLE or Wi-Fi stack, updating a display and logging, because each activity can be a separate task and a high-priority task always responds on time. The costs are extra RAM for stacks, more complexity, and new bug types like deadlocks and priority inversion. Many vendor connectivity stacks already require an RTOS, which often makes the decision for you.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Embedded Systems Engineer questions
- What is the difference between a microcontroller and a microprocessor?
- What is an interrupt, and how is it different from polling?
- Compare UART, SPI and I2C. When would you use each?
- Explain volatile and const in embedded C. Can a variable be both?
- What GPIO modes does a typical microcontroller pin support, and when would you use each?
- What is PWM, how is it generated on a microcontroller, and what is it used for?
- What is a bootloader in an embedded device, and why would a product need one?
- What is endianness, and how do you deal with it when exchanging data between devices?
- How do you approach reading a datasheet for a new sensor or microcontroller?