Electronics, PCB Design and PCB Layout

Custom Firmware, Electronics Design, and PCB Layout



Water Level Sensor







Atmel (ASF) system_clock_init() Bug - Daycounter

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;
	system_interrupt_enter_critical_section();
	/* Select the requested generator channel */
	*((uint8_t*)&GCLK->CLKCTRL.reg) = channel;
	if(GCLK->CLKCTRL.bit.WRTLOCK) {
		write_locked = true;
	}
	system_interrupt_leave_critical_section();
	if(write_locked){ 
		return;
	}

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.

[Employment] [Downloads] [Articles] [Contact Us]

Salt Lake City, UT, USA

Disclaimer: Daycounter, Inc. doesn't guarantee the accuracy of any of it's content. Use at your own risk.

© Copyright 2016 Daycounter, Inc. All rights Reserved.






Soil Moisture Sensor Probe