ASF Project hangs waiting for stable clock -> "No external oscillator on the selected board"?

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

now i found the problem, that in the function osc_enable_external() in osc.h there is the following code with the remark: "No external oscillator on the selected board"!:

static inline void osc_enable_external(uint8_t id)
{
	Assert(false); // No external oscillator on the selected board
}
#endif

How should i tell the ASF, that my controller has an external oscillator?

Hacking the program by enable the oscillator with my own code runs, but i would like to do it the right way...

 

 

Previous post "ASF Project hangs waiting for stable clock":

 

i just started with ASF.

My startup project is a simple "Hello World"-Project just flashing a led on startup, with the following user board configuration:

- ATxmega32E5

- Internal 2MHz System clock from 8MHz clock (default setting)

- External 32'768Hz Crystal on the TOSC pins for the RTC running with 1kHz.

Test with clocks on Ports:

PORTCFG.CLKOUT = (PORTCFG_CLKOUT_PD7_gc | PORTCFG_RTCOUT_PD6_gc);

First i started with only the "Generic board support" module initializing the Ports and flashing the led.

The "System Clock" module wasn't needed, since it is already default on 2MHz from 8MHz.

-> OK, the Clock i can see on the Port PD7

 

Then i added the ASF RTC driver with the following settings recommended in http://asf.atmel.com/docs/3.22.0...

conf_rtc.h:

#define CONFIG_RTC_PRESCALER          RTC_PRESCALER_DIV256_gc

conf_clock.h:

#define CONFIG_RTC_SOURCE           SYSCLK_RTCSRC_TOSC

and added the functions

sysclk_init();

rtc_init();

just before the board_init(); function.

 

But the program hangs in the sysclk_rtcsrc_enable() function waiting for the oscillator ready....

 

Since on the first Test i didn't need the sysclk_init() because it is already default, i obviously need it is requested in the Quick start guide.

Removing it, results in a running program but only with the 2MHz System Clock...

 

Also while debugging in the sysclk_rtcsrc_enable function (with optimize none, debug max) the debugger omits the osc_enable(OSC_ID_XOSC);

But this could be a bug in Atmel studio, because adding a asm("NOP"), just before ommitted just the NOP, but the program hangs anyway...

 

static inline void sysclk_rtcsrc_enable(uint8_t id)
{
	Assert((id & ~CLK_RTCSRC_gm) == 0);

	switch (id) {
	case SYSCLK_RTCSRC_RCOSC:
#if !XMEGA_A && !XMEGA_D
	case SYSCLK_RTCSRC_RCOSC32:
#endif
		osc_enable(OSC_ID_RC32KHZ);
		osc_wait_ready(OSC_ID_RC32KHZ);
		break;
	case SYSCLK_RTCSRC_TOSC:
	case SYSCLK_RTCSRC_TOSC32:
#if !XMEGA_A && !XMEGA_D
	case SYSCLK_RTCSRC_EXTCLK:
#endif
        asm("NOP"); // added by me
		osc_enable(OSC_ID_XOSC);
		osc_wait_ready(OSC_ID_XOSC);
		break;
	}

	CLK.RTCCTRL = id | CLK_RTCEN_bm;
}

 

 

This topic has a solution.
Last Edited: Sun. Dec 31, 2017 - 11:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When creating an "ASF Board Project" you are required to select a board.  Which board did you select?  Which board are you using?

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using my own (user) board. Nobody wants to use a demo board to make a product!

So i am still searching what to do to adapt ASF to my user board. Unfortunately there is much documentation for demo boards, but for me it seems that ASF is just done for fun (making programs for unusable demo boards).

Can you tell me how to adapt my files for my project? There are several files (..user_board\init.c, ..user_board\user_board.h, ..config\conf_board.h, many others wich might mach)

My board has:

- External Crystal 32'768 (TOSC)

- SPI on Port C

- RS on Port C

- TWI on Port C

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

delphinis wrote:
Nobody wants to use a demo board to make a product!

Maybe not - but you use the demo board to get familiar with the product and the tools.

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@delphinis said:

Can you tell me how to adapt my files for my project? There are several files...

 The two you need to focus on are:

...\src\ASF\common\boards\user_board\user_board.h

...\src\ASF\common\boards\user_board\init.c

 

Board-specific stuff goes in user_board.h:

#define BOARD_XOSC_HZ          32768UL
#define BOARD_XOSC_TYPE        XOSC_TYPE_32KHZ
#define BOARD_XOSC_STARTUP_US  50000

 

The board_init() function is defined in init.c:

#include <asf.h>
#include <board.h>
#include <conf_board.h>

void board_init(void)
{
	/* This function is meant to contain board-specific initialization code
	 * for, e.g., the I/O pins. The initialization can rely on application-
	 * specific board configuration, found in conf_board.h.
	 */
}

 

Look at the code for an ASF demo project for the XMEGA-32E5 Xplained to get an idea of what ASF expects you to do in these files:

...\src\ASF\xmega\boards\xmega_e5_xplained\init.c
...\src\ASF\xmega\boards\xmega_e5_xplained\xmega_e5_xplained.h

 

 

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Greg,

thanks for your answer. I already tried the following,

#define BOARD_XOSC_TYPE        XOSC_TYPE_32KHZ
#define BOARD_XOSC_STARTUP_US  50000

but obviously forget to define the frequency. I just wasn't shure that it is the right place because I wouldn't the External Cristal as system clock ressource.

But now with this setting it works fine!

So i think the conf_board.h is only for an eventually external clock... A better name for this conf file would then be ext_clk_conf.h or so on, but user_board.h??? Ok, it is, as it is.

Now i have to study the init.c files with the other initialization for my interfaces...

(I already had a look at the XMEGA-32E5 Xplained board, but in the schematic I saw, that there was no external crystal. Therefore it didn't help me. Also there are no examples for TWI or SPI, but i will look at other controllers, maybe it's similar, just p.e. there's no example for TWI for any Xmega...)

Anyway thanks again.

 

Other question: is there a possibility in atmel studio to mark the code wich is excluded by the compiler commands #ifdef ?

That would be very helpful with this huge set of files with all of its dependencies.

I already tried Options-Fonts and Colors-Excluded Code, but it doesn't work, respectively this option is already gray but does not mark excluded code by compiler commands.

Last Edited: Sun. Dec 31, 2017 - 03:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@delphinis said:

Other question: is there a possibility in atmel studio to mark the code wich is excluded by the compiler commands #ifdef ?

Install the Naggy extension:

 

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly