I am using SAMD21 with FreeRTOS. I am putting the system on sleep level Standby and relying on a TC that works as a systick for the tickless FreeRtos to wake up the MCU however, when the debugger isn't connected (which it shouldn't be) the MCU goes to sleep and never wakes up.

enter image description here

I have tried it with the internal 8M and external 32K and had no lock. The only clock which the CPU can wake up from sleep with is ULP32K which is always on so On Demand doesn't really mean much in that case.

This is the snippets of the TC and my Clock configurations:

// From conf_clock.h
/* SYSTEM_CLOCK_SOURCE_OSC8M configuration - Internal 8MHz oscillator */
#  define CONF_CLOCK_OSC8M_ON_DEMAND              true  // <--
#  define CONF_CLOCK_OSC8M_RUN_IN_STANDBY         false // <--

/* Configure GCLK generator 5 */
#  define CONF_CLOCK_GCLK_5_ENABLE                true 
#  define CONF_CLOCK_GCLK_5_RUN_IN_STANDBY        true // <--
#  define CONF_CLOCK_GCLK_5_PRESCALER             1
#  define CONF_CLOCK_GCLK_5_OUTPUT_ENABLE         false

// From tickless.c
void vPortSetupTimerInterrupt(void)
    // Struct for configuring TC
    struct tc_config tcconf;
    // Set up configuration values
    tcconf.clock_source     = GCLK_GENERATOR_5;
    tcconf.counter_size    = TC_COUNTER_SIZE_32BIT;
    tcconf.run_in_standby  = true;                       // <--
    tcconf.clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
    tcconf.wave_generation = TC_WAVE_GENERATION_MATCH_FREQ;

    // Initialize the TC
    tc_init(&tc, TICK_TC, &tcconf);

    // Register and enable callback for freeRTOS tick handler
    tc_register_callback(&tc, (tc_callback_t) xPortSysTickHandler, TC_CALLBACK_CC_CHANNEL0);
    tc_enable_callback(&tc, TC_CALLBACK_CC_CHANNEL0);

    // Set top value equal to one OS tick
    tc_set_count_value(&tc, 0);
    tc_set_top_value(&tc, TIMER_RELOAD_VALUE_ONE_TICK);

    // Enable the timer

What I am missing here.

Is this the same issue people are talking here -> http://www.avrfreaks.net/forum/samd21-samd21e16b-sporadically-locks-and-does-not-wake-standby-sleep-mode

Just to clarify, the sleep level IDLE_2 works and CPU can recover from sleep successfully.

  • \$\begingroup\$ In order to determine whether Errata 10416 is relevant, try running your tests with the TC peripheral in 8bit mode. According to the datasheet, none of the registers are read-synchronized in 8bit mode. \$\endgroup\$ – David Freitag Aug 15 '17 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.