Using Linux with ARM Tutorial #3.

Slides:



Advertisements
Similar presentations
Computer System Laboratory
Advertisements

USERSPACE I/O Reporter: R 張凱富.
Lab7: Introduction to Arduino
U-Boot and Linux Kernel Debug using CCSv5
Configurable System-on-Chip: Xilinx EDK
Programming I/O for Embedded System. Page 2 Overview Basis: A DE2 Computer Architecture Parallel I/O 7-Segment Display Basic Manipulating 7-Segment Display.
ECE Department: University of Massachusetts, Amherst Lab 1: Introduction to NIOS II Hardware Development.
Dr. Kimberly E. Newman Hybrid Embedded wk3 Fall 2009.
CCNA 2 v3.1 Module 2.
Computer System Laboratory
Introduction Purpose Objectives Content Learning Time
1 Semester 2 Module 2 Introduction to Routers Yuda college of business James Chen
What is Router? Router is a device which makes communication between two or more networks present in different geographical locations. Routers are data.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
1 Chapter 2 ROUTER FUNDAMENTALS By: Tassos Tassou.
Silicon Labs ToolStick Development Platform
NET+OS 6.1 Training. BSP NET+OS 6.1 BSP Initialization Memory map New features Debugging Porting Issues.
Renesas Technology America Inc. 1 M16C/Tiny SKP Tutorial 2 Creating A New Project Using HEW4.
Configuring the MagicInfo Pro Display
Hands-On Microsoft Windows Server 2008
System Calls 1.
Getting Started Installing GreenHills and Net+OS Setting up the Development Board Building the Sample Application.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
AT91SAM9261-EK WinCE 6.0 DEMO ATMEL AT91 Application & Support Group
Hands-On Virtual Computing
ECE Department: University of Massachusetts, Amherst Using Altera CAD tools for NIOS Development.
University of Management & Technology 1 Operating Systems & Utility Programs.
AT91SAM9261-EK WinCE 5.0 DEMO ATMEL AT91 Application & Support Group Version 1.O February 2007.
Beagle Board Fast Boot Hui Chen Keji Ren Dec 10 th, 2009 EE382N-4 Project.
GBT Interface Card for a Linux Computer Carson Teale 1.
Page 1 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/Jansen June 2003 N e v e r s t o p t h i n k i n g. Infineon C868 Hands On Training CAPCOM6.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
NIOS II Ethernet Communication Final Presentation
S&IP Consortium Course Material Standard I/O and Core Peripherals Speaker: Tian-Sheuan Chang July, 2004.
SAPC Hardware Pentium CPU (or 486) 4M usable memory no hard disk; boot from floppy no keyboard or monitor or mouse COM2 serial port: used for console i/o.
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13 – Interrupt + Timer 2014/12/23 1 /16.
SOC Consortium Course Material Core Peripherals National Taiwan University Adopted from National Chiao-Tung University IP Core Design.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
SAM9260-EK WinCE DEMO AT91 SAM9 Product Group. Version 1.0 October 2006.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Altera University Program Cyclone V SoC Course
AT91 C-startup. 2 For reasons of modularity and portability most application code for an embedded application is written in C The application entry point.
CSC190 Introduction to Computing Operating Systems and Utility Programs.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Implementation of Embedded OS Lab3 Porting μC/OS-II.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Teaching Digital Logic courses with Altera Technology
Other Demos 1 Gsensor  Communicates with the accelerometer chip, displays the X, Y, Z acceleration values  Graphically displays an ASCII “bubble” in.
Hands-on Session 1 Boot Linux Connect to Linux via USB-to-UART and Putty Compile and run a simple program.
Embedded Systems Design with Qsys and Altera Monitor Program
Linux Boot Process on the Raspberry Pi 2 1 David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis,
Exercise 5: Developing an Embedded Application Write a software application to run on the system that we built in the previous exercise Compile the code.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Chap. 4 ARM Boot Loader Internals. 2 S3C2500 ARM940T Core module ARM9TDMI CoreIC.
1 © 2004, Cisco Systems, Inc. All rights reserved. CCNA 2 v3.1 Module 2 Introduction to Routers.
Introduction to Operating Systems Concepts
Computer System Laboratory
CCNA 2 v3.1 Module 2 Introduction to Routers
Lab 1: Using NIOS II processor for code execution on FPGA
Linux Kernel Development - Robert Love
Chapter Objectives In this chapter, you will learn:
Computer System Laboratory
CS4101 Introduction to Embedded Systems Lab 8: Tower System
Chapter 1: A Tour of Computer Systems
Computer System Laboratory
AT91RM9200 Boot strategies This training module describes the boot strategies on the AT91RM9200 including the internal Boot ROM and the U-Boot program.
SAPC Hardware Pentium CPU (or 486) 4M usable memory
Implementation of Embedded OS
Computer System Laboratory
Computer System Laboratory
Presentation transcript:

Using Linux with ARM Tutorial #3

Why use an Operating System? USB Device Drivers Keyboard, Mouse, Bluetooth Internet Stack Easily start using the Ethernet port Multi-threaded Applications

But Maybe an Operating System is Overkill If only limited OS features are required Use ARM Semihosting

Hands-on Session Learn about Semihosting functions

Exercise 6: Semihosting Virtual Operating System Allows C programs to make system calls I/O functions Time functions File operations Altera Monitor Program supports a subset printf and scanf to and from the terminal window. Some time functions

Printf, scanf and time functions Program Printf, scanf and time functions #include <stdio.h> #include <time.h> int main(void)( char str[64]; int age = 0; // Get the initial timestamp clock_t start_time = clock(); while(1){ printf("What is your name?\n"); scanf("%s",str); printf("What is your age?\n"); scanf("%d",&age); ... } return 0;

Step 1: Create a New Project Sets up the Altera Monitor Program Select files to work with Specify target system

Step 1.1: Specify name, directory and architecture

Step 1.2: Select the DE1-SoC Computer System

Step 1.3: Select Program Type and Sample Program

Step 1.4: Automatically Includes Example’s Source Files

Step 1.5: Set Board Connection and Select Processor

Step 1.6: Leave Default Memory Settings

Step 2: Program the FPGA with the Computer System

Step 3: Compile and Load Compile your C language program Load the compiled code into the memory on the DE1-SoC board

Step 4: Run

Step 5: Type in your name

Step 6: Type in your age

Step 7: See the Result of the Semi-hosting Functions

Step 8: Open the Sample Code

Please read the instructions at Hands-on Session Please read the instructions at “/exercise6/instructions.pdf”

Boot Sequence with Altera Monitor Program Resets the HPS Halts the code in the Boot ROM Loads a preloader into the HPS on-chip RAM Preloader comes pre-compiled with the Monitor Program Initializes the DDR3 SDRAM and HPS I/O pins Enables the HPS-FPGA bridges Disables the watchdog timers Re-maps the DDR3 SDRAM to address 0x00000000 Loads the user’s code into the DDR3 SDRAM Pauses the processor at the first instruction

Typical ARM Cortex-A9 Boot Sequence Boot ROM Hard coded by Altera Determines the boot source by reading the boot select pins Preloader In Flash/SD Card or FPGA Typically initializes the DDR3 SDRAM and HPS I/O pins Boot loader Loads and starts the operating system

We provide premade SD Card Images Linux SD Card Images We provide premade SD Card Images Preloader, Boot Loader, Linux (Kernel + Distro) FPGA related drivers Automatically programs FPGA with prebuilt system We have: Command-line GUI (Ubuntu)

Hands-on Session Boot Linux Connect to Linux via USB-to-UART and Putty Compile and run a simple program

Exercise 7: Talking to Linux on the DE1-SoC Compile and execute the “Hello World” program #include <stdio.h> int main(void){ printf("Hello World!\n"); return 0; }

Step 1: Power Off the DE1-SoC

Step 2: Set MSEL to `b01010 on the DE1-SoC Enables ARM to be able to configure the FPGA

Step 3: Insert Linux SD Card

Step 4: Power On the DE1-SoC

Step 5: Ensure the UART-to-USB is Connected to the Host Computer

Step 6: Check Device Manager for COM Port Settings

Step 7: Open Putty

Step 8: Select ‘Serial’ Connection Type

Step 9: Enter COM Port Name in ‘Serial line’ Box

Step 10: Enter Serial Port Settings as shown

Step 11: Save Session for Later Use

Step 12: Open Connection

Step 13: In Putty: Change to the Example Directory

Step 14: Compile the Sample Program

Step 15: Execute the Sample Program

Step 16: See the Output

Please read the instructions at Hands-on Session Please read the instructions at “/exercise7/instructions.pdf”

What if We Want to Communicate with the FPGA?

Copy the programming bitstream to Linux Then within Linux command line Programming the FPGA Create the desired system using the Quartus II software and the Qsys System Integration Tool Copy the programming bitstream to Linux Then within Linux command line Disable the HPS-FPGA bridges Configure the FPGA with your bitstream Re-enable the bridges

The Default DE1-SoC Computer System The Linux distribution automatically programs the FPGA with the DE1-SoC Computer System during boot

Virtual Addresses vs Physical Addresses Linux creates a virtual address space for programs FPGA peripheral are given physical addresses in Qsys Linux provides the function ‘mmap’ to map virtual address space to physical addresses ‘munmap’ un-maps addresses

Hands-on Session Communicate with FPGA peripheral within Linux

Exercise 8: Using FPGA Peripherals within Linux We will use the default DE1-SoC Computer system We will use the red LEDs and the slider switches The program copies the value of the switches to the LEDs

MMAP #define HW_REGS_BASE ( 0xff200000 ) #define HW_REGS_SPAN ( 0x00200000 ) #define HW_REGS_MASK ( HW_REGS_SPAN - 1 ) // Open /dev/mem if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) { printf( "ERROR: could not open \"/dev/mem\"...\n" ); return( 1 ); } // get virtual addr that maps to physical virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE ); if( virtual_base == MAP_FAILED ) { printf( "ERROR: mmap() failed...\n" ); close( fd ); return(1);

Using the Virtual Address #define LED_PIO_BASE 0x0 #define SW_PIO_BASE 0x40 volatile unsigned int *h2p_lw_led_addr=NULL; volatile unsigned int *h2p_lw_sw_addr=NULL; // Get the address that maps to the LEDs h2p_lw_led_addr=(unsigned int *)(virtual_base + (( LED_PIO_BASE ) & ( HW_REGS_MASK ) )); h2p_lw_sw_addr=(unsigned int *)(virtual_base + (( SW_PIO_BASE ) & ( HW_REGS_MASK ) )); while(!stop){ *h2p_lw_led_addr = *h2p_lw_sw_addr; }

MUNMAP if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) { printf( "ERROR: munmap() failed...\n" ); close( fd ); return( 1 ); }

Step 1: Open the Connection to the DE1-SoC using Putty

Step 2: Change to the Example Directory

Step 3: Compile the Sample Program

Step 4: Execute the Sample Program

Step 5: The Program is Running. Try Toggling the Switches.

Step 6: Press Control-C to Exit the Program

Step 7: Open the leds.c file. See the mmap usage.

Please read the instructions at Hands-on Session Please read the instructions at “/exercise8/instructions.pdf”

Handling Interrupts from FPGA Peripherals This requires a Linux device driver A. Modify the Linux kernel B. Write a kernel module Kernel modules can be loaded at run-time Easily register interrupt handler using library functions

Interrupt handling (optional) Exit routine Kernel Modules Initialization Sets up the module upon loading Interrupt handling (optional) Exit routine Clears used resources upon unloading

Hands-on Session Create a Linux device driver

Exercise 8: Creating a Linux Device Driver We will use the red LEDs and pushbuttons The program increments the value displayed on the LEDs when a pushbutton is pressed

Kernel Module - Initialization void * lwbridgebase; static int __init intitialize_pushbutton_handler(void) { // get the virtual addr that maps to 0xff200000 lwbridgebase = ioremap_nocache(0xff200000, 0x200000); // Set LEDs to 0x200 (the leftmost LED will turn on) iowrite32(0x200,lwbridgebase); // Clear the PIO edgecapture register (clear any pending interrupt) iowrite32(0xf,lwbridgebase+0x5c); // Enable IRQ generation for the 4 buttons iowrite32(0xf,lwbridgebase+0x58); // Register the interrupt handler. return request_irq(73, (irq_handler_t)irq_handler, IRQF_SHARED, "pushbutton_irq_handler", (void *)(irq_handler)); } module_init(intitialize_pushbutton_handler);

Kernel Module – Interrupt Handler irq_handler_t irq_handler(int irq, void *dev_id, struct pt_regs *regs) { // Increment the value on the LEDs iowrite32(ioread32(lwbridgebase)+1,lwbridgebase); // Clear the edgecapture register (clears current interrupt) iowrite32(0xf,lwbridgebase+0x5c); return (irq_handler_t) IRQ_HANDLED; }

Kernel Module – Exit Routine static void __exit cleanup_pushbutton_handler(void) { // Turn off LEDs and de-register irq handler iowrite32(0x0,lwbridgebase); free_irq(73, (void*) irq_handler); } module_exit(cleanup_pushbutton_handler);

Step 1: Open the Connection to the DE1-SoC using Putty

Step 2: Change to the Example Directory

Step 3: Compile the Sample Program

Step 4: Compilation Complete

Step 5: Insert Newly Compiled Kernel Module into Linux

Step 6: Run ‘lsmod’ to See All Loaded Kernel Modules

Step 6: The Pushbutton IRQ Handler was Loaded

Step 7: Try Toggling the Pushbuttons

Step 8: Remove the Kernel Module

Step 9: Run ‘lsmod’ to See All Loaded Kernel Modules

Step 10: Examine the ‘pushbutton_irq_handler.c’ file

Please read the instructions at Hands-on Session Please read the instructions at “/exercise9/instructions.pdf”

Where did we go from here? Summary #4 What did we learn? Using semi-hosting ARM Cortex-A9 Boot Sequence How to run the Linux operating system How to communicate between the HPS and FPGA under Linux How to create a kernel module Where did we go from here? Tutorials: Using Linux on the DE1-SoC Using Terminals with DE-Series Boards SD Card images Linux for the DE1-SoC Tons of Linux documentation online http://university.altera.com