CSE 379 Lab #3




5/5 - (2 votes)

CSE 379
Lab #3

In this lab, you will learn how to communicate with the ARM processor via a serial connection using the UART
(universal asynchronous receiver transmitter). In doing so, you will also learn how to write and use assembly
language subroutines.
Write two (2) ARM assembly language subroutines, called output_character and read_character. These
subroutines will allow a user to enter a character and display the character in PuTTy via the UART. All user input
should be echoed back to the display.
PuTTy Setup
Open PuTTy (Start → All Programs → PuTTy → PuTTy) to communicate with the board. Select Serial as the
connection type. To determine which COM port the board is connected to, go to Start, and in the search bar type
cmd and press Enter. In the command line, type mode and press Enter. Typically, the highest numbered COM
port corresponds to the ARM board. In PuTTy enter COMx as the serial line, where x is the number of the COM
port you determined using mode command in the previous step. Set the baud rate to 115,200 in the speed field.
Save the session by entering Tiva-c under Saved Sessions and then hit Save. Load the session called Tiva-c by
selecting Tiva-c from the list and clicking on the Load button. The figures below will help you navigate the setup.
The following C program can be used to test your code. The program first initializes the UART by calling
serial_init, and then calls lab3, which is the assembly language subroutine that contains your code. This code is
available on the Labs page of the course website. The routine lab3 should call read_character followed by
output_character to allow the user to enter a character and then echo that character back to the display.
#include <stdint.h>
extern int lab3(void);
void serial_init(void);
void serial_init(void)
/* Provide clock to UART0 */
(*((volatile uint32_t *)(0x400FE618))) |= 1;
/* Enable clock to PortA */
(*((volatile uint32_t *)(0x400FE608))) |= 1;
/* Disable UART0 Control */
(*((volatile uint32_t *)(0x4000C030))) |= 0;
/* Set UART0_IBRD_R for 115,200 baud */
(*((volatile uint32_t *)(0x4000C024))) |= 8;
/* Set UART0_FBRD_R for 115,200 baud */
(*((volatile uint32_t *)(0x4000C028))) |= 44;
/* Use System Clock */
(*((volatile uint32_t *)(0x4000CFC8))) |= 0;
/* Use 8-bit word length, 1 stop bit, no parity */
(*((volatile uint32_t *)(0x4000C02C))) |= 0x60;
/* Enable UART0 Control */
(*((volatile uint32_t *)(0x4000C030))) |= 0x301;
/* Make PA0 and PA1 as Digital Ports */
(*((volatile uint32_t *)(0x4000451C))) |= 0x03;
/* Change PA0,PA1 to Use an Alternate Function */
(*((volatile uint32_t *)(0x40004420))) |= 0x03;
/* Configure PA0 and PA1 for UART */
(*((volatile uint32_t *)(0x4000452C))) |= 0x11;
int main()
Skeleton Code
The following ARM assembly language skeleton code can be used to get you started. It is available online on the
Labs page of the course website.
.global lab3

U0LSR: .equ 0x18 ; UART0 Line Status Register
STMFD SP!,{lr} ; Store register lr on stack

; Your code is placed here

LDMFD sp!, {lr}
mov pc, lr
You will work with a partner in this lab. Your partner MUST be the partner you signed up to work with online.
One partner is responsible for writing output_character and the other is responsible for writing
read_character. They must be done individually! It is recommended that you test output_character first, and
then use output_character to echo the character back when testing read_character. When testing, both
partners should be present and participate in the debugging process.
Demonstrations & Submissions
You MUST demonstrate to your TA that your output_character and read_character routines work properly
before starting the second part of this lab. The due date for getting output_character and read_character working
is the end of your lab session on February 17 or 18 (depending upon which day you have lab).