Starting Electronics needs your help! Please make a donation to help cover our hosting and other costs. Click the donate button to send a donation of any amount.

Atmel Software Framework Checklist for ARM Cortex ASF C Projects

Created on: 30 May 2016

Part 7 of the ASF ARM Tutorial

This checklist goes through the steps needed to make a new ASF project for Atmel ARM Cortex microcontrollers, which files to modify and how to add ASF modules to a project. The list is intended as a quick reference for starting new ASF projects.

Atmel Software Framework supported devices and latest documentation can be found on the Microchip ASF website.

The following steps are also available as a handy downloadable pdf file from startingelectronics on GitHub. The pdf file can be downloaded, viewed or even printed and used as a reference whenever a new ASF ARM project is created.

Books that may interest you:

C Programming with Arduino Book Ultimate Arduino MEGA 2560 Hardware Manual Ultimage Arduino Uno Hardware Manual

Create a New ASF Project

  1. Open Atmel Studio and start a new project using File → New → Project... from the top menu bar or Ctrl + Shift + N on the keyboard.
  2. In the New Project dialog box, select GCC ASF Board Project, give the project a name and select the project location.
  3. In the Board Selection dialog box enter the ARM microcontroller part number in the search field and then select User Board template for the desired microcontroller.

Select Clock Sources and Frequencies

  1. Open the ASF Wizard using ASF → ASF Wizard from the top menu bar or Alt + W on the keyboard.
  2. Search for clock under Available Modules in the ASF Wizard. Select System Clock Control (service) and then click the Add >> button. Click the Apply button to add the selected module.
  3. Use Solution Explorer (image below) to open src → config → conf_board.h and add definitions for the clock resonators and oscillator start-up time, e.g.
    // clock resonators
    #define BOARD_FREQ_SLCK_XTAL      (32768U)
    #define BOARD_FREQ_SLCK_BYPASS    (32768U)
    #define BOARD_FREQ_MAINCK_XTAL    (12000000U)
    #define BOARD_FREQ_MAINCK_BYPASS  (12000000U)
    #define BOARD_MCK                 CHIP_FREQ_CPU_MAX
    #define BOARD_OSC_STARTUP_US      15625
    
    Without these definitions the compiler will issue several warnings.
  4. Use Solution Explorer to open src → config → conf_clock.h and comment out and uncomment the definitions to select the desired main clock source and settings.
  5. To select an external 32.768kHz crystal for the slow clock source and for an example of changing the main clock to use an external crystal, see https://startingelectronics.org/software/atmel/asf-arm-tutorial/external-crystals/
Atmel Studio Solution Explorer
Atmel Studio Solution Explorer

Add Hardware Definitions

  1. Open src → config → conf_board.h from Solution Explorer to add hardware definitions, e.g.:
    // output pin for LED
    #define LED0         IOPORT_CREATE_PIN(PIOB, 14)
    // input pin for switch
    #define SW0          IOPORT_CREATE_PIN(PIOA, 30)
    

Add Board Specific Initialization Code and Initialize System Clock

  1. Use Solution Explorer to open src → ASF → common → boards → user_board → init.c and add board specific initialization code in the board_init() function in init.c, e.g. code to disable the watchdog timer, code to set the pin direction of GPIO pins defined in conf_board.h, etc.
    WDT->WDT_MR = WDT_MR_WDDIS;                    // disable watchdog
    ioport_init();                                 // call before using IOPORT service
    ioport_set_pin_dir(LED0, IOPORT_DIR_OUTPUT);   // LED pin set as output
    ioport_set_pin_dir(SW0, IOPORT_DIR_INPUT);     // switch pin set as input
    
    In the above code example, the IOPORT – General purpose I/O service (service) ASF module must be added to the project to be able to call functions starting with ioport_ in the project.
  2. Call sysclk_init() in main.c
    int main (void)
    {
        sysclk_init();
        board_init();
    
        while (1) {
        }
    }
    

Finally the application code for the project can be written.