Difference between revisions of "DT 8025 2016 Practical 0"
Line 72: | Line 72: | ||
The LED can be controlled by any GPIO pin; the numbering of the GPIO pins is available at the Raspberry Pi's [https://www.raspberrypi.org/documentation/usage/gpio-plus-and-raspi2/README.md GPIO usage guide]. | The LED can be controlled by any GPIO pin; the numbering of the GPIO pins is available at the Raspberry Pi's [https://www.raspberrypi.org/documentation/usage/gpio-plus-and-raspi2/README.md 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 ); | 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. | + | 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 [[media:Lab0_2016.zip|lab0.c]] that turns on LED connected to the GPIO16 pin and modify it to a blinker using the above given instructions. | + | You can start with a simple example code [[media:Lab0_2016.zip|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 [https://launchpad.net/gcc-arm-embedded Arm Cross Compiler Toolchain]. | To compile the code we use the [https://launchpad.net/gcc-arm-embedded Arm Cross Compiler Toolchain]. |
Revision as of 10:22, 23 August 2016
Contents
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.
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 the GPU boot loader). Rename the existing kernel.img on the SD card to something else, and put the new kernel.img on the SD card using an SD card reader.