The reference to idle() on the Arduino web site says the CPU should stop, but the following sketch continues to run for me, ie the TX_LED continues to flash.
Looking into the .cpp of the library the routine does as the datasheet describes:
16.6.2.8.1 IDLE Mode
Entering IDLE mode: The IDLE mode is entered by executing the WFI instruction. Before entering theIDLE mode, the user must configure the IDLE mode configuration bit group and must write a zero
to the SCR.SLEEPDEEP bit.
Not sure how the terminology works for the Zero, but idle is probably the lightest sleep mode that just turns off the CPU and leaves all the peripherals running. Usually any interrupt will be enough to wake the CPU up and let it continue running. It's probably the timer interrupt that left running that 's waking you up.
Jiggy-Ninja:
It's probably the timer interrupt that left running that 's waking you up.
I thought that myself but disabling global interrupts makes no diffo.
It may be a flag that's already set but I wouldn't know where to look to clear it.
Me again, the problem was two fold. SysTick keeps going in idle mode, which generates an interrupt for millis(). Also having an active native USB connection causes interrupts as well. Unmasking SysTick interrupt and disabling USB gets idle working.
I did a bit of light reading in the Cortex M0 Devices Generic User Guide. It's the WFI (Wait For Interrupt) instruction in the idle function that's the culprit. Even with interrupts disabled with a noInterrupts() call, it wakes up from idle as soon as an interrupt is pending. The intention of idle() might be to be used in a tight loop, which only exits when a flag is set in an interrupt or similar mechanism.