Difference between revisions of "PA 8001 2014 Practical 0"

From CERES
Jump to: navigation, search
Line 32: Line 32:
 
'''Unpacking and Installing Your Raspberry Pi'''
 
'''Unpacking and Installing Your Raspberry Pi'''
  
 +
* Plug in your raspberry pi board to a power supply.
 +
* Choose the Raspbian OS to be installed by checking the box next to it.
 +
* You can choose some settings such for your OS  or skip it (you can also set them later).
 +
* Click on install button at top left corner of the window.
 +
* Log in to the linux OS by the following username and password:
 +
       
 +
username: pi
 +
password: raspberry
 +
 +
* Enter the “startx” command to get started.
 +
* You can now start with writing and compiling a simple C code.
 +
To write your C code you need to use an editor. Leafpad is a simple text editor which you can use or you can install your own editor by transferring the required files to the memory and then installing the editor. Standard Linux editors such as Vi are also available.
 +
You can find the Leafpad editor under Start-> Accessories->Leafpad  Open the Leafpad editor and write the following program and then save your file by “.c “  extension.
 +
*  To compile your program, start the LXterminal (you can find it on your desktop). Type the following command in the terminal:
 +
  gcc /path of your C program/name of your program.c –o /address of the output file/output file
  
  

Revision as of 01:17, 7 September 2014

Under Preparation; To be finalised befoer Monday

Objectives

The objectives of this practical are twofold:

  • To set up and familiarise yourself with the lab environment (e.g., Raspberri Pi and ARM Cross Compiler)
  • To make sure that you have understood the basic concepts of C programming required for the rest of the course
  • To acquire basic familiarity with Raspberri PI bare-metal programming
  • To apply basic principles of Test Driven Development

Instructions

You need to submit a single .zip file on blackboard containing the programs for Part 1 and Part 2. The two parts should be put in two different folders, named Part 1 and Part 2, respectively. Only submissions before the deadline are considered, unless you ask for a deadline extension before the deadline. You do not have to wait for an acknowledgment if you ask for an extension. You can only ask for a deadline extension for one week for at most 2 out of 5 practicals.

The practicals are based on the following two practicals:


Part 1: C Programming

Unpacking and Installing Your Raspberry Pi

  • Plug in your raspberry pi board to a power supply.
  • Choose the Raspbian OS to be installed by checking the box next to it.
  • You can choose some settings such for your OS or skip it (you can also set them later).
  • Click on install button at top left corner of the window.
  • Log in to the linux OS by the following username and password:
username: pi
password: raspberry
  • Enter the “startx” command to get started.
  • You can now start with writing and compiling a simple C code.

To write your C code you need to use an editor. Leafpad is a simple text editor which you can use or you can install your own editor by transferring the required files to the memory and then installing the editor. Standard Linux editors such as Vi are also available. You can find the Leafpad editor under Start-> Accessories->Leafpad Open the Leafpad editor and write the following program and then save your file by “.c “ extension.

  • To compile your program, start the LXterminal (you can find it on your desktop). Type the following command in the terminal:
 gcc /path of your C program/name of your program.c –o /address of the output file/output file 


Programming Bit-Vectors in C

  • Create a local directory in your raspberry pi and move iregister.zip there.
  • Unpack the zip file and open main.c and study the instructions.
  • Include the required documentation as comments in iregister.h .
  • Implement the required functions in iregister.c and the testcases in main.c .
  • After compiling, linking and running the files, make sure that all the test cases have run successfully.

Part 2: Bare-Metal Programming for Raspberry Pi

In this part of the lab, you will replace the Linux operating system on Raspberry Pi with your own program. You will implement a kernel that blinks the ACT LED on Raspberry Pi. This LED is controlled by GPIO16. Thus, to blink the LED first, you need to set GPIO16 as an output; then to turn the LED on and off, you iteratively set and reset the 16th bit of GPIO6 with some delay in between. To set GPIO16 output low and high, use an iRegister and map its contents to the 4 bytes from the base address 0x20200000.

You can start with a code <lab0.c> that turn off ACT LED and modify it to a blinker using the above given instructions.

You need to compile the code using the Arm Cross Compiler with the following options:

arm-none-eabi-gcc -O2 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles lab0.c -o lab0.elf

and create an image file using

arm-none-eabi-objcopy lab0.elf -O binary recovery.img

Raspberry-Pi board has two processors: a GPU to start the execution of a code and an ARM processor to run the code. The SD card already has a GPU bootloader (if not you can download it form <GPU boot>). Rename the existing recovery.img on the SD card to something else, and put the new recovery.img on the SD card using a SD card reader.