Ndless and C and assembly development introduction: Difference between pages

From Hackspire
(Difference between pages)
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
Line 1: Line 1:
��Ndless combines a resident program and utilities to open the TI-Nspire to third-party C and assembly development. Ndless is distributed under the Open Source [https://en.wikipedia.org/wiki/Mozilla_Public_License Mozilla Public License].
��This tutorial describes how to set up an environment and use the Ndless SDK to write native Ndless-compatible programs for the TI-Nspire.


The installation of Ndless on a TI-Nspire is required to be able to run [[Assembly_programs|assembly programs]].
==Install dependencies==
===On Linux distros===
* '''Make sure your system has the following dependencies''': git, GCC (with c++ support), binutils, GMP (libgmp-dev), MPFR (libmpfr-dev), MPC (libmpc-dev), zlib, boost-program-options, wget. Install them with your system's package manager if not.


Find help for any Ndless related question or issues on the [https://github.com/ndless-nspire/Ndless/issues issue tracker].
===On Mac OS X===
* TODO
* '''Make sure your system has the following dependencies''': git, GCC (with c++ support), binutils, GMP, MPFR, MPC, boost-program-options, zlib, wget. Install them with your system's package manager if not, for example brew.


'''[http://ndless.me/ Latest stable release]
===On Windows===
====Cygwin====
* MinGW and MSYS do not work correctly, so install Cygwin (32bit, x86).
* Install the following dependencies: php (5.6+), libboost-devel, libboost_program_options*, binutils, gcc-core, gcc-g++, git, mpfr, mpfr-devel, gmp, libgmp-devel, libmpc3, libmpc-devel, make, zlib-devel, wget
====Windows Subsystem for Linux====
* You can also use the Windows Subsystem for Linux. In this case, follow the instructions in the Linux section.


==Developing with Ndless==
==Build and install toolchain and SDK==
Tutorials and general information are available in the [[Main_Page#Development_resources|Development resources]] section.
*'''Get the latest code from [https://github.com/ndless-nspire/Ndless GitHub]'''
git clone --recursive https://github.com/ndless-nspire/Ndless.git


===Version upgrade===
* On Windows, fix the few symlinks, for instance zehn.h in the ndless-sdk/tools/genzehn folder, which has to be deleted then copied there from ndless-sdk/include (and if you intend to rebuild Ndless, utils.c from the resources folder into the different installers folders)
The executable format, the conventions and the header files are currently being defined and prone to change. Some changes are forced by This section describes the upgrade steps between the different releases of Ndless.


====To v4.4 r2005====
* '''Run the SDK's ''build_toolchain.sh'' '''script that will download and build a complete ARM toolchain compatible with Ndless, and install it (edit the <tt>PREFIX</tt> variable at the beginning of the script to change the install location). You don't need to be root for this.
*Should work directly for most programs if they don't contain any OS-version specific addresses (SYSCALL_CUSTOM(), hooks, etc.)
cd ndless-sdk/toolchain/
./build_toolchain.sh


====To v4.2 r2004====
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>0</tt> indicates success.
*HW rev. W introduced a new 240x320px screen which breaks most Ndless programs.
* Now '''add the following folders to your PATH environment variable'''. On linux, <tt>~/.bash_profile</tt> should be a good place for this, just add something like this to it:
*A new API to make use of the different screen is now available, SCREEN_BASE_ADDRESS is only available in OLD_SCREEN_API (Add the define to the compile options) mode. See [[Libndls#LCD_API|LCD API]] for information about the new API.
export PATH="[path_to_ndless]/ndless-sdk/toolchain/install/bin:[path_to_ndless]/ndless-sdk/bin:${PATH}"
*Nspire I/O and nSDL support the new screen, and programs that use them should work after recompilation.
* '''Build Ndless and the SDK''', in the top level of the repository, run:
make


====From v3.9 to v4.2====
===Verifying the installation===
*Should work directly for most programs if they don't contain any OS-version specific addresses (SYSCALL_CUSTOM(), hooks, etc.)
*Open a console, and run:
$ nspire-gcc
If everything has been set up correctly you should see something similar to:
arm-none-eabi-gcc: fatal error: no input files
compilation terminated.


====From v3.6 to v3.9====
==2-minute tutorial==
*Migration to newlib and libsyscalls. os.h and common.h shouldn't be used anymore. Use the standard C API directly.
As a convention for the next chapters, lines starting with <tt>$</tt> are commands you should type in a console. Other lines are the command's output.
*Introduction of the new [[Zehn]] format. Makefiles need to be updated to use [[Zehn#genzehn|genzehn]] and [[Zehn#make-prg|make-prg]].
===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 <tt>make</tt>. So let's ''make'' the program:
$ make
nspire-gcc -Wall -W -marm -Os -c hello-sdl.c
mkdir -p .
nspire-ld hello-sdl.o -o ./helloworld-sdl.elf
genzehn --input ./helloworld-sdl.elf --output ./helloworld-sdl.tns --name "helloworld-sdl"
make-prg ./helloworld-sdl.tns ./helloworld-sdl.prg.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'').


====From v2.0 to v3.1====
<tt>nspire-ld</tt> is the wrapper for ''GCC'', which redirects gcc with the option "-fuse-ld=gold" to use another wrapper "arm-none-eabi-ld.gold" as linker. "arm-none-eabi-ld.gold" adds some necessary libraries to the final program.
*Programs must be rebuilt to work on TI-Nspire CX because of several hardware changes. Programs with low-level accesses to hardware must also be slightly adapted: some hardware controllers have changed and their registers are laid out differently. The [[libndls#Hardware|IO() macro]] can be used to select the address corresponding to the TI-Nspire model.
**The LCD control register of the [[Memory-mapped_I/O_ports#C0000000_-_LCD_controller|LCD controller]] has moved from C000001C to C0000018. Use IO_LCD_CONTROL instead.
**The [[Memory-mapped_I/O_ports#900D0000_-_Second_timer|timer module]] has changed and has completely different registers
**Programs are run in color mode. Add ''clrscr(); lcd_ingray();'' at the beginning of a program ported from classic TI-Nspire to CX (the ''clrscr()'' avoids displaying color data that remains in screen buffer)
**Keep the TI-Nspire classic user base in mind: make your programs compatible with both color and grayscale mode with the help of ''has_color'' . The color screen buffer is in [[Memory-mapped_I/O_ports#A4000000_-_Internal_SRAM|R5G6B5 mode]].
*Programs which use ''show_msgbox()'' must be rebuilt with the new SDK, even for TI-NSpire classic
*SYSCALL_CUSTOM(): the first parameter should now only contain [[Ndless_features_and_limitations#Syscalls|OS v3.1 addresses]].


====From v1.7 to v2.0====
<tt>genzehn</tt> converts the executable created by "nspire-ld" to a format, which ndless supports.
* Touchpad key map support: rebuild your programs with the SDK of v2.0, which includes an updated <tt>isKeyPressed()</tt> function. Make sure that the programs do not depend on keys specific to the Clickpad.


====From v1.1.x to v1.7====
<tt>make-prg</tt> adds a simple loader on top so the executable works on older versions of ndless.


C and assembly programs:
===Your first program===
* The syscall convention has changed, programs built with Ndless < v1.7 need to be rebuilt without any change to the code. This format should be compatible with the new OS versions once supported by Ndless, as long as backward compatibility can be kept.
If you want to create a program from scratch:
* Custom syscalls should be defined using SYSCALL_CUSTOM (see above)
*Create a new directory for the program
* The "PRG\0" signature before main() isn't required anymore, you can remove it
*Type in a console:
* MakeTNS doesn't exist anymore. You must objcopy directly to the .tns file in your Makefile.
cd "<your directory path>"
* The program format is not specific to an hardware model anymore. You can now build your programs only once without defining NSPIRE_HARDWARE.
nspire-tools new <name>
* OS v1.1 is not supported anymore. Check that your programs still work on OS v1.7.
:where <name> is your program name. This will create a Makefile to build ''<program>.tns''
* The program path is passed to the main function by following the C calling convention instead of using register r9
*Create a new .c file and edit your program
 
*Run <tt>make</tt> to build it
Assembly programs:
* The way to call syscalls has changed: replace 'oscall <os_function>' with 'syscall(<os_function>)'
 
====From v1.0 to v1.1====
 
C and assembly programs:
* Install the toolchain as described above. Your project doesn't need to follow the Ndless file tree anymore.
* Adapt your Makefile based on src/arm/Makefile or src/arm/demo/Makefile
* You may upgrade to the latest version of YAGARTO. Don't forget to delete any remaining *.o file before rebuilding a project.
 
Pure-assembly programs:
* Make sure that the file extensions is in uppercase (.S)
* Add the "main" symbol as described in the previous section
* You do not need to define the symbol "_start" anymore

Revision as of 14:40, 21 June 2019

��This tutorial describes how to set up an environment and use the Ndless SDK to write native Ndless-compatible programs for the TI-Nspire.

Install dependencies

On Linux distros

  • Make sure your system has the following dependencies: git, GCC (with c++ support), binutils, GMP (libgmp-dev), MPFR (libmpfr-dev), MPC (libmpc-dev), zlib, boost-program-options, wget. Install them with your system's package manager if not.

On Mac OS X

  • TODO
  • Make sure your system has the following dependencies: git, GCC (with c++ support), binutils, GMP, MPFR, MPC, boost-program-options, zlib, wget. Install them with your system's package manager if not, for example brew.

On Windows

Cygwin

  • MinGW and MSYS do not work correctly, so install Cygwin (32bit, x86).
  • Install the following dependencies: php (5.6+), libboost-devel, libboost_program_options*, binutils, gcc-core, gcc-g++, git, mpfr, mpfr-devel, gmp, libgmp-devel, libmpc3, libmpc-devel, make, zlib-devel, wget

Windows Subsystem for Linux

  • You can also use the Windows Subsystem for Linux. In this case, follow the instructions in the Linux section.

Build and install toolchain and SDK

  • Get the latest code from GitHub
git clone --recursive https://github.com/ndless-nspire/Ndless.git
  • On Windows, fix the few symlinks, for instance zehn.h in the ndless-sdk/tools/genzehn folder, which has to be deleted then copied there from ndless-sdk/include (and if you intend to rebuild Ndless, utils.c from the resources folder into the different installers folders)
  • Run the SDK's build_toolchain.sh script that will download and build a complete ARM toolchain compatible with Ndless, and install it (edit the PREFIX variable at the beginning of the script to change the install location). 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 $?. 0 indicates success.

  • Now add the following folders to your PATH environment variable. On linux, ~/.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 Ndless and the SDK, in the top level of the repository, run:
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: fatal error: no input files
compilation terminated.

2-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
nspire-gcc -Wall -W -marm -Os -c hello-sdl.c
mkdir -p .
nspire-ld hello-sdl.o -o ./helloworld-sdl.elf 
genzehn --input ./helloworld-sdl.elf --output ./helloworld-sdl.tns --name "helloworld-sdl"
make-prg ./helloworld-sdl.tns ./helloworld-sdl.prg.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 GCC, which redirects gcc with the option "-fuse-ld=gold" to use another wrapper "arm-none-eabi-ld.gold" as linker. "arm-none-eabi-ld.gold" adds some necessary libraries to the final program.

genzehn converts the executable created by "nspire-ld" to a format, which ndless supports.

make-prg adds a simple loader on top so the executable works on older versions of 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 <name>
where <name> is your program name. This will create a Makefile to build <program>.tns
  • Create a new .c file and edit your program
  • Run make to build it