You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Bernd Walter <be...@bwct.de> on 2020/01/28 15:26:23 UTC

unconditional 32kHz xtal oscillator on SAM34

I have had problens with a new SAM4S based board in that it hang eraly
during startup, before initializing my 12MHz xtal.
Also the SWD didn't work anymore until I erased the chip.
Since the SWD didn't work it was quite obvious that there is some clock
related issue.
I've found out that the startup code unconditionally switches to an
external 32kHz xtal.
On my board I didn't need one.
Interestingly I had no such problem on a SAM4E board, but there is
a small difference between those boards in that the SAM4E has XIN32/XOU3
pins unconnected and the SAM4S has XIN32 used as GPIO.
Or maybe the SAM4E just behave differently when trying to init an unhooked
32kHz xtal.
However, after commenting the sam_supcsetup() call my board worked fine.
I think there should be an option to initialize the 32kHz xtal or not.

arch/arm/src/sam34/sam_clockconfig.c:

/****************************************************************************
 * Name: sam_supcsetup
 *
 * Description:
 *   Select the external slow clock
 *
 ****************************************************************************/

static inline void sam_supcsetup(void)
{
  /* Check if the 32-kHz is already selected */

  if ((getreg32(SAM_SUPC_SR) & SUPC_SR_OSCSEL) == 0)
    {
      uint32_t delay;

      putreg32((SUPC_CR_XTALSEL | SUPR_CR_KEY), SAM_SUPC_CR);
      for (delay = 0;
           (getreg32(SAM_SUPC_SR) & SUPC_SR_OSCSEL) == 0 && delay < UINT32_MAX;
           delay++);
    }
}

...

/************************************************************************************
 * Name: sam_clockconfig
 * 
 * Description:
 *   Called to initialize the SAM3/4.  This does whatever setup is needed to put the
 *   SoC in a usable state.  This includes the initialization of clocking using the
 *   settings in board.h.  (After power-on reset, the SAM3/4 is initially running on
 *   a 4MHz internal RC clock).  This function also performs other low-level chip
 *   initialization of the chip including EFC, master clock, IRQ & watchdog
 *   configuration.
 *
 ************************************************************************************/

void sam_clockconfig(void)
{
  /* Configure embedded flash access */

  sam_efcsetup();
  
  /* Configure the watchdog timer */
  
  sam_wdtsetup();
 
  /* Setup the supply controller to use the external slow clock */

  sam_supcsetup();
  
  /* Initialize clocking */
 
  sam_pmcsetup();
 
  /* Optimize CPU setting for speed */

  sam_enabledefaultmaster();
}

-- 
B.Walter <be...@bwct.de> http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.

Re: [nuttx] unconditional 32kHz xtal oscillator on SAM34

Posted by Bernd Walter <be...@bwct.de>.
On Tue, Jan 28, 2020 at 05:22:08PM +0100, Bernd Walter wrote:
> On Tue, Jan 28, 2020 at 12:40:12PM -0300, Alan Carvalho de Assis wrote:
> > Hi Bernd,
> > 
> > On 1/28/20, Bernd Walter <be...@bwct.de> wrote:
> > > I have had problens with a new SAM4S based board in that it hang eraly
> > > during startup, before initializing my 12MHz xtal.
> > > Also the SWD didn't work anymore until I erased the chip.
> > > Since the SWD didn't work it was quite obvious that there is some clock
> > > related issue.
> > > I've found out that the startup code unconditionally switches to an
> > > external 32kHz xtal.
> > > On my board I didn't need one.
> > > Interestingly I had no such problem on a SAM4E board, but there is
> > > a small difference between those boards in that the SAM4E has XIN32/XOU3
> > > pins unconnected and the SAM4S has XIN32 used as GPIO.
> > > Or maybe the SAM4E just behave differently when trying to init an unhooked
> > > 32kHz xtal.
> > > However, after commenting the sam_supcsetup() call my board worked fine.
> > > I think there should be an option to initialize the 32kHz xtal or not.
> > >
> > 
> > Please check how other boards are doing it. Normally you have a DEFINE
> > USE_CLOCK_XYZ inside the boardname/include/board.h.
> 
> Ok - will do that.
> 
> > I faced an issue similar to your on SAMD21, it was defined to use
> > external crystal, but my board didn't have one. When I enabled the
> > internal clock the serial console wasn't working correctly. Then
> > Alexander noticed that it was missing a function to read the NVRAM
> > calibration data to use with the internal RC clock.
> 
> I have had the same problem with wrong uart clock on a few identic SAMD21
> boards, but results were different.
> My board had been running on internal RC without USB.
> An external 12MHz xtal existed, but I hadn't used it because of lazyness.
> My problem however wasn't the RC, because after switching to the xtal
> the problem still existed.
> In my case it was the DFLL and everything was fine after switching to
> the DPLL.
> The DPLL however is not an option if you want to use the RC and
> still being able to run device USB.

Oh - by the way.
When you use an extarnal xtal on a SAMD21 disable the oscillator power saving
feature (BOARD_DPLL_LPEN/SYSCTRL_DPLLCTRLB_LPEN) while debugging.
The amplitude is insanely low and I couldn't see it swinging on my scope.

-- 
B.Walter <be...@bwct.de> http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.

Re: [nuttx] unconditional 32kHz xtal oscillator on SAM34

Posted by Bernd Walter <be...@bwct.de>.
On Tue, Jan 28, 2020 at 12:40:12PM -0300, Alan Carvalho de Assis wrote:
> Hi Bernd,
> 
> On 1/28/20, Bernd Walter <be...@bwct.de> wrote:
> > I have had problens with a new SAM4S based board in that it hang eraly
> > during startup, before initializing my 12MHz xtal.
> > Also the SWD didn't work anymore until I erased the chip.
> > Since the SWD didn't work it was quite obvious that there is some clock
> > related issue.
> > I've found out that the startup code unconditionally switches to an
> > external 32kHz xtal.
> > On my board I didn't need one.
> > Interestingly I had no such problem on a SAM4E board, but there is
> > a small difference between those boards in that the SAM4E has XIN32/XOU3
> > pins unconnected and the SAM4S has XIN32 used as GPIO.
> > Or maybe the SAM4E just behave differently when trying to init an unhooked
> > 32kHz xtal.
> > However, after commenting the sam_supcsetup() call my board worked fine.
> > I think there should be an option to initialize the 32kHz xtal or not.
> >
> 
> Please check how other boards are doing it. Normally you have a DEFINE
> USE_CLOCK_XYZ inside the boardname/include/board.h.

Ok - will do that.

> I faced an issue similar to your on SAMD21, it was defined to use
> external crystal, but my board didn't have one. When I enabled the
> internal clock the serial console wasn't working correctly. Then
> Alexander noticed that it was missing a function to read the NVRAM
> calibration data to use with the internal RC clock.

I have had the same problem with wrong uart clock on a few identic SAMD21
boards, but results were different.
My board had been running on internal RC without USB.
An external 12MHz xtal existed, but I hadn't used it because of lazyness.
My problem however wasn't the RC, because after switching to the xtal
the problem still existed.
In my case it was the DFLL and everything was fine after switching to
the DPLL.
The DPLL however is not an option if you want to use the RC and
still being able to run device USB.

-- 
B.Walter <be...@bwct.de> http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.

Re: [nuttx] unconditional 32kHz xtal oscillator on SAM34

Posted by Alan Carvalho de Assis <ac...@gmail.com>.
Hi Bernd,

On 1/28/20, Bernd Walter <be...@bwct.de> wrote:
> I have had problens with a new SAM4S based board in that it hang eraly
> during startup, before initializing my 12MHz xtal.
> Also the SWD didn't work anymore until I erased the chip.
> Since the SWD didn't work it was quite obvious that there is some clock
> related issue.
> I've found out that the startup code unconditionally switches to an
> external 32kHz xtal.
> On my board I didn't need one.
> Interestingly I had no such problem on a SAM4E board, but there is
> a small difference between those boards in that the SAM4E has XIN32/XOU3
> pins unconnected and the SAM4S has XIN32 used as GPIO.
> Or maybe the SAM4E just behave differently when trying to init an unhooked
> 32kHz xtal.
> However, after commenting the sam_supcsetup() call my board worked fine.
> I think there should be an option to initialize the 32kHz xtal or not.
>

Please check how other boards are doing it. Normally you have a DEFINE
USE_CLOCK_XYZ inside the boardname/include/board.h.

I faced an issue similar to your on SAMD21, it was defined to use
external crystal, but my board didn't have one. When I enabled the
internal clock the serial console wasn't working correctly. Then
Alexander noticed that it was missing a function to read the NVRAM
calibration data to use with the internal RC clock.

BR,

Alan