The code
Embedded C for Cortex-M. It compiles. There are 3 real bugs in it: the kind that pass a bench test and fail in the field.
SemaphoreHandle_t spi_lock;
void app_init(void)
{
spi_lock = xSemaphoreCreateBinary();
xSemaphoreGive(spi_lock);
}
void display_task(void *p) /* priority 3 */
{
for (;;) {
xSemaphoreTake(spi_lock, portMAX_DELAY);
lcd_flush();
xSemaphoreGive(spi_lock);
}
}
void logger_task(void *p) /* priority 1 */
{
for (;;) {
xSemaphoreTake(spi_lock, portMAX_DELAY);
sd_write_block();
if (sd_error()) continue;
xSemaphoreGive(spi_lock);
vTaskDelay(pdMS_TO_TICKS(100));
}
}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: LowEspressifChipmaker · India hiring: MediumGarminConsumer devices · India hiring: LowMedtronicMedical devices · India hiring: MediumMeta Reality LabsConsumer devices · India hiring: LowNordic SemiconductorChipmaker · India hiring: LowQualcommChipmaker · India hiring: HighRenesasChipmaker · India hiring: Medium
Related challenges
FreeRTOS sensor pipelineRTOS · Hard · 5 bugs · ~8 minLogging through a queueRTOS · Warm-up · 3 bugs · ~4 minCritical sections and scheduler locksRTOS · Medium · 4 bugs · ~5 minPeriodic control loopRTOS · Medium · 3 bugs · ~5 minNested mutexes under loadRTOS · Hard · 3 bugs · ~8 minTask check-in watchdogRTOS · Medium · 3 bugs · ~7 min
Flag the lines, say what breaks, then fix it and build it with clang in your browser.
Find the bugs