C and assembly development introduction: Difference between revisions
(Docker image moved to ndless organization) |
(Up to date with Ndless's github repo) |
||
Line 17: | Line 17: | ||
git clone git://github.com/OlivierA/Ndless.git | git clone git://github.com/OlivierA/Ndless.git | ||
* '''Make sure your system has the following dependencies''': GMP (libgmp-dev), MPFR (libmpfr-dev), MPC (libmpc-dev) and wget. Install them with your system's package manager if not. | * '''Make sure your system has the following dependencies''': GMP (libgmp-dev), MPFR (libmpfr-dev), MPC (libmpc-dev) and wget. Install them with your system's package manager if not. | ||
* '''Run the SDK's ''build_toolchain.sh'' '''script that will download and build a complete ARM toolchain compatible with Ndless, and install it to | * '''Run the SDK's ''build_toolchain.sh'' '''script that will download and build a complete ARM toolchain compatible with Ndless, and install it to ndless_toolchain/install (edit the <tt>PREFIX</tt> variable at the beginning of the script to change this). You don't need to be root for this. | ||
cd | cd ndless-sdk/toolchain/ | ||
./build_toolchain.sh | ./build_toolchain.sh | ||
Running the script again will continue from the last successful step (not redownloading everything for instance). At the end of a successful build you should see <tt>Done!</tt>. Alternatively you can verify the build using <tt>echo $?</tt>. <tt>1</tt> indicates a failure. | Running the script again will continue from the last successful step (not redownloading everything for instance). At the end of a successful build you should see <tt>Done!</tt>. Alternatively you can verify the build using <tt>echo $?</tt>. <tt>1</tt> indicates a failure. | ||
* Now | * Now '''add the following folders to your PATH environment variable'''. <tt>~/.bash_profile</tt> should be a good place for this, just add something like this to it: | ||
export PATH="[path_to_ndless]/ndless-sdk/toolchain/install/bin:[path_to_ndless]/ndless-sdk/bin:${PATH}" | |||
export PATH=" | |||
* '''Build the SDK''', only if you are using the GitHub's clone version of the SDK: | * '''Build the SDK''', only if you are using the GitHub's clone version of the SDK: | ||
make | make | ||
Line 35: | Line 32: | ||
If everything has been set up correctly you should see something similar to: | If everything has been set up correctly you should see something similar to: | ||
arm-none-eabi-gcc: no input files | arm-none-eabi-gcc: no input files | ||
==5-minute tutorial== | ==5-minute tutorial== | ||
Line 46: | Line 38: | ||
Ndless comes with sample programs in the ''_samples/'' directory of the Ndless SDK. We will try to build the C Hello World. | Ndless comes with sample programs in the ''_samples/'' directory of the Ndless SDK. We will try to build the C Hello World. | ||
Change the current directory of the console: | Change the current directory of the console: | ||
$ cd "<my_ndless_sdk_copy>/ | $ cd "<my_ndless_sdk_copy>/ndless-sdk/samples/helloworld-sdl" | ||
Ndless programs are built with ''GNU Make'', which is run with the command <tt>make</tt>. So let's ''make'' the program: | |||
$ make | $ make | ||
nspire-gcc -Wall -W -marm | rm -f *.o *.elf | ||
rm -f ./helloworld-sdl.tns | |||
nspire-gcc -Os -Wall -W -marm -c hello-sdl.c | |||
mkdir -p . | mkdir -p . | ||
nspire-ld | nspire-ld hello-sdl.o -o ./helloworld-sdl.tns | ||
<tt>nspire-gcc</tt> is Ndless's wrapper for the GNU C Compiler ''GCC'', which compiles C and assembly source files to object files (here ''hello.o''). | <tt>nspire-gcc</tt> is Ndless's wrapper for the GNU C Compiler ''GCC'', which compiles C and assembly source files to object files (here ''hello.o''). | ||
<tt>nspire-ld | <tt>nspire-ld</tt> is the wrapper for the GNU linker ''ld'', which combines object files to produce an executable in a format supported by Ndless. | ||
===Your first program=== | ===Your first program=== | ||
If you want to create a program from scratch: | If you want to create a program from scratch: | ||
*Create a new directory for the program | *Create a new directory for the program | ||
Line 100: | Line 59: | ||
*Create a new .c file and edit your program | *Create a new .c file and edit your program | ||
*Run the <tt>make</tt> command to build it | *Run the <tt>make</tt> command to build it | ||
Revision as of 22:12, 15 August 2014
This tutorial describes how to set up an environment and use the Ndless SDK to write native Ndless-compatible programs for the TI-Nspire on Linux.
If you are looking for a Windows tutorial, get one in the development resources of ndlessly.
This article is written for the Ndless SDK v3.6 and higher.
Setting up a development environment
Option 1 : Get the Ndless SDK Docker image
Docker is a platform to build and share applications through lightweight containers. The Ndless SDK Docker image packs the Ndless SDK and all its dependencies. This is the easiest and quickest method to get a fully functional development environment.
To install the Ndless SDK Docker image follow the instructions on hub.docker.com. If you don't have Docker, don't know much of Docker or prefer to use a standard installation, skip to Option 2.
Option 2 : Building and installing the toolchain and the SDK
- Get the latest Ndless SDK build for C, C++ and assembly development on TI-Nspire.
- You may also prefer to use the freshest in-development version of the Ndless SDK from GitHub. Just git-clone it:
git clone git://github.com/OlivierA/Ndless.git
- Make sure your system has the following dependencies: GMP (libgmp-dev), MPFR (libmpfr-dev), MPC (libmpc-dev) and wget. Install them with your system's package manager if not.
- Run the SDK's build_toolchain.sh script that will download and build a complete ARM toolchain compatible with Ndless, and install it to ndless_toolchain/install (edit the PREFIX variable at the beginning of the script to change this). You don't need to be root for this.
cd ndless-sdk/toolchain/ ./build_toolchain.sh
Running the script again will continue from the last successful step (not redownloading everything for instance). At the end of a successful build you should see Done!. Alternatively you can verify the build using echo $?. 1 indicates a failure.
- Now add the following folders to your PATH environment variable. ~/.bash_profile should be a good place for this, just add something like this to it:
export PATH="[path_to_ndless]/ndless-sdk/toolchain/install/bin:[path_to_ndless]/ndless-sdk/bin:${PATH}"
- Build the SDK, only if you are using the GitHub's clone version of the SDK:
make
Verifying the installation
- Open a console, and run:
$ nspire-gcc
If everything has been set up correctly you should see something similar to:
arm-none-eabi-gcc: no input files
5-minute tutorial
As a convention for the next chapters, lines starting with $ are commands you should type in a console. Other lines are the command's output.
Your first build
Ndless comes with sample programs in the _samples/ directory of the Ndless SDK. We will try to build the C Hello World. Change the current directory of the console:
$ cd "<my_ndless_sdk_copy>/ndless-sdk/samples/helloworld-sdl"
Ndless programs are built with GNU Make, which is run with the command make. So let's make the program:
$ make rm -f *.o *.elf rm -f ./helloworld-sdl.tns nspire-gcc -Os -Wall -W -marm -c hello-sdl.c mkdir -p . nspire-ld hello-sdl.o -o ./helloworld-sdl.tns
nspire-gcc is Ndless's wrapper for the GNU C Compiler GCC, which compiles C and assembly source files to object files (here hello.o).
nspire-ld is the wrapper for the GNU linker ld, which combines object files to produce an executable in a format supported by Ndless.
Your first program
If you want to create a program from scratch:
- Create a new directory for the program
- Type in a console:
cd "<your directory path>" nspire-tools new <program>
- where <program> is your program name. This will create a Makefile to build <program>.tns
- Create a new .c file and edit your program
- Run the make command to build it