Logo

Lab 1: Getting Started

Red Pitaya Setup and Hello World!

Overview >> Setup >> Instructions >> Conclusion >> Code Given

Overview


Welcome to Lab 1! Here, you will learn how to set up your red pitaya, connect to it using your laptop, and start writing some code. Luckily for you, this year all the red-pitayas will be given to you pre-assembled, which cuts down on the time-commitment of this lab. Remember that this online guide is for your convenience, but is not comprehensive and should not be used as a replacement for the official lab guide, which you can download above. If you find any errors in this guide—whether logic, spelling, or grammar—please let TA Cooper know so he can get it fixed up ASAP.

Red Pitaya Setup


Physical Setup

For the physical red pitaya, make sure you have done these things:


  1. Place the microSD card into the slot, if it is not already in there.
  2. Plug the ethernet cable from the pitaya to your computer (we will be passing out adapters at the beginning of the lab)
  3. Provide power to the board with the microUSB port. There are 2 ports, so make sure you are using the PWR one (the one on the right).

If you have completed these steps, you should see the light on the pitaya blinking green and occasionally red. This is normal.


Virtual Setup

Now that your pitaya is all connected, we can make sure it is working digitally. To make sure you are connected properly, visit http://rp-xxxxxx.local (replace the x's with the six digits on your red pitaya. It will be on your case, or the sticker with the QR code if the other one fell off). If you are connected properly, you should be brought to a website with a Red Pitaya logo in the background and some buttons. If the website times out, then something went wrong. See below for some troubleshooting tips.


Troubleshooting

  1. Double check the website name. It is case insensitive. You may also need to add a "/" at the end to connect (i.e. http://rp-xxxxxx.local/), but try it with and without the slash.
  2. If you are using a VPN, you may need to disconnect from it to interact with the red pitaya.
  3. Try flipping around the ethernet cord and/or the adapter. If you have a nearby friend who's device is working, try using their adapter and see if that is the issue.
  4. If none of the above works, contact the nearest TA for assistance.

Connecting and Editing

To edit and create files on your red pitaya, we will be using something called Nano (or vim, if you choose to use that). We used to use VSCode to manage files on the pitaya, but recent updates have presented interfacing issues. Nano is also a good skill to learn, so consider it part of your learning experience.


If you are new to the terminal (which I expect most of you to be), I highly suggest you read through my Conquering the Terminal guide. It is a short read and will teach you the basics of using the terminal and the 7 commands that you will need to be able to use in this class.


  1. Open "Terminal" if you are on Mac and "Powershell" if you are on Windows.
  2. When it opens, type ssh root@rp-xxxxxx.local where "xxxxxx" is your pitaya number, and click enter.
  3. It should prompt you for a password. It is root. You won't see the letters you are typing in the command line. This is normal. Just type "root" and click enter.
  4. You should now be connected to your red pitaya (you can check this by seeing what the beginning of the line in the terminal says. It should say "root:~ $" or something similar instead of your laptop name).
  5. To create a file, type touch main.s. This creates a file called "main.s" in the current directory (a.k.a folder).
  6. Type nano main.s to start editing an empty file named main.s. This is the Nano window. It is VERY confusing, even to experienced users. Here is a general overview of what you need to know:

  1. You can type to enter text into a file and delete with the backspace key just like in a text editor.
  2. Some helpful commands are listed at the bottom. The "M-" means 'modifier', which varies depending on Mac vs Windows. I believe you can also hold down ESC and press the listed key for M- commands. You can also look up Nano commands if there is something specific you want to do.
  3. You cannot use your mouse to select an area or move your cursor. You need to use arrow keys to move around.
  4. To save, press Control+O (it is still Control on Mac, not Command). It will ask you for a file name, which should be filled as 'main.s' from your previous command.
  5. When you are done editing, press Control+X to exit the editor. It may ask if you want to "save the modified buffer", which just means Save. Click Y to save.
  6. Nano can be very confusing and overwhelming. If you get stuck or have questions, ask a TA.

This should be everything you need to know to setup the Red Pitaya. If you encounter difficulty at any step, let the nearest TA know and we can help you through the process. For the first lab, we will be prioritizing getting people's pitayas working. Please be patient if you have a coding question, as hardware errors are our primary concern.

Lab Instructions


Welcome to Lab 1! Here, you will learn how to set up your red pitaya, connect to it using your laptop, and start writing some code. Luckily for you, this year all the red-pitayas will be given to you pre-assembled, which cuts down on the time-commitment of this lab.


This is out first semester using this website as a replacement for an pdf lab document (we made this update after 100% of previous students said they prefer the website instructions over the pdf). If you find any errors in this guide—whether logic, spelling, or grammar—please let TA Cooper know so he can get it fixed up ASAP. Expect new features to be added to this site in upcoming labs. I am writing this as of 8:33PM on Jan 22, 2025 for context.


For this lab, you will need "Raspberry Pi Assembly Language Programming by Stephen Smith" (referred to as the "Smith book"), which is required for this class. You need a copy of the book, either digital or physical. You can get the book for free on Pearson if you log in with your SMU email.


Now, read through chapter 1. You can skim until page 17, where you will be getting instructions for this lab.


Step 1

Code from the book can be found in the Code Given section at the bottom of this guide.


Type the code from the book into a new file called "HelloWorld.s" using Nano, as described above. Next, add the two lines from the book/Code Given into a file called "build". It should NOT have a filetype (i.e. .txt, .s, etc.). You can check to make sure all the files were created properly by typing ls into the terminal. This will list all the files in the current folder on your Red Pitaya. If you don't see "HelloWorld.s" and "build", ask a TA for assistance.


In your terminal (not in the Nano editor) type this command: chmod +x build. This command basically just tells the computer to transform the file "build" into an executable, or a file the computer can run. We can finally start executing some code.


To compile your code, run ./build in your terminal. This with create a new file called "HelloWorld" (namely different than "HelloWorld.s"). This is the code your computer can run. To run it, type ./HelloWorld into your terminal. This should output the phrase "Hello World!" in the next line of your terminal. If it does not, ask a TA for assistance.


Step 2

Here, you need to edit the code using Nano to make it more personal. To do this, change the string at the bottom of "HelloWorld.s" (Not "HelloWorld" or "HelloWorld.o") to "Hello [Your Name Here]!". Remember that the red pitaya needs to know how many characters to write on the screen, so you will need to update the line mov R2, #13 @ length of our string to the new length of the string. Remember to include spaces, special characters, and the "\n" as a single character when counting.


To check that your program works, you will need to run it again. It is important to note that you must recompile your code every time you make a change. You can recompile using the command ./build. Run your program again using ./HelloWorld, which should output "Hello [Your Name]!"into the terminal. Take a screenshot of the output, as well as your code, and make sure to include it in your lab report.



Step 3

This next step is pretty simple. Go into HelloWorld.s and change the LAST svc 0 to svc AnyOtherNumber. Where "AnyOtherNumber" is a number other than 0. Recompile your code and rerun it. What happened? Take a screenshot of the output and write out what you saw happen in your own words. If nothing happened, take note of that as well.

Conclusion


Congrats! You just completed your first lab for ECE1181. All that's left to do now is to write your lab report and submit it sometime before your next lab session. Check the assignment on Canvas for more information about what to include in your lab report. Note that the first lab is often the longest of the semester, and you will often get out 1-2 hours early depending on how fast you work.


You may have felt a little overwhelmed during this first session. That's okay. It may take a minute to settle into these concepts, but know that there are plenty of resources available to you if you are confused. See either Dr. Camp's office hours or preferably the TA office hours for help with labs, homework, or general questions about the course. We hope you have a great rest of your day and look forward to the next lab!

Code Given


Code is derived from Stephen Smith's Raspberry Pi Assembly Language Programming book, modified to fit the needs of this course. Credit belongs to the original author.


WARNING: I strongly recommend typing this into your Red Pitaya directly. The reason is that there are hidden symbols that may cause a high degree of frustration from copy/paste that would be spared by just typing it in. Also, you get a better feel for the code in doing so. You will likely not understand all that is happening in this code for now. That is okay. As the semester goes on, you will gain an understanding of everything you see below.


build

as -o HelloWorld.o HelloWorld.s
ld -o HelloWorld HelloWorld.o

HelloWorld.s

@ Assembler program to print "Hello World!"
@ to stdout.
@ R0-R2 - parameters to linux function services
@ R7 - linux function number

.global _start  @ Provide program starting @ address to linker
                @ Set up the parameters to print hello world
                @ and then call Linux to do it.
_start: 
    mov R0, #1          @ 1 = StdOut
    ldr R1, =helloworld @ string to print
    mov R2, #13         @ length of our string
    mov R7, #4          @ linux write system call
    svc 0               @ Call linux to print
                        @ Set up the parameters to exit the program
                        @ and then call Linux to do it.
.data
    mov R0, #0  @ Use 0 return code
    mov R7, #1  @ Service command code 1
                @ terminates this program
    svc 0       @ Call linux to terminate

helloworld: .ascii "Hello World!\n"