Back to main page

AVR®32 AT32UC3 Series Software Framework: GCC Projects

Copyright © 2007 Atmel Corporation

 

Introduction

To use the GCC projects, you need to install the AVR32 GNU toolchain first.

Let's take the example of the ADC driver module. The /DRIVER/ADC/EXAMPLE/AT32UC3A0512/GCC folder contains a Makefile, a configuration file (config.mk) and a configuration file for the GDB debugger.

 

Makefile

The ADC Makefile Makefile is a generic Makefile for avr32-gcc. The Makefile comes with pre-built Make goals:

  • [all]: Default goal: build the project.
  • clean: Clean up the project.
  • rebuild: Rebuild the project.
  • ccversion: Display CC version information.
  • cppfiles file.i: Generate preprocessed files from C source files.
  • asfiles file.x: Generate preprocessed assembler files from C and assembler source files.
  • objfiles file.o: Generate object files from C and assembler source files.
  • a file.a: (Archive) Create an archive output file from object files.
  • elf file.elf: (Link) Create ELF output file from object files.
  • lss file.lss: Create extended listing from target output file.
  • sym file.sym: Create symbol table from target output file.
  • hex file.hex: Create Intel HEX image from ELF output file.
  • bin file.bin: Create binary image from ELF output file.
  • sizes: Display target size information.
  • isp: Use ISP instead of JTAGICE mkII when programming.
  • cpuinfo: Get CPU information.
  • halt: Stop CPU execution.
  • chiperase: Perform a JTAG Chip Erase command.
  • erase: Perform a flash chip erase.
  • program: Program MCU memory from ELF output file.
  • secureflash: Protect chip by setting security bit.
  • reset: Reset MCU.
  • debug: Open a debug connection with the MCU.
  • run: Start CPU execution.
  • readregs: Read CPU registers.
  • doc: Build the documentation.
  • cleandoc: Clean up the documentation.
  • rebuilddoc: Rebuild the documentation.
  • verbose: Display main executed commands.
  •  

    To program the target and run the program, you can type the following command from cygwin if you want to use JTAGICE mkII:

     make program run
    

    Or the following command if you want to use the bootloader:

     make isp program run
    

    config.mk: Configuration options for the Makefile.

    Check the ADC config.mk file for Makefile configuration.

    This config.mk defines configurations like target, include path, source files and compiler optimization:

     

  • Base paths: define the path of the framework main directories

    PRJ_PATH = ../../../../..
    APPS_PATH = $(PRJ_PATH)/APPLICATIONS
    BRDS_PATH = $(PRJ_PATH)/BOARDS
    COMP_PATH = $(PRJ_PATH)/COMPONENTS
    DRVR_PATH = $(PRJ_PATH)/DRIVERS
    SERV_PATH = $(PRJ_PATH)/SERVICES
    UTIL_PATH = $(PRJ_PATH)/UTILS
    
  • GCC Architecture and parts: the AVR32 UC architecture and part number.
  • ARCH = uc
    
    PART = uc3a0512
    
    
  • Device/Platform/Board include path: the /BOARDS/board.h file use the BOARD define to select the correct board definitions.
    PLATFORM_INC_PATH = \
      $(BRDS_PATH)/
    
  • Definitions: Preprocessor definitions. Note that the BOARD preprocessor define must be defined to identify the target board.
    
    DEFS = -D BOARD=EVK1100 -D _ASSERT_ENABLE_
    
    
  • Include paths: all used modules includes path.

    UTILS/PREPROCESSOR is required when the UTILS/compiler.h file is used. This is the case for all examples provided in this Software framework.

    SERVICES/USB/CLASS/DFU/EXAMPLES/ISP/BOOT may be useful when linking with the bootloader or its trampoline.

    INC_PATH = \
      $(UTIL_PATH)/ \
      $(UTIL_PATH)/PREPROCESSOR/ \
      $(UTIL_PATH)/DEBUG/ \
      $(SERV_PATH)/USB/CLASS/DFU/EXAMPLES/ISP/BOOT/ \
      $(DRVR_PATH)/INTC/ \
      $(DRVR_PATH)/USART/ \
      $(DRVR_PATH)/GPIO/ \
      $(DRVR_PATH)/PM/ \
      ../../../ \
      ../../
    
  • C and Assembler source files : usart.c and print_funcs.c are used to print debug messages on RS232 output.

    adc.c and adc_example.c respectively are the ADC driver and the example application.

    gpio.c is used to select alternate functions on IOs.

    pm.c is used to switch the main clock on external crystal.

    intc.c and exception.S files are used to manage exceptions and handler addresses for processor events.

    crt0.S is the C runtime startup which gets executed just after the reset vector and before the main() C function: its main mission is to initialize critical registers (example: the stack pointer) and memory. If it is not provided, unlike here, GCC will use its own start entry point depending on ARCH value.

    trampoline.S is the code positionned at the reset vector and launching the C runtime startup in crt0.S by jumping over the memory area normally dedicated to the bootloader.

    CSRCS = \
      $(DRVR_PATH)/USART/usart.c \
      $(DRVR_PATH)/INTC/intc.c \
      $(DRVR_PATH)/GPIO/gpio.c \
      $(DRVR_PATH)/PM/pm.c \
      $(UTIL_PATH)/DEBUG/print_funcs.c \
      ../../../adc.c \
      ../../adc_example.c
    
    ASSRCS = \
      $(SERV_PATH)/USB/CLASS/DFU/EXAMPLES/ISP/BOOT/trampoline.S \
      $(UTIL_PATH)/STARTUP_FILES/GCC/crt0.S \
      $(DRVR_PATH)/INTC/exception.S
    
  • Libraries to link with the project if any: e.g., add `m' to link the math library libm.a.
    LIBS =
    
  • Linker script if any: If nothing is specified, GCC will use its default linker script based on the ARCH & PART definition (described here above): do that if the application uses the GCC standard C library support (malloc, memcpy,...). Here, the ADC example doesn't use any of the functions provided by the standard C library; we thus link to the simplified UC3A0512 linker script in /UTILS/LINKER_SCRIPTS/AT32UC3A/0512/GCC/.
    
    LINKER_SCRIPT = $(UTIL_PATH)/LINKER_SCRIPTS/AT32UC3A/0512/GCC/link_uc3a0512.lds
    
    
  • Compiler optimization: [-O[0|1|2|3|s]]...For further details, refer to the chapter "GCC Command Options" of the GCC manual.
    OPTIMIZATION = -O0 -ffunction-sections -fdata-sections
    
  • Extra flags to be used by the GCC linker: -nostdlib tells the linker to not link with the C standard library. crt0.S and exception management files (intc.c and exception.S) will be used instead (cf. above). -nostartfiles can be used instead to save space without preventing from linking standard C functions.

    The linker --gc-sections option makes sense when used with the GCC compiler optimization options -ffunction-sections or -fdata-sections : it is destined to optimize the link step in terms of generated size (unused sections won't be linked).
  • LD_EXTRA_FLAGS = -Wl,--gc-sections -nostdlib
    

    gdb_cmdfile.txt: configuration file for the avr32-gdb program

    Usage: you can type from your favorite terminal:

     avr32-gdb -x gdb_cmdfile.txt
    
    or

     ddd --debugger avr32-gdb -x gdb_cmdfile.txt
    

     

    Embedded Development Quick Start

    GCC quick start with ADC example: how to deploy the ADC example on target in 5 steps.

     

    FAQ

    In the FAQ page, you will find a list of Frequently Asked Questions related to the Software Framework.

     


    AVR is a registered trademark of Atmel Corporation.