MINDSTORMS TUTORIAL ESWEEK 2009 Module NXT http://nxtgcc.sf.net TUTORIAL

Outline

ESWEEK 2009 http://nxtgcc.sf.net Rasmus Ulslev Pedersen [email protected]

Please sit close to the screen: there will be lots of small code shown... NXT.1 LEGO MINDSTORMS Presentation Overview TUTORIAL ESWEEK 2009 http://nxtgcc.sf.net Overview Non-technical overview of LEGO MINDSTORMS c NXT from a community and user standpoint

HW and SW Description of NXT hardware and Outline software from a developer perspective Examples (1) Using TinyOS as a firmware, (2) an intelligent algorithm Q&A There will be time for discussion and future research ideas Lab Drawing for the NXT 2.0 and lab exercise using it Note 1: LEGO has sponsored a NXT 2.0 kit Note 2: LEGOr, MINDSTORMSrare trademarks of LEGOr. The tutorial contains pictures from ARM7 documentation, and from LEGO documentation. Note 3: There is additional material included: Many slides are supplementary and included for future reference.

NXT.2 LEGO MINDSTORMS

ESWEEK 2009 http://nxtgcc.sf.net Module NXT LEGO MINDSTORMS

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

ESWEEK 2009 http://nxtgcc.sf.net Rasmus Ulslev Pedersen [email protected]

NXT.1 Outline LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

1 Aim of Tutorial

2 Introduction

Outline 3 Open Source Aim of Tutorial Introduction 4 Sensors Open Source Sensors 5 Inside NXT C 101 Inside NXT C 101 Firmware Programming 6 Firmware Programming ARM7 NXT Software 7 ARM7 Debugging NXT

8 NXT Software

9 Debugging NXT

NXT.2 Aim LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• How the open source universe around Lego Mindstorms NXT is structured Outline Aim of Tutorial

• Talk about a world that stretches from high-schools to Introduction adults and from building bricks to programming in Open Source assembler Sensors • Emphasis on the overview and the programming aspects Inside NXT C 101 Firmware • Participants will be able to see where in the NXT Programming programming spectrum their interest match most ARM7 NXT Software

• Use the tutorial to get started with open source Debugging NXT programming on NXT

NXT.3 Introduction LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline • Description of open source hardware and software Aim of Tutorial Introduction • LEGO business models are discussed Open Source • The old RCX Sensors • NXT in several (online) communities Inside NXT C 101 Firmware • Overview of how NXT can be programmed in different Programming environments ARM7 NXT Software

Debugging NXT

NXT.4 Some Mindstorms History LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• 10 years since Mindstorms was released Outline • First LEGO Mindstorms was the LEGO RCX: Successful Aim of Tutorial Introduction • LEGO intended it to be a closed source product, but... Open Source • It was soon hacked:-) Sensors Inside NXT C 101

• The open source strategy was pursued even more with the Firmware present LEGO Mindstorms Programming ARM7

• A Goldplated NXT and a limited edition Black NXT was NXT Software

produced in relation to the 10 year anniversary Debugging NXT

NXT.5 NXT Development LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Development of NXT started in the 2004

• Initial group was Ralph, Steven, John, and David Outline • First prototypes were circulated on a limited number basis Aim of Tutorial inside the current MUP group and a select few outside that Introduction Open Source group Sensors • MUP: Jan 2006, 5 people Inside NXT C 101 Firmware • MUP II: Nov. 2005, 11 people Programming • MDP: 2006 ARM7 NXT Software • MCP 2: 31 persons, 100 chosen from 10000 applicants Debugging NXT • MCP 3: 2008-2009 • MCP 4: Next slide

NXT.6 LEGO Design Routines LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Lego has a group of people who has the privilege of talking directly to LEGO staff Outline Aim of Tutorial • Under non-disclosure Introduction

agreements (NDA) Open Source • First group of MCPs Sensors (MUP) were a select Inside NXT C 101 Firmware group Programming • Used as a sounding ARM7 board for the ideas that NXT Software went into developing the Debugging NXT first LEGO MINDSTORMS NXT. • MCP 4 is commencing as we speak

NXT.7 Lego Education LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline • Lego has a website for educational activities Aim of Tutorial • Strong focus on university segment Introduction • LEGO MINDSTORMS NXT comes in educational sets Open Source Sensors

• Rechargeable battery and extra building pieces Inside NXT C 101 • Firmware Sold with site licences that accompany the NXT Programming • Different sales curve from retail (slow start, longer product ARM7 life) NXT Software Debugging NXT

NXT.8 Mindstorms Community LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• MINDSTORMS Outline

community is large and Aim of Tutorial

diverse Introduction • Blogs, forums, large Open Source events, books, the MCP Sensors program and more Inside NXT C 101 Firmware • NXTStep and the Programming NXTasy blogs ARM7 NXT Software • Lugnet is a large LEGO Debugging NXT fanclub

NXT.9 Schools LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Many schools participate in First LEGO League Outline Aim of Tutorial

• A tournament where Introduction current theme is played Open Source out Sensors • The idea is to have Inside NXT C 101 Firmware adults lead or mentor a Programming team of children aged ARM7 9-14 (16 outside the US) NXT Software Debugging NXT • NXT is used to complete a challenge put out by the FLL management

NXT.10 Business Models LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• LEGO earns money on NXT by selling the kit itself • Licences to educational institutions are also revenue Outline source Aim of Tutorial Introduction

• First version of LEGO MINDSTORMS NXT was released Open Source

in the beginning of 2007 Sensors • A second version appeared in the fall of 2009 (biannual Inside NXT C 101 Firmware release schedule:-)?) Programming • NXT 2.0 is shipped with a different set of standard sensors ARM7 (color sensor) NXT Software Debugging NXT • Spring releases at toys fairs which is then ready for Christmas sale

NXT.11 LEGO SYSTEMS LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• LEGO partly produce and package NXT on

their factory in Billund Outline • Staff around NXT Aim of Tutorial development is not big Introduction Open Source

• Firmware development Sensors team is in control of the Inside NXT C 101 software development Firmware Programming • National Instruments ARM7 (NI) designs the NXT-G NXT Software environment Debugging NXT • The careful selection of close partners makes for long-time stability

NXT.12 Firmware Releases LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

• NXT is a complex product compared to other LEGO Aim of Tutorial products Introduction • Requires focus on quality Open Source Sensors

• Updated versions released on the official MINDSTORMS Inside NXT C 101 website (http://mindstorms.lego.com) Firmware Programming

• First firmware had the version number 1.1 (or 1.0...) and ARM7

the current released version for NXT 2.0 is versioned 1.28 NXT Software

Debugging NXT

NXT.13 Partners LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net • Many institutions, companies, groups, and individuals have a stake in NXT • National Instruments is Outline presumably the most Aim of Tutorial Introduction

important Open Source • MIT, Tuft, Carnigie Sensors Mellon, and others are Inside NXT C 101 Firmware also active Programming • Others such as ARM7 nxtprograms NXT Software Debugging NXT • Number of large events • This includes Brickfest • There has also been a MINDSTORMS NXT Sumo Competition NXT.14 NXT Alternatives LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• NXT is not completely alone...

• Sun Spots from Outline Sun/Oracle Aim of Tutorial • Fisher-Technic offers a Introduction new controller Open Source Sensors which is is based on an Inside NXT C 101

ARM9 processor Firmware running at 200MHz Programming ARM7 • Various evaluation kits: NXT Software

mbed, IAR, etc. Debugging NXT • However, it is difficult to match dealer network, community, and

NXT.15 Source and Documents by LEGO LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

NXT Firmware Open Source Complete software for the NXT firmware, which can be compiled with a compliant C Outline Aim of Tutorial

Software Developer Kit A kit with software for controlling NXT Introduction

remotely from a host . It includes a Open Source

description of the NXT virtual machine. Sensors Hardware Developer Kit Description of the possible sensor Inside NXT C 101 Firmware and actuator interfaces for NXT. This is Programming extensively used by thirdparty sensor vendors. ARM7 Bluetooth Developer Kit It includes the communication protocol NXT Software for controlling NXT over a Bluetooth connection. Debugging NXT Demo Show PDF files which are important for firmware replacements...

NXT.16 Schematics LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial

• Lego published the schematics Introduction • Can see which pins of the ARM7 MCU is connected to Open Source what ports Sensors Inside NXT C 101

• Lego uses Orcad for its schematics, which is a commercial Firmware program Programming ARM7

NXT Software

Debugging NXT

NXT.17 Analog/Digital Protocols LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• NXT features both analogue and digital interfaces to its Outline

sensors. Aim of Tutorial • Sensors are based on an analogue to digital conversion Introduction Open Source • Signals are fed into the ARM processor for further Sensors

processing Inside NXT C 101 • Digital sensors are made with an I2C compliant protocol Firmware Programming • I2C is a two wire protocol that allows for a number of ARM7 devices on the shared bus NXT Software • It can be monitored with a logical probe Debugging NXT

NXT.18 NXT-G Blocks LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• LEGO provides a proprietary programming language for Outline LEGO MINDSTORMS NXT called NXT-G Aim of Tutorial Introduction

• G implies it is a graphical programming language Open Source • Places NXT-G programming blocks in a sequence that Sensors involves the usual programming constructs such as loops, Inside NXT C 101 Firmware branches and computations Programming • Tutorials and small videos with instructions for a given task ARM7 NXT Software • Show Robocup NXT-G program in NXT-G... Debugging NXT

NXT.19 Firmware Source LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• LEGO MINDSTORMS NXT comes with an open source Outline

operating system Aim of Tutorial • Operating system is written in ANSI C Introduction Open Source • Source code fundamentally access the physical layer such Sensors

as input and output ports of the ARM processor Inside NXT C 101 • Firmware Another part provides an abstraction layer to these Programming

services (Show the HPL, HAL files...) ARM7 • Operating system is a traditional round robin scheduler NXT Software Debugging NXT • Services each a number of modules

NXT.20 Modules Overview LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Each module is centered on a logical or a physical unit in Outline NXT Aim of Tutorial Introduction

• Example: the display or the user interface Open Source • The virtual machine a logical module Sensors • Each time the virtual machine is serviced it can/will Inside NXT C 101 Firmware execute a number of bytecodes Programming • A 1 ms period (system tick) services all modules ARM7 NXT Software

• Show scheduler... Debugging NXT

NXT.21 Fantom PC/Mac Interface LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• LEGO has released an interface both for the PC and the Outline Macintosh Aim of Tutorial • Linux is not supported at this point Introduction Open Source

• Firmware image in NXT is updated via a USB cable Sensors connection Inside NXT C 101 Firmware • NXT is programmed from NXT-G either over USB or Programming

Bluetooth ARM7 • We will revisit this Fantom DLL when GNU debugger is NXT Software discussed Debugging NXT

NXT.22 Sensor Partners and Independent Manufactures LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• A limited number of third-party sensors exists • Hitechnic, Mindsensors, Outline and Vernier Aim of Tutorial Introduction

• Hitecnic produces its Open Source sensors in a standard Sensors LEGO sensor housing Inside NXT C 101 Firmware • Mindsensors make its Programming sensors available in ARM7 Vernier different shapes and r NXT Software forms Debugging NXT • Vernier specializes in natural sciences experiments • DCP

NXT.23 Standard Sensors LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline • Input and output ports Aim of Tutorial feature a 6-wire RJ12 Introduction connector Open Source Sensors • (a) Light (b) Motor (c) Sound Ultrasonic distance Inside NXT C 101

measurement sensor, a Firmware light intensity sensor, a Programming sound sensor, a touch ARM7 NXT Software sensor, and motors (d) Touch (e) Ultra (f) NXT-G Debugging NXT Standard Lego Mindstorms NXT sensors and a NXT-G block

NXT.24 Mindsensors LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Camera

• Realtime Clock Outline • Acceleration (2,3, and 5 axis reading) Aim of Tutorial Introduction

• Dual Infra Red Obstacle Detector Open Source • Motor Multiplexer for NXT Sensors • Magnetic compass Inside NXT C 101 Firmware • Pneumatic Pressure Sensor Programming ARM7

• High Precision Infrared distance sensor (short, medium, NXT Software

long range) Debugging NXT • Various accessories: port splitter, cables, plugs, sensor kit, tools

NXT.25 Selected NXT sensors from Mindsensors LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

(g) Multi-axis (h) Magnetic Outline acc. compass Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

(i) Pneumatic (j) Infrared ARM7

pressure distance NXT Software

Debugging NXT

(k) Sensor buil- (l) Temperature ding kit NXT.26 Hitechnic LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Prototype Board Outline • Gyro Aim of Tutorial Introduction

• IR seeker Open Source • Compass Sensors Inside NXT C 101 • Color sensor Firmware • Acceleration/tilt Programming ARM7

• Sensor and motor multiplexer NXT Software • Accessories: Cables Debugging NXT

NXT.27 Sensors from Hitechnic LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction (m) Color (n) Gyro Open Source Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

(o) Multiplexer (p) Prototyping board

If you don’t think "How fast can I get these sensors...", then something is wrong:-)"

NXT.28 Custom Sensors LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• It is possible to create custom sensors • EAGLE is a CAD Outline program for creating Aim of Tutorial specialized PCBs Introduction Open Source

• The PCBs can be Sensors fabricated at places Inside NXT C 101 such as Olimex. Firmware Programming • Olimex accepts EAGLE ARM7 files (probably easier NXT Software than Gerber files) Debugging NXT • Sensors can be prototyped for under $50

NXT.29 EAGLE LEGO MINDSTORMS ESWEEK 2009 It is easy to modify a schematic in EAGLE http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.30 Create a (non-functional...) Demo Temperature Sensor LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

• Select components Aim of Tutorial • Take some pin header Introduction Open Source • Search for termistor and Sensors

add it Inside NXT C 101 • Firmware Wire it Programming • Try ARM7 File->Run->bom.ulp NXT Software Debugging NXT

NXT.31 Create a Temperature Sensor LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source • Try Sensors File->Run->bom.ulp Inside NXT C 101 Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.32 Create a Temperature Sensor LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

• Create the board Sensors • File->Switch to Inside NXT C 101 Firmware board Programming

ARM7

NXT Software

Debugging NXT

NXT.33 Create a Temperature Sensor LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Take Tools->Auto... Outline Aim of Tutorial • Check the layers Introduction

(View-Display/hide Open Source

layers) Sensors • Perhaps a little Inside NXT C 101 Firmware overdoing with not using Programming a single layer board... ARM7 • Resize the board by NXT Software using MOVE corners Debugging NXT

NXT.34 Create a Temperature Sensor LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial

• Make Gerber files Introduction • Run excellon.cam Open Source from the File->CAM Sensors Inside NXT C 101

• Use GerbView (or Firmware similar to inspect files) Programming ARM7

• or Textpad... NXT Software

Debugging NXT

NXT.35 NXT C Programming 101 LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Just to refresh out C programming skills • NXT types • Function pointers Outline • void pointers Aim of Tutorial Introduction

typedef struct Open Source { Sensors ULONG ModuleID; UBYTE ModuleName[FILENAME_LENGTH + 1]; Inside NXT C 101 Firmware void (*cInit)(void* pHeader); Programming void ( cCtrl)(void); * ARM7 void (*cExit)(void); NXT Software void *pIOMap; Debugging NXT void *pVars; UWORD IOMapSize; UWORD VarsSize; UWORD ModuleSize; } __attribute__((__packed__)) HEADER; /*nxtgcc converter*/

NXT.36 NXT C Programming 101 LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Pointers * Outline • Address of & Aim of Tutorial Introduction

• Dereferencing * Open Source

Sensors

ULONG* pUL; Inside NXT C 101

ULONG someUL; Firmware someUL = 4; Programming pUL = &someUL; ARM7

*pUL = 5; NXT Software //Now someUL == 5 Debugging NXT

NXT.37 NXT C Types LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net • typedef • struct • enum • #define Outline Aim of Tutorial typedef struct Introduction { Open Source

ULONG someUL; Sensors

... Inside NXT C 101 }SOMESTRUCTYPE; Firmware ... Programming

enum ARM7

{ NXT Software SOMEENUMVAL0, Debugging NXT SOMEENUMVAL1, SOMEENUMVALEND = SOMEENUMVAL1, }; ... ifndef SOME_H_FILE define SOME_H_FILE // code endif //SOME_H_FILE

NXT.38 Embedded Programming LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline • A central micro processor controls NXT Aim of Tutorial Introduction • A second small micro processor assisting it Open Source • Code is compiled to machine instructions which are Sensors executed one at a time Inside NXT C 101 Firmware • NXT allows for firmware updates, which is the basis for Programming alternative operating systems ARM7 NXT Software

Debugging NXT

NXT.39 NXT Firmware LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net • NXT actually consists of two different firmwares • The main firmware controls the interaction with the user, and radio Outline communication to other Aim of Tutorial NXTs Introduction Open Source • An ATmega48 Sensors generates the pulse Inside NXT C 101 width modulation Firmware Programming

(PWM) signals for the ARM7

three motors NXT Software • It also provides input Debugging NXT regarding the state of the push buttons on the NXT • Host side SDK which allows for interaction with the NXT via a DLL NXT.40 NXT Inside LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• (a) ARM7 MCU • (b) ATmega48 MCU Outline • (c) CSR BlueCore4 Aim of Tutorial

Bluetooth radio Introduction • (d) SPI bus and Open Source touchpad signals Sensors Inside NXT C 101 • (e) high-speed UART Firmware behind input port 4 Programming ARM7 • (f) output (generally NXT Software

motor) port Debugging NXT • (g) USB port, (h) NXT with important hardware four-button touchpad highlighted • (i) 100x64 LCD display

NXT.41 ARM to AT48 Communication LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• AVR to ARM: Buttons, ADC values, and Battery • ARM to AVR: Motor control etc.

• Show m_sched.h file... Outline

Aim of Tutorial typedef struct Introduction { UWORD AdValue[NOS_OF_AVR_INPUTS]; Open Source UWORD Buttons; Sensors UWORD Battery; Inside NXT C 101 }IOFROMAVR; Firmware Programming typedef struct ARM7 { NXT Software UBYTE Power; Debugging NXT UBYTE PwmFreq; SBYTE PwmValue[NOS_OF_AVR_OUTPUTS]; UBYTE OutputMode; UBYTE InputPower; }IOTOAVR;

NXT.42 Firmware Enhancements LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline • Firmware enhancements are possible only because Lego Aim of Tutorial released the software as open source Introduction Open Source

• IAR is a commercial compiler used by LEGO Sensors • It was recently released in a free version for Mindstorms Inside NXT C 101 Firmware • The other option for programming the existing firmware is Programming to use GCC ARM7 NXT Software

Debugging NXT

NXT.43 Firmware Replacements LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net • A growing number of firmware replacements available • Examples: , NQC, pbLua, and RobotC • A different example is TinyOS

• leJOS is based on a small virtual Java machine. It is a Outline firmware replacement that allows for Java programming on Aim of Tutorial Lego Mindstorms NXT. There is extensive support in forms Introduction of tutorials, well-developed , and Netbeans/ Open Source programming IDEs at the leJOS website. Sensors Inside NXT C 101

• Lua is a scripting language (see Lua website). It is said to Firmware perform faster than other scripting languages. Ralph Programming Hempel has ported Lua to Lego Mindstorms NXT and ARM7 labeled it pbLua NXT Software Debugging NXT • Not eXactly C (NXC) is language similar to C. It is supported on Lego Mindstorms NXT by John C. Hansen and available from http://bricxcc.sourceforge.net/nbc/. It is built on top of the Next Byte Codes (NBC) compiler. It is a firmware replacement.

NXT.44 IAR Toolchains and Firmware LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• The free IAR compiler can be downloaded from IAR’s Outline homepage Aim of Tutorial • It is an industry strength programming environment called Introduction Open Source

Embedded Workbench Sensors • It interacts with a JTAG programmer connected to Lego Inside NXT C 101 Mindstorms NXT via the IAR C-SPY debugger Firmware Programming • The visualSTATE program interacts with the C-SPY ARM7 debugger to give a graphical view of the debugging NXT Software session Debugging NXT

NXT.45 GCC LEGO MINDSTORMS ESWEEK 2009 • The GCC compiler can http://nxtgcc.sf.net be downloaded from the nxtgcc home page • It is an arm-elf-gcc compiler Outline Aim of Tutorial • There exists several Introduction

good toolchains such as Open Source

WinArm, CodeSurgery Sensors etc. Inside NXT C 101 Firmware • Show nxtgcc Eclipse Programming project... ARM7 • binsert.c NXT Software Debugging NXT • nxtgcc.rfw • ConvertNxtGcc.java and NGU.java • Source-xx =⇒ Source copy • m_sched.map NXT.46 GCC Compliance Process LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Changes needed to make the source code compile with Outline

an arm-elf based GCC Aim of Tutorial • See details in ConvertNxtGcc.java program Introduction Open Source • First versions of NXTGCC were error-prone Sensors • IAR supports, and Lego uses, nested flexible array Inside NXT C 101 members Firmware Programming • GCC does not support this ARM7 • Key was to change the nested flexible array to become a NXT Software fixed size nested array Debugging NXT

NXT.47 Nested Array LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Show Display.txt in SourceOrig and in Source Outline

typedef struct Aim of Tutorial

{ Introduction typedef struct UBYTE FormatMsb; Open Source { ... Sensors UBYTE FormatMsb; UBYTE PixelsY; Inside NXT C 101 ... /*nxtgcc converter*/ Firmware UBYTE Data[]; UBYTE Data[1]; Programming } } ARM7 BMPMAP; /*nxtgcc converter*/ __attribute__((_packed__)) NXT Software BMPMAP; Debugging NXT

NXT.48 ARM7 LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Characterized by a number of modes, exception types, and interrupts Outline Aim of Tutorial

• Associated with each mode is a current program status Introduction

register (CPSR) Open Source • Each exception and interrupt type is associated with a Sensors priority Inside NXT C 101 Firmware • 6 privileged modes named system, svc, abort, fast Programming interrupt, interrupt, and undefined mode ARM7 NXT Software

• They can all modify the CPSR Debugging NXT • The unprivileged user mode cannot modify the CPSR

NXT.49 The Bible: Atmel doc6175.pdf LEGO MINDSTORMS ESWEEK 2009 The ARM7 processor used in NXT is underlined. http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.50 Periodical Interval Timer LEGO MINDSTORMS ESWEEK 2009 The PIT timer generates the system tick. http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.51 Memory Controller LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net The MC generates the abort exception

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.52 MCU Overview I LEGO MINDSTORMS ESWEEK 2009 SAM-BA, SPI, TWI, AIC, SSC, etc. http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.53 MCU Overview II LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

SAM-BA, SPI, TWI, AIC, SSC, etc.

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.54 ARM MCU Features LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net JTAG, Thumb, ARM

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.55 ARM MCU Peripherals and Memory Mappings LEGO MINDSTORMS ESWEEK 2009 The Big (Small...) Picture http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.56 ARM MCU Peripherals and Memory Mappings LEGO MINDSTORMS ESWEEK 2009 Main memory http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.57 ARM MCU Peripherals and Memory Mappings LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Main memory remapping

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.58 ARM MCU Peripherals and Memory Mappings LEGO MINDSTORMS ESWEEK 2009 Peripherals such as timers http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.59 ARM MCU Peripherals and Memory Mappings LEGO MINDSTORMS ESWEEK 2009 System Peripherals such as interrupt controller http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source

Sensors

Inside NXT C 101

Firmware Programming

ARM7

NXT Software

Debugging NXT

NXT.60 ARM7 Registers LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• The CPSR defines the characteristics of the current mode • It can mask (ie. not allow) interrupts and fast interrupts

• The CPSR includes a flag whether the ARM7 is executing Outline

thumb code or arm code Aim of Tutorial • There is a register file which includes 37 registers Introduction Open Source

• Each register is 32 bit wide Sensors • Each mode uses 17 registers Inside NXT C 101 Firmware • Registers R0-R12 are shared between usr, sys, svc, Programming abt, irq, and und modes ARM7 • The fiq mode has its own banked version of the R8-R12 NXT Software Debugging NXT registers • All modes have their own stack pointer and link/return pointer: R13 and R14 • The program counter, pc, is placed in R15

NXT.61 ARM and Thumb Instruction Sets LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• The ARM instruction set is 32 bit Outline

• Thumb instruction set is Aim of Tutorial 16 bit Introduction • Most of the code in NXT Open Source is compiled toward the Sensors Inside NXT C 101 Thumb instruction set Firmware • Thumb code is more Programming ARM7 dense than ARM NXT Software • Exception and interrupt Debugging NXT handlers are compiled to ARM code NXT schematics Demo ARM compilation.

NXT.62 ARM Pins LEGO MINDSTORMS ESWEEK 2009 Show PDF with ARM... http://nxtgcc.sf.net PCB Port/pin ARM7 pin ARM7 PIO DIGIA0 1/5 15 PA23/PGMD11 DIGIA1 1/6 10 PA18/PGMD6/AD1 Outline DIGIB0 2/5 38 PA28 Aim of Tutorial DIGIB1 2/6 13 PA19/PGMD7/AD2 Introduction Open Source

DIGIC0 3/5 41 PA29 Sensors

DIGIC1 3/6 16 PA20/PGMD8/AD3 Inside NXT C 101

Firmware DIGID0 4/5 42 PA30 Programming DIGID1 4/6 6 AD7 ARM7 NXT Software • Port 1 through 4 are mapped to general purpose input Debugging NXT output pins • Most ARM7 pins are multiplexed • Pin 6 on inout port 1-3 both can serve as GPIO pins and as an analog to digital converter (ADC) • The Lowspeed module use the GPIO pins to bit-bang an I2C protocol NXT.63 Memory Layout and Dynamics LEGO MINDSTORMS ESWEEK 2009 • is initially mapped to address 0x0000 0000 http://nxtgcc.sf.net • Flash is also accessible at address 0x0010 0000 • NXT immediately branches to the reset handler that is defined in CStartup.S Outline • It uses a temporary stack in the RAM area Aim of Tutorial • The reset handler sets up the stacks for the interrupt Introduction handler (IRQ), the undefined instruction handler (UND) Open Source stack, and the user stack (USR) Sensors Inside NXT C 101 • The USR stack is used when the normal code executes Firmware • IRQ stack is obviously used when the IRQ handler is Programming ARM7

invoked: it branches to the correct interrupt service routine NXT Software

(ISR) Debugging NXT • Controlled by writing the address of that ISR into the advanced interrupt controller (AIC) source vector register (SVR) • Example: each of the three timers (TC0, TC1, TC2) have an ID, and that ID is used as index in the AIC SVR vector

Next: Memory Layout NXT.64 Memory Layout LEGO MINDSTORMS ESWEEK 2009 Flash (.text) RAM (.data) http://nxtgcc.sf.net Remap 0x0010 0000 0x0020 0000 0x0000 0000 Reset interrupt vector (boot) Reset interrupt vector - Undefined instruction vector - Software interrupt vector - Prefetch abort vector - Data abort vector Reserved Reserved - IRQ vector - FIQ vector IRQ handler Reset handler Advanced interrupt controller (IRQ mode) Outline Undefined instruction handler ARM compiled code Used as breakpoint entry (Undefined instruction mode) Aim of Tutorial Reset handler (Supervisor mode) Thumb compiled code Introduction

.fastrun C code to run in RAM Open Source I.e. Interrupt service routines Sensors

.bss RAM 64 KB Flash 256 KB Zero initialized variables Inside NXT C 101

Firmware Programming NXT file system Free space ARM7

User stack NXT Software

Reset handler stack Debugging NXT

Undefined handler stack

IRQ handler stack Descending stacks NXT file handles NXT file version

0x F000 0000

Memory mapped peripherals TWI (I2C), SPI, USART, etc. Notes about the NXTGCC memory layout figure: Not drawn to scale Strikethrough: not used in standard firmware Interrupt and exceptions is handled in assembler Some details omitted for clarity

0x FFFF FFFF NXT.65 Memory Layout LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net Flash (.text) RAM (.data) Remap 0x0010 0000 0x0020 0000 0x0000 0000 Reset interrupt vector (boot) Reset interrupt vector - Undefined instruction vector - Software interrupt vector - Prefetch abort vector - Data abort vector Reserved Reserved - IRQ vector - FIQ vector IRQ handler Reset handler Advanced interrupt controller Outline (IRQ mode) Undefined instruction handler ARM compiled code Used as breakpoint entry Aim of Tutorial • The stacks on NXT (i.e. (Undefined instruction mode) Reset handler (Supervisor mode) Thumb compiled code Introduction

ARM7) are fully .fastrun C code to run in RAM Open Source I.e. Interrupt service routines descending stacks Sensors

.bss RAM 64 KB Flash 256 KB • Using the instructions Zero initialized variables Inside NXT C 101 Firmware STMFD and LDMFD Programming NXT file system • Postfix FD depicts that Free space ARM7 User stack we are working with a NXT Software Reset handler stack Debugging NXT full descending stack Undefined handler stack

IRQ handler stack Descending stacks NXT file handles NXT file version

0x F000 0000

Memory mapped peripherals TWI (I2C), SPI, USART, etc. Notes about the NXTGCC memory layout figure: Not drawn to scale Strikethrough: not used in standard firmware Interrupt and exceptions is handled in assembler Some details omitted for clarity

0x FFFF FFFF

TODO: Show code with descending stacks NXT.66 Undefined Instruction Stack Setup LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Undefined stack setup in Cstartup.S Outline

• The illegal memory access (ABT) stack is set up before Aim of Tutorial the undefined instruction stack Introduction Open Source /* Set up Undefined Instruction Mode Sensors and set UND Mode Stack*/ Inside NXT C 101 .EQU UND_STACK_TOP, (ABT_STACK_TOP - ABT_STACK_SIZE) Firmware msr CPSR_c, #ARM_MODE_UND | I_BIT | F_BIT Programming ARM7 mov sp, r0 /* Init stack UND */ sub r0, r0, #UND_STACK_SIZE NXT Software Debugging NXT

NXT.67 Post Boot LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Remapping of address 0x0000 0000 such that it is now the RAM and not the flash that is accessible from address Outline 0x0000 0000 Aim of Tutorial Introduction • Main reason for this is that we need to service interrupts Open Source

even when the NXT flash-based file system is being Sensors

written to Inside NXT C 101

Firmware • Remapping the memory ensures that the interrupt vector Programming

table is access in RAM ARM7 • All interrupt service routines are linked into the .fastrun NXT Software segment Debugging NXT Show segments in file.

NXT.68 NXT Running LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial

• Mostly taking place in the Thumb compiled code Introduction • Interrupt is asserted from one of the ARM7 peripheral Open Source sources then that interrupt service routine takes over Sensors Inside NXT C 101

• Most peripherals in NXT are associated with a software Firmware module Programming ARM7

NXT Software

Debugging NXT

NXT.69 Modules LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

• Each module is built from an header file, a C file, and .iom Aim of Tutorial file Introduction • Layered in a hardware physical layer (HPL), and a Open Source hardware abstraction layer (HAL) Sensors Inside NXT C 101 • HAL files start with the letter c followed by an underscore, Firmware while the HPL files start with the letter d Programming ARM7

• Show a module... NXT Software

Debugging NXT

NXT.70 NXT Software Modules and ARM7 HW Peripherals LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net Name ARM Peripherals Note Scheduler - Main control Button AVR via I2C/TWI 4 buttons Display SPI LCD display CMD - Virtual machine Outline Input GPIO, PWM, AD 4 input ports Aim of Tutorial IOCtrl I2C, AIC AVR communication Introduction Loader MC File management Open Source Lowspeed GPIO, PWM I2C emulation Sensors Output AVR via I2C Motor control Inside NXT C 101 Firmware Sound SSC Loadspeaker control Programming

UI - Menu system ARM7

Timer PIT Operating system tick NXT Software

Bluetooth SPI, GPIO Communication control Debugging NXT Communication UDP, UART, SPI USB, RS485, and BT

Abbreviations: I2C:Inter-integrated circuit, TWI:Two-wire interface, PWM:Pulse width modulation, AIC:Advanced interrupt controller, MC:Memory controller, SSC:Synchronious serial controller, PIT:Periodic interval timer, SPI:Serial peri- pheral interface, UDP:USB device port, and UART:Universal asynchronous receiver tranceiver.

NXT.71 NXT Modules LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net Scheduler This is the main scheduler: m_sched. It works in a round robin fashion with a 1 ms system tick. It will call each of the modules listed below using function pointers. There is an initialization phase in which each module’s cInit method is called. Outline Then the system starts calling the cCtrl methods. Aim of Tutorial Termination is done via calls to CExit. Introduction Open Source

Button It handles the four buttons on top of NXT. Sensors

Principle: It uses the AD converter peripheral Inside NXT C 101

Button 0 is read as? Button 1-3 is read as an AD Firmware converted value. Programming ARM7

CMD This is the Lego virtual machine. It reads the NXT Software executable files stored in flash and creates a Debugging NXT RAM space for runtime information. The rxe file contains bytecode instructions, bytecode scheduling, and run-time data. Comm It takes care of the BT, USB and the Highspeed port. Peripherals used: SPI to BT, USB, and USART in RS485 mode. NXT.72 NXT Modules LEGO MINDSTORMS ESWEEK 2009 Display It is code for accessing the pixels of the 100 x 64 http://nxtgcc.sf.net pixel display. It is possible to both set pixels, write characters, and strings (it is a matter of abstraction). There is a font included with the NXT. There are eight text lines on the display. It Outline accesses the serial peripheral interface (SPI) Aim of Tutorial

hardware peripheral. The SPI works by writing Introduction

data to a slave (the display in this case) over the Open Source master out slave in (MOSI) line. It receives data Sensors from the slave over the master in slave out line Inside NXT C 101 Firmware (MISO). The data flow is synchronous and is Programming

regulated by a serial clock (SPCK) line. The ARM7

display receives a command from the ARM7 NXT Software specifying which line is to be written, and then it Debugging NXT receives the actual data for that line. Input The input sensors are plugged into the 4 input ports on NXT. NXT will know which type of sensor is plugged into a port. It can be a temperature sensor, sound, lowspeed, and so on. The lowspeed sensor is an I2C/TWI compliant sensor. NXT.73 NXT Modules LEGO MINDSTORMS ESWEEK 2009 IOCtrl This module controls the booting and power http://nxtgcc.sf.net down sequences of NXT. It will write to the AVR what the power should be and what the PWM for the motors should be. The IOCtrl module uses the I2C(TWI) hardware peripheral to relay this Outline information to the AVR. It also uses the Aim of Tutorial

advanced interrupt controller (AIC), by having it Introduction

call an I2C handler routine. Open Source Loader File management is achieved by the loader Sensors module. It reads, writes, creates, and deletes Inside NXT C 101 Firmware files in the NXT flash. It resides in the upper part Programming

of the flash memory starting from the value of the ARM7

memory address STARTOFUSERFLASH in NXT Software d_loader.h. It uses the memory controller (MC) Debugging NXT peripheral module of the ARM7. No read while writing: the methods that perform erase and write of flash pages are placed in RAM. This is achieved by marking the methods with __ramfunc, which tags the method to belong to a section called .fastrun. The .fastrun section are placed in the DATA=RAM area. NXT.74 NXT Modules LEGO MINDSTORMS ESWEEK 2009 Lowspeed An I2C compliant device can be connected to http://nxtgcc.sf.net one of the four input ports. The lowspeed module handles the communication and recognizes the connected sensor as either the standard ultrasonic device, or a custom device. It uses an Outline IRQ handler that is invoked via the AIC hardware Aim of Tutorial

peripheral: It utilizes the pulse width modulation Introduction

controller (PWM) peripheral to generate the Open Source clock. Sensors Output Motors are connected to NXT through the three Inside NXT C 101 Firmware output ports: A, B, and C. The module Programming

communicates the motor output to the AVR via ARM7

the I2C bridge. It is managed by struct, which is NXT Software passed to the AVR from the ARM7 that controls Debugging NXT this communication line. The information that controls the motors are an output mode and a PWM frequency for each motor. Thus, the output module make use of the hardware peripherals TC0, TC1, TC2, to monitor motor C, A, and B respectively. Interrupt handlers: the tacho count bookkeeping. NXT.75 NXT Modules LEGO MINDSTORMS ESWEEK 2009 Sound A loudspeaker with 8 bit resolution is controlled http://nxtgcc.sf.net by the sound module. It plays sounds which are files residing in the NXT file system. Each time cCtrl method of the sound module is called, then

it either plays a sound, continues to play a Outline

sound, or closes the sound file that has been Aim of Tutorial

played. The module utilizes the synchronous Introduction serial controller (SSC) hardware peripheral. With Open Source the SCC providing the AC signal Sensors ((SOUND_ARMA from PA17) to the SPY0030A Inside NXT C 101 Firmware audio driver, NXT can play sounds. It uses the Programming peripheral DMA controller (PDC) to handle the ARM7 transmission of the bitstream to the speaker. NXT Software UI The module manages the menu system, selected Debugging NXT files, icons, animations, etc. on NXT. It responds when an user press on of the buttons on NXT. Timer NXT is programmed around a system tick of 1 ms. This property is supported by the timer module that use the periodic interval timer (PIT) hardware peripheral to maintain a 1 ms counter. NXT.76 Debugging Overview LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial • Easiest way to debug NXT is to use the light sensor Introduction Open Source • We can find the memory location that controls the GPIO Sensors

pin Inside NXT C 101 • Firmware Other choices is to use a JTAG debugger Programming

ARM7

NXT Software

Debugging NXT

NXT.77 Light Sensor Port LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Outline

Aim of Tutorial

Introduction

Open Source //Turn on an input port #define ON(port) Sensors { Inside NXT C 101 *AT91C_PIOA_SODR = PORT_TO_PIN(port); } Firmware Programming Turn on a light sensor on an input port for low-level debugging... ARM7 Show section 15.4.4 Output Control in ARM PDF... NXT Software

Debugging NXT

Light sensor schematics: Show how to turn on the light sensor in code

NXT.78 Display Debugging LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Example (from c_cmd.c): Outline {// LCD DEBUG START Aim of Tutorial cnt++; // a static counter Introduction

UBYTE DebugString[50]; Open Source

sprintf(DebugString,"Debug info: %d", cnt); Sensors if(cnt==1) Inside NXT C 101 { Firmware cDebugString(&DebugString[0]); Programming

} ARM7 }//LCD DEBUG END NXT Software Showing a debug string in the display Debugging NXT

NXT.79 GDB Debugging LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• We may think (initially) that we have stopped the processor Outline • A break point can be inserted into the code using the GCC Aim of Tutorial inline assemble syntax Introduction Open Source /* Sensors * Trigger a breakpoint exception. Inside NXT C 101 */ Firmware __ramfunc void bsp_breakpoint(void){ Programming //asm volatile (".word 0xE7FFDEFE"); ARM7 NXTGCCBREAK; NXT Software } Debugging NXT

NXT.80 GDB LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• GDB is the debugging system that is connected to GCC Outline • GDB system offers a remote debugging system Aim of Tutorial Introduction

• USB driver to use is the Fantom SDK Open Source • Fantom C++ files, there is a section with ëxtern C" Sensors Inside NXT C 101 • Read and write methods for arbitrary bytes Firmware • Allows for an implementation of the GDB remote Programming ARM7 debugging protocol NXT Software • Debugger is arm-elf-gdb Debugging NXT

NXT.81 GDB Remote Protocol LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• It includes a one-byte checksum Outline • Comes after the # in the packet Aim of Tutorial Introduction • Problem is that the Fantom DLL does not like if we try to Open Source

read from the USB if there is not something to read Sensors • We read two characters (checksum) Inside NXT C 101 Firmware • NXTGCC Fantom GDB wrapper (discussed later) writes Programming and especially reads one character at a time to/from NXT, ARM7 even though the USB endpoints are in bulk mode NXT Software Debugging NXT Show GDB files here...

NXT.82 Hardware Debugging LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• It is possible to create one using a 1.27 mm pitch row Outline Aim of Tutorial • Each of the eight pins Introduction

from J17 can be Open Source

connected to a standard Sensors 20 port JTAG like this: Inside NXT C 101 1 → 9, 2 → 7, 3 → 13, Firmware Programming 4 → 15, 5 → 5, 6 → 4, ARM7

7 → not connected, and NXT Software

8 → 1. Debugging NXT Using a JLink to flash an ARM7 Eval. • Use Segger, IAR or board, while warming up for NXT to some open source arrive in the summer of 2006. project like OPENOCD

NXT.83 Compiler Performance LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

• Eclipse is one possibility Outline as an programming Aim of Tutorial environment Introduction Open Source • Output from compiling Sensors the firmware has been Inside NXT C 101 Firmware shown Programming • Size and memory ARM7 addresses of the NXT Software different sections are Debugging NXT displayed after a successful build

Reading the compilation statistics in Eclipse NXT.84 Comparison LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net Comparison of GCC and IAR Code Size

Packing Size of .text Size of .data Compiler structs (bytes) (bytes) Outline Aim of Tutorial

GCC All 202052 54548 Introduction

NXTGCC Selected 180104 54144 Open Source GCC None 162136 54228 Sensors Inside NXT C 101 IAR (speed) 127552 49831 Firmware IAR (size) 122440 49763 Programming ARM7 GCC compiler (arm-elf-gcc version 4.2.2) that NXTGCC uses, NXT Software creates a larger code footprint than the IAR compiler does. For Debugging NXT the flash we can compare the GCC compiler’s approx. 175 KB to the IAR compiler’s approx. 120 KB. Regarding RAM, the picture is approx. 53 KB compared to approx. 49 KB in favor of IAR.

NXT.85 Code Speed LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Comparison of GCC and IAR Code Speed Outline Aim of Tutorial

Introduction

Speed Open Source

Compiler # loops Sensors NXTGCC (selected structs) 615 Inside NXT C 101 Firmware IAR (size optimized) 640 Programming Benchmark code: Steven Hassenplug ARM7 NXT Software

Debugging NXT

NXT.86 Documentation LEGO MINDSTORMS ESWEEK 2009 http://nxtgcc.sf.net

Lego, Atmel, and the NXTGCC project provide comprehensive Outline information about NXT. This includes hardware schematics, Aim of Tutorial explanation of important protocols, and documentation for Introduction programming NXT: Open Source Sensors

• Lego: Hardware Developer Kit Inside NXT C 101 • Firmware Lego: Software Developer Kit Programming • Atmel: AT91SAM7S256 aka ARM7 hardware description ARM7 • NXTGCC http://nxtgcc.sourceforge.net NXT Software Debugging NXT

NXT.87