Вы находитесь на странице: 1из 116

ARM Cortex-M3

6633 KB ENG
" ARM Cortex-M3"
1. ...............................................................................................................4
1.1. Cortex ......................................................................................4
1.2. STM32 ...............................................................................6
1.2.1. ..............................................................8
1.2.2. ......................................................................................8
1.2.3. ...................................................................................9
1.2.4. ........................................................................9
1.2.5. Performance Line Access Line ..........................................10
2. Cortex .................................................................................11
2.1. ARM ..............................................................................12
2.2. Cortex Cortex .................................................................13
2.3. Cortex ...................................................................................................13
2.3.1. ...........................................................................................13
2.3.2. .............................................................14
2.3.2.1. XPSR ..............................................................................................15
2.3.3. .......................................................................16
2.3.4. Thumb-2 .............................................................18
2.3.5. ....................................................................................19
2.3.6. ..........................................21
2.3.7. "Bit Banding" ..........................................................................21
2.4. Cortex ........................................................................................24
2.4.1. .................................................................................................24
2.4.2. ....................................................................................24
2.4.3. ..........................................................................25
2.4.4. ...................................................................25
2.4.5. ................26
2.4.5.1.
...............................................................................................................27
2.4.5.2. ............................28
2.4.5.2.1. ...............................................28
2.4.5.2.2.
....................................................28
2.4.5.2.3.
...................................................................................................29
2.4.5.3. ........................................30
2.4.5.3.1. .................30
2.5. , .................................35
2.5.1. .........................................35
2.5.2. CoreSight .......................................................36
3. ...............................................................................................38
1

3.1. .............................................................................................38
3.2. ..................................................................................38
3.3. ..............................................................................................40
3.4. ..................................................................................................41
3.4.1. ...........................................42
3.4.2. ..............................................42
3.4.3. .....................................................................43
3.4.4.
....................................................................................43
3.4.5. ..............................................................................43
3.4.6. .............................................................................44
4. STM32 ..........................................44
4.1. ...............................................................................45
4.2. ..............................................47
4.2.1. .........................................48
4.2.1.1. .......................................................................50
4.2.2. Flash .........................................................................51
4.2.3. ..................................................................52
5. - ..................................................................................57
5.1. ..............................................................................60
5.1.1. - ......................................60
5.1.1.1. ....................................................62
5.1.1.2. ........................................................63
5.1.2. ......................................................................63
5.1.3. ...................................................................................................65
5.1.3.1. ............66
5.1.3.2. ...........................................68
5.1.3.3. ................................................69
5.1.3.4. ..................................70
5.1.3.4.1.

...............................................................................72
5.1.3.5.
/ ................................................73
5.1.3.6.
.....................................................................74
5.1.3.7. ...............................................75
5.1.3.8.
......................75
5.1.3.9.
....76
5.1.4. 76
5.1.4.1. ...............................................76
5.1.4.1.1. / ....................................................77
5.1.4.1.2. .......................................................................78
5.1.4.1.3. - .................79
5.1.4.1.4. .........................................................80
5.1.4.1.5. ...............................................................80
5.1.4.1.6. - ..........................81
2

5.1.4.1.7. .......................................................82
5.1.4.2. ...................................................................82
5.1.4.2.1. .....................................84
5.1.4.2.2. ................................................84
5.1.4.3. ..............................84
5.1.5.
.......................................................................................................85
5.1.6. ....87
5.2. .............................................................................87
5.2.1. SPI .................................................................................87
5.2.2. I2C ........................................................................................88
5.2.3. 5.2.3. .......................................................................90
5.3. AN USB ......................................................................................92
5.3.1. CAN- ...............................................................................92
5.3.2. USB .................................................................95
6. ...........................................................................96
6.1. RUN ..................................................................................................96
6.1.1. .................97
6.2. ...................................................................97
6.2.1. SLEEP ...................................................................................98
6.2.2. STOP .....................................................................................99
6.3. STANDBY .......................................................................................100
6.4. ......................101
6.5. ......................................101
7. .......................................102
7.1. .................................................................................102
7.2. .................................................................104
7.3. .....................................................104
7.4. ...............................................................................106
7.4.1. ........................................................106
7.4.2. ................................................108
7.5. ......................................................................................109
7.5.1. ....................................................109
7.5.2. .....................................................................110
7.5.3. .......................................................110
8. Flash ........................................................................................110
8.1. Flash .............................................110
8.2. ....................................................................111
8.3. ...............................................................................................111
8.3.1. ...........................................................................112
8.3.2. ...........................................................................112
8.3.3. ...............................................................112
9. .......................................113
9.1. .................................................................................114
9.2. ...........................................................114
9.3. ..........................................115

1.
-
ARM7 ARM9
. ,
240 ARM-.
ST Microelectronics, STM32 ,
, ARM CortexM3.
. ,

.

1.1. Cortex
ARM Cortex - ,
.
ARM, Cortex
,
. Cortex : A
, R -
M
. STM32 Cortex-M3,
,
, , .
, 8 16 . ARM7 ARM9
,
(SoC).
, ..

. Cortex-M3
, ,
( .. , SysTick,
). 4 CortexM3 , ,
- . ARM7, Cortex-M3
, , ,
. Cortex
(unaligned data),
ARM.
.
Cortex
1 bit banding.
,
,
.

STM32 Cortex-M3.
, 32- ,
, ,
.
5

Cortex-M3
().
Cortex- .
240 ,
.
.

12 .
,
. ,

6 .
,
,
.
Cortex-M3 .

.

.
, Cortex-M3 ,
32- , , :
(Thread) (Handler),
. ,

(). Cortex
24- ,
.
ARM7 ARM9 (32- ARM 16- Thumb),
Cortex ARM Thumb-2.
16- 32- ,
32- ARM ,
16- Thumb. Thumb-2 -
, C/C++. ,
Cortex- .

1.2. STM32
STM32 ST 4
ARM7 ARM9,
STM32
. STM32,
,
8- .
STM32 14 ,
: Performance Line,
72 , Access Line ( 36 ).

. Flash 128 ,
6

- 20 . STM32

Flash , .

STM32 . Performance Line


72 , Access Line
36

1.2.1.
, .. ,
, I2C, SPI, CAN, USB (),
.
, , . , 12
,
. , ,
, ,
, .
(advanced timer) .
6 -
, -
. SPI
CRC 8 16 ,
Flash SD MMC.
, STM32 7 ().

8/16 32- .
,
.

. , ,
.
STM32
.
2- 72
, , ,
, 36 .
Cortex ,
2 STANDBY.
RC- 8 .
.

.

1.2.2.
,
, ,
. STM32.
, , ..
8

,
.
(windowed watchdog).
. ,
.
. ,
.
,
RC 8 .

1.2.3.

. , Flash STM32
.
- Flash ,
.
Flash .
STM32
,
.
.
.

1.2.4.
, ARM-,

Thumb-2 Cortex. ,
, . ST
, USB, ANSI C ,
STR7 STR9.
.
Cortex
, (TCP/IP, ..).
Cortex-M3
CoreSight. CoreSight
Debug Access Port (DAP ), ,
JTAG 2-
. CoreSight,
, (data
watchpoint) (instrumentation trace).

.

.
9

1.2.5. Performance Line Access


Line
STM32 : Performance Line Access Line.
Performance Line
72 . , Access Line
32 . ,

. ,

.

10

2. Cortex
, Cortex
ARM. ,
ARM,
( Cortex
) "" .
11

, Cortex
. Cortex.
:

Cortex-A - ()
. ARM,
Thumb Thumb-2.
Cortex-R - .
ARM, Thumb Thumb-2.
Cortex-M - ,
.
Thumb-2.

, Cortex,
, 1 , 8 -
.
- . STM32
Cortex-M3.

2.1. ARM
ARM ,
. ( : ARMV6, ARMV7 ..).
Cortex M3 - ARMV7M.

Cortex-M3 ARMV7
12

Thumb-2
, Cortex-M3
Cortex-M3 ARMV7M.
ARM .

2.2. Cortex Cortex


Cortex
RISC , Cortex
Cortex, .
Cortex, Cortex.

2.3. Cortex
Cortex 32- RISC .
ARM7/9, , ,
,
- .
2.3.1.
Cortex .
ARM7 ARM9, .

Cortex-M3, ARM7/ARM9, .
Cortex-M3

, - , . , ,
, ,
, . ARM7 ARM9

. , Cortex
. ,
, ,

13

.
, ..
.
, - ,
Cortex -
.

2.3.2.
Cortex RISC-,
/.
,
, ,
.

Cortex-M3 /. ,
,
,
. 32- .
R0-R12 - ,
. R13-R15
Cortex. R13 .
, Cortex ,
.

(), "" .
Cortex :
. R14 .
. , Cortex
.
,
R14 . R15 - ;
,
.

14

Cortex-M3 , 16 32- .
ARM7/9 R13
. R14 - , R15 - . R13
, Cortex-M3 :

2.3.2.1. XPSR
, ,
. ,
. xPSR
, Cortex.

,
. :
,
xPSR ,
. ( )
. N, Z,
C, V ( (N) (Z) , (C)
(V))
. Q
15


()
. 32- ARM,
Thumb-2
.
, NOP
( ).
. Cortex
, 268
xPSR. : "If then" (IT),
Thumb.
Thumb-2
'if then'. ,
IT
. - ,
NOP.
:
If (r0 ==0)
CMP r0,#0 r0
ITTEE EQ ,
Then r0 = *r1 +2;
LDR r0,[r1] r0
ADDr0,#2 2

, Thumb-2 ,
(, /)
. Cortex
, .

,
. ,
,
/ . Thumb
ARM.
, ARM Thumb.
Cortex-M3 . ,

.

2.3.3.
, Cortex ,

, . Cortex
: Thread ( )
Handler ( ). Thread
, Handler
. , Cortex
.
16

, ,
(,
MRS MSR, xPSR
).
Cortex.
. (R13)
Thread Handler. , Handler
( R13).

Cortex-M3 ('flat'),
.
Handler Thread (
)
Cortex

Handler
-

( ( - )
)

(Thread) Thread
-

/

Cortex 'flat'.
, Thread Handler, ,
17

.. - .
Thread Handler .
, ,
- . ,
,
: Handler
(
)
Thread
.
, , ,
.

2.3.4. Thumb-2
ARM7 ARM9 : 32- ARM 16 Thumb. ,

: 32- ,
, 16-, . Cortex
Thumb-2, 16- 32-
. thumb-2 26%
32- ARM 25%
16- Thumb. Thumb-2
,
, , 27 .

Cortex
1.2 DMIPS/, 1.2

16 16

32 16

32 32
18


32

32

32


32 32
64
37*

Thumb-2
, .. ; if/then
;
. RISC-, Cortex
, . Cortex-M3
ANSI ANSI ,
,
.

2.3.5.
Cortex-M3 ,
, .
, 4 .
1
.
I-Code. ,
D-code. ,
,
, .
,
, Flash ,
. 0.5 - .

. 1
. bit banding. ,
, , ,
. 2
. 0.5
Cortex Cortex.
Cortex Cortex. ,
STM32 Cortex- .
Cortex-M3 4
, ,
, -, ,
Cortex. Cortex

19

20

2.3.6.

ARM7 ARM9
, . ,

, 8- 16-
. ARM ,

.

. (
25%.)

Cortex-M3 ,

Cortex , ,
. ,

. , Cortex bit banding
,
.

2.3.7. "Bit Banding"


ARM7 ARM9
AND OR.
- - .


.

21

bit banding
Cortex-M3
,

, .
, , bit banding,
, -
. Cortex
: ( 1
) , 32
.
. ,

.

Bit Banding ( 1
), STM32
, , ,
,
Cortex .
, ,

22

. :
= +
,
=
0x20 + 4
, .
.
- ()
-. - 0x40010C0C.
, 8 .
:
= 0x40010C0C
= 0x40000000
= 0x42000000
=
0x40010C0C - 0x40000000 = 10C0C
= (0x100 x 0x20) +(8x4) =
0x2181A0
= 0x42000000 + 0x2181A0 = 0x422181A0

-:
#define PortBbit8 (*((volatile unsigned long *) 0x422181A0 ))

, :
PB8 = 1; //

:
MOVS r0,#0x01
LDR r1,[pc,#104]
STR r0,[r1,#0x00]

:
PB8 = 0; //

:
MOVS r0,#0x00
LDR r1,[pc,#88]
STR r0,[r1,#0x00]

, 16 . STM32, 72 ,
80 . ,
"" ""
:
GPIOB->ODR |= 0x00000100; //
LDR r0,[pc,#68]

23

ADDS r0,r0,#0x08
LDR r0,[r0,#0x00]
ORR r0,r0,#0x100
LDR r1,[pc,#64]
STR r0,[r1,#0xC0C]
GPIOB->ODR &=!0x00000100; //
LDR r0,[pc,#40]
ADDS r0,r0,#0x08
LDR r0,[r0,#0x00]
MOVS r0,#0x00
LDR r1,[pc,#40]
STR r0,[r1,#0xC0C]

, /
16- 32- , 14
180 . , ,
/ ,
, bit banding
, , .

2.4. Cortex
2.4.1.
Cortex-M3 ,
. Dcode
Icode, .
0x00000000 - 0x1FFFFFFF.
,
0x20000000-0xDFFFFFFF
0xE0100000-0xFFFFFFFF. Cortex
,
(Private Peripheral Bus, PPB).

2.4.2.

, .
Cortex
, , ,
. (, Cortex )
, ,
, ,
. , Cortex,
.
.

24

2.4.3.
Cortex 24-
. SysTick
Cortex. SysTick

.
SysTick,
Cortex-M3, .
CLKSOURCE, SysTick
. , , 1/8
.

SysTick - 24- - ,
Cortex-M3.

SysTick .

.
ENABLE, , TICKINT,
.
Cortex SysTick
STM32.

2.4.4.
Cortex
ARM
. ARM7 ARM9 :
.

. ,
,
. ARM7 ARM9
. -, , .. ,
.
, ,
25

. -,
ARM7 ARM9

. , ,
Cortex,
,
.

2.4.5.

()
Cortex. , Cortex-
,
. ,
, ,
.
, .
: ,
Thumb-2, , ,
/, .
,
. ,
, , STM32 16
.
-
, ANSI, .

STM32 ,
240
, Cortex,
26

,
, .
240
, . Cortex
15 ,
Cortex.
STM32 43.

2.4.5.1.

, Cortex
. Cortex ,
. ,
.
.
,
12 .

12 .
,

,
. , ,
Cortex CPU. , R0 - R3.
, ,

. - R12.
. ,
, ,
27

R12.
:
, ,
, ,
12 .

2.4.5.2.

,
,
.
,

.

2.4.5.2.1.
,
. ,
, 12

. ,

.

2.4.5.2.2.

, ,
, Cortex
,
.


,

28

, 12
. ,
, Cortex
. ,
. ,
6
.
. , 12
.
,

, 6
. ,
7-18 .

,
, 7-18

2.4.5.2.3.

,

. ,

. 6
,
.

29

,
,
,

6 .

2.4.5.3.

.
.

. , , .

2.4.5.3.1.
Cortex .
, 0x00000004,
..
.
,
,

1
Reset
2

NMI

Hard Fault

MemManageFault

BusFault

UsageFault

7-10
11

Reserved
SVCall

30

-3 ()

-2


,
-1

AHB

,
2

N.A.
N.A.
3

,
12
DebugMonitor
4
,

13
Reserved
N.A.
N.A.

14
PendSV
5

15
SYSTICK
6


16
0
7
0
.......
................................ .................... ................................

256
240
247

240
4
. 15 -
, Cortex.
, , ,
SysTick.
Thumb-2 ,
. 16 ,
.
.

:

__Vectors

AREA RESET, DATA, READONLY


EXPORT __Vectors
DCD __initial_sp
;
DCD Reset_Handler
;
DCD NMI_Handler
;
DCD HardFault_Handler
;
DCD MemManage_Handler
;
DCD BusFault_Handler
;
DCD UsageFault_Handler
;
DCD 0
;
DCD 0
;
DCD 0
;
DCD 0
;
DCD SVC_Handler
;
DCD DebugMon_Handler
;
DCD 0
;
DCD PendSV_Handler
;
DCD SysTick_Handler
;




HardFault

BusFault
UsageFault

PendSV
SysTick

, SysTick,
:
void SysTick_Handler (void)
{
}

,
31

,
SysTick. , :
, .
.

Cortex-M3

Cortex
,
- IRQ. SysTick
Cortex , ,
.
. ,
, tSysTick, ,
.
SysTick
:
SysTickCurrent = 0x9000;
SysTick
SysTickReload = 0x9000;
SysTickControl = 0x07;

//
//
//

Cortex
. Reset, NMI hard fault
. ,
.
,
. STM32 16 ,
, 4 . ,
.
IRQ.
.
32- .

32

. ,
.

, , .
STM32 16
16 . 8 .
. STM32 , ..
16 . ,
.
16 , 0 -
, 15 - .
. ,
PRIGROUP

.

33

PRIGROUP .

PRIGROUP (3
)
(.)
- -
- -

011
4.0

4
16
0
0
100
3.1

3
8
1
2
101
2.2

2
4
2
4
110
1.3

1
2
3
8
111
0.4

0
0
4
16
PRIGROUP 4-
. , PRIGROUP 3
4 . ,

. , .. ,
, . ,

.
Cortex.
,
:
DCD
ADC_IRQHandler ;
void ADC_Handler void
{
}


:
ADC1->CR2
ADC1->SQR1
ADC1->SQR2
ADC1->SQR3
ADC1->CR2

34

= ADC_CR2;
= sequence1;
= sequence2;
= sequence3;
|= ADC_CR2;

//
//
//
//

ADC1->CR1
GPIOB->CRH
NVIC->Enable[0]
NVIC->Enable[1]

=
=
=
=

ADC_CR1;
0x33333333;
0x00040000;
0x00000000;

// ,
//
//

2.5. ,

STM32 .
, Cortex,
. Cortex SLEEP,
Cortex
. ,
Cortex
STM32 .

2.5.1.

Cortex SLEEP WFI


( ) WFE ( ).
WFI, Cortex
.
.

. , SLEEPON EXIT
, Cortex
SLEEP.
,

, , -
, SLEEP.
WFE Cortex ,
SLEEP.
. -
,
. , Cortex
,
. WFI WFE
, Thumb-2
, ,
-:
__WFI
__WFE

SLEEPNOW SLEEPONEXIT, Cortex


35

SLEEPDEEP
.

SLEEP Cortex.
STM32 ,
Cortex DeepSleep

, , STM32
.

2.5.2. CoreSight
ARM . ARM7
ARM9, , JTAG,
,
Flash . JTAG
( ,
.) .
,
(ETM), ARM7 ARM9
. ,
, . ARM ,
JTAG ,

. , .
- ARM7 ARM9
, (
). ,
- ,
ETM. ,
.
Cortex ,
CoreSight.

36

CoreSight JTAG Serial Wire.



.
, STM32 .
JTAG
CoreSight DAP-,
JTAG .
5 JTAG 2- Serial Wire.
JTAG , CoreSight
Data Watch ETM.
Flash (FLASH patch).
STM32 CoreSight,
ETM. ,
STM32 CoreSight,
JTAG , -
. CoreSight STM32
8 ,
Cortex ,
. CoreSight ,
Cortex .
37

. ,
STM32
CoreSight . ,

Cortex. CoreSight STM32

ARM7 ARM9 , ,
.

3.
STM32
. STM32 RC-
, , .
,
.

3.1.
Access line
Performance line . ,

. STM32 LQFP
48 144.

3.2.
STM32
2.03.6. Cortex 1.8
. STM32
.
,

(deep power down).
, VBAT VDD.

38

STM32 2.03.6. ,
,
, ( 144-
)
.
, VDD 2.4
3.6. 100-
() , VREF+ VREF-. VREF-
VDDA, VREF+ 2.4 VDDA.
.
,
.

39

3.3.
STM32 ,
, VDD 2.0 ( 40 ).

(POR) (PDR)

.

40

3.3.1.

, STM32,
nRST
. nRST JTAG.
.
STM32 ,
(
, ).

3.4.
STM32 RC-,
. ,
72 . ,
, ,
,
.

41

3.4.1.

STM32.
(HSE-).
/ .
,
, , , 50%-,
25.



/ ,
416 .
72 ,
, .
, HSE-
.

3.4.2.
STM32 ,
(LSE-).
. HSE-, LSE
- ,
, 50%.
LSE- 32,768 ,
.
,
, LSE.

42

3.4.3.
- ,
(MCO). , MCO
.
.

3.4.4.


. BOOT0 BOOT1.
,
. Flash ,
.
, STM32
,
Flash .

3.4.5.
BOOT0 GND.
,
.

,
2 . Flash
, 2 .

.
1, ,
, 43

RS232.

3.4.6.
.
STM32. Cortex CoreSight
: 5- JTAG 2-
Cortex.
- . Cortex
,
. ,
-,
. 5-
JTAG 20- IDC JTAG .
A_13
_14 .

4.
STM32
STM32 Cortex, Flash
. Cortex
AHB.
AHB, .
APB.
AHB . AHB
, Cortex. , AHB
, ,
. ,
APB2 72 ,
APB1 36 .
, Cortex, .
,
, APB1 APB2.
, ,
2/3 1/3
Cortex.

44


, Cortex

4.1
, STM32 ,
4 .
STM32 Cortex,
.
0x00000000. 0x20000000.
.
, 0x40000000,
. , Cortex ,
0xE0000000.

45

STM32 Cortex. 2
Flash , ,

Flash . - Flash
- 0x0000000. ,
. Flash
4 ,
. , 0x1FFFF800,
.
,
STM32.
USART1 Flash
. STM32 ,
BOOT0 BOOT1 ,
.
, 0x00000000. ,
STM32, Flash ,
46

.
Flash
, ST.
DLL-,

.
0x00000000 Flash
.
,

. ,
Flash .

4.2.

, STM32 RC. Cortex


, 8
. - 32,768
.
.

STM32
, .


Cortex
.

. , STM32 72
.
47

8
.
.
, Cortex
72 , .
,
( RCC).

4.2.1.

HSI-.
.
STM32
HSE- .

48

STM32 .

RCC->CR |= 0x10000; // HSE
// HSE-
while(!(RCC->CR &0x00020000))
{
;
}

RCC_Control.
. ,
, .

,
RCC_PLL_configuration. 8 ,
72
9. ,
.
,
Cortex.

49

HSE- .


// HSE- 9
RCC->CFGR = 0x001D0000; //
RCC->CR |= 0x01000000;
while(!(RCC->CR & 0x02000000))
{
;
}
//
RCC->CR |= 0x00000001;
//
RCC->CFGR |= 0x005D0402;

4.2.1.1.

Cortex 72 .
,
AHB APB.
50


.

// AHB,APB1 APB2
RCC- AHBENR
= 0x00000014;
RCC->APB2ENR
= 0x00005E7D;
RCC->APB1ENR
= 0x1AE64807;
// APB1 APB2
RCC->APB2RSTR= 0x00000000
RCC->APB1RSTR= 0x00000000;

4.2.2. Flash
STM32, ,
Cortex-M3 Flash
I-Bus. , , ,

(72 ). , Cortex
, Flash
1.3 . STM32
8, , Flash
.
Flash
(35 ), Cortex
. 72
, Flash
, 64- .
64- Flash 16- 32 Cortex.
Thumb-2
Cortex. ,
- Flash .

, Flash .
51

Flash . ,
,
8 Flash
. :
0< SYSCLK <24 0
24< SYSCLK <48 1
48<SYSCLK <72 2

Flash Cortex.
, , ,

.

4.2.3.
,
Cortex,
. STM32
,
, , . - .
,

. ,
.
FIFO,
.
STM32
,
.

- .
5 , - 1
, , :
, ,
. , , 1 .
( , ) 3
. Cortex
, , ..
. ,
52

.

.
.
,
.

.
.

,
.
,
,
. ,
, .
,
.

.
- , 60% ,
. ,
, Cortex
I-code
-
, ,
5 . - 53

, ,
Cortex. ,
40%
. - .
AHB
, APB 2
2 AHB.

. , SPI
SPI,
. ,
SPI . = SPI (APB) + . (AHB) +
(AHB) = (2 APB + 2 AHB) + 2 AHB + 1 AHB =
2 APB + 5 AHB
, , ..
Cortex I-Bus.

, , ,
.
.
AHB .
RCC->AHBENR |= 0x00000001; //

.
. (
). "
", -
.

54


: ,

: "
", "", "" "".
. , 32-
(3 ) , 8-
( 35 64,
8- .)
. , ,

. , -
- , ,
. - 14
. , ,
,
. , -,
.
- :
DMA_Channel1->CCR = 0x00007AC0;
DMA_Channel1->CPAR = (unsigned int)src_arry;
DMA_Channel1->CMAR = (unsigned int)arry_dest;
DMA_Channel1->CNDTR = 0x000A;
TIM2->CR1 = 0x00000001;
DMA_Channel1->CCR |= 0x00000001;
while(!(DMA->ISR & 0x0000001))
{;}
TIM2->CR1 = 0;
TIM2->CNT = 0;
TIM2->CR1 = 1;
for(index = 0;index <0xA;index++)
{
arry_dest[index] = arry_src[index];
}
TIM2->CR1 = 0; //
}

55

// -
//
//
//
// -
//
//
//
//
// ,

-.

10
: ,
Cortex. ,
.
220 , - 536.

, , .
, -.
, -

, -
, ,

. ,
. ,
. ,
. ,

10- .
,
. ,
-,

.

.

56

STM32 - .

.
,
,
, .
,
, .
,
, , ,
. ,
, , ,
.
. , ,
.
, SPI
.

5. -
(),
STM32. :
.
STM32
. ,

. , ,
.

57

5.1.
STM32 -
() , , -
, ,
( )
.

5.1.1. -
STM32 80 -.
- 5 16 - .

- .
16
AE 5.
-
, , I2C. , 16

-.


. , ,
.

58

32- .
64- . 64 4-
, -.
, 4- 2- 2-
. ,
: ,
:

,
;
, , ,
.
: 2, 10 50 .

CNF1 CNF0 MOD1 MOD0



0
0
( ) 0
1
00

1
0

1
0

0
0
00:

0
1
01: 10
.
1
0
10: 2
.
11: 50
1
1

,
.
. .

. ,
59

16 1, 0, 1.
. ,
.
0, 1 .
- .

Cortex "bit banding"
,
. / - 32- . 16
. 1
-. , 1
16 . - . 16. 1
-. , "bit banding"

- STM32
-.

5.1.
STM32 -
() , , -
, ,
( )
.

5.1.1. -
STM32 80 -.
- 5 16 - .

- .
16
AE 5.
-
, , I2C. , 16

-.
60


. , ,
.

32- .
64- . 64 4-
, -.
, 4- 2- 2-
. ,
: ,
:

61

,
;
, , ,
.
: 2, 10 50 .


CNF1 CNF0 MOD1 MOD0

0
0
( ) 0
1
00

1
0

1
0

0
0
00:

0
1
01: 10
.
1
0
10: 2
.
11: 50
1
1

,
.
. .

. ,
16 1, 0, 1.
. ,
.
0, 1 .
- .

Cortex "bit banding"
,
. / - 32- . 16
. 1
-. , 1
16 . - . 16. 1
-. , "bit banding"

- STM32
-.

5.1.1.
-
.
, -
.

62


, -

STM32
. (,CAN, , I2C SPI) ,
. ,
.
JTAG-. , JTAG
. JTAG
,
-

5.1.2.
Cortex ,
,
. ,
STM32.
SEV Thumb-2.
,
.
-. -,
.

5.1.2.
19 ,
. 16
,
. ,
USB
.
(EXTI) 0-4, ,
USB. EXTI , 5-9
10-15, .

STM32. , ,
, STOP,
. EXTI ,
63

Wait , Wait
.

STM32 16 ,
-
16 EXTI -
. .
,
EXTI. EXTI
, , EXTI0 0 A, B, C, D E.
.
EXTI ,
.
//
AFIO->EXTICR[0]
= 0x00000000;
//
EXTI->IMR
= 0x00000001;
//
EXTI->EMR
= 0x00000000;
//
EXTI->FTSR
= 0x00000001;
//
EXTI->RTSR
= 0x00000000;
//
NVIC->Enable[0]
= 0x00000040;
NVIC->Enable[1]
= 0x00000000;

64

STM32 16 ,
-. ,
/
EXTI,
.
EXTI
.

5.1.3.
, STM32
- .
,
2.43.6. ()
, .
12-
1. 18 , 16
.
.

STM32 12-
1

65

5.1.3.1.


. 8
1.5 239.5 .


:
.
, .
( 16 ).
, ,
.

1- (EXTI 1).
, .
, ,

.


() ,

, ,
66


. 12- 16 .

12- 16-

1 ,

.

.
,
, ,
, , .

, .

1

.
,
.
,
, ,
.
,

67

. , ,

.



16- ,
.
- ,
. ,

5.1.3.2.
,
,

( , ).

, .
,
.

68

5.1.3.3.

.

:
,
,
.
.

.

ADC1->CR2
ADC1->SQR1
ADC1->SQR2
ADC1->SQR3
ADC1->CR2
ADC1->CR1

69

=
=
=
=
|=
=

0x005E7003;
0x0000;
0x0000;
0x0001;
0x005E7003;
0x000100;

//
// 1
// 0
//
// ,
//

NVIC->Enable[0] = 0x00040000; //
NVIC->Enable[1] = 0x00000000;


-.
void ADC_IRQHandler (void)
{
GPIOB->ODR = ADC1->DR<<5; //
}

,
.
DMA_Channel1->CCR

= 0x00003A28;

// ,
//

// -
DMA_Channel1->CPAR
= (unsigned int) 0x4001244C;
//
DMA_Channel1->CMAR
= (unsigned int) 0x40010C0C;
DMA_Channel1->CNDTR = 0x1;
DMA_Channel1->CCR |= 0x00000001;

//
//

.
ADC1->CR2 |= 0x0100;

5.1.3.4.
STM32, ,
.
, ..
,

. , STM32
, .

70


,
2 1,
.

71

5.1.3.4.1.



.

, , .

72

5.1.3.5.

/

,
, .

73

5.1.3.6.


,
,
1 .


2.
14 .

.

74

5.1.3.7.

1
1, -
2.

5.1.3.8.


. ,
, .

75

5.1.3.9.



, - .

5.1.4.

STM32 . 1 - ,
.
. ,

. ,
.

5.1.4.1.
16- ,
16- .
. ,
( , ).

. : ,
;
,
/.
76

STM32 16- , 16-


4- /.
,

,
/. ,
, .
.

5.1.4.1.1. /
/ .
, .
, ,
-,
. ,
, -,
.

77

5.1.4.1.2.
4 ,
. ,
16- /.
,
. ,
-.

.
78

5.1.4.1.3.
-

-, ..
.

-
-
M3->CR1
TIM3->PSC
TIM3->ARR
TIM3->CCMR1
TIM3->CCER
TIM3->CCMR1
TIM3->CCER
TIM3->SMCR

=
=
=
=
|=
|=
|=
=

0x00000000;
0x000000FF;
0x00000FFF;
0x00000001;
0x00000000;
0x00000200;
0x00000020;
0x00000054;

TIM3->CCER
TIM3->CR1

|= 0x00000011;
= 0x00000001;

//
// . .
// . .
// IC1 TI1
//IC1
// IC2 TI1
//IC2
// TI1FP1 ,
//
//
//

-
.
( -) .
79

-
, .


-.

5.1.4.1.4.

,
.


,

.
. .
.

5.1.4.1.5.
STM32 4 .
,
16- ,
/.
/ , ,
-.

80

,
CAP/COM

5.1.4.1.6. -

,
-.
.
/ . ,
-. ,
, 16
-.

,
-
-
. ,
.
/
-. ,
,
, - .
/ ,
.

81

TIM2->CR1
TIM2->PSC
TIM2->ARR
TIM2->CCMR1
TIM2->CCR1
TIM2->CCER
TIM2->DIER
TIM2->EGR
TIM2->CR1

=
=
=
=
=
=
=
=
=

0x00000000;
0x000000FF;
0x00000FFF;
0x00000068;
0x000000FF;
0x00000101;
0x00000000;
0x00000001;
0x00000001;

//
// . .
// . .
//
//
// 1
//
//
//

5.1.4.1.7.
,
. , ,

. , ,
, -
( ) .

.

5.1.4.2.
1.
, .
.
, 6- -.
,

. ,
82

,
. .


,
.

83

5.1.4.2.1.
-

.

,
. ,
-
STM32
.

5.1.4.2.2.
, .. ,
,
.
1 " ". ,
,
.
, . ,
, ,
.

5.1.4.3.

,
.
,
-
.

84

,
, /
,
. , 1 2
(TI1FP1 TI2FP2) .
.
.



, - .
,
. ,
. ,
.

5.1.5.

STM32 : ,
. 16-
, .
- 10 ,
, STM32
.

, ,
85

STM32
.
STM32 32-
, 32.768 .
,
,
.

(128).
.
: ,
.
,
, .


.

,
VBAT, ,
, 17- . ,
STM32 .
. , ,
Cortex
STM32.
86

,
,
, , .

5.1.6.

16- ,
.

.
. ( )
.
,
. ,

.

5.2.
16- ,
.

.
. ( )
.
,
. ,

.

5.2.1. SPI
STM32
SPI,
18. , SPI
APB2, 72.
APB1,
36 . SPI

(8 16 ,
). , SPI
, ,
SPI.

87

SPI
18.

SPI
:
.
.
SPI, SPI STM32
CRC. CRC ,
- . CRC8 CRC16.

SPI MMC/SD.

SPI CRC,
Flash MMC SD

5.2.2. I2C
STM32
- I2C. I2C
88

,
. I2C
: 100
400 .
I2C 7- 10- .

. I2C
:
. , ,

. ,

.

I2C ,
SMBus PMBus.
, I2C
.
,
I2C. I2C STM32
( PEC). , PEC
CRC- .

.
PEC
.
.
89

PEC
.
I2C STM32
: SMBus PMBus. SMBus Intel 1995
. SMBus
, .. PEC
BIOS
. SMBus, I2C, PEC,
SMBus.
SMN, host-
SMBALERT. PMBus SMBus
. PMBus
,
.

5.2.3.
,
,
.

. STM32 3 ,
,
.
4.5 /.
, .. (8 9 ),
-, .
APB2, 72 .
36- APB1.

,
LIN, IrDA -

. ,
90


.
,
. ,
.
, Tx.
, ,
CTS RTS.



LIN.

. /
(SIR).
IrDA 115200 /
NRZ-
1.42.2.
-,
ISO 7618-3.

91

- IrDA
,
.
, SPI- , 3-
. , SPI
.
, SPI .


SPI

5.3. AN USB
STM32 - CAN USB.
, , ,

CAN USB. , USB CAN,

, , STM32
512 , CAN USB.
. ,
. ,
CAN USB .
, .

5.3.1. CAN-
STM32 CAN- CAN, CAB 2.0A
2.0B 1 /. CAN
CAN-
TTCAN. TTCAN

CAN-
.
CAN- .
92

CAN CAN 2.0B TTCAN


CAN- - bxCAN, bx
. CAN
, CAN
. bxCAN
CAN.
.
FIFO
.
.

CAN

TTCAN
CAN- -
. CAN ,
. CAN-
.
CAN- CAN. , CAN-
, . CAN-
STM32 14 ,
93

CAN-,
.

14 ,

32-
.
.
, ,
.
. 3 11- 29-
, RTR IDE 16- .

, 32-
, - .
, '' ''. ,
.
,
FIFO .

.
CAN- :
94


. , STM32
SLEEP. bxCAN ,
. bxCAN
CAN.
.
, . SILENT. CAN- ,
.
CAN- .
- LOOPBACK. ,
.
.
.
.

5.3.2. USB
USB, STM32,
(12 /) USB, , .
, ..
. USB-
,
. USB,
USB
. ST
USB .
USB USB-, .. HID, MASS STORAGE,
AUDIO LEGACY COMMUNICATIONS PORT.

.

USB USB- 2.0


USB 8 ,
, , .

512 , CAN-.
95

USB,
.

,
.
, .
, ,
- . ,
, , .
, ,
.
- , , .
512- .
,
.
,
.

6.
STM32, ,
RUN
. SLEEP, STOP
STANDBY
. STM32 :
. Cortex
,
.
Cortex ,
SLEEPDEEP.
WFI
WFE.
, .

.

6.1. RUN
RUN STM32 , ,
.

.
, .
, ,
, ,

.
96

, Cortex STM32
72 . ,
30 .
.
.

(RCC).

. ,
STM32
HSE-.
HSE- HSI-. , HSE-,
HSI- - .
LSI-,
.

6.1.1.

HSE- 8,
Flash
. , ,
, RUN.

34 , 8 (9.6 DMIPS) 1
APB1 APB2

DIV4 DIV2
DIV8
DIV8
DIV4
DIV4
DIV4
DIV4

DIV8
DIV8
DIV2
DIV2
DIV2
DIV2

WFI

25
[]

72

HSE

33.15

72
72
8
8
8
8

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

HSE
HSE
HSE
HSE
HSE
HSI

27.75
23.65
8.65
8.48
1.68
0.9

6.2.
RUN,
8.5 . , ,
STM32.

97

6.2.1. SLEEP
- SLEEP. ,
Cortex WFE WFI,
. SLEEP,
STM32 . SLEEP ,
. STM32
HSE- 72 ,
SLEEP 14.4. ,
STM32 ,
, ,
Cortex, HSI-
( 1 ),
0.5 .
SLEEP 0.14


.
APB
.

72
14.4
5.5
48
9.9
3.9
36
7.6
3.1
24
5.3
2.3
3.8
1.8
HSE, 16

8
2.1
1.2
AHB
4
1.6
1.1
2
1.3
1
1
1.11
0.98
500
1.04
0.96
125
0.98
0.95

64
12.3
4.4
48
9.3
3.3
36
7
2.5
24
4.8
1.8
3.2
1.2
RC 16
(HSI), 8
1.6
0.6
AHB
4
1
0.5
2
0.72
0.47
1
0.56
0.44
500
0.49
0.42
125
0.43
0.41
, ,
SLEEP , .
,

98

fHCLK

STM32
.
, Cortex,
HSI RC-, .

6.2.2. STOP
STOP.
SLEEPDEEP
Cortex Power Down Deep Sleep (PDDS)
STM32.

STOP, WFI
WFE Cortex HSI- HSE-.
-, , ,
STM32 . SLEEP, STOP
. STOP
, .
, STOP
-. ,
, , ,
.
(LSI LSE),
STM32
STOP.
STM32 STOP
, RUN, 24 .

.
LPDS STM32.
STOP , 14 .
99

, 1.4
.
VDD/VBA VDD/VBA
..
T=2.4 T=3.3

Run,
RC ,
(
)
,
RC ,
(
)

NA

24

NA

14

.
.

STOP
3.52
( RUN)
STOP
( RUN +
5.42
WFI)

tWUSTOP

STOP
HSI RC
(
5.32
+ WFE)
STOP
(
7.21
+ WFI)
STOP 5.5
, , 7.3 ,
.

6.3. STANDBY
STM32 STANDBY,
SLEEPDEEP Cortex
Power Down Deep Sleep STM32. ,
WFI WFE STM32
. STANDBY STM32
. HSE-
HSI-. STM32 2 .
STANDBY 2 ,
50


100

VDD/VBAT VDD/VBAT
..
=2.4
=3.3
NA
2

1.08

1.4



HSI
50

STANDBY
RC-
STANDBY
( ) STOP.
, STM32
. STANDBY
0 .
, WKUP EWUP
. STANDBY
, :
50 .
STANDBY , Cortex STM32
. STANDBY .
tWUSTDBY

6.4.

.
.
3.3 1.4 .

6.5.

,
, . ,

. ,
. , STM32
HSI-
CoreSight
. STM32
DBG_MCU.

101

7.

STM32 ,

.
, STM32
, , VDD
- . ,
,
.
, .
HSE. ,
HSI-.
.
- ,
. - ,
, .
, Flash
30 85,
.

, ( ,
, ,
). ,
STM32
,
,
. ,
.

7.1.
STM32, , .
STM32 ,
, /
.
RCC, ..
,
.
. 1 .

102

STM32 .
RCC

103

7.2.
STM32
. ( PVD). PVD

2.2 2.9 0.1.
.

,
,

PVD 16- .
,
, PVD
.

7.3.
STM32
Cortex STM32
, HSE-.
CSS,
. ,
8
.

104

, CSS
RC-
CSS
RCC.


CSS RCC
CSS ,
1,
Cortex.
- .
, Cortex -,
.
105

7.4.
STM32 .
STM32.

(LSI).
STM32 .
/
.

STM32 ,

7.4.1.

106


. ,

0x40 0x3F, .. T6.

,
.
,
, .
,
107

,

.
6- ,
PCLK1 12- (
PCLK1 4096). 2 ,
1, 2, 4
8. 6 7 .
,
:
Twwdg = Tpclk1 x 4096 x 2^(WDGTB) x ( + 1)
Pclk1 36 ,
910 , - 58.25 .
,
.
, .

7.4.2.
,
STM32, ,
STM32.
VDD, STOP
STANDBY.

12-
, .

8- . LSI- 32.768
, 3060 .

, , LSI-,
4256, 2 ,
108

.
0.1, - 26 .

.

- .
. ,
Stop Standby

Flash
, .
0xCCCC
. ,
0xFFF.
0xAAAA.
.
,
. ,
. ,
, .
,
. , ,
. STM32 MCUDBG

Cortex-M3,
CoreSight. ,

.

7.5.
,
STM32. ,
, :

7.5.1.
-
. ,
109

.
.
.

7.5.2.
,

.

7.5.3.

.
,
- .

8. Flash
STM32 Flash . Flash , .
64-.
.
Flash 4 . .
10 30-
85. Flash
25C. ,
STM32 Flash . ,
:
. 2
Flash
,
1.
.
STM32 .

8.1. Flash

Flash
, JTAG
,
Flash (FPEC-).
FPEC-
.

110

FPEC- Flash
. -

8.2.
, FPEC- .
,
. 0x45670123, 0xCDEF89AB
FPEC-. ,
FPEC- .
FPEC-,
Flash . Flash
4 . .

. BSY
, Flash
0xFFFF. .
Flash
, .
-, BSY , .
Flash
.
, .
Flash ,
FPEC- .

8.3.

.
Flash . ,
,
111

. .
- Flash ,
. ,
FPEC- .
,
.
Flash .
OPTER ,
STRT.
BSY.
, OPTPG
Flash .
.
, - .
FPEC-
.

8.3.1.
Flash
.
Flash .
.

8.3.2.
, Flash
.
, ,
.
,
Flash .
.
Flash .
.
Flash ,
0xFF.
, 0xFA ,
.

8.3.3.
.
STM32 STANDBY STOP.
.
- ,
STM32. ,
RC-.

. : ,
112

, ,
.

9.

ARM7 ARM9
.
ARM
, .. GCC, Greenhills, Keil, IAR Tasking.
Cortex
Thumb-2. ,
ARM-,
STM32
.
.
, ARM-,

. ,
,
. "GCC" "GNU".
, ,
. GCC,
,
. , GCC
,
, ,
. ,
, ,
.
ARM RealView, ARM .
RealView ARM
RealView.
. ,
2006 RealView
Keil (MDK-ARM). MDK-ARM
, ARM. MDK (
4 ) .
GCC
, .

. , ARM,

.
. , , ,
113

GCC
. , , .. ,
.

9.1.

.
. - ST
.
STM32 Performance Stick
Hitex. 50 , Performance Stick
STM32.
USB-
HiTOP
GCC Tasking. STM32,
Performance Stick STR750.

STM32 .
.
STM32
,
, , .

Performance Stick Hitex -


STM32.
Performance Stick HiTOP GCC ,
, -
. ,

JTAG- Tantino Hitex

9.2.
, ST
114

STM32,
-.
. ,
,
.
STM32 USB-.
USB-, ST
USB-. ,
- ST.
USB- USB-
HID, Mass Storage, Audio Device Field Upgrade.

,


STM32,
(MAC- Ethernet, TFT- .).

. ,
, , TCP/IP,
, .. ,
. ,

.

9.3.

8- 16- , ,
, . , Cortex-M3


.
115

, , STM32
.
,
,
.
. ,
.
ARM Cortex,
.
,
"FreeRTOS". www.freertos.org.
FreeRTOS "SafeRTOS".
IEC 61508 .

116