MEAM.Design - M4 - Getting Started in OS X



Install Xcode

Download and install the latest Xcode Tools from the Apple Developer Connection (note - you will need to register for a free ADC account). You could also install these from the DVD that came with your machine, if you have it.

Note: If you install Xcode 4.3 or above, you will also need to do the following:

1. Start XCode, and open "Preferences..." from the "XCode" menu.

2. Switch to the "Downloads" tab, then click the "Install" button on the "Command Line Tools" row.


Install ARM GCC Compiler binaries

1. Download the GCC-ARM-Embedded Binaries for Mac from here

2. Extract the tar file you downloaded

3. Rename the extracted folder to "gcc-arm-none-eabi"

3. Assuming the extracted folder is in the Downloads folder you can just execute the following commands in terminal:

	ditto ~/Downloads/gcc-arm-none-eabi /usr/local/bin/gcc-arm-none-eabi

	echo export PATH=$PATH:/usr/local/bin/gcc-arm-none-eabi/bin >> ~/.profile

	export PATH=$PATH:/usr/local/bin/gcc-arm-none-eabi/bin


Install libusb driver and dfu-util

If you don't have brew package manager, install it by executing the following in terminal:

	ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Then just execute the following in terminal:

	brew install dfu-util 

and this will install and configure everything for you and you can skip to the 'Compile Source Code' step.

If you don't want to use brew you could just download the individual packages for libusb and dfu-util and install them as shown below (you might need to install dependencies if its not found on your system)

1. Install libusb

2. Install dfu-util by entering the following commands in terminal:

	cd ~/Downloads
	git clone git://gitorious.org/dfu-util/dfu-util.git
	cd dfu-util
	./autogen.sh
	./configure 
	sudo make install


Compile Source Code

1. Download the template code which contains all the libraries. (Note if you have Green M4 edit the Makefile and change -DM4_WHITE to -DM4_GREEN)

2. Place your source files (*.c) in "m4Template/src" folder OR "m4Template" folder

3. Place your header files (*.h) in "m4Template/inc" folder OR "m4Template" folder

4. Navigate terminal to m4Template folder and execute:

	make

5. Last line should look something like

	[>--BinaryGenerated--<]


Upload your code

1. Connect the microcontroller to the computer, hold the onboard button until the Orange LED is on (about two seconds), then release it.

2. Execute the following in terminal

	make flash 

3. Last lines should read

	[>--^--M4 Loaded--^--<]

Running your code

1. Tap the onboard button for less than two seconds, the orange LED should turn off, and your code should run.


Note:

You can also call make with following arguments

	make clean -- cleans all the object files of user source files 
	make cleanlib -- cleans all object files for the library and user source files
	make flash -- upload code using USB DFU Bootloader
	make disassemble -- generates .dis and .dmp file for debug purposes


----
Xcode Extras

Follow these hints to create an Xcode project template for the M4. Note: the following setup is verified with OS-X 10.6.8 and Xcode 3.2.6. For other versions, directory structures, etc. may vary.

1. In the directory "/Developer/Library/Xcode/Project Templates", you will find the standard templates that Xcode displays when you go to create a new project. In here, add a new directory called "Microcontrollers" (or any other fitting name), and within that, create a new directory called "M4 Project". Copy the m4Template into this folder, and rename it as "firmware".

2. From within Xcode, create a new "Empty Project" (this should be listed under "Other" in the Xcode menu). Put the project in a temporary folder and call it whatever you like. Save, and close.

3. Move the newly created *.xcodeproj file into the "M4 Project" directory, and rename it as "___PROJECTNAME___.xcodeproj".

4. From its new location, open the project. Right-click "___PROJECTNAME___" in the toolbar, and select "Add -> Existing Files..." Browse into the "M4 Project" directory, to "src/main.c" and click "Add".

5. Repeat the above step to add "M4 Project/inc/mGeneral.h".

6. Now right-click and select "Add -> New Target...". Select "External Target", and click "Next". Name the target "build" and click "Finish".

7. Double-click the new target, "build", and enter the following, then close:

Build Tool: /usr/bin/make
Arguments: all
Path: $(PATH):/usr/local/bin/gcc-arm-none-eabi/bin

8. Right-click "build" and select "Build "build"". If everything is done right, your code should now compile.

9. Repeat steps 6-8 to create a new target called "flash", with the following parameters:

Build Tool: /usr/bin/make
Arguments: flash
Path: $(PATH):/usr/local/bin/gcc-arm-none-eabi/bin:/usr/local/bin.

10. Plug in an M4 and test.

11. To take this a bit further, go browse around in other project templates; right-click on the .xcodeproj file and select "Show Package Contents". This should show you enough to learn how to set the project description and the icon that show up when Xcode displays it, if you so desire.

Note: If you encounter issues you can't resolve, please let Noam know.