|
1. Cortex-M3 Processor ¼Ò°³
1.1 ARM Cortex-M3 ÇÁ·Î¼¼¼¶õ ¹«¾ùÀΰ¡ ?
Cortex-M3 Processor´Â
ARMv7-M profile ÇÁ·Î¼¼¼·Î low gate count, low interrupt latency, and low-cost ÀÇ Æ¯Â¡À» °®´Â ±âÁ¸ÀÇ 8Bit Microcontroller(AVR, PIC, 8051 µî) ½ÃÀå¿¡ ´ëÀÀÇÏ´Â Processor ÀÔ´Ï´Ù. ¶ÇÇÑ Cortex ´Â °¢°¢ ´Ù¸¥ Ư¡À» °®´Â 3°¡ÁöÀÇ Profile ÀÌ ÀÖ½À´Ï´Ù.
(1) A profile (ARMv7-A) : Application Profile
- For sophisticated, high-end applications running open and complex operating systems
- ARM, Thumb, Thumb-2 instruction sets
- S5PC100, S5PV210, OMAP3530 ..
(2)
R profile (ARMv7-R) :
Real-time Profile
- For real-time system
- ARM, Thumb, Thumb-2 instruction sets
(3) M profile (ARMv7-M) :
Microcontroller Profile
- For cost-sensitive and microcontroller applications
- Thumb-2 instruction set only
- Banked Stack Pointer (SP) only.
- Hardware divide instructions, SDIV and UDIV (Thumb-2 32-bit
instructions).
- Handler and Thread modes.
- Thumb and Debug states.
- Interruptible-continued LDM/STM, PUSH/POP for low interrupt latency.
- Automatic processor state saving and restoration for low latency Interrupt
Service Routine (ISR) entry and exit.
- Support for ARMv6 unaligned accesses.
- Support Nested Vectored Interrupt Controller (NVIC)
- STM32F, LPC111x Series
[ Cortex-M3 ½Ã¸®Áî Performance ]
2. Cortex-M3 Procesor °³¿ä
2.1 Cortex-M3 Procesor Overview
(1) Thumb-2 Instruction Set Architecture
- 16, 32 bit ¸í·ÉÀ» Á¶ÇÕÇؼ »ç¿ëÇÒ¼ö ÀÖ½À´Ï´Ù.
- No more mode switching
- 16-bit code density·Î 32-bit ¸í·É ¼º´ÉÀ» ³¾¼ö ÀÖ½À´Ï´Ù.
- 16-bit Thumb Instruction °ú ÇÏÀ§ ȣȯ¼ºÀÌ ÀÖ½À´Ï´Ù.
(2) Harvard architecture
- Separate I&D buses allow parallel instruction fetching & data storage
- ¸í·É¾î¿Í Data¸¦ µ¿½Ã¿¡ FetchÇÒ¼ö ÀÖ´Â ±â´ÉÀº ÀÎÅÍ·´Æ® ¼öÇà½Ã Latency¸¦ ÁÙÀϼö ÀÖ´Â Áß¿äÇÑ feature ÀÔ´Ï´Ù.
(3) 3-Stage Pipeline with Branch Speculation
- Fetch, Decode, Execute
- ºÐ±â ¿¹ÃøÀ» ÇÒ¼ö ÀÖ´Ù¸é Pipeline ¿¡¼ Branch
½Ã Pipeline Flush¸¦ ÁÙÀϼö ÀÖ¾î ½Ã½ºÅÛÀÇ ¼º´ÉÀ» ³ôÀÏ ¼ö ÀÖ½À´Ï´Ù.
(4) Integrated Nested Vectored Interrupt Controller(NVIC) for low latency interrupt processing
(5) Vector Table is address, not instruction
(6) Designed to be fully programmed in "C"
(7) System Timer(SysTick) for Real Time OS - Not Peripheral timer
(8) Bit Band Aliasing
(9) Interruptible-continued LDM/STM, PUSH/POP
(10) Support Unaligned Data Access
- Unaligned access¸¦ Áö¿øÇؼ ¸Þ¸ð¸® »ç¿ëÀÇ È¿À²¼ºÀº ³ô¿´Áö¸¸ ¿©ÀüÈ÷ ¼Óµµ¸¦ À§Çؼ´Â Aligned access¸¦ ÇÏ´Â °ÍÀÌ È¿À²Àû ÀÔ´Ï´Ù.
2.2 Cortex-M3 Processor Block Diagram
(1) Cortex-M3 ºí·°µµ
Cortex-M3 Core´Â Bus Matrix( I-code, D-code, System Bus) ¸¦ ÅëÇؼ Cortex-M3 Äھ Base·Î ÇÏ´Â CPUµé(STM32F, LPC111x ½Ã¸®Áî µî)°ú ¿¬°áÀÌ µË´Ï´Ù.
(2) Bus Matrix System
- ICode Bus : Instruction & Vector fetches from CODE space
(0x0000.0000 ~ 0x1FFF.FFFF)
- DCode Bus : Data & Debugging access to CODE space
(0x0000.0000 ~ 0x1FFF.FFFF)
- System Bus : Instruction & Vector fetches from System Memory space
Data & Debug accesses to System Memory space
System Memory( SRAM, External RAM )
(3) STM32F ½Ã¸®Áî ºí·°µµ
[ Cortex-M3 Core¸¦ Base·Î ÇÑ STM32F ½Ã¸®Áî ºí·°µµ ]
À§ÀÇ ºí·°µµ¿¡¼ Cortex-M3 ºÎºÐ¸¸ ARM»ç¿¡¼ µðÀÚÀÎÇÑ °ÍÀÌ°í ³ª¸ÓÁö ºÎºÐÀº ST Microelectronics ¿¡¼ ¼³°èÇÑ °ÍÀÔ´Ï´Ù. Philips»çÀÇ LPC11x Cortex-M3 ½Ã¸®Áîµµ Cortex-M3 Core ºÎºÐÀº STM32F ½Ã¸®ÁîÀÇ Core ¿Í µ¿ÀÏÇÏ°í ÁÖº¯ Peripheral, interface bus µîÀÇ ºÎºÐ¸¸ ´Ù¸¥ °ÍÀÔ´Ï´Ù.
(4) Cortex-M3 ¿Í ARM7 ºñ±³
|
ARM7TDMI |
Cortex-M3 |
Architecture |
ARMv4T(von Neumann) |
ARMv7M(Harvard) |
ISA Support |
ARM(32-Bit) & Thumb(16-Bit)
need Mode Change |
Thumb-2 Only
No more Mode Change
|
DMIPS/MHz |
0.74(Thumb)/0.93(ARM) |
Thumb-2(1.25) |
Pipeline |
3-Stage |
3-Stage+Branch Speculation |
Interrupts |
IRQ/FIQ |
NMI,SysTick and up to 240
Interrupts. Integrated NVIC
Interrupt Controller
Up to 1-255 Priorities |
Interrupt Latency |
24~42 Cycles |
12 Cycles
(6 when Tail Chaining) |
Memory Map |
Undefined |
Architecture defined |
System Status |
PSR, 6modes
20 Banked regs |
xPSR, 2modes(Thread, Handler)
Stacked regs(1 bank) |
Sleep Modes |
No |
Three |
3. Cortex-M3 Processor Architecture
3.1 Register
(1) General Register
ÀüÅëÀûÀÎ ARM(ARM7,ARM9) ¿¡¼´Â 7°³ÀÇ µ¿ÀÛ ¸ðµåº°·Î Banked Register °¡ ÀÖ¾úÀ¸³ª Cortex-M3 ¿¡ ¿Í¼´Â R13(SP) ÀÌ Main Stack Pointer¿Í
Process Stack Pointer ·Î ±¸ºÐµÇ¾î Banked Register·Î Á¸ÀçÇÏ°í ³ª¸ÓÁö ·¹Áö½ºÅÍ´Â Cortex-M3 µ¿ÀÛ ¸ðµå(Thread Mode, Handler Mode) ¿¡ »ó°ü¾øÀÌ 1°³¾¿¸¸ Á¸Àç ÇÕ´Ï´Ù. 16-bit Thumb ¸í·É¾î ¿¡¼´Â R0 ~ R7 ·¹Áö½ºÅ͸¸ »ç¿ëÀÌ µÇ°í 32-bit
Thumb2 ¸í·É¾î¿¡¼´Â R0 ~ R15°¡ ¸ðµÎ »ç¿ëÀÌ µË´Ï´Ù. Stack Pointer (R13) ´Â Ç×»ó 4-ByteÁ¤·ÄÀÌ µÇ¾î ¿î¿µ µÇ¾î¾ß ÇϹǷΠStack PointerÀÇ ÇÏÀ§ 2ºñÆ®´Â Ç×»ó '2b00' ÀÌ µÇ¾î¾ß ÇÏ°ÚÁö¿ä. ±×¸®°í StackÀº Full Descending ¹æ½ÄÀ¸·Î ¿î¿µÀÌ µË´Ï´Ù.
Linked Register(R14) ´Â ÀüÅëÀûÀÎ ARM°ú ¸¶Âù °¡Áö·Î BLX ¸í·É¾î »ç¿ë½Ã º¹±Í ÇÒ ÁÖ¼Ò°¡ ÀúÀå µÇ¾î ÀÖ½À´Ï´Ù. Program Counter(R15)´Â ´ç¿¬È÷ ÇöÀç ½ÇÇàÇÏ°í ÀÖ´Â ¸í·É¾îÀÇ ÁÖ¼Ò(¾ö¹ÐÈ÷ ¸»ÇÏ¿¬ Pipeline ´Ü°è¿¡¼ Fetch ÇÏ°í ÀÖ´Â ¸í·É¾îÀÇ ÁÖ¼Ò)¸¦ °¡Áö°í ÀÖ½À´Ï´Ù. ±×·¯¹Ç·Î ½ÇÁ¦ PC´Â ÇöÀç ½ÇÇàÇÏ°í ÀÖ´Â ¸í·É¾î ´ÙÀ½ ´ÙÀ½ÀÇ ¸í·É¾îÀÇ ÁÖ¼Ò°¡ ÀúÀåµÇ¾î ÀÖ½À´Ï´Ù.
(2) Special Register
ÀüÅëÀûÀÎ ARM ¿¡¼´Â CPSR(Current Processer Status Register) À̶ó´Â Ưº°ÇÑ »óÅ ·¹Áö½ºÅÍ¿Í µ¿ÀÛ ¸ðµåº°·Î SPSR(Saved Processor Status Register) ÀÌ Á¸Àç ÇÏ¿´´Âµ¥, Cortex-M3 ¿¡¼´Â Special Register ÀÇ Á¾·ù°¡ ¸¹ÀÌ ´Ã¾î ³µ½À´Ï´Ù. ÇÏÁö¸¸ ±âÁ¸ÀÇ CPSR ·¹Áö½ºÅÍ¿Í ÀúÀåÇÏ°í ÀÖ´Â Á¤º¸´Â ºñ½ÁÇÕ´Ï´Ù.
[ ARM7 ¿¡¼ÀÇ CPSR ·¹Áö½ºÅÍ ]
xPSRÀº APSR, IPSR, EPSR 3°³ÀÇ Spectial Register·Î ³ª´©¾î º¼¼ö ÀÖ½À´Ï´Ù.
- APSR(Application Program Status Register)
ÇöÀç ½ÇÇàÇÏ°í ÀÖ´Â ÇÁ·Î±×·¥ÀÇ »óÅ Á¤º¸¸¦ ´ã°í ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¸é CMP ¸í·É¾î¿Í °°Àº ºñ±³ ¹®À̳ª ALU ¿¬»êÀÇ °á°ú°¡ APSR ·¹Áö½ºÅÍÀÇ Flag ºñÆ®¸¦ ¾÷µ¥ÀÌÆ® ÇÕ´Ï´Ù.
* ¾î¼Àºí¸®¾î
CMP R0, R1 ; R0 = 0, R1 = 1, R0 - R1 and update APSR Register
ADDMI R0, R0, R1 ; R0 = R0 + R1
SUBEQ
R0, R0, R1 ; R0 = R0 - R1
* C¾ð¾î
if( R0 - R1 < 0 )
R0 = R0 + 1
else
R0 = R0 - R1
CMP ¸í·É¾î´Â °á±¹Àº R0 - R1 À» ÇÑ °á°ú¸¦ °¡Áö°í APSR ·¹Áö½ºÅ͸¦ ¾÷µ¥ÀÌÆ® ÇÕ´Ï´Ù. °á±¹ 0¿¡¼ 1À» »©¸Õ -1ÀÌ µÇ°í Negative "N" ÀÌ APSR·¹Áö½ºÅÍ 31¹ø ºñÆ®¿¡ Set ÀÌ µË´Ï´Ù. "N" Flag°¡ Set ÀÌ µÇ¸é
À§ÀÇ ¸í·É¾î Áß¿¡¼ ADDMI ¸í·É¾î¸¸ ½ÇÇàÀÌ µÇ°í SUBEQ ¸í·É¾î´Â NOP ¸í·É¾î·Î ´ëü°¡ µÇ¾î ½ÇÇàÀÌ µÇÁö ¾Ê½À´Ï´Ù. ARM7¿¡¼´Â CPSR ·¹Áö½ºÅÍÀÇ [31:27] ºñÆ®¿Í °°Àº ¿ªÇÒÀ» ÇÕ´Ï´Ù.
- IPSR(Interrupt Program Status Register)
ÀÌÀüÀÇ ARM Processor´Â ÀÎÅÍ·´Æ® ÄÁÆ®·Ñ·¯°¡ ARM Core¿¡ Á¸Àç ÇÏÁö´Â ¾Ê¾Ò½À´Ï´Ù. ÁÖ·Î CPU¸¦ ¼³°è, Á¦Á¶ÇÏ´Â ¹ÝµµÃ¼ Vendor¿¡¼ ARM CoreÀÇ ¿ÜºÎ¿¡ CPU ¼³°è½Ã Ãß°¡ÇÏ´Â Peripheralµé ÁßÀÇ Çϳª ¿´½À´Ï´Ù. ±×·¡¼ IRQ°¡ ¹ß»ýÇÏ¸é ¾î¶² ÀÎÅÍ·´Æ®°¡ ¹ß»ý ÇÏ¿´´ÂÁö¸¦ CPU¿¡ Á¸ÀçÇÏ´Â ÀÎÅÍ·´Æ® ÄÁÆ®·Ñ·¯¿¡¼ INTOFFSET°ú °°Àº ARM Core ¿ÜºÎÀÇ SFT ·¹Áö½ºÅÍ¿¡ ÀúÀåÀÌ µÇ¾ú½À´Ï´Ù. ÇÏÁö¸¸ Cortex-M Profile ¿¡¼´Â ÀÎÅÍ·´Æ® ÄÁÆ®·Ñ·¯°¡
ARM Core ³»ºÎ(NVIC)¿¡ Á¸Àç ÇÕ´Ï´Ù. IPSRÀº ÇöÀç ¼öÇàÁßÀÎ Exception(Interrupt)ÀÇ ¹øÈ£¸¦ ÀúÀåÇÏ°í ÀÖ´Â ·¹Áö½ºÅÍ ÀÔ´Ï´Ù.
- EPSR(Execution Program Status Register)
ICI(Interruptible-Continuable Instruction)/IT(If-Then) 2°³ÀÇ ÁßøµÈ Çʵ带 Áö´Ï°í ÀÖ´Â ·¹Áö½ºÅÍ ÀÔ´Ï´Ù. ÀüÅëÀûÀÎ ARM ¿¡¼´Â LDM, STM ¸í·É¾î ¼öÇàÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÀ» ÇÏ´õ¶óµµ ¸ØÃâ¼ö°¡ ¾ø¾ú½À´Ï´Ù. ¸í·É¾î Boundary¿¡¼ ÀÎÅÍ·´Æ® 󸮰¡ µÇ±â ¶§¹®¿¡ LDM(POP), STM(PUSH) ¸í·É¾î ¼öÇàÀÌ ³¡³ª°í ³ª¼¾ß ÀÎÅÍ·´Æ®¸¦ ó¸®ÇÒ ¼ö°¡ ÀÖ½À´Ï´Ù. ÇÏÁö¸¸ Cortex-M3 ¿¡¼´Â LDM(POP)/STM(PUSH) ¸í·É ¼öÇàÁß¿¡µµ ÀÎÅÍ·´Æ® 󸮰¡ °¡´ÉÇÕ´Ï´Ù.
LDMFD SP!, {R0, R1, R4-R6}
À§¿Í °°ÀÌ Multiple Load ¸í·É¾î ¼öÇà½Ã R1À» Load ÇÏ´Â Áß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÀ» ÇϰԵǸé Cortex-M3 ¿¡¼´Â R1·¹Áö½ºÅÍ ±îÁö¸¸ ó¸®ÇÑ ´ÙÀ½ LDM ¸í·ÉÀ» Áß´ÜÇÏ°í ÇöÀç ¹ß»ýÇÑ Exception(ÀÎÅÍ·´Æ®) 󸮸¦ ³¡³»°í ³ª¼ Áß´Ü µÇ¾ú´ø ³ª¸ÓÁö R4-R6 Load ¸í·ÉÀ» ¼öÇàÇÏ°Ô µÇ´Âµ¥, À̶§ ÀÎÅÍ·´Æ®¸¦ ³¡³»°í ³ª¼ Áß´Ü µÇ¾ú´ø ·¹Áö½ºÅͺÎÅÍ ´Ù½Ã Load ¸í·É¾î¸¦ ¼öÇàÇÒ ¼ö ÀÖµµ·Ï Àӽ÷ΠICI Çʵ忡 Áß´Ü ÁöÁ¡ÀÇ ·¹Áö½ºÅÍ ¼ø¼¸¦ ÀúÀåÇÏ°í ÀÖ´Â ÀúÀå¼Ò°¡ ¹Ù·Î EPSR ·¹Áö½ºÅÍÀÇ ICI Çʵå ÀÔ´Ï´Ù. [15:12] ºñÆ®¸¸ »ç¿ëÀ» ÇÏ°í ³ª¸ÓÁö ºñÆ® [11:10], [26:25] Çʵå´Â »ç¿ëÇÏÁö ¾Ê½À´Ï´Ù.
IT Çʵå´Â Thumb-2 ¸í·É¾îÀÎ If-Then ºí·°ÀÇ Condition°ú ¸í·É¾îÀÇ ¼ø¼ ¹øÈ£¸¦ °¡Áö°í ÀÖ½À´Ï´Ù.
CMP R0, R1
ITTEE EQ
ADDEQ R2, R0, R1 ; R2 = R0 + R1
ADDEQ R2, R0, R3 ; R2 = R0 + R3
SUBNE R2, R0, R1 ; R2 = R0 - R1
SUBNE R2, R0, R3 ; R2 = R0 - R3
À§ÀÇ ¾î¼Àºí¸®¾î ¸í·É¾îµéÀ» Çؼ®ÇØ º¸¸é R0 - R1 ÇÑ °á°ú°¡ "0" À̸é ADDEQ ¸í·É¾î 2°³¸¦ ½ÇÇàÇÏ°í "0" ÀÌ ¾Æ´Ï¸é SUBNE ¸í·É¾î 2°³¸¦ ½ÇÇà Ç϶ó ÀÔ´Ï´Ù.
C¾ð¾î·Î Ç¥ÇöÇÏ¸é ¾Æ·¡¿Í °°½À´Ï´Ù.
if( R0 == R1 )
{
R2 = R0 + R1
R2 = R0 + R3
}
else
{
R2 = R0 - R1
R2 = R0 - R3
}
If-Then ¸í·É¾î Block ¼öÇàÁß¿¡
ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇϸé ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀ¸·Î ºÐ±â¸¦ Çß´Ù°¡ ´Ù½Ã If-Then ¸í·É¾î BlockÀ¸·Î º¹±ÍÇÏ¿© ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇß´ø ÁöÁ¡ÀÇ ´ÙÀ½ ¸í·É¾î ºÎÅÍ ¼öÇàÇØ¾ß Çϴµ¥ ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀ¸·Î ºÐ±âÇϱâÀü¿¡ IT Çʵ忡 ¸î¹ø° ¸í·É¾î±îÁö ¼öÇàÇß¾ú´ÂÁö¸¦ Àá½Ã ÀúÀåÇÏ´Â ·¹Áö½ºÅÍ ÀÔ´Ï´Ù.
À̶§ IT[7:5] ºñÆ®´Â Base Condition Á¤º¸ "CMP" ¸¦ ÀúÀåÇÏ°í ÀÖ°í IT[1:0], IT[7:4] ºñÆ®´Â If-Then ¸í·É¾î Block¾ÈÀÇ ISRÀÌ ¹ß»ýÇϱâ Àü±îÁöÀÇ ¼öÇàµÈ ¸í·É¾î ¹øÈ£¸¦ ÀúÀåÇÏ°í ÀÖ½À´Ï´Ù. ¶ÇÇÑ ICI/IT ´Â EPSR ·¹Áö½ºÅÍ ¾È¿¡¼ °°Àº ºñÆ®ÀÇ Çʵ带 °øÀ¯ÇÏ°í Àֱ⠶§¹®¿¡ If-Then Block ¿¡¼ LDM/STM °ú °°Àº Multiple Load/Store ¸í·É¾î¸¦ »ç¿ëÇϸé LDM/SDM ¸í·É¾î ¼öÇàÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇؼ ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀ» ³¡³»°í º¹±Í ÇßÀ»¶§ ¼öÇàÇß´ø ·¹Áö½ºÅÍ ¹øÈ£ºÎÅÍ ½ÃÀÛÇÏÁö ¸øÇÏ°í óÀ½ºÎÅÍ ´Ù½Ã LDM/STM ¸í·É¾î°¡ ¼öÇàµÇ°Ô µË´Ï´Ù. EPSR ·¹Áö½ºÅÍÀÇ °¢ ºñÆ®µéÀ» Ç¥·Î Á¤¸® ÇÏ¿´½À´Ï´Ù.
EPSR[26:25] |
EPSR[15:12] |
EPSR[11:10] |
IT[1:0] |
IT[7:4]
[7:5] --> Base Condition
Á¤º¸ |
IT[3:2] |
ICI[7:6] (‘00’) |
ICI[5:2] --> reg_num |
ICI[1:0] (‘00’) |
reg_num ´Â LDM, STM ¸í·É¾î ¼öÇàÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇÏ¿© Àá½Ã Áß´Ü µÇ¾ú´ø ·¹Áö½ºÅÍÀÇ ¹øÈ£ ÀÔ´Ï´Ù.
3.2 Operation Mode
ÀüÅëÀûÀÎ ARM¿¡¼´Â µ¿ÀÛ¸ðµå°¡ 7Á¾·ù(User,System,Fiq,Irq,SVC,Abord,Undefined)°¡ ÀÖ¾ú½À´Ï´Ù. Cortex-M3 ¿¡¼´Â Thread, Handler Mode 2°¡Áö·Î Ãà¼Ò µÇ¾ú½À´Ï´Ù. ±×¸®°í Priviledge Level ¿¡´Â Privileged, Unprivileged 2°¡ÁöÀÇ °æ¿ì°¡ ÀÖ½À´Ï´Ù. Cortex-M ÀÌÀüÀÇ ARM ¿¡¼´Â USER Mode¸¦ Á¦¿ÜÇÑ ³ª¸ÓÁö 6°³ÀÇ µ¿ÀÛ ¸ðµå°¡ Privilegdge Mode ÀÔ´Ï´Ù.
(1) Thread Mode
Exception ÀÌ ¹ß»ýÇÏÁö ¾ÊÀº º¸ÅëÀÇ »óÅ°¡ Thread Mode ÀÔ´Ï´Ù. Reset Exception ¹ß»ý½Ã(CPU ¿¡ Àü¿øÀÌ Àΰ¡µÇ¾î Ãʱ⠺ÎÆýÃ)¿¡ Thread Mode + Privileged + Main_stack(Stack Pointer)·Î ½ÃÀÛÇÏ°Ô µË´Ï´Ù. ´ç¿¬È÷ Ãʱ⠺ÎÆýÿ¡´Â ±ÇÇÑÀÌ ÀÖ´Â ¸ðµå·Î ½ÇÇàÀÌ µÇ¾î¾ß ÇÏ°ÚÁö¿ä? ±ÇÇÑÀÌ ÀÖ´Â ¸ðµå·Î ºÎÆÃÀ» ½ÃÀÛÇØ¾ß H/W, S/W ¼³Á¤À» ³¡³»°í Unprivileged ¸ðµå·Î ÀüȯÀ» Çؼ User ApplicationÀ» ½Ç»ý ½Ãų¼ö ÀÖÀ»Å״ϱî¿ä. ±×¸®°í Çѹø ±ÇÇÑÀÌ ¾ø´Â ¸ðµå·Î ÀüȯÀÌ µÇ°í ³ª¸é ÀϹÝÀûÀÎ ¹æ¹ýÀ¸·Î´Â Privilege ¸ðµå·Î ÀüȯÇÒ¼ö ¾ø½À´Ï´Ù. ExceptionÀÌ ¹ß»ýÇÏ¿© Handler Mode(Handler Mode ¿¡¼´Â Ç×»ó Privilege ¸ðµå)·Î ÀüȯÀÌ µÇ°Å³ª ȤÀº S/W ÀûÀ¸·Î "SVC(Super Visor Call)" ¸í·É¾î¸¦ ½á¼ SVC_Handler Exception À» ¹ß»ý½ÃÄѼ Handler ModeÀÇ ¼ºñ½º ·çƾ¿¡¼ MSR ¸í·É¾î¸¦ »ç¿ëÇÏ¿© Priviledge Mode·Î º¯°æ ½ÃÄÑ¾ß ÇÕ´Ï´Ù.
Privilege ¸ðµå¿¡¼ Unprivileged ·Î ÀüȯÇÏ´Â ¹æ¹ýÀº MSR ¸í·É¾î¸¦ »ç¿ëÇÏ´Â °ÍÀÔ´Ï´Ù. ´ç¿¬È÷ MSR ¸í·É¾î´Â Privilege ¸ðµå¿¡¼¸¸ »ç¿ëÀÌ °¡´É ÇÕ´Ï´Ù. Privilege level º¯°æ ¹æ¹ýÀº CONTROL Register ¼³¸í½Ã¿¡ ¿¹¸¦µé¾î º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
(2) Handler Mode
Thread Mode ¿¡¼ IRQ, Fault µîÀÇ Exception ÀÌ ¹ß»ýÇßÀ» °æ¿ì ¹®¸Æ º¸Á¸À» À§Çؼ Stack¿¡ {R0~R4, R12, LR, PC, xPSR} ·¹Áö½ºÅÍ°¡ Stack¿¡ H/WÀûÀ¸·Î PUSH(ÀúÀå)°¡ µÇ°í ÀÌ¿Í º´·ÄÀûÀ¸·Î Thread Mode ¿¡¼ ÀÚµ¿À¸·Î Handler Mode ·Î ÀüȯÀÌ µÇ¸é¼ Cortex-M3 Architecture ÀûÀ¸·Î ¹Ì¸® Á¤ÀÇ µÇ¾î ÀÖ´Â Vector Table¿¡ ÀÖ´Â Exception Handler ÁÖ¼Ò°¡ Fetch µÇ¾î PCÀÇ ÁÖ¼Ò°¡ ¹Ù²î°Ô µË´Ï´Ù. ÀÌ·¸°Ô Stack ¸Þ¸ð¸®¿Í Vector Table Fetch ÀÛ¾÷ÀÌ µ¿½Ã¿¡ ÀÌ·ç¾î Áú¼ö ÀÖ´Â ÀÌÀ¯´Â Cortex-M3 °¡ Havard Architecture ±¸Á¶ À̱⠶§¹®¿¡ °¡´É ÇÕ´Ï´Ù. Harvard Architecure´Â ±¸Á¶ÀûÀ¸·Î Code, Data Bus °¡ º°µµ·Î Á¸ÀçÇÏ´Â ±¸Á¶ ÀÔ´Ï´Ù. ¹Ý´ë·Î Code¿Í Data Bus°¡ Çϳª¸¸ Á¸ÀçÇÏ´Â ±¸Á¶¸¦ Von-Neumann Bus ±¸Á¶¶ó°í ÇÕ´Ï´Ù.
[ Von-Neumann bus ±¸Á¶ - Wikipedia ÂüÁ¶ ]
[ Harvard bus ±¸Á¶ - Wikipedia ÂüÁ¶]
´ç¿¬È÷ Harvard Architecure ±¸Á¶°¡ Von-Neumann Bus ±¸Á¶º¸´Ù È¿À²ÀûÀÌ °ÚÁö¿ä. Handler Mode ¿¡¼´Â ±ÇÇÑ »óÅ°¡ Ç×»ó Privilegde ¸ðµå ÀÔ´Ï´Ù. Handler ¼ºñ½º ·çƾÀÌ ³¡³ª¸é Exception ÀÌ ¹ß»ýÇÑ ¸í·É¾îÀÇ ´ÙÀ½ ¸í·É¾î·Î PC°¡ º¹±Í°¡ µÇ°í ±×¿Í µ¿½Ã¿¡ Stack ¿¡¼ POP ÀÌ ¹ß»ýÇÏ¿© ÀÌÀü¿¡ Stack¿¡ Àá½Ã º¸°ü µÇ¾ú´ø {R0~R4, R12, LR, PC, xPSR} ·¹Áö½ºÅ͵éÀÌ º¹±¸°¡ µË´Ï´Ù. {R0~R4, R12} ·¹Áö½ºÅ͸¦ Cortex-M3 ¿¡¼ ÀÚµ¿À¸·Î Stack¿¡ ÀúÀåÇÏ´Â ÀÌÀ¯´Â {R0~R4, R12} ·¹Áö½ºÅ͵éÀÌ Scratch ·¹Áö½ºÅ͵é À̱⠶§¹® ÀÔ´Ï´Ù. ÀÚ¼¼ÇÑ »çÇ×Àº ¾Æ·¡ AAPCS Register ºÎºÐÀ» ÂüÁ¶Çϼ¼¿ä.
3.3 Stack
Cortex-M3 ¿¡¼ StackÀº Main_stack, Process_stack 2°³°¡ Banked µÇ¾î Á¸ÀçÇÏ°í Ç×»ó 4Byte Aligned µÇ¾î ÀÖ¾î¾ß ÇÕ´Ï´Ù. 4Byte·Î Aligned µÇ¾î¾ß ÇÑ´Ù´Â °ÍÀº Stack Memory¿¡ 8Bit, 16Bit µ¥ÀÌÅ͸¦ ÀúÀå(PUSH) ÇÏ´õ¶óµµ Ç×»ó 32Bit °ø°£À» Â÷Áö ÇÑ´Ù´Â °ÍÀÔ´Ï´Ù. ÀüÅëÀûÀÎ ARM¿¡¼´Â 7°¡Áö µ¿ÀÛ¸ðµåº°·Î SP°¡ º°µµ·Î Á¸Àç ÇÏ¿´½À´Ï´Ù.
Reset Exception ¹ß»ý½Ã(CPU ¿¡ Àü¿øÀÌ Àΰ¡µÇ¾î Ãʱ⠺ÎÆýÃ)¿¡ Thread Mode + Privileged + Main_stack ·Î ½ÃÀÛÇÑ´Ù°í ÇÏ¿´½À´Ï´Ù. Reset Exception ¹ß»ý½Ã¿¡ À§ÀÇ »çÇ× ¸»°íµµ ÇÏ´Â ÀÏÀÌ ÇÑ°¡Áö ´õ ÀÖ½À´Ï´Ù. ±×°ÍÀº 0x00 ¹øÁö¿¡ ÀÖ´Â ÁÖ¼Ò¸¦ Hardware ÀûÀ¸·Î Àоî¿Í¼ Main_stack Pointer¸¦ Setup ÇÏ°í ³ª¼ 0x4 ¹øÁö ÁÖ¼Ò¿¡ ÀÖ´Â Reset Handler Address( Progragm ½ÃÀÛ ÁÖ¼Ò)¸¦ Àоî¿Í¼ PC ¿¡ ÀúÀåÇÏ´Â °ÍÀÔ´Ï´Ù. ÀÌ·¯ÇÑ ÀÌÀ¯¶§¹®¿¡ Cortex-M3 ¿¡¼´Â ½ÇÁ¦·Î ÇÁ·Î±×·¥ÀÇ ½ÃÀÛ ÁÖ¼Ò°¡ 0x4 ¹øÁö°¡ µË´Ï´Ù. ÀüÅëÀûÀÎ ARM¿¡¼´Â 0x0 ÁÖ¼Ò¿¡ ÇÁ·Î±×·¥ÀÇ ½ÃÀÛ Æ÷ÀÎÅÍÀÎ Reset Handler°¡ Á¸Àç ÇÏ¿´°í 0x0 ÁÖ¼ÒÀÇ ³»¿ëÀº ¸í·É¾î(Branch)°¡ Á¸Àç Çؾ߸¸ ÇßÀ¸¸ç 7°¡Áö µ¿ÀÛ¸ðµåº°·Î Boot Äڵ忡¼ S/W ÀûÀ¸·Î MSR ¸í·É¾î¸¦ »ç¿ëÇÏ¿© SP¸¦ Setup Çؾ߸¸ Çß½À´Ï´Ù. ÀÌ¿¡ ºñÇϸé Cortex-M3 ÀÇ Stack Pointer SetupÀº H/W ÀûÀ¸·Î ÀÌ·ç¾î Áö°í ÀÖ¾î °³¹ßÀÚ ÀÔÀå¿¡¼´Â ¸¹Àº ¼ö°í¸¦ ´ú¼ö°¡ ÀÖ½À´Ï´Ù. Âü°í·Î STM32F ½Ã¸®Áî¿¡¼´Â 0x0 ¹øÁö¿Í 0x8000000 ¹øÁö°¡ Alias µÇ¾î ÀÖ¾î 0x0 ÁÖ¼ÒÀÇ ³»¿ë°ú 0x8000000 ÁÖ¼ÒÀÇ ³»¿ëÀÌ µ¿ÀÏ ÇÕ´Ï´Ù.
[ STM32F ¿¡¼ÀÇ 0x8000000 ÁÖ¼ÒÀÇ Memory ³»¿ë ]
[ STM32F ¿¡¼ÀÇ 0x0000000 ÁÖ¼ÒÀÇ Memory ³»¿ë ]
Main_stack pointer °¡ H/W ÀûÀ¸·Î Setup ÀÌ µÈ´Ù´Â °ÍÀº 0x04 ¹øÁö¿¡¼ Segment Ãʱâȸ¦ ³¡³»°í ¹Ù·Î main ÇÔ¼ö·Î ºÐ±âÇÏ¿© "C" Program ·çƾ¿¡¼ ºÎÅÍ ºÎÆÃÀ» ½ÃÀÛ ÇÒ¼ö ÀÖ´Ù´Â À̾߱â ÀÔ´Ï´Ù.
¿©±â¼ Segment Ãʱâȶó´Â ¿ë¾î°¡ ³ª¿À´Âµ¥ Àá½Ã ¤°í ³Ñ¾î °¡µµ·Ï ÇÏ°Ú½À´Ï´Ù. ÀÌÀü¿¡ ARM Architecture °Á¿¡¼µµ Çѹø ¾ð±ÞÀ» Çß¾ú½À´Ï´Ù.
main.c ÆÄÀÏÀ» ÄÄÆÄÀÏÇÏ°í ¾î¼ÀºíÇÏ¿© main.o ÆÄÀÏÀÌ »ý¼ºÀÌ µÈ´Ù¸é .o ÆÄÀÏÀÇ ±¸Á¶´Â À§¿Í °°ÀÌ ZI(Zero Initialized), RW(Read Write), RO(Read Only) ¿µ¿ªµî À¸·Î ³ª´©¾îÁ® »ý¼ºÀÌ µË´Ï´Ù. °á±¹ hex(bin) ÆÄÀÏÀÇ ±¸Á¶´Â main.o ÆÄÀÏ°ú °°Àº ¿©·¯°³ÀÇ *.o + *.a(¶óÀ̺귯¸® ÆÄÀÏ) + Link Script(Scattor Loading) ÆÄÀÏÀÌ Á¶ÇÕÀÌ µÇ¾î Linker¿¡ ÀÇÇØ »ý¼ºÀÌ µÇ´Â °ÍÀÔ´Ï´Ù.
ZI, RO, RW ¿µ¿ªµéÀ» Segment ¶ó°í Çϸç ÀÌ SegmentµéÀÌ Å¸°Ù ½Ã½ºÅÛÀÇ RAM, ROM ¿¡ Àû´çÈ÷ ÀÚ¸®¸¦ Àâ°í ÀÖµµ·Ï ÇÏ´Â ÀÛ¾÷À» Segment ÃʱâÈ ÀÛ¾÷ À̶ó°í ÇÕ´Ï´Ù. Segment ÃʱâÈ ÀÛ¾÷Àº H/W ÀûÀ¸·Î ÀÌ·ç¾î ÁöÁö´Â ¾Ê½À´Ï´Ù. Hex ÆÄÀÏÀ» JTAG µîÀÇ Àåºñ¸¦ ÀÌ¿ëÇÏ¿© ROM ¿µ¿ª¿¡ ǻ¡(Write)À» ÇÑ »óÅ¿¡¼ ºÎÆÃÀ» Çϸé Startup(Bootloader) Äڵ忡¼ ROM ¸Þ¸ð¸®¿¡¼ RW ¿µ¿ªÀ» Àоî¿Í¼ RAM¿¡ º¹»çÇØÁÖ°í ZI ¿µ¿ªÀº ¸ðµÎ 0x0 °ªÀ¸·Î ÃʱâÈ ÇØÁÖ´Â ÀÛ¾÷À» ÇØÁÖ¾î¾ß ÇÕ´Ï´Ù. ÀÌ·¯ÇÑ Segment ÃʱâÈ ÀÛ¾÷À» ÇØÁÖÁö ¾ÊÀ¸¸é C ¾ð¾î¿¡¼ »ç¿ëÇÏ´Â Àü¿ªº¯¼öµî¿¡ ¿Ã¹Ù¸¥ ÃʱⰪÀÌ µé¾î°¡ ÀÖÁö ¾Ê½À´Ï´Ù.
hex(bin) ÆÄÀÏ°ú ½Ã½ºÅÛÀÇ RAM, ROM °úÀÇ °ü°è¸¦ ±×¸²À¸·Î Ç¥ÇöÇØ º¸¾Ò½À´Ï´Ù.
Âü°í·Î Cortex-M3 IAR ÄÄÆÄÀÏ·¯´Â ºÎÆ®ÄÚµå ¶óÀ̺귯¸®¿¡¼ ÀÌ ÀÛ¾÷À» °³¹ßÀÚ ´ë½Å ÇØÁÖ°í ÀÖ½À´Ï´Ù. IAR Startup ÄÚµåÁß¿¡¼
__iar_program_start ¶ó´Â ¼ºê·çƾ Äڵ忡¼ ¾Æ·¡ ±×¸²°ú °°Àº ¶óÀ̺귯¸® ·çƾµéÀÌ ¼øÂ÷ÀûÀ¸·Î È£Ã⠵˴ϴÙ.
__iar_data_init3 °¡ Segment ÃʱâÈÀÛ¾÷ ¼ºê ·çƾ ÀÔ´Ï´Ù.
[ IAR ÄÄÆÄÀÏ·¯ Cortex-M3 Áö¿ø ÄÚµå ]
(1) Main Stack setup
Main Stack Æ÷ÀÎÅÍ´Â ºÎÆýÿ¡ H/W ÀûÀ¸·Î 0x0 ¹øÁö¿¡¼ 32Bit(4Byte) °ª(Main Stack Æ÷ÀÎÅÍÀÇ ÁÖ¼Ò)À» Àоî¿Í¼ ÀÚµ¿À¸·Î Setup ÀÌ µÈ´Ù°í ÇÏ¿´½À´Ï´Ù. Cortex-M3 ¿¡¼ 0x0 ¹øÁö¿¡´Â Ç×»ó Main Stack ÀÇ ÁÖ¼Ò°¡ ÀÖ¾î¾ß ÇÕ´Ï´Ù. ÀÚµ¿À¸·Î SetupÀÌ µÇÁö¸¸ ºÎÆà ÀÌÈÄ¿¡ Main Stack Æ÷ÀÎÅ͸¦ º¯°æÇÏ´Â °æ¿ì¿¡´Â MSR ¸í·É¾î¸¦ »ç¿ëÇÏ¸é µË´Ï´Ù.
MOV R0 , #0x20002000
MSR MSP , R0
(2) Processor Stack setup
º¸ÅëÀÇ °æ¿ì¿¡´Â Main Stack¸¸ »ç¿ëÇؼ ÇÁ·Î±×·¥À» °³¹ßÇÏ¸é µË´Ï´Ù. ÇÏÁö¸¸ RTOSµî¿¡¼ Ä¿³ÎÀº Privilegde + Main Stack À» »ç¿ëÇÏ°Ô ÇÏ°í User Application¿¡¼´Â Unpriviledge + Processor Stack À» »ç¿ëÇÏ¿© ¿î¿µÃ¼Á¦¸¦ º¸È£ÇÏ°í ½Í´Ù¸é Processor_stack Æ÷ÀÎÅ͸¦ Setup ÇØ¾ß ÇÕ´Ï´Ù.
MOV R0 , #0x20001500
MSR PSP , R0
·¹Áö½ºÅÍ ¼³¸í¿¡¼ CONTROL·¹Áö½ºÅÍ¿¡ ´ëÇÑ ¼³¸íÀ» ÇÏÁö ¾Ê¾Ò¾ú´Âµ¥, ¿©±â¼ »ìÆ캸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
CONTROL ·¹Áö½ºÅÍ´Â Cortex-M3 Core ÀÇ ÇöÀç ±ÇÇÑ ·¹º§(Privilege, Unprivileged)°ú »ç¿ëÇÏ°í ÀÖ´Â StackÀ» ÀúÀåÇÏ°í ÀÖ´Â Special Register ÀÔ´Ï´Ù.
- Bit[0] : 0 : privileged, 1 : Unprivileged
- Bit[1] : 0 : Use SP_main, 1 : Use SP_process
- Bit[2] : 0 : FP extension not active, 1 : Active
- Bit[31:3] : Reserved
(3) Stack Setup ¿¹Á¦
ARM¿¡¼ StackÀº Full-Descending ¹æ½ÄÀ¸·Î ¿î¿µµÇ±â ¶§¹®¿¡ º¸Åë RAMÀÇ °¡Àå ³ôÀº ÁÖ¼Ò ¿µ¿ª¿¡ Stack Pointer¸¦ ¼³Á¤ÇÏ°Ô µË´Ï´Ù.
À§ÀÇ ¿¹Á¦¿¡ ÀÖ´Â ¾î¼Àºí¸®¾î´Â Processor Stack Æ÷ÀÎÅ͸¦ 0x20001800À¸·Î ¼³Á¤(MSR PSP, R0)ÇÏ°í MSR ¸í·É¾î¸¦ »ç¿ëÇؼ CONTROL ·¹Áö½ºÅÍÀÇ ÇÏÀ§ [1:0] ºñÆ®¸¦ "2b11" ·Î ¼³Á¤ÇÏ¿©Cortex-M3ÀÇ ±ÇÇÑ ·¹º§À»
Unprivileged·Î Stack Æ÷ÀÎÅÍ´Â Processor StackÀ» »ç¿ëÇϵµ·Ï ÇÏ´Â ÄÚµå ÀÔ´Ï´Ù.
* Full-Descending ¹æ½ÄÀ̶õ ?
Stack ¸Þ¸ð¸®¿¡ µ¥ÀÌÅÍ°¡ ÀúÀåÀÌ µÉ¶§ Full-Descending ¿¡¼ Full À̶ó´Â °ÍÀº Stack µ¿ÀÛÀÌ ³¡³ª°í ³µÀ»¶§ Ç×»ó SP´Â À¯È¿ÇÑ µ¥ÀÌÅ͸¦ °¡¸£Å°°í ÀÖ´Ù´Â °ÍÀÌ°í Descending À̶ó´Â °ÍÀº ³ôÀº ÁÖ¼Ò¿¡¼ ³·Àº ÁÖ¼Ò·Î ÁÖ¼Ò°¡ °¨¼Ò ÇÏ¸é¼ µ¥ÀÌÅÍ°¡ ÀúÀåÀÌ µÇ´Â ¹æ½Ä ÀÔ´Ï´Ù. Stack PUSH µ¿ÀÛÀÌ ³¡³µÀ»¶§ SP°¡ À¯È¿ÇÑ µ¥ÀÌÅ͸¦ °¡¸£Å°°í ÀÖÀ¸·Á¸é µ¥ÀÌÅ͸¦ PUSHÇϱâ Àü¿¡ ¸ÕÀú SPÀÇ ÁÖ¼Ò¸¦ 4Byte °¨¼Ò½ÃÅ°°í ³ª¼ µ¥ÀÌÅ͸¦ ÀúÀå ÇØ¾ß ÇÕ´Ï´Ù. ¹Ý´ë·Î POP µ¿ÀÛ¿¡¼´Â µ¥ÀÌÅ͸¦ ¸ÕÀú ²¨³»°í ³ª¼ SPÀÇ ÁÖ¼Ò¸¦ 4Byte Áõ°¡ ½ÃÄÑ¾ß ÇÕ´Ï´Ù. PUSH, POP µ¿ÀÛÀ» ±×¸²À¸·Î ¿¹¸¦ µé¾î º¸°Ú½À´Ï´Ù.
- PUSH Operation
- POP Operation
À§ÀÇ ±×¸²¿¡¼ POP µ¿ÀÛÀÌ ³¡³ ÀÌÈÄ¿¡µµ RAM STACK¿µ¿ª¿¡´Â µ¥ÀÌÅÍ°¡ ±×´ë·Î ³²¾Æ ÀÖ½À´Ï´Ù. POPÀ» Çß´Ù°í Çؼ ¸Þ¸ð¸®¿¡¼ µ¥ÀÌÅÍ°¡ »ç¶óÁö´Â °ÍÀº ¾Æ´Ï°í ´ÜÁö SP ¸¸ÀÌ º¯°æµÈ´Ù´Â »ç½ÇÀ» ¾Ë¼ö ÀÖ½À´Ï´Ù.
3.4 Cortex-M3 Memory Map
Cortex-M3 ¿¡¼´Â CODE ¿µ¿ª(ROM) °ú RAM(SRAM)ÀÇ ÁÖ¼Ò°¡ Architecture Â÷¿ø¿¡¼ Á¤ÀÇ°¡ µÇ¾î Àֱ⠶§¹®¿¡ Cortex-M3 Core¸¦ ±â¹ÝÀ¸·ÎÇÑ CPU(ST, Luminsary, TI, Samsung »çÀÇ Cortex-M3 CPU)µé »çÀÌ¿¡´Â Æ÷Æà ÀÛ¾÷ÀÌ ¸¹ÀÌ ½¬¿ö Á³½À´Ï´Ù. ÀÌÀüÀÇ ÀüÅëÀûÀÎ ARM¿¡¼´Â CPUÀÇ ¸Þ¸ð¸® ¹ðÅ©¿¡ µû¶ó¼ RAMÀÇ ½ÃÀÛÁÖ¼Ò°¡ °°Áö ¾ÊÀ»¼ö ÀÖ°í, Peripheral µéÀÇ ½ÃÀÛÁÖ¼Ò ¶ÇÇÑ CPU¸¶´Ù ´Ù¸¦¼ö ÀÖ½À´Ï´Ù. À§ÀÌ Memory MapÀ» º¸¸é 32bit Core À̱⠶§¹®¿¡ 4GB ¸Þ¸ð¸®±îÁö Á¢±ÙÀÌ °¡´ÉÇÏ°í SRAM, Peripheral ¿µ¿ªÀÇ ÁÖ¼Ò¿¡ ƯÀÌÇÏ°Ôµµ Bit band alias ¿µ¿ªÀ̶ó´Â °ÍÀÌ Á¸Àç ÇÕ´Ï´Ù. ÀÌ ºÎºÐÀº Bit Banding Àå¿¡¼ ÀÚ¼¼È÷ ¼³¸í Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù.
(1) STM32F103VC(High desnsity) ÀÇ Memory Model
0x0800.0000 ~ 0x0801.FFFF ( FLASH )
0x2000.0000 ~ 0x2000.BFFF ( SRAM )
0x4000.0000 ~ 0x4002.3FFF ( Peripheral Memory Map )
0xE000.0000 ~ 0xE00F.FFFF ( Cortex-M3 Internal Peri. )
3.4 Thumb-2 Instruction Set
Cortex-M3 ´Â Thumb-2 ¸í·É¾î¸¸ Áö¿ø ÇÕ´Ï´Ù. ÀüÅëÀûÀÎ ARM ¿¡¼´Â 16Bit Thumb ¸í·É¾î¿Í 32Bit ARM ¸í·É¾î¸¦ »ç¿ëÇÒ ¼ö°¡ ÀÖ¾ú´Âµ¥, Thumb ¸ðµå¿¡¼´Â 16Bit ¸í·É¾î¸¸ »ç¿ëÇÒ ¼ö ÀÖ°í 32Bit ¸í·É¾î¸¦ »ç¿ëÇϱâ À§Çؼ´Â Mode Change(Thumb Mode --> ARM Mode)¸¦ Çؾ߸¸ Çß½À´Ï´Ù. Mode Change¸¦ À§Çؼ´Â BX ¶ó´Â ºÐ±â ¸í·É¾î¸¦ »ç¿ëÇؾ߸¸ Çß½À´Ï´Ù. Thumb-2 ¸í·É¾îÀÇ °¡Àå Å« Ư¡Àº Thumb¸ðµå¿Í ARM¸ðµå »çÀÌ¿¡ ¸ðµå Àüȯ ¾øÀÌ 16bit Thumb ¸í·É¾î¿Í 32Bit ¸í·É¾î¸¦ ¼¯¾î¼(Blend) »ç¿ëÇÒ¼ö ÀÖ´Â °ÍÀÔ´Ï´Ù. ÀÌ·¯ÇÑ Æ¯Â¡À¸·Î Thumb ¸í·É¾î¸¸ »ç¿ëÇßÀ»¶§ º¸´Ù ¼º´ÉÀº ÁÁ¾ÆÁö°í ÄÚµåÀÇ ÁýÀû´Â ARM 32Bit ¸í·É¾î¿¡ ºñÇؼ ÁÁ¾ÆÁ³½À´Ï´Ù. Thumb-2 ¸í·É¾î´Â ±âÁ¸ÀÇ Thumb ¸í·É¾î¿Í ÇÏÀ§ ȣȯ¼ºÀ» À¯Áö ÇÕ´Ï´Ù.
À§ÀÇ ±×¸²Àº ¸í·É¾îµé »çÀÌÀÇ Performance¿Í Code size ¸¦ Ç¥·Î ³ªÅ¸³½°ÍÀÔ´Ï´Ù.
ARM ¸í·É¾î¸¦ »ç¿ëÇßÀ» ¶§¿Í Thumb-2 ¸í·É¾î¸¦ »ç¿ëÇßÀ»¶§ÀÇ ÄÚµå »çÀÌÁ ºñ±³ÇØ º¸¾Ò½À´Ï´Ù. À§ÀÇ ¾î¼Àºí¸® ¸í·É¾î´Â µÎ¼ö(R0, R1) »çÀÌÀÇ Àý´ë°ªÀ» ±¸ÇÏ´Â ¸í·É¾î ÀÔ´Ï´Ù. "C" ¾ð¾î¸¦ ÂüÁ¶Çϼ¼¿ä. 16Bit Thumb ¸í·É¾î¿¡¼´Â Conditional Execution À» »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù. ´Ü, Thumb ¸í·É¾î¿¡¼µµ BX ¸í·É¾îÀÇ °æ¿ì¿¡´Â Conditional Execution À» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
3.5 Bit Banding
Cortex-M3 Memory MapÀ» ¼³¸íÇÒ¶§ Bit band alias ¿µ¿ªÀÌ ÀÖ´Ù°í ÇÏ¿´½À´Ï´Ù.
SRAM, Peripheral ¿µ¿ª¿¡ Á¸ÀçÇϸç SRAM¿µ¿ªÀÇ °æ¿ì 0x22000000 ÁÖ¼Ò¿¡ '0' or '1' À» Write Çϸé 0x20000000 ÁÖ¼ÒÀÇ ½ÇÁ¦ SRAM ÀÇ [0] ¹ø ºñÆ® ¿¡ '0' or '1' ÀÌ Write µÇ¾î Áö´Â °ÍÀÔ´Ï´Ù. Write »Ó¸¸ÀÌ ¾Æ´Ï¶ó 0x22000000 ÁÖ¼ÒÀÇ Data À» ÀÐÀ¸¸é 0x20000000 ÁÖ¼ÒÀÇ SRMÀÇ [0] ¹ø ºñÆ®°¡ Àоî Áý´Ï´Ù. Áï SRAM 1MB bit-band region 1ºñÆ®´Â 32MBÀÇ alias region ¿µ¿ªÀÇ 32bit(1 WORD) ¿Í Alias(µ¿ÀÏÇÏ°Ô Mapping) µÇ¾î ÀÖ´Â °ÍÀÔ´Ï´Ù. ÀÌ·¯ÇÑ Æ¯Â¡Àº Peripheral ¿µ¿ªµµ ¸¶Âù°¡Áö·Î Àû¿ëÀÌ µË´Ï´Ù. ±×¸²À¸·Î ´Ù½Ã º¸¸é ¾Æ·¡¿Í °°½À´Ï´Ù.
±×·¯¸é Cortex-M3 ÀÇ ÀÌ·± Ư¡ÀÌ ÀÖ´Â ÀÌÀ¯´Â ¹«¾ù Àϱî¿ä ? ¿¹¸¦ µé¸é
0x4001180C ÁÖ¼Ò¿¡ 32bit GPIOE ±×·ìÀÇ µ¥ÀÌÅÍ ·¹Áö½ºÅÍ°¡ Á¸ÀçÇÏ°í ÀÖ°í GPIOE2, 3, 4 Æ÷Æ®¿¡ °¢°¢ LED °¡ ¿¬°áµÇ¾î ÀÖ´Ù°í °¡Á¤ÇØ º¾½Ã´Ù.
ȸ·Î»óÀ¸·Î´Â À§ÀÇ ±×¸²°ú °°½À´Ï´Ù. ¿©±â¼ PE2, PE4ÀÇ »óÅ´ °Çµå¸®Áö ¾Ê°í PE3¿¡ ¿¬°áµÇ¾î ÀÖ´Â LED3¸¸ ON(PE3 Æ÷Æ®¸¦ High)½ÃÅ°·Á°í ÇÑ´Ù¸é Bit BandingÀÌ Áö¿øµÇÁö ¾Ê´Â ½Ã½ºÅÛ¿¡¼´Â ´ÙÀ½°ú °°ÀÌ Äڵ带 ÀÛ¼ºÇØ¾ß ÇÕ´Ï´Ù.
(*(volatile unsigned *)0x4001180C) |= (0x1 << 2);
ARMÀÇ Load, Store ±¸Á¶¿¡¼ ÀÌ°ÍÀ» ¾î¼Àºí¸®¾î·Î ´Ù½Ã ÀÛ¼ºÇØ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
LDR R0, =
0x4001180C ; R0 = 0x4001180C
MOV
R2, #0x4 ; R2 = 0x4
LDR R1, [R0]
; R0°¡ °¡¸£Å°´Â ÁÖ¼Ò¿¡¼ 32Bit µ¥ÀÌÅ͸¦ Àоî¿Í¼ R1 ·¹Áö½ºÅÍ¿¡ ÀúÀå
ORR R1, R2 ; R1 | R2
STR R1, [R0] ; R1·¹Áö½ºÅÍÀÇ °ªÀ» R0°¡ °¡¸£Å°´Â ÁÖ¼Ò¿¡ ÀúÀå
ÀÌ¿Í °°ÀÌ Bit BandingÀ» Áö¿øÇÏÁö ¾Ê´Â ½Ã½ºÅÛ¿¡¼´Â ·¹Áö½ºÅÍ¿¡ ¸Þ¸ð¸®ÀÇ ³»¿ëÀ» Register¿¡ Load Çسõ°í
Bit wise ¿¬»êÀ» ÇÑ ÀÌÈÄ¿¡ ´Ù½Ã STR ¸í·É¾î¸¦ »ç¿ëÇؼ RegisterÀÇ ³»¿ëÀÇ ¸Þ¸ð¸®¿¡ ÀúÀåÇÏ´Â ¹æ½ÄÀ¸·Î Çؾ߸¸ ÇÕ´Ï´Ù. ARM¿¡¼ ¿¬»ê ¸í·É¾îµéÀº ·¹Áö½ºÅÍ¿Í ¸Þ¸ð¸®ÀÇ ³»¿ëÀ¸·Î Á÷Á¢ ¿¬»êÀ» ÇÒ¼ö°¡ ¾ø°í Ç×»ó ¸Þ¸ð¸®ÀÇ ³»¿ëÀ» ·¹Áö½ºÅÍ¿¡ Àоî¿Í¼ ¿¬»êÀ» ¸¶Ä£ ÀÌÈÄ¿¡ ¸Þ¸ð¸®¿¡ ´Ù½Ã ÀúÀåÇÏ´Â ¹æ½ÄÀ¸·Î »ç¿ëÇØ¾ß ÇÕ´Ï´Ù. ARMÀº Load/Store ¹æ½ÄÀ̱⠶§¹® ÀÔ´Ï´Ù.
À̹ø¿¡´Â Bit Banding À» ÀÌ¿ëÇؼ °°Àº ÀÛ¾÷À» ¼öÇàÇØ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. ¿ì¼± C ÄÚµå·Î ÀÛ¼ºÇØ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
(*(volatile unsigned *)(0x42000000 + (0x4001180C-0x40000000)*32 + 3*4)) = 0x0;
¾î¼Àºí¸®¾î·Î ¹Ù²Ù¾î º¸¸é
; »ó¼öµéÀÇ ¿¬»êÀº ÀÌÇظ¦ µ½±âÀ§ÇÑ ÀÇ»ç ÄÚµåÀÓ
; ½ÇÁ¦·Î´Â µ¡¼À°ú °ö¼ÀÀÌ ¿Ï·áµÈ ÃÖÁ¾ »ó¼ö°ªÀÌ ¿Í¾ß ÇÕ´Ï´Ù.
LDR R0, =
(0x42000000 + (0x4001180C-0x40000000)*32 + 3*4))
MOV R2, #1
STR R2, [R0]
Bit BandingÀÌ Áö¿øµÇÁö ¾Ê´Â ½Ã½ºÅÛ¿¡¼ÀÇ "LDR, ORR, STR" 3°³ÀÇ ¸í·É¾î¸¦ »ç¿ëÇؼ ±¸Çö µÇ¾ú´ø ³»¿ëÀÌ "STR" ¸í·É¾î 1°³¸¦ ÀÌ¿ëÇؼ °°Àº ÀÛ¾÷À» ÇÏ´Â ÄÚµå·Î ¹Ù²Ü¼ö°¡ ÀÖ½À´Ï´Ù. ÀÌ·¯ÇÑ Æ¯Â¡Àº ¼öÇà ¼Óµµ¿Í ÄÚµå ÁýÀûµµ¿¡¼µµ À¯¸®Çϸç ÀÌ·¯ÇÑ ±â´ÉÀÌ ÁÖ´Â °¡Àå Áß¿äÇÑ Æ¯Â¡Àº ¹Ù·Î Atomic Operation ÀÌ °¡´É ÇÏ´Ù´Â °ÍÀÔ´Ï´Ù. Atomic Operation À̶ó´Â °ÍÀº ´õ ÀÌ»ó ÂÉ°³ÁöÁö ¾Ê´Â Áï, 1°³ÀÇ ¸í·ÉÀ¸·Î ±â´ÉÀÌ ¼öÇàµÇ¾î ¸í·É¾î ¼öÇà µµÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇÏÁö ¾Ê´Â°ÍÀ» À̾߱â ÇÕ´Ï´Ù. ¿©·¯°¡Áö º¹ÀâÇÑ ÀÎÅÍ·´Æ®°¡ ¸¹Àº ½Ã½ºÅÛ¿¡¼ Atomic OperationÀÌ µÈ´Ù´Â °ÍÀº Àü¿ª µ¥ÀÌÅÍ È¤Àº PeripheralÀÇ SFR(Special Function Register)µî¿¡ Á¢±ÙÇÒ¶§ ÀÎÅÍ·´Æ®¿¡ ÀÇÇؼ µ¥ÀÌÅÍ Ã³¸® ¸í·ÉÀÌ Ä§ÇØ ´çÇÏÁö ¾Ê´Â °ÍÀ» º¸Àå ÇÕ´Ï´Ù. Atomic OperationÀÌ ¾Æ´Ñ ¸í·É¾î·Î 2°³ ÀÌ»óÀÇ ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾ¿¡¼ °øÀ¯·Î »ç¿ëÇÏ´Â Àü¿ª µ¥ÀÌÅ͵îÀ» ó¸®Çϱâ À§Çؼ´Â ÀϹÝÀûÀ¸·Î µ¥ÀÌÅÍ Ã³¸®Àü¿¡ ÀÎÅÍ·´Æ®¸¦ Disable½ÃÅ°°í µ¥ÀÌÅÍ Ã³¸®°¡ ³¡³ª¸é ´Ù½Ã ÀÎÅÍ·´Æ®¸¦ Enable ½ÃÅ°´Â ¹æ½ÄÀ¸·Î ó¸® ÇÕ´Ï´Ù. Âü°í·Î ARM ¿¡¼ ÀÎÅÍ·´Æ®´Â ¸í·É¾î ¹Ù¿î´õ¸®(Boundary) ¿¡¼ ¹ß»ýÇÕ´Ï´Ù. ¸í·É¾î Boundary¶ó´Â °ÍÀº ¸í·É¾î¿Í ¸í·É¾î »çÀ̸¦ À̾߱â ÇÕ´Ï´Ù. Cortex-M3 ¿¡¼ LDM, STM(PUSH, POP)µî Multiple µ¥ÀÌÅÍó¸® ¸í·ÉÀ» Á¦¿ÜÇÏ¸é ´ÜÀÏ ¸í·É¾î ¼öÇàÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÀ» ÇÏ´õ¶óµµ ¸í·É¾î ¼öÇàÀÌ ³¡³ª¸é ÀÎÅÍ·´°¡ ½ÃÀÛ µË´Ï´Ù.
Bit band region°ú Bit band alias ¿µ¿ª°úÀÇ Alias °ü°è¸¦ Á¤±ÔÈµÈ ¼ö½ÄÀ¸·Î Ç¥ÇöÇÏ¸é ¾Æ·¡¿Í °°½À´Ï´Ù.
bit_word_offset = (byte_offset x 32) + (bit_number × 4)
bit_word_addr = bit_band_base + bit_word_offset
0x40000000 ÀÇ 1¹ø ºñÆ®¿¡ ÇØ´çÇÏ´Â Bit Banding ÁÖ¼Ò´Â 0x42000000 + 32*0 + 4*1 ÀÇ ¼ö½ÄÀÌ Àû¿ë µË´Ï´Ù.
¾à°£ º¹ÀâÇÑµí º¸ÀÌÁö¸¸ Àß »ý°¢ÇØ º¸¸é °è»ê½ÄÀ» ÀÌÇØÇÒ ¼ö ÀÖ½À´Ï´Ù.
3.6 System Timer(SysTick)
Cortex-M3 Core ³»ºÎ¿¡ À§Ä¡ÇÑ ½Ã½ºÅÛ Å¸ÀÌ¸Ó ÀÔ´Ï´Ù. 24bit self-reloading down counter À̸ç count°¡ 0ÀÌ µÇ¸é SysTick Interrupt¸¦ ¹ß»ý ½Ãų ¼ö ÀÖ½À´Ï´Ù. ¸ðµç CPU¿¡´Â º¸Åë ŸÀ̸Ӹ¦ 1°³ ÀÌ»óÀº °¡Áö°í ÀÖ½À´Ï´Ù. ÇÏÁö¸¸ SysTickÀÌ ÀÏ¹Ý Å¸ÀÌ¸Ó¿Í ´Ù¸¥Á¡À̶ó¸é Core(Á¤È®È÷´Â NVIC¿¡ Á¸ÀçÇÔ)¿¡ ³»ÀåµÈ ŸÀÌ¸Ó ¶ó´Â °ÍÀÔ´Ï´Ù. ÀÌ·¯ÇÑ Æ¯Â¡Àº Cortex-M3 Core¸¦ »ç¿ëÇÑ ¸ðµç CPU´Â ¸ðµÎ µ¿ÀÏÇÑ System Timer¸¦ °¡Áö°í ÀÖ´Ù´Â °ÍÀÔ´Ï´Ù. ¿¹¸¦ µé¾î RTOS¸¦ Æ÷ÆÃÇÑ´Ù°í ÇßÀ»¶§ ÇʼöÀûÀ¸·Î ÁÖ±âÀûÀΠŸÀÌ¸Ó ÀÎÅÍ·´Æ®°¡ ÇÊ¿äÇѵ¥ Cortex-M3 ÀÌÀüÀÇ ÇÁ·Î¼¼¼¿¡¼ RTOS¸¦ Æ÷ÆÃÀ» ÇÏ´Â °æ¿ì¿¡´Â CoreÀÚü¿¡ Timer°¡ ¾ø±â ¶§¹®¿¡ Vendor SpecificÇÑ Timer ¸¦ »ç¿ëÇÏ°Ô µË´Ï´Ù. ¾î¶² °³¹ßÀÚ´Â Timer0¸¦ »ç¿ëÇÒ¼öµµ ÀÖ°í ´Ù¸¥ °³¹ßÀÚ´Â Timer1À» »ç¿ëÇؼ Æ÷ÆÃÀ» ÇÒ¼ö ÀÖ½À´Ï´Ù. ÀÌ·¸°Ô µÇ¸é °°Àº ARM Core¸¦ »ç¿ëÇß´Ù°í ÇÏ´õ¶óµµ Processorµé °£ÀÇ SW Æ÷ÆÃÀÌ ´Þ¶óÁ®¾ß ÇÕ´Ï´Ù. ÇÏÁö¸¸ Cortex-M3 Core¸¦ »ç¿ëÇؼ RTOS Æ÷ÆÃÀ» ÇÑ´Ù¸é ´ç¿¬È÷ Core¿¡ ³»ÀåµÈ °øÅëÀûÀÎ TimerÀÎ System Timer¸¦ »ç¿ëÇØ¾ß °ÚÁö¿ä. System Timer¿¡ ´ëÇÑ Á»´õ »ó¼¼ÇÑ ³»¿ë°ú »ç¿ë¹ýÀº Cortex-M3 Applicaiton °Á¿¡¼ Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù.
4. Nested Vectored Interrupt Controller
4.1 NVIC
Cortex-M3ÀÇ °¡Àå Áß¿äÇÑ Æ¯Â¡ÁßÀÇ Çϳª ÀÔ´Ï´Ù. Cortex-M3 ÀÌÀüÀÇ ÀüÅëÀûÀÎ ARM ¿¡¼´Â ÀÎÅÍ·´Æ® ÄÁÆ®·Ñ·¯°¡ ARM CoreÀÇ ¿ÜºÎ¿¡ À§Ä¡ÇØ ÀÖ¾ú½À´Ï´Ù. ¾Æ·¡ ±×¸²Àº ARM9 S3C2440 CPU ÀÇ ºí·°µµ ÀÔ´Ï´Ù. ÀÚ¼¼È÷ º¸¸é Interrupt Controller °¡ CPUÀÇ Peripheral ·Î ±¸ÇöÀÌ µÇ¾î ÀÖ½À´Ï´Ù.
ÇÏÁö¸¸ Cortex-M3 ¿¡¼´Â Interrupt Controller °¡ ARM Core ÀÇ ³»ºÎ ÀÚ¿øÀ¸·Î µé¾î¿Í ÀÖ½À´Ï´Ù. ±×°Íµµ Nested Vectored Interrupt Controller ¶ó´Â »õ·Î¿î À̸§À» ´Þ°í ¸»ÀÔ´Ï´Ù. ¾Æ·¡ Á¡¼± ¹Ú½º ºÎºÐÀÌ CM3Core(Cortex-M3 Core) ¿¡ ³»ÀåµÈ NVIC(Nested Vectored Interrupt Controller) ÀÔ´Ï´Ù. Âü°í·Î ¾Æ·¡ ºí·°µµ´Â STM32F103x ½Ã¸®Áî CPU ÀÇ ºí·°µµ ÀÔ´Ï´Ù.
CM3Core ºÎºÐÀº Vendor Defined Specific ºÎºÐÀÌ ¾Æ´Ï¶ó Cortex-M3 CPU µéÀÇ °øÅë »ç¾ç ÀÔ´Ï´Ù. NVIC´Â CM3Core ³»ºÎ¿¡ À§Ä¡ÇØ ÀÖ½À´Ï´Ù. À§¿¡¼ ¼³¸íÇß´ø Register(R0 ~ R15), Special Register(xPSR, CONTROL) µîÀº ¸ðµÎ CM3Core ³»ºÎ¿¡ À§Ä¡ÇØ ÀÖ´Â °ÍÀÔ´Ï´Ù. Nested Vectored Interrupt Controller ¶ó°í ÇÏ¿´´Âµ¥ ¿ì¼± Vectored ¶ó´Â ¿ë¾îºÎÅÍ ¼³¸íÀ» Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù.
ÀüÅëÀûÀÎ ARMÀÇ ÀÎÅÍ·´Æ® ºí·°µµ¸¦ °£·«ÇÏ°Ô Ç¥ÇöÇØ º¸¾Ò½À´Ï´Ù.
[ ÀüÅëÀûÀÎ ARM CPUÀÇ °£·«ÇÑ
ÀÎÅÍ·´Æ® ±¸¼ºµµ ]
ÀüÅëÀûÀÎ ARM¿¡¼´Â ÀÎÅÍ·´Æ® ÄÁÆ®·Ñ·¯°¡ ARM CoreÀÇ ¿ÜºÎ¿¡ À§Ä¡ÇØ ÀÖÀ¸¸ç CPUÀÇ ¿©·¯°³ÀÇ PeripheralµéÀÌ 1°³ÀÇ IRQ, FIQ ¿¡ ¿¬°áÀÌ µÇ¾î ÀÖ½À´Ï´Ù. ÀÌ·¯ÇÑ ÀÌÀ¯·Î ¸¸¾à¿¡ EINT0 ÀÎÅÍ·´Æ®°¡ ¹ß»ýÀ» ÇÏ¿´´Ù¸é CPU ¿ÜºÎ¿¡ ÀÖ´Â ÀÎÅÍ·´Æ® ÄÁÆ®·Ñ·¯¸¦ ÅëÇؼ ARM Core ¿¡ Interrupt Request °¡ Àü´ÞµÇ°Ô µÇ´Âµ¥ ARM Core ÀÔÀå¿¡¼ º¸¸é EINT0 ÀÌ ¹ß»ýÇÏ¿´´ÂÁö EINT1 ÀÌ ¹ß»ýÇÑ °ÍÀÎÁö ¾Ë¼ö ÀÖ´Â ¹æ¹ýÀÌ ¾ø½À´Ï´Ù. ARM Core ¿¡¼ ¾Ë¼ö ÀÖ´Â ¹æ¹ýÀº S/W ÀûÀ¸·Î ARM Core ¿ÜºÎ¿¡ ÀÖ´Â Interrupt Controller ÀÇ SFR ·¹Áö½ºÅÍ¿¡ Á¢±ÙÇÏ¿© INTOFFSET(ÇöÀç ¹ß»ýÇÑ ÀÎÅÍ·´Æ® ¹øÈ£°¡ ÀúÀåµÇ¾î ÀÖ´Â ·¹Áö½ºÅÍ) À» Àоî¿Í¼ ÀÎÅÍ·´Æ® ¹øÈ£¸¦ È®ÀÎÇÏ°í Àû´çÇÑ ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀ¸·Î ºÐ±â¸¦ ÇÏ´Â °ÍÀÔ´Ï´Ù. ÇÏÁö¸¸ Cortex-M3 ¿¡¼´Â À̰ͺ¸´Ù ÈξÀ È¿À²ÀûÀÎ ¹æ¹ýÀ¸·Î ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀ¸·Î ºÐ±â¸¦ ÇÕ´Ï´Ù.
Cortex-M3 ¿¡¼´Â EINT0 ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇϸé ÀÌ¹Ì Á¤ÇØÁø Interrupt Vector Table ¿¡ ÀÖ´Â ÁÖ¼Ò·Î ¹Ù·Î ºÐ±â Çϸç À̶§ Special Register Áß IPSR ¿¡ ¹ß»ýÇÑ ÀÎÅÍ·´Æ® ¹øÈ£°¡ ÀúÀåÀÌ µË´Ï´Ù. ¹°·Ð ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀ¸·Î ºÐ±â ÇϱâÀü¿¡ ¹®¸Æ º¸Á¸À» À§Çؼ H/W ÀûÀ¸·Î {R0-R3,R12,LR,PC,xPSR} ·¹Áö½ºÅ͵éÀÌ Stack¿¡ ÀúÀåÀÌ µÇ¾ú´Ù°¡ ISR ¼ºñ½º ·çƾÀÌ ³¡³ª¸é ´Ù½Ã H/W ÀûÀ¸·Î Stack ¿¡¼ ·¹Áö½ºÅÍ·Î º¹¿øÀÌ µË´Ï´Ù. ÀüÅëÀûÀÎ ARM¿¡¼ ¹®¸Æ º¸Á¸Àº S/W ÀûÀ¸·Î °³¹ßÀÚÀÇ ¸òÀ̾ú½À´Ï´Ù. R0-R3, R12 ¸¦ Stack¿¡ ÀúÀåÇÏ´Â ÀÌÀ¯´Â ¾Õ¿¡¼ ¼³¸íÇßµíÀÌ Scratch Register µé À̱⠶§¹®ÀÔ´Ï´Ù. Cortex-M3 ¿¡¼ ExceptionÀÇ Á¾·ù´Â ÃÖ´ë 256°³±îÁö Á¸Àç ÇÒ¼ö ÀÖ°í 0 ~ 15 ±îÁö´Â Cortex-M3 Internal Exception ÀÌ°í 16¹ø ºÎÅÍ ³ª¸ÓÁö 240°³´Â Core ¿ÜºÎ Exception ÀÔ´Ï´Ù. Exception Vector 0 ~ 15¹ø ±îÁö´Â Cortex-M3 Core¸¦ »ç¿ëÇÏ´Â ¸ðµç CPU´Â µ¿ÀÏÇϸç 16 ~ 254 ±îÁö´Â Vendor Specific »ç¾ç ÀÔ´Ï´Ù. Áï CPU ¸¶´Ù ´Ù¸¦¼ö ÀÖ´Ù´Â À̾߱â ÀÔ´Ï´Ù.
[ Cortex-M3 Vector Table ]
Vectored ¶ó´Â ¸»Àº 0 ~ 255 ±îÁöÀÇ Exception Vector ÀÇ ÁÖ¼Ò°¡ ÀÌ¹Ì Á¤ÇØÁ® ÀÖ´Ù´Â ¸»ÀÔ´Ï´Ù. ±×·¯¹Ç·Î Exception ÀÌ ¹ß»ý ÇßÀ»¶§ ¾î¶² Exception ÀÌ ¹ß»ýÇß´ÂÁö ¿©ºÎ¿¡ »ó°ü¾øÀÌ Á¤ÇØÁø Vector TableÀÇ ÁÖ¼Ò¿¡ ÀÖ´Â ³»¿ëÀÇ Address ·Î ¹Ù·Î Exception ºÐ±â¸¦ ÇÒ¼ö ÀÖ½À´Ï´Ù.
[ STM32F10x Exception Vector Table ]
À§ÀÇ ±×¸²Àº STM32F10x ½Ã¸®ÁîÀÇ Exception Vector Table ÀÔ´Ï´Ù. Cortex-M3 ¿ÜºÎ ÀÎÅÍ·´Æ® º¤ÅÍÀÇ ÁÖ¼Ò°¡ 0x0000_0040 ºÎÅÍ ½ÃÀÛÇÏ°í Àֳ׿ä. Reset½Ã¿¡ Vector TableÀÇ Offset ÁÖ¼Ò´Â 0x0 ÀÌÁö¸¸ Exception Vector TableÀÇ ½ÃÀÛ ÁÖ¼Ò´Â Vector Table Offset Register ¸¦ ¼öÁ¤ÇÏ¸é ¿Å±æ¼ö ÀÖ½À´Ï´Ù.
TBLBASE ÀÇ °ªÀ» "1" ·Î ¼öÁ¤À» Çϸé Vector TableÀ» RAM ¿¡ À§Ä¡ ½Ãų¼öµµ ÀÖ½À´Ï´Ù. ±×¸®°í TBLOFF ¿¡ µû¶ó¼ Vector Table ÀÇ ÁÖ¼Ò¸¦ Á¤ÇØÁÙ ¼ö ÀÖ½À´Ï´Ù.
´ÙÀ½À¸·Î Nested ¶ó´Â ¿ë¾î¸¦ »ìÆì º¸Áö¿ä. Nested ¶ó´Â °ÍÀº »çÀüÀûÀÎ ¿ë¾î·Î´Â "ÁßøµÇ¾î ÀÖ´Â" ¹¹ ÀÌ·¯ÇÑ ÀÇ¹Ì ÀÔ´Ï´Ù. Cortex-M3 ¿¡¼´Â ÀÎÅÍ·´Æ® ¼öÇàÁß¿¡ ¿ì¼±¼øÀ§°¡ ³ôÀº ÀÎÅÍ·´Æ®°¡ ¹ß»ýÀ» Çϸé ÇöÀç ¼öÇàÁßÀÎ ÀÎÅÍ·´Æ®¸¦ Àá½Ã Áß´ÜÇÏ°í ³ªÁß¿¡ ¹ß»ýÇÑ ¿ì¼±¼øÀ§°¡ ³ôÀº ÀÎÅÍ·´Æ®¸¦ ¸ÕÀú ¼öÇàÇÑ ÀÌÈÄ¿¡ Àá½Ã Áß´Ü µÇ¾ú´ø ÀÎÅÍ·´Æ® ·çƾÀ¸·Î º¹±ÍÇÏ¿© ¼öÇàÀ» ¸¶Ä¡°í Normal ·çƾÀ¸·Î º¹±Í¸¦ ÇÕ´Ï´Ù. ÀÌ·¯ÇÑ °æ¿ì¸¦ ÀÎÅÍ·´Æ®°¡ ÁßøµÇ¾ú´Ù°í ÇÕ´Ï´Ù. ÀüÅëÀûÀÎ ARM ¿¡¼ IRQ³¢¸®´Â ÁßøµÇ´Â °æ¿ì°¡ ¾ø½À´Ï´Ù. ¸ðµç IRQ´Â ¿ì¼±¼øÀ§°¡ °°±â ¶§¹®¿¡ ÁßøÀÌ µÇÁö¾Ê°í IRQ ¼öÇàÁß¿¡ ´Ù½Ã IRQ°¡ ¹ß»ýÀ» ÇÏ¸é ³ªÁß¿¡ ¹ß»ýÇÑ ÀÎÅÍ·´Æ®´Â Àá½Ã Pending»óÅ¿¡ µé¾î °¬´Ù°¡ ÇöÀç ¼öÇàÁßÀÎ ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀÌ Á¾·áµÇ¸é(¾ö¹ÐÈ÷ ¸»Çϸé ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾ¾È¿¡¼ Pending Clear¸¦ ÇÏ´Â ½ÃÁ¡¿¡¼) Àá½Ã Pending µÇ¾ú´ø ÀÎÅÍ·´Æ®°¡ ½ÃÀÛ µË´Ï´Ù. ÀÎÅÍ·´Æ®°¡ ÁßøµÇ´Â °æ¿ì´Â IRQ ¼öÇà µµÁß¿¡ FIQ(Fast IRQ) °¡ ¹ß»ýÇÏ´Â °æ¿ì¿¡¸¸ ÁßøÀÌ µË´Ï´Ù. ÀÎÅÍ·´Æ®°¡ ÁßøÀÌ µÇ·Á¸é ÀÎÅÍ·´Æ®¸¶´Ù ¿ì¼±¼øÀ§°¡ ´Þ¶ó¾ß Çϴµ¥ Cortex-M3 ¿¡¼´Â ÃÖ´ë 255 ´Ü°èÀÇ ¿ì¼±¼øÀ§ ·¹º§À» Á¤ÇØ ÁÙ¼ö°¡ ÀÖ½À´Ï´Ù. ÀÎÅÍ·´Æ® ¿ì¼±¼øÀ§ ´Ü°è´Â AIRCR(Application Interrupt and Reset Control Register) ¿¡ ÀÇÇؼ Á¤ÇØ ÁÙ¼ö ÀÖ½À´Ï´Ù.
PRIGROUP ºÎºÐ¿¡ 0 ~ 7 »çÀÌÀÇ °ªÀ» Write ÇÒ¼ö ÀÖ½À´Ï´Ù. PRIGROUP ¿¡ ÀÇÇؼ Goup Priority(Pre-emption)°ú Sub PriorityÀÇ °æ°è¸¦ ³ª´©¾î ÁÙ¼ö ÀÖ½À´Ï´Ù.
[ Cortex-M3 ¿¡¼ÀÇ ¿ì¼±¼øÀ§ ±×·ì ]
STM32F10x ½Ã¸®Áî¿¡¼´Â 0 ~ 7 ºñÆ®Áß¿¡¼ 4ºñÆ®(»óÀ§ 4 ~ 7 ºñÆ®) ¸¸ »ç¿ëÇÏ¿© Priority°¡ ±¸ÇöµÇ¾î ÀÖ½À´Ï´Ù. ÇÏÀ§ 4ºñÆ®´Â H/WÀûÀ¸·Î "0" À¸·Î Mapping µÇ¾î ÀÖ½À´Ï´Ù. STM32F10x ½Ã¸®Áî¿¡¼ PRIGROUPÀÇ °ª¿¡ ÀÇÇؼ Á¤ÇØÁö´Â Priority ´Ü°è¸¦ Ç¥·Î ³ªÅ¸³» º¸¾Ò½À´Ï´Ù.
À§ÀÇ Ç¥¿¡¼ PRIGROUPÀÇ °ªÀÌ 0b100(4) °¡ µÇ¸é Group Priorities·Î 8´Ü°è, Sub Priorities ·Î 2´Ü°è ±îÁö ·¹º§À» Á¤ÇÒ ¼ö ÀÖ½À´Ï´Ù. PRIGROUP°ª¿¡ ÀÇÇؼ Group Priorities¿Í Sub Priorities ÀÇ ·¹º§À» µ¿ÀûÀ¸·Î Á¶Á¤ ÇÒ¼ö ÀÖ´Â °ÍÀÔ´Ï´Ù. Group Priorities¿Í Sub Priorities ¿¡´Â Â÷ÀÌÁ¡ÀÌ ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î PRIGROUPÀÇ °ªÀÌ 0b100(4) ·Î ÇÏ°í EINT0, EINT1 ¿¡ ´ëÇؼ ¾Æ·¡ ±×¸²°ú °°ÀÌ ¿ì¼±¼øÀ§ ·¹º§À» Á¤ÀÇÇØ ÁÖ¾ú´Ù°í °¡Á¤ÇØ º¾½Ã´Ù.
STM32F10x ½Ã¸®Áî¿¡¼´Â »óÀ§ 4bit¸¸ ÀÌ¿ëÇÏ¿© ÀÎÅÍ·´Æ® Priority¸¦ ±¸Çö ÇÏ¿´´Ù°í ÇÏ¿´½À´Ï´Ù. PRIGROUPÀÌ 0b100(0x4) ÀÏ °æ¿ì¿¡ ¾Æ·¡ ±×¸²°ú °°ÀÌ Group Priority·Î 3bit, Sub Priority·Î 1bit ¸¦ ÀÌ¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ±×·¯¹Ç·Î Group Priority °ª¿¡´Â 0x0 ~ 0x7 »çÀÌÀÇ °ª, Sub Priority ¿¡¼´Â 0x0 ~ 0x1 ÀÇ °ªÀÌ ¿Ã¼ö ÀÖ½À´Ï´Ù.
EINT0 ÀÇ ÀÎÅÍ·´Æ®°¡ ¸ÕÀú ¹ß»ýÇÏ¿© ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾÀÌ ½ÇÇàÁß¿¡ ÀÖÀ»´ë EINT1 ÀÌ ¹ß»ýÇϸé EINT0ÀÇ Group Priority°¡ ³ô±â ¶§¹®¿¡ EINT0 °¡ ³¡³¯¶§ ±îÁö EINT1Àº Pending »óÅ¿¡ ÀÖ´Ù°¡ EINT0ÀÌ ³¡³ª¸é EINT1 ÀÌ ¼öÇàÀÌ µË´Ï´Ù. ±×·¯¸é ¹Ý´ë·Î EINT1ÀÌ ¸ÕÀú ¹ß»ýÇÏ¿© ÀÎÅÍ·´Æ® ¼ºñ½º ·çƾ ½Ç»ýÁß¿¡ EINT0°¡ ³ªÁß¿¡ ¹ß»ýÇÏ¸é ¾î¶»°Ô µÉ±î¿ä ? ÀÌ °æ¿ì¿¡´Â EINT0ÀÇ Group Priority°¡ ³ô±â ¶§¹®¿¡ EINT1 ¼öÇàÀ» Àá½Ã Áß´ÜÇÏ°í EINT0 ¸¦ ¼öÇàÇÑ ÀÌÈÄ¿¡ ÁߴܵǾú´ø EINT1ÀÌ ¼öÇàÀÌ µË´Ï´Ù. ¿©±â¼ ¾Ë¼ö ÀÖ´Â °ÍÀº Sub Priority¿Í´Â »ó°ü¾øÀÌ Group Priority¿¡ ÀÇÇؼ ÀÎÅÍ·´Æ®ÀÇ ¼±Á¡ ¿ì¼±¼øÀ§°¡ ´Þ¶ó Áý´Ï´Ù. ±×·¸´Ù¸é Sub Priority´Â ¾î¶² ¿ëµµ·Î »ç¿ëÀÌ µÉ±î¿ä ? EINT0, EINT1ÀÇ Group Priority ÀÇ °ªÀÌ °°Àº °æ¿ì µ¿½Ã¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇϸé Sub Priority°¡ ³ôÀº EINT1ÀÌ ¸ÕÀú ¼öÇàÀÌ ¿Ï·á µÇ°í ³ª¸é EINT0°¡ ³ªÁß¿¡ ¼öÇàÀÌ µË´Ï´Ù.
ExceptionÀÌ ¹ß»ýÇÏ¿© Exception Handler ·çƾÀÌ È£ÃâµÇ°í ´Ù½Ã ¿ø·¡ÀÇ ·çƾÀ¸·Î º¹±Í ÇÒ¶§±îÁöÀÇ È帧À» ±×¸²À¸·Î Ç¥ÇöÇØ º¸¾Ò½À´Ï´Ù.
´ÙÀ½ Chapter¿¡¼´Â ÀüÅëÀûÀÎ ARMÀÇ Interrupt Response¿¡ ºñÇؼ Cortex-M3 ¿¡¼ ¾ó¸¶³ª ÁÁ¾ÆÁ³´ÂÁö »ìÆì º¸°Ú½À´Ï´Ù.
4.2 Interrupt Response
(1) Tail Chaining
À§ÀÇ ±×¸²À» º¸¸é ÀüÅëÀûÀÎ ARM¿¡¼´Â IRQ1ÀÌ IRQ2º¸´Ù ¿ì¼±¼øÀ§°¡ ³ô°í µ¿½Ã¿¡ ¹ß»ý ÇßÀ» °æ¿ì¿¡ IRQ1ÀÌ ¸ÕÀú ¼öÇàÀÌ ³¡³ª°í IRQ2°¡ ¼öÇàÀÌ µË´Ï´Ù. ÀÌ °úÁ¤¿¡¼ ´ç¿¬È÷ ¹®¸Æ º¸Á¸À» À§Çؼ ISR1·çƾÀ¸·Î ºÐ±âÇϱâ Àü¿¡ {R0-R3, R12, LR, PC} ·¹Áö½ºÅ͵îÀ» S/W ÀûÀ¸·Î PUSHÇÏ°í ISR1 ¼ºñ½º ·çƾÀÌ ³¡³¯¶§ POPÀ» ÇÕ´Ï´Ù. ±×¸®°í ´Ù½Ã ISR2 ·çƾÀ¸·Î ºÐ±âÇϱâ Àü¿¡ PUSH¸¦ ÇÏ°í ISR2 ·çƾÀÌ ³¡³¯¶§ POPÀ» ÇÏ°Ô µË´Ï´Ù. ¿©±â¼ »ç½Ç ISR1 ¿¡¼ ISR2 ·çƾÀ¸·Î ¿¬°áµÉ¶§ Áß°£¿¡ ÀÖ´Â POP, PUSH´Â ÇÏÁö ¾Ê¾Æµµ µÇ´Â ºÒÇÊ¿äÇÑ µ¿ÀÛ ÀÔ´Ï´Ù. ¿Ö³ª¸Ï¸é ÀÌ °úÁ¤¿¡¼ POP ÇÏ´Â ·¹Áö½ºÅ͵éÀº ISR2 ·çƾÀÌ ³¡³ª°í ¼öÇàµÇ´Â POP°ú, PUSH ÇÏ´Â ·¹Áö½ºÅ͵éÀº ISR1 ½ÃÀÛÀü¿¡ PUSH µÇ´Â ·¹Áö½ºÅ͵é°ú µ¿ÀÏÇϱ⠶§¹®ÀÔ´Ï´Ù. Cortex-M3 ¿¡¼´Â Áߺ¹µÇ´Â Áß°£ ºÎºÐÀÇ POP, PUSH¸¦ »ý·«ÇÏ°í ISR1 ·çƾÀÌ ³¡³ª¸é 6Cycle¿¡ ÇØ´çÇÏ´Â Tail-Chaining ÀÌ ¼öÇàµÈ ÀÌÈÄ¿¡ ¹Ù·Î ISR2 ·çƾÀ¸·Î ºÐ±â¸¦ ÇÕ´Ï´Ù. Âü È¿À² ÀûÀÌÁÒ.. Tail-Chaining ºÎºÐ¿¡¼ 6Cycle µ¿¾È¿¡ ½ÇÁ¦ÀûÀ¸·Î´Â ÇÏ´Â ÀÏÀº Vector Table ¿¡¼ ISR2ÀÇ ½ÃÀÛÁÖ¼Ò¸¦ FetechÇØ¿À´Â ÀÛ¾÷À» ÇÕ´Ï´Ù.
(2) Preemption
À§ÀÇ °æ¿ì´Â ISR1 ¼ºñ½º ·çƾ ¼öÇàÀ» ³¡³»°í ¹®¸Æ º¸Á¸À» À§Çؼ POPÀ» ¼öÇàÇÏ°í ÀÖ´Â µµÁß¿¡ IRQ2°¡ ¹ß»ýÇÏ´Â °æ¿ì ÀÔ´Ï´Ù. ÀüÅëÀûÀÎ ARM¿¡¼´Â Multiple Load ¸í·É¾î ¼öÇàÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇÒ¼ö ¾øÀ¸¹Ç·Î POPÀ» ¸ðµÎ ¼öÇàÇÏ°í ´Ù½Ã ISR2¸¦ À§ÇÑ PUSH·çƾÀ¸·Î ÁøÀÔÇÕ´Ï´Ù. ÇÏÁö¸¸ Cortex-M3 ¿¡¼´Â POP(LDMFD) ¼öÇàÁß¿¡µµ ÀÎÅÍ·´Æ®°¡ °¡´ÉÇϱ⠶§¹®¿¡ ISR1°ú ISR2 »çÀÌ¿¡ Tail-Chaining ÀÌ ¹ß»ýÇϸé 6Cycle ÀÌÈÄ¿¡ ISR2 ·çƾÀÌ ¼öÇàµÉ¼ö ÀÖ½À´Ï´Ù.
(3) Late Arriving
ÀüÅëÀûÀÎ ARM¿¡¼ IRQ2(IRQ) ¼öÇàÀ» À§Çؼ PUSH µµÁß¿¡ IRQ1 º¸´Ù ¿ì¼±¼øÀ§°¡ ³ôÀº ÀÎÅÍ·´Æ®(FIQ)°¡ ¹ß»ýÇϸé ISR2À» À§ÇÑ PUSHÀÛ¾÷ÀÌ ³¡³ªÀÚ ¸¶ÀÚ ISR1À» À§ÇÑ PUSH ÀÛ¾÷ÀÌ ÁøÇàÀÌ µË´Ï´Ù. Cortex-M3¿¡¼´Â ISR2¸¦ À§ÇÑ PUSHÀÛ¾÷Áß¿¡ IRQ2º¸´Ù ¿ì¼±¼øÀ§°¡ ³ôÀº IRQ1ÀÌ ¹ß»ýÇÏ°Ô µÇ¸é IRQ1¸¦ À§ÇÑ PUSHÀÛ¾÷Àº ÁøÇàµÇÁö ¾Ê°í ¹Ù·Î ¿ì¼±¼øÀ§°¡ ³ôÀº ISR1ÀÌ ¼öÇàµÇ°í Tail-Chaining ÀÌÈÄ¿¡ ISR2¸¦ ¼öÇàÇÏ°Ô µË´Ï´Ù.
¿©±â±îÁö Cortex-M3¿¡ ´ëÇÑ ±¸Á¶´Â ¾î´À Á¤µµ Á¤¸®°¡ µÈ°Í °°½À´Ï´Ù. ³õÄ£ ºÎºÐÀÌ ÀÖ´Ù¸é ÀÌÈÄ¿¡ ÁøÇàµÈ Cortex-M3 Application¿¡¼ ¿¹Á¦¸¦ ÅëÇؼ ´Ù½Ã ¾ð±Þ Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù. Cortex-M3 Application¿¡¼´Â STM32F103VC Dragon °³¹ßº¸µå¸¦ °¡Áö°í Cortex-M3 Architecture¿¡¼ ÀÌ·ÐÀ¸·Î ´Ù·ç¾ú´ø ³»¿ëµéÀ» ½Ç½ÀÀ» ÅëÇؼ Çϳª¾¿ °øºÎÇØ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. ½ÇÁ¦ ¿¹Á¦¿¡¼ ÄÄÆÄÀÏ·¯´Â IAR 5.4 Evaluation ¹öÁ¯À» »ç¿ëÇÒ °ÍÀÌ°í Emulator·Î´Â ARM-JTAG Light Edition À» ÀÌ¿ëÇÒ °ÍÀÔ´Ï´Ù. Âü°í·Î ¾Æ·¡ ±×¸²Àº ¿ì¸®°¡ Cortex-M3 Application ¿¡¼ »ç¿ëÇÏ°ÔµÉ °³¹ßº¸µåÀÇ »ç¾ç ÀÔ´Ï´Ù.
Âü°í·Î ´ÙÀ½ °ÁÂÀÎ Cortex Application¿¡¼ ÁøÇàÇÒ ¸ñÂ÷ ÀÔ´Ï´Ù.
1. STM32F10x Overview
1.1 STM32F10x Block Diagram
1.2 STM32F10x Memory Map
1.3 STM32F10x Boot Modes
1.4 STM32F10x GPIO
2. STM32F103VC Dragon°³¹ßº¸µå ¼Ò°³
2.1 Features
3. Examples
3.1 GPIO Output without SDK
3.2 GPIO Output with SDK
3.3 GPIO Output with BitBand
3.4 GPIO Input - Polling
3.5 GPIO Input - Interrupt
3.6 General Purpose Timer
3.7 Systick - Delay
3.8 Systick - Interrupt
3.9 USART - Polling
3.10 USART - Interrupt
3.11 USART - Name Card
3.12 Interrupt Priority1
3.13 Interrupt Priority2
3.14 Power Management - Sleep
3.15 Power Management - Stop
3.16 Power Management - StandBy
3.17 Mode Privilege
3.18 USART Monitor Program
|