Atmel (ASF) system_clock_init() Bug

Using the Atmel Software Framework (ASF) we had an issue with an infinite loop occurring during the initialization stage. It would happen when the system_init() was in system_clock_init() trying to switch all of the peripheral clock channels over to an inactive GCLK generator.

The infinite loop would occur in the system_gclk_chan_disable() function once it reached the line “while (GCLK->CLKCTRL.reg & GCLK_CLKCTRL_CLKEN)”. It was attempting to disable the clock channel of a peripheral and then waiting for it to be disabled.

After some digging we discovered that the reason it was failing was that the watchdog timer had been set up with the .always_on property set to true. This caused the watchdog timer’s register to be write-locked. Because of this write-lock, the system_gclk_chan_disable() function was unable to modify the watchdog’s register and thus the clock channel was never changed.

The solution was to add a check for write-lock on the register before an attempt was made to disable it. The following code segment was added to the beginning of the system_gclk_chan_set_config() function in gclk.c.

	// User added check for write-lock on this channel.
	int write_locked = false;
	/* Select the requested generator channel */
	*((uint8_t*)&GCLK->CLKCTRL.reg) = channel;
		write_locked = true;

With this code in place the register is checked for a write-lock and skipped if one is found. This allows the initialization to continue normally, bypassing the registers that it cannot modify, instead of locking in an infinite loop.

Water Level Sensor

[Plant Database], [Soil Moisture Sensor] [Water Level Sensor] [Soil Moisture Meter]

© Copyright 2024 Daycounter, Inc. All rights Reserved. There is no guarantee for any information on this website. Use at your own risk.