Starting a New GCC Project for SAM (ARM) Device

  1. 1.Create a new project by selecting New Project from the Project menu. This will open the Project Wizard.


  2. 2.Select C/C++GCC C Executable Project as a template, then specify a project name, select a location, and write a solution name for the project. Some start-up files will be added to the project by default, which will contain some device specific functions and libraries. Press OK when you are satisfied with the settings.
  3. 3.Select C/C++GCC C Static Library Project as a template, then specify a project name, select a location, and write a solution name for the project. This creates a Static Library (LIB) project, which is a good way to reuse code.
    Tip:

    See section Static Library Project to learn more about Static Library projects.

  4. 4. A device selection table will appear. Choose the device family as SAM3 or SAM4 and select the target platform for your project. To start you can select the ATSAM3S1A device.

  5. 5.The project tree will be set up. Notice that the initial files created in step 2 have been added to the project node. Also, the file containing main() function will be opened in the editor.

    Here is a list of files that will be created:

    • A file with the same name as the project will be created and added to the project by default. It will contain the main() function.

    • A startup file(startup_*.c) will be available at 'cmsis\src' directory. It contains the default interrupt handlers for all the peripherals.

    • A system file(system_*.c) available at 'cmsis\src' provides the system level initialization functions that are called on start-up

    • Linker scripts with appropriate sections based on the device will be created at 'cmsis\LinkerScripts' directory in the project folder

    • In case if you have deleted any files in cmsis folder and want to revert it back or if you have changed the device, just right click the Project and click 'CMSIS Update from Atmel' to get the appropriate files.



    Note: It is recommended not to change the contents of the startup_*.c and system_*.c files unless you have no other choice. These startup, system, and linker scripts will not be created for ARM static library projects.
  6. 6.In order to facilitate applications development and verification, you can also use the Driver Selection Wizard, invoked from Project ASF Wizard.


    In the ASF Wizard you can select which Drivers, Components, and Services you would like to use in the project for current build architecture and board.
  7. 7.Now, write the following code into the open editor window:
    #define MAXINT 200000
    
    int main(void) 
    {
        unsigned int t=1000, k=0, l=5, pn=2; 
        unsigned int primes[t];
        primes[0]=2;
        primes[1]=3;
    
        while (pn < t || primes[pn] < MAXINT)
        {
            for ( k = 0; k <= pn; k++)
            {
                if (l % primes[k] == 0)
    			{
                    goto otog;
    			}
                else 
                {
                    if (k == pn)
                        primes[pn++]=l;
                } 
            }
    otog:
            l += 2;
        }
        return 0;
    }
  8. 8.Build the project.