Professional Documents
Culture Documents
Application using uC/OS-II on Stellaris Guru Evaluation Kit for Teaching ARM Cortex- M3 and Embedded Systems
By
Prof. P.V.Patel
CERTIFICATE
This is to certify that the project titled Application using uC/OS-II on Stellaris
Guru Evaluation Kit for Teaching ARM Cortex- M3 and Embedded Systems by VAISHNAV JAYKUMAR P. & THAKKAR SUKET J. is a
bonafide work carried out by him under my guidance and supervision.
Prof. P.V. Patel Project Supervisor, Department of Electronics & Communication DDU , Nadiad.
ABSTRACT
The goal of the project is to understand the features of Stellaris Guru Evaluation Kit and to port a Real Time Operationg System (RTOS) on it to do & understand multitasking. Three tasks are created and multitasking has been done to bring out the advantage of the RTOS , that is aading more intelligence and time accurate system. We are thankful to our project supervisor and head of department for including term project in 7th semester. It is very helpful in improving our fundamentals and also getting in touch with the new technology trends. Term project got very useful while dealing with company interviews. We are very thankful to Prof. M.J. Limachia sir who aspired to make project on this kit. We are also thankful to Prof. V.A.Vohra sir who has provided the guidance to fulfil the project on RTOS.
APPLICATIONS OF PROJECT
The project is used to do efficient multitasking between several tasks (i.e. LED patterns , temperature control , MIC ,UART etc. for this kit). Soft real time operations can be done successfully, which in turn get useful getting knowledge about hard real time systems (i.e. PLC). Since its real time system it can be used in Vehicle Braking , Toaster.
CONTENTS
No.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
Name of topic
The Stellaris Guru kit Overview of ARM Cortex M3 Evolution of the ARM Instruction Set LM3S608 Microcontroller Features Components of kit Real Time System & Concepts Working of Semaphore Simulation in Keiluvision4 & Output Troubleshooting References
Page No.
1
LIST OF FIGURES
No.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13.
Caption of figures
Stellaris Guru Kit Kit components ARM Cortex M3 v/s ARM7TDMI Pin Out Diagram of LM3S608 Power supply Temperature Sensor and Potentiometer Task operations Task State Diagram Non-Preemptive Kernel Preemptive Kernel Synchronizing tasks and ISRs Tasks synchronizing their activities Screenshots
Page No.
Xyz
Reset pushbutton and power indicator LED. A LM35 temperature sensor for taking temperature readings using the Analog to Digital Convertor. Thumbwheel potentiometer for reading analog voltage through one of the ADC channels of the microcontroller. Microphone amplifier with high gain and sensitivity connected to an independent ADC channel of the microcontroller. Ambient light sensor using a LED operated in reverse bias. Standard ARM 20[pin JTAG debug connector. Arduino compatible interface connector. UART0 accessible through a USB virtual COM port (VCP). Programmable through UART using preinstalled boot loader. USB interface for all communication and power.
Fig.3 ARM Cortex M3 v/s ARM7TDMI Note: Dhrystone MIPS (DMIPS); Million Instructions Per Second (MIPS)
For ARM Instructions More 16-bit Thmb instructions are required to execute same functions compared to ARM instructions. But performance may be degraded.
THUMB-2 Instruction Set Instruction Set: Word length: Architecture: Registers: Thumb2 32 bit Harvard (ARMv7-M) 13 general purpose, 1 Stack Pointer, 1 Link Register, 1 Program Counter, 1 Program Status, Special Registers 1.25 DMIPS/MHz (Dhrystone MIPS) 12 Cycles
Benchmark: Interrupt-Latency:
Energy consumption: 0.19 mW/MHz Area 5]: 0.86mm2 (Core and Peripherals) Note: Does not include optional system peripherals (MPU & ETM) or integration level component Features: NVIC, Sleep modes, MPU, Bit-Banding, Debug functionality
On chip internal temperature sensor. Sample rate of 500 thousand samples/second. UART Two fully programmable 16C550 type UARTs. Separate 16x8 transmit (TX) and receive (RX) FIFOs to reduce CPU interrupt service loading. Fully programmable serial interface characteristics 5,6,7 or 8 data bits. Even/Odd/Stick or No Parity generation. 1 or 2 stop bit generation. Synchronous Serial Interface Master of Slave Operation. Programmable clock bit rate and operation. Programmable data frame size from 4 to 16 bits. I2C Devices on the I2C bus can be designated as either master or a slave. Four I2C modes: Master transmit Mater receive Salve transmit Slave receive Two transmission speeds, standard (100kbps) and Fast (400kbps). Master and slave interrupt generation. Analog Comparators One integrated analog comparator. Configurable for output to drive an output pin, generate an interrupt or initiate an ADC sample sequence. Power On chip Low Drop (LDO) voltage regulator with programmable output user adjustable from 2.25V to 2.75V.
Low power options on controller: Sleep and Deep Sleep Modes. Low power options for peripherals: software controls shutdown of individual peripherals. 3.3V supply brownout detection and reporting via interrupt or reset. Flexible Reset Sources Power on Reset (POR) Reset pin assertion. Brownout (BOR) detector alerts to system power drops. Software reset. Watchdog timer reset. JTAG IEEE 1149.1 1990 compatible Test Access Port (TAP) controller. Four bits Instruction Register (IR) chain for storing JTAG instructions. IEEE standard instructions: BYPASS, IDCODE, SAMPLE/PRELOAD, EXTEST and INTEST. Integrated ARM Serial Wire Debug (SWD).
The soul of the Stellaris Guru is the LM3S608 microcontroller. It follows the ARM Cortex-M 32-bit RISC architecture. The LM3S608 used on the kit is in the 48-pin Thin Quad FlatPackage (TQFP). The pin assignment is shown is Figure 4.
5.Components of kit
5.1 Power Supply
The power supply section of the kit is shown below in Figure 5. Power is drawn directly from the USB bus of a computer, which is at +5V potential. This voltage is then fed to a Low Drop Out voltage regulator LM1117[3.3 (IC3) to generate +3.3V required by the microcontroller and other kit components. Tantalum capacitors C1 and C2 provide input and output filtering respectively. LED1 connected in series with the resistor R1 provides visual indication for power being supplied to the kit.
Definition:
Real Time Systems are characterized by consequences that result if logical as well as timing correctness properties of the system are not met A real-time deadline must be met, regardless of system load There are two types of real-time systems: SOFT and HARD.
Types of RTOS:
Soft Real Time Tasks are performed by the systems as fast as possible, but failing to complete within specified deadlines is not catastrophic. Video Surveillance, Radio Transmissions, Online Ticket reservation systems, etc.., Hard Real Time Tasks have to be performed not only correctly but in time. Failure to comply to the set deadlines would result catastrophical Nucleur Reactors, Vehicle Braking, etc... Most real-time systems have a combination of SOFT and HARD requirements. Real-time applications cover a wide range. Most applications for real-time systems are embedded. This means that the computer is built into a system and is not seen by the user as being a computer.
Jet engine controls Domestic: Microwave ovens Dishwashers Washing machines Thermostats
Multitasking:
Multitasking is the process of scheduling and switching the CPU between several tasks. A single CPU switches attention between several sequential tasks. Multitasking is like FG/BG with multiple BGs.
Advantages of Multitasking:
Maximizes the CPU Utilization. It Provides Modular construction of Applications. Application programs are typically easier to design & maintain if Multitasking is used.
Task:
A task, also called a thread, is a simple program that thinks it has the CPU all to itself.
Real Time application involves splitting the work to be done in Tasks. Each Task is assigned its own set of CPU Registers, Stack Area and a Priority.
Task State:
DORMANT READY RUNNING WAITING ISR Note: Typically Tasks are infinite loops
Dormant State:
Corresponds to the task that resides in the memory but has not been made available to the multitasking Kernel
Ready State:
A task is READY when it can execute but its priority is less than the currently running task.
Running Task:
A task is running when it has control of the CPU
Waiting State:
A Task is waiting when it requires a occurrence of a event (waiting for an I/O operation to complete, a shared resource to be available, a timing pulse to occur, time to expire etc).
ISR State:
A task is in the ISR State when an interrupt has occurred and the CPU is in the process of servicing the Interrupt
Kernel:
Fundamental Service provided by the Kernel is Task Switching Kernel simplifies the design of a system allowing the application to be divided into several tasks. Kernel adds overhead to the System(ROM & RAM) & also consumes CPU time(2-5%)
Task Priority:
A priority is assigned to each task The more important the task the more the priority Two types of priority assigning Static (Assigned at Compile Time) Dynamic (Assigned at Execution Time)
Scheduler:
Part of the Kernel which will decide the next task to run Most RT Kernels are priority based Control is always given to highest priority task ready to run Two types of priority based Kernels Non-Preemptive Preemptive
Semaphores:
Control Access to a shared resource (ME) Signal Occurrence of an event Allow two tasks to synchronize their activities Synchronization Further elaboration is done in the section Working of Semaphore.
7. Working of Semaphore
A task can be synchronized with an ISR, or another task when no data is being exchanged, by using a semaphore as shown in Figure below . Note that, in this case, the semaphore is drawn as a flag, to indicate that it is used to signal the occurrence of an event (rather than to ensure mutual exclusion, in which case it would be drawn as a key). When used as a synchronization mechanism, the semaphore is initialized to 0. Using a semaphore for this type of synchronization is using what is called a unilateral rendezvous. A task initiates an I/O operation and then waits for the semaphore. When the I/O operation is complete, an ISR (or another task) signals the semaphore and the task is resumed.
Fig.11 : Synchronizing tasks and ISRs If the kernel supports counting semaphores, the semaphore would accumulate events that have not yet been processed. Note that more than one task can be waiting for the event to occur. In this case, the kernel could signal the occurrence of the event either to: a) the highest priority task waiting for the event to occur, or b) the first task waiting for the event. Depending on the application, more than one ISR or task could signal the occurrence of the event. Two tasks can synchronize their activities by using two semaphores, as shown in Figure below. This is called a bilateral rendezvous. A bilateral rendezvous is similar to a unilateral rendezvous except both tasks must synchronize with one another before proceeding.
Fig.12 : Tasks synchronizing their activities. C/OS-II Semaphore functions Provides for using same semaphore functions as an event signaling flag or mutex or counting semaphore
Semaphore for event flag functions When a semaphore created is used as a an event signaling flag or as counting semaphore, semaphore value at start = 0, which means event yet to occur and 1 will mean event occurred. Semaphore as mutex functions When a semaphore created is used as a resource acquiring key, Semaphore value at start = 1, which means resource available and 0 will mean not available. OSSemCreate (semVal) OS_Event OSSemCreate (unsigned short semVal) OSSemPend (*eventPointer, timeOut, *SemErrPointer) void OSSemPend (OS_Event *eventPointer, unsigned short timeOut, unsigned byte *SemErrPointer) OSSemAccept (*eventPointer) unsigned short OSSemAccept (OS_EVENT *eventPointer) To create and initialize semaphores. For event-flag, key and count, respectively. To check whether semaphore is pending or not pending (0 or >0). If pending (=0), then suspend the task till >0 (released). If >0, decrement the value of semaphore and run the waiting codes To check whether semaphore value > 0 and if yes, then retrieve and decrement. Used when there is no need to suspend a task, only decrease it to 0 if value is not already zero. SemVal if 0 or more, increment. Increment makes the semaphore again not pending for the waiting tasks.
Fig.13.3: In this figure we have to create our application tasks which are specified here as Task(A,B & C).
Fig.13.5: As Task A has got 2nd priority so after execution of Task C, due to OSdelay(), it will jump here.
Fig.13.6: As Task b has got 3rd priority, due to sempost , so that it will jump here.
Fig.13.7: This figure shows how to give delay in OS. As in above figure 6u is defined, which means 6 microsec delay. We can change value over there according to our application.
Fig.13.8: This figure shows after execution of Task C two step, see in GPIO C window I/O Port pin 7 goes low.
Fig.13.9: This figure shows after execution of Task A all step, see in GPIO B window I/O Port pin (7,6,5) goes low.
Fig.13.10: This figure shows after execution of Task B, as shown in GPIO D I/O pin (7,5) gows down, in figure blue arrow indicates that, due to time over of OSdelay it will again go to Task C, now when again OSdelay comes in TaskC it will resume its position from where it had ended, in figure it is shown by yellow color arrow.
9. Troubleshooting
Since the software and hardware both were new for us , it took much time first to become familiar with it. Our half of the semester(!) just gone understanding Eclipse,Cortex-M3. It was tedious doing all time the configuration settings for each new project created. Thats what shown in Manual of kit. After becoming familiar we are given a task to port OS in kit & perform an application on it afterwards. Thats now new challenge. We wandered on internet & to our CE friends to know concepts of OS & then for knowing the concepts of Semaphore. VAV sir helped a lot. We got tons of errors(!) while simulating the program in Eclipse. Then the tragedy was eliminated , when Keil comes to help us saying that Im with you why Eclipse? . Keil uv4 was helpful running our 8KB code , which is not possible in Keil uv3 (2KB max. size). Atlast the OS got ported in kit(bingo). Now, 75% task is done. But 25% was also not easy. We gone through Rajkamal book for embedded and also uCOS-II ebook. Many fundamentals got cleared. Then the tasks created and multitasking is done. Also , making an report is also not an easy task !...
10. References
1. 2. 3. 4. 5. 6. 7. Stellaris Guru Manual V7 Final ebook. uCOSII_ebook Use r Guide for Stellaris Peripheral Driver Library;. Embedded System by RajKamal. www.dreamcatcher.asia/cw (ARM Cortex M3 , Thumb State) www.pudn.com (OS Porting information) www.en.wikipedia.com/RTOS (Information about Real Time Systems)