CS428 Embedded Systems Lab


Assignment 1: Hello World

The goal of this assignment is to help you become familiar with the lego nxt platform and the tools for programming the ARM processors under unix. 

1. Get a lego kit from the lab!

For this assignment you will need the lego nxt controller, the light sensor, the charger for the controller battery, and a usb cable. Details on the procedure you need to follow for getting access to these will be given in class. 


Please refer
to the Assignments page for information about forking the assignment repo. Create a file as1_readme.txt that will contain answers to any questions below and your remarks about your implementation.

2. Experiment with the kit

Read the following introductory lego documentation:

The kit is currently running the original firmware. Charge the battery, turn it on, and experiment with the menus and sensors. This is the only time you can expertiment with the default/original firmware. In the steps below you will replace it with custom firmware and you will not be able to re-use the original one (unless you re-load it). 


Answer the following questions 

2.1 How many processors are there in the controller. What architecture (ISA) and speed supports each processor? 

2.2 What type of memory and how much of each type is accessible by each processor? 

2.3 What sensors come with the kit? To which processor can each sensor be connected? 

2.4 Why do some of the sensors connect on one and not the other processor?


3. Install the unix toolchain

For this (and most subsequent) assignments you will need a system running Linux. Many flavors (and kernel versions) will work, but the assignments (the toolchain mostly) have been tested with Ubuntu. You may use the systems that are already setup for this purposes in the lab (B.107). 


Clone the repo Lego-toolchain from CS428 gitlab. This directory tree contains the utilities needed for compiling and downloading code (firmware) to the lego NXT. The toolchain is self-contained and you should not need any files outside this directory, except for the generic usb library, as follows: The firmware toolchain requires the 32 bit version of the usb library, libusb i386, to be installed in your system. If instead you have the 64-bit version, libusb i686, installed, make sure to install libusb i386 as well.


4. Build a very simple first firmware

Fork and clone the repo as1_helloworld as described in Assignments. This directory tree contains the skeleton of a very simple firmware program. 

To build the firmware: 

- Go to the as1_helloworld directory 

- Edit the Makefile and change the "PREFIX" variable to point to the directory of the toolchain in your account 

- make clean; make 


Answer the following questions 

4.1 In which file is the main function? 

4.2 In which directory(ies) are located the .h files used by the firmware .c files? 

4.3 Which path(s) does gcc use for locating each type of file? (use --print-search-paths) 

4.4 What are the targets in the Makefile? What does each target do?


5. Download the new firmware

To download the firmware: - Connect the controller to the usb port. 

- The controller has a hidden button under the usb port. Use a pin to press this button for 3 seconds. Wait for 5 more seconds (or so). You will hear a characteristic periodic beep sound. 

- Type "make download" 

- You should get a message that the firmware was downloaded successfully and is running. A fairly useless firmware is now running! 


Answer the following questions 

5.1 On which processor is this firmware downloaded? What is running on the other processor? 

5.2 Can you turn off the controller using the original on/off button? Yes or no and why?


6. Your first firmware

6.1 Modify the firmware to display "Hello World!" 100 times.You will need to examine the code for the display, to figure out which functions to use and how. 

6.2 Modify your firmware to display "Hello World!" and blink at about 1sec intervals. Write a function that delays for about 1ms and then use this. 

6.3 Move your helloworld function in a separate helloworld.c file and modify the Makefile accordingly. 

6.4 Make the led of the light sensor blink before and after the "Hello World!" message is displayed, using the provided led.h module. 


Answer the following questions 

6.5 What happens when main returns? 

6.6 What happens if you press the orange button while your firmware is running? Explain briefly. 

6.7 What happens if you press the orange button after your firmware has stopped running? Explain briefly. 

6.8 (optional) In your delay function, you use some counting variable. What happens if you declare this to be volatile? Explain briefly.


7. Submit

Submit all files required to run the assignment, including your documentation file as1_readme.txt with all your answers and remarks. Please refer to the policies for information about the submission process. Also, follow the procedure outlined in class for returning the components you used in this assignment. 

 ___________________________________________________________________________________________________________________________________
(c) Copyright University of Crete, Greece, Last Modified: 07-Feb-2022