The code
Embedded C for Cortex-M. It compiles. There are 2 real bugs in it: the kind that pass a bench test and fail in the field.
static volatile uint32_t overflow_count;
void TIM2_IRQHandler(void)
{
if (TIM2->SR & TIM_SR_UIF) {
TIM2->SR = ~TIM_SR_UIF;
overflow_count++;
}
}
uint64_t micros64(void)
{
return ((uint64_t)overflow_count << 32) | TIM2->CNT;
}
static volatile uint64_t g_last_event_us; /* written in an EXTI ISR */
uint64_t last_event_us(void)
{
return g_last_event_us;
}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: LowArmChipmaker · India hiring: MediumTeslaAutomotive OEM · India hiring: LowAMD IndiaChipmaker · India hiring: MediumAnalog DevicesChipmaker · India hiring: MediumAptivAutomotive supplier · India hiring: MediumBoschAutomotive supplier · India hiring: HighContinentalAutomotive supplier · India hiring: High
Related challenges
Tick timeouts and delaysTiming · Warm-up · 3 bugs · ~4 minPWM duty and frequency controlTiming · Medium · 5 bugs · ~6 minPacking a log recordMemory & C · Medium · 3 bugs · ~6 minFixed-point speed loopTiming · Medium · 3 bugs · ~6 minFlow meter input captureTiming · Medium · 3 bugs · ~6 minMicrosecond delays that hangTiming · Medium · 3 bugs · ~6 min
Flag the lines, say what breaks, then fix it and build it with clang in your browser.
Find the bugs