| Author |
Message |
|
|
Posted: Mar 28, 2012 - 11:53 AM |
|

Joined: Jun 25, 2001
Posts: 348
Location: Melbourne Australia
|
|
Hi, I have a custom board that uses an AT32UC3AO256 and created a new project using the user application template for the User Board - UC3A0/A1. So far all good. I set up some I/O using gpio functions and all worked perfectly. I then decided to use the external 12MHz xtal OCS0 so i added the asf clock control module and added the following to user_board.h
Code:
#define BOARD_OSC0_HZ 12000000
#define OSC_ID_OSC0 0 //!< External Oscillator 0
#define BOARD_OSC0_STARTUP_US OSC_STARTUP_4096
Code all compiled ok but no go as it hangs on waiting for the xtal to satrt so i am obviously missing something in board.h
I tried the following code:
Code:
//Configure the oscillator 0 in crystal mode.
AVR32_PM.oscctrl0=AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3<<AVR32_PM_OSCCTRL0_MODE_OFFSET | 3<<AVR32_PM_OSCCTRL0_STARTUP_OFFSET;
//Enable the oscillator 0.
AVR32_PM.mcctrl |= AVR32_PM_MCCTRL_OSC0EN_MASK;
//Wait for oscillator 0 to be ready.
while (!(AVR32_PM.poscsr & AVR32_PM_POSCSR_OSC0RDY_MASK));
//Switch main clock from internal RC oscillator to oscillator 0.
AVR32_PM.mcctrl |= AVR32_PM_MCCTRL_MCSEL_OSC0;
and all worked perfectly.
So basically i wnat to get the asf code going.
Any help would be greatly appreciated.
Regards
Paul |
|
|
| |
|
|
|
|
|
Posted: Mar 28, 2012 - 01:42 PM |
|

Joined: Jul 10, 2006
Posts: 78
Location: Switzerland
|
|
Hello Paul,
Have you looked up the ASF online documentation, more specifically this
http://asf.atmel.com/docs/3.0.1/uc3a/html/group__sysclk__group.html ?
The function sysclk_init() is very common in the asf example. Unfortunately I can't help you more than that as I didn't have the time yet to play with my UC3L0 Xplained board, but I hope it could helped you a little...
Have a nice day,
Kraal |
_________________ Have a nice day,
Kraal
|
| |
|
|
|
|
|
Posted: Mar 28, 2012 - 01:54 PM |
|

Joined: Jun 25, 2001
Posts: 348
Location: Melbourne Australia
|
|
| Hey Kraal, thanks for the reply. I have an xplained board and can get that working with no issues. So that is not the issue. Its the user board template that i am having trouble setting up as far as the clock goes |
|
|
| |
|
|
|
|
|
Posted: Mar 28, 2012 - 02:22 PM |
|

Joined: Jul 10, 2006
Posts: 78
Location: Switzerland
|
|
Hello again Paul,
I am like you, the asf looks great to use, but it seems to me that the learning process is a bit harder than it should, regarding what function to call with what parameters/defines...Sorry that I can't help you with this,
Have a nice day,
Kraal |
_________________ Have a nice day,
Kraal
|
| |
|
|
|
|
|
Posted: Mar 29, 2012 - 08:06 AM |
|

Joined: Jun 16, 2011
Posts: 17
Location: United States of Europe
|
|
if you want to use sysclk_init() you have to edit conf_clock.h.
By default the RC cicuit is used as clock. If you want to use the oscilator, you also have to define crystal characteristics. I'm using a user board with a UCB0512 and use the following defines:
Code:
#define BOARD_OSC0_HZ 12000000
#define BOARD_OSC0_TYPE XOSC_TYPE_XTAL
#define BOARD_OSC0_IS_XTAL true
#define BOARD_OSC0_STARTUP_US 17000
You used OSC_STARTUP_4096 but that symbol is not expanded to a startup delay in useconds. It is expanded to the value 4 instead. This value is to be set in the registry at the end. sysclk_init will calculate the proper value based on the delay in us.
If you specify
Code:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_OSC0
in conf_clock.h youre processor will use the oscilator and will run at 12 MHz.
For higher frequencies you have to switch to the a PLL. Specify the following in conf_clock.h:
Code:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_PLL0
#define CONFIG_PLL0_MUL 10
#define CONFIG_PLL0_DIV 2
And your processor will run on 60 MHz, which is the maximum for the UC3B series. To get a frequency of 66 MHz (maximum for the A series) change the multiplier to 11. |
|
|
| |
|
|
|
|
|
Posted: Mar 29, 2012 - 08:20 AM |
|

Joined: Jun 16, 2011
Posts: 17
Location: United States of Europe
|
|
|
Kraal wrote:
Hello again Paul,
I am like you, the asf looks great to use, but it seems to me that the learning process is a bit harder than it should, regarding what function to call with what parameters/defines...Sorry that I can't help you with this,
Have a nice day,
Kraal
I concur, the documentation is lousy. Proper documentation includes some information about how to use the functions, not just a function definition and some (in most cases) poorly documented examples.
I have struggled quite some time to get started with the framework. The best way is to look at the source code what is actually happening. You also have to check the datasheet for registers modified, only then you have a change to understand what is happening.
And last but not least, not all code is perfect. I have rewritten the driver for SPI Flash memory. At one hand the driver is over complete (I don not want to deal with up to for different external chips), at the other hand it is incomplete (some functionality I need is missing). The SPI driver it self is also far from perfect and is another component I rewrote.
Apart from these minor inconveniences I am still happy with the framework, its free and improved frequently. If only that documentation …. |
|
|
| |
|
|
|
|
|
Posted: Mar 29, 2012 - 09:58 AM |
|

Joined: Jun 25, 2001
Posts: 348
Location: Melbourne Australia
|
|
Hi rob.aarnts, that worked perfectly. Thanks so much for your help. Greatly appreciated. As you say and i agree ASF has potential but documentation is crap. Is there someone from atmel reading this and would like to comment.
I will say that for a user board which i have you need to add the code to user_board.h for the ext xtal to work.
Regards Paul |
|
|
| |
|
|
|
|
|
Posted: Mar 29, 2012 - 10:15 AM |
|

Joined: Jun 25, 2001
Posts: 348
Location: Melbourne Australia
|
|
so to clarify for anyone who wants to use the code for an ext crystal add this code to user_board.h
Code:
#ifndef USER_BOARD_H
#define USER_BOARD_H
/* This file is intended to contain definitions and configuration details for
* features and devices that are available on the board, e.g., frequency and
* startup time for an external crystal, external memory devices, LED and USART
* pins.
*/
#define BOARD_OSC0_HZ 12000000
#define BOARD_OSC0_TYPE XOSC_TYPE_XTAL
#define BOARD_OSC0_IS_XTAL true
#define BOARD_OSC0_STARTUP_US 17000
#endif // USER_BOARD_H
|
|
|
| |
|
|
|
|
|
Posted: Mar 29, 2012 - 10:40 AM |
|

Joined: Jun 25, 2001
Posts: 348
Location: Melbourne Australia
|
|
| Will also add the the ASF has so much potential. Will be glad when it becomes a stable release. As far as my avr32 project goes it has simplified the learning procedure. |
|
|
| |
|
|
|
|
|