The code
Embedded C for Cortex-M. It compiles. There are 5 real bugs in it: the kind that pass a bench test and fail in the field.
QueueHandle_t sensor_q;
SemaphoreHandle_t i2c_mutex;
/* Sensor data-ready line on PB3 */
void EXTI3_IRQHandler(void)
{
EXTI->RPR1 = EXTI_RPR1_RPIF3;
xSemaphoreTake(i2c_mutex, portMAX_DELAY);
uint16_t raw = i2c_read_reg(SENSOR_ADDR, REG_TEMP);
xSemaphoreGive(i2c_mutex);
xQueueSend(sensor_q, &raw, 0);
}
void sensor_task(void *arg)
{
char log_line[1024];
uint16_t raw;
for (;;) {
if (xQueueReceive(sensor_q, &raw, portMAX_DELAY) == pdTRUE) {
float temp_c = raw * 0.0625f;
snprintf(log_line, sizeof(log_line), "T=%.2f C", temp_c);
log_write(log_line);
}
}
}
void app_init(void)
{
sensor_q = xQueueCreate(8, sizeof(uint16_t));
i2c_mutex = xSemaphoreCreateMutex();
xTaskCreate(sensor_task, "sensor", 256, NULL, 2, NULL);
NVIC_SetPriority(EXTI3_IRQn, 2);
NVIC_EnableIRQ(EXTI3_IRQn);
}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.
QualcommChipmaker · India hiring: HighRenesasChipmaker · India hiring: MediumTata ElxsiEngineering services · India hiring: HighABBIndustrial · India hiring: MediumAMD IndiaChipmaker · India hiring: MediumAnalog DevicesChipmaker · India hiring: MediumAppleConsumer devices · India hiring: LowDysonConsumer devices · India hiring: Low
Related challenges
UART receive ring bufferDrivers & ISRs · Medium · 4 bugs · ~6 minSharing SPI between tasksRTOS · Medium · 3 bugs · ~6 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 min
Flag the lines, say what breaks, then fix it and build it with clang in your browser.
Find the bugs