The code
Embedded C for Cortex-M. It compiles. There are 4 real bugs in it: the kind that pass a bench test and fail in the field.
#define RX_BUF_SIZE 64
static uint8_t rx_buf[RX_BUF_SIZE];
static uint8_t head = 0;
static uint8_t tail = 0;
static bool data_ready = false;
void USART2_IRQHandler(void)
{
if (USART2->ISR & USART_ISR_RXNE) {
uint8_t byte = USART2->RDR;
rx_buf[head] = byte;
head = (head + 1) % RX_BUF_SIZE;
data_ready = true;
printf("RX: %c\n", byte);
}
}
/* Called from the main loop */
int uart_read(uint8_t *out)
{
while (!data_ready) { }
*out = rx_buf[tail];
tail = (tail + 1) % RX_BUF_SIZE;
if (tail == head) {
data_ready = false;
}
return 1;
}What an interviewer expects
- Point to each line you'd stop in a code review.
- Say what actually breaks: the failure mode, not just the rule it violates.
- Fix it, then defend the fix when asked the follow-up.
The bugs, reference fixes and the follow-up question are in the practice app, after you've tried it.
Companies that test this
Matched on the skills each company's embedded roles emphasise.
AppleConsumer devices · India hiring: LowGarminConsumer devices · India hiring: LowMedtronicMedical devices · India hiring: MediumQualcommChipmaker · India hiring: HighRenesasChipmaker · India hiring: MediumSTMicroelectronicsChipmaker · India hiring: MediumTata ElxsiEngineering services · India hiring: HighABBIndustrial · India hiring: Medium
Related challenges
FreeRTOS sensor pipelineRTOS · Hard · 5 bugs · ~8 minSPI NOR flash driverDrivers & ISRs · Medium · 4 bugs · ~6 minSTM32 HAL I2C readDrivers & ISRs · Warm-up · 4 bugs · ~4 minButton debounce in an EXTI ISRDrivers & ISRs · Warm-up · 3 bugs · ~4 minIndependent watchdog usageDrivers & ISRs · Medium · 3 bugs · ~5 minFlags shared with an ISRDrivers & ISRs · Medium · 2 bugs · ~5 min
Flag the lines, say what breaks, then fix it and build it with clang in your browser.
Find the bugs