3.2.4 Starting a New GCC Project for SAM Device
- Create a new project by
selecting New Project from the Project
menu. This will open the Project Wizard.
- 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.
- 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 great way to
reuse code.Tip:
See section Static Library Project to learn more about Static Library projects.
-
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 choose the ATSAM3S1A device.
- The project tree will be set
up. Notice the addition of the initial files created in step 2 to the project node.
Also, the file containing the main() function opens in the editor.
Here is a list of files that will be created:
- A file with the same name as the
project will, by default, be created and added to the project. 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 the 'cmsis\LinkerScripts' directory in the project folder
- If you have deleted any files in the cmsis folder and want to revert it or changed the device, just right click the Project and click 'CMSIS Update from Microchip' 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 start-up, system, and linker scripts will not be created for Arm static library projects. - A file with the same name as the
project will, by default, be created and added to the project. It will contain the
- You can also use the Driver
Selection Wizard, invoked from Project → ASF
Wizard, to facilitate applications development and verification.In the ASF Wizard, you can select which Drivers, Components, and Services you would like to use in the project for the current build architecture and board.
- 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; }
- Build the project.