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.
diff --git a/firmware/src_board/board_lowlevel.c b/firmware/src_board/board_lowlevel.c
index a3493ee..f288fc0 100644
--- a/firmware/src_board/board_lowlevel.c
+++ b/firmware/src_board/board_lowlevel.c
@@ -94,14 +94,17 @@
*/
/* 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;