Difference between revisions of "DT 8025 2016 Practical 0"

From CERES
Jump to: navigation, search
 
(10 intermediate revisions by one user not shown)
Line 84: Line 84:
  
 
'''Preparing the SD card'''
 
'''Preparing the SD card'''
 +
 
Raspberry-Pi board has two processors: a GPU to start the execution of a code and an ARM processor to run the code.  
 
Raspberry-Pi board has two processors: a GPU to start the execution of a code and an ARM processor to run the code.  
The original SD card already has a GPU bootloader (which is replaced by other one in the following steps).  The latest firmware (bootloader, ...) for the Raspberry Pi's is available from [[http://github.com/raspberrypi]].
+
The original SD card already has a GPU bootloader (which is replaced by other one in the following steps).  The latest firmware (bootloader, ...) for the Raspberry Pi's is available from [[http://github.com/raspberrypi/firmware http://github.com/raspberrypi/firmware]].
For the practicals in this course, we use the minimum configuration we need to get stated. You only need bootcode.bin and start.elf (under the boot directory). You can also download [[MiniBoot]].
+
For the practicals in this course, we use the minimum configuration -only 'bootcode.bin' and 'start.elf' (under the boot directory)- to get started.
  
For using the SD card for the first time, perform the following actions to have the SD card ready to use:
+
To have the SD card ready to use and copy our program into it, perform the following actions. ('''note:''' you need to format the card  (step 4) and copy the boot files (step 5) if you are using the SD card for the first time).
  
 
# power off the Raspberry Pi
 
# power off the Raspberry Pi
 
# remove the SD card
 
# remove the SD card
 
# insert the SD card into a computer using the USB reader
 
# insert the SD card into a computer using the USB reader
# format the SD card using this [[instruction]].  
+
# format the SD card using [[Format SD Card]].  
# copy the files from [[boot.zip]]
+
# copy the files from [[media:Boot-2016.zip|boot.zip]]
 
# copy kernel.img to the SD card
 
# copy kernel.img to the SD card
 
# remove the SD card and insert it into the Raspberry Pi
 
# remove the SD card and insert it into the Raspberry Pi
 
# power on the Raspberry Pi.
 
# power on the Raspberry Pi.
  
=[[DT_8025_2016 | Back to Course Home Page]]=
+
 
 +
===[[DT_8025_2016 | Back to Course Page]]===

Latest revision as of 20:08, 18 September 2016

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 Part1.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 an LED on a breadboard that is externally connected to your Raspberry Pi. First, you will need to wire the circuit as described at the Raspberry Pi Learning Resources.

The blinking starts happening very quickly and slows down as the time goes by. To do this, you count up to a number between each two blinking and the number exponentially increases, that is, you first count up to 2 and blink, then count up to 4 and blink, then count up to 8 and blink, then count up to 16 and blink, and so on...

The LED can be controlled by any GPIO pin; the numbering of the GPIO pins is available at the Raspberry Pi's GPIO usage guide. Thus, to blink the LED first, you need to set the GPIO pin as an output (set the respective bit of the GPIO Function Select Register form the base address 0x3F200000 ); then to turn the LED on and off, you iteratively set the respective bit of the GPIO Output Set and GPIO Output Clear register with some delay in between. To set these outputs low and high, use an iRegister and map its contents to them.

You can start with a simple example code lab0.c that turns on an LED connected to the GPIO16 pin and modify it to a blinker using the above given instructions.

To compile the code we use the Arm Cross Compiler Toolchain. You will find a Makefile in the directory of the example code that takes care of all compiler options so that you only have to call

make run

to generate an image file, i.e., kernel.img.

Preparing the SD card

Raspberry-Pi board has two processors: a GPU to start the execution of a code and an ARM processor to run the code. The original SD card already has a GPU bootloader (which is replaced by other one in the following steps). The latest firmware (bootloader, ...) for the Raspberry Pi's is available from [http://github.com/raspberrypi/firmware]. For the practicals in this course, we use the minimum configuration -only 'bootcode.bin' and 'start.elf' (under the boot directory)- to get started.

To have the SD card ready to use and copy our program into it, perform the following actions. (note: you need to format the card (step 4) and copy the boot files (step 5) if you are using the SD card for the first time).

  1. power off the Raspberry Pi
  2. remove the SD card
  3. insert the SD card into a computer using the USB reader
  4. format the SD card using Format SD Card.
  5. copy the files from boot.zip
  6. copy kernel.img to the SD card
  7. remove the SD card and insert it into the Raspberry Pi
  8. power on the Raspberry Pi.


Back to Course Page