Professional Documents
Culture Documents
Introduction to Embedded
Software Development
Create project
Add files to project
Setup project options
Compile and link
Flash programming
Execute program and debug
During execution of the compiled program, you can check the
program execution status and results by outputting information via
various I/O mechanisms such as a UART interface or an LCD
module
1
Compiling your applications
Toolchaine
ARM Toolchaine
Most development
GNU ToolChaine
suites contain the
tools listed
5
Various Tools in a Development Suite
Polling
Polling method
for simple
application
processing
2
Software development flow
The processor can enter sleep mode to
Interrupt driven
save power when no servicing is needed
Simple
interrupt-driven
application
Software
development flow
Application with
both polling
method and
interrupt-driven
arrangement
When the applications get more complex, some tasks that can
take a long time to execute might need to be processed
concurrently.
3
Software development flow
RTOS
at the end of each time slot, a
timer generates a timer interrupt,
which triggers the task
scheduler and decides if context
switching should be carried out.
If yes, the current executing
process is suspended and the
rocessor executes another
process.
10
Instruction Set
11
4
SOFTWARE DEVELOPMENT TOOLS
There are many software tools (IDE :Integrated Development Envirenment)
CCS Cloud
Energia:
Driver Library
MSPWare:
13
• User’s Guides
• Application Notes
• Deep-dive Training
• Code Examples
14
EnergyTrace+TM technology
Provides a complete ecosystem for real-time power debugging and quickens time to
market. Spends less time debugging and more time developing.
Graphical User Interface in TI’s Code Composer Studio integrated development
environment (IDE) and IAR Systems’ Embedded provides energy profiles of your
application
Current measurement and CPU states can be tracked over time to help identify
power black holes
15
5
SW Development Environment
16
A Cortex-M3
development board
from Keil
STM32 Value TI MSP432 LaunchPad (MCBSTM32)
Line Discovery 17
18
6
What you need to start : MSP432 LaunchPad
Develop high performance applications
that benefit from low power operation
Features
• Low-power, high performance MSP432P401R MCU
• 40 pin BoosterPack Connector, and support for 20 pin BoosterPacks
• Onboard XDS-110ET emulator featuring EnergyTrace+ Technology
• 2 buttons and 2 LEDs for User Interaction
• Back-channel UART via USB to PC
Kit Includes
Development board with demo application
USB cable
Quick start guide
Software
MSPWare featuring example code, User’s Guides, Application notes,
training, and more
Out-of-box LaunchPad GUI
MSP-EXP432P401R
$12.99
19
MSP432 LaunchPad
20
MSP432 LaunchPad
21
7
22
23
24
8
25
Block Diagram
26
9
Schematics (1 of 6)
30
29
28
10
BoosterPack Pinout
31
32
33
11
Flowcharts
34
64
Embedded C
Anatomy of a program
35
12
PORT CONFIGURATION
There are two approaches to configure MSP432 subsystems :
the registers may be configured directly using C programming techniques
or via higher level application program interface (APIs).
The MSP432 has an extensive complement of APIs for all MSP432 subsystems within the
MSPWare library for example, the following APIs available for I/O:
void GPIO_setAsOutputPin(uint_fast8_t selectedPort, uint_fast16_t
selectedPins)
void GPIO_setAsInputPin(uint_fast8_t selectedPort, uint_fast16_t selectedPins)
void GPIO_setOutputHighOnPin(uint_fast8_t selectedPort, uint_fast16_t
selectedPins)
void GPIO_setAsInputPinWithPullUpResistor(uint_fast8_t selectedPort,
uint_fast16_t selectedPins)
uint8_t GPIO_getInputPinValue(uint_fast8_t selectedPort, uint_fast16_t
selectedPins)
37
PORT CONFIGURATION
Register configuration: The “msp.h” header file within the CCS compiler
provides the link between software and the MSP432 hardware.
//******************************************************************
*****
// DIO Registers
//
//Copyright, Texas Instruments, [www.TI.com]
//****************************************************************
#define PAIN (HWREG16(0x40004C00)) //Port A Input
#define PAOUT (HWREG16(0x40004C02)) //Port A Output
#define PADIR (HWREG16(0x40004C04)) //Port A Direction
#define PAREN (HWREG16(0x40004C06)) //Port A Resistor Enable
#define PADS (HWREG16(0x40004C08)) //Port A Drive Strength
#define PASEL0 (HWREG16(0x40004C0A)) //Port A Select 0
#define PASEL1 (HWREG16(0x40004C0C)) //Port A Select 1
//****************************************************************
38
PORT CONFIGURATION
the 16-bit PORTA is comprised of two 8-bit ports P1 and P2. snapshot of the
file containing memory locations for the Port P1 and P2 associated registers
//***************************************************************
// DIO Registers [www.TI.com]
//*************************************************************
#define P1IN (HWREG8(0x40004C00)) //Port 1 Input
#define P2IN (HWREG8(0x40004C01)) //Port 2 Input
#define P2OUT (HWREG8(0x40004C03)) //Port 2 Output
#define P1OUT (HWREG8(0x40004C02)) //Port 1 Output
#define P1DIR (HWREG8(0x40004C04)) //Port 1 Direction
#define P2DIR (HWREG8(0x40004C05)) //Port 2 Direction
#define P1REN (HWREG8(0x40004C06)) //Port 1 Resistor Enable
#define P2REN (HWREG8(0x40004C07)) //Port 2 Resistor Enable
#define P1DS (HWREG8(0x40004C08)) //Port 1 Drive Strength
#define P2DS (HWREG8(0x40004C09)) //Port 2 Drive Strength
#define P1SEL0 (HWREG8(0x40004C0A)) //Port 1 Select 0
#define P2SEL0 (HWREG8(0x40004C0B)) //Port 2 Select 0
#define P1SEL1 (HWREG8(0x40004C0C)) //Port 1 Select 1
#define P2SEL1 (HWREG8(0x40004C0D)) //Port 2 Select 1 39
//*****************************************************************
13
PORT CONFIGURATION
Also included in the header file are definitions for each register. For example,
provided below is the definition for the PADIR register referred to as “rPADIR.”
union
{ //PADIR Register
__IO uint16_t r;
Struct { //PADIR Bits
__IO uint16_t bP1DIR : 8; //Port 1 Direction
__IO uint16_t bP2DIR : 8; //Port 2 Direction
}b;
}rPADIR;
Definitions are also provided for the constituent bP1DIR and bP2DIR bits:
//PADIR[P1DIR] Bits
#define P1DIR_OFS ( 0) //P1DIR Offset
#define P1DIR_M (0x00ff) //Port 1 Direction
//PADIR[P2DIR] Bits
#define P2DIR_OFS ( 8) //P2DIR Offset
#define P2DIR_M (0xff00) //Port 2 Direction
40
PORT CONFIGURATION
The following example toggles the LED at pin P1.0.
• disabling the watchdog timer.
• The next line configures pin P1.0 as an output pin.
• Note how the specific bit related to pin P1.0 is accessed within the PADIR register.
//******************************************************************
// MSP432 main.c - P1.0 port toggle [www.TI.com]
//******************************************************************
#include "msp.h"
void main(void) {
volatile uint32_t i;
WDT_A->rCTL.r = WDTPW | WDTHOLD; //Stop watchdog timer
DIO->rPADIR.b.bP1DIR |= BIT0; //Configure P1.0 as output
//*****************************************************************
//MSP432 main.c - P1.0 port toggle ////Built with Code Composer Studio v6
//*****************************************************************
#include <driverlib.h>
void main(void) {
volatile uint32_t i;
WDT_A_hold(WDT_A_BASE); //Stop watchdog timer
//Set P1.0 to output
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
while(1) {
//Toggle P1.0 output
GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
for(i=10000; i>0; i--); //Delay
}
} 42
14
//*****************************************************
Frequently, within a microcontroller application, the program begins
with system initialization
actions. Once initialization activities are completed, the processor
enters a continuous loop.
this may be accomplished using the following code fragment.
//*****************************************************
while(1)
{
….
….
…
}
//*****************************************************43
if_example.c
#include "msp.h"
void main(void) {
unsigned char switch_value;
WDT_A->rCTL.r = WDTPW | WDTHOLD; //Stop watchdog timer
DIO->rPADIR.b.bP1DIR |= 0x01; //Bit 0 to logic 1
//Configure P1.1 as input (0) for switch with pullup resistor enabled:
// PxDIR = 0, PxREN = 1, PxOUT = 1
DIO->rPADIR.b.bP1DIR &= 0xfd; //Bit 1 to logic 0
DIO->rPAREN.b.bP1REN |= 0x02; //Bit 1 to logic 1
DIO->rPAOUT.b.bP1OUT |= 0x02; //Bit 1 to logic 1
while(1) {
switch_value = DIO->rPAIN.b.bP1IN;
if((switch_value & 0x02) == 0x02) {
DIO->rPAOUT.b.bP1OUT |= 0x01; //P1.0 to logic one
printf("high\n"); }
Else {
DIO->rPAOUT.b.bP1OUT &= 0xFE; //P1.0 to logic zero
printf("low\n"); } }
}
44
Procedure 1: Energia.
1. Create a counter that counts continuously from 1–100 with a 50 ms
delay between counts. the red LED should illuminate for odd numbers
and green LED for even
Procedure 2: C.
1. Develop a program that prompts the user for two integer numbers. If the
first number is less than the second, the program should count up
continuously from the lower to the higher number with a 50 ms delay
between counts. e onboard red LED should illuminate forodd numbers and
the onboard green LED for even numbers. If the first number is higher, the
program should count down
45
15
ASSEMBLER
Msp432 Instruction Set
46
Instruction Set
47
Instruction Types
A general-purpose instruction set can be expected to include
instructions in the following categories:
• Data processing: e.g., add, subtract, multiply
• Data movement: that copy data between memory and memory, or
between memory and register.
• Control flow instructions: that switch execution from one part of
the program to another, possibly depending on data values.
• Special instructions to control the processor’s state: for
instance to switch into a privileged mode to carry out an OS function.
Orthogonal:
An instruction set is said to be orthogonal if each choice in the
building of an instruction is independent of the other choices. An
orthogonal instruction set is easier for the assembly language
programmer to learn and easier for the complier writer to target. The
hardware implementation will usually be more
efficient too.
48
16
Addressing Modes
When accessing an operand for a data processing or movement
instruction, there are several standard techniques used specify the
desired location.
• Immediate
• Absolute
• Indirect
• Register
• Register indirect
• Base plus offset
• Base plus index
• Base plus scaled index
• Stack addressing
49
50
51
17
Instruction Set
A number of different directives are available in both ARM assembler
and GNU assembler for inserting data into a program
52
53
Instruction Set
-- - Moving data within the processor
18
Instruction Set
Memory access instructions for various Data Sizes
Note: The LDRSB and the LDRSH automatically perform a sign extend
operation on the loaded data to convert it to a signed 32-bit value. For
example, if 0x83 is read in a LDRB instruction, the value is converted into
0xFFFFFF83 before being placed in the destination register
55
Instruction Set
Immediate offset (pre-
index)
57
19
Instruction Set
PC-related addressing (Literal)
A memory access can generate the address value from the current
PC value and an offset value (Table). This is commonly needed for
loading immediate values into a register, also known as literal pool
accesses (LDR pseudo instruction).
58
Instruction Set
-- Register offset (pre-index)
For example:
LDR R3, [R0, R2, LSL #2] ; Read memory[R0+(R2 << 2)] into R3
The shift operation is optional.
59
Instruction Set
Memory access instructions with post indexing
One of the key advantages of the ARM architecture is that it allows you
to read or write multiple data that are contiguous in memory. The
LDM (Load Multiple
registers) and STM
(Store Multiple registers)
instructions only support
32-bit data.
They support two types
of pre-indexing:
20
Instruction Set
-- Arithmetic operations
For example, an ADD instruction can operate between two registers or
between one register and an immediate data value:
ADD R0, R0, R1 ; R0 = R0 + R1
ADDS R0, R0, #0x12 ; R0 = R0 + 0x12 with APSR (flags) update
ADC R0, R1, R2 ; R0 = R1 + R2 + carry
in Unified Assembly Language (UAL) syntax, the S suffix should be
used if the following operation depends on the flags:
ADD R0, R1, R2 ; Flag unchanged
ADDS R0, R1, R2 ; Flag change
Instruction Set
Instractions for arithmetic data operations
62
Instruction Set
Instructions for Logical operations
63
21
Instruction Set
Instructions for Shift and Rotate Operations
64
Instruction Set
Instructions for Shift and Rotate Operations
65
Instruction Set
Bit-field processing instructions
22
Instruction Set
Bit-field processing instructions
BFI (Bit Field Insert ) copies 1 to 31 bits (#width) from one register to
any location (#lsb) in another register.
The syntax is: BFI <Rd>, <Rn>, <#lsb>, <#width>
For example:
LDR R0,=0x12345678
LDR R1,=0x3355AACC
BFI R1, R0, #8, #16 ; Insert R0[15:0] to R1[23:8]
This will give R1 = 0x335678CC.
The RBIT instruction reverses the bit order in a data word.
The syntax is: RBIT <Rd>, <Rn>
This instruction is very useful for processing serial bit streams in data
communications. For example, if R0 is 0xB4E10C23 (binary value
1011_010 0_1110_0001_000 0_1100_0010 _0011) , executing :
RBIT R0, R1
R0 will become 0xC430872D (binary value 1100_010 0_0011_0
000_1000 _0111_001 0_1101) 67
UBFX
UBFX <Rd>, <Rn>, <#lsb>, <#width>
SBFX <Rd>, <Rn>, <#lsb>, <#width>
UBFX extracts a bit field from a register starting from any location
(specified by the < #lsb> operand) with any width (specified by the
< #width> operand), zero extend s it, and puts it in the destina tion
register. For example:
LDR R0,=0x5678ABCD
UBFX R1, R0, #4, #8
68
Instruction Set
Program flow control
There are several types of instructions for program flow control:
69
23
Instruction Set
Compare and branches
CBZ (Compare and Branch if Zero) and CBNZ (Compare and Branch if
NonZero). CBZ and CBNZ are very useful in loop structures such as
while loops.
For example:
i = 5;
while (i != 0 ){
func1(); // call a function
i--;
}
This can be compiled into:
MOV R0, #5 ; Set loop counter
loop1 CBZ R0, loop1exit ; if loop counter = 0 then exit the loop
BL func1 ; call a function
SUBS R0, #1 ; loop counter decrement
B loop1 ; next loop
loop1exit
70
Instruction Set
Conditional execution (IF-THEN instruction)
71
Instruction Set
Table branches
The TBB instruction has the syntax:
TBB [Rn, Rm]
where Rn stores the base address of the branch table and Rm is the
branch table index. The immediate value for the TBB offset
calculation is located in
memory[Rn + Rm]. If R15/PC is used as Rn
72
24
Instruction Set
TBH instruction is very similar, except that each entry in the branch
table is two bytes in size, so that the array indexing is different and
the branch offset range is larger. The syntax of TBH is slightly
different to reflect the indexing difference:
Instruction Set
In ARM assembler (armasm), including the Keil MD K-ARM , the TBB
branch table can be created in assembly in the following way
when the TBB instruction is executed, the current PC value is the address of
TBB instruction plus 4 (due to the pipe line structure ), which is the same as
the start of the branch table because the TBB instruction is 4 bytes in size.
(Both TBB and TBH are 32-bit instructions.) 74
Adresses physiques
static const uint8_t RED_LED = 75; //RGB LED - red component
static const uint8_t GREEN_LED = 76; //RGB LED - green component
static const uint8_t BLUE_LED = 77; //RGB LED - blue component
static const uint8_t YELLOW_LED = 78; //Mapped to the other RED LED
static const uint8_t PUSH1 = 73; //Switch 1
static const uint8_t A9 = 27;
static const uint8_t PUSH2 = 74; //Switch 2 static const uint8_t A10 = 6;
static const uint8_t A0 = 30; //analog-to-digital converter static const uint8_t A11 = 25;
static const uint8_t A1 = 29; //channels 0 to 23 static const uint8_t A12 = 5;
//static const uint8_t A2 = n/a; static const uint8_t A13 = 24;
static const uint8_t A14 = 23;
static const uint8_t A3 = 12;
static const uint8_t A15 = 2;
static const uint8_t A4 = 33; static const uint8_t A16 = 59;
static const uint8_t A5 = 13; static const uint8_t A17 = 42;
static const uint8_t A6 = 28; static const uint8_t A18 = 58;
static const uint8_t A7 = 8; static const uint8_t A19 = 57;
static const uint8_t A20 = 41;
static const uint8_t A8 = 27;
static const uint8_t A21 = 43;
static const uint8_t A22 = 69;
static const uint8_t A23 = 44
75
25