Embedded Systems Interview Questions
In this moderately long page, I’ll list down the most common embedded systems interview questions. I’ve been answering too many questions over the past few years and many readers have asked for a compiled list of questions and answers for embedded systems and embedded c interview questions. So here it is!
Whether you’re a student searching for an embedded systems internship, a graduate seeking an embedded software position, or a full-time embedded systems engineer seeking to switch your position or the company. In all cases, you’ll need to go through one or more technical interviews to get where you want.
Please, be advised that the interview questions depend heavily on the specialty of the company you’re going after (automotive, security, robotics, etc), the position you’re applying for (internship, testing, embedded software, tooling, etc), and also your CV. Yea, your CV somehow dictates some of the interview questions. For me personally, I was asked in (USB, CapTouch, etc) just because it’s all written in my CV, however, these topics are not mandatory at all for most embedded systems positions. So, only write in your CV what you can actually demonstrate and be ready to get questions about it.
Regardless of the position you’re seeking, the company specialty, or your previous experience, there are many general questions that you’ll most probably get. And this is what I’m going to mainly focus on this page. To help you quickly revise and get ready for your next embedded systems interview.
We can categorize these questions as follows.
Embedded Systems Interview Questions
- Embedded C: some questions about C programming, structs, typedef, pointers, the C build process, multi-file projects, memory sections, bootloader vs startup code, arrays, strings manipulations, and things like that.
- Computer Architecture: some questions about memory types, buses, 8-bit and 32-bit microcontrollers, Harvard vs von Neuman, ARM, instruction sets, Endianness, and other questions in this area.
- Microcontroller Peripherals: some questions about ADC, Timers, Interrupts, PWM, WDT, Com Protocols like UART, SPI, I2C, and others.
- Data Structures & Algorithms: some questions about basic data structures like the stack, queue, linked list, and implementation in C programming language. As well as some algorithms questions for sorting, searching, and things like that.
- RTOS & OS Concepts: some questions about real-time operating systems, FreeRTOS-based implementations, Mutex, Semaphores, DeadLock, Priority inversion and inheritance, and other OS concepts.
- Problem Solving & IQ: some questions for IQ assessment and to check how do you think while solving a problem and how well you can communicate this with the interviewer. You don’t have to actually solve all the problems as long as you can show logical thinking and communicate this in a good manner.
- Automotive: (optional in most cases) questions about CAN, LIN, Ethernet, AUTOSAR software architecture, etc.
- Embedded Software Testing: (optional in most cases) questions about Static testing, Dynamic testing, V-Model, etc.
- Embedded Hardware: some questions about general embedded hardware knowledge. Things like debuggers, JTAG, using DSO, logic analyzers, emulators, and troubleshooting.
Note: The questions on this page are answered in 3 different ways. Short answers are collapsable by clicking the question text you can view/hide the answer. Long answers are found on dedicated pages that redirect you back to here, after reading the answer with a couple of links there. And previously answered questions will be linked-to in such a way so that it opens up in a new tab without redirection. I hope it’s a convenient way of handling this. |
Note: You should expect more or less questions on certain topics depending on the 2 factors I’ve stated earlier. The company’s specialty and the position you’re applying for. You may not be asked about automotive protocols at all or barely get a question related to software testing unless you’re seeking certain positions. The same goes for RTOS and data structures and so. |
Embedded C Interview Questions
[expand title=”What’s The Startup Code?” trigclass=”arrowright”]
The Startup Code in embedded systems is used to set up data memory sections such as global data variables. It also zero initializes part of the data memory for variables that are uninitialized at load time. The startup code copies 5 from flash to variable y in the RAM as it’s an initialized global. And it also initialized the x variable with 0 value.
For applications that use dynamic memory allocation C functions like malloc, the C startup code also needs to initialize the data variables controlling the heap memory.
After this initialization, the C startup code branches to the beginning of the main program, and your application starts running. The C startup code is inserted by the compiler at the linker stage automatically and is toolchain specific.[/expand]
[expand title=”What’s The Bootloader?” trigclass=”arrowright”]
A Bootloader in embedded systems is a standalone application that gets developed, if needed, aside from the target application itself to provide the following functionalities. The bootloader is the first software that runs after board power up and it does hardware check, and initializations for the processor, peripherals, and the OS if used. Then it starts to run your main application.
The bootloader application can also be used to upgrade the firmware on the target microcontroller via serial communication ports like UART, SPI, I2C, USB. So, it does control the hardware peripherals to do this task. Then, it does release everything and initializes the peripherals to be used by your main application after the bootloader has done its work.[/expand]
Local, Static, Global variables in C
[expand title=”Global Vs Static Global In C” trigclass=”arrowright”]
A Global variable in C has a global scope across your whole project files. Not only the .c file in which this variable is declared. For any source code .c file to be able to use that variable it’ll only need to extern it and it has access to it.
However, on the other hand, if a global variable is declared to be static, it’ll be only global across the source code .c file it’s been declared into. No other files in the project can extern and access this variable.[/expand]
[expand title=”What’s a CallBack Function? Usage Examples?” trigclass=”arrowright”]
A Callback Function is a reference to executable code that is passed as an argument to other code that allows a lower-level software layer to call a function defined in a higher-level layer. A callback allows a driver or library developer to specify a behavior at a lower layer but leave the implementation definition to the application layer. Which makes the software easily reusable and more portable.
For example, if you’re developing a driver code for a Timer module and it has a function to do whenever an overflow interrupt is fired. The functionality doesn’t need to be fixed but it has to be defined by the application higher-level. So, you can use a call back function that points to nothing. And in the application code, the user will write the interrupt handler function’s code and set the timer call back to point to this handler routine. So, whenever an interrupt is fired, the ISR will call the call back function which points to the user handler code and it’ll get executed.
And yes, this means that you as a driver developer will have to provide the call back registering “setting” function that the user can use to set the call back function and make it point to the implementation in the higher-level software layer.[/expand]
[expand title=”What’s Void Pointer in C?” trigclass=”arrowright”]
A Void Pointer is a pointer that has no associated data type with it. A void pointer can hold the address of any type and can be type-casted to any type. This means you can use it to point to any variable type you want as shown in the code snippet below.
1 2 3 4 5 |
int x = 10; char y = 'B'; void* ptr = &x; // void pointer holds address of int 'x' variable ptr = &y; // void pointer holds address of char 'y' variable |
Dynamic memory allocation c functions like malloc and calloc return (void *) type and this allows these functions to be used to allocate memory of any data type, as you can type-cast it to fit your variable data type.
Void pointers in C are used to implement generic functions. And note that void pointers cannot be dereferenced. And C standards don’t allow pointer arithmetic with void pointers.[/expand]
Null, Void, Dangling, Wild Pointers in C
[expand title=”State All Memory Sections & Their Usage” trigclass=”arrowright”]
RAM Memory Sections: [ .stack – .heap – .data – .bss ]
- .stack: This memory section is used for local variables
- .heap: For dynamically allocated variables (not used in most embedded applications)
- .data: For global and static initialized variables
- .bss: For global and static uninitialized variables
Flash Memory (ROM) Sections: [ .sdata – .rodata – .text – .cstartup ]
- .sdata: For initialized globals, the startup code copies it to .data section at system start
- .rodata: For const variables (read-only)
- .text: The code of your application
- .cstartup: The startup code that initialized the system and branches to the main application
[/expand]
[expand title=”What’s A Segmentation Fault?” trigclass=”arrowright”]
A Segmentation Fault occurs when the system tries to access a memory location that is not allowed to be accessed or attempts to access a memory location in a way that is not allowed (i.e. attempting to write to a read-only location).
At the hardware level, the fault is initially raised by the memory management unit (MMU) on illegal access (if the referenced memory exists), as part of its memory protection feature.
At the operating system level, this fault is caught and a signal is passed on to the offending process, activating the process’s handler for that signal. Different operating systems have different signal names to indicate that a segmentation fault has occurred.
[/expand]
Startup Code Vs BootLoader
[expand title=”Explain The Usage of extern Keyword in Embedded C” trigclass=”arrowright”]
extern is a keyword in the C programming language that is being used to declare global variables and functions. The typical use case for the extern keyword is to get a global variable from another .c source file. We always use extern in header files only to bring in global variables and functions from other .c files.
All variables and functions in header files should be explicitly extern. Otherwise, you should make your global variables static to restrict access to those global variables and/or functions to everything within the same .c file but nothing outside. And if you want any function and/or global variable to be seen and accessed in other .c files outside their .c file, then you shouldn’t make them static and extern them in the header .h file.
[/expand]
What’s the use of the “Static” keyword in embedded C?
What’s the use of the “Volatile” keyword in embedded C?
When to use “volatile” variables in code?
What’s the difference between array and pointer in C?
Constant pointer Vs pointer to a constant
What are Macros in C? Pros and Cons?
What does it mean to have a static function?
What’s an inline function in C?
[expand title=”What’s A Reentrant Function in C?” trigclass=”arrowright”]
A Function or Routine is described as reentrant if it can be safely called again before its previous invocation has been completed (i.e it can be safely executed concurrently). This type of function is used in different cases like recursion, hardware interrupt handling (ISR). To be reentrant, a computer program or function:
- Must hold no static (or global) non-constant data.
- Must not return the address to static (or global) non-constant data.
- Must work only on the data provided to it by the caller.
- Must not rely on locks to singleton resources.
- Must not modify its own code (unless executing in its own unique thread storage)
- Must not call non-reentrant computer programs or routines.
[/expand]
What’s memory padding and alignment?
What’s the C Preprocessor’s Function?
Functions of #define, #if, #pragma
How to prevent multiple inclusion of header files? Why?
Explain The Embedded C Build Process (Detailed Steps)
What do you know about MISRA C rules?
Do you think we can write recursive code in embedded C? why yes or no?
Static vs Dynamic memory allocation in C
[expand title=”What’s Memory Fragmentation?” trigclass=”arrowright”]
Memory Fragmentation is an issue that arises when using dynamic memory allocation. If you keep allocating and releasing memory spaces over the time, you’ll end up having non-contiguous memory blocks that are actually free and your in-use variables are scattered everywhere in the RAM.
This is called memory fragmentation, and can potentially lead to dynamic memory allocation failure. If you’d like to allocate an array of 100 integers and there is no contiguous block of memory with that space. This causes a runtime error and it’s one of the strongest reasons why we don’t use dynamic memory allocation in embedded systems firmware in the first place.[/expand]
What’s dynamic memory allocation? And why it’s avoided in embedded C?
[expand title=”Can you include a .c File into another .c file?” trigclass=”arrowright”]
The short answer is yes, however you shouldn’t. It’s a very bad practice to do this, you should only include header files that have declarations and functions prototypes, not their implementation.
So, it depends on the contents of the .c file you’re willing to include as #include is a preprocessor directive that works as a text “code” replacement tool. Which copies the code inside a .c file into your target .c file. Now, it’s up to the compiler to look at the code and see if there is a C rule violation or not.
Another thing to note is an important issue that arises from this bad practice is that you perform the inclusion process with preprocessor text replacement in mind. However, there is another important stage in the compilation process which is the linker stage which will link the compiled .c object file .o with the file in which you included it maybe main.c which is main.o at linker stage.
Now, the linker will find duplicate implementations for certain functions if it’s the case and this will fire linker errors and stop the build process. Therefore, it’s another issue to care for and you’d better avoid this practice altogether in the first place.
[/expand]
How to set, clear, and toggle a single bit of a register in C?
Computer Architecture Questions
Discuss RISC vs CISC processors
What’s pipelining? How does it affect CPU performance?
What are the differences between Harvard & Von Neumann Architectures?
What are the differences between a Microcontroller & a Microprocessor?
What are the differences between RAM & ROM?
What are the differences between FLASH & EEPROM?
What is Endianness? Little and Big
What’s Bit Banging?
What’s Bit Banding?
Differences between 8-Bit and 32-Bit architectures?
What’s DMA? Give example applications for DMA
Microcontroller Peripherals Questions
Timers
Using a timer, measure the execution time of a C function
Using a timer, generate software PWM signal
Using a timer, measure a digital pulse width
Using a timer, measure a digital signal’s frequency
Write the equations and select the parameters to generate a 1ms timer interrupt
What’s the watchdog timer (WDT)? When and Why it’s used?
When should you kick the WDT?
Interrupts
What’s an ISR routine?
Can we send and return data from ISR?
Can we call other functions inside ISR?
Explain interrupt execution sequence
State the types of interrupts
Vectored VS Non-Vectored interrupts
Explain Interrupts late arrival – ARM
Explain Interrupts tail-chaining – ARM
What’s NVIC in ARM Cortex?
Explain interrupts nesting
What’s interrupt latency? What causes it?
How can you measure interrupt latency?
How can we reduce the interrupt latency?
What’s the interrupt vector table? Where it’s stored? Can you change its location?
ICU & PWM
What’s PWM? How does it work? And What are the parameters of a PWM Signal?
How to generate multiple software PWM signals with 1 timer?
How to measure pulse width with ICU (input capture unit)?
How to measure the frequency of a signal with ICU?
How to measure the duty cycle of a signal with ICU?
What’s PWM resolution? How to control it?
How to implement a software ICU?
Using PWM, create a DAC system
Generate 2 software PWM signals with controllable duty cycle and phase difference
ADC & DAC
How does ADC work? What are the ADC types?
Explain ADC sampling time and acquisition time
How to pick the proper sampling rate for ADC?
What’s the effect of analog input impedance on the ADC’s reading?
What’s ADC channels cross-coupling? How to eliminate it?
Write code to read temperature with ADC
Using 8-Bit DAC, write code to generate a sawtooth waveform @ 50Hz
Using 8-Bit DAC, write code to generate a triangular waveform @ 50Hz
Using 8-Bit DAC, write code to generate a sine waveform @ 50Hz
Serial Communication
Compare between SPI and I2C
Which offers the highest data rate among SPI, I2C, UART protocols?
Which port to use for onboard high-speed communication? Why?
At the same baud rate which would send more data SPI or UART? Why?
1. UART
How does UART communication work?
What’s the UART frame structure?
What’s Baud Rate and Bit Rate?
Differences between UART and USART
What’s parity bit in UART?
is UART synchronous or asynchronous protocol?
is UART Full-duplex or Half-duplex communication?
What’s the pin sampling rate for the UART receiver?
Can UART be a multi-slave protocol?
Give some example applications in which UART is a good choice as a communication port
Write code to send 1000 bytes of data with UART
2. SPI
How does SPI communication work?
Define the SPI clock phase and polarity
What are SPI mode numbers 0,1, 2, 3
How to daisy-chain some SPI devices?
How many slaves can SPI master communicate to?
Can an SPI slave initiate a communication?
Is SPI a synchronous or asynchronous protocol?
Give some example applications in which SPI is a good choice as a communication port
What do you think sets the upper limit for SPI speed?
3. I2C
How does I2C communication work?
What are the basic elements of I2C transactions?
How many slaves can be addressed on the I2C bus?
Is I2C a synchronous or asynchronous protocol?
What are start and stop conditions?
What is arbitration in I2C? Why it’s useful?
Give some example applications in which I2C is a good choice as a communication port
What would happen if two masters wanted to send data to the same slave at the exact same moment?
Data Structures & Algorithms Questions
Implement stack in c
Implement a linked list in c
Implement a double linked list in c
Implement a queue in c
Search for a number in an unsorted array
Search for a number in a sorted array
Reverse an array
RTOS & OS Questions
What’s a kernel?
What’s a task and a process?
What’s The CPU Load?
What’s the scheduler? List down some scheduling algorithms
What’s a deadlock and when does it occur?
Differences between Mutex and Semaphores
What’s the priority ceiling?
What’s the priority inversion?
What’s the priority inheritance?
What does RTOS mean? Give some examples
Write a FreeRTOS task implementation in c
Preemptive vs Non-Preemptive kernels
Automotive Embedded Interview Questions
What’s the speed range for the CAN bus?
What’s the speed range for LIN?
Applications For CAN and LIN
Differences between CAN and LIN
Why CAN bus has 2 resistors at both ends?
What happens when 2 CAN nodes transmit data with the same id at the same time?
What do you know about AUTOSAR?
What’s SWC?
What’s the RTE? It’s functions?
What do you know about iso26262 and functional safety?
Embedded Hardware Questions
What’s JTAG?
Simulator VS Emulator
Local, Static, Global variables in C
Problem Solving Questions
Write C code to count the 1’s in an integer number
Write C code to count the 0’s in an integer number
Write C code to check for prime number
Write C code to check if an int is a palindrome number or not (like 1243421)
Write C code to draw X pattern with stars ‘*’
Write C code to draw Z pattern with stars ‘*’
Write C code to draw triangle pattern with stars ‘*’
Write C code to draw char A pattern with stars ‘*’
Write C code to draw a diamond pattern with stars ‘*’
Write C code to reverse the digits of an integer number
Write C code to find the greatest common divisor (GCD) of 3 numbers
Write C code to check for the endianness of the system
Write C code to send 4-Byte integers from a big-endian machine to little-endian machine via UART
The embedded systems interview questions mentioned on this page are general questions and most commonly seen in embedded systems interviews. I’ll do my best to keep this page updated with more questions and to answer each of them on a separate page and update its link here, so you have a single page resource to do a quick revision before your next interview. I wish you all the best of luck.
If you’ve got any further questions, please let me know. And if you’d like to give me any feedback, don’t hesitate to drop me a comment down below. In case you’d like to support my work, you can see this page or visit my store.
If you find this a helpful resource, then SHARE it with your network on social accounts! Let others know about it.
Regards,
Khaled Magdy