From 5e00400a05af0a5dee1a404c1bead9c37310df49 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 16 Mar 2016 20:40:19 +0100 Subject: [PATCH] board_lowlevel.c: Improve main oscillator initialization * ensure the PB8/PB9 pins are actually not in GPIO mode, which they apparently are on boot-up * ensure that neither pull-up nor pull-down are enabled on PB8/PB9 * ensure we first start the oscillator, before selecting it The sum of the above changes seems to make oscillator start-up much more reliable than before. The time needed for initialization is now pretty stable, and the occasional 15-20second clock stabiliziation has not been observed with this change. --- firmware/src_board/board_lowlevel.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/firmware/src_board/board_lowlevel.c b/firmware/src_board/board_lowlevel.c index a3493eef..f288fc04 100644 --- a/firmware/src_board/board_lowlevel.c +++ b/firmware/src_board/board_lowlevel.c @@ -94,14 +94,17 @@ extern WEAK void LowLevelInit( void ) */ /* Initialize main oscillator */ -/* if ( !(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) ) + if ( !(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) ) { PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN; timeout = 0; while (!(PMC->PMC_SR & PMC_SR_MOSCXTS) && (timeout++ < CLOCK_TIMEOUT)); - }*/ + } /* Switch to 3-20MHz Xtal oscillator */ + PIOB->PIO_PDR = (1 << 8) | (1 << 9); + PIOB->PIO_PUDR = (1 << 8) | (1 << 9); + PIOB->PIO_PPDDR = (1 << 8) | (1 << 9); PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL; /* wait for Main XTAL oscillator stabilization */ timeout = 0;