Sei sulla pagina 1di 36

Pr esent ed by:

Jan Ray C. Rul i da


INTRODUCTION TO
HARDWARE/FIRMWARE
INTERFACE DESIGN
'If a cluttered desk is a sign of a
cluttered mind, of what, then, is
an empty desk a sign?
-Albert Einstein
Quote:
My Desk:
INTRODUCTION TO
FIRMWARE
Origin of firmware
The word firmware was coined by Ascher Opler in 1967
In electronics systems and computing, this is
now referred to as the combination of persistent
memory and program code and data stored in it.

Firmware existed on the boundary between
hardware and software
Popular usage extended the word firmware to
anything that resides in ROM, include processor
machine-instructions for BIOS and bootloaders
WHAT IS FIRMWARE?
Also called embedded software
Non-volatile, this means that firmware is
installed on ROM (ROM, PROM, EPROM) or
FLASH chips.
Enables the device(e.g., embedded system,
etc.) to render its features and capabilities
functional
Usually written in C, C++, Java, Javascript,
or Lua.

WHAT IS FIRMWARE?
Commonly developed for embedded systems.
Found in smartphones routers, digital
watches, digital cameras, and pretty much
anything digital and runs on microcontrollers.

WHAT IS FIRMWARE?
From now on, let us make firmware refer to
any piece of code that is written and loaded
into hardware device to make that hardware
device work.
Let us also define firmware as any piece of
code that runs on hardware.
WHAT IS FIRMWARE?
Upgradable:
Firmware, nowadays, are stored in flash
memory making them easily updatable and
upgradable.

Portable:
Loading the firmware from the host system is
cheaper and more flexible. The loading of
firmware is done using device drivers.
TRENDS IN FIRMWARE
A bootloader is a piece of code that runs
before any operating system is running.
A bootloader is highly processor and board
specific as it is the first software to run after
powerup or reset.
Bootloaders also usually starts from ROM or
flash.
Bootloader code is moved to RAM for actual
execution.
A bootloader decides which OS kernel image
to use.
FIRMWARE vs BOOTLOADER
The bootloader removes the need for special
hardware to program and load firmware.
Bootloaders can also be classified as firmware, in
the sense that it is code embedded in hardware
FIRMWARE vs BOOTLOADER
When you upload a sketch(firmware), you're
using the Arduino bootloader. It allows you
to upload code without using any additional
hardware.
The bootloader is active for a few seconds
when the board resets; then it starts
whichever sketch was most recently
uploaded to the microcontroller. The
bootloader will blink the on-board (pin 13)
LED when it starts (i.e. when the board
resets).
ARDUINO FIRMWARE AND
BOOTLOADER
The bootloader removes the need for special
hardware to program and load firmware.
Bootloaders can also be classified as firmware, in
the sense that it is code embedded in hardware
FIRMWARE vs BOOTLOADER
FIRMWARE
DEVELOPMENT
Writing and developing firmware is closely
related to software engineering principles.
When developing firmware, one must know the
target device (8-bit, 16-bit, or 32-bit MCUs or
full-blown processors).
FIRMWARE DEVELOPMENT
Development tools should also be considered,
whether commercial or free (IAR, Keil, GCC)
Choosing a hardware and software debugger.
The choice of programming language should
also be taken into account (C/C++, Java,
Assembler, etc).
Licensing can also be an issue. (Commercial,
free, open-source, share-alike, etc.)
Version control: Github, Mercurial, Subversion
Bare-metal programming or use RTOS
FIRMWARE DEVELOPMENT
Requirements gathering
System architecture design
Firmware design (Hardware Design)
Firmware development (Hardware
Development)
Software and Hardware integration
Debugging and Testing
Validation
Deployment
Maintenance
FIRMWARE DEVELOPMENT CYCLE
According to William Y. Arms, there is a
Fundamental Assumption for software
processes:
Good processes lead to good software
Good processes reduce risk
Good processes enhance visibility
Good processes enable teamwork
FIRMWARE SOFTWARE PROCESS
SOURCE: Steps in the software development process by William Y. Arms. CS5150.
Cornell University Computing and Information Science. Fall 2013.
http://www.cs.cornell.edu/Courses/cs5150/2013fa/slides/B2-processes.pdf
#include "stm32f4xx_conf.h"
void TIM2_IRQHandler(void) {
if (TIM2->SR & TIM_SR_UIF) GPIOD->ODR ^= (1 << 13);

TIM2->SR = 0x0; // reset the status register
}

int main(void)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
GPIOD->MODER = (1 << 26);
NVIC->ISER[0] |= 1<< (TIM2_IRQn);
TIM2->PSC = 0x0;
TIM2->DIER |= TIM_DIER_UIE;
TIM2->ARR = 0x01;
TIM2->CR1 |= TIM_CR1_ARPE | TIM_CR1_CEN;
TIM2->EGR = 1;

while (1);
}

EXAMPLE 32-BIT ARM CODE
int led = 13;

void setup() {
pinMode(led, OUTPUT);
}

void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
EXAMPLE ARDUINO CODE
FIRMWARE AND
EMBEDDED
SYSTEMS
Firmware is an integral part of embedded
systems
FIRMWARE & EMBEDDED SYSTEMS
Typical embedded system components.
Figure from Software Engineering for Embedded Systems by Robert Oshana.
Processor Cores
Memory
Emulation and
Diagnostics
User Interface
Application-specific
gates
Analog I/O
Power and cooling
S
e
n
s
o
r
s

A
c
t
u
a
t
o
r
s

Software/Firmware
Firmware is everywhere
Over 95% of software systems are
actually embedded
Embedded systems permeate
everyday life, but are mostly taken
for granted

EMBEDDED SYSTEMS
Firmware should be safe, robust and reliable
Coding and quality standards must be
implemented and adhered to especially for
firmware used in mission and life-critical
embedded systems (e.g., MISRA C/C++ for the
automotive industry)
Good code could save a life, bad code could
kill a person. (e.g. Bookout v Toyota Motor
Corp.)
Be careful of stack overflow
SAFE AND RELIABLE FIRMWARE IN
EMBEDDED SYSTEMS
Internet of Things
Wearable electronics and technology
Sensor networks
Digital Signal Processing
Toys
Lower cost to entry for hardware design
FUTURE TRENDS IN FIRMWARE DEV
The Internet of Things (IoT) is a scenario
in which objects, animals or people are
provided with unique identifiers and the
ability to automatically transfer data over
a network without requiring human-to-
human or human-to-computer interaction.
INTERNET OF THINGS
SOURCE: http://whatis.techtarget.com/definition/Internet-of-Things
WEARABLE TECHNOLOGY
Image URL: http://static.dezeen.com/uploads/2013/03/Wearable-Technology-on-Dezeen.jpg
WEARABLE TECHNOLOGY
Image URL: http://static.guim.co.uk/sys-images/Guardian/Pix/pictures/2012/7/18/1342629671354/Google-Glass-008.jpg
SENSOR NETWORKS
SOURCE: http://searchdatacenter.techtarget.com/definition/sensor-network
A sensor network is a group of
specialized transducers with a communications
infrastructure intended to monitor and record
conditions at diverse locations.
Commonly monitored parameters are temperature,
humidity, pressure, wind direction and speed,
illumination intensity, vibration intensity, sound
intensity, power-line voltage, chemical
concentrations, pollutant levels and vital body
functions.
FIRMWARE DESIGN
AND IMPLEMENTATION
THINGS TO REMEMBER
Make your code efficient, stable, and easy to read.
Document your code. Always. I mean it. Seriously.
Use a version control system. Again, seriously.
Make yourself familiar with DMA (direct memory
access) and interrupts
Use timers.
Use coding standards, stick to it and be consistent
Make use of pointers and buffers to avoid
needlessly copying data
Remember that your system is typically connected
to real hardware; software errors can have
dramatic and expensive results.
Roughly determine the purpose of your
firmware.
Determine the challenges that your are facing
with regard to your firmwares purpose
Plan how to deal with these challenges. Do
you have a strategy to follow?
Make detailed plan for the firmware
architecture. Tesla might not approve, but
making drawings when planning your
architecture cant hurt.
Start documenting.

FIRST STEPS: FIRMWARE DESIGN
This largely depends on your target
microcontroller or system but the
following should be more or less
generic.
Set up the framework. These will include
empty header and source files.
Set up the clock of the microcontroller.
Create the main() function.
FIRMWARE IMPLEMENTATION
Set the pins of your microcontroller accordingly
and properly.
Set up your timer correctly. You will need it.
Work some blinkenlights to check your GPIOs,
clock and timer!
You may set up a UART for some extra debugging
and then try sending and receiving data using the
UART.
Start implementing the specific functions of your
firmwar.
Always commit your work to your version control
system.

FIRMWARE IMPLEMENTATION
C/C++ Programming
Knowledge of assembly language (not really).
When doing bare-metal programming,
knowledge of target
microcontroller/microprocessor architecture is
important.
A particular set of skills is needed for firmware
and embedded systems developers according
to specifications of the client .
Knows how to RTFM.
READY TO GET STARTED?
THANK YOU!

Potrebbero piacerti anche