Sei sulla pagina 1di 43

Embedded Systems

A perspective from the industry

(c) Nirav Patel


Microcontroller Basics

(c) Nirav Patel 2/


Microcontroller Basics
RAM
Memory
Flash

USART
Communication
SPI
uC Core (CPU)
GPIO (set as
input)
Inputs
ADC

PWM (via
Timers)
Outputs
GPIO (set as 3/
output)
Microcontroller Basics

1. How to get detailed information about a controller?

2. General points of comparison for controllers


a. Peripheral features like timers, UART, I2C, SPI etc.
b. Power consumption
c. Memory size (Flash and RAM)
d. Physical Size
e. Operating frequency

(c) Nirav Patel 4/


Microcontroller Basics

Questions

(c) Nirav Patel 5/


Agenda
1. Device drivers
2. Interrupts
3. Timing Analysis
4. Embedded Development tools

(c) Nirav Patel 6/


Device Driver Programming
Device Driver Programming
1. Driver acts as an interface between
Application the hardware and user application
software

Driver
2. Eliminates the application’s need to
know about the specifics of the
hardware.

Hardware (I/O, Uart, etc.) 3. Enables the application to be portable


across hardware platforms
Device Driver Programming
1. In this architecture, a device driver is
Application Task 1 Application Task 2 used by multiple tasks within the
application

2. For instance, serial communication


Driver can be used by multiple tasks in order
to transmit and receive data

3. Driver helps timeshare a single


Hardware (I/O, Uart, etc.)
hardware resource across multiple
tasks.
Device Driver Programming

Let’s look at an example!

(c) Nirav Patel 10 /


Device Driver Programming
Application 1. This architecture is an example of an
application compatible to run on
multiple hardware platforms
User Driver
2. Newer and older generations of a
phone running the same OS is a
classic example.
Hardware 1 driver Hardware 2 driver
3. An additional layer of abstraction
added to allow application to be
Hardware Platform 1 Hardware Platform 2 independent of hardware.
Device Driver Programming
1. This architecture is an example of an
Application 1 Application 2
application compatible to run on
multiple hardware platforms
Application specific abstraction
2. Running DOS within context of
Windows environment is an example
Common User Driver
of this abstraction.

Hardware 1 driver Hardware 2 driver 3. The application specific abstraction


acts as a mediator between the user
Hardware Platform 1 Hardware platform 2
driver and the application in such
cases.
Device Driver Programming
1. Let’s look at an example of a serial
Application communications driver

2. DLL responsible for error free transmit


Protocol Layer and receive operations.

3. Protocol layer responsible for


DLL (data link layer) interpreting received data and passing
it to the application

Hardware (I/O, Uart, etc.) 4. Protocol layer also collects data from
an application and transmits it
Device Driver Programming

1. Review the reference manual for the hardware.

2. Understand the underlying features and quirks of the hardware.

3. Most microcontroller manufacturers provide HAL drivers.


Device Driver Programming

Considerations:

1. Portability of your application across hardware platforms

2. Portability of your driver across applications.


Device Driver Programming

Questions

(c) Nirav Patel 16 /


Interrupts Basic

1. What is an interrupt?

2. Interrupt Vs. Polling

3. Advantages of using interrupts.


Interrupts
Finish current instruction
Interrupt
execution

Save current context


Processor (push local variables to stack,
save program counter etc.)

Execute program
Switch context to execute
Interrupt Service Routine (ISR)

Load previous context state


from the stack
Interrupts Vs. Polling

1. Efficient way to handle asynchronous events

2. Saves CPU execution cycles

3. Faster execution for time sensitive processing

4. Reduces chances of an event being missed


Interrupts - Considerations

1. Need good understanding of the hardware

2. Need to consider memory usage during interrupts – has the


potential to cause memory corruption.

3. Debugging becomes slightly difficult

4. Measuring timing performance of the system becomes difficult


Interrupts

Questions

(c) Nirav Patel 21 /


Software Timing Analysis

1. What is timing analysis?


2. Interrupts vs. tasks – which is more critical?
3. What if timing deadlines are not met?

(c) Nirav Patel 22 /


Software Timing Analysis

Example 1:

Worst case Worst


Interrupt Worst case
Priority execution Deadline case end Leeway
Name start time
time time

Interrupt 1 1 10 20 5 15 5

Interrupt 2 2 5 50 15 20 30

(c) Nirav Patel 23 /


Software Timing Analysis

Example 2:

Worst case Worst


Interrupt Worst case
Priority execution Deadline case end Leeway
Name start time
time time

Interrupt 1 1 10 50 5 15 35

Interrupt 2 2 5 10 15 20 -10

(c) Nirav Patel 24 /


Software Timing Analysis

Example 3:

Worst case Worst


Interrupt Worst case
Priority execution Deadline case end Leeway
Name start time
time time

Interrupt 2 1 5 10 10 15 -5

Interrupt 1 2 5 50 15 25 25

(c) Nirav Patel 25 /


Software Timing Analysis

1.Measuring timing
• Using an oscilloscope or a logic analyzer
• Using special software to collect timing data

(c) Nirav Patel 26 /


Software Timing Analysis

1.Assumptions very crucial to this analysis


2.Other factors to be considered
–Preemptive interrupts
–Mutually exclusive interrupts
–Periodic interrupts
–Timing data collection overheads

(c) Nirav Patel 27 /


Software Timing Analysis

Questions

(c) Nirav Patel 28 /


Tools

1. Program editor - Eclipse IDE for C/C++


2. Compiler, Linker - ARM GCC Tool chain
3. Change management - Bitbucket and SourceTree
4. Unit testing - CppuTest Framework

(c) Nirav Patel 29 /


Tool chains

1. Who has used IDEs like AVR Studio, mikroC, Keil etc.?

2. How is machine code generated?

(c) Nirav Patel 30 /


Tool chains
C/C++, 1. Collection of all
Assembly source files provided
Source files (.c .cpp .s) to compiler
Target Core –
e,g, AVR, ARM 2. Compiler Interprets
Compiler
options
Compiler the source code and
Object file (*.o files) generates object files
List file (*.lst files)
Target Core –
e,g, AVR
3. Linker takes the
Linker script file Linker object code, resolves
references and
(ld, dld files)

Machine Code (*.bin, *.s19


etc.) assigns it to physical
Map file (*.map) memory
Debug-able application (*.elf)
(c) Nirav Patel 31 /
Tool chains
1. A debugger uses the
Executable file (*.bin, information in elf file
*.s19, *.elf etc.)
Target – e.g.
to know the source
ATMega16, STM32 code being executed
currently.
Target Debugger
programming
algorithm

Target

(c) Nirav Patel 32 /


Tool chains

1. Compiler – GCC, Keil C51, Keil MDK ARM compiler 6 etc.

2. Linker – GCC, Keil armlink, etc.


3. Debugging interface – OpenOCD and GDB, DS-5 for ARM

(c) Nirav Patel 33 /


Let’s look at an example!

(c) Nirav Patel 34 /


Tool chains

Questions

(c) Nirav Patel 35 /


Software Source Control

1. How to efficiently manage software when a large team is working


on a project?

2. How to track changes made over time to the software?

(c) Nirav Patel 36 /


Software Source Control

1. Source control systems track changes


2. Git is an open source tool available
3. Other paid packages built on top of Git like Atlassian’s Bitbucket
4. Git is a popular tool used tool right now
5. Ideal for college projects as well

(c) Nirav Patel 37 /


Software Source Control

Let’s look at an example!

(c) Nirav Patel 38 /


Software Source Control

Questions

(c) Nirav Patel 39 /


Software Unit Testing

1. Unit testing is basically testing your application software with


another software
2. Very effective for catching software issues early in the
development process
3. Helpful with validating existing features after changes are made to
the software in the future

(c) Nirav Patel 40 /


Software Unit Testing

1. CppUTest is a good open source framework for unit testing


2. Provides coverage report for the source code under test

(c) Nirav Patel 41 /


Software Unit Testing

Let’s look at an example!

(c) Nirav Patel 42 /


Software Unit Testing

Questions

(c) Nirav Patel 43 /

Potrebbero piacerti anche