Author Topic: Tutorial - Setting up C Development Environment for the TI-Nspire  (Read 65611 times)

0 Members and 2 Guests are viewing this topic.

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
TI-Nspire C Development Set Up For Ndless Version 1.7

Many people on this website, including myself, have had questions/problems on setting up a C development environment for the TI-Nspire. Because of this, I thought I would write this tutorial to clearly describe the steps to set up a development environment, compile a file, and describe some of the common errors when compiling.

Setting up a Windows C development environment

Two programs are needed for a Windows C development environment:  MSYS, and the YAGARTO toolchain.  You will also need a copy of Ndless for some tools needed to compile.

First, you must install MSYS, which is, according to its website "MSYS, a contraction of "Minimal SYStem", is a Bourne Shell command line interpreter system. Offered as an alternative to Microsoft's cmd.exe, this provides a general purpose command line environment, which is particularly suited to use with MinGW, for porting of many Open Source applications to the MS-Windows platform; it includes a small selection of Unix tools, chosen to facilitate that objective, and using it is a necessary prerequisite for building mingwPORTs."  Here is the link to install MSYS.

http://sourceforge.net/projects/mingw/files/MSYS/BaseSystem/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download

Then, you must install YAGARTO, which is a GNU ARM toolchain for Windows.  When you install, make sure the box "Add YAGARTO's to your PATH variable" is checked.  Here is the link.

http://sourceforge.net/projects/yagarto/

Finally, you have to add the Ndless /sdk/bin Directory to your path variable.  If you are running Windows Vista or Windows 7, you can add to the Path variable by press the "Windows" key.  Then, type Path in the search field and choose option two, "Edit the system environment variables".  A dialog box should open up; click "Environment Variables" near the bottom of the dialog box.  A new dialog box should pop up; in the second field, navigate to the "Path" variable and click "edit", then add the Ndless /sdk/bin directory to the end of the list.

To confirm that you have successfully added to the path variable, open the command prompt and type:

Code: [Select]
echo %path%

It should be at the end of the list.

You now have all of the components needed for a C development environment for Windows.  In the next section, I will explain how to compile a file.

Compiling a file

For this example, we will compile the Ndless demo.  First, it is probably best to start with a fresh copy of Ndless, which can be downloaded from the following link.  After you download, unzip the file and remember the file directory to the folder.  You will need this soon.

http://www.ticalc.org/archives/files/fileinfo/426/42626.html

Now, open MSYS and set the current directory to the folder in Ndless that contains the Ndless demo.  Do this by typing "cd <Place Ndless folder path here>/src/samples/particles.  Now type "make".  The Ndless demo should have successfully compiled! You should have received the message:

Code: [Select]
$ make
nspire-gcc -Os -Wall -W -c main.c
nspire-gcc -Os -Wall -W -c utils.c
nspire-gcc -Os -Wall -W -c vector.c
nspire-gcc -Os -Wall -W -c particle.c
nspire-gcc -Os -Wall -W -c particle_system.c
nspire-gcc -Os -Wall -W -c gravity_particles.c
nspire-ld  main.o utils.o vector.o particle.o particle_system.o gravity_particles.o -o particles.elf
arm-none-eabi-objcopy -O binary particles.elf ../../calcbin/samples/particles.tns

If you received this message, or something close to it, you are now ready to start developing in C for the Nspire!  The easiest way to do so is simply to edit the "main.c" file.  Look in the files "common.h", "utils.h", and "os.h" to find commands you can use.  Likewise, there are several functions in the Nspire libraries, which are documented at hackspire.  Also, there are some very useful header files in the tread "Post your Nspire routines here" here at Omnimaga.  If you did not receive this message shown above, you probably received an error message.  In the next section, I will list common error messages and methods to fix them.

Common Error Messages

If you are getting an error message about a file not being found (such as MakeTNS.exe, FlashEdit.exe, nsprie-gcc), make sure you added the bin/ of Ndless to your path variable.  Check this by opening a command prompt window and typing:

Code: [Select]
echo %PATH%

Note:  If you are attempting to build Ndless and you are getting errors, please ensure that the following directories are in your path:
1. MSYS /bin
2. MinGW /bin
3. Ndless Root /bin (created by "make" in the tools directory of Ndless)
4. 7zip Root
5. YAGARTO /bin

If the Ndless /sdk/bin/ directory is not listed in the %PATH% list, follow the procedure above to add it.

If your error message is not listed here, or you have any other questions about the instillation process, feel free to post a reply below and I will try to edit this post and add new error messages here. Thank you!  Good luck developing!

Also, If you do not like using notepad/wordpad to type your code in a text editor with colorized syntax, you can use different text editors such as gedit, Programmers Notepad 2, and Notepad++, all of which have syntax highlighting for C code.

In addition, you can also use the Eclipse C/C++ IDE for developing Ndless programs.  More information on setting up this IDE, and linking it with the GDB Debugging support incorporated into the TI-Nspire Emulator Ncubate can be found in this video on YouTube:

« Last Edit: February 23, 2011, 09:31:25 pm by apcalc »


Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #1 on: July 10, 2010, 01:17:37 pm »
I found it easier to install YAGARTO tools (at least in windows), which can be run from cmd.exe, so I can just create a batch file that just contains "make".
Download YAGARTO tools:
http://www.yagarto.de/download/yagarto/yagarto-tools-20100703-setup.exe
« Last Edit: July 10, 2010, 01:51:57 pm by fb39ca4 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #2 on: July 10, 2010, 02:48:27 pm »
Nice that should be useful :D

Thanks apcalc fro posting this :D
« Last Edit: July 10, 2010, 02:48:40 pm by DJ Omnimaga »

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #3 on: July 10, 2010, 03:39:30 pm »
Excellent :)
This should be stickied. Someday, this sub-forum will have many threads in it, and this tutorial will be hard to find.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #4 on: July 10, 2010, 10:54:53 pm »
Stickied

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #5 on: July 11, 2010, 01:36:20 am »
Some fixes and improvements to the Ndless demo Makefile were performed after Ndless 1.0, in the public part of the SVN repository.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline qazz42

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1130
  • Rating: +30/-12
  • hiiiiiiiii
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #6 on: July 22, 2010, 02:27:03 pm »
ok I am having a problem, as seen in this video




Heck with it, can someone give the the source code for saying "hello world", that is compatible with the nspire, if I can just make that I can go from there.
« Last Edit: July 22, 2010, 02:45:19 pm by qazz42 »

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #7 on: July 22, 2010, 04:07:09 pm »
You should start by trying to compile the Ndless demo with no modifications. If that works, you know your dev environment is working.
Like so:
Code: [Select]
cd <ndless root directory>/src/arm/demo
make
Post any errors you get here.
Alternatively, you can grab skeleton-windows.zip from the first post here, unzip it, cd to the directory it unzipped to, and run 'make'. This has the advantage containing only what you need to compile, which makes it easier to distribute your sources when you release.
« Last Edit: July 22, 2010, 04:18:14 pm by bwang »

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #8 on: July 22, 2010, 04:11:09 pm »
You should use YAGARTO, it's much more windows-friendly.

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #9 on: July 22, 2010, 05:24:22 pm »
qazz, in the video, you are typing "make test".  Try only typing "make", then press enter.  When I type "make main", I get the same error message.  Also, here is the code for a program that will display "Hello World" in a dialog box:

Code: [Select]
#include <os.h>
#include "utils.h"

asm(".string \"PRG\"\n");

int main(void) {
showSimpleDialogBox("Hello World!","Hello World");
return 0;
}

Also, attached is a .tns file of that code compiled.


Offline qazz42

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1130
  • Rating: +30/-12
  • hiiiiiiiii
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #10 on: July 22, 2010, 05:44:17 pm »
If I say make, it says no target specified

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #11 on: July 22, 2010, 05:46:37 pm »
If I say make, it says no target specified

Did you successfully compile the Ndless demo.

In MSYS, type:

Code: [Select]
cd <Path to Ndless directory>/src/arm/demo
make

Post the message you get.


Offline qazz42

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1130
  • Rating: +30/-12
  • hiiiiiiiii
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #12 on: July 22, 2010, 06:08:23 pm »
Yes I have

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #13 on: July 22, 2010, 06:10:10 pm »
Ok, If you have successfully compiled the Ndless, demo, try opening the main.c file in the demo, erase the contents, and replace it with the code for the "hello world" program above.  You may just not have the right header files in the directory to compile


Offline qazz42

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1130
  • Rating: +30/-12
  • hiiiiiiiii
    • View Profile
Re: Tutorial - Setting up C Development Environment for the TI-Nspire
« Reply #14 on: July 22, 2010, 08:57:35 pm »
Apcalc, here is my result