STR71xF Reference Manual
STR71xF Reference Manual
Microcontroller
Reference Manual
Rev. 7
November 2005
1
REFERENCE MANUAL
1 INTRODUCTION
This Reference Manual provides complete information for application developers on how to
use the STR71x Microcontroller memory and peripherals.
The STR71xF is a family of microcontrollers with different memory sizes, packages and
peripherals.
For Ordering Information, Mechanical and Electrical Device Characteristics please refer to the
STR71x datasheet.
For information on programming, erasing and protection of the internal Flash memory please
refer to the STR7 Flash Programming Reference Manual
For information on the ARM7TDMI® core please refer to the ARM7TDMI® Technical
Reference Manual.
Related documents:
Available from www.arm.com:
STR71x Datasheet
The above is a selected list only, a full list STR71x application notes can be viewed at
http://www.st.com.
Rev. 7
2/349
1
Table of Contents
3.5 Low Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.5.1 Slow Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.5.2 WFI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.5.3 LPWFI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.5.4 Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.5.5 Standby Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.5.5.1 Software Standby Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.5.5.2 Hardware Standby Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.5.5.3 Wakeup / RTC Alarm Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.6 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.6.1 Clock Control Register (RCCU_ CCR) . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.6.2 Clock Flag Register (RCCU_CFR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.6.3 PLL Configuration Register (RCCU_PLL1CR) . . . . . . . . . . . . . . . . . . . 57
3.6.4 Peripheral Enable Register (RCCU_PER) . . . . . . . . . . . . . . . . . . . . . . . 58
3.6.5 System Mode Register (RCCU_SMR) . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.6.6 MCLK Divider Control (PCU_MDIVR) . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.6.7 Peripheral Clock Divider Control Register (PCU_PDIVR) . . . . . . . . . . . 61
3.6.8 Peripheral Reset Control Register (PCU_PRSTR) . . . . . . . . . . . . . . . . 62
3.6.8.1 PLL2 Control Register (PCU_PLL2CR) . . . . . . . . . . . . . . . . . . . . 62
3.6.9 Boot Configuration Register (PCU_BOOTCR) . . . . . . . . . . . . . . . . . . . 64
3.6.10 Power Control Register (PCU_PWRCR) . . . . . . . . . . . . . . . . . . . . . . . . 66
3.7 PRCCU Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4 I/O PORTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.1 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.1.1 Input Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.1.2 Input Pull Up/Pull Down Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.1.3 Output Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.1.4 Alternate Function Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.1.5 High impedance-Analog Input Configuration . . . . . . . . . . . . . . . . . . . . . 76
4.2 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
4.2.1 I/O Port Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5 INTERRUPTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.1 Interrupt latency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.2 Enhanced Interrupt Controller (EIC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.2.1 IRQ mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.2.1.1 Priority Decoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.2.1.2 Finite State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5.2.1.3 Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5.2.1.4 EIC Interrupt Vectoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.2.1.5 EIC IRQ Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.2.2 FIQ Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
3/349
1
Table of Contents
5.3 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.3.1 Interrupt Control Register (EIC_ICR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.3.2 Current Interrupt Channel Register (EIC_CICR) . . . . . . . . . . . . . . . . . . 90
5.3.3 Current Interrupt Priority Register (EIC_CIPR) . . . . . . . . . . . . . . . . . . . 91
5.3.4 Interrupt Vector Register (EIC_IVR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.3.5 Fast Interrupt Register (EIC_FIR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.3.6 Interrupt Enable Register 0 (EIC_IER0) . . . . . . . . . . . . . . . . . . . . . . . . 95
5.3.7 Interrupt Pending Register 0 (EIC_IPR0) . . . . . . . . . . . . . . . . . . . . . . . 96
5.3.8 Source Interrupt Registers - Channel n (EIC_SIRn) . . . . . . . . . . . . . . . 98
5.3.9 EIC Register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.3.10 Programming considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
5.3.11 Application note . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5.3.11.1 Avoiding LR_sys and r5 register content loss . . . . . . . . . . . . . . 101
5.3.11.2 Hints on calling subroutines from within ISRs . . . . . . . . . . . . . . 102
5.4 External Interrupts (XTI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.4.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.4.2 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.4.2.1 Interrupt Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.4.2.2 Wake-up Mode Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.4.3 Programming Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.4.3.1 Procedure for Entering/Exiting STOP mode . . . . . . . . . . . . . . . 106
5.4.3.2 Simultaneous Setting of Pending Bits . . . . . . . . . . . . . . . . . . . . 106
5.4.3.3 STOP Mode Entry Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5.4.4 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
5.4.4.1 XTI Software Interrupt Register (XTI_SR) . . . . . . . . . . . . . . . . . 109
5.4.4.2 Wake-up Control Register (XTI_CTRL) . . . . . . . . . . . . . . . . . . . 109
5.4.4.3 XTI Mask Register High (XTI_MRH) . . . . . . . . . . . . . . . . . . . . . 111
5.4.4.4 XTI Mask Register Low (XTI_MRL) . . . . . . . . . . . . . . . . . . . . . . 111
5.4.4.5 XTI Trigger Polarity Register High (XTI_TRH) . . . . . . . . . . . . . . 112
5.4.4.6 XTI Trigger Polarity Register Low (XTI_TRL) . . . . . . . . . . . . . . 112
5.4.4.7 XTI Pending Register High (XTI_PRH) . . . . . . . . . . . . . . . . . . . 113
5.4.4.8 XTI Pending Register Low (XTI_PRL) . . . . . . . . . . . . . . . . . . . . 113
5.4.5 XTI Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
6 REAL TIME CLOCK (RTC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.3 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.3.2 Reset procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
349
6.3.3 Free-running mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
6.3.4 Configuration mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
4/349
1
Table of Contents
6.4 Register description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
6.4.1 RTC Control Register High (RTC_CRH) . . . . . . . . . . . . . . . . . . . . . . . 118
6.4.2 RTC Control Register Low (RTC_CRL) . . . . . . . . . . . . . . . . . . . . . . . . 119
6.4.3 RTC Prescaler Load Register High (RTC_PRLH) . . . . . . . . . . . . . . . . 120
6.4.4 RTC Prescaler Load Register Low (RTC_PRLL) . . . . . . . . . . . . . . . . 121
6.4.5 RTC Prescaler Divider Register High (RTC_DIVH) . . . . . . . . . . . . . . . 121
6.4.6 RTC Prescaler Divider Register Low (RTC_DIVL) . . . . . . . . . . . . . . . 122
6.4.7 RTC Counter Register High (RTC_CNTH) . . . . . . . . . . . . . . . . . . . . . 122
6.4.8 RTC Counter Register Low (RTC_CNTL) . . . . . . . . . . . . . . . . . . . . . . 122
6.4.9 RTC Alarm Register High (RTC_ALRH) . . . . . . . . . . . . . . . . . . . . . . . 123
6.4.10 RTC Alarm Register Low (RTC_ALRL) . . . . . . . . . . . . . . . . . . . . . . . . 123
6.5 RTC Register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
7 WATCHDOG TIMER (WDG) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.3 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.3.1 Free-running Timer mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.3.2 Watchdog mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7.4 Register description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7.4.1 WDG Control Register (WDG_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7.4.2 WDG Prescaler Register (WDG_PR) . . . . . . . . . . . . . . . . . . . . . . . . . 127
7.4.3 WDG Preload Value Register (WDG_VR) . . . . . . . . . . . . . . . . . . . . . . 127
7.4.4 WDG Counter Register (WDG_CNT) . . . . . . . . . . . . . . . . . . . . . . . . . 127
7.4.5 WDG Status Register (WDG_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
7.4.6 WDG Mask Register (WDG_MR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
7.4.7 WDG Key Register (WDG_KR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
7.5 WDG Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8 TIMER (TIM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.3 Special Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.4 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.4.1 Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.4.2 External Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
8.4.3 Internal Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
8.4.4 Input Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
8.4.4.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
8.4.5 Output Compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
8.4.5.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
8.4.6 Forced Compare Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.4.7 One Pulse Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
5/349
1
Table of Contents
8.4.7.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.4.8 Pulse Width Modulation Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.4.8.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.4.9 Pulse Width Modulation Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
8.4.9.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
8.5 Interrupt Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
8.5.0.1 Use of interrupt channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
8.6 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
8.6.1 Input Capture A Register (TIMn_ICAR) . . . . . . . . . . . . . . . . . . . . . . . . 147
8.6.2 Input Capture B Register (TIMn_ICBR) . . . . . . . . . . . . . . . . . . . . . . . . 147
8.6.3 Output Compare A Register (TIMn_OCAR) . . . . . . . . . . . . . . . . . . . . 147
8.6.4 Output Compare B Register (TIMn_OCBR) . . . . . . . . . . . . . . . . . . . . 148
8.6.5 Counter Register (TIMn_CNTR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
8.6.6 Control Register 1 (TIMn_CR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
8.6.7 Control Register 2 (TIMn_CR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.6.8 Status Register (TIMn_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
8.7 Timer Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9 CONTROLLER AREA NETWORK (CAN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
9.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
9.3 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
9.4 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9.4.1 Software Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9.4.2 CAN Message Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9.4.3 Disabled Automatic Re-Transmission Mode . . . . . . . . . . . . . . . . . . . . 156
9.5 Test Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.5.1 Silent Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.5.2 Loop Back Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.5.3 Loop Back Combined with Silent Mode . . . . . . . . . . . . . . . . . . . . . . . . 158
9.5.4 Basic Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
9.5.5 Software Control of CAN_TX Pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
9.6 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.6.1 CAN Interface Reset State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
9.6.2 CAN Protocol Related Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
9.6.2.1 CAN Control Register (CAN_CR) . . . . . . . . . . . . . . . . . . . . . . . 161
9.6.2.2 Status Register (CAN_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.6.2.3 Error Counter (CAN_ERR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.6.2.4 Bit Timing Register (CAN_BTR) . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.6.2.5 Test Register (CAN_TESTR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
349
9.6.2.6 BRP Extension Register (CAN_BRPR) . . . . . . . . . . . . . . . . . . . 168
9.6.3 Message Interface Register Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
6/349
1
Table of Contents
9.6.3.1 IFn Command Request Registers (CAN_IFn_CRR) . . . . . . . . . 169
9.6.3.2 IFn Command Mask Registers (CAN_IFn_CMR) . . . . . . . . . . . 170
9.6.3.3 IFn Message Buffer Registers . . . . . . . . . . . . . . . . . . . . . . . . . . 172
9.6.3.4 IFn Mask 1 Register (CAN_IFn_M1R) . . . . . . . . . . . . . . . . . . . . 173
9.6.3.5 IFn Mask 2 Register (CAN_IFn_M2R) . . . . . . . . . . . . . . . . . . . . 173
9.6.3.6 IFn Message Arbitration 1 Register (CAN_IFn_A1R) . . . . . . . . 173
9.6.3.7 IFn Message Arbitration 2 Register (CAN_IFn_A2R) . . . . . . . . 174
9.6.3.8 IFn Message Control Registers (CAN_IFn_MCR) . . . . . . . . . . . 174
9.6.3.9 IFn Data A/B Registers (CAN_IFn_DAnR and CAN_IFn_DBnR) 174
9.6.3.10 Message Object in the Message Memory . . . . . . . . . . . . . . . . . 175
9.6.4 Message Handler Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
9.6.4.1 Interrupt Identifier Register (CAN_IDR) . . . . . . . . . . . . . . . . . . . 180
9.6.4.2 Transmission Request Registers 1 & 2 (CAN_TxRnR) . . . . . . . 181
9.6.4.3 New Data Registers 1 & 2 (CAN_NDnR) . . . . . . . . . . . . . . . . . . 181
9.6.4.4 Interrupt Pending Registers 1 & 2 (CAN_IPnR) . . . . . . . . . . . . . 182
9.6.4.5 Message Valid Registers 1 & 2 (CAN_MVnR) . . . . . . . . . . . . . . 183
9.7 Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
9.8 CAN Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9.8.1 Managing Message Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9.8.2 Message Handler State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9.8.2.1 Data Transfer from/to Message RAM . . . . . . . . . . . . . . . . . . . . 188
9.8.2.2 Message Transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
9.8.2.3 Acceptance Filtering of Received Messages . . . . . . . . . . . . . . . 189
9.8.2.4 Receive/Transmit Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
9.8.3 Configuring a Transmit Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
9.8.4 Updating a Transmit Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
9.8.5 Configuring a Receive Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
9.8.6 Handling Received Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
9.8.7 Configuring a FIFO Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
9.8.8 Receiving Messages with FIFO Buffers . . . . . . . . . . . . . . . . . . . . . . . . 193
9.8.8.1 Reading from a FIFO Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
9.8.9 Handling Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
9.8.10 Configuring the Bit Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
9.8.10.1 Bit Time and Bit Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
9.8.10.2 Propagation Time Segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
9.8.10.3 Phase Buffer Segments and Synchronization . . . . . . . . . . . . . . 199
9.8.10.4 Oscillator Tolerance Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
9.8.10.5 Configuring the CAN Protocol Controller . . . . . . . . . . . . . . . . . . 202
9.8.10.6 Calculating Bit Timing Parameters . . . . . . . . . . . . . . . . . . . . . . . 204
10 I2C INTERFACE MODULE (I2C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
10.1 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
7/349
1
Table of Contents
10.2 General Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
10.2.1 Mode Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
10.2.2 Communication Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
10.2.3 SDA/SCL Line Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
10.3 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
10.3.1 Slave Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
10.3.1.1 Slave Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
10.3.1.2 Slave Transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
10.3.1.3 Closing slave communication . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
10.3.1.4 Error Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
10.3.1.5 How to release the SDA / SCL lines . . . . . . . . . . . . . . . . . . . . . 212
10.3.2 Master Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
10.3.2.1 Start condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
10.3.2.2 Slave address transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
10.3.2.3 Master Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
10.3.2.4 Master Transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
10.3.2.5 Error Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
10.4 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
10.5 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
10.5.1 I2C Control Register (I2Cn_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
10.5.2 I2C Status Register 1 (I2Cn_SR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
10.5.3 I2C Status Register 2 (I2Cn_SR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
10.5.4 I2C Clock Control Register (I2Cn_CCR) . . . . . . . . . . . . . . . . . . . . . . . 224
10.5.5 I2C Extended Clock Control Register (I2Cn_ECCR) . . . . . . . . . . . . . . 225
10.5.6 I2C Own Address Register 1 (I2Cn_OAR1) . . . . . . . . . . . . . . . . . . . . 225
10.5.7 I2C Own Address Register 2 (I2Cn_OAR2) . . . . . . . . . . . . . . . . . . . . 226
10.5.8 I2C Data Register (I2Cn_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
10.6 I2C Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
11 BUFFERED SPI (BSPI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
11.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
11.3 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
11.4 BSPI Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
11.5 Transmit FIFO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
11.6 Receive FIFO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
11.7 Start-up Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
11.8 Clocking problems and clearing of the shift-register. . . . . . . . . . . . . . . . 235
11.9 Interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
11.10 Register description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
349
11.10.1 BSPI Control/Status Register 1 (BSPIn_CSR1) . . . . . . . . . . . . . . . . . 236
11.10.2 BSPI Control/Status Register 2 (BSPIn_CSR2) . . . . . . . . . . . . . . . . . 238
8/349
1
Table of Contents
11.10.3 BSPI Master Clock Divider Register (BSPIn_CLK) . . . . . . . . . . . . . . . 241
11.10.4 BSPI Transmit Register (BSPIn_TXR) . . . . . . . . . . . . . . . . . . . . . . . . 241
11.10.5 BSPI Receive Register (BSPIn_RXR) . . . . . . . . . . . . . . . . . . . . . . . . . 242
11.11 BSPI Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
12 UART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
12.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
12.3 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
12.3.1 Transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
12.3.2 Reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
12.3.3 Timeout Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
12.3.4 Baud Rate Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
12.3.5 Interrupt Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
12.3.6 Using the UART Interrupts when FIFOs are Disabled . . . . . . . . . . . . . 251
12.3.7 Using the UART Interrupts when FIFOs are Enabled . . . . . . . . . . . . . 251
12.3.8 SmartCard mode specific Operation . . . . . . . . . . . . . . . . . . . . . . . . . . 251
12.4 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
12.4.1 UART BaudRate Register (UARTn_BR) . . . . . . . . . . . . . . . . . . . . . . . 253
12.4.2 UART TxBuffer Register (UARTn_TxBUFR) . . . . . . . . . . . . . . . . . . . . 253
12.4.3 UART RxBuffer Register (UARTn_RxBUFR) . . . . . . . . . . . . . . . . . . . 254
12.4.4 UART Control Register (UARTn_CR) . . . . . . . . . . . . . . . . . . . . . . . . . 255
12.4.5 UART IntEnable Register (UARTn_IER) . . . . . . . . . . . . . . . . . . . . . . . 256
12.4.6 UART Status Register (UARTn_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . 258
12.4.7 UART GuardTime Register (UARTn_GTR) . . . . . . . . . . . . . . . . . . . . . 259
12.4.8 UART Timeout Register (UARTn_TOR) . . . . . . . . . . . . . . . . . . . . . . . 259
12.4.9 UART TxReset Register (UARTn_TxRSTR) . . . . . . . . . . . . . . . . . . . . 260
12.4.10 UART RxReset Register (UARTn_RxRSTR) . . . . . . . . . . . . . . . . . . . . 260
12.5 UART Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
13 SMARTCARD INTERFACE (SC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
13.2 External interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
13.3 Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
13.4 SmartCard clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
13.5 Register description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
13.5.1 SmartCard Clock Prescaler Value (SC_CLKVAL) . . . . . . . . . . . . . . . . 264
13.5.2 SmartCard Clock Control Register (SC_CLKCON) . . . . . . . . . . . . . . . 265
13.6 Register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
14 USB SLAVE INTERFACE (USB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
14.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
14.3 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
9/349
1
Table of Contents
14.4 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
14.4.1 Description of USB Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
14.4.2 Programming Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
14.4.3 Generic USB Device Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
14.4.4 System and Power-On Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
14.4.4.1 USB Reset (RESET Interrupt) . . . . . . . . . . . . . . . . . . . . . . . . . . 271
14.4.4.2 Structure and Usage of Packet Buffers . . . . . . . . . . . . . . . . . . . 271
14.4.4.3 Endpoint Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
14.4.4.4 IN Packets (Data Transmission) . . . . . . . . . . . . . . . . . . . . . . . . 273
14.4.4.5 OUT and SETUP Packets (Data Reception) . . . . . . . . . . . . . . . 274
14.4.4.6 Control Transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
14.4.5 Double-Buffered Endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
14.4.6 Isochronous Transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
14.4.7 Suspend/Resume Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
14.5 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
14.5.1 Common Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
14.5.1.1 USB Control Register (USB_CNTR) . . . . . . . . . . . . . . . . . . . . . 283
14.5.1.2 USB Interrupt Status Register (USB_ISTR) . . . . . . . . . . . . . . . . 285
14.5.1.3 USB Frame Number Register (USB_FNR) . . . . . . . . . . . . . . . . 290
14.5.1.4 USB Device Address (USB_DADDR) . . . . . . . . . . . . . . . . . . . . 291
14.5.1.5 Buffer Table Address (USB_BTABLE) . . . . . . . . . . . . . . . . . . . . 292
14.5.2 Endpoint-Specific Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
14.5.2.1 USB Endpoint n Register (USB_EPnR) . . . . . . . . . . . . . . . . . . . 293
14.5.3 Buffer Descriptor Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
14.5.3.1 Transmission Buffer Address n (USB_ADDRn_TX) . . . . . . . . . 300
14.5.3.2 Transmission Byte Count n (USB_COUNTn_TX) . . . . . . . . . . . 300
14.5.3.3 Reception Buffer Address n (USB_ADDRn_RX) . . . . . . . . . . . . 301
14.5.3.4 Reception Byte Count n (USB_COUNTn_RX) . . . . . . . . . . . . . . 301
14.6 Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
15 HIGH LEVEL DATA LINK CONTROLLER (HDLC) . . . . . . . . . . . . . . . . . . . . . . . . 305
15.1 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
15.2 HDLC Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
15.2.1 HDLC Frame Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
15.2.2 Basic Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
15.2.2.1 Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
15.2.2.2 Transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
15.2.2.3 Data Encoding/Decoding and Clocks . . . . . . . . . . . . . . . . . . . . . 310
15.2.2.4 Baud Rate Generator and Prescaler . . . . . . . . . . . . . . . . . . . . . 313
15.2.2.5 Cyclic Redundancy Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
349
15.2.2.6 Interrupt working mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
15.3 Register description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
10/349
1
Table of Contents
15.3.1 Private Address Register High (HDLC_PARH) . . . . . . . . . . . . . . . . . . 318
15.3.2 Private Address Register Low (HDLC_PARL) . . . . . . . . . . . . . . . . . . . 318
15.3.3 Private Address Mask Register High (HDLC_PAMH) . . . . . . . . . . . . . 319
15.3.4 Private Address Mask Register Low (HDLC_PAML) . . . . . . . . . . . . . . 319
15.3.5 Group Address Register 1 (HDLC_GA1) . . . . . . . . . . . . . . . . . . . . . . . 320
15.3.6 Group Address Register 0 (HDLC_GA0) . . . . . . . . . . . . . . . . . . . . . . . 320
15.3.7 Group Address Mask Register 1 (HDLC_GAM1) . . . . . . . . . . . . . . . . 321
15.3.8 Group Address Mask Register 0 (HDLC_GAM0) . . . . . . . . . . . . . . . . 321
15.3.9 Preamble Sequence Register (HDLC_PRES) . . . . . . . . . . . . . . . . . . . 322
15.3.10 Postamble Sequence Register (HDLC_POSS) . . . . . . . . . . . . . . . . . . 322
15.3.11 Transmission Control Register (HDLC_TCTL) . . . . . . . . . . . . . . . . . . 322
15.3.12 Receive Control Register (HDLC_RCTL) . . . . . . . . . . . . . . . . . . . . . . 323
15.3.13 Baud Rate Register (HDLC_BRR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
15.3.14 Prescaler Register (HDLC_PRSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
15.3.15 Peripheral Status Register (HDLC_PSR) . . . . . . . . . . . . . . . . . . . . . . 326
15.3.16 Frame Status Byte Register (HDLC_FSBR) . . . . . . . . . . . . . . . . . . . . 327
15.3.17 Transmission Frame Byte Count Register (HDLC_TFBCR) . . . . . . . . 327
15.3.18 Receive Frame Byte Count Register (HDLC_RFBCR) . . . . . . . . . . . . 328
15.3.19 Peripheral Command Register (HDLC_PCR) . . . . . . . . . . . . . . . . . . . 328
15.3.20 Interrupt Status Register (HDLC_ISR) . . . . . . . . . . . . . . . . . . . . . . . . . 329
15.3.21 Interrupt Mask Register (HDLC_IMR) . . . . . . . . . . . . . . . . . . . . . . . . . 330
15.4 HDLC Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
15.4.1 Memory RAM buffer mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
16 A/D CONVERTER (ADC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
16.2 Main Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
16.3 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
16.3.1 Normal (Round-Robin) Operation of ADC . . . . . . . . . . . . . . . . . . . . . . 334
16.3.2 Single-Channel Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
16.3.3 Clock Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
16.3.4 Gain and Offset Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
16.3.5 ADC Output Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
16.3.6 Power Saving Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
16.3.7 ADC Input Equivalent Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
16.4 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
16.4.1 ADC Control/Status Register (ADC_CSR) . . . . . . . . . . . . . . . . . . . . . 338
16.4.2 ADC Clock Prescaler Register (ADC_CPR) . . . . . . . . . . . . . . . . . . . . 340
16.5 ADC Register Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
17 APB BRIDGE REGISTERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
17.1 APB Clock Disable Register (APBn_CKDIS) . . . . . . . . . . . . . . . . . . . . . . . 342
17.2 APB Software Reset Register (APBn_SWRES) . . . . . . . . . . . . . . . . . . . . . 343
11/349
Table of Contents
17.3 APB Register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
18 JTAG INTERFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.2 Debug System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.2.1 The Debug Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.2.2 The Protocol Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.2.3 ARM7TDMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.3 ARM7TDMI Debug Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
18.3.1 Physical Interface Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
19 REVISION HISTORY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
349
12/349
Index
13/349
1
Index
I2Cn_OAR2 .............................................. 226 TIMn_CR2 ................................................ 150
I2Cn_SR1 ................................................. 220 TIMn_ICAR ............................................... 147
I2Cn_SR2 ................................................. 222 TIMn_ICBR ............................................... 147
TIMn_OCAR ............................................. 147
P TIMn_OCBR ............................................. 148
TIMn_SR ................................................... 151
PCU_BOOTCR .......................................... 64
PCU_MDIVR .............................................. 61 U
PCU_PDIVR ............................................... 61
PCU_PLL2CR ............................................ 62 UARTn_BR ............................................... 253
PCU_PRSTR.............................................. 62 UARTn_CR............................................... 255
PCU_PWRCR ............................................ 66 UARTn_IER .............................................. 256
UARTn_RxBUFR .................................... 254
R UARTn_SR ............................................... 258
UARTn_TOR ............................................ 259
RCCU_CFR ................................................ 55 UARTn_TxBUFR ..................................... 253
RCCU_PER ................................................ 58 UARTn_TxRSTR ..................................... 260
RCCU_PLL1CR ......................................... 57
RCCU_SMR ............................................... 59 W
RTC_ALRH ............................................... 123
RTC_ALRL ............................................... 123 WDG_CNT ............................................... 127
RTC_CNTH .............................................. 122 WDG_CR .................................................. 126
RTC_CNTL ............................................... 122 WDG_KR .................................................. 129
RTC_CRH ................................................. 118 WDG_MR.................................................. 128
RTC_CRL ................................................. 119 WDG_PR .................................................. 127
RTC_DIVH ................................................ 121 WDG_SR .................................................. 128
RTC_DIVL ................................................ 122 WDG_VR .................................................. 127
RTC_PRLH ............................................... 120
RTC_PRLL ............................................... 121 X
14/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
2 MEMORY
The native bus system includes CPU, RAM, Flash, External Memory Interface (EMI) and the
Power, Reset and Clock Control Unit (PRCCU).
The APB bridges (APB1 & APB2) interface two groups of peripherals. Wait states are inserted
automatically on the CPU clock when accessing APB peripherals clocked slower than the
ARM7 core.
Program memory, data memory, registers and I/O ports are organized within the same linear
address space of 4 GBytes.
The bytes are treated in memory as being in Little Endian format. The lowest numbered byte
in a word is considered the word’s least significant byte and the highest numbered byte the
most significant.
Figure 1 on page 16 shows the STR71x Memory Map. For the detailed mapping of peripheral
registers, please refer to the related chapters.
The addressable memory space is divided into 8 main blocks, selected by the three most
significant bits A[31:29] of the memory address bus A[31:0]
15/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
0xFFFF FFFF
EIC 4K
Addressable Memory Space 0xFFFF F800
B1F0 8K reserved
0x8000 0000
Reserved 4K 0x400C 0000
0xC001 0000
reserved 4K
reserved 0xC000 F000
0x4002 0000
UART 3 4K
0xC000 7000
UART 2 4K
0xC000 6000
1
B0F5 64K
UART 1 4K
0xC000 5000
Reserved
16/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
17/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note: EIC is aliased in the memory map; it can be addressed with an offset of 0xFFFF F800.
This is used to branch from the ARM7 Interrupt vector (0x0000 0018) to the EIC_IVR register,
that points to the active Interrupt Routine (see section 5 on page 79).
Three boot modes are selected by configuration pins on exit from Reset (See “Boot
Configuration” on page 22.)
■ Flash boot mode: In this mode, the Flash is mapped in both memory block 010 and memory
block 000. The system boots from bank 0, sector 0 of the Flash
■ RAM boot mode: In this mode, RAM is mapped in both memory block 001 and memory
block 000, and the system boots from RAM Memory. This is useful for debug purposes, the
RAM can be pre-loaded by an external JTAG controller or development system (emulator).
■ External Memory boot mode: In this mode, External Memory is mapped in both memory
block 011 and memory block 000, and the system boots from External Memory bank 0.
2.1.6 RAM
STR71x features 64 KBytes of fully static, synchronous RAM. It can be accessed as bytes,
half-words (16 bits) or full words (32 bits). The RAM start address is 0x2000 0000.
18/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In RAM boot mode (see Section 2.1.5) the RAM start address is mapped at both 0x0000
0000h and at 0x2000 0000h.
You can remap the RAM on-the-fly to RAM boot mode configuration, using the BOOT[1:0] bits
in the PCU_BOOTCR register. This is particularly useful for managing interrupt vectors and
routines, you can copy them to RAM, modify and access them even when Flash is not
available (i.e. during Flash programming or erasing).
2.1.7 Flash
Bank 0 is intended for program memory. Sectors B0F0-B0F7 can be used as Boot sectors;
they can be write protected against unwanted write operations.
Bank 1 contains 16 Kbytes of Data Memory: it is divided into 2 sectors (8 Kbytes each). You
can program application data in this area.
You can Program Bank 0 and Bank 1 independently, i.e. you can read from one bank while
writing to the other.
Flash memory can be protected against different types of unwanted access (read/write/
erase).
You can program Flash memory using In-Circuit Programming and In-Application
programming. Refer to the STR7 Flash Programming Reference Manual.
19/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The STR71x Flash memory has two access modes: Burst mode and Low power mode.
You can enable or disable Burst mode using the FLASHLP bit in the PCU_PWRCR register.
In Burst mode, sequential accesses are performed with zero wait states at speeds of up to the
maximum device frequency. Non sequential accesses are performed with 1 wait state.
When Burst Mode is disabled, the Flash operates in low power (LP) mode and all accesses
are performed at speeds of up to 33 MHz with zero wait states.
Depending on your application requirements, you can optionally power down the Flash in Stop
or Low power wait for interrupt modes (Refer to the STR7 Flash programming reference
manual). Otherwise, in Stop mode, the Flash automatically reduces its power consumption
and can be read immediately after wake-up.
The External Memory Interface can be used to interface external memory components such
as ROM, FLASH, SRAM or external peripherals.
The External Memory space is divided into 4 banks based on decoding of A[26:25]. Each
Bank can address up to 16 MBytes of external memory. Addressing one of these banks will
activate the related Chip Select output CSN[3:0]. EMI address bus A[23:0] is available
externally, as well as the control signals WEN[1:0] (Byte Write Enable) and RDN (Read
Enable).
The length of time required to properly transfer data from/to external memory banks is
controlled by programming the control registers for each bank which determines the number
of wait states used to access it. The access time also depends on the selected external bus
width. Each register also contains a flag bit to indicate if a particular memory bank is
accessible or not.
20/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
APB2
0xE000 0000
APB1
0xC000 0000
External Memory Space
64 MBytes
5
0x6C00 000C BCON3 register
0x6C00 0008 BCON2 register
PRCCU
0xA000 0000 0x6C00 0004 BCON1 register
0x6C00 0000 BCON0 register
4
0x66FF FFFF
Reserved
0x8000 0000 Bank3 16M
CSn.3
0x6600 0000
3
0x64FF FFFF
0x6400 0000
2 0x62FF FFFF
Bank1 16M
CSn.1
0x4000 0000 FLASH
0x6200 0000
0x60FF FFFF
1 Bank0 16M
CSn.0
FLASH/RAM/EMI
0x0000 0000
Reserved
21/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
BOOTEN is a dedicated pin. It must normally be tied to ground through a 10K resistor. When
BOOTEN = 0, the device is in FLASH boot mode, the BOOT[1:0] pins are not used, and they
may have any value.
When BOOTEN = 1, the BOOT[1:0] pins are latched at the second CK rising edge after the
release of the external RSTINn pin. Their value is used to configure the device BOOT mode,
as shown in Table 5.
Note: When booting with the following configuration BOOTEN=1, BOOT1=0 and BOOT0=1
the system boots in a reserved ST boot mode.
In the following section, the abbreviation B[1:0] refers to the BOOT[1:0] pins, and BOOTEN is
considered equal to 1 unless specified.
This is the standard operating mode; to enter this mode it is not necessary to control
BOOT[1:0], if BOOTEN = 0.
This mode is also entered by forcing the external pins B1=0 and B0=0. This status is latched
when the external Reset is released.
It is up to the user to develop the in-application programming (IAP) procedure and determine
the best usage of the different sectors. For example, B0F0 and B0F1 can be used as the user
boot-loader. When this mode is used, at least block B0F0 must have been previously
programmed, as the system boot is performed from Flash sector B0F0.
22/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note: To guarantee maximum security, it is recommended that the flash Erase and
Programming routines are not stored in the Flash itself, but loaded into RAM from an external
tool at the start of the ICP procedure.
RAM mode is provided to ease application development. RAM mode is entered by forcing the
external pins B1=1 and B0=0, while EXTMEM mode is entered by forcing the external pins
B1=1 and B0=1. This status is latched on the second CK clock pulse after external Reset is
released.
In EXTMEM mode the system boot is performed from the external memory, bank 0 (CSN0 is
activated). The external memory is also mapped at address 0h (see PCU_BOOTCR register).
In RAM mode the system boot is performed from the internal RAM, which is also visible at
address 0h (see PCU_BOOTCR register). You must pre-load your boot code in RAM, for
example using a Development System (MultiICE™ or equivalent).
It is up to the user application to provide the proper signals on B0, B1, since there is no
specific microcontroller I/O to control B0 and B1 during the reset phase.
23/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The EMI memory map is shown in Table 7. Each bank makes use of all 24 bits of A[23:0],
providing 16 MByte of addressable space. The base address of the External Memory space is
EMI_BASE = 0x6000 0000.
Table 7. EMI Memory Map
Addressable
Address Range Description Bus Width (bit)
Size (Bytes)
0x6000 0000 - 0x60FF FFFF Bank 0 - BOOT 16M 16 bit access only1)
(CSn.0)
0x6C00 0000 - 0x6C00 0010 Internal Registers n/a 16 bit access only
Note 1: If External memory is used for boot operation, it must be 16-bit as the CSN0 memory
bank has been hard-wired for 16-bit memory interface only.
Each memory bank of the EMI can have a programmable number of wait states (up to 15)
added to any read or write cycle: this is software configurable via the C_LENGTH bitfield of
the EMI_BCONx register (x=0,..,3).
Depending on the used external memory data bus width, two access types are possible:
Single cycle access and Multiple cycle access:
For write cycles which translate in a single external bus operation (e.g. a 16-bit write to a bank
configured 16-bit wide), the total length (measured in EMI internal clock units) that a single
access will require (equal to the length over which the Chip Select will be active) will depend
on the memory bank the cycle is executed on. It can be calculated using the formula:
This value is also the number of WAIT states generated. Hence for performance calculations
each external access will last (Int_Access_length + CSn[3:0] length) MCLK cycles where
Int_Access_length may be derived from ARM7 programmer’s manual, depending on the type
of access.
For read cycles which translate in a single external bus operation (e.g. a 16-bit read from a
bank configured 16-bit wide), the total length (measured in EMI internal clock units) that a
24/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
single access will require (equal to the length over which the Chip Select will be active) can be
calculated using the formula:
Each external access will last (Int_Access_length + CSn[3:0] length) MCLK cycles as above.
For read or write cycles that translate in multiple (N) external bus cycles (e.g. a 32-bit write to
a region configured 8-bit wide, for which N=4), the total external bus cycle duration can be
obtained using the following formula
In this case the total duration of the access will be (Int_Access_length + Total CS length)
MCLK cycles.
25/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In the Figure 3 shown below, a 16-bit write is being performed on a 16-bit external memory. As
can be seen from the diagram, both external write strobes are asserted for the duration of the
write cycle. This is a one-cycle write, hence the LSB of the external address is not modified,
and takes 5 MCLK cycles to complete (C_LENGTH = 3).
MCLK
C_Length[3:0] 0x3
B_Size[1:0] 0x1
CSn.2
WEn.1
A[0] 0
A[23:1] address[23:1]
D[15:0] Data
(Output)
26/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In Figure 4, a 32-bit write is being performed. However in this case, the external bus width is
only 8-bits (B_SIZE = 0). This has the effect that 4 write cycles are required to perform the full
32-bit write. The 2 LSBs of the external address are modified by the read-write controller for
each write beginning at “00” for the 1st write and incrementing for each write cycle until it
reaches “11”.
As only the 8 LSBs of the external data bus are used, only WEn.0 is asserted for any write.
MCLK
C_Length[3:0] 0x0
B_Size[1:0] 0x0
CSn.3
WEn.0
WEn.1
A[23:2] address[23:2]
In this case CS3n is used; it should be noted that CS3n is maintained asserted until all write
cycles have been completed whereas WEn.0 is de-asserted for 1 MCLK cycle between
separate write operations.
27/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The following diagram shows a basic READ operation. In the case of a READ only 1 external
read strobe is required (RDn). In this example, a 32-bit read is being performed. The external
bus size is 16 bits however (B_SIZE = 1) so the EMI peripheral has to perform 2 successive
read operations. The results from the 1st read operation are latched internally in the EMI block
(In this case - “2DDA” - i.e 16 LSBs of data) so that the correct 32-bit data (i.e “A16F2DDA”) is
returned after the 2nd 16-bit read.
MCLK
C_Length[3:0] 0x1
B_Size[1:0] 0x1
RDn
WEn.1
0x0 0x2
A[1:0]
A[23:2] address[23:2]
For the 1st read operation, A[1:0] is assigned “00”, for the second this is incremented by 2 (i.e
“10”).
28/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw - rw rw
The Bank n Configuration Register (BCONn) is a 16-bit read/write control register used to
configure the operation of Bank n. The BCONn control bits are described below.
29/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
30/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The VDDA and VSSA pins supply the reference voltages for the A/D Converter.
VDDA
A/D converter
VSSA
V18BKP
V18
V33 3.3V
I/Os
Core
V18
Main Voltage Regulator
See Note1
V33
StandbyMode I/Os
32 kHz Oscillator RTC and Standby Logic
Backup Block
Note 1: In normal operating mode V18 is shorted with V18BKP. In Standby Mode the V18
domain is disconnected from the V18BKP domain.
Note 2: The two V18 pins must be connected to external stabilization capacitors. Connecting
an external 1.8V supply to the V18 pins is not supported (refer to the STR71x datasheet).
31/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In Standby mode, (see section 3.5.5 on page 48) the Main Voltage Regulator is switched off,
and the Low Power Voltage Regulator supplies power to the backup block. It is possible to
bypass the Low Power Voltage Regulator under software control when an external 1.8V
supply (V18BKP) is available in addition to V33, increasing the power efficiency of the system.
In this case V18BKP must not be connected directly but through a diode to avoid any
contention when the device is not in Standby mode.
Because it powers the I/Os, V33 cannot be switched off in Standby mode since the nSTDBY,
nRSTIN and WAKEUP pins must remain functional.
The Main Voltage Regulator (MVR) is able to generate sufficient current for the device to
operate in any mode through ballast P-channel transistors located inside the I/O ring. It
includes a bandgap reference for thermal compensation and it has a static power
consumption of 100 µA (typical).
Notes:
The separate Low Power Regulator should be used only when the device is in Standby, STOP
or LPWFI. It has a different design from the main VR and generates a non-stabilized and
non-thermally-compensated voltage of approximately 1.6V. The output current is not generally
sufficient for the device to run in normal operation. Because of this limitation, the PLL is
automatically disabled when the Main VR is switched off and the maximum allowed operating
frequency is 1 MHz.
The Low Power VR can be switched off as well when an external regulator provides a 1.8V
supply to the chip through the V18BKP pin for use by Real Time Clock and Wake-Up logic
during Standby mode (See section 3.1.1 on page 32.)
32/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
For both the Main VR and the Low Power, VR stabilization is achieved by external capacitors,
connected respectively to the V18 pins (Main Regulator) and V18BKP pin (Low Power
Regulator). The minimum recommended value is 10µF (Tantalum, low series resistance) plus
33nF ceramic for the Main Voltage Regulator, and 1µF for the Low-Power Voltage Regulator.
Precaution should be taken to minimize the distance between the chip and the capacitors.
Care should also be taken to limit the serial inductance to less than 60 nH.
Note:
Both the Main Voltage Regulator and the Low Power Voltage Regulator contain each a low
voltage detection circuitry which keep the device under reset when the corresponding
controlled voltage value (V18 or V18BKP) falls below 1.35V (+/- 10%).
3.3 Reset
At power on, the nRSTIN pin must be held low by an external reset circuit until V33 reaches
the minimum specified in the datasheet.
The Reset Manager resets the MCU when one of the following events occurs:
The event causing the last Reset is flagged in the RCCU_CFR register: the corresponding bit
is set. A hardware-initiated reset or a Voltage Regulator low voltage detector reset will leave
all these bits reset.
The hardware reset overrides all other conditions and forces the system to reset state. During
the Reset phase, the internal registers are set to their reset values, where these are defined,
and the I/O pins go into their reset configuration.
A Reset from the nRSTIN pin is asynchronous: as soon as it is driven low, a Reset cycle is
initiated.
The on-chip Timer/Watchdog generates a reset condition if Watchdog mode is enabled and if
the programmed period elapses without the specific code being written to the appropriate
register (refer to Watchdog specifications).
33/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When the nRSTIN pin goes high again, 2048 clock CLK plus 8 CLK2 (refer to Section 3.4)
cycles are counted before exiting Reset state (plus possibly one more CLK period, depending
on the delay between the rising edge of the nRSTIN pin and the first rising edge of CLK)
.Refer to Figure 7.
At the end of the Reset phase, the Program Counter is set to the location specified in the
Reset Vector located in memory location 0x0h.
34/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
255 cycles
CK ...
RSTINn
FLASH RESET
(internal signal)
ARMTDMI RESET
(internal signal)
MCLK
PCLKx
35/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
V33 MAX
CLK
MCLK
RSTIN
PIN
To improve the noise immunity of the device, the RESET input pin (nRSTIN) has a Schmitt
trigger input circuit with hysteresis. Spurious RESET events are masked by an analog filter
which guarantees that all the glitches (single pulse and burst) on the nRSTIN pin shorter than
100ns are not recognized by the system as valid RESET pulses. On the other hand, it is
recommended to provide a valid pulse on nRSTIN with a duration of at least 1 µs to be sure
that the asynchronous pulse is properly latched. This means that all pulses longer than 100ns
and shorter than 1 µs can have an unpredictable effect on the device: they can either be
recognized as valid or filtered.
0.7 V33
0.3 V33
36/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
3.4 Clocks
The following figure gives the STR71x clock distribution scheme:.
Osc 32KHz
RTCXTI RTC Block
RTCXT0
The source clock CLK is derived from an external oscillator, through the CK pin. This clock
may be turned off during Low power modes. (refer to Section 3.5)
The system PLL (PLL1) is used to multiply the input internally, to generate the appropriate
operating frequency. RCLK is the output of the system PLL or if enabled the CK_AF alternate
source (32KHz RTC clock).
■ Main Clock MCLK, including CPU, internal memories, External Memory Interface, PRCCU
Registers (except RCCU registers see note 2 below)
■ PCLK1, including APB1 peripherals (serial communication peripherals) , as listed in Memory
Map table
■ PCLK2, including APB2 peripherals (system peripherals) , as listed in Memory Map table
Each domain may use different frequencies independently by programming the various clock
dividers. Having a divider dedicated to the CPU subsystem allows software to dynamically
37/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
change CPU operating frequency, tailoring computing speed and power consumption to
application needs, while maintaining a stable operation of all the peripherals.
On-chip peripherals, mapped in the APB memory space, make use of the RCLK output
divided, independently from MCLK, by 2, 4 or 8. Wait states are automatically added by the
bus bridge when accessing their registers.
Note that clock may be enabled/disabled independently to each peripheral. Each peripheral
may also be reset under software control (Refer to Section 17)
Notes:
1. It is forbidden to access peripheral registers if the CPU clock MCLK is slower than the
related peripheral clocks PCLK1 and PCLK2.
2. If the MCLK clock divider is set to a prescaling value other than 1 (i.e. if RCLK frequency
differs from MCLK), it is not possible to access the RCCU registers since they are always
clocked by RCLK.
3. For non-intensive operations, PLL1 may be disabled; in addition CLK2 may be divided by
a factor of 16, to allow low-power operation while maintaining fast interrupt response.
4. System blocks (ARM7TDMI®, PRCCU, on-chip memories and bridges) are driven by
MCLK (Bus clock) and cannot be disabled by software in order to guarantee basic func-
tionalities.
The HDLC peripheral can optionally receive its reference clock from an external pin, and may
dynamically change its frequency independently from CPU operation. An internal PLL (PLL2)
allows the use of a low-frequency external signal, thus reducing power consumption and
generated noise.
The USB Interface needs a precise 48 MHz clock reference. This may be generated either
externally through the USBCLK pin, or by the internal PLL2, multiplying an external reference
at lower speed, if PLL2 is not used by the HDLC interface.
Note: If the USB interface is not used, set bits 0, 1 and 2 in the PCU_PLL2CR register to
switch off PLL2 (and reduce power consumption).
Caution: To reduce power consumption, bits 0, 1 and 3 in the RCCU_PER register must
be reset by the application software in the initialization phase. These bits are enabled
by hardware at reset for factory test purposes only.
38/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The CLK signal drives a programmable divide-by-two circuit. If the DIV2 control bit in
RCCU_CFR register is set (reset condition), CLK2, is equal to CLK divided by two; if DIV2 is
reset, CLK2 is identical to CLK. In practice, the divide-by-two is used in order to ensure a 50%
duty cycle signal.
When the PLL is active, it multiplies CLK2 by 12, 16, 20 or 24, depending on the status of the
MX[1:0] bits in the RCCU_PLL1CR register. The multiplied clock is then divided by a factor in
the range 1 to 7, determined by the status of the DX[2:0] bits in the RCCU_PLL1CR register.
When the DX[2:0] bits are programmed to 111, and the FREEN bit in the RCCU_PLL1CR is
set to ‘1’, the PLL loop is open and the PLL provides a slow frequency back-up clock which
depends on the MX[1:0] and FREF_RANGE bits (refer to Section 3.4.2.1 and Table 9). If
instead DX[2:0]=’111’ and FREEN is ‘0’, the PLL is switched off.
The frequency multiplier contains a frequency comparator between CLK2 and the PLL clock
output that verifies if the PLL clock has stabilized (locked status). The LOCK bit in the
RCCU_CFR register becomes set when this condition occurs and maintains this value as
long as the PLL is locked, going back to 0 if for some reason (change of MX[1:0] bits value,
stop and restart of PLL or CLK2 and so on) loses the programmed frequency in which it was
locked. It is possible to select the PLL clock as system clock only when the LOCK bit is ‘1’. If
the LOCK bit return to ‘0’ the system clock switches back to CLK2 even if the CSU_CKSEL bit
is ‘1’. The PLL selection is further conditioned by the status of the Main Voltage regulator: only
when VROK bit in PCU_PWRCR register is ‘1’, that is the Voltage Regulator is providing a
stabilized supply voltage, the PLL can be selected (refer to Voltage Regulator specifications).
Setting the CSU_CKSEL bit in the RCCU_CFR register allows to select the multiplier clock as
system clock, but the two previous conditions must be matched.
Care is required, when programming the PLL multiplier and divider factors, not to exceed the
maximum allowed operating frequency for each clock. Refer to the datasheet specifications.
There is no lower limit for MCLK. However, some peripherals can show incorrect operation
when the system clock has a too low frequency.
The PLL is able to provide a low-precision clock PLLCLK, usable for slow program execution.
The frequency range is from 125 kHz to 500 kHz, depending on the MX[1:0] bits and the
FREF_RANGE. This mode enabled by the FREEN and DX[2:0] bits in the RCCU_PLL1CR
register: when PLL is off and FREEN bit is ‘1’, that is, all these four bits are set, the PLL
provides this clock. The selection of this clock is still managed by the CSU_CKSEL bit, but is
not conditioned by bits LOCK in RCCU_CFR and VROK in the PCU_PWRCR register. To
avoid unpredictable behavior of the PLL clock, the user must set and reset the Free Running
mode only when the PLL clock is not the system clock, i.e when the CSU_CKSEL bit is ‘0’.
39/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The following figure describes the PRCCU registers programming for configuring the clocks:
Osc 32KHz
RTCXTI RTC Block
RTCXTO
(4)
CK_AF
MCLK to Core &
DIV1/2/4/8 Memories
1/16
(4)
RCLK PCLK1 to peripherals
(2) DIV1/2/4/8 on APB1
CK 1/2 CLK2 CLK3 (4)
CLK
PLL1 Clock (3) PCLK2 to peripherals
(1) Multiplier & DIV1/2/4/8 on APB2
divider PLLCLK
In reset state, the RCCU_CFR value is 8008h and The PCU_MDIVR and PCU_PDIVR
register values (FACT bits) are 0000h. Consequently, in reset state the clock configuration is
DIV2 = 1, CK2_16=1 and therefore MCLK, PCLK1 and PCLK2 operate at the external clock
frequency CLK2
40/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
41/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When any of these events occur, the corresponding pending bit in the RCCU_CFR register
becomes ‘1’ and the interrupt request is forwarded to the interrupt controller. It is up to the
user to reset the pending bit as the first instruction of the interrupt routine. The pending bits
are clear-only (cleared only by writing ‘1’). Each interrupt can be masked by resetting the
corresponding mask bit in the RCCU_CCR register.
42/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In Slow mode, you reduce power consumption by slowing down the main clock. In Slow mode
you can continue to use all the device functions of the chip, but at reduced speed.
To enter Slow mode, RCLK frequency can be forced to CLK2, CLK2 divided by 16, or to
CK_AF (32KHz clock) provided CKAF_ST is set, indicating that the Real Time Clock is
selected and actually present.
To reduce power consumption, you can turn off the PLL1 by setting bits DX[2:0] in the
RCCU_PLL1CR register.
Notes:
1. PLL1 can be configured to switch off automatically when the 32KHz CK_AF clock is
selected, this can be done by setting the CKSTOP_EN bit in the RCCU_CFR register.
2. When selecting the 32KHz as system clock, you can reduce power consumption by stop-
ping the external oscillator using a GPIO pin.
In WFI mode, you reduce power consumption by stopping the core. The program stops
executing, but peripherals are kept running and the register contents are preserved. The
device resumes, and execution restarts when an interrupt request is sent to the EIC.
To enter WFI mode, software must write a 0 in the WFI bit of the RCCU_SMR register.
To wakeup from WFI mode an interrupt request must be acknowledged by the EIC.
LPWFI (Low power wait for interrupt) is a combination of WFI and Slow modes. In fact, when
entering in this low power mode, the following occurs:
To wakeup from LPWFI mode, an interrupt request must be acknowledged by the EIC.
Notes:
43/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
44/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
User Program
Execution of user program
40 MHz
resumes at full speed
45/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
User Program
24 MHz
Wait For Interrupt
activated
Clear WFI bit CLK2/16 selected and PLL
stopped automatically
User Program
Execution of user program
24 MHz
resumes at full speed
46/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In Stop mode you stop the RCLK (core and peripherals clocks) without resetting the device,
hence preserving the MCU status (except the CSU_CKSEL and the STOP_I bits in the
RCCU_CFR register).
To enter Stop Mode you have to execute the Stop bit setting sequence described in the XTI
chapter. The device will remain in Stop mode until a wake-up line is asserted to restart the
program execution.
The MCU resumes program execution after a delay of 2048 clock periods after the Stop
mode wakeup event.
On wake-up from Stop mode, the STOP_I bit in the RCCU_CFR register is set and an
interrupt is generated if enabled.
Notes:
If a reset occurs while the device is in Stop mode, the clock restarts.
Note: Assuming MCLK=PCLK, a STOP mode Wake-up event cannot occur less than (N+
6)*MCLK periods after the start of the STOP bit setting sequence, where N is the number of
cycles needed to perform the stop bit setting sequence (refer to “STOP Mode Entry
Conditions” on page 107 for further details). Otherwise the wakeup event will be ignored.
47/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Main Voltage Regulator control logic manages the power-down/wake-up sequence to
ensure a smooth transition to and from the ultra low-power Standby state.
In Standby mode, the power supply is given through V33 pins as normal. The Main Voltage
Regulator is switched off and the V18 domain (the kernel of the device) is powered off (the
voltage on external V18 pins falls to zero). The Backup block, including Real Time Clock and
Wake-Up logic, is independently powered by the Low-Power Voltage Regulator.
See also Section 3.1.1: Optional use of External V18BKP Supply on page 32
Note Since in Standby mode, the V18 supply of the device kernel is switched off, the
content of the system RAM is lost and the Watchdog is disabled.
Note When entering Standby mode the V18 domain (the kernel of the device) is powered
off while the logic belonging to the Backup block is kept powered-on. When leaving
Standby mode, all the logic belonging to the V18 domain starts from the reset state.
This means that the registers (PCU_PWRCR, RTC_ALR and RTC_PRL) that
contain bits, which affect the behaviour of Backup logic will in general not reflect its
status. These bits are in fact latched in the Backup domain to retain their value during
Standby but on leaving Standby mode, their value is not transferred back to the logic
in the V18 domain which in turn shows the reset value.
Note Since any write operation to the Real Time Clock registers requires at least two 32
kHz clock cycles to complete, if software configures the Real Time Clock registers,
Standby mode can only be entered after the write operation to the Real Time Clock
register is over. This can be monitored by polling the RTOFF bit in the RTC_CRL
register.
Note Ensure that the Wake-up pin is pulled down when entering Standby mode.
Figure 14 and Figure 15, show the sequence of events that occur at external signal level and
at software level when Standby mode is entered via software.
• All the signals connecting the main kernel (V18 domain) and the Backup block are forced
to ground to avoid electrical damage.
48/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• The V18BKP domain is disconnected from the V18 domain and therefore the Backup block
is supplied only by the Low Power Regulator.
• The Main Voltage Regulator is switched off.
• All the I/Os belonging to the kernel are forced into High Impedance.
• The nSTDBY pin is forced low by the device.
nSTDBY
(Device Output)
(SW sets PWRCTRL[6])
WAKEUP
> 100µS
nSTDBY
(Device Output)
> 10µS
(SW sets PWRCTRL[6])
WAKEUP
> 100 µS
nRSTIN
49/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Power-on –
Enter in Standby Wakeup
Power-On
SW sets
PRCCU_PWRCR Pwrdwn WAKEUP (or nRESET) RTC alarm triggers
pin is forced active
Apply power ramp
Reset held active Interface between Kernel
and Backup is locked Main Vreg switched on
(if not bypassed),
Main Voltage Kernel is held under Reset
Kernel Pads are disabled
Regulator starts
When V18 stabilizes,
Vbkp disconnected from Vbkp is connected to V18
V18 - Backup logic
Release nRESET uses LP-VReg Interface between Kernel
and Backup is released,
LVD keeps internal Main Vreg switched off Kernel Pads are enabled,
Reset active until STDBY output disabled
V18 stabilizes STDBY output activated,
Reset to Kernel is released,
WAKEUP input enabled
PRCCU _CFR flags
CPU boots boot source
Chip in Standby
CPU boots
A wake-up event may be generated by the RTC alarm or can be generated externally by a
wake-up pin. In this case, a pulse of at least 100µS is necessary. The other source of wake-up
is the external nRSTIN pin.
A wake-up event switches the power to the kernel back on. The kernel is kept under reset up
to when the internal voltage is correctly regulated. At this point, the interface between the
kernel and the Backup block is reconnected, and the CPU restarts from its reset sequence.
The flags in the RCCU_CFR register will indicate the wake-up source (RTC, WAKEUP pin,
nRSTIN pin, Watchdog, Software).
Notes:
1. If the WAKEUP pin is at high logic level, it is not allowed to enter Standby mode.
2. In Standby mode, the RTC alarm will always cause a wake-up event regardless of the
mask bit configuration.
In case of Standby mode entered via hardware, the sequence is the same but it is started by
the external activation of nSTDBY pin, which is hence operating as an input. In this case,
50/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
rising edges on both WAKEUP and nSTDBY pin are requested to exit from Standby mode
(see Figure 17 and Figure 18). The WAKEUP rising edge switches the Main Voltage
Regulator back on, while the nSTDBY pin rising edge releases the internal Reset to the V18
domain of the device (powered by the Main VR).
Notes:
1. In Hardware Standby mode entry, the minimum time between the WAKEUP and nSTDBY
rising edges is 100µs.
2. In Standby mode, the RTC alarm will always cause a wake-up event regardless of the
mask bit configuration.
3. If WAKEUP pin is at high logic level, it is not allowed to enter Standby mode. It is forbidden
to keep WAKEUP pin high while forcing nSTDBY low. It is also forbidden to force nSTDBY
high before or after the pulse on both WAKEUP and nRSTIN.
4. A Reset event (nRSTIN activation) has priority over nSTDBY. Therefore, reset activation
will force exit from Standby mode. If nRSTIN is activated while nSTDBY is active, the
device exits from Standby mode. If a Reset pulse is given while nSTDBY is kept at con-
stant low level, the device will enter Standby mode again after nRSTIN rising edge.
5. In order to wake-up the system using the WAKEUP pin, the WAKEUP signal pulse width
must be held active high for at least 100us. A pulse width of less than 100us may affect
the system.
nSTDBY
(Device Input) > 10µS
> 10ns
WAKEUP
> 100µS
nSTDBY
(Device Input)
> 10ns > 10µS
WAKEUP
nRSTIN
51/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When a Wakeup event restarts the device from the Standby Mode and power supply is
reapplied to the V18 domain, the reset is activated. The reset source is indicated by a bit set in
RCCU_CFR register.
52/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
- - - - - - - - - - - - - - - -
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
53/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note: To check if the selection has actually occurred, check that CKAF_ST is set. If no Real
Time Clock is present, the selection will not occur.
0: Low Power mode during WFI disabled. When WFI is executed, MCLK is unchanged
1: The device enters Low Power mode when the WFI instruction is executed. The clock during
this state depends on WFI_CKSEL
54/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
- - - - - - - - - - - - - - - -
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CK2_ WKP_ LVD_RE RTC_ WDG SOFT CKSTO CK2_ CKAF_ CSU_
DIV2 STOP_I CKAF_I LOCK_I - LOCK
16_I RES S ALARM RES RES P_EN 16 ST CKSEL
55/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
56/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
0: The PLL is turned off or not locked and cannot be selected as RCLK source.
1: The PLL is locked
If the FREEN bit is set, this bit selects this clock independently of the LOCK and VROK bits.
Note: Setting the CKAF_SEL bit overrides any other clock selection. The clearing the CK2_16
bit overrides the CSU_CKSEL selection (see Figure 11 on page 40)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
- - - - - - - - - - - - - - - -
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FREF_
- - - - - - - - FREEN MX1 MX0 - DX2 DX1 DX0
RANGE
rw rw rw rw rw rw rw
57/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note: It is recommended to deselect and switch-off the PLL before changing MX values.
Bit 2:0 = DX[2:0]: PLL output clock division factor. Refer to Table 13 for the DX bit settings.
Table 13. PLL Division Factors
DX2 DX1 DX0 RCLK
0 0 0 PLLCK / 1
0 0 1 PLLCK / 2
0 1 0 PLLCK / 3
0 1 1 PLLCK / 4
1 0 0 PLLCK / 5
1 0 1 PLLCK / 6
1 1 0 PLLCK / 7
FREEN= 0: CLK2 (PLL OFF, Reset State)
1 1 1
FREEN=1: PLL in Free Running mode
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PH_CK[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PH_CK[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
58/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The relation between register bits and peripherals is shown in Table 14.
Table 14. Peripheral Clock Management
PH_CKEN Reg. Status Peripheral Stopped
PH_CK[1:0] = 0 not used1)
PH_CK[2] = 0 EMI
PH_CK[3] = 0 not used1)
PH_CK[4] = 0 USB KERNEL
PH_CK[16:5] = 0 not used1)
PH_CK[31:17] = 0 not used
1)
To reduce power consumption, these bits should be cleared by software after reset.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
- - - - - - - - - - - - - - - -
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
- - - - - - - - - - - - - - HALT WFI
rw rw
59/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
means that this bit, once reset, can only be set to ‘1’ by hardware.
1: No effect
Caution: If all EIC interrupt channels are masked, clearing this bit will stop program execution
indefinitely unless the device is reset. Hence you must ensure that at least one interrupt
channel is enabled before clearing the WFI bit.
60/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
reserved FACT
rw
This register sets the prescaling factor for the Main System Clock MCLK, according to Table
15. It may be written by software at any time, to dynamically adjust the operation frequency.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
This register sets the prescaling factor for the two APB Clocks PCLK1, for peripherals
belonging to the APB1 group, and PCLK2, for peripherals belonging to the APB2 group;
prescaling values are listed in Table 15 on page 61. It may be written by software at any time.
FACT1 and FACT2 may be chosen independently.
Note: Peripheral clock speed must be equal or lower than CPU clock speed, but lower or
equal to the values specified in the datasheet. It is up to the user to ensure this condition is
always met. Unexpected behaviour may occur otherwise.
61/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EMI
Reserved Reserved
RST
This register allows to force a Reset activation individually to most system blocks. Not all
system blocks may be reset by software, to guarantee consistent behaviour of the device.
Bit 3 = Reserved for factory test. To reduce power consumption, this bit must be set by
software.
Bit 2 = EMIRST
If this bit is set to logical one, the External Memory interface peripheral will be forced to Reset
state. Reset activation/ deactivation is synchronous with system clock MCLK.
If this bit is set to logical zero, the EMI operate normally.
Bit 1:0 = Reserved for factory test. To reduce power consumption, this bit must be set by
software.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r clr rw rw rw rw rw rw
This register controls operation of the PLL2, dedicated to HDLC or USB blocks.
62/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
provides a stable frequency. Any change of this bit may generate an interrupt request, if
enabled by setting bit 9, IRQ MASK.
Note: To switch off PLL2, and reduce power consumption, set the DX[2:0] bits.
63/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Bit 2:0 = DX[2:0]: PLL output clock divider factor. Refer to Table 17 for PLL divider settings,
where PLL CLOCK represents the output of the Multiplier section.
Table 17. PLL Divider Factors
DX2 DX1 DX0 CK
0 0 0 PLL CLOCK / 1
0 0 1 PLL CLOCK / 2
0 1 0 PLL CLOCK / 3
0 1 1 PLL CLOCK / 4
1 0 0 PLL CLOCK / 5
1 0 1 PLL CLOCK / 6
1 1 0 PLL CLOCK / 7
1 1 1 BYPASS (PLL OFF)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LPOW
ADC USB SPI0
res. PKG64 res. HDLC CAN DBG BOOT
EN FILT EN EN
EN
r r r r rw rw rw rw rw
This register includes Boot options and other global configuration controls.
Boot options are values latched on external BOOT pins at reset time, and visible to sofware
through these bits; they can be modified afterward to restore a different configuration
(memory map). See section 2.2 on page 22 for full description.
Configuration bits are fixed (hardware) device options, not available to user modification.
These bits allow reading the configuration value by the software.
Bit 8 = Reserved.
64/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
65/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The memory bank corresponding to BOOT value is mapped at address 0000.0000 in addition
to its normal position in the memory map, and the CPU starts fetching code from this block
after end of Reset sequence.
These bits may subsequently be modified by software, to map whatever memory at address
0000.0000.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw r r r rw rws rw rw rw rw rw
66/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When this bit is set, no Reset will be generated when a voltage drop occurs.
Note: For security reasons, it is allowed to set this bit only when the Low Power voltage
regulator is disabled (LPVRBYP bit = 1).
67/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Backup (Low-Power) Voltage Regulator is still active, supplying the Backup section: Real
Time Clock and wake-up logic.
When VRBYP = ‘1’, the Main Voltage Regulator is unconditionally switched off. In this case,
the device is only powered by the Low Power Voltage Regulator. In this configuration the
maximum allowed operation frequency is 1MHz and the PLL is disabled.
68/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
RCCU_ STOP_ CK2_1 CKAF_ LOCK_ WKP_ LVD_ RTC_A WDG SOFT CKSTO CK2 CKAF_ CSU_
8 DIV2 - LOCK
CFR I 6_I I I RES RES LARM RES RES P_EN _16 ST CKSEL
FREF_
RCCU_
18 - - - - - - - - FREEN RANG MX1 MX0 - DX2 DX1 DX0
PLL1CR
E
RCCU_
20 WFI
SMR
PCU_
40 reserved FACT
MDIVR
PCU_
44 reserved FACT2 reserved FACT1
PDIVR
PCU_
48 RST[15:0]
RSTR
LPOW USB
PCU_ PKG ADC SPI0
50 reserved - HDLC CAN DBG FILT BOOT
BOOTCR 64 EN EN
EN EN
69/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
4 I/O PORTS
Subject to the specific hardware characteristics of each I/O port listed in the datasheet device
pin description table, you can configure each port bit individually as input, output, alternate
function etc.
Each I/O port bit is freely programmable, however the I/O port registers have to be accessed
as 16-bit words. Byte or bit-wise access is not allowed.
TTL
CMOS I/O PIN
READ/WRITE
OUTPUT LATCH
Push-Pull
Tristate
Open Drain
FROM ON-CHIP Weak Push-Pull
PERIPHERAL
Alternate Function (OUT)
70/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PC1(n) 0 0 1 1 0 0 1 1
PC2(n) 0 0 0 0 1 1 1 1
At reset the I/O ports are configured as general purpose (memory mapped I/O).
When you write to the I/O Data register the data is always loaded in the Output Latch. The
Output Latch holds the data to be output while the Input Latch captures the data present on
the I/O pin.
A read access to the I/O Data register reads the Input Latch or the Output Latch depending on
whether the Port bit is configured as input or output.
The alternate functions for each pin are listed in the datasheet. If you configure a port bit as
Alternate Function, this disconnects the output latch and connects the pin to the output signal
of an on-chip peripheral.
To use the alternate function, you also have to enable it in the peripheral control registers.
Only one alternate function can be used on each pin
71/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Some ports have external interrupt capability (see datasheet). To use external interrupts, the
port must be configured in input mode. For more information on interrupts and wakeup lines,
refer to Section 5.
The Figure 20 on page 72 shows the Input Configuration of the I/O Port bit.
TTL
CMOS I/O PIN
OUTPUT LATCH
Tristate
72/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
■ The Output Buffer is turned on in Weak Push-Pull configuration and software can write the
appropriate level in the output latch to activate the weak pull-up or pull-down as required.
■ The data in the Output Latch drives the I/O pin (a logic zero activates a weak pull-down, a
logic one activates a weak pull-up)
■ A read access to the I/O Data register gets the Input Latch value.
The Figure 21 shows the Input PUPD Configuration of the I/O Port.
I/O PIN
OUTPUT LATCH
PU
PD
Weak Push-Pull
73/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Figure 22 on page 74 shows the Output Configuration of the I/O Port bit.
I/O PIN
OUTPUT LATCH
Open Drain
Push-Pull
74/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Figure 23 on page 75 shows the Alternate Function Configuration of the I/O Port bit.
I/O PIN
OUTPUT LATCH
Open Drain
Push-Pull
75/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Figure 24 on page 76 shows the High impedance-Analog Input Configuration of the I/O
Port bit.
Analog Input
INPUT LATCH
I/O PORT DATA REGISTER
I/O PIN
OUTPUT LATCH
Tristate
76/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
C015 C014 C013 C012 C011 C010 C09 C08 C07 C06 C05 C04 C03 C02 C01 C00
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
C115 C114 C113 C112 C111 C110 C19 C18 C17 C16 C15 C14 C13 C12 C11 C10
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
C215 C214 C213 C212 C211 C210 C29 C28 C27 C26 C25 C24 C23 C22 C21 C20
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
77/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
The following table summarizes the registers implemented in each I/O port.
Table 21. I/O-port Register Map
Addr. Register
Offset Name
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 PC0 C0[15:0]
4 PC1 C1[15:0]
8 PC2 C2[15:0]
C PD D[15:0]
78/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
5 INTERRUPTS
The ARM7 CPU provides two levels of interrupt, FIQ (Fast Interrupt Request) for fast, low
latency interrupt handling and IRQ (Interrupt Request) for more general interrupts.
The STR71x interrupt management system provides two interrupt management blocks: the
EIC and XTI. Refer to Figure 25.
Software Interrupt
XTI EIC
USB 16 External
14 I/O Port Interrupt IRQ5
Interrupts Lines 32 IRQ
Channels
IRQ ARM7TDMI®
On-Chip CORE
Interrupt
IRQn
Sources
Timer 0 2 FIQ
Channels FIQ
Watchdog
79/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
■ 32 maskable interrupt channels, mapped on the IRQ interrupt request line of the ARM CPU
■ 16 programmable priority levels for each interrupt channel mapped on IRQ
■ Hardware support for interrupt nesting (up to 16 interrupt requests can be nested), with
internal hardware nesting stack
■ 2 maskable interrupt channels, mapped on FIQ interrupt request line of the ARM CPU, with
neither priority nor vectorization
■ at register offset 0x18h, the jump instruction to the start address (defined by the user) of the
ISR of the highest priority interrupt.
■ 16 external interrupts from the XTI block are mapped on IRQ5.
If multiple interrupt sources are mapped on the same interrupt vector, software has read the
peripheral interrupt flag register to determine the exact source of interrupt (see Interrupt Flags
column in Table 23 on page 81)
80/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Two maskable interrupt sources are mapped on FIQ vectors, as shown in Table 24:
Table 24. FiQ Vector table
Vector Interrupt Source
FIQ0 T0.GI - Timer 0 Global Interrupt
FIQ1 WDG.IRQ - Watchdog timer interrupt
81/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
These sources are also available as normal IRQs. In most cases, you should only enable one
FIQ source in your application. If you enable both FIQ sources, then you can determine the
source of the interrupt by reading the FIQ pending bits in the the EIC register. Bear in mind
that FIQ has no priority mechanism, so if simultaneous FIQ events occur, software has to
manage the priority.
The ARM7TDMI CPU provides two levels of interrupt, FIQ (Fast Interrupt Request) for fast,
low latency interrupt handling and IRQ (Interrupt Request) for more general interrupts.
Hardware handling of multiple interrupt channels, interrupt priority and automatic vectorization
require therefore a separate Enhanced Interrupt Controller (EIC).
SIR Register
IER Register IPR Register
IRQ0
IE0 IP0 Interrupt
IRQ1 Vector Table Interrupt from line IRQx IRQx
IE1 IP1
(32 ENTRY) VECTOR
Interrupt
Interrupt Pending Highest Priority Interrupt
Enable bits
bits
CIPR
Current
STACK CTL (PUSH/POP) PRIORITY Interrupt
STACK Priority
(15 ENTRY)
IRQ
IRQ31 control logic
IE31 IP31 IRQ to
IRQ request ARM7TDMI
82/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The priority decoder is a combinational block continuously calculating the highest priority
pending IRQ. If there is a winner, it updates the EIC_IVR (Interrupt Vector Register) with the
address of the IRQ interrupt routine that has won the arbitration, and asserts the nIRQ
internal signal low. The nIRQ internal signal ORed with the inverted EIC IRQ enable bit
(IRQ_EN) corresponds to the ARM7TDMI® nIRQ signal.
Each channel has a 4-bit field, the SIPL (Source Interrupt Priority Level) in the EIC_SIRn
(Source Interrupt Register 0-31) defining the channel priority level in the range of 0 (lowest
priority) to 15 (highest).
If several channels are assigned with the same priority level, an internal hardware daisy chain
fixes the priority between them. The higher the channel address, the higher the priority. If
channel 2 and channel 6 are assigned to the same software priority level, and if they are both
pending at the same time, channel 6 will be served first.
In order to declare a channel as a winner, the channel must:
• Be pending (EIC_IPR0-1 - Interrupt Pending Register, 32 pending bits, one per channel).
In order to be pending, a channel has to be enabled (EIC_IER0-1 - Interrupt Enable
Register, 32 enable bits, one per channel).
• Have the highest priority level, higher than the current one (EIC_CIPR - Current Interrupt
Priority Register) and higher than any other pending interrupt channel.
• Have the highest position in the interrupt channel chain if there are multiple pending
interrupt channels with the same priority level.
The EIC_CIPR register provides the priority of the interrupt routine currently being served. At
reset, the EIC_CIPR is cleared. During an interrupt routine, it can be modified by software
from the initialized priority value stored in the EIC_SIRn (Source Interrupt Register 0-31) up to
15. Attempting to write a lower value that the one in EIC_SIRn will have no effect.
For safe operation, it is recommended to disable the global IRQ before modifying EIC_CIPR
EIC_SIR, or EIC_IPR pending IRQ clearing, to avoid dangerous race conditions. Moreover, if
IRQ_EN is cleared in an interrupt service routine, the pending bit related to the IRQ currently
being served must not be cleared, otherwise it will no longer be possible to recover EIC status
before popping the stack.
83/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Finite State Machine (FSM) has two states, READY and WAIT. The two states
correspond to the ARM7TDMI® nIRQ line being asserted (WAIT) or not (READY). The state
of nIRQ will be unconditionally masked (deasserted high) by the EIC global enable bit
IRQ_EN being cleared. After a reset the FSM is in READY state (EIC nIRQ line is high). When
the priority decoder elects a new winner, the FSM moves from READY to WAIT state and the
EIC nIRQ line is asserted low.
To move the FSM back to the ready state, it is mandatory to read the EIC_IVR register or to
reset the EIC cell. The EIC can be reset by a global reset resetting the entire device or by
clearing bit 14 in the APB2_SWRES register.
Reading the EIC_IVR always moves the FSM from WAIT to READY state, assuming that the
FSM was in WAIT state, and automatically releases the EIC nIRQ line.
5.2.1.3 Stack
84/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When the ARM7TDMI® decodes an IRQ interrupt request, the instruction at address 0x18 is
executed. By this time, the EIC_IVR register is updated with the address of the highest
pending interrupt routine. In order to get the maximum advantage from the EIC mechanism,
the instruction at address 0x18 can load the program counter with the address located in the
EIC_IVR. In this way, the CPU vector points directly to the right interrupt routine without any
software overhead.
As the priority decoder is always active, the arbitration is never stopped. It may happen that an
interrupt event asserts low the ARM7TDMI® nIRQ line, and if between the nIRQ line asserted
low and the EIC_IVR read operation a new highest priority event appears the EIC_IVR will
have the value corresponding to the highest priority pending interrupt when the EIC_IVR is
read.
It is not mandatory to read the EIC_IVR and to branch directly to the right interrupt routine with
the instruction at address 0x18. An alternative solution could be to branch to a single interrupt
entry point and to read the EIC_IVR register later on. The only mandatory operations are to
first read the EIC_IVR once only, then to clear the corresponding pending bit. From an EIC
standpoint, the interrupt is acknowledged when the EIC_IVR is read and is completed when
the corresponding pending bit is cleared. From an ARM7TDMI® core standpoint, the interrupt
is acknowledged when the ARM7TDMI® nIRQ line is asserted low and is completed when the
exception return sequence is executed.
The EIC nIRQ line is equivalent to the ARM7TMDI nIRQ line but in addition it is masked by the
EIC global enable bit (IRQ_EN). The EIC nIRQ line can be asserted low but if the global EIC
enable bit is not set, the ARM7TDMI® nIRQ line will not be asserted low.
The EIC_IPR is a read/clear register, so writing a ‘0’ has no effect, while writing a ‘1’ resets the
related bit. Therefore, refrain from using read-modify instructions to avoid corruption of the
EIC_IPR status. Most of the EIC pending bits are related to a peripheral pending bit. The
peripheral pending bit must be cleared prior to clearing the EIC pending bit. Otherwise the
EIC pending bit will be set again and the interrupt routine will be executed twice.
85/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
re-enable interrupt
6 INT. 7 INT. 1
4 INT. 4 INT. 5
INT. 5 CPL = 4
INT. 3 re-enable interrupt
3 INT. 4
INT. 3 INT. 3
CPL = 3 CPL = 3
re-enable interrupt
2 INT. 2 INT. 2
CPL = 2 re-enable interrupt re-enable interrupt CPL = 2
1 INT. 2 INT. 1
86/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Reading the EIC_IVR, while the FSM is in READY state, will have no effect. The value read
will be unpredictable. Actually, the EIC assigns the default IRQ routine addresses to the
EIC_IVR.
As a consequence of a bad programming procedure, the EIC_IVR could also have an
unpredictable value while the FSM is in WAIT state. This case has obviously to be avoided as
the CPU, when subsequently executing an interrupt subroutine, would execute it while the
value in the EIC_IVR register is not relevant. This would result in a stack EIC corruption as the
corresponding pending bit could be reset.
There are several cases where this can happen:
• When lowering a pending channel priority level in the EIC_SIRn register to a value equal
or lower than the current program priority.
• When the software clears some pending bits without taking care to execute the standard
interrupt routine sequence (see below).
In such cases, the priority decoder loses the winner while the EIC nIRQ line is still being
asserted. Only reading EIC_IVR will release the EIC nIRQ line.
The CPU will execute the interrupt routine without having a relevant value in the EIC_IVR
register, possibly corrupting the stack. If the corresponding pending bit is reset, it will not be
possible to execute the EIC stack pop operation.
The normal way to process an interrupt event is to read the EIC_IVR register only once in the
interrupt routine. Before exiting the interrupt routine, the corresponding peripheral and the EIC
pending bits must be cleared. As soon as the EIC_IVR is read, the application software can
read the EIC_CICR register to know which interrupt routine is currently executing, as long as
the EIC_IVR register is not used as a routine pointer.
If the EIC_IVR is not read in the interrupt routine the nIRQ line will not be released and the
interrupt will be executed twice. If the pending bit is already cleared, the EIC stack will be
corrupted as it will not be able to perform the pop operation.
Inside an interrupt routine, it is not an issue to clear pending bits having a lower priority level
than the current one, as the nIRQ line is not asserted low in this case. It can be an issue to
clear a pending bit that has a higher priority level because the EIC nIRQ line is already
asserted low, and when interrupts are re-enabled, the EIC stack will be corrupted.
Clearing a pending bit of an interrupt already in the stack will corrupt the stack.
In the main program, if the global interrupts are disabled, all interrupt sources are disabled
and all pending bits are cleared. If the nIRQ was already asserted low, as soon as the global
interrupts are enabled the CPU executes an interrupt routine. In this situation, the EIC_IVR
read will have an unpredictable value, corrupting the EIC stack.
87/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
There is only one safe way to clear pending bits without executing the corresponding interrupt
routine. This is to clear them from an IRQ routine that has a higher priority level. In this way,
the EIC nIRQ line is guaranteed to be released.
All EIC pending bits can be cleared including the ones that the user application wants to
address later on. The user code needs to make sure that, for those interrupts, the peripheral
pending bit is not cleared. By this way, the corresponding EIC pending bits will be set again.
As all EIC pending bits are cleared, the EIC stack is guaranteed to pop properly. An
alternative solution is to make sure that the EIC pending bit corresponding to the EIC_IVR
read is cleared.
read/clear (rc_w1) Software can read as well as reset this bit by writing ‘1’. Writing
‘0’ has no effect on the bit value.
88/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
89/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CIC[4:0]
- r
The EIC_CICR reports the number of the interrupt channel currently being serviced. There
are 32 possible channel IDs (0 to 31), so the significant register bits are only five (4 down to 0).
After reset, the EIC_CICR value is set to ‘0’ and is updated by the EIC only after the processor
has started servicing a valid IRQ interrupt request, i.e. one clock cycle after having read IVR.
• EIC_ICR IRQ_EN bit =1 (to have the nIRQ signal to ARM7TDMI active)’
• EIC_IER0 not all ‘0’ (at least one interrupt channel must be enabled)
• Among the interrupt channels enabled by the IERx registers, at least one must have the
SIPL field of the related SIR register not set to 0 because the EIC generates a processor
interrupt request (asserting the nIRQ line) ONLY IF it detects an enabled interrupt request
whose priority value is greater than the EIC_CIPR (Current Interrupt Priority
Register) value.
When the nIRQ signal to ARM7TDMI® is activated, the software will read the EIC_IVR
(Interrupt Vector Register). This read operation will advise the EIC logic that the ISR (Interrupt
Service Routine) has been initiated and that the CICR can be updated
The EIC_CICR value can not be modified by the software (read only register).
90/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CIP[3:0]
- rw
The EIC_CIPR register reports the priority value of the interrupt currently being serviced.
There are 16 possible priority values (0 to 15), so the significant register bits are only four (3
down to 0).
After reset, the Current Interrupt Priority (CIP) value is set to ‘0’ and is updated by the EIC only
after the processor has started servicing a valid IRQ interrupt request.
The EIC_CIPR value can be modified by software only to promote a running ISR to a higher
level and only during an ISR. The EIC logic will allow a write to the CIP field of any value equal
or greater than the priority value associated with the interrupt channel currently being
serviced.
e.g.: suppose the IRQ signal is set because of an enabled interrupt request on channel #4,
whose priority value is 7 (i.e. SIPL of SIR7 is 7); after software reads the EIC_IVR register, the
EIC will load the CIP field with 7. Until the interrupt service procedure is completed, writes of
91/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
values 7 up to 15 will be allowed, while attempts to modify the CIP content with priority lower
than 7 will have no effect.
The user software has to avoid a situation where the FSM is in WAIT state and the EIC_IVR
has an unpredictable value.
IVR[31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IVR[15:0]
The EIC_IVR is the EIC register that the sofware has to read after detecting the nIRQ signal
assertion.
The EIC_IVR read operation informs the EIC that the interrupt service routine (ISR)
corresponding to the pending request has been initiated.
92/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• no interrupt requests, whose priority is lower or equal than the current one can be
processed.
Note The EIC does not care about the IVR content: from the controller point of view it is a
simple concatenation of two 16-bit fields.
What has to be written in the IVR(31:16) is the higher part of the address pointing to
the memory location where the interrupt service routine begins. The field
SIRn(31:16) will contain the lower 16 bits (offset) of the memory address related to
the channel specific ISR.
Reading the IVR is acknowledged only when the CPU is not in debug mode and the user code
is executing in ARM IRQ mode.
93/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
In order for the controller to react to the 2 fast-interrupt (FIQ) channels, the enable bits 1 and
0 must be set to 1. Bits 3 and 2 indicate which channel is the source of the interrupt.
94/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
IER[31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IER[15:0]
rw
95/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
IPR[31:16]
rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IPR[15:0]
rc_w1
This is where the information about the channel interrupt status is kept. If
the corresponding bit in the enable register EIC_IER0 has been set, the
EIC_IPR0 bit set high implies that the related channel has asserted an
interrupt request that has not been serviced yet.
The bits are Read/Clear, i.e. writing a ‘0’ has no effect, whereas writing a ‘1’
clears the bit.
0: No interrupt pending.
1: Interrupt pending.
Note Before exiting an ISR, the software must have cleared the EIC_IPR0 bit related to the
executed routine. This bit clear operation will be interpreted by the EIC as End of
Interrupt (EOI) sequence and will allow the interrupt stack pop and processing of
new interrupts.
Note The Interrupt Pending bits must be carefully handled because the EIC state machine
and its internal priority hardware stack could be forced to a non recoverable condition
if unexpected pending bit clear operations are performed.
Example 1:
• Suppose that one or more interrupt channels are enabled, with a priority higher than zero.
As soon as an interrupt request arises, the EIC FSM processes the new input and asserts
the nIRQ signal. If before reading the EIC_IVR, for any reason, software clears the
pending bits, the nIRQ signal will remain asserted the same, even if no more interrupts
are pending.
96/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The only way to reset the nIRQ line logic is to read the EIC_IVR (0x18) register or to send
a software reset to the EIC.
Example 2:
• Suppose that one or more interrupt channels are enabled, with a priority higher than zero.
As soon as an interrupt request arises, the EIC FSM processes the new input and asserts
the nIRQ signal. If after reading the EIC_IVR, for any reason, software clears the pending
bit related to the serviced channel before completing the ISR, the EIC will detect an End
Of Interrupt command, will send a pop request to the priority stack and a new interrupt,
even of lower priority, will be processed.
To close an interrupt handling section (EOI), the interrupt pending clear operation must be
performed at the end of the related ISR, on the pending bit related to the serviced
channel. On the other hand, as soon as the pending bit of the serviced channel is cleared
(even by mistake) by the software, the EOI sequence is entered by the EIC.
Note In order to safely clear a pending bit of an IRQ not currently serviced, bit IRQ_EN of
EIC_ICR register should be cleared first. If this is not done, the EIC FSM can enter
an unrecoverable state.
In general, while in the main program, clearing a pending bit has no drawbacks.
When this operation is instead performed inside an IRQ routine it is very important
not to clear by mistake the IPR bit related to the IRQ currently being serviced. Since
IRQ_EN bit freezes the Stack, the pop operation for the current IRQ will not be
performed and will not be even possible in future when IRQs will be re-enabled.
97/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
SIV[31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved SIPL[3:0]
rw
There are 32 different EIC_SIRn registers for each input interrupt channel.
Bits 31:16 SIV[31:16]: Source Interrupt Vector for interrupt channel n (n=0... 31)
This field contains the interrupt channel dependent part of the interrupt
vector that will be provided to the processor when the EIC_IVR (address
0x18) is read.
Depending on what the processor expects (32 bit address or opcode, see
IVR description), the SIV will have to be loaded with the interrupt channel
ISR address offset or with the lower part (including the jump offset) of the
first ISR instruction opcode.
Bit 3:0 SIPL[3:0]: Source Interrupt Priority Level for interrupt channel n (n=0... 31)
These 4 bits allow to associate the interrupt channel to a priority value
between 0 and 15. The reset value is 0.
Note To be processed by the EIC logic an interrupt channel must have a priority level
higher than the current interrupt priority (CIP). The lowest value CIP can have is 0 so
all the interrupt sources that have a priority level equal to 0 will never generate an
IRQ request, even if properly enabled.
98/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
99/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Here are a few guidelines on how to program the EIC registers in order to get up and running
quickly. In the following, it is assumed we are dealing with standard interrupts and that we
want, for example, to detect an interrupt on channel #22, which has a priority of 5.
First of all, you have to assign the priority and the jump address for the interrupt channel #22.
Therefore:
■ Write the binary value “0101” in the SIPL field of the SIR22 register, i.e. priority 5 (it must be
non-zero to allow IRQ to be generated).
Two registers are used to supply the channel interrupt vector to the EIC controller (IVR[31:16]
and SIR22[31:16]):
■ write in SIR22[31:16], i.e. in the upper part of the SIR register related to channel #22, the
memory address offset (or the jump offset) where the Interrupt Service Routine, related to
interrupt channel #7, starts.
■ insert the base jump address (or the jump opcode) in the most significant half of the IVR
register, i.e. IVR[31:16].
Finally, you have to enable interrupts both at the global level and at the interrupt channel level.
To do this, perform these steps:
As far as the FIQ interrupts are concerned, since they have no vectorization or priority, only
the first two steps above are involved. Supposing you want to enable FIQ channel #1:
100/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Every Interrupt Service Routine (ISR) should have the following blocks of code.
1) STMFD sp!,{r5,lr} The workspace r5 plus the current return address lr_irq
is pushed into the system stack.
2) MRS r5,spsr Save the spsr into r5
3) STMFD sp!,{r5} Save r5
4) MSR cpsr_c,#0x1F Reenable IRQ, go into system mode
5) STMFD sp!,{lr} Save lr_sys for the system mode
Note r5 is a generic register chosen in this example from the available registers r0 to r12.
Since there is no way to save SPSR directly into the ARM stack, the operation is
executed in two steps using r5 as a temporary register.
The following two sections give some comments on the above code and hints on calling
subroutines from an ISR.
This first example refers to a LR_sys content loss problem: it is assumed that an ISR without
instruction 5) in the header routine (and consequently without instruction 1) in the footer
routine) has just started; the following happens:
101/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• The highest priority ISR ends and address B is restored: now the LR_sys value can be put
in the stack but its value has changed to address C (instead of A).
The work-around to avoid such a dangerous situation is to insert line 5) at the end of the
header routine and consequently line 1) at the beginning of the footer routine.
Similar reasons could lead register r5 to be corrupted. To fix this problem, lines 3) in header
and 4) in footer should be added.
To avoid this, the previous two instructions must be replaced with the single instruction:
LDMFD SP!, { ... , PC }
which automatically moves the stored link register directly into the program counter, making
the subroutine return correctly.
102/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Using the XTI registers, 14 I/O ports can be programmed as external interrupt lines or as
wake-up lines, able to wake-up the MCU from STOP mode.
Note: Only the WAKEUP pin (P0.15) can be used to wake-up from STANDBY mode
• Software interrupt
• USB End Suspend event.
Some external interrupt lines are mapped to I/O ports that can be enabled as inputs to the
CAN, I2C, BSPI or UART peripherals. This means you can program it so that any activity on
these serial buses will generate an interrupt and wake-up the MCU STOP mode.
Table 26. External Interrupt Line mapping
Wake-up
Wake-up line source
line #
0 SW interrupt - no HW connection.
1 USB wake-up event: generated while exiting from suspend mode
2 Port 2.8 - External Interrupt
3 Port 2.9 - External Interrupt
4 Port2.10 - External Interrupt
5 Port 2.11 - External Interrupt
6 Port 1.11 - CAN module receive pin (CANRX).
7 Port 1.13 - HDLC clock (HCLK) or I2C.0 Clock (I0.SCL)
8 Port 1.14 - HDLC receive pin (HRXD) or I2C.0 Data (SDA)
9 Port 0.1 - BSPI0 Slave Input data (S0.MOSI) or UART3 Receive Data Input (U3.Rx)
10 Port 0.2 - BSPI0 Slave Input serial clock (S0.SCLK) or I2C.1 Clock (I1.SCL)
11 Port 0.6 - BSPI1 Slave Input serial clock (S1.SCLK)
12 Port 0.8 - UART0 Receive Data Input (U0.Rx)
13 Port 0.10 - UART1 Receive Data Input (U1.Rx)
14 Port 0.13 - UART2 Receive Data Input (U2.Rx)
15 Port 0.15 - WAKEUP pin or RTC ALARM
103/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
5.4.1 Features
■ External interrupt lines can be used to wake-up the system from STOP mode
■ Programmable selection of Wake-up or Interrupt
■ Programmable Wake-up trigger edge polarity
■ All Wake-up Lines individually maskable
■ Wake-up interrupt generated by software
Figure 28. XTI Block Diagram
EXTERNAL INTERRUPT LINE[7:0] EXTERNAL INTERRUPT LINE[15:8]
XTI_TRL XTI_TRH
TRIGGERING LEVEL REGISTERS
XTI_MRL XTI_MRH
MASK REGISTERS
XTI_CTRL
WKUP-INT
ID1S
104/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
105/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The following paragraphs give some guidelines for designing an application program.
1. Program the polarity of the trigger event of external wake-up lines by writing registers
XTI_TRH and XTI_TRL.
2. Check that at least one mask bit (registers XTI_MRH, XTI_MRL) is equal to 1 (so at least
one external wake-up line is not masked).
3. Reset at least the unmasked pending bits: if unmasked pending bits are not cleared
STOP Mode cannot be entered.
4. Set the ID1S t and the WKUP-INT bits in the XTI_CTRL register.
5. To generate an interrupt on the associated channel (IRQ5), set the related enable, mask
and priority bits in the EIC registers.
6. Reset the STOP bit in register XTI_CTRL and STOP_I bit in CLK_FLAG register
(PRCCU).
7. To enter STOP mode, write the sequence 1, 0, 1 to the STOP bit in the XTI_CTRL regis-
ter. As already said, the three write operations are effective even though not executed in a
strict sequence (intermediate instructions are allowed): to reset the sequence it is suffi-
cient to write twice a logic ‘0’ to the STOP bit of XTI_CTRL register (corresponding any-
way to a bad sequence).
8. The code to be executed just after the STOP sequence must check the status of the
STOP and PRCCU STOP_I bits to determine if the device entered STOP mode or not. If
the device did not enter in STOP mode it is necessary to re-loop the procedure from the
beginning, otherwise the procedure continues from next point.
9. Poll the wake-up pending bits to determine which wake-up line caused the exit from STOP
mode.
10. Clear the wake-up pending bit that was set.
It is possible that several simultaneous wake-up events set different pending bits. In order to
accept subsequent events on external wake-up/interrupt lines, once the first interrupt routine
has been executed, the corresponding pending bit in XTI_PRx register it is necessary to clear
at least one pending bit: this operation allows a rising edge to be generated on the internal line
(if there is at least one more pending bit set and not masked) and so to set the interrupt
controller pending bit again. A further interrupt on the same channel of the interrupt controller
will be serviced depending on the status of the mask bit. Two possible situations may arise:
1. The user chooses to reset all pending bits: no further interrupt requests will be generated
on the channel. In this case the user has to:
– Reset the interrupt controller mask bit (to avoid generating a spurious interrupt request
during the next reset operations)
106/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Assuming the device is in Run mode: during the STOP bit setting sequence the following
cases may occur:
This can happen if an Interrupt request is acknowledged during the STOP bit setting
sequence. In this case polling the STOP and STOP_I bits will give:
STOP = 0, STOP_I = 0
This means that the device did not enter STOP mode due to a bad STOP bit setting
sequence: the user must retry the sequence.
STOP = 0, STOP_I = 1
This means that the device entered and exited STOP mode due to an external wake-up line
event.
Case 3: A wake-up event on the external wake-up lines occurs during the STOP bit
setting sequence
1. Interrupt requests to the CPU are disabled: in this case the device will not enter STOP
mode, no interrupt service routine will be executed and the program execution continues
from the instruction following the STOP bit setting sequence. The status of STOP and
STOP_I bits will be again:
STOP = 0, STOP_I = 0
The application can determine why the device did not enter STOP mode by polling the
pending bits of the external lines (at least one must be at 1).
2. Interrupt requests to CPU are enabled: in this case the device will not enter STOP mode
and the interrupt service routine will be executed. The status of STOP and STOP_I bits
107/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
will be again:
STOP = 0, STOP_I = 0
The interrupt service routine can determine why the device did not enter STOP mode by
polling the pending bits of the external lines (at least one must be at 1).
If the device really exits from STOP Mode, the PRCCU STOP_I bit is still set and must be
reset by software. Otherwise, if an Interrupt request was acknowledged during the STOP bit
setting sequence, the PRCCU STOP_I bit is reset. This means that the system has filtered the
STOP Mode entry request.
The WKUP-INT bit can be used by an interrupt routine to detect and to distinguish events
coming from Interrupt Mode or from Wake-up Mode, allowing the code to execute different
procedures.
To exit STOP mode, it is sufficient that one of the 16 wake-up lines (not masked) generates an
event: the clock restarts after the delay needed for the oscillator to restart.
Note: After waking-up from STOP Mode, software can successfully reset the pending bits
(edge sensitive), even though the corresponding wake-up line is still active (high or low,
depending on the Trigger Event register programming); the user must poll the external pin
status to detect and distinguish a short event from a long one (for example keyboard input with
keystrokes of varying length).
108/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
rw rw rw rw rw rw rw rw
- rw rw rw
Otherwise the device cannot enter STOP mode, the program code continues executing and
the STOP bit remains cleared.
The bit is reset by hardware if, while the device is in STOP mode, a wake-up interrupt comes
from any of the unmasked wake-up lines. The STOP bit is at 1 in the two following cases:
109/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
– After the first write instruction of the sequence (a 1 is written to the STOP bit)
– At the end of a successful sequence (i.e. after the third write instruction of the sequence)
CAUTION: If interrupt requests are acknowledged during the sequence, the system will not
enter STOP mode (since the sequence is not completed). At the end of the interrupt service
routine, it is recommended to reset the sequence state machine by twice writing a logic ‘0’ to
the STOP bit of XTI_CTRL register (corresponding anyway to a bad sequence). Otherwise,
the incomplete sequence will wait to be completed, (STOP bit is set only after the third correct
writing instruction of the sequence).
CAUTION: Whenever a STOP request is issued to the device,several clock cycles are needed
to enter STOP mode (see PRCCU chapter for further details). Hence the execution of the
instruction following the STOP bit setting sequence might start before entering STOP mode
(consider the ARM7 three-stage pipeline as well). In order to avoid executing any valid
instructions after a correct STOP bit setting sequence and before entering STOP mode, it is
mandatory to execute a few (at least 6) dummy instructions after the STOP bit setting
sequence (after the third valid STOP bit write operation. Additionally, if an interrupt routine is
executed when exiting from STOP mode , another set of dummy instructions (at least 3) must
be added, to take into account of the latency period. This takes into account that when STOP
mode is entered, the pipeline content is frozen as well, and when the system restarts the first
executed instruction was already fetched and decoded before entering STOP mode. Below is
some example code for managing STOP mode entering/exiting.
LDR R0, = APB0 + APB_XTIP ; Base address of Wake-up Module setting
If you want the system to restart from STOP mode without entering an interrupt service
routine, but simply by executing the first valid instruction just after the STOP sequence, only
the first six dummy instructions are needed.
110/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
WARNING: To avoid spurious interrupt requests on the IRQ5 channel of the EIC, it is
recommended to clear the corresponding enable bit in the EIC IER register before modifying
the ID1S bit.
rw rw rw rw rw rw rw rw
– If ID1S=1 and WKUP-INT=1 then an interrupt and a wake-up events are generated.
– If ID1S=1 and WKUP-INT=0 only an interrupt is generated.
– If ID1S=0 and WKUP-INT=1 only a wake-up event is generated.
– If ID1S=0 and WKUP-INT=0 neither interrupts nor wake-up events are generated.
rw rw rw rw rw rw rw rw
111/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
– If ID1S=1 and WKUP-INT=1 then an interrupt and a wake-up events are generated.
– If ID1S=1 and WKUP-INT=0 only an interrupt is generated.
– If ID1S=0 and WKUP-INT=1 only a wake-up event is generated.
– If ID1S=0 and WKUP-INT=0 neither interrupts nor wake-up events are generated.
If XTIMx is reset, no wake-up events can be generated.
rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw
112/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Caution:
1. As the external wake-up lines are edge triggered, no glitches must be generated on these
lines.
2. If either a rising or a falling edge on the external wake-up lines occurs while writing the
XTI_TRH or XTI_TRL registers, the pending bit will not be set.
113/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
114/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
6.1 Introduction
The RTC provides a set of continuously running counters which can be used, with suitable
software, to provide a clock-calendar function. The counter values can be written to set the
current time/date of the system.
The RTC includes an APB slave interface, to provide access by word to internal 32-bit
registers; this interface is disconnected from the APB bus when the main power supply is
removed.
6.3.1 Overview
The RTC consists of two main units (see Figure 29 on page 116), the first one (APB Interface)
is used to interface the APB bus. This unit also contains a set of 16-bit registers, synchronous
to PCLK2 Clock and accessible from the APB bus in read or write mode (for more details refer
to Register description section). The APB interface is clocked by the PCLK2 Clock.
The other unit (RTC Core) consists of a chain of programmable counters made of 2 main
blocks. The first block is the RTC precaler block which generates the RTC time base TR_CLK
which can be programmed to have a period of up 1 second. It includes a 20-bit programmable
divider (RTC Prescaler). Every TR_CLK period, the RTC generates an interrupt (SecInt) if it is
enabled in the RTC_CR register. The second block is a 32-bit programmable counter that can
be initialised to the current system time. The system time is incremented at the TR_CLK rate
and compared with a programmable date (stored in the RTC_ALR register) in order to
generate an alarm interrupt, if enabled in RTC_CR control register.
115/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Important note: Due to the fact the RTC has 2 different clock domains, after wake-up from
STOP mode, the APB interface (controlled by PCLK2) does not match the registers/counter
values of the RTC domain (clocked by the 32kHz osc) that keeps running while the system is
in STOP mode. Therefore to avoid reading wrong values in the APB interface, the application
should wait for at least 1 RTC clock period or 31.25us after exiting STOP mode before reading
the RTC registers. The same precaution applies to WFI mode, as the APB interface is
switched off and switched on at a later stage.
APB bus
APB interface
clock32
RTC_ALR
RTC_PRL
RTC_AlarmIT
=
reload
RTC_CNT RTC_DIV
TR_CLK
32-bit Progammable Counter
RTC Prescaler
RTC_OwIT
RTC_CR
116/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
All system registers are asynchronously reset by the System Reset or the Software Reset,
except RTC_ALR, RTC_CNT, RTC_DIV. These registers and the Real-time clock counter are
reset only by the Low Voltage Detector (Power-on reset). They are not affected by any other
reset source, nor by Standby mode.
After Power-on reset, the peripheral enters free-running mode. In this operating mode, the
RTC Prescaler and the Programmable counter start counting. Interrupt flags are activated too
but, since interrupt signals are masked, there is no interrupt generation. Interrupt signals must
be enabled by setting the appropriate bits in the RTC_CR register. In order to avoid spurious
interrupt generation it is recommended to clear old interrupt requests before enabling them.
To write in RTC_PRL, RTC_CNT, RTC_ALR registers, the peripheral must enter Configuration
mode. This is done setting the CNF bit in the RTC_CRL register.
In addition, writing to any RTC register is only enabled if the previous write operation is
finished. To enable the software to detect this situation, the RTOFF status bit is provided in the
RTC_CR register to indicate that an update of the registers is in progress. A new value can be
written to the RTC counters only when the status bit value is ’1’.
Configuration Procedure:
The write operation only executes when the CNF bit is cleared and it takes at least two
Clock32 cycles to complete.
117/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
- rw rw rw rw
These bits are used to mask interrupt requests. Note that at reset all interrupts are disabled,
so it is possible to write to the RTC registers to ensure that no interrupt requests are pending
after initialization. It is not possible to write RTC_CRH register when the peripheral is
completing a previous write operation (flagged by RTOFF=0, see “Configuration mode” on
page 117).
The functions of the RTC are controlled by this control register. Some bits must be written
using a specific configuration procedure (see “Configuration mode” on page 117).
118/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The functions of the RTC are controlled by this control register. It is not possible to write
RTC_CR register when the peripheral is completing a previous write operation (flagged by
RTOFF=0, see “Configuration mode” on page 117).
119/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Any interrupt request remains pending until the appropriate RTC_CR request bit is reset by
software, notifying that the interrupt request has been granted.
Note that at reset the interrupts are disabled, it is possible to write the RTC registers and no
interrupt requests are pending.
The Prescaler Load registers keep the period counting value of the RTC prescaler. They are
write protected by the RTOFF bit in the RTC_CR register, write operation is allowed if RTOFF
value is ‘1’.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved PRSL(19:16)
- w
120/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PRSL(15:0)
Note: The reset value sets the TR_CLK signal period to 1 sec for a 32-kHz oscillator.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved RTCDIV(19:16)
- r
Every period of TR_CLK the counter inside RTC prescaler is reloaded with the value stored in
the RTC_PRL register. To get an accurate time measurement it is possible to read the current
value of the prescaler counter, stored into the RTC_DIV register, without stopping it. This reg-
ister is read only and it is reloaded by hardware after any change in RTC_PRL or RTC_CNT
registers.
121/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
RTCDIV(15:0)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC_CNT[31:16]
rw
The RTC core has one 32-bit programmable counter, accessed through 2 16-bit registers; the
count rate is based on the TR_Clock time reference, generated by the prescaler. RTC_CNT
registers keep the counting value of this counter. They are write protected by bit RTOFF in the
RTC_CR register, write operation is allowed if RTOFF value is ‘1’. A write operation on the
upper (RTC_CNTH) or lower (RTC_CNTL) registers directly loads the corresponding
programmable counter and reloads the RTC Prescaler. When reading, the current value in the
counter (system date) is returned. The counters keep on running while the external clock
oscillator is working even if the main system is powered down (Standby mode).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC_CNT[15:0]
rw
122/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC_ALR[31:16]
When the programmable counter reaches the 32-bit value stored in the RTC_ALR register, an
alarm is triggered and the RTC_alarmIT interrupt request is generated. This register is write
protected by the RTOFF bit in the RTC_CR register, write operation is allowed if the RTOFF
value is ‘1’.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC_ALR[15:0]
123/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
124/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7.1 Introduction
The Watchdog Timer peripheral can be used as free-running timer or as Watchdog to resolve
processor malfunctions due to hardware or software failures.
If the WE bit of WDG_CR register is not written to ‘1’ by software, the peripheral enters
Free-running Timer mode.
When in this operating mode as the SC bit of WDG_CR register is written to ‘1’ the WDG_VR
value is loaded in the Counter and the Counter starts counting down.
Figure 30. Watchdog Timer Functional Block
WDG_PR WDG_VR
Register Register
PCLK2 sys_RES
8-bit
16-bit Counter EC_int
Prescaler
WE SC
When it reaches the end of count value (0000h) an End of Count interrupt is generated
(EC_int) and the WDG_VR value is re-loaded. The Counter runs until the SC bit is cleared.
125/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
If the WE bit of WDG_CR register is written to ‘1’ by software, the peripheral enters Watchdog
mode. This operating mode can not be changed by software (the SC bit has no effect and WE
bit cannot be cleared).
As the peripheral enters in this operating mode, the WDG_VR value is loaded in the Counter
and the Counter starts counting down. When it reaches the end of count value (0000h) a
system reset signal is generated (sys_RES).
If a sequence of two consecutive values (0xA55A and 0x5AA5) is written in the WDG_KR
register see Section 7.4, the WDG_VR value is re-loaded in the Counter, so the End of count
can be avoided.
reserved SC WE
- rw rw
126/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
- rw rw rw rw rw rw rw rw
TV15 TV14 TV13 TV12 TV11 TV10 TV9 TV8 TV7 TV6 TV5 TV4 TV3 TV2 TV1 TV0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
(PR[7:0]+1)*(TV[15:0]+1)*tPCLK2/1000 (µs)
127/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT15 CNT14 CNT13 CNT12 CNT11 CNT10 CNT9 CNT8 CNT7 CNT6 CNT5 CNT4 CNT3 CNT2 CNT1 CNT0
r r r r r r r r r r r r r r r r
reserved EC
- r-c
reserved ECM
- rw
Bit15:1 = Reserved.
128/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
0 WDG_CR reserved SC WE
8 WDG_VR TV(15:0)
C WDG_CNT TV(15:0)
10 WDG_SR reserved EC
18 WDG_KR K[15:0]
129/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
8 TIMER (TIM)
8.1 Introduction
A timer consists of a 16-bit counter driven by a programmable prescaler.
It may be used for a variety of purposes, including pulse length measurement of up to two
input signals (input capture) or generation of up to two output waveforms (output compare and
PWM).
Pulse lengths and waveform periods can be modulated from a very wide range using the timer
prescaler.
130/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Timer0:
• T0.EXTCLK input is directly connected to CK pin through a prescaler, which divides the
input frequency by eight.
• T0.ICAP_B is connected to RTC ALARM; this allows to synchronize Timer0 and the Real
Time Clock.
Timer2:
8.4.1 Counter
The principal block of the Programmable Timer is a 16-bit counter and its associated 16-bit
registers.
Writing in the Counter Register (CNTR) resets the counter to the FFFCh value.
The timer clock source can be either internal or external selecting ECKEN bit of CR1 register.
When ECKEN = 0, the frequency depends on the prescaler division bits (CC7-CC0) of the
CR2 register.
An overflow occurs when the counter rolls over from FFFFh to 0000h then the TOF bit of the
SR register is set. An interrupt is generated if TOIE bit of the CR2 register is set; if this
condition is false, the interrupt remains pending to be issued as soon as it becomes true.
Clearing the overflow interrupt request is done by a write access to the SR register while the
TOF bit is set with the data bus 13-bit at ‘0’, while all the other bits shall be written to ‘1’ (the
SR register is clear only, so writing a ‘1’ in a bit has no effect: this makes possible to clear a
pending bit without risking to clear a new coming interrupt request from another source).
131/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PCLK2 CLOCK
PERIPHERAL INTERFACE
16 16 16 16 16
EXEDG
OVERFLOW
EXTCLK OUTPUT COMPARE EDGE DETECT
DETECT CIRCUIT A
ICAPA
CIRCUIT
CIRCUIT
6
EDGE DETECT
ICAPB
CIRCUIT B
SR
LATCH B OCMPB
ICAIE OCAIE TOIE ICBIE OCBIE CC7 CC6 CC5 CC4 CC3 CC2 CC1 CC0
CR2
EN FOLVB FOLVAOLVLB OLVLA OCAE OCBE OPM PWM IEDGB IEDGA EXEDG ECKEN
TOIE ICAIE ICBIE OCAIE OCFB
TOF ICFA ICFB OCFA OCBIE CR1
. . . . .
132/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The status of the EXEDG bit determines the type of level transition on the external clock pin
EXTCLK that will trigger the counter.
The counter is synchronized with the rising edge of the internal clock coming from the PCLK2
block.
At least four rising edges of the PCLK2 clock must occur between two consecutive active
edges of the external clock; thus the external clock frequency must be less than a quarter of
the PCLK2 clock frequency.
PCLK2 CLOCK
INTERNAL RESET
TIMER STROBE:
PCLK2 CLOCK
INTERNAL RESET
TIMER STROBE
133/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PCLK2 CLOCK
INTERNAL RESET
TIMER STROBE
The two input capture 16-bit registers (ICAR and ICBR) are used to latch the value of the
counter after a transition detected by the ICAPi pin (see Figure 35).
The active transition is software programmable through the IEDGi bit of the Control Register
(CR1).
8.4.4.1 Procedure
To use the input capture function select the following in the CR1 and CR2 registers:
134/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
1. A write access to the SR register while the ICFi bit is cleared, 15-bit at ‘0’ for ICAPA and
12-bit at ‘0’ for ICAPB.
ICAPA
CC7-CC0
from CR2
135/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PCLK2 CLOCK
ICAPi PIN
ICAPi FLAG
This function can be used to control an output waveform or indicating when a period of time
has elapsed.
When a match is found between the Output Compare register and the counter, the output
compare function:
Two 16-bit registers Output Compare Register A (OCAR) and Output Compare Register B
(OCBR) contain the value to be compared to the counter each timer clock cycle.
These registers are readable and writable and are not affected by the timer hardware. A reset
event changes the OCiR value to 8000h.
8.4.5.1 Procedure
To use the output compare function, select the following in the CR1/CR2 registers:
– Set the OCiE bit if an output is needed then the OCMPi pin is dedicated to the output com-
136/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
pare i function.
– Select the timer clock (ECKGEN) and the prescaler division factor (CC7÷CC0).
– Select the OLVLi bit to applied to the OCMPi pins after the match occurs.
– Set OCAIE (OCBIE) if only compare A (compare B) needs to generate an interrupt.
Clearing the output compare interrupt request is done by a write access to the SR register
while the OCFi bit is cleared, 14-bit at ‘0’ for OCAR and 12-bit at ‘0’ for OCBR.
If the OCiE bit is not set, the OCMPi pin is at ‘0’ and the OLVLi bit will not appear when match
is found.
The value in the 16-bit OCiR register and the OLVLi bit should be changed after each
successful comparison in order to control an output waveform or establish a new elapsed
timeout.
The OCiR register value required for a specific timing application can be calculated using the
following formula:
∆t * fPCLK2
∆ OCiR = (CC7÷CC0+1)
Where:
137/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Latch
B
OCMPB
16-bit 16-bit
OCFA OCFB
OCAR OCBR
(Control Register 2) CR2 high byte
TIMER STROBE
138/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Bits 11:8 of CR1 register and bits 7:0 of CR2 are used (Refer to Section 8.6 for detailed
Register Description).
When the FOLVA bit is set, the OLVLA bit is copied to the OCMPA pin if PWM and OPM are
both cleared. When FOLVB bit is set, the OLVLB bit is copied to the OCMPB pin.
The OLVLi bit has to be toggled in order to toggle the OCMPi pin when it is enabled (OCiE
bit=1).
Note
One Pulse mode enables the generation of a pulse when an external event occurs. This mode
is selected via the OPM bit in the CR1 register.
The one pulse mode uses the Input Capture A function (trigger event) and the Output
Compare A function.
8.4.7.1 Procedure
To use one pulse mode, select the following in the CR1 register:
– Using the OLVLA bit, select the level to be applied to the OCMPA pin after the pulse.
– Using the OLVLB bit, select the level to be applied to the OCMPA pin during the pulse.
– Select the edge of the active transition on the ICAPA pin with the IEDGA bit.
– Set the OCAE bit, the OCMPA pin is then dedicated to the Output Compare A function.
– Set the OPM bit.
– Select the timer clock (ECKGEN) and the prescaler division factor (CC7-CC0).
Load the OCAR register with the value corresponding to the length of the pulse (see the
formula in next Section 8.4.8.1).
139/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Counter is
When initialized
event occurs to FFFCh
on ICAPA
OCMPA = OLVLB
When
Counter
= OCAR OCMPA = OLVLA
Then, on a valid event on the ICAPA pin, the counter is initialized to FFFCh and OLVLB bit is
loaded on the OCMPA pin after four clock period. When the value of the counter is equal to the
value of the contents of the OCAR register, the OLVLA bit is output on the OCMPA pin (See
Figure 40).
Note
– The OCFA bit cannot be set by hardware in one pulse mode but the OCFB bit can generate
an Output Compare interrupt.
– The ICFA bit is set when an active edge occurs and can generate an interrupt if the ICAIE
bit is set. The ICAR register will have the value FFFCh.
– When the Pulse Width Modulation (PWM) and One Pulse Mode (OPM) bits are both set with
FOLVA= 1, the OPM mode is the only active one, otherwise the PWM mode is the only active
one.
– Forced Compare B mode works in OPM
– Input Capture B function works in OPM
– When OCAR = FFFBh in OPM, then a pulse of width FFFFh is generated
– If event occurs on ICAPA again before the Counter reaches the value of OCAR, then the
Counter will be reset again and the pulse generated might be longer than expected as in Fig-
ure 40.
– If a write operation is performed on the counter register before the Counter reaches the value
of OCAR, then the Counter will be reset again and the pulse generated might be longer than
expected.
– If a write operation is performed on the counter register after the Counter reaches the value
of OCAR, then there will have no effect on the waveform.
140/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
COUNTER .... FFFC FFFD FFFE 2ED0 2ED1 2ED2 FFFC FFFD
2ED3
ICAPA
4 clock period
COUNTER .... FFFC FFFD FFFE 0010 FFFC 2ED0 2ED1 2ED2 FFFC FFFD
2ED3
ICAPA
Pulse Width Modulation mode enables the generation of a signal with a frequency and pulse
length determined by the value of the OCAR and OCBR registers.
The pulse width modulation mode uses the complete Output Compare A function plus the
OCBR register.
8.4.8.1 Procedure
To use pulse width modulation mode select the following in the CR1 register:
– Using the OLVLA bit, select the level to be applied to the OCMPA pin after a successful com-
parison with OCAR register.
– Using the OLVLB bit, select the level to be applied to the OCMPA pin after a successful com-
parison with OCBR register.
– Set OCAE bit: the OCMPA pin is then dedicated to the output compare A function.
– Set the PWM bit.
– Select the timer clock (ECKGEN) and the prescaler division factor (CC7-CC0).
141/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Load the OCBR register with the value corresponding to the period of the signal.
Load the OCAR register with the value corresponding to the length of the pulse if (OLVLA=0
and OLVLB=1).
If OLVLA=1 and OLVLB=0 the length of the pulse is the difference between the OCBR and
OCAR registers.
The OCiR register value required for a specific timing application can be calculated using the
following formula:
t * fPCLK2 - 5
OCiR Value = tPRESC
Where:
The Output Compare B event causes the counter to be initialized to FFFCh (See Figure 42).
Figure 41. Pulse Width Modulation Mode Cycle
When
Counter OCMPA = OLVLA
= OCAR
Note
– The OCFA bit cannot be set by hardware in PWM mode, but OCFB is set every time counter
matches OCBR.
– The Input Capture function is available in PWM mode.
– When Counter = OCBR, then OCFB bit will be set. This can generate an interrupt if OCBIE
is set. This interrupt will help any application where pulse-width or period needs to be
changed interactively.
– When the Pulse Width Modulation (PWM) and One Pulse Mode (OPM) bits are both set with
FOLVA = 0, the PWM mode is the only active one, otherwise the OPM mode is the only ac-
tive one.
142/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
– The value loaded in OCBR must always be greater than that in OCAR to produce mean-
ingful waveforms. Note that 0000h is considered to be greater than FFFCh or FFFDh or
FFFEh or FFFFh.
– When OCAR > OCBR, no waveform will be generated.
– When OCBR = OCAR, a square waveform with 50% duty cycle will be generated as in Fig-
ure 42.
– When OCBR and OCAR are loaded with FFFCh (the counter reset value) then a square
waveform will be generated & the counter will remain stuck at FFFCh. The period will be cal-
culated using the following formula:
– When OCAR is loaded with FFFCh (the counter reset value) then the waveform will be gen-
erated as in Figure 42.
– When FOLVA bit is set and PWM bit is set, then PWM mode is the active one. But if FOLVB
bit is set then the OLVLB bit will appear on OCMPB (when OCBE bit = 1).
– When a write is performed on CNTR register in PWM mode, then the Counter will be reset
and the pulse-width/period of the waveform generated may not be as desired.
143/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
COUNTER 34E2 FFFC FFFD FFFE 2ED0 2ED1 2ED2 34E2 FFFC
144/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The PWM Input functionality enables the measurement of the period and the pulse width of an
external waveform. The initial edge is programmable.
It uses the two Input Capture registers and the Input signal of the Input Capture A module.
8.4.9.1 Procedure
The CR2 register must be programmed as needed for Interrupt generation. To use pulse width
modulation mode select the following in the CR1 register:
To have a coherent measure the interrupt should be linked to the Input Capture A Interrupt,
reading in ICAR the period value and in ICBR the pulse width.
tPRESC * ICAR
Period =
fPCLK2
tPRESC * ICBR
Pulse =
fPCLK2
Where:
The Input Capture A event causes the counter to be initialized to 0000h, allowing a new
measure to start. The first Input Capture on ICAPA do not generate the corresponding
interrupt request.
145/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
COUNTER 34E2 0000 0001 0002 2ED0 2ED1 2ED2 34E2 0000
ICAPA
PERIOD = ICAPA
PULSE LENGTH = ICAPB
Capture B,
Capture A, pulse width measurement
period measurement,
reset counter
Interrupt
To use the interrupt features, for each interrupt channel used, perform the following sequence:
– Set the OCiIE and/or ICiIE and/or TOIE bits of CR2 register to enable the peripheral to per-
form interrupt requests on the desired events
The selection of the five or single interrupt channels is performed by connecting the desired
interrupt wire(s) to the interrupt controller when the timer peripheral is instantiated inside a
system.
146/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
MSB LSB
r r r r r r r r r r r r r r r r
This is a 16-bit read only register that contains the counter value transferred by the Input
Capture A event.
MSB LSB
r r r r r r r r r r r r r r r r
This is a 16-bit read only register that contains the counter value transferred by the Input
Capture B event.
MSB LSB
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
This is a 16-bit register that contains the value to be compared to the CNTR register and
signalled on OCMPA output.
147/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
MSB LSB
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
This is a 16-bit register that contains the value to be compared to the CNTR register and
signalled on OCMPB output.
MSB LSB
r r r r r r r r r r r r r r r r
This is a 16-bit register that contains the counter value. By writing in this register the counter
is reset to the FFFCh value.
EN PWMI Reserved FOLVB FOLVA OLVLB OLVLA OCBE OCAE OPM PWM IEDGB IEDGA EXEDG ECKEN
rw rw - rw rw rw rw rw rw rw rw rw rw rw rw
148/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
149/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
ICAIE OCAIE TOE ICBIE OCBIE reserved CC7 CC6 CC5 CC4 CC3 CC2 CC1 CC0
rw rw rw rw rw - rw rw rw rw rw rw rw rw
150/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
151/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
ECKE
14 TIMn_CR1 EN PWMI reserved FOLVB FOLVA OLVLB OLVLA OCBE OCAE OPM PWM IEDGB IEDGA EXEDG
N
18 TIMn_CR2 ICAIE OCAIE TOE ICBIE OCBIE reserved CC7 CC6 CC5 CC4 CC3 CC2 CC1 CC0
152/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
9.1 Introduction
The C_CAN consists of the CAN Core, Message RAM, Message Handler, Control Registers
and Module Interface (Refer to Figure 44).
The CAN Core performs communication according to the CAN protocol version 2.0 part A and
B. The bit rate can be programmed to values up to 1MBit/s. For the connection to the physical
layer, additional transceiver hardware is required.
For communication on a CAN network, individual Message Objects are configured. The
Message Objects and Identifier Masks for acceptance filtering of received messages are
stored in the Message RAM.
All functions concerning the handling of messages are implemented in the Message Handler.
These functions include acceptance filtering, the transfer of messages between the CAN Core
and the Message RAM, and the handling of transmission requests as well as the generation
of the module interrupt.
The register set of the C_CAN can be accessed directly by the CPU through the module
interface. These registers are used to control/configure the CAN Core and the Message
Handler and to access the Message RAM.
153/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
CAN Core
CAN Protocol Controller and Rx/Tx Shift Register for serial/parallel conversion of messages.
Message RAM
Stores Message Objects and Identifier Masks.
Registers
All registers used to control and to configure the C_CAN.
Message Handler
State Machine that controls the data transfer between the Rx/Tx Shift Register of the CAN
Core and the Message RAM as well as the generation of interrupts as programmed in the
Control and Configuration Registers.
Module Interface
C_CAN interfaces to the AMBA APB 16-bit bus from ARM.
Figure 44. Block Diagram of the CAN Peripheral
CAN_TX CAN_RX
CAN Peripheral
MESSAGE HANDLER
CAN CORE
Message RAM
REGISTERS
CAN_WAIT_B
MODULE INTERFACE
DataOUT
DataIN
Reset
Clock
Control
Interrupt
Address(7:0)
154/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
While the Init bit is set, all message transfers to and from the CAN bus are stopped and the
status of the CAN_TX output pin is recessive (HIGH). The Error Management Logic (EML)
counters are unchanged. Setting the Init bit does not change any configuration register.
To initialize the CAN Controller, software has to set up the Bit Timing Register and each
Message Object. If a Message Object is not required, the corresponding MsgVal bit should be
cleared. Otherwise, the entire Message Object has to be initialized.
Access to the Bit Timing Register and to the BAud Rate Prescaler (BRP) Extension Register
for configuring bit timing is enabled when the Init and Configuration Change Enable (CCE) bits
in the CAN Control Register are both set.
Resetting the Init bit (by CPU only) finishes the software initialization. Later, the Bit Stream
Processor (BSP) (see Section 9.8.10: Configuring the Bit Timing on page 195) synchronizes
itself to the data transfer on the CAN bus by waiting for the occurrence of a sequence of 11
consecutive recessive bits (≡ Bus Idle) before it can take part in bus activities and start the
message transfer.
The initialization of the Message Objects is independent of Init and can be done on the fly, but
the Message Objects should all be configured to particular identifiers or set to not valid before
the BSP starts the message transfer.
To change the configuration of a Message Object during normal operation, software has to
start by resetting the corresponding MsgVal bit. When the configuration is completed, MsgVal
is set again.
Received messages are stored in their appropriate Message Objects if they pass the
Message Handler’s acceptance filtering. The whole message including all arbitration bits,
DLC and eight data bytes are stored in the Message Object. If the Identifier Mask is used, the
arbitration bits which are masked to “don’t care” may be overwritten in the Message Object.
Software can read or write each message any time through the Interface Registers and the
Message Handler guarantees data consistency in case of concurrent accesses.
155/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
transmission. If several transmit messages are assigned to the same Message Object (when
the number of Message Objects is not sufficient), the whole Message Object has to be
configured before the transmission of this message is requested.
The transmission of any number of Message Objects may be requested at the same time.
Message objects are transmitted subsequently according to their internal priority. Messages
may be updated or set to not valid any time, even when their requested transmission is still
pending. The old data will be discarded when a message is updated before its pending
transmission has started.
Depending on the configuration of the Message Object, the transmission of a message may
be requested autonomously by the reception of a remote frame with a matching identifier.
• When a transmission starts, bit TxRqst of the respective Message Buffer is cleared, while
bit NewDat remains set.
• When the transmission completed successfully, bit NewDat is cleared.
• When a transmission fails (lost arbitration or error), bit NewDat remains set.
To restart the transmission, the CPU should set the bit TxRqst again.
156/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In Silent Mode, the C_CAN is able to receive valid data frames and valid remote frames, but it
sends only recessive bits on the CAN bus and it cannot start a transmission. If the CAN Core
is required to send a dominant bit (ACK bit, Error Frames), the bit is rerouted internally so that
the CAN Core monitors this dominant bit, although the CAN bus may remain in recessive
state. The Silent Mode can be used to analyse the traffic on a CAN bus without affecting it by
the transmission of dominant bits. Figure 45 shows the connection of signals CAN_TX and
CAN_RX to the CAN Core in Silent Mode.
CAN_TX CAN_RX
CAN Peripheral
=1
• •
Tx Rx
CAN Core
157/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
CAN_TX CAN_RX
CAN Peripheral
• •
Tx Rx
CAN Core
This mode is provided for self-test functions. To be independent from external stimulation, the
CAN Core ignores acknowledge errors (recessive bit sampled in the acknowledge slot of a data/
remote frame) in Loop Back Mode. In this mode, the CAN Core performs an internal feedback
from its Tx output to its Rx input. The actual value of the CAN_RX input pin is disregarded by
the CAN Core. The transmitted messages can be monitored on the CAN_TX pin.
Figure 47. CAN Core in Loop Back Mode Combined with Silent Mode
CAN_TX CAN_RX
CAN Peripheral
=1
• •
Tx Rx
CAN Core
158/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The IF1 Registers are used as Transmit Buffer. The transmission of the contents of the IF1
Registers are requested by writing the Busy bit of the IF1 Command Request Register to one.
The IF1 Registers are locked while the Busy bit is set. The Busy bit indicates that the
transmission is pending.
As soon the CAN bus is idle, the IF1 Registers are loaded into the shift register of the CAN
Core and the transmission is started. When the transmission has been completed, the Busy
bit is reset and the locked IF1 Registers are released.
A pending transmission can be aborted at any time by resetting the Busy bit in the IF1
Command Request Register while the IF1 Registers are locked. If the CPU has reset the
Busy bit, a possible retransmission in case of lost arbitration or in case of an error is disabled.
The IF2 Registers are used as a Receive Buffer. After the reception of a message the
contents of the shift register is stored into the IF2 Registers, without any acceptance filtering.
Additionally, the actual contents of the shift register can be monitored during the message
transfer. Each time a read Message Object is initiated by writing the Busy bit of the IF2
Command Request Register to one, the contents of the shift register are stored in the IF2
Registers.
In Basic Mode, the evaluation of all Message Object related control and status bits and the
control bits of the IFn Command Mask Registers are turned off. The message number of the
Command request registers is not evaluated. The NewDat and MsgLst bits in the IF2
Message Control Register retain their function, DLC3-0 indicate the received DLC, and the
other control bits are read as ‘0’.
The output mode for the CAN_TX pin is selected by programming the Tx1 and Tx0 bits of the
CAN Test Register.
The three test functions of the CAN_TX pin interfere with all CAN protocol functions. CAN_TX
must be left in its default function when CAN message transfer or any of the test modes (Loop
Back Mode, Silent Mode, or Basic Mode) are selected.
159/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The two sets of interface registers (IF1 and IF2) control the CPU access to the Message RAM.
They buffer the data to be transferred to and from the RAM, avoiding conflicts between CPU
accesses and message reception/transmission.
read/write (rw) The software can read and write to these bits.
160/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Additionally the busoff state is reset and the output CAN_TX is set to recessive (HIGH). The
value 0x0001 (Init = ‘1’) in the CAN Control Register enables the software initialization. The
C_CAN does not influence the CAN bus until the CPU resets the Init bit to ‘0’.
The data stored in the Message RAM is not affected by a hardware reset. After powering on,
the contents of the Message RAM are undefined.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCE
DAR
Test
EIE
SIE
rw rw rw rw rw rw rw
161/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Bit 4 Reserved
This is a reserved bit. This bit is always read as ‘0’ and must always be
written with ‘0’.
Note The busoff recovery sequence (see CAN Specification Rev. 2.0) cannot be
shortened by setting or resetting the Init bit. If the device goes in the busoff state, it
will set Init of its own accord, stopping all bus activities. Once Init has been cleared
by the CPU, the device will then wait for 129 occurrences of Bus Idle (129 * 11
consecutive recessive bits) before resuming normal operations. At the end of the
busoff recovery sequence, the Error Management Counters will be reset.
During the waiting time after resetting Init, each time a sequence of 11 recessive bits has
been monitored, a Bit0Error code is written to the Status Register, enabling the CPU to readily
check up whether the CAN bus is stuck at dominant or continuously disturbed and to monitor
the proceeding of the busoff recovery sequence.
162/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EWarn
EPass
RxOk
TxOk
BOff
Reserved LEC
r r r rw rw rw
163/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Bits 2:0 LEC[2:0]: Last Error Code (Type of the last error to occur on the CAN bus)
The LEC field holds a code, which indicates the type of the last error to
occur on the CAN bus. This field will be cleared to ‘0’ when a message has
been transferred (reception or transmission) without error. The unused code
‘7’ may be written by the CPU to check for updates. Table 32 describes the
error codes.
0 No Error
1 Stuff Error: More than 5 equal bits in a sequence have occurred in a part of a
received message where this is not allowed.
2 Form Error: A fixed format part of a received frame has the wrong format.
3 AckError: The message this CAN Core transmitted was not acknowledged by
another node.
4 Bit1Error: During the transmission of a message (with the exception of the arbitra-
tion field), the device wanted to send a recessive level (bit of logical value ‘1’), but
the monitored bus value was dominant.
6 CRCError: The CRC check sum was incorrect in the message received, the CRC
received for an incoming message does not match with the calculated CRC for the
received data.
7 Unused: When the LEC shows the value ‘7’, no CAN bus event was detected since
the CPU wrote this value to the LEC.
Status Interrupts:
A Status Interrupt is generated by bits BOff and EWarn (Error Interrupt) or by RxOk, TxOk,
and LEC (Status Change Interrupt) assuming that the corresponding enable bits in the CAN
Control Register are set. A change of bit EPass or a write to RxOk, TxOk, or LEC will never
generate a Status Interrupt.
Reading the Status Register will clear the Status Interrupt value (8000h) in the Interrupt
Register, if it is pending.
164/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RP REC[6:0] TEC[7:0]
r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
Bit 15 Reserved
This is a reserved bit. This bit is always read as ‘0’ and must always be
written with ‘0’.
165/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Bits 11:8 TSeg1: Time segment before the sample point minus Sync_Seg
0x01-0x0F: valid values for TSeg1 are [ 1 … 15 ]. The actual interpretation
by the hardware of this value is such that one more than the value
programmed is used.
Note With a module clock APB_CLK of 8 MHz, the reset value of 0x2301 configures the
C_CAN for a bit rate of 500 kBit/s. The registers are only writable if bits CCE and Init
in the CAN Control Register are set.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Tx[1:0]
LBack
Silent
Basic
Rx
Reserved Res
r rw rw rw rw
166/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Write access to the Test Register is enabled by setting the Test bit in the CAN Control
Register. The different test functions may be combined, but Tx1-0 ≠ “00” disturbs message
transfer.
167/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved BRPE
rw
The function of the two interface register sets is identical except for the Basic test mode. They
can be used the way one set of registers is used for data transfer to the Message RAM while
the other set of registers is used for the data transfer from the Message RAM, allowing both
processes to be interrupted by each other. Table 33 IF1 and IF2 Message Interface Register
Set on page 169 provides an overview of the two Interface Register sets.
Each set of Interface Registers consists of Message Buffer Registers controlled by their own
Command Registers. The Command Mask Register specifies the direction of the data transfer
and which parts of a Message Object will be transferred. The Command Request Register is
used to select a Message Object in the Message RAM as target or source for the transfer and
to start the action specified in the Command Mask Register.
168/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r rw
A message transfer is started as soon as the application software has written the message
number to the Command Request Register. With this write operation, the Busy bit is
automatically set to notify the CPU that a transfer is in progress. After a waiting time of 3 to 6
APB_CLK periods, the transfer between the Interface Register and the Message RAM is
completed. The Busy bit is cleared.
169/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note When a Message Number that is not valid is written into the Command Request
Register, the Message Number will be transformed into a valid value and that
Message Object will be transferred.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ClrIntPnd
NewDat
TxRqst/
WR/RD
Control
Data A
Data B
Mask
Arb
Reserved
rw rw rw rw rw rw rw rw
The control bits of the IFn Command Mask Register specify the transfer direction and select
which of the IFn Message Buffer Registers are source or target of the data transfer.
170/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Bits 6:0 These bits of IFn Command Mask Register have different functions
depending on the transfer direction:
Direction = Write
171/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The bits of the Message Buffer registers mirror the Message Objects in the Message RAM.
The function of the Message Objects bits is described in Section 9.6.3.10: Message Object in
the Message Memory on page 175.
172/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Msk[15:0]
rw
The function of the Msk bits is described in Section 9.6.3.10: Message Object in the Message
Memory on page 175.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw r rw
The function of the Message Objects bits is described in the Section 9.6.3.10: Message
Object in the Message Memory on page 175.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID[15:0]
rw
The function of the Message Objects bits is described in the Section 9.6.3.10: Message
Object in the Message Memory on page 175.
173/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
The function of the Message Objects bits is described in the Section 9.6.3.10: Message
Object in the Message Memory on page 175.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
NewDat
MsgLst
TxRqst
UMask
RmtEn
IntPnd
RxIE
TxIE
EoB
Reserved DLC[3:0]
rw rw rw rw rw rw rw rw rw rw
The function of the Message Objects bits is described in the Section 9.6.3.10: Message
Object in the Message Memory on page 175.
The data bytes of CAN messages are stored in the IFn Message Buffer Registers in the
following order:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
174/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
In a CAN Data Frame, Data(0) is the first, Data(7) is the last byte to be transmitted or received.
In CAN’s serial bit stream, the MSB of each byte will be transmitted first.
There are 32 Message Objects in the Message RAM. To avoid conflicts between CPU access
to the Message RAM and CAN message reception and transmission, the CPU cannot directly
access the Message Objects, these accesses are handled through the IFn Interface
Registers.
Message Object
The Arbitration Registers ID28-0, Xtd, and Dir are used to define the identifier and type of
outgoing messages and are used (together with the mask registers Msk28-0, MXtd, and MDir)
for acceptance filtering of incoming messages. A received message is stored in the valid
175/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Message Object with matching identifier and direction set to receive (Data Frame) or transmit
(Remote Frame). Extended frames can be stored only in Message Objects with Xtd set,
standard frames in Message Objects with Xtd clear. If a received message (Data Frame or
Remote Frame) matches more than one valid Message Object, it is stored into that with the
lowest message number. For details see Section 9.8.2.3, “Acceptance Filtering of Received
Messages,” on page 189.
Note The application software must reset the MsgVal bit of all unused
Messages Objects during the initialization before it resets bit Init
in the CAN Control Register. This bit must also be reset before the
identifier Id28-0, the control bits Xtd, Dir, or the Data Length Code
DLC3-0 are modified, or if the Messages Object is no longer
required.
Note If the UMask bit is set to one, the Message Object’s mask bits
have to be programmed during initialization of the Message
Object before MsgVal is set to one.
176/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note This bit is used to concatenate two or more Message Objects (up
to 32) to build a FIFO Buffer. For single Message Objects (not
belonging to a FIFO Buffer), this bit must always be set to one. For
details on the concatenation of Message Objects see
Section 9.8.7, “Configuring a FIFO Buffer,” on page 192.
1: The Message Handler or the application software has written new data
into the data portion of this Message Object.
0: No new data has been written into the data portion of this Message
Object by the Message Handler since last time this flag was cleared by the
application software.
177/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
MsgLst Message Lost (only valid for Message Objects with direction = receive)
1: The Message Handler stored a new message into this object when
NewDat was still set, the CPU has lost a message.
0: No message lost since last time this bit was reset by the CPU.
178/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note The Data Length Code of a Message Object must be defined the
same as in all the corresponding objects with the same identifier
at other nodes. When the Message Handler stores a data frame, it
will write the DLC to the value given by the received message.
Note The Data 0 Byte is the first data byte shifted into the shift register
of the CAN Core during a reception while the Data 7 byte is the
last. When the Message Handler stores a Data Frame, it will write
all the eight data bytes into a Message Object. If the Data Length
Code is less than 8, the remaining bytes of the Message Object
will be overwritten by unspecified values.
179/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IntId[15:0]
Bits 15:0 IntId15:0 Interrupt Identifier (Table 35 indicates the source of the interrupt)
If several interrupts are pending, the CAN Interrupt Register will point to the
pending interrupt with the highest priority, disregarding their chronological
order. An interrupt remains pending until the application software has
cleared it. If IntId is different from 0x0000 and IE is set, the IRQ interrupt
signal to the EIC is active. The interrupt remains active until IntId is back to
value 0x0000 (the cause of the interrupt is reset) or until IE is reset.
The Status Interrupt has the highest priority. Among the message interrupts,
the Message Object’ s interrupt priority decreases with increasing message
number.
180/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TxRqst[32:17]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TxRqst[16:1]
These registers hold the TxRqst bits of the 32 Message Objects. By reading the TxRqst bits,
the CPU can check which Message Object in a Transmission Request is pending. The TxRqst
bit of a specific Message Object can be set/reset by the application software through the IFn
Message Interface Registers or by the Message Handler after reception of a Remote Frame
or after a successful transmission.
Bits 31:16 TxRqst32-17 Transmission Request Bits (of all Message Objects)
0: This Message Object is not waiting for transmission.
1: The transmission of this Message Object is requested and is not yet done.
Bits 15:0 TxRqst16-1 Transmission Request Bits (of all Message Objects)
0: This Message Object is not waiting for transmission.
1: The transmission of this Message Object is requested and is not yet done.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
NewDat[32:17]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
181/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
NewDat[16:1]
These registers hold the NewDat bits of the 32 Message Objects. By reading out the NewDat
bits, the CPU can check for which Message Object the data portion was updated. The
NewDat bit of a specific Message Object can be set/reset by the CPU through the IFn
Message Interface Registers or by the Message Handler after reception of a Data Frame or
after a successful transmission.
Bits 31:16 NewDat32-17 New Data Bits (of all Message Objects)
0: No new data has been written into the data portion of this Message
Object by the Message Handler since the last time this flag was cleared
by the application software.
1: The Message Handler or the application software has written new
data into the data portion of this Message Object.
Bits 15:0 NewDat16-1 New Data Bits (of all Message Objects)
0: No new data has been written into the data portion of this Message
Object by the Message Handler since the last time this flag was cleared
by the application software.
1: The Message Handler or the application software has written new
data into the data portion of this Message Object.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IntPnd[32:17]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IntPnd[16:1]
These registers contain the IntPnd bits of the 32 Message Objects. By reading the IntPnd
bits, the CPU can check for which Message Object an interrupt is pending. The IntPnd bit of a
182/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
specific Message Object can be set/reset by the application software through the IFn
Message Interface Registers or by the Message Handler after reception or after a successful
transmission of a frame. This will also affect the value of IntId in the Interrupt Register.
Bits 31:16 IntPnd32-17 Interrupt Pending Bits (of all Message Objects)
0: This message object is not the source of an interrupt.
1: This message object is the source of an interrupt.
Bits 15:0 IntPnd16-1 Interrupt Pending Bits (of all Message Objects)
0: This message object is not the source of an interrupt.
1: This message object is the source of an interrupt.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MsgVal[32:17]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MsgVal[16:1]
These registers hold the MsgVal bits of the 32 Message Objects. By reading the MsgVal bits,
the application software can check which Message Object is valid. The MsgVal bit of a specific
Message Object can be set/reset by the application software via the IFn Message Interface
Registers.
Bits 31:16 MsgVal32-17 Message Valid Bits (of all Message Objects)
0: This Message Object is ignored by the Message Handler.
1: This Message Object is configured and should be considered by the
Message Handler.
Bits 15:0 MsgVal16-1 Message Valid Bits (of all Message Objects)
0: This Message Object is ignored by the Message Handler.
1: This Message Object is configured and should be considered by the
Message Handler.
183/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Addr 1 1 1 1 1 1
Register Name 9 8 7 6 5 4 3 2 1 0
offset 5 4 3 2 1 0
DAR
CCE
Test
re
EIE
SIE
00h CAN_CR Reserved IE Init
s
EWarn
EPass
RxOk
TxOk
BOff
04h CAN_SR Reserved LEC
R
08h CAN_ERR REC6-0 TEC7-0
P
re
0Ch CAN_BTR TSeg2 TSeg1 SJW BRP
s
LBack
Silent
Basic
Tx1
Tx0
Rx
B
20h CAN_IF1_CRR u Reserved Message Number
sy
ClrIntPnd
TxRqst/
WR/RD
Control
Data A
Data B
Mask
Arb
M M
re
2Ch CAN_IF1_M2R Xt Di Msk28-16
s
d r
M
s
Xt Di
34h CAN_IF1_A2R g ID28-16
d r
V
al
184/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Addr 1 1 1 1 1 1
Register Name 9 8 7 6 5 4 3 2 1 0
offset 5 4 3 2 1 0
NewDat
MsgLst
TxRqst
UMask
RmtEn
IntPnd
RxIE
TxIE
EoB
38h CAN_IF1_MCR Reserved DLC3-0
CAN_IF1_DA1
3Ch Data(1) Data(0)
R
CAN_IF1_DA2
40h Data(3) Data(2)
R
CAN_IF1_DB1
44h Data(5) Data(4)
R
CAN_IF1_DB2
48h Data(7) Data(6)
R
B
80h CAN_IF2_CRR u Reserved Message Number
sy
ClrIntPnd
TxRqst/
WR/RD
Control
Data A
Data B
Mask
Arb
M M
re
8Ch CAN_IF2_M2R Xt Di Msk28-16
s
d r
M
s
Xt Di
94h CAN_IF2_A2R g ID28-16
d r
V
al
NewDat
MsgLst
TxRqst
UMask
RmtEn
IntPnd
RxIE
TxIE
EoB
CAN_IF2_DA1
9Ch Data(1) Data(0)
R
185/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Addr 1 1 1 1 1 1
Register Name 9 8 7 6 5 4 3 2 1 0
offset 5 4 3 2 1 0
CAN_IF2_DA2
A0h Data(3) Data(2)
R
CAN_IF2_DB1
A4h Data(5) Data(4)
R
CAN_IF2_DB2
A8h Data(7) Data(6)
R
Note Reserved bits are read as 0’ except for IFn Mask 2 Register where they are read as
’1’.
186/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When the Init bit in the CAN Control Register is cleared, the CAN Protocol Controller state
machine of the CAN_Core and state machine of the Message Handler control the internal
data flow of the C_CAN. Received messages that pass the acceptance filtering are stored in
the Message RAM, messages with pending transmission request are loaded into the
CAN_Core’s Shift Register and are transmitted through the CAN bus.
The application software reads received messages and updates messages to be transmitted
through the IFn Interface Registers. Depending on the configuration, the CPU is interrupted
on certain CAN message and CAN error events.
187/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The respective Command Mask Register specifies whether a complete Message Object or
only parts of it will be transferred. Due to the structure of the Message RAM, it is not possible
to write single bits/bytes of one Message Object. It is always necessary to write a complete
Message Object into the Message RAM. Therefore, the data transfer from the IFn Registers to
the Message RAM requires a read-modify-write cycle. First, those parts of the Message
Object that are not to be changed are read from the Message RAM and then the complete
contents of the Message Buffer Registers are written into the Message Object.
Figure 48. Data transfer between IFn Registers and Message RAM
START
No
Write Command Request Register
Yes
Busy = 1
CAN_WAIT_B = 0
No Yes
WR/RD = 1
Busy = 0
CAN_WAIT_B = 1
188/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
After a partial write of a Message Object, the Message Buffer Registers that are not selected
in the Command Mask Register will set the actual contents of the selected Message Object.
After a partial read of a Message Object, the Message Buffer Registers that are not selected
in the Command Mask Register will be left unchanged.
After a successful transmission and also if no new data was written to the Message Object
(NewDat = ‘0’) since the start of the transmission, the TxRqst bit of the Message Control
register (CAN_IFn_MCR) will be reset. If TxIE bit of the Message Control register
(CAN_IFn_MCR) is set, IntPnd bit of the Interrupt Identifier register (CAN_IDR) will be set
after a successful transmission. If the C_CAN has lost the arbitration or if an error occurred
during the transmission, the message will be retransmitted as soon as the CAN bus is free
again. Meanwhile, if the transmission of a message with higher priority has been requested,
the messages will be transmitted in the order of their priority.
To scan the Message RAM for a matching Message Object, the Acceptance Filtering unit is
loaded with the arbitration bits from the CAN Core shift register. The arbitration and mask
fields (including MsgVal, UMask, NewDat, and EoB) of Message Object 1 are then loaded into
the Acceptance Filtering unit and compared with the arbitration field from the shift register.
This is repeated with each following Message Object until a matching Message Object is
found or until the end of the Message RAM is reached.
If a match occurs, the scan is stopped and the Message Handler FSM proceeds depending on
the type of frame (Data Frame or Remote Frame) received.
189/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The NewDat bit is set to indicate that new data (not yet seen by the CPU) has been received.
The application software should reset NewDat bit when the Message Object has been read. If
at the time of reception, the NewDat bit was already set, MsgLst is set to indicate that the
previous data (supposedly not seen by the CPU) is lost. If the RxIE bit is set, the IntPnd bit is
set, causing the Interrupt Register to point to this Message Object.
The TxRqst bit of this Message Object is reset to prevent the transmission of a Remote
Frame, while the requested Data Frame has just been received.
MsgLst
TxRqst
RmtEn
IntPnd
Mask
RxIE
Data
TxIE
EoB
Arb
Dir
190/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Arbitration Register values (ID28-0 and Xtd bit) are provided by the application. They
define the identifier and type of the outgoing message. If an 11-bit Identifier (“Standard
Frame”) is used, it is programmed to ID28 - ID18. The ID17 - ID0 can then be disregarded.
If the TxIE bit is set, the IntPnd bit will be set after a successful transmission of the Message
Object.
If the RmtEn bit is set, a matching received Remote Frame will cause the TxRqst bit to be set;
the Remote Frame will autonomously be answered by a Data Frame.
The Data Register values (DLC3-0, Data0-7) are provided by the application, TxRqst and
RmtEn may not be set before the data is valid.
The Mask Registers (Msk28-0, UMask, MXtd, and MDir bits) may be used (UMask=’1’) to
allow groups of Remote Frames with similar identifiers to set the TxRqst bit. The Dir bit should
not be masked.
When only the (eight) data bytes are updated, first 0x0087 is written to the Command Mask
Register and then the number of the Message Object is written to the Command Request
Register, concurrently updating the data bytes and setting TxRqst.
To prevent the reset of TxRqst at the end of a transmission that may already be in progress
while the data is updated, NewDat has to be set together with TxRqst. For details see Section
9.8.2.2: Message Transmission on page 189.
When NewDat is set together with TxRqst, NewDat will be reset as soon as the new
transmission has started.
MsgLst
TxRqst
RmtEn
IntPnd
Mask
RxIE
Data
TxIE
EoB
Arb
Dir
191/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Arbitration Registers values (ID28-0 and Xtd bit) are provided by the application. They
define the identifier and type of accepted received messages. If an 11-bit Identifier (“Standard
Frame”) is used, it is programmed to ID28 - ID18. Then ID17 - ID0 can be disregarded. When
a Data Frame with an 11-bit Identifier is received, ID17 - ID0 will be set to ‘0’.
If the RxIE bit is set, the IntPnd bit will be set when a received Data Frame is accepted and
stored in the Message Object.
The Data Length Code (DLC3-0) is provided by the application. When the Message Handler
stores a Data Frame in the Message Object, it will store the received Data Length Code and
eight data bytes. If the Data Length Code is less than 8, the remaining bytes of the Message
Object will be overwritten by unspecified values.
The Mask Registers (Msk28-0, UMask, MXtd, and MDir bits) may be used (UMask=’1’) to
allow groups of Data Frames with similar identifiers to be accepted. The Dir bit should not be
masked in typical applications.
Typically, the CPU will write first 0x007F to the Command Mask Register and then the number
of the Message Object to the Command Request Register. This combination will transfer the
whole received message from the Message RAM into the Message Buffer Register.
Additionally, the bits NewDat and IntPnd are cleared in the Message RAM (not in the Message
Buffer).
If the Message Object uses masks for acceptance filtering, the arbitration bits shows which of
the matching messages have been received.
The actual value of NewDat shows whether a new message has been received since the last
time this Message Object was read. The actual value of MsgLst shows whether more than
one message has been received since the last time this Message Object was read. MsgLst
will not be automatically reset.
By means of a Remote Frame, the CPU may request another CAN node to provide new data
for a receive object. Setting the TxRqst bit of a receive object will cause the transmission of a
Remote Frame with the receive object’s identifier. This Remote Frame triggers the other CAN
node to start the transmission of the matching Data Frame. If the matching Data Frame is
received before the Remote Frame could be transmitted, the TxRqst bit is automatically reset.
192/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
To concatenate two or more Message Objects into a FIFO Buffer, the identifiers and masks (if
used) of these Message Objects have to be programmed to matching values. Due to the
implicit priority of the Message Objects, the Message Object with the lowest number will be
the first Message Object of the FIFO Buffer. The EoB bit of all Message Objects of a FIFO
Buffer except the last have to be programmed to zero. The EoB bits of the last Message
Object of a FIFO Buffer is set to one, configuring it as the End of the Block.
When a message is stored in a Message Object of a FIFO Buffer, the NewDat bit of this
Message Object is set. By setting NewDat while EoB is zero, the Message Object is locked for
further write access by the Message Handler until the application software has written the
NewDat bit back to zero.
Messages are stored into a FIFO Buffer until the last Message Object of this FIFO Buffer is
reached. If none of the preceding Message Objects is released by writing NewDat to zero, all
further messages for this FIFO Buffer will be written into the last Message Object of the FIFO
Buffer and therefore overwrite previous messages.
To assure the correct function of a FIFO Buffer, the CPU should read the Message Objects
starting at the FIFO Object with the lowest message number.
Figure 49 shows how a set of Message Objects which are concatenated to a FIFO Buffer can
be handled by the CPU.
193/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
No
NewDat = 1
Yes
Yes
EoB = 1
No
MessageNum = MessageNum + 1
194/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Status Interrupt has the highest priority. Among the message interrupts, interrupt priority
of the Message Object decreases with increasing message number.
A message interrupt is cleared by clearing the IntPnd bit of the Message Object. The Status
Interrupt is cleared by reading the Status Register.
The interrupt identifier, IntId, in the Interrupt Register, indicates the cause of the interrupt.
When no interrupt is pending, the register will hold the value zero. If the value of the Interrupt
Register is different from zero, then there is an interrupt pending and, if IE is set, the IRQ
interrupt signal to the EIC is active. The interrupt remains active until the Interrupt Register is
back to value zero (the cause of the interrupt is reset) or until IE is reset.
The value 0x8000 indicates that an interrupt is pending because the CAN Core has updated
(not necessarily changed) the Status Register (Error Interrupt or Status Interrupt). This
interrupt has the highest priority. The CPU can update (reset) the status bits RxOk, TxOk and
LEC, but a write access of the CPU to the Status Register can never generate or reset an
interrupt.
All other values indicate that the source of the interrupt is one of the Message Objects. IntId
points to the pending message interrupt with the highest interrupt priority.
The CPU controls whether a change of the Status Register may cause an interrupt (bits EIE
and SIE in the CAN Control Register) and whether the interrupt line becomes active when the
Interrupt Register is different from zero (bit IE in the CAN Control Register). The Interrupt
Register will be updated even when IE is reset.
The CPU has two possibilities to follow the source of a message interrupt. First, it can follow
the IntId in the Interrupt Register and second it can poll the Interrupt Pending Register (see
See “Interrupt Pending Registers 1 & 2 (CAN_IPnR)” on page 182..).
An interrupt service routine that is reading the message that is the source of the interrupt may
read the message and reset the Message Object’s IntPnd at the same time (bit ClrIntPnd in
the Command Mask Register). When IntPnd is cleared, the Interrupt Register will point to the
next Message Object with a pending interrupt.
In many cases, the CAN bit synchronization will amend a faulty configuration of the CAN bit
timing to such a degree that only occasionally an error frame is generated. However, in the
195/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
case of arbitration, when two or more CAN nodes simultaneously try to transmit a frame, a
misplaced sample point may cause one of the transmitters to become error passive.
The analysis of such sporadic errors requires a detailed knowledge of the CAN bit
synchronization inside a CAN node and interaction of the CAN nodes on the CAN bus.
CAN supports bit rates in the range of lower than 1 kBit/s up to 1000 kBit/s. Each member of
the CAN network has its own clock generator, usually a quartz oscillator. The timing
parameter of the bit time (i.e. the reciprocal of the bit rate) can be configured individually for
each CAN node, creating a common bit rate even though the oscillator periods of the CAN
nodes (fosc) may be different.
The frequencies of these oscillators are not absolutely stable, small variations are caused by
changes in temperature or voltage and by deteriorating components. As long as the variations
remain inside a specific oscillator tolerance range (df), the CAN nodes are able to
compensate for the different bit rates by re-synchronizing to the bit stream.
According to the CAN specification, the bit time is divided into four segments (see Figure 50).
The Synchronization Segment, the Propagation Time Segment, the Phase Buffer Segment 1
and the Phase Buffer Segment 2. Each segment consists of a specific, programmable number
of time quanta (see Table 39). The length of the time quantum (tq), which is the basic time unit
of the bit time, is defined by the CAN controller’s system clock fAPB and the BRP bit of the Bit
Timing Register (CAN_BTR): tq = BRP / fAPB.
The Synchronization Segment, Sync_Seg, is that part of the bit time where edges of the CAN
bus level are expected to occur. The distance between an edge, that occurs outside of
Sync_Seg, and the Sync_Seg is called the phase error of that edge. The Propagation Time
Segment, Prop_Seg, is intended to compensate for the physical delay times within the CAN
network. The Phase Buffer Segments Phase_Seg1 and Phase_Seg2 surround the Sample
Point. The (Re-)Synchronization Jump Width (SJW) defines how far a re-synchronization may
move the Sample Point inside the limits defined by the Phase Buffer Segments to compensate
for edge phase errors.
Figure 50. Bit Timing
1 Time Quantum
(t ) Sample Point
q
196/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
This table describes the minimum programmable ranges required by the CAN protocol
A given bit rate may be met by different bit time configurations, but for the proper function of
the CAN network the physical delay times and the oscillator’s tolerance range have to be
considered.
Any CAN node synchronized to the bit stream on the CAN bus will be out of phase with the
transmitter of that bit stream, caused by the signal propagation time between the two nodes.
The CAN protocol’s non-destructive bitwise arbitration and the dominant acknowledge bit
provided by receivers of CAN messages requires that a CAN node transmitting a bit stream
must also be able to receive dominant bits transmitted by other CAN nodes that are
synchronized to that bit stream. The example in Figure 51 shows the phase shift and
propagation times between two CAN nodes.
197/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Node B
Node A
Delay A_to_B >= node output delay(A) + bus line delay(A→B) + node input delay(B)
Prop_Seg >= Delay A_to_B + Delay B_to_A
Prop_Seg >= 2 • [max(node output delay+ bus line delay + node input delay)]
In this example, both nodes A and B are transmitters, performing an arbitration for the CAN
bus. Node A has sent its Start of Frame bit less than one bit time earlier than node B, therefore
node B has synchronized itself to the received edge from recessive to dominant. Since node
B has received this edge delay (A_to_B) after it has been transmitted, B’s bit timing segments
are shifted with respect to A. Node B sends an identifier with higher priority and so it will win
the arbitration at a specific identifier bit when it transmits a dominant bit while node A
transmits a recessive bit. The dominant bit transmitted by node B will arrive at node A after the
delay (B_to_A).
Due to oscillator tolerances, the actual position of node A’s Sample Point can be anywhere
inside the nominal range of node A’s Phase Buffer Segments, so the bit transmitted by node B
must arrive at node A before the start of Phase_Seg1. This condition defines the length of
Prop_Seg.
If the edge from recessive to dominant transmitted by node B arrives at node A after the start
of Phase_Seg1, it can happen that node A samples a recessive bit instead of a dominant bit,
resulting in a bit error and the destruction of the current frame by an error flag.
The error occurs only when two nodes arbitrate for the CAN bus that have oscillators of
opposite ends of the tolerance range and that are separated by a long bus line. This is an
example of a minor error in the bit timing configuration (Prop_Seg to short) that causes
sporadic bus errors.
Some CAN implementations provide an optional 3 Sample Mode but the C_CAN does not. In
this mode, the CAN bus input signal passes a digital low-pass filter, using three samples and
a majority logic to determine the valid bit value. This results in an additional input delay of 1 tq,
requiring a longer Prop_Seg.
198/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The Phase Buffer Segments (Phase_Seg1 and Phase_Seg2) and the Synchronization Jump
Width (SJW) are used to compensate for the oscillator tolerance. The Phase Buffer Segments
may be lengthened or shortened by synchronization.
Synchronizations occur on edges from recessive to dominant, their purpose is to control the
distance between edges and Sample Points.
Edges are detected by sampling the actual bus level in each time quantum and comparing it
with the bus level at the previous Sample Point. A synchronization may be done only if a
recessive bit was sampled at the previous Sample Point and if the bus level at the actual time
quantum is dominant.
An edge is synchronous if it occurs inside of Sync_Seg, otherwise the distance between edge
and the end of Sync_Seg is the edge phase error, measured in time quanta. If the edge
occurs before Sync_Seg, the phase error is negative, else it is positive.
A Hard Synchronization is done once at the start of a frame and inside a frame only when
Re-synchronizations occur.
• Hard Synchronization
After a hard synchronization, the bit time is restarted with the end of Sync_Seg,
regardless of the edge phase error. Thus hard synchronization forces the edge, which has
caused the hard synchronization to lie within the synchronization segment of the restarted
bit time.
• Bit Re-synchronization
Re-synchronization leads to a shortening or lengthening of the bit time such that the
position of the sample point is shifted with regard to the edge.
When the phase error of the edge which causes Re-synchronization is positive,
Phase_Seg1 is lengthened. If the magnitude of the phase error is less than SJW,
Phase_Seg1 is lengthened by the magnitude of the phase error, else it is lengthened by
SJW.
When the phase error of the edge, which causes Re-synchronization is negative,
Phase_Seg2 is shortened. If the magnitude of the phase error is less than SJW,
Phase_Seg2 is shortened by the magnitude of the phase error, else it is shortened by
SJW.
When the magnitude of the phase error of the edge is less than or equal to the programmed
value of SJW, the results of Hard Synchronization and Re-synchronization are the same. If the
magnitude of the phase error is larger than SJW, the Re-synchronization cannot compensate
the phase error completely, an error (phase error - SJW) remains.
199/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Only one synchronization may be done between two Sample Points. The Synchronizations
maintain a minimum distance between edges and Sample Points, giving the bus level time to
stabilize and filtering out spikes that are shorter than (Prop_Seg + Phase_Seg1).
Apart from noise spikes, most synchronizations are caused by arbitration. All nodes
synchronize “hard” on the edge transmitted by the “leading” transceiver that started
transmitting first, but due to propagation delay times, they cannot become ideally
synchronized. The “leading” transmitter does not necessarily win the arbitration, therefore the
receivers have to synchronize themselves to different transmitters that subsequently “take the
lead” and that are differently synchronized to the previously “leading” transmitter. The same
happens at the acknowledge field, where the transmitter and some of the receivers will have
to synchronize to that receiver that “takes the lead” in the transmission of the dominant
acknowledge bit.
Synchronizations after the end of the arbitration will be caused by oscillator tolerance, when
the differences in the oscillator’s clock periods of transmitter and receivers sum up during the
time between synchronizations (at most ten bits). These summarized differences may not be
longer than the SJW, limiting the oscillator’s tolerance range.
The examples in Figure 52 show how the Phase Buffer Segments are used to compensate for
phase errors. There are three drawings of each two consecutive bit timings. The upper
drawing shows the synchronization on a “late” edge, the lower drawing shows the
synchronization on an “early” edge, and the middle drawing is the reference without
synchronization.
recessive
Rx-Input “late” Edge
dominant
Sample-Point Sample-Point
Sample-Point Sample-Point
Sample-Point Sample-Point
recessive
Rx-Input “early” Edge dominant
200/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In the first example, an edge from recessive to dominant occurs at the end of Prop_Seg. The
edge is “late” since it occurs after the Sync_Seg. Reacting to the “late” edge, Phase_Seg1 is
lengthened so that the distance from the edge to the Sample Point is the same as it would
have been from the Sync_Seg to the Sample Point if no edge had occurred. The phase error
of this “late” edge is less than SJW, so it is fully compensated and the edge from dominant to
recessive at the end of the bit, which is one nominal bit time long, occurs in the Sync_Seg.
In the second example, an edge from recessive to dominant occurs during Phase_Seg2. The
edge is “early” since it occurs before a Sync_Seg. Reacting to the “early” edge, Phase_Seg2
is shortened and Sync_Seg is omitted, so that the distance from the edge to the Sample Point
is the same as it would have been from an Sync_Seg to the Sample Point if no edge had
occurred. As in the previous example, the magnitude of phase error of this “early” edge’s is
less than SJW, so it is fully compensated.
The Phase Buffer Segments are lengthened or shortened temporarily only; at the next bit
time, the segments return to their nominal programmed values.
In these examples, the bit timing is seen from the point of view of the CAN state machine,
where the bit time starts and ends at the Sample Points. The state machine omits Sync_Seg
when synchronizing on an “early” edge, because it cannot subsequently redefine that time
quantum of Phase_Seg2 where the edge occurs to be the Sync_Seg.
The examples in Figure 53 show how short dominant noise spikes are filtered by
synchronizations. In both examples the spike starts at the end of Prop_Seg and has the
length of “Prop_Seg + Phase_Seg1”.
recessive
Rx-Input Spike
dominant
Sample-Point Sample-Point
SJW ≥ Phase Error
recessive
Rx-Input Spike
dominant
Sample-Point Sample-Point
SJW < Phase Error
201/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In the first example, the Synchronization Jump Width is greater than or equal to the phase
error of the spike’s edge from recessive to dominant. Therefore the Sample Point is shifted
after the end of the spike; a recessive bus level is sampled.
In the second example, SJW is shorter than the phase error, so the Sample Point cannot be
shifted far enough; the dominant spike is sampled as actual bus level.
The oscillator tolerance range was increased when the CAN protocol was developed from
version 1.1 to version 1.2 (version 1.0 was never implemented in silicon). The option to
synchronize on edges from dominant to recessive became obsolete, only edges from
recessive to dominant are considered for synchronization. The only CAN controllers to
implement protocol version 1.1 have been Intel 82526 and Philips 82C200, both are
superseded by successor products. The protocol update to version 2.0 (A and B) had no
influence on the oscillator tolerance.
The tolerance range df for an oscillator frequency fosc around the nominal frequency fnom is:
( 1 – df ) • f nom ≤ f osc ≤ ( 1 + df ) • f nom
It depends on the proportions of Phase_Seg1, Phase_Seg2, SJW, and the bit time. The
maximum tolerance df is the defined by two conditions (both shall be met):
min(Phase_Seg1 , Phase_Seg2)
I: df ≤ ---------------------------------------------------------------------------------------
2 ⋅ ( 13 ⋅ bit_time – Phase_Seg2 )
SJW
II: df ≤ --------------------------------
20 ⋅ bit_time
It has to be considered that SJW may not be larger than the smaller of the Phase Buffer
Segments and that the Propagation Time Segment limits that part of the bit time that may be
used for the Phase Buffer Segments.
In most CAN implementations and also in the C_CAN, the bit timing configuration is
programmed in two register bytes. The sum of Prop_Seg and Phase_Seg1 (as TSEG1) is
combined with Phase_Seg2 (as TSEG2) in one byte, SJW and BRP are combined in the
other byte (see Figure 54 on page 203).
202/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In these bit timing registers, the four components TSEG1, TSEG2, SJW, and BRP have to be
programmed to a numerical value that is one less than its functional value. Therefore, instead
of values in the range of [1..n], values in the range of [0..n-1] are programmed. That way, e.g.
SJW (functional range of [1..4]) is represented by only two bits.
Therefore the length of the bit time is (programmed values) [TSEG1 + TSEG2 + 3] tq or
(functional values) [Sync_Seg + Prop_Seg + Phase_Seg1 + Phase_Seg2] tq.
Configuration (BRP)
Sampled_Bit
Receive_Data Bit
Sync_Mode
Timing
IPT
Bit_to_send
Logic Received_Data_Bit
Transmit_Data Bus_Off
Send_Message
Control
Next_Data_Bit Shift-Register
Received_Message
Configuration (TSEG1, TSEG2, SJW)
The data in the bit timing registers is the configuration input of the CAN protocol controller.
The Baud Rate Prescaler (configured by BRP) defines the length of the time quantum, the
basic time unit of the bit time; the Bit Timing Logic (configured by TSEG1, TSEG2, and SJW)
defines the number of time quanta in the bit time.
The processing of the bit time, the calculation of the position of the Sample Point, and
occasional synchronizations are controlled by the BTL state machine, which is evaluated once
each time quantum. The rest of the CAN protocol controller, the BSP state machine is
evaluated once each bit time, at the Sample Point.
The Shift Register sends the messages serially and receives the messages parallely. Its
loading and shifting is controlled by the BSP.
The BSP translates messages into frames and vice versa. It generates and discards the
enclosing fixed format bits, inserts and extracts stuff bits, calculates and checks the CRC
code, performs the error management, and decides which type of synchronization is to be
used. It is evaluated at the Sample Point and processes the sampled bus input bit. The time
203/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
that is needed to calculate the next bit to be sent after the Sample point(e.g. data bit, CRC bit,
stuff bit, error flag, or idle) is called the Information Processing Time (IPT).
The IPT is application specific but may not be longer than 2 tq; the IPT for the C_CAN is 0 tq.
Its length is the lower limit of the programmed length of Phase_Seg2. In case of a
synchronization, Phase_Seg2 may be shortened to a value less than IPT, which does not
affect bus timing.
Usually, the calculation of the bit timing configuration starts with a desired bit rate or bit time.
The resulting bit time (1/bit rate) must be an integer multiple of the system clock period.
The bit time may consist of 4 to 25 time quanta, the length of the time quantum tq is defined by
the Baud Rate Prescaler with tq = (Baud Rate Prescaler)/fsys. Several combinations may lead
to the desired bit time, allowing iterations of the following steps.
First part of the bit time to be defined is the Prop_Seg. Its length depends on the delay times
measured in the system. A maximum bus length as well as a maximum node delay has to be
defined for expandible CAN bus systems. The resulting time for Prop_Seg is converted into
time quanta (rounded up to the nearest integer multiple of tq).
The Sync_Seg is 1 tq long (fixed), leaving (bit time – Prop_Seg – 1) tq for the two Phase Buffer
Segments. If the number of remaining tq is even, the Phase Buffer Segments have the same
length, Phase_Seg2 = Phase_Seg1, else Phase_Seg2 = Phase_Seg1 + 1.
The minimum nominal length of Phase_Seg2 has to be regarded as well. Phase_Seg2 may
not be shorter than the IPT of the CAN controller, which, depending on the actual
implementation, is in the range of [0..2] tq.
The length of the Synchronization Jump Width is set to its maximum value, which is the
minimum of 4 and Phase_Seg1.
The oscillator tolerance range necessary for the resulting configuration is calculated by the
formulas given in Section 9.8.10.4: Oscillator Tolerance Range on page 202
If more than one configuration is possible, that configuration allowing the highest oscillator
tolerance range should be chosen.
CAN nodes with different system clocks require different configurations to come to the same
bit rate. The calculation of the propagation time in the CAN network, based on the nodes with
the longest delay times, is done once for the whole network.
The oscillator tolerance range of the CAN systems is limited by that node with the lowest
tolerance range.
The calculation may show that bus length or bit rate have to be decreased or that the stability
of the oscillator frequency has to be increased in order to find a protocol compliant
configuration of the CAN bit timing.
204/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
(Phase_Seg2-1)&(Phase_Seg1+Prop_Seg-1)&
(SynchronisationJumpWidth-1)&(Prescaler-1)
tq 100 ns = tAPB_CLK
tProp 600 ns = 6 • tq
tSJW 100 ns = 1 • tq
tSync-Seg 100 ns = 1 • tq
0.1µs
= -----------------------------------------------------------
2x ( 13x ( 1µs – 0.2µs ) )
In this example, the concatenated bit time parameters are (2-1)3&(7-1)4&(1-1)2&(1-1)6, the Bit
Timing Register is programmed to= 0x1600.
205/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
tq 1 µs = 2 •tAPB_CLK
tProp 1 µs = 1 • tq
tSJW 4 µs = 4 • tq
tSync-Seg 1 µs = 1 • tq
=
4 µs
----------------------------------------------------------
2x ( 13x ( 10µs – 4 µs ) )
In this example, the concatenated bit time parameters are (4-1)3&(5-1)4&(4-1)2&(2-1)6, the Bit
Timing Register is programmed to= 0x34C1.
206/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• Clock generation
207/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• Slave transmitter/receiver
• Master transmitter/receiver
The interface automatically switches from slave to master after it generates a START
condition and from master to slave in case of arbitration loss or a STOP generation, allowing
then Multi-Master capability.
In Master mode, it initiates a data transfer and generates the clock signal. A serial data
transfer always begins with a start condition and ends with a stop condition. Both start and
stop conditions are generated in master mode by hardware as soon as the Master mode is
selected.
In Slave mode, the interface is capable of recognizing its own address (7 or 10-bit), and the
General Call address. The General Call address detection may be enabled or disabled by
software.
Data and addresses are transferred as 8-bit bytes, MSB first. The first byte(s) following the
start condition contain the address (one in 7-bit mode, two in 10-bit mode). The address is
always transmitted in Master mode.
A 9th clock pulse follows the 8 clock cycles of a byte transfer, during which the receiver must
send an acknowledge bit to the transmitter. Refer to Figure 55.
208/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
SDA
MSB ACK
SCL
1 2 8 9
START STOP
CONDITION CONDITION
The I2C interface address and/or general call address can be selected by software.
The speed of the I2C interface may be selected between Standard (0-100KHz) and Fast I2C
(100-400KHz).
Transmitter mode: the interface holds the clock line low before transmission to wait for the
microcontroller to write the byte in the Data Register.
Receiver mode: the interface holds the clock line low after reception to wait for the
microcontroller to read the byte in the Data Register.
The SCL frequency (fSCL) is controlled by a programmable clock divider which depends on
the I2C bus mode.
209/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
COMPARATOR
INTERRUPT
210/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
By default the I2C interface operates in Slave mode (M/SL bit is cleared) except when it
initiates a transmit or receive sequence.
First the interface frequency must be configured using the FRi bits in the I2Cn_OAR2 register.
As soon as a start condition is detected, the address is received from the SDA line and sent to
the shift register; then it is compared with the address of the interface or the General Call
address (if selected by software).
Note In 10-bit addressing mode, the comparison includes the header sequence
(11110xx0) and the two most significant bits of the address.
Header matched (10-bit mode only): the interface generates an acknowledge pulse if the
ACK bit is set.
Address not matched: the interface ignores it and waits for another Start condition.
Then the interface waits for a read of the I2Cn_SR1 register, holding the SCL line low (see
Figure 57 Transfer sequencing EV1).
Next, in 7-bit mode read the I2Cn_DR register to determine from the least significant bit (Data
Direction Bit) if the slave must enter Receiver or Transmitter mode.
In 10-bit mode, after receiving the address sequence the slave is always in receive mode. It
will enter transmit mode on receiving a repeated Start condition followed by the header
sequence with matching address bits and the least significant bit set (11110xx1).
Following the address reception and after I2Cn_SR1 register has been read, the slave
receives bytes from the SDA line into the I2Cn_DR register via the internal shift register. After
each byte the interface generates in sequence:
211/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Then the interface waits for a read of the I2Cn_SR1 register followed by a read of the
I2Cn_DR register, holding the SCL line low (see Figure 57 Transfer sequencing EV2).
Following the address reception and after I2Cn_SR1 register has been read, the slave sends
bytes from the I2Cn_DR register to the SDA line via the internal shift register.
The slave waits for a read of the I2Cn_SR1 register followed by a write in the I2Cn_DR
register, holding the SCL line low (see Figure 57 Transfer sequencing EV3).
• The EVF and BTF bits are set by hardware with an interrupt if the ITE bit is set.
After the last data byte is transferred a Stop Condition is generated by the master. The
interface detects this condition and sets:
• EVF and STOPF bits with an interrupt if the ITE bit is set.
Then the interface waits for a read of the I2Cn_SR2 register (see Figure 57 Transfer
sequencing EV4).
• BERR: Detection of a Stop or a Start condition during a byte transfer. In this case, the
EVF and the BERR bits are set with an interrupt if the ITE bit is set.
If it is a Stop then the interface discards the data, released the lines and waits for another
Start condition.
If it is a Start then the interface discards the data and waits for the next slave address on
the bus.
• AF: Detection of a non-acknowledge bit. In this case, the EVF and AF bits are set with an
interrupt if the ITE bit is set.
Note In both cases, SCL line is not held low; however, SDA line can remain low due to
possible «0» bits transmitted last. It is then necessary to release both lines by
software.
Set and subsequently clear the STOP bit while BTF is set. The SDA/SCL lines are released
after the transfer of the current byte.
212/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
To switch from default Slave mode to Master mode a Start condition generation is needed.
Setting the START bit while the BUSY bit is cleared causes the interface to switch to Master
mode (M/SL bit set) and generates a Start condition.
• The EVF and SB bits are set by hardware with an interrupt if the ITE bit is set.
Then the master waits for a read of the I2Cn_SR1 register followed by a write in the I2Cn_DR
register with the Slave address, holding the SCL line low (see Figure 57 Transfer
sequencing EV5).
Then the slave address is sent to the SDA line via the internal shift register.
In 10-bit addressing mode, sending the first byte including the header sequence causes the
following event:
• The EVF bit is set by hardware with interrupt generation if the ITE bit is set.
Then the master waits for a read of the I2Cn_SR1 register followed by a write in the I2Cn_DR
register, holding the SCL line low (see Figure 57 Transfer sequencing EV9).
After completion of this transfer (and acknowledge from the slave if the ACK bit is set):
• The EVF bit is set by hardware with interrupt generation if the ITE bit is set.
Then the master waits for a read of the I2Cn_SR1 register followed by a write in the I2Cn_CR
register (for example set PE bit), holding the SCL line low (see Figure 57 Transfer
sequencing EV6).
Note In 10-bit addressing mode, to switch the master to Receiver mode, software must
generate a repeated Start condition and re-send the header sequence with the least
significant bit set (11110xx1).
213/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Following the address transmission and after I2Cn_SR1 and I2Cn_CR registers have been
accessed, the master receives bytes from the SDA line into the I2Cn_DR register via the
internal shift register. After each byte the interface generates in sequence:
Then the interface waits for a read of the SR1 register followed by a read of the I2Cn_DR
register, holding the SCL line low (see Figure 57 Transfer sequencing EV7).
To close the communication: before reading the last byte from the I2Cn_DR register, set the
STOP bit to generate the Stop condition. The interface goes automatically back to slave mode
(M/SL bit cleared).
Note In order to generate the non-acknowledge pulse after the last received data byte, the
ACK bit must be cleared just before reading the second last data byte.
Following the address transmission and after I2Cn_SR1 register has been read, the master
sends bytes from the I2Cn_DR register to the SDA line via the internal shift register.
The master waits for a read of the I2Cn_SR1 register followed by a write in the I2Cn_DR
register, holding the SCL line low (see Figure 57 Transfer sequencing EV8).
• EVF and BTF bits with an interrupt if the ITE bit is set.
To close the communication: after writing the last byte to the I2Cn_DR register, set the STOP
bit to generate the Stop condition. The interface goes automatically back to slave mode (M/SL
bit cleared).
• BERR: Detection of a Stop or a Start condition during a byte transfer. In this case, the
EVF and BERR bits are set by hardware with an interrupt if ITE is set.
• AF: Detection of a non-acknowledge bit. In this case, the EVF and AF bits are set by
hardware with an interrupt if the ITE bit is set. To resume, set the START or STOP bit.
• ARLO: Detection of an arbitration lost condition.
In this case the ARLO bit is set by hardware (with an interrupt if the ITE bit is set and the
interface goes automatically back to slave mode (the M/SL bit is cleared).
214/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note In all these cases, the SCL line is not held low; however, the SDA line can remain low
due to possible «0» bits transmitted last. It is then necessary to release both lines by
software.
Legend:
215/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
EV3: EVF=1, BTF=1, cleared by reading I2Cn_SR1 register followed by writing to the DR
register.
EV3-1: EVF=1, AF=1, BTF=1; AF is cleared by reading SR2 register. BTF is cleared by
releasing the lines (STOP=1, STOP=0) or by writing I2Cn_DR register (DR=FFh).
Note: If lines are released bySTOP=1, STOP=0, the subsequent EV4 is not seen.
EV5: EVF=1, SB=1, cleared by reading I2Cn_SR1 register followed by writing I2Cn_DR
register.
EV6: EVF=1, ENDAD=1 cleared by reading I2Cn_SR2 register followed by writing I2Cn_CR
register (for example PE=1).
EV9: EVF=1, ADD10=1, cleared by reading the I2Cn_SR1 register followed by writing to the
I2Cn_DR register.
10.4 Interrupts
Several interrupt events can be flagged by the module:
• requests related to bus events, like start or stop events, arbitration lost, etc.;
• requests related to data transmission and/or reception;
These requests are issued to the interrupt controller by two different lines as described in
Figure 58. The different flags identify the events and can be polled by the software (interrupt
service routine).
216/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
ITE
ADD10
SB
ADSL
ENDAD
AF ITERR
STOPF
ARLO
BERR
SCLFAL
BTF
TRA TX
TX_RX_INT
RX
217/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7 6 5 4 3 2 1 0
- rw rw rw rw rw rw
• 0: all the bits of the I2Cn_CR register and the I2Cn_SR register except the STOP bit are
reset. All outputs are released while PE=0.
• 1: the corresponding I/O pins are selected by hardware as alternate functions.
To enable the I2C interface, write the I2Cn_CR register TWICE with PE=1 as the first write
only activates the interface (only PE is set).
• In master mode:
0: No start generation.
1: Repeated start generation.
• In slave mode:
0: No start generation.
1: Start generation when the bus is free.
218/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• In master mode:
0: No stop generation.
1: Stop generation after the current byte transfer or after the current Start condition is
sent. The STOP bit is cleared by hardware when the Stop condition is sent.
• In slave mode:
0: No stop generation.
1: Release the SCL and SDA lines after the current byte transfer (BTF=1). In this mode
the STOP bit has to be cleared by software.
219/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7 6 5 4 3 2 1 0
r r r r r r r r
220/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• Following a byte transmission, this bit is set after reception of the acknowledge clock
pulse. In case an address byte is sent, this bit is set only after the EV6 event (See Figure
57). BTF is cleared by writing the next byte in I2Cn_DR register.
• Following a byte reception, this bit is set after transmission of the acknowledge clock
pulse if ACK=1. BTF is cleared by reading I2Cn_SR1 register followed by reading the byte
from I2Cn_DR register.
Bit 2 = ADSL: Address matched (Slave mode). This bit is set by hardware as soon as the
received slave address matched with the I2Cn_OAR register content or a general call is
recognized. An interrupt is generated if ITE=1. It is cleared by software reading I2Cn_SR1
register or by hardware when the interface is disabled (PE=0).
The SCL line is held low while ADSL=1.
0: Address mismatched or not received.
1: Received address matched.
221/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7 6 5 4 3 2 1 0
- r r r r r r
When the master needs to receive data from the slave, it has to send just the MSB of the slave
address once again; hence the ENDAD flag is set, without waiting for the LSB of the address.
It is cleared by software by reading SR2 and a following write to the CR or by hardware when
the interface is disabled (PE=0).
222/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
223/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
Note The programmed fSCL assumes no load on SCL and SDA lines.
Note For a correct usage of the divider, [CC11...CC0] must be equal or greater than 0x002
(000000000010b). [CC11...CC0] equal to 0x001 (000000000001b) is not admitted.
224/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7 6 5 4 3 2 1 0
rw rw rw rw rw
7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
225/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7 6 5 4 3 2 1 0
rw rw rw - rw rw -
5 - 10 0 0 0
10 - 16.67 0 0 1
16.67 - 26.67 0 1 0
26.67 - 40 0 1 1
40 - 53.33 1 0 0
53.33 -66 1 0 1
66 - 80 1 1 0
80 - 100 1 1 1
226/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
7 6 5 4 3 2 1 0
D7 D6 D5 D4 D3 D2 D1 D0
rw rw rw rw rw rw rw rw
• Transmitter mode: Byte transmission start automatically when the software writes in the
I2Cn_DR register.
• Receiver mode: the first data byte is received automatically in the I2Cn_DR register using
the least significant bit of the address. Then, the following data bytes are received one by
one after reading the I2Cn_DR register.
227/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Address Register
7 6 5 4 3 2 1 0
Offset Name
18 I2Cn_DR D7 D6 D5 D4 D3 D2 D1 D0
228/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
11.1 Introduction
A BSPI block is a standard 4-pin Serial Peripheral Interface for inter-IC control
communication. It interfaces on one side to the SPI bus and on the other has a standard
register data and interrupt interface.
A BSPI contains two 10-word x 16-bit FIFOs, one for receive and the other for transmit. It can
directly operate with words 8 and 16 bit long and generates vectored interrupts separately for
receive and transmit events.
11.3 Architecture
The processor views the BSPI as a memory mapped peripheral, which may be used by
standard polling or interrupt programming techniques. Memory-mapping means processor
communication can be achieved using standard instructions and addressing modes.
When an SPI transfer occurs data is transmitted and received simultaneously A serial clock
line synchronizes shifting and sampling of the information on the two serial data lines. A slave
select line allows individual selection of a slave device. The central elements in the BSPI
system are the 16-bit shift register and the read data buffer which is 10 words x 16-bit. A block
diagram of the BSPI is shown in Figure 59 on page 230.
229/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
16 MISO
SHIFT REGISTER S
MOSI
M
16 M SCLK
S
SS
16 10 WORD RECEIVE PIN CONTROL
FIFO LOGIC
(16 bits)
16
BSPI_CLK
CLK
S
BSPI CONTROL LOGIC
M
16
BSPI_CSR1
16
BSPI_CSR2
The BSPI is a four wire, bi-directional bus. The data path is determined by the mode of
operation selected. A master and a slave mode are provided together with the associated pad
control signals to control pad direction. These pins are described in Table 41 BSPI pins on
page 230.
Pin
Description
Name
SCLK The bit clock for all data transfers. When the BSPI is a master the SCLK is output from
the chip. When configured as a slave the SCLK is input from the external source.
SS Slave Select. The SS input pin is used to select a slave device. Must be pulled low after
the SCLK is stable and held low for the duration of the data transfer. The SS on the
master must be deasserted high.
230/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
SCLK
8 bits 8 bits
MOSI/MISO DATA0 DATA1
SS
During a BSPI transfer (Figure 60 on page 231), data is shifted out and shifted in (transmitted
and received) simultaneously. The SCLK line synchronizes the shifting and sampling of the
information. It is an output when the BSPI is configured as a master and an input when the
BSPI is configured as a slave. Selection of an individual slave BSPI device is performed on
the slave select line and slave devices that are not selected do not interfere with the BSPI
buses.
The CPOL (clock polarity) and CPHA (clock phase) bits of the BSPIn_CSR1 register are used
to select any of the four combinations of serial clock (see Figure 61 on page 232, Figure 62 on
page 232, Figure 63 on page 233, Figure 64 on page 233). These bits must be the same for
both the master and slave BSPI devices. The clock polarity bit selects either an active high or
active low clock but does not affect transfer format. The clock phase bit selects the transfer
format.
There is a 16-bit shift register which interfaces directly to the BSPI bus lines. As transmit data
goes out from the register, received data fills the register.
Note When the BSPI cell is configured in Slave mode, the SCLK_IN clock must be divided
by a factor of 8 or more compared with the system clock (APB1 clock).
231/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
SCLK (out)
MOSI (out)
MSB 6 5 4 3 2 1 LSB
SLAVE SIGNALS
SCLK (in)
SS
MISO (out)
MSB 6 5 4 3 2 1 LSB
SCLK (out)
MOSI (out)
MSB 6 5 4 3 2 1 LSB
SLAVE SIGNALS
SCLK (in)
SS
MISO (out)
MSB 6 5 4 3 2 1 LSB
232/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
SCLK (out)
MOSI (out)
MSB 6 5 4 3 2 1 LSB
SLAVE SIGNALS
SCLK (in)
SS
MISO (out)
MSB 6 5 4 3 2 1 LSB
SCLK (out)
MOSI (out)
MSB 6 5 4 3 2 1 LSB
SLAVE SIGNALS
SCLK (in)
SS
MISO (out)
MSB 6 5 4 3 2 1 LSB
233/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The user can set the depth of the FIFO from the default one location up to a maximum of ten
locations. This can be set dynamically but will only take effect after the completion of the
current transmission. Status flags report if the FIFO is full (TFF), the FIFO is not empty
(TFNE), the FIFO is empty (TFE) and the transmit buffer has under flown (TUFL). The
transmit interrupt enable (TIE[1:0]) control bits of BSPIn_CSR2 determine the source of the
transmit interrupt. If the interrupt source is enabled then an active high interrupt will be
asserted to the processor.
If the TUFL flag is asserted then a subsequent write to the transmit FIFO will clear the flag. If
interrupts are enabled then the interrupt will be de-asserted. The TFF and TFNE flags are
updated at the end of the processor write cycle and at the end of each transmission.
Note data should be written in the FIFO only if the macro is enabled (see BSPI System
Enable bit of BSPI Control Register). If one data word is written in the trasmit fifo
before enabling the BSPI no data is trasmitted.
The FIFO can operate in 8-bit and 16-bit modes as configured by the WL[1:0] bits of the
Control/Status Register 1 BSPIn_CSR1 . Irrelevant of the word depth in the FIFO, if operating
in 8-bit mode the data will occupy the Most Significant Byte of each location of the FIFO (data
is left justified). The receive FIFO enable bits RFE[3:0] declare how many words deep the
FIFO is for all transfers. The FIFO defaults to one word deep. Whenever there is at least one
block of data in the FIFO the RFNE bit is set in the Control/Status register 2 BSPIn_CSR2, i.e
there is data in at least one location. The RFF flag does not get set until all locations of the
FIFO contain data, i.e. RFF is set when the depth of FIFO is filled and nothing has been read
out.
If the FIFO is one word deep then the RFNE and RFF flags are set once data is written to it.
When the data is read then both flags are cleared. A write to and a read from the FIFO can
happen independent of each once RFF is not set, if RFF is set a read must occur before the
next write or an overflow(ROFL) will occur.
234/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
If the BSPI is to operate in slave mode, once again the device must be enabled. The SS line
must only be asserted low after the SCLK from the master is stable. The TFE flag will be set
signalling that the Transmit Data register is empty and will be cleared by a write to the
Transmit Data register BSPIn_TXR. The second TFE interrupt occurs to request data for the
following transfer.
For example, in the case of TFE, whenever the last word has been transferred to the transmit
buffer, the TFE flag is asserted. If interrupts are enabled then an interrupt will be asserted to
the processor. To clear the interrupt the user must write at least one data word into the FIFO,
or disable the interrupts if this condition is valid.
235/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSTR
CPHA
CPOL
BSPE
REIE
BEIE
res.
res.
rw rw rw rw rw - - rw rw rw rw
The receive FIFO can be programmed to operate with a word depth up to 10. The receive
FIFO enable bits declare how many words deep the FIFO is for all transfers. The FIFO
defaults to one word deep, i.e. similar to a single data register. Table below shows how the
FIFO is controlled.
236/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
These two bits configure the word length operation of the Receive FIFO and transmit data
registers as shown below:
When this bit is set to a 1 and the Receiver Overflow error condition occurs, a Receive Error
Interrupt will be asserted to the processor.
237/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note The peripheral should be enabled before selecting the interrupts. In this way the user
can avoid unexpected behaviours of interrupt request signal.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIE[1:0] TFE[3:0]
DFIFO
BERR
RFNE
ROFL
TFNE
TUFL
RFF
TFE
TFF
res.
rw rw r r r r r r r r - w
0 0 Disabled
1 0 Transmit underflow.
238/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
This bit is set whenever the FIFO contains at least one data word.
TFF is set whenever the number of words written to the transmit FIFO is equal to the number
of FIFO locations enabled by TFE[3:0]. The flag is set immediately after the data write is
complete.
This status bit gets set if the TFE bit is set and, by the time the Transmit Data Register
contents are to be transferred to the shift register for the next transmission, the processor has
not yet put the data for transmission into the Transmit Data Register.
TUFL is set on the first edge of the clock when CPHA = 1 and when CPHA = 0 on the
assertion of SS. If TIE[1:0] bits are set to “10” then, when TUFL gets set an interrupt will be
asserted to the processor.
Note From an application point of view, it is important to be aware that the first word
available after an underflow event has occurred should be ignored, as this data was
loaded into the shift register before the underflow condition was flagged.
239/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
This bit gets set whenever the Transmit FIFO has transferred its last data word to the transmit
buffer. If interrupts are enabled then an interrupt will be asserted whenever the last word has
been transferred to the transmit buffer.
This bit gets set if the Receive FIFO is full and has not been read by the processor by the time
another received word arrives. If the REIE bit is set then, when this bit gets set an interrupt will
be asserted to the processor. This bit is cleared when a read takes place of the CSR register
and the FIFO.
This status bit indicates that the number of FIFO locations, as defined by the RFE[3:0] bits,
are all full, i.e. if the FIFO is 4 deep then all data has been received to all four locations. If the
RIE[1:0] bits are configured as ‘11’ then, when this status bit gets set, an interrupt will be
asserted to the processor. This bit is cleared when at least one data word has been read.
This status bit indicates that there is data in the Receive FIFO. It is set whenever there is at
least one block of data in the FIFO i.e. for 8-bit mode 8 bits and for 16-bit mode 16 bits. If the
RIE[1:0] bits are configured to ‘01’ then whenever this bit gets set an interrupt will be asserted
to the processor. This bit is cleared when all valid data has been read out of the FIFO.
This status bit indicates that a Bus Error condition has occurred, i.e. that more than one
device has acted as a Master simultaneously on the BSPI bus. A Bus Error condition is
defined as a condition where the Slave Select line goes active low when the module is
configured as a Master. This indicates contention in that more than one node on the BSPI bus
is attempting to function as a Master.
When this bit is enabled, the FIFO pointers are all reset to zero, the RFE bits are set to zero
and therefore the BSPI is set to one location. The data within the FIFO is lost. This bit is reset
to zero after a clock cycle.
240/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
reserved DIV[7:0]
- rw
These bits are used to control the frequency of the BSPI serial clock with relation to the APB1
clock. In master mode this number must be an even number greater than five, i.e. six is the
lowest divide factor. In slave mode this number must be an even number greater than seven,
i.e. eight is the lowest divide factor.
These bits must be set before the BSPE or MSTR bits, i.e. before the BSPI is configured into
master mode.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
16-bit TX[15:0]
Transmis-
sion
This register is used to write data for transmission into the BSPI. If the FIFO is enabled then
data written to this register will be transferred to the FIFO before transmission. If the FIFO is
disabled then the register contents are transferred directly to the shift register for
transmission. In sixteen bit mode all of the register bits are used. In eight bit mode only the
upper eight bits of the register are used. In both case the data is left justified,.i.e Bit[15] =
MSB, Bit[0] / Bit[8] = LSB depending on the operating mode.
241/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
16-bit RX[15:0]
Transmis-
sion
This register contains the data received from the BSPI bus. If the FIFO is disabled then the
data from the shift register is placed into the receive register directly. If the FIFO is enabled
then the received data is transferred into the FIFO. In sixteen bit mode all the register bitsare
utilised. In eight bit transmission mode only the upper eight bits of the register are used. The
data is left justified in the register in both transmission modes,.i.e Bit[15] = MSB, Bit[0] / Bit[8]
= LSB depending on the operating mode.
242/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Addr. Reg. 1 1 1 1 1 1
9 8 7 6 5 4 3 2 1 0
Offset Name 5 4 3 2 1 0
CPHA
CPOL
REIE
BEIE
CSR1 ] S S
res.
res.
T P
R E
DFIFO
BERR
RFNE
ROFL
TFNE
TUFL
RFF
TFE
TFF
res.
CSR2
243/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
12 UART
12.1 Introduction
A UART interface, provides serial communication between the STR71x and other
microcontrollers, microprocessors or external peripherals.
A UART supports full-duplex asynchronous communication. Eight or nine bit data transfer,
parity generation, and the number of stop bits are programmable. Parity, framing, and overrun
error detection are provided to increase the reliability of data transfers. Transmission and
reception of data can simply be double-buffered, or 16-deep fifos may be used. For
multiprocessor communications, a mechanism to distinguish the address from the data bytes
is included. Testing is supported by a loop-back option. A 16-bit baud rate generator provides
the UART with a separate serial clock signal.
Eight bit data frames (see Figure 65) either consist of:
• eight data bits D0-7 (by setting the Mode bit field to 001);
• seven data bits D0-6 plus an automatically generated parity bit (by setting the Mode bit
field to 011).
Parity may be odd or even, depending on the ParityOdd bit in the UARTn_CR register. An
even parity bit will be set, if the modulo-2-sum of the seven data bits is 1. An odd parity bit will
be cleared in this case.}
244/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Nine bit data frames (see Figure 66) either consist of:
• nine data bits D0-8 (by setting the Mode bit field to 100);
• eight data bits D0-7 plus an automatically generated parity bit (by setting the Mode bit
field to 111);
• eight data bits D0-7 plus a wake-up bit (by setting the Mode bit field to 101).
Parity may be odd or even, depending on the ParityOdd bit in the UARTn_CR register. An
even parity bit will be set, if the modulo-2-sum of the eight data bits is 1. An odd parity bit will
be cleared in this case.
In wake-up mode, received frames are only transferred to the receive buffer register if the
ninth bit (the wake-up bit) is 1. If this bit is 0, no receive interrupt request will be activated and
no data will be transferred.
This feature may be used to control communication in multi-processor systems. When the
master processor wants to transmit a block of data to one of several slaves, it first sends out
an address byte which identifies the target slave. An address byte differs from a data byte in
that the additional ninth bit is a 1 for an address byte and a 0 for a data byte, so no slave will
be interrupted by a data byte. An address byte will interrupt all slaves (operating in 8-bit data
+ wake-up bit mode), so each slave can examine the 8 least significant bits (LSBs) of the
received character (the address). The addressed slave will switch to 9-bit data mode, which
enables it to receive the data bytes that will be coming (with the wake-up bit cleared). The
slaves that are not being addressed remain in 8-bit data + wake-up bit mode, ignoring the
following data bytes.
245/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
12.3.1 Transmission
If the fifos are enabled (the UARTn_CR(FifoEnable) is set), the TxFIFO is considered full
(UARTn_SR(TxFull) is set) when it contains 16 characters. Further writes to
UARTn_TxBUFR in this situation will fail to overwrite the most recent entry in the TxFIFO. If
the fifos are disabled, the TxFIFO is considered full (UARTn_SR(TxFull) is set) when it
contains 1 character, and a write to UARTn_TxBUFR in this situation will overwrite the
contents.
If the fifos are enabled, UARTn_SR(TxHalfEmpty) is set when the TxFIFO contains 8 or
fewer characters. If the fifos are disabled, it’s set when the TxFIFO is empty.
Values are shifted out of the bottom of the TxFIFO into a 9-bit txshift register in order to be
transmitted. If the transmitter is idle (the txshift register is empty) and something is written to
the UARTn_TxBUFR so that the TxFIFO becomes non-empty, the txshift register is
immediately loaded from the TxFIFO and transmission of the data in the txshift register begins
at the next baud rate tick.
At the time the transmitter is just about to transmit the stop bits, then if the TxFIFO is
non-empty, the txshift register will be immediately loaded from the TxFIFO, and transmission
of this new data will begin as soon as the current stop bit period is over (i.e. the next start bit
will be transmitted immediately following the current stop bit period). Thus back-to-back
transmission of data can take place. If instead the TxFIFO is empty at this point, then the
txshift register will become empty. UARTn_SR(TxEmpty) indicates whether the txshift
register is empty.
After changing the FifoEnable bit, it is important to reset the FIFO to empty (by writing to the
UARTn_TxRSTR register), since the state of the fifo pointer may be garbage.
The loop-back option (selected by the UARTn_CR(LoopBack) bit) internally connects the
output of the transmitter shift register to the input of the receiver shift register. This may be
used to test serial communication routines at an early stage without having to provide an
external network.
12.3.2 Reception
Reception is initiated by a falling edge on the data input pin (RXD), provided that the
UARTn_CR(Run) and UARTn_CR(RxEnable) bits are set. The RXD pin is sampled at 16
times the rate of the selected baud rate. A majority decision of the first, second and third
samples of the start bit determines the effective bit value. This avoids erroneous results that
may be caused by noise.
246/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
If the detected value is not a 0 when the start bit is sampled, the receive circuit is reset and
waits for the next falling edge transition at the RXD pin. If the start bit is valid, the receive
circuit continues sampling and shifts the incoming data frame into the receive shift register.
For subsequent data and parity bits, the majority decision of the seventh, eighth and ninth
samples in each bit time is used to determine the effective bit value.
Note: If reception is initiated when the data input pin (RXD) is being stretched at ‘0’, a frame
error is reported since the reception stage samples the initial value as a falling edge.
For 0.5 stop bits, the majority decision of the third, fourth, and fifth samples during the stop bit
is used to determine the effective stop bit value.
For 1 and 2 stop bits, the majority decision of the seventh, eighth, and ninth samples during
the stop bits is used to determine the effective stop bit values.
For 1.5 stop bits, the majority decision of the fifteenth, sixteenth, and seventeenth samples
during the stop bits is used to determine the effective stop bit value.
The effective values received on the RXD pin are shifted into a 10-bit rxshift register.
The receive fifo, RxFIFO, is implemented as a 16 deep array of 10-bit vectors (each 9 down to
0). If the RxFIFO is empty, UARTn_SR(RxBufNotEmpty) is set to ‘0’. If the RxFIFO is not
empty, a read from UARTn_RxBUFR will get the oldest entry in the RxFIFO. If fifos are
disabled, the RxFIFO is considered full when it contains one character.
UARTn_SR(RxHalfFull) is set when the RxFIFO contains more than 8 characters. Writing
anything to UARTn_RxRSTR empties the RxFIFO.
As soon as the effective value of the last stop bit has been determined, the content of the
rxshift register is transferred to the RxFIFO (except in wake-up mode, in which case this
happens only if the wake-up bit, bit8, is a ‘1’). The receive circuit then waits for the next start
bit (falling edge transition) at the RXD pin.
UARTn_SR(OverrunError) is set when the RxFIFO is full and a character is loaded from the
rxshift register into the RxFIFO. It is cleared when the UARTn_RxBUFR register is read.
The most significant bit of each RxFIFO entry (RxFIFO[x][9]) records whether or not there was
a frame error when that entry was received (i.e. one of the effective stop bit values was ’0’).
UARTn_SR(FrameError) is set when at least one of the valid entries in the RxFIFO has its
MSB set.
If the mode is one where a parity bit is expected, then the bit RxFIFO[x][8] (if 8 bit data + parity
mode is selected) or the bit RxFIFO[x][7] (if 7 bit data + parity mode is selected) records
whether there was a parity error when that entry was received.
Note: It does not contain the parity bit that was received. UARTn_SR(ParityError) is set when
at least one of the valid entries in the RxFIFO has bit 8 set (if 8 bit data + parity mode is
selected) or bit 7 set (if 7 bit data + parity mode is selected).
247/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
After changing the fifoenable bit, it is important to reset the fifo to empty (by writing to the
UARTn_RxRSTR register), since the state of the fifo pointers may be garbage.
The UART contains an 8-bit timeout counter. This reloads from UARTn_TOR whenever one
or more of the following is true
• UARTn_RxBBUFR is read
• The UART starts to receive a character
• UARTn_TOR is written to
If none of these conditions hold, the counter decrements towards 0 at every baud rate tick.
UARTn_SR(TimeoutNotEmpty) is ’1’ exactly whenever the RxFIFO is not empty and the
timeout counter is zero.
UARTn_SR(TimeoutIdle) is ‘1’ exactly whenever the RxFIFO is empty and the timeout
counter is zero.
The effect of this is that whenever the RxFIFO has got something in it, the timeout counter will
decrement until something happens to the RxFIFO. If nothing happens, and the timeout
counter reaches zero, the UARTn_SR(TimeoutNotEmpty) flag will be set.
When the software has emptied the RxFIFO, the timeout counter will reset and start
decrementing. If no more characters arrive, when the counter reaches zero the
UARTn_SR(TimeoutIdle) flag will be set.
The baud rate generator provides a clock at 16 times the baud rate, called the oversampling
clock. This clock only ticks if UARTn_CR(Run) is set to’1’. Setting this bit to 0 will immediately
freeze the state of the UART’s transmitter and receiver. This should only be done when the
UART is idle.
The baud rate and the required reload value for a given baud rate can be determined by the
following formulae:
248/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Table 43 and Table 44 list various commonly used baud rates together with the required
reload values and the deviation errors for two different PCLK1 clock frequencies (16 and
20MHz respectively).
625K 2 2 0002 0%
249/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The UART has a single interrupt request line, called UARTn_interrupt. The status bits in the
UARTn_SR register determine the cause of the interrupt. UARTn_interrupt will go high when
a status bit is 1 (high) and the corresponding bit in the UARTn_IER register is 1 (see
Figure 67).
Note: The UARTn_Status register is read only. The UART_Status bits can only be cleared by
operating on the FIFOs. The RxFIFO and TxFIFO can be reset by writing to the
UARTn_RxReset and UARTn_TxReset registers.
RxBufNotEmpty IE
RxBufNotEmpty
TxEmpty IE
TxEmpty
TxHalfEmpty IE
TxHalfEmpty
ParityError IE
ParityError UART_interrupt
FrameError IE
FrameError
OverrunError IE
OverrunError
TimeoutNotEmpty IE
TimeoutNotEmpty
TimeoutIdle IE
TimeoutIdle
RxHalfFull IE
RxHalfFull
250/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When fifos are disabled, the UART provides three interrupt requests to control data exchange
via the serial channel:
• TxHalfEmpty is activated when data is moved from UARTn_TxBUFR to the txshift register.
For single transfers it is sufficient to use the transmitter interrupt (TxEmpty), which indicates
that the previously loaded data has been transmitted, except for the stop bit.
For multiple back-to-back transfers using TxEmpty would leave just one stop bit time for the
handler to respond to the interrupt and initiate another transmission. Using the transmit buffer
interrupt (TxHalfEmpty) to reload transmit data allows the time to transmit a complete frame
for the service routine, as UARTn_TxBUFR may be reloaded while the previous data is still
being transmitted.
TxHalfEmpty is an early trigger for the reload routine, while TxEmpty indicates the
completed transmission of the data field of the frame. Therefore, software using handshake
should rely on TxEmpty at the end of a data block to make sure that all data has really been
transmitted.
To transmit a large number of characters back to back, the driver routine would write 16
characters to UARTn_TxBUFR, then every time a TxHalfEmpty interrupt fired, it would write
8 more. When it had nothing more to send, a TxEmpty interrupt would tell it when everything
has been transmitted.
When receiving, the driver could use RxBufNotEmpty to interrupt every time a character
came in. Alternatively, if data is coming in back-to-back, it could use RxHalfFull to interrupt it
when there were more than 8 characters in the RxFIFO to read. It would have as long as it
takes to receive 8 characters to respond to this interrupt before data would overrun. If less
than eight character streamed in, and no more were received for at least a timeout period, the
driver could be woken up by one of the two timeout interrupts, TimeoutNotEmpty or
TimeoutIdle.
To conform to the ISO SmartCard specification the following modes are supported in the
UART SmartCard mode.
When the SmartCard mode bit is set to 0, normal UART operation occurs.
When the SmartCard mode bit is set to 1, the following operation occurs:
251/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The receiver enable bit is reset after a character has been received. This avoids the receiver
detecting another start bit in the case of the smartcard driving the RXD line low until the UART
driver software has dealt with the previous character.
252/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BaudRate[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
A read from this register returns the content of the timer, writing to it updates the reload
register.
An auto-reload of the timer with the content of the reload register is performed each time the
UARTn_BR register is written to. However, if the Run bit of the UARTn_CR register is 0 at the
time the write operation to the UARTn_BR register is performed, the timer will not be reloaded
until the first PCLK1 clock cycle after the Run bit is 1.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved TX TX TX TX TX TX TX TX TX
[8] [7] [6] [5] [4] [3] [2] [1] [0]
w w w w w w w w w w w w w w w w
Note: If the Mode field selects an 8 bit frame then this bit should be written as 0.
253/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note:If the Mode field selects a frame with parity bit, then the TX[8] bit will contain the parity
bit (automatically generated by the UART). Writing ‘0’ or ‘1’ in this bit will have no effect on the
transmitted frame.
Note: If the Mode field selects a frame with parity bit, then the TX[7] bit will contain the parity
bit (automatically generated by the UART). Writing ‘0’ or ‘1’ in this bit will have no effect on the
transmitted frame.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved RX RX RX RX RX RX RX RX RX RX
[9] [8] [7] [6] [5] [4] [3] [2] [1] [0]
r r r r r r r r r r r r r r r r
The received data and, if provided by the selected operating mode, the received parity bit can
be read from the receive buffer register.
Note If the Mode field selects a 7- or 8-bit frame then this bit is undefined. Software should
ignore this bit when reading 7- or 8-bit frames.
254/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved Mode
Fifo Enable
Loop Back
Rx Enable
ParityOdd
Stop Bits
Enable
Run
SC-
rw rw rw rw rw rw rw rw rw rw rw r r r r r
w w w w w
This register controls the operating mode of the UART and contains control bits for mode and
error check selection, and status flags for error identification.
Note: Programming the mode control field (Mode) to one of the reserved combinations may
result in unpredictable behavior.
Note: Serial data transmission or reception is only possible when the baud rate generator run
bit (Run) is set to 1. When the Run bit is set to 0, TXD will be 1. Setting the Run bit to 0 will
immediately freeze the state of the transmitter and receiver. This should only be done when
the UART is idle.
255/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note: This bit may be modified only when the UART is inactive.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RESERVED
Timeout Not Empty IE
Overrun Error IE
Time out IdleIE
NotEmpty IE
Empty IE
Empty IE
Error IE
Error IE
Rx Half
TxHalf
Frame
RxBuf
FullIE
Parity
Tx
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Interrupts will occur when a status bit in the UARTn_SR register is 1, and the corresponding
bit in the UARTn_IER register is 1.
256/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
257/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
Rx BufNotEmpty
Tx Half Empty
Overrun Error
Timeout Idle
Frame Error
Rx Half Full
Parity Error
Tx Empty
Tx Full
r r r r r r r r r r r r r r r r
258/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved UART_GuardTime
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
The UARTn_GTR register enables the user to define a programmable number of baud clocks
to delay the assertion of TxEmpty.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved UART_Timeout
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
This register is to have a timeout system to be sure that not too much time pass between two
successive received characters.
259/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
w w w w w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
w w w w w w w w w w w w w w w w
260/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Addr. Register
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Offset Name
0 UARTn_B UART_BaudRate
R
4 UARTn_ Reserved UART_TxBuffer
TxBUFR
8 UARTn_ Reserved UART_RxBuffer
RxBUFR
FifoEnable
ParityOdd
LoopBack
RxEnable
C UARTn_ Reserved Reserved Run Stop Mode
CR
Bits
261/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
13.1 Introduction
The SmartCard Interface an extension of UART1, for the description of the UART registers,
pls refer to section 12 on page 244. The SmartCard interface is designed to support
asynchronous protocol SmartCards as defined in the ISO7816-3 standard. UART1 configured
as eight data bits plus parity, 0.5 or 1.5 stop bits, with SmartCard mode enabled provides the
UART function of the SmartCard interface. A 16 bit counter, the SmartCard clock generator,
divides down the PCLK1 clock to provide the clock to the SmartCard. GPIO bits in conjunction
with software are used to provide the rest of the functions required to interface to the
SmartCard. The inverse signalling convention as defined in ISO7816-3, inverted data and
MSB first, is handled in software.
The ScRST, ScCmdVpp, ScCmdVcc, and ScDetect signals are provided by GPIO bits of the
IO ports under software control. Programming the GPIO bits of the port for alternate function
modes connects the UART TXD data signal to the ScDataOut pin with the correct driver type
262/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
and the clock generator to the ScClk pin. Details of the GPIO bit assignments for the Alternate
Function pins can be found in the STR71x pinout table.
Note: The STR71x I/Os are compatible with 3V smartcards. In the case of 5V cards, the
STR71x I/Os can correctly drive a 5V input to the smartcard. The only problem could come
from the SCDATA line, because it is bi-directional and the 5V logic levels (VIH/VIL) will not
match. This is why only in this case an open drain buffer has to be used. The pull-up resistor
(external), must be connected to VCC (5V or 3.3V depending on the type of smartcard).
13.3 Protocol
The ISO standard defines the bit times for the asynchronous protocol in terms of a time unit
called an ETU which is related to the clock frequency input to the card. One bit time is of
length one ETU. The UART transmitter output and receiver input need to be connected
together externally. For the transmission of data from the STR71x to the SmartCard, the
UART will need to be set up in SmartCard mode.
S a b c d e f g h P
Note: STR71xx is able to detect, via hardware, a parity error on a data byte received from the
Card, however a parity error detected on a data byte received from the Reader has to be
handled by the software.
263/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
either the old or new programmed value. The clock generator clock source is the PCLK1
clock. Two registers control the period of the clock and the running of the clock.
Reserved ScClkVal
- rw
The SC_CLKVAL register determines the SmartCard clock frequency. The value given in the
register is multiplied by 2 to give the division factor of the input clock frequency.
ScClkVal4:0 Division
264/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Reserved EN
- rw
The SC_CLKCON register controls the source of the clock and determines whether the
SmartCard clock output is enabled. The programmable divider and the output are reset when
the enable bit is set to 0.
Bit 0 = EN
SmartCard clock generator enable bit.
44 SC_ClkCon Reserved EN
265/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
14.1 Introduction
The USB Peripheral implements an interface between a full-speed USB 2.0 bus and the APB
bus.
USB suspend/resume are supported which allows to stop the device clocks for low power
consumption.
266/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
D+ D-
USB
Control
RX-TX Clock
registers & logic
Suspend Recovery
Timer Control
Endpoint Interrupt
S.I.E. Selection registers & logic
Packet
Buffer Endpoint Endpoint
Interface Registers Registers
Packet
Register Interrupt
Arbiter Buffer
Mapper Mapper
Memory
APB wrapper
APB Interface
PCLK APB bus IRQs to EIC
267/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Each endpoint is associated with a buffer description block indicating where the endpoint
related memory area is located, how large it is or how many bytes must be transmitted. When
a token for a valid function/endpoint pair is recognized by the USB Peripheral, the related data
transfer (if required and if the endpoint is configured) takes place. The data buffered by the
USB Peripheral is loaded in an internal 16 bit register and memory access to the dedicated
buffer is performed. When all the data has been transferred, if needed, the proper handshake
packet over the USB is generated or expected according to the direction of the transfer.
Special support is offered to Isochronous transfers and high throughput bulk transfers,
implementing a double buffer usage, which allows to always have an available buffer for the
USB Peripheral while the microcontroller uses the other one.
The unit can be placed in low-power mode (SUSPEND mode), by writing in the control
register, whenever required. At this time, all static power dissipation is avoided, and the USB
clock can be slowed down or stopped. The detection of activity at the USB inputs, while in
low-power mode, wakes the device up asynchronously. A special interrupt source can be
connected directly to a wake-up line to allow the system to immediately restart the normal
clock generation and/or support direct clock start/stop.
The USB Peripheral implements all the features related to USB interfacing, which include the
following blocks:
268/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• Serial Interface Engine (SIE): The functions of this block include: synchronization pattern
recognition, bit-stuffing, CRC generation and checking, PID verification/generation, and
handshake evaluation. It must interface with the USB transceivers and uses the virtual
buffers provided by the packet buffer interface for local data storage,. This unit also
generates signals according to USB Peripheral events, such as Start of Frame (SOF),
USB_Reset, Data errors etc. and to Endpoint related events like end of transmission or
correct reception of a packet; these signals are then used to generate interrupts.
• Suspend Timer: This block generates the frame locked clock pulse for any external device
requiring Start-of-Frame synchronization and it detects a global suspend (from the host)
when no traffic has been received for 3 mS.
• Packet Buffer Interface: This block manages the local memory implementing a set of
buffers in a flexible way, both for transmission and reception. It can choose the proper
buffer according to requests coming from the SIE and locate them in the memory
addresses pointed by the Endpoint registers. It increments the address after each
exchanged word until the end of packet, keeping track of the number of exchanged bytes
and preventing the buffer to overrun the maximum capacity.
• Endpoint-Related Registers: Each endpoint has an associated register containing the
endpoint type and its current status. For mono-directional/single-buffer endpoints, a single
register can be used to implement two distinct endpoints (IN and OUT). The STR71x USB
IP includes 16 endpoint registers allowing up to 16 double-buffer endpoints or up to 32
mono-directional/single-buffer ones in any combination.
• Control Registers: These are the registers containing information about the status of the
whole USB Peripheral and used to force some USB events, such as resume and
power-down.
• Interrupt Registers: These contain the Interrupt masks and a record of the events. They
can be used to inquire an interrupt reason, the interrupt status or to clear the status of a
pending interrupt.
The USB Peripheral is connected to the APB bus through an APB interface, containing the
following blocks:
• Packet Memory: This is the local memory that physically contains the Packet Buffers. It
can be used by the Packet Buffer interface, which creates the data structure and can be
accessed directly by the application software. The size of the Packet Memory is 512
Bytes, structured as 256 words by 16 bits.
• Arbiter: This block accepts memory requests coming from the APB bus and from the USB
interface. It resolves the conflicts by giving priority to APB accesses, while always
reserving half of the memory bandwidth to complete all USB transfers. This time-duplex
scheme implements a virtual dual-port RAM that allows memory access, while an USB
transaction is happening. Multi-word APB transfers of any length are also allowed by this
scheme.
269/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• Register Mapper: This block collects the various byte-wide and bit-wide registers of the
USB Peripheral in a structured 16-bit wide word set addressed by the APB.
• Interrupt Mapper: This block is used to select how the possible USB events can generate
interrupts and map them to IRQ lines of the EIC.
• APB Wrapper: This provides an interface to the APB for the memory and register. It also
maps the whole USB Peripheral in the APB address space.
In the following sections, the expected interactions between the USB Peripheral and the
application program are described, in order to ease application software development.
This part describes the main tasks required of the application software in order to obtain USB
compliant behaviour. The actions related to the most general USB events are taken into
account and paragraphs are dedicated to the special cases of double-buffered endpoints and
Isochronous transfers. Apart from system reset, action is always initiated by the USB
Peripheral, driven by one of the USB events described below.
Upon system and power-on reset, the first operation the application software should perform
is to provide all required clock signals to the USB Peripheral and subsequently de-assert its
reset signal so to be able to access its registers. The whole initialization sequence is hereafter
described.
As a first step application software needs to activate register macrocell clock and de-assert
macrocell specific reset signal using related control bits provided by device clock
management logic.
After that the analog part of the device related to the USB transceiver must be switched on
using the PDWN bit in CNTR register which requires a special handling. This bit is intended to
switch on the internal voltage references supplying the port transceiver . Since this circuits
have a defined start-up time, during which the behaviour of USB transceiver is not defined, it
is necessary to wait this time, after having set the PDWN bit in CNTR register, then the reset
condition on the USB part can be removed (clearing of FRES bit in CNTR register) and the
ISTR register can be cleared, removing any spurious pending interrupt, before enabling any
other macrocell operation.
As a last step the USB specific 48 MHz clock needs to be activated, using the related control
bits provided by device clock management logic, where applicable.
At system reset, the microcontroller must initialize all required registers and the packet buffer
description table, to make the USB Peripheral able to properly generate interrupts and data
transfers. All registers not specific to any endpoint must be initialized according to the needs
270/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
of application software (choice of enabled interrupts, chosen address of packet buffers, etc.).
Then the process continues as for the USB reset case (see further paragraph).
When this event occurs, the USB Peripheral is put in the same conditions it is left by the
system reset after the initialization described in the previous paragraph: the USB_DADDR
register is reset, and communication is disabled in all endpoint registers (the USB Peripheral
will not respond to any packet). As a response to the USB reset event, the USB function must
be enabled, having as USB address 0, implementing only the default control endpoint
(endpoint address is 0 too). This is accomplished by setting the Enable Function (EF) bit of
the USB_DADDR register and initializing the EP0R register and its related packet buffers
accordingly. During USB enumeration process, the host assigns a unique address to this
device, which must be written in the ADD[6:0] bits of the USB_DADDR register, and
configures any other necessary endpoint.
When a RESET interrupt is received, the application software is responsible to enable again
the default endpoint of USB function 0 within 10mS from the end of reset sequence which
triggered the interrupt.
Each bidirectional endpoint may receive or transmit data from/to the host. The received data
is stored in a dedicated memory buffer reserved for that endpoint, while another memory
buffer contains the data to be transmitted by the endpoint. Access to this memory is
performed by the packet buffer interface block, which delivers a memory access request and
waits for its acknowledgement. Since the packet buffer memory has to be accessed by the
microcontroller also, an arbitration logic takes care of the access conflicts, using half APB
cycle for microcontroller access and the remaining half for the USB Peripheral access. In this
way, both the agents can operate as if the packet memory is a dual-port RAM, without being
aware of any conflict even when the microcontroller is performing back-to-back accesses. The
USB Peripheral logic uses a dedicated clock. The frequency of this dedicated clock is fixed by
the requirements of the USB standard at 48 MHz, and this can be different from the clock
used for the interface to the APB bus. Different clock configurations are possible where the
APB clock frequency can be higher or lower than the USB Peripheral one. However, due to
USB data rate and packet memory interface requirements, the APB clock frequency must be
greater than 8 MHz to avoid data overrun/underrun problems.
Each endpoint is associated with two packet buffers (usually one for transmission and the
other one for reception). Buffers can be placed anywhere inside the packet memory because
their location and size is specified in a buffer description table, which is also located in the
packet memory at the address indicated by the USB_BTABLE register. Each table entry is
associated to an endpoint register and it is composed of four 16-bit words so that table start
address must always be aligned to an 8-byte boundary (the lowest three bits of USB_BTABLE
register are always “000”). Buffer descriptor table entries are described in the Section “Buffer
Descriptor Table”. If an endpoint is unidirectional and it is neither an Isochronous nor a
double-buffered bulk, only one packet buffer is required (the one related to the supported
271/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
transfer direction). Other table locations related to unsupported transfer directions or unused
endpoints, are available to the user. isochronous and double-buffered bulk endpoints have
special handling of packet buffers (Refer to “Isochronous Transfers” and “Double-Buffered
Endpoints”” respectively). The relationship between buffer description table entries and
packet buffer areas is depicted in Figure 71.
Figure 71. Packet Buffer Areas and Buffer Description Table Locations
Each packet buffer is used either during reception or transmission starting from the bottom.
The USB Peripheral will never change the contents of memory locations adjacent to the
allocated memory buffers; if a packet bigger than the allocated buffer length is received (buffer
overrun condition) the data will be copied to the memory only up to the last available location.
272/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The first step to initialize an endpoint is to write appropriate values to the ADDRn_TX/
ADDRn_RX registers so that the USB Peripheral finds the data to be transmitted already
available and the data to be received can be buffered. The EP_TYPE bits in the USB_EPnR
register must be set according to the endpoint type, eventually using the EP_KIND bit to
enable any special required feature. On the transmit side, the endpoint must be enabled using
the STAT_TX bits in the USB_EPnR register and COUNTn_TX must be initialized. For
reception, STAT_RX bits must be set to enable reception and COUNTn_RX must be written
with the allocated buffer size using the BL_SIZE and NUM_BLOCK fields. Unidirectional
endpoints, except Isochronous and double-buffered bulk endpoints, need to initialize only bits
and registers related to the supported direction. Once the transmission and/or reception are
enabled, register USB_EPnR and locations ADDRn_TX/ADDRn_RX, COUNTn_TX/
COUNTn_RX (respectively), should not be modified by the application software, as the
hardware can change their value on the fly. When the data transfer operation is completed,
notified by a CTR interrupt event, they can be accessed again to re-enable a new operation.
When receiving an IN token packet, if the received address matches a configured and valid
endpoint one, the USB Peripheral accesses the contents of ADDRn_TX and COUNTn_TX
locations inside buffer descriptor table entry related to the addressed endpoint. The content of
these locations is stored in its internal 16 bit registers ADDR and COUNT (not accessible by
software). The packet memory is accessed again to read the first word to be transmitted
(Refer to Section “Structure and Usage of Packet Buffers”) and starts sending a DATA0 or
DATA1 PID according to USB_EPnR bit DTOG_TX. When the PID is completed, the first byte
from the word, read from buffer memory, is loaded into the output shift register to be
transmitted on the USB bus. After the last data byte is transmitted, the computed CRC is sent.
If the addressed endpoint is not valid, a NAK or STALL handshake packet is sent instead of
the data packet, according to STAT_TX bits in the USB_EPnR register.
The ADDR internal register is used as a pointer to the current buffer memory location while
COUNT is used to count the number of remaining bytes to be transmitted. Each word read
from the packet buffer memory is transmitted over the USB bus starting from the least
significant byte. Transmission buffer memory is read starting from the address pointed by
ADDRn_TX for COUNTn_TX/2 words. If a transmitted packet is composed of an odd number
of bytes, only the lower half of the last word accessed will be used.
On receiving the ACK receipt by the host, the USB_EPnR register is updated in the following
way: DTOG_TX bit is toggled, the endpoint is made invalid by setting STAT_TX=10 (NAK) and
bit CTR_TX is set. The application software must first identify the endpoint, which is
requesting microcontroller attention by examining the EP_ID and DIR bits in the USB_ISTR
register. Servicing of the CTR_TX event starts clearing the interrupt bit; the application
software then prepares another buffer full of data to be sent, updates the COUNTn_TX table
location with the number of byte to be transmitted during the next transfer, and finally sets
STAT_TX to ‘11’ (VALID) to re-enable transmissions. While the STAT_TX bits are equal to ‘10’
273/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
(NAK), any IN request addressed to that endpoint is NAKed, indicating a flow control
condition: the USB host will retry the transaction until it succeeds. It is mandatory to execute
the sequence of operations in the above mentioned order to avoid losing the notification of a
second IN transaction addressed to the same endpoint immediately following the one which
triggered the CTR interrupt.
These two tokens are handled by the USB Peripheral more or less in the same way; the
differences in the handling of SETUP packets are detailed in the following paragraph about
control transfers. When receiving an OUT/SETUP PID, if the address matches a valid
endpoint, the USB Peripheral accesses the contents of the ADDRn_RX and COUNTn_RX
locations inside the buffer descriptor table entry related to the addressed endpoint. The
content of the ADDRn_RX is stored directly in its internal register ADDR. While COUNT is
now reset and the values of BL_SIZE and NUM_BLOCK bit fields, which are read within
COUNTn_RX content are used to initialize BUF_COUNT, an internal 16 bit counter, which is
used to check the buffer overrun condition (all these internal registers are not accessible by
software). Data bytes subsequently received by the USB Peripheral are packed in words (the
first byte received is stored as least significant byte) and then transferred to the packet buffer
starting from the address contained in the internal ADDR register while BUF_COUNT is
decremented and COUNT is incremented at each byte transfer. When the end of DATA packet
is detected, the correctness of the received CRC is tested and only if no errors occurred
during the reception, an ACK handshake packet is sent back to the transmitting host. In case
of wrong CRC or other kinds of errors (bit-stuff violations, frame errors, etc.), data bytes are
anyways copied in the packet memory buffer, at least until the error detection point, but ACK
packet is not sent and the ERR bit in USB_ISTR register is set. However, there is usually no
software action required in this case: the USB Peripheral recovers from reception errors and
remains ready for the next transaction to come. If the addressed endpoint is not valid, a NAK
or STALL handshake packet is sent instead of the ACK, according to bits STAT_RX in the
USB_EPnR register and no data is written in the reception memory buffers.
Reception memory buffer locations are written starting from the address contained in the
ADDRn_RX for a number of bytes corresponding to the received data packet length, CRC
included (i.e. data payload length + 2), or up to the last allocated memory location, as defined
by BL_SIZE and NUM_BLOCK, whichever comes first. In this way, the USB Peripheral never
writes beyond the end of the allocated reception memory buffer area. If the length of the data
packet payload (actual number of bytes used by the application) is greater than the allocated
buffer, the USB Peripheral detects a buffer overrun condition. in this case, a STALL
handshake is sent instead of the usual ACK to notify the problem to the host, no interrupt is
generated and the transaction is considered failed.
When the transaction is completed correctly, by sending the ACK handshake packet, the
internal COUNT register is copied back in the COUNTn_RX location inside the buffer
description table entry, leaving unaffected BL_SIZE and NUM_BLOCK fields, which normally
do not require to be re-written, and the USB_EPnR register is updated in the following way:
DTOG_RX bit is toggled, the endpoint is made invalid by setting STAT_RX = ‘10’ (NAK) and bit
274/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
CTR_RX is set. If the transaction has failed due to errors or buffer overrun condition, none of
the previously listed actions take place. The application software must first identify the
endpoint, which is requesting microcontroller attention by examining the EP_ID and DIR bits
in the USB_ISTR register. The CTR_RX event is serviced by first determining the transaction
type (SETUP bit in the USB_EPnR register); the application software must clear the interrupt
flag bit and get the number of received bytes reading the COUNTn_RX location inside the
buffer description table entry related to the endpoint being processed. After the received data
is processed, the application software should set the STAT_RX bits to ‘11’ (Valid) in the
USB_EPnR, enabling further transactions. While the STAT_RX bits are equal to ‘10’ (NAK),
any OUT request addressed to that endpoint is NAKed, indicating a flow control condition: the
USB host will retry the transaction until it succeeds. It is mandatory to execute the sequence
of operations in the above mentioned order to avoid losing the notification of a second OUT
transaction addressed to the same endpoint following immediately the one which triggered
the CTR interrupt.
Control transfers are made of a SETUP transaction, followed by zero or more data stages, all
of the same direction, followed by a status stage (a zero-byte transfer in the opposite
direction). SETUP transactions are handled by control endpoints only and are very similar to
OUT ones (data reception) except that the values of DTOG_TX and DTOG_RX bits of the
addressed endpoint registers are set to 1 and 0 respectively, to initialize the control transfer,
and both STAT_TX and STAT_RX are set to ‘10’ (NAK) to let software decide if subsequent
transactions must be IN or OUT depending on the SETUP contents. A control endpoint must
check SETUP bit in the USB_EPnR register at each CTR_RX event to distinguish normal
OUT transactions from SETUP ones. A USB device can determine the number and direction
of data stages by interpreting the data transferred in the SETUP stage, and is required to
STALL the transaction in the case of errors. To do so, at all data stages before the last, the
unused direction should be set to STALL, so that, if the host reverses the transfer direction too
soon, it gets a STALL as a status stage. While enabling the last data stage, the opposite
direction should be set to NAK, so that, if the host reverses the transfer direction (to perform
the status stage) immediately, it is kept waiting for the completion of the control operation. If
the control operation completes successfully, the software will change NAK to VALID,
otherwise to STALL. At the same time, if the status stage will be an OUT, the STATUS_OUT
(EP_KIND in the USB_EPnR register) bit should be set, so that an error is generated if a
status transaction is performed with not-zero data. When the status transaction is serviced,
the application clears the STATUS_OUT bit and sets STAT_RX to VALID (to accept a new
command) and STAT_TX to NAK (to delay a possible status stage immediately following the
next setup).
Since the USB specification states that a SETUP packet cannot be answered with a
handshake different from ACK, eventually aborting a previously issued command to start the
new one, the USB logic doesn’t allow a control endpoint to answer with a NAK or STALL
packet to a SETUP token received from the host.
275/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When the STAT_RX bits are set to ‘01’ (STALL) or ‘10’ (NAK) and a SETUP token is received,
the USB accepts the data, performing the required data transfers and sends back an ACK
handshake. If that endpoint has a previously issued CTR_RX request not yet acknowledged
by the application (i.e. CTR_RX bit is still set from a previously completed reception), the USB
discards the SETUP transaction and does not answer with any handshake packet regardless
of its state, simulating a reception error and forcing the host to send the SETUP token again.
This is done to avoid losing the notification of a SETUP transaction addressed to the same
endpoint immediately following the transaction, which triggered the CTR_RX interrupt.
All different endpoint types defined by the USB standard represent different traffic models,
and describe the typical requirements of different kind of data transfer operations. When large
portions of data are to be transferred between the host PC and the USB function, the bulk
endpoint type is the most suited model. This is because the host schedules bulk transactions
so as to fill all the available bandwidth in the frame, maximizing the actual transfer rate as long
as the USB function is ready to handle a bulk transaction addressed to it. If the USB function
is still busy with the previous transaction when the next one arrives, it will answer with a NAK
handshake and the host PC will issue the same transaction again until the USB function is
ready to handle it, reducing the actual transfer rate due to the bandwidth occupied by
re-transmissions. For this reason, a dedicated feature called ‘double-buffering’ can be used
with bulk endpoints.
When ‘double-buffering’ is activated, data toggle sequencing is used to select, which buffer is
to be used by the USB Peripheral to perform the required data transfers, using both
‘transmission’ and ‘reception’ packet memory areas to manage buffer swapping on each
successful transaction in order to always have a complete buffer to be used by the application,
while the USB Peripheral fills the other one. For example, during an OUT transaction directed
to a ‘reception’ double-buffered bulk endpoint, while one buffer is being filled with new data
coming from the USB host, the other one is available for the microcontroller software usage
(the same would happen with a ‘transmission’ double-buffered bulk endpoint and an IN
transaction).
Since the swapped buffer management requires the usage of all 4 buffer description table
locations hosting the address pointer and the length of the allocated memory buffers, the
USB_EPnR registers used to implement double-buffered bulk endpoints are forced to be used
as uni-directional ones. Therefore, only one STAT bit pair must be set at a value different from
‘00’ (Disabled): STAT_RX if the double-buffered bulk endpoint is enabled for reception,
STAT_TX if the double-buffered bulk endpoint is enabled for transmission. In case it is
required to have double-buffered bulk endpoints enabled both for reception and transmission,
two USB_EPnR registers must be used.
To exploit the double-buffering feature and reach the highest possible transfer rate, the
endpoint flow control structure, described in previous chapters, has to be modified, in order to
switch the endpoint status to NAK only when a buffer conflict occurs between the USB
Peripheral and application software, instead of doing it at the end of each successful
276/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
transaction. The memory buffer which is currently being used by the USB Peripheral is
defined by the DTOG bit related to the endpoint direction: DTOG_RX (bit 14 of USB_EPnR
register) for ‘reception’ double-buffered bulk endpoints or DTOG_TX (bit 6 of USB_EPnR
register) for ‘transmission’ double-buffered bulk endpoints. To implement the new flow control
scheme, the USB Peripheral should know which packet buffer is currently in use by the
application software, so to be aware of any conflict. Since in the USB_EPnR register, there
are two DTOG bits but only one is used by USB Peripheral for data and buffer sequencing
(due to the uni-directional constraint required by double-buffering feature) the other one can
be used by the application software to show which buffer it is currently using. This new buffer
flag is called SW_BUF. In the following table the correspondence between USB_EPnR
register bits and DTOG/SW_BUF definition is explained, for the cases of ‘transmission’ and
‘reception’ double-buffered bulk endpoints.
Table 48. Double-Buffering Buffer Flag Definition
The memory buffer which is currently being used by the USB Peripheral is defined by DTOG
buffer flag, while the buffer currently in use by application software is identified by SW_BUF
buffer flag. The relationship between the buffer flag value and the used packet buffer is the
same in both cases, and it is listed in the following table.
Table 49. Double-Buffering Memory Buffers Usage
0 ADDRn_TX / COUNTn_TX
buffer description table locations.
1 ADDRn_RX / COUNTn_RX
buffer description table locations.
• writing EP_TYPE bit field at ‘00’ in its USB_EPnR register, to define the endpoint as a
bulk, and
• setting EP_KIND bit at ‘1’ (DBL_BUF), in the same register.
The application software is responsible for DTOG and SW_BUF bits initialization according to
the first buffer to be used; this has to be done considering the special toggle-only property that
these two bits have. The end of the first transaction occurring after having set DBL_BUF,
277/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
triggers the special flow control of double-buffered bulk endpoints, which is used for all other
transactions addressed to this endpoint until DBL_BUF remain set. At the end of each
transaction the CTR_RX or CTR_TX bit of the addressed endpoint USB_EPnR register is set,
depending on the enabled direction. At the same time, the affected DTOG bit in the
USB_EPnR register is hardware toggled making the USB Peripheral buffer swapping
completely software independent. Unlike common transactions, and the first one after
DBL_BUF setting, STAT bit pair is not affected by the transaction termination and its value
remains ‘11’ (Valid). However, as the token packet of a new transaction is received, the actual
endpoint status will be masked as ‘10’ (NAK) when a buffer conflict between the USB
Peripheral and the application software is detected (this condition is identified by DTOG and
SW_BUF having the same value). The application software responds to the CTR event
notification by clearing the interrupt flag and starting any required handling of the completed
transaction. When the application packet buffer usage is over, the software toggles the
SW_BUF bit, writing ‘1’ to it, to notify the USB Peripheral about the availability of that buffer. In
this way, the number of NAKed transactions is limited only by the application elaboration time
of a transaction data: if the elaboration time is shorter than the time required to complete a
transaction on the USB bus, no re-transmissions due to flow control will take place and the
actual transfer rate will be limited only by the host PC.
The application software can always override the special flow control implemented for
double-buffered bulk endpoints, writing an explicit status different from ‘11’ (Valid) into the
STAT bit pair of the related USB_EPnR register. In this case, the USB Peripheral will always
use the programmed endpoint status, regardless of the buffer usage condition.
The USB standard supports full speed peripherals requiring a fixed and accurate data
production/consume frequency, defining this kind of traffic as ‘Isochronous’. Typical examples
of this data are: audio samples, compressed video streams, and in general any sort of
sampled data having strict requirements for the accuracy of delivered frequency. When an
endpoint is defined to be ‘isochronous’ during the enumeration phase, the host allocates in
the frame the required bandwidth and delivers exactly one IN or OUT packet each frame,
depending on endpoint direction. To limit the bandwidth requirements, no re-transmission of
failed transactions is possible for Isochronous traffic; this leads to the fact that an isochronous
transaction does not have a handshake phase and no ACK packet is expected or sent after
the data packet. For the same reason, Isochronous transfers do not support data toggle
sequencing and always use DATA0 PID to start any data packet.
The Isochronous behaviour for an endpoint is selected by setting the EP_TYPE bits at ‘10’ in
its USB_EPnR register; since there is no handshake phase the only legal values for the
STAT_RX/STAT_TX bit pairs are ‘00’ (Disabled) and ‘11’ (Valid), any other value will produce
results not compliant to USB standard. Isochronous endpoints implement double-buffering to
ease application software development, using both ‘transmission’ and ‘reception’ packet
memory areas to manage buffer swapping on each successful transaction in order to have
always a complete buffer to be used by the application, while the USB Peripheral fills the
other.
278/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The memory buffer which is currently used by the USB Peripheral is defined by the DTOG bit
related to the endpoint direction (DTOG_RX for ‘reception’ isochronous endpoints, DTOG_TX
for ‘transmission’ isochronous endpoints, both in the related USB_EPnR register) according
to Table 50.
The application software is responsible for the DTOG bit initialization according to the first
buffer to be used; this has to be done considering the special toggle-only property that these
two bits have. At the end of each transaction, the CTR_RX or CTR_TX bit of the addressed
endpoint USB_EPnR register is set, depending on the enabled direction. At the same time,
the affected DTOG bit in the USB_EPnR register is hardware toggled making buffer swapping
completely software independent. STAT bit pair is not affected by transaction completion;
since no flow control is possible for Isochronous transfers due to the lack of handshake phase,
the endpoint remains always ‘11’ (Valid). CRC errors or buffer-overrun conditions occurring
during Isochronous OUT transfers are anyway considered as correct transactions and they
always trigger an CTR_RX event. However, CRC errors will anyway set the ERR bit in the
USB_ISTR register to notify the software of the possible data corruption.
The USB standard defines a special peripheral state, called SUSPEND, in which the average
current drawn from the USB bus must not be greater than 500 µA. This requirement is of
fundamental importance for bus-powered devices, while self-powered devices are not
required to comply to this strict power consumption constraint. In suspend mode, the host PC
sends the notification to not send any traffic on the USB bus for more than 3mS: since a SOF
packet must be sent every mS during normal operations, the USB Peripheral detects the lack
of 3 consecutive SOF packets as a suspend request from the host PC and set the SUSP bit to
‘1’ in USB_ISTR register, causing an interrupt if enabled. Once the device is suspended, its
normal operation can be restored by a so called RESUME sequence, which can be started
279/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
from the host PC or directly from the peripheral itself, but it is always terminated by the host
PC. The suspended USB Peripheral must be anyway able to detect a RESET sequence,
reacting to this event as a normal USB reset event.
A brief description of a typical suspend procedure is provided below, focused on the USB-
related aspects of the application software routine responding to the SUSP notification of the
USB Peripheral:
1. Set the FSUSP bit in the USB_CNTR register to 1. This action activates the suspend
mode within the USB Peripheral. As soon as the suspend mode is activated, the check on
SOF reception is disabled to avoid any further SUSP interrupts being issued while the
USB is suspended.
2. Remove or reduce any static power consumption in blocks different from the USB Periph-
eral.
3. Set LP_MODE bit in USB_CNTR register to 1 to remove static power consumption in the
analog USB transceivers but keeping them able to detect resume activity.
4. Optionally turn off external oscillator and device PLL to stop any activity inside the device.
When an USB event occurs while the device is in SUSPEND mode, the RESUME procedure
must be invoked to restore nominal clocks and regain normal USB behaviour. Particular care
must be taken to insure that this process does not take more than 10mS when the wakening
event is an USB reset sequence (See “Universal Serial Bus Specification” for more details).
The start of a resume or reset sequence, while the USB Peripheral is suspended, clears the
LP_MODE bit in USB_CNTR register asynchronously. Even if this event can trigger an
WKUP interrupt if enabled, the use of an interrupt response routine must be carefully
evaluated because of the long latency due to system clock restart; to have the shorter latency
before re-activating the nominal clock it is suggested to put the resume procedure just after
the end of the suspend one, so its code is immediately executed as soon as the system clock
restarts. To prevent ESD discharges or any other kind of noise from waking-up the system
(the exit from suspend mode is an asynchronous event), a suitable analog filter on data line
status is activated during suspend; the filter width is about 70nS.
280/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
RESET bit in USB_ISTR register is set to 1, issuing an interrupt if enabled, which should
be handled as usual.
[RXDP,RXDM]
Wake-up event Required resume software action
Status
A device may require to exit from suspend mode as an answer to particular events not directly
related to the USB protocol (e.g. a mouse movement wakes up the whole system). In this
case, the resume sequence can be started by setting the RESUME bit in the USB_CNTR
register to ‘1’ and resetting it to 0 after an interval between 1mS and 15mS (this interval can
be timed using ESOF interrupts, occurring with a 1mS period when the system clock is
running at nominal frequency). Once the RESUME bit is clear, the resume sequence will be
completed by the host PC and its end can be monitored again using the RXDP and RXDM
bits in the USB_FNR register.
Note The RESUME bit must be anyway used only after the USB Peripheral has been put
in suspend mode, setting the FSUSP bit in USB_CNTR register to 1.
281/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
read/write (rw) The software can read and write to these bits.
read-only (r) The software can only read these bits.
write-only (w) The software can only write to these bits.
Read-clear (rc_w0) The software can only read or clear this bit by writing ‘0’.
Writing ‘1’ has no effect.
Toggle (t) The software can only toggle this bit by writing ‘1’. Writing ‘0’
has no effect.
PMA Packet Memory Area
282/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
These registers affect the general behaviour of the USB Peripheral defining operating mode,
interrupt handling, device address and giving access to the current frame number updated by
the host PC.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RESUME
RESETM
WKUPM
DOVRM
SUSPM
ESOFM
FSUSP
PDWN
MODE
ERRM
CTRM
SOFM
FRES
LP
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw
283/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
These are reserved bits. These bits are always read as ‘0’ and must always
be written with ‘0’.
The microcontroller can set this bit to send a Resume signal to the host. It
must be activated, according to USB specifications, for no less than 1mS
and no more than 15mS after which the Host PC is ready to drive the
resume sequence up to its end.
284/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
This bit is used to completely switch off all USB-related analog parts if it is
required to completely disable the USB Peripheral for any reason. When
this bit is set, the USB Peripheral is disconnected from the transceivers and
it cannot be used.
0: Exit Power Down.
1: Enter Power down mode.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RESET
WKUP
DOVR
SUSP
ESOF
ERR
SOF
CTR
DIR
Reserved EP_ID[3:0]
This register contains the status of all the interrupt sources allowing application software to
determine, which events caused an interrupt request.
The upper part of this register contains single bits, each of them representing a specific event.
These bits are set by the hardware when the related event occurs; if the corresponding bit in
the USB_CNTR register is set, a generic interrupt request is generated. The interrupt routine,
examining each bit, will perform all necessary actions, and finally it will clear the serviced bits.
If any of them is not cleared, the interrupt is considered to be still pending, and the interrupt
line will be kept high again. If several bits are set simultaneously, only a single interrupt will be
generated.
285/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• Higher priority USB IRQ: The pending requests for endpoints, which have transactions
with a higher priority (isochronous and double-buffered bulk) and they cannot be masked.
• Lower priority USB IRQ: All other interrupt conditions, which can either be non-maskable
pending requests related to the lower priority transactions and all other maskable events
flagged by the USB_ISTR high bytes.
For endpoint-related interrupts, the software can use the Direction of Transaction (DIR) and
EP_ID read-only bits to identify, which endpoint made the last interrupt request and called the
corresponding interrupt service routine.
The user can choose the relative priority of simultaneously pending USB_ISTR events by
specifying the order in which software checks USB_ISTR bits in an interrupt service routine.
Only the bits related to events, which are serviced, are cleared. At the end of the service
routine, another interrupt will be requested, to service the remaining conditions.
To avoid spurious clearing of some bits, it is recommended to clear them with a load
instruction where all bits which must not be altered are written with 1, and all bits to be cleared
are written with ‘0’ (these bits can only be cleared by software). Read-modify-write cycles
should be avoided because between the read and the write operations another bit could be
set by the hardware and the next write will clear it before the microprocessor has the time to
serve the event.
286/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
287/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Set when the USB Peripheral detects an active USB RESET signal at its inputs.
The USB Peripheral, in response to a RESET, just resets its internal protocol state
machine, generating an interrupt if RESETM enable bit in the USB_CNTR register
is set. Reception and transmission are disabled until the RESET bit is cleared. All
configuration registers do not reset: the microcontroller must explicitly clear these
registers (this is to ensure that the RESET interrupt can be safely delivered, and
any transaction immediately followed by a RESET can be completed). The
function address and endpoint registers are reset by an USB reset event.
This bit is read/write but only ‘0’ can be written and writing ‘1’ has no effect.
Bit 9 SOF: Start Of Frame
This bit signals the beginning of a new USB frame and it is set when a SOF packet
arrives through the USB bus. The interrupt service routine may monitor the SOF
events to have a 1mS synchronization event to the USB host and to safely read
the USB_FNR register which is updated at the SOF packet reception (this could
be useful for isochronous applications). This bit is read/write but only ‘0’ can be
written and writing ‘1’ has no effect.
Bit 8 ESOF: Expected Start Of Frame
This bit is set by the hardware when an SOF packet is expected but not received.
The host sends an SOF packet each mS, but if the hub does not receive it
properly, the Suspend Timer issues this interrupt. If three consecutive ESOF
interrupts are generated (i.e. three SOF packets are lost) without any traffic
occurring in between, a SUSP interrupt is generated. This bit is set even when the
missing SOF packets occur while the Suspend Timer is not yet locked. This bit is
read/write but only ‘0’ can be written and writing ‘1’ has no effect.
Bits 7:5 Reserved.
These are reserved bits. These bits are always read as ‘0’ and must always be
written with ‘0’.
288/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
If DIR bit=0, CTR_TX bit is set in the USB_EPnR register related to the
interrupting endpoint. The interrupting transaction is of IN type (data transmitted
by the USB Peripheral to the host PC).
If DIR bit=1, CTR_RX bit or both CTR_TX/CTR_RX are set in the USB_EPnR
register related to the interrupting endpoint. The interrupting transaction is of OUT
type (data received by the USB Peripheral from the host PC) or two pending
transactions are waiting to be processed.
289/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RXDM
RXDP
LCK
LSOF[1:0] FN[10:0]
r r r r r
This bit field contains the 11-bits frame number contained in the last
received SOF packet. The frame number is incremented for every frame
sent by the host and it is useful for Isochronous transfers. This bit field is
updated on the generation of an SOF interrupt.
290/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved EF ADD[6:0]
- rw rw
This register is also reset when a USB reset is received from the USB bus or forced through
bit FRES in the USB_CNTR register.
These are reserved bits. These bits are always read as ‘0’ and must always
be written with ‘0’.
This bit is set by the software to enable the USB device. The address of this
device is contained in the following ADD[6:0] bits. If this bit is at ‘0’ no
transactions are handled, irrespective of the settings of USB_EPnR
registers.
291/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BTABLE[15:3] Reserved
rw
These are reserved bits. These bits are always read as ‘0’ and must always
be written with ‘0’.
The STR71x USB Peripheral supports up to 16 bidirectional endpoints. Each USB device
must support a control endpoint whose address (EA bits) must be set to 0. The USB
Peripheral behaves in an undefined way if multiple endpoints are enabled having the same
endpoint number value. For each endpoint, an USB_EPnR register is available to store the
endpoint specific information.
292/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
STAT EP STAT
EA[3:0]
RX[1:0] TYPE[1:0] TX[1:0]
r-c t t r rw rw r-c t t rw
They are also reset when an USB reset is received from the USB bus or forced through bit
FRES in the CTLR register, except the CTR_RX and CTR_TX bits, which are kept unchanged
to avoid missing a correct packet notification immediately followed by an USB reset event.
Each endpoint has its USB_EPnR register where n is the endpoint identifier.
Read-modify-write cycles on these registers should be avoided because between the read
and the write operations some bits could be set by the hardware and the next write would
modify them before the microprocessor has the time to detect the change. For this purpose,
all bits affected by this problem have an ‘invariant’ value that must be used whenever their
modification is not required. It is recommended to modify these registers with a load
instruction where all the bits, which can be modified only by the hardware, are written with
their ‘invariant’ value.
A transaction ended with a NAK or STALL handshake does not set this bit,
since no data is actually transferred, as in the case of protocol errors or
data toggle mismatches.
This bit is read/write but only ‘0’ can be written, writing 1 has no effect.
293/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
294/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
295/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note A transaction ended with a NAK or STALL handshake does not set
this bit, since no data is actually transferred, as in the case of
protocol errors or data toggle mismatches.
296/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
STAT_RX[1:0] Meaning
01 STALL: the endpoint is stalled and all reception requests result in a STALL
handshake.
10 NAK: the endpoint is naked and all reception requests result in a NAK hand-
shake.
EP_TYPE[1:0] Meaning
00 BULK
01 CONTROL
10 ISO
297/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
EP_TYPE[1:0] Meaning
11 INTERRUPT
00 BULK DBL_BUF
01 CONTROL STATUS_OUT
STAT_TX[1:0] Meaning
01 STALL: the endpoint is stalled and all transmission requests result in a STALL
handshake.
10 NAK: the endpoint is naked and all transmission requests result in a NAK hand-
shake.
298/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Although this table is located inside packet buffer memory, its entries can be considered as
additional registers used to configure the location and size of packet buffers used to exchange
data between USB and the STR71x. Due to the common APB bridge limitation on word
addressability, all packet memory locations are accessed by the APB using 32-bit aligned
addresses, instead of the actual memory location addresses utilized by the USB Peripheral for
the USB_BTABLE register and buffer description table locations. In the following pages two
location addresses are reported: the one to be used by application software while accessing
the packet memory, and the local one relative to USB Peripheral access. To obtain the correct
STR71x memory address value to be used in the application software while accessing the
packet memory, the actual memory location address must be multiplied by two. The first
packet memory location is located at 0xC000 8000.
The buffer description table entry associated with the USB_EPnR registers is described
below. A thorough explanation of packet buffers and buffer descriptor table usage can be
found in the Section “Structure and Usage of Packet Buffers”.
299/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADDRn_TX[15:1] -
rw
Bit 0 Must always be written as ‘0’ since packet memory is word-wide and all
packet buffers must be word-aligned.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
- COUNTn_TX[9:0]
rw
Bits 15:10 These bits are not used since packet size is limited by USB specifications
to 1023 bytes. Their value is not considered by the USB Peripheral.
300/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADDRn_RX[15:1] -
rw
Bit 0 This bit must always be written as ‘0’ since packet memory is word-wide
and all packet buffers must be word-aligned.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BLSIZE
NUM_BLOCK[4:0] COUNTn_RX[9:0]
rw rw r
This table location is used to store two different values, both required during packet reception.
The most significant bits contains the definition of allocated buffer size, to allow buffer overflow
detection, while the least significant part of this location is written back by the USB Peripheral
at the end of reception to give the actual number of received bytes. Due to the restrictions on
the number of available bits, buffer size is represented using the number of allocated memory
blocks, where block size can be selected to choose the trade-off between fine-granularity/
small-buffer and coarse-granularity/large-buffer. The size of allocated buffer is a part of the
endpoint descriptor and it is normally defined during the enumeration process according to its
maxPacketSize parameter value (See “Universal Serial Bus Specification”).
301/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Bits 9:0 COUNTn_RX[9:0]. These bits contain the number of bytes received by the
endpoint associated with the USB_EPnR register during the last OUT/
SETUP transaction addressed to it.
17 (‘10001’) 34 bytes
18 (‘10010’) 36 bytes
30 (‘11110’) 60 bytes
302/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Off
15
14
13
12
11
10
Register 9 8 7 6 5 4 3 2 1 0
set
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x00 USB_EP0R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x04 USB_EP1R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x08 USB_EP2R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x0C USB_EP3R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x10 USB_EP4R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x14 USB_EP5R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x18 USB_EP6R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x1C USB_EP7R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x20 USB_EP8R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x24 USB_EP9R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
303/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Off
15
14
13
12
11
10
Register 9 8 7 6 5 4 3 2 1 0
set
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x28 USB_EP10R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x2C USB_EP11R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x30 USB_EP12R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x34 USB_EP13R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x38 USB_EP14R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR TX
SETUP
EP
STAT STAT
0x3C USB_EP15R TYPE[1: EA[3:0]
RX[1:0] TX[1:0]
0]
RESUME
RESETM
WKUPM
DOVRM
SUSPM
ESOFM
FSUSP
PDWN
ERRM
CTRM
SOFM
FRES
LP
ESOF
SUSP
ERR
SOF
CTR
DIR
LCK
LSOF
0x48 USB_FNR FN[10:0]
[1:0]
EF
304/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
- Two independent input clock lines (one in reception and one in transmission)
- Autoecho mode
305/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
All user information and protocol messages are transmitted in form of frames.The following
picture shows the format of the HDLC frame.
The HDLC, receives/transmits the serial bits of a byte starting from its least significant bit.
- Preamble
- Postamble
- Flag
The Flag is the unique binary number pattern (01111110). It provides the frame boundary
and a reference for the position of each field of the frame. A single flag can be used as
closing flag of a frame and as opening flag of next.
- Address Field
The field following the opening flag is defined as Address field. Its size is up to 32 bits.
A check on the address field with several programmable values can be performed to
accept or not the receive frame.
- Information Field
The information field precedes the FCS field. It contains any sequence of bytes.
The 16 bit preceding the closing flag is the FCS field. The FCS is an error detecting code
calculated from the remaining bits of the frame (flags excluded). The code used is the
CyclicRedundancyCheck CCITT (CRCCCITT, X16+X12+X5+1).
Both transmitter and receiver polynomial registers can be independently initialized to “1”s
or to “0s” .
306/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
one Receiver Part (HDLC Receiver ) and one Transmitter Part (HDLC Transmitter).
AEN
1 TCK HDLC
12-bit BRG ENCODER 0 HTXD
0 Transmitter
1
TCKS Transmit
HTEN RAM buffer
Receive
PLL2 PCLK1 RAM buffer
HDLC
Receiver
HRMC
RCKS
1
DECODER
RCK 0 HRXD
0 8-bit PRS
1
1 DPLL DPLLE
LBEN
Notes:
1. HTEN (HDLC Transmit ENable) signal is internally connected to Timer2 Output Compare
B (T2.OCMP_B) , this allows to trigger the start of the transmission using the Timer2,
enabling a precise timing for this event.
2. HRMC (HDLC Receive Message Complete) signal is internally connected to Timer2 Input
Capture B.
15.2.2.1 Receiver
■ Flag detection: a zero followed by six consecutive ones and another zero is recognized as
a flag.
■ Zero delete : a zero after five consecutive ones, within a HDLC frame, is deleted.
■ CRC checking: the CRC field is checked according to the generator polynomial
CRCCCITT. The checking result is reported in the CyclicRedundancyCheck bit (bit1=CRC)
of the Frame Status Byte register HDLC_FSBR.
307/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
■ Abort checking: seven or more consecutive ones within a frame are interpreted as Abort
condition.The detection of an abort condition is reported in the Receiver Abort bit (bit0=RAB)
of the Frame Status Byte register HDLC_FSBR.
■ Idle checking: fifteen or more consecutive ones are interpreted as Idle condition. The
detection of an idle condition is indicated in the RLS bits of the HDLC Status Register
HDLC_PSR.
■ Address field recognition: One private address of 32-maskable bits and 4 group
addresses of one maskable byte, one of which can be used as broadcast address, can be
recognised to accept the frame. The frame is accepted if the address field fits at least one of
the address register values according to the corresponding mask value that is, if bit n of
Mask registers is “0”, the comparison between the n bits of the receiver Address field and the
n bits of the Address register has no effect. Figure 73 shows the address filtering
mechanism. If the Private Address Mask registers ( HDLC_PAMH and HDLC_PAML) are
cleared any input frame is accepted. The Group Address recognition and the Private
Address must be enabled by setting the corresponding bit in the Receive Control
Register.The compared Group address is the first byte after the opening flag.
Figure 73. Address Field Recognition
MASK n
b0
ADDR n
bn 1 = OK
b30
b31
DATA n
308/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15.2.2.2 Transmitter
■ Preamble generation: a value from 0 to 16bit programmed in the Preamble Register, can
be transmitted before the opening flag. The number of preamble bits is defined in the
Transmission Control register.
The functionality must be enabled by setting the PREE bit of the Transmission Control
register.
■ Postamble generation: a value from 0 to 16bit programmed in the Postamble Register, can
be transmitted after the closing flag. The number of postamble bits is defined in the
Transmission Control register.
The functionality must be enabled by setting the POSE bit of the Transmission Control
register.
■ Flag generation: a flag is generated at the beginning and at the end of each frame.
■ Zero insertion: a zero bit is inserted after five consecutive ones within a HDLC frame.
■ CRC generation: the FCS field of the transmitter frame is generated according to the
generator polynomial CRCCCITT (X16+X12+X5+1).
■ Abort sequence generation: An abort sequence is generated when the HDLC frame is
aborted( programming to “0” the TEN bit of the HDLC Command Register) or when a
transmission overrun occurs(TDU = 1)
■ Interframe time fill: idle condition or Flags can be transmitted during the interframe time
according to the Interframe Time Fill bit of the TCTL Register .
309/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
■ Data Encoding/Decoding:
In addition to the classical NRZ code, the HDLC Controller is able to handle NRZI,FM0
and MANCHESTER codes (see Figure 74).
Figure 74. Data Encoding Example
DATA 1 1 0 0 1 0
NRZ
NRZI
FM0
MANCHESTER
Transmitter and receiver codes are independently selected through the RCOD bits of the
Receive Control Register and TCOD of the Transmission Control Register.
■ Clocks:
Three possible clocks could be used for clocking the HDLC transmit and receive blocks:
– PLL2 output
– PCLK1 (APB1 clock)
– DPLL (for data reception)
■ DPLL (Digital Phased Locked Loop):
An internal DPLL allows the recovery of the clock information from the receiving frame. The
DPLL input clock, taken from the Prescaler output, must be 16 times faster than the receiver
data rate.
If the DPLL is disabled (using DPLLE bit in HDLC_RCTL register),the HDLC can work in NRZ
and NRZI modes only, using the PLL2 input clock.
When the DPLL is enabled, its internal counter counts from 0 up to 15 (dividing the ideal bit
width in 16 subcells) and generates an output clock .
310/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
After a reset condition the DPLL, when enabled, enters in Search Mode. On the first data
edge, the DPLL enters in Synch Mode starting from count 0.
In NRZ and NRZI modes the DPLL divides the bit cell in the following four regions (see Figure
75):
When the DPLL is in Synch Mode, a data input signal edge involves one of the following
action depending upon which region it occurs:
– DPLL ignores the edge(i.e. no action are done) (in the ignore region)
– DPLL doubles next count 0 (in the increment region)
– DPLL skips next count 0 (in the decrement region)
– DPLL restarts at count 0 (in the search region)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
In FM0 and MANCHESTER modes the DPLL divides the bit cell in the following three regions
(see Figure 75):
When the DPLL is in Synch Mode, a data input signal edge, involves one of the following
actions depending upon which region it occurs:
311/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
DPLL stops the internal counter if one of the following condition happens:
DPLL will restart from count 0 on next data edge. After a reset condition the DPLL enters in
Search Mode.
On the first edge, the DPLL (if enabled) enters in Normal Mode, starting from count 0.
|t1| < D
|t2| < D
D D D D
IDEAL BIT CELL WIDTH
As soon as the DPLL is synchronized on the incoming data, it can keep the synchronism with
input pulse width variations (PhaseJitter) less than:
312/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
The HDLC has an 12-bit Baud Rate Generator in transmission and a 8-bit Prescaler in
reception. (see Figure 72).
The Baudrate and Prescaler Time Constant are programmed in the HDLC_BRR and
HDLC_PRS Registers and they give a division factor respectively from 1 up to 4096 and from
1 up to 256.
The frequency Fckout of the Prescaler or Baudrate Generator output clock is:
where division factor is equal to the HDLC_BRG+1 or HDLC_PRS+1 values and Fckin is the
frequency of Prescaler or Baudrate Generator input clock .
The HDLC Frame Check Sequence is calculated with the Cyclic Redundancy Check
procedure using the CCITT polynomial X16+X12+X5+1.
The internal CRC Generator and Checker can be indepentently preset to all “1s” or “0s”
according to the CRC Initialization selection bits (TCRCI bit of HDLC_TCTL register and
RCRCI of HDLC_RCTL register).
The following program shows in C language how the CRCCCITT pattern is generated:
313/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
FF[14]= FF[15];
FF[15]= R;
}
For instance, with the data pattern:
DAT[7][0] = d1 (hex)
DAT[15][8]= d2 (hex)
the CRC output pattern (with initialization to “1s”) is:
1100000100110010 ( FF[0]=1 ).
314/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
- Transmission
As long as the bit TEN in HDLC_PCR is low only idle or flag interframe are transmitted
according to the value of ITF bit of HDLC_TCTLR.
To start a Frame transmission, the following must be written:
– data into the Transmission Buffer (all the packet or until the Buffer is full) see Figure 77,
– the number of bytes to be transmitted in the HDLC_TFBC register
– bit TEN must be set to ‘1’ (by software or by hardware if HTEN = 1).
As soon register HDLC_TFBC is set, the HDLC starts postamble transmission, and reads
data from the buffer until it is half empty or the number of transmitted bytes matches the value
in HDLC_TFBC register.
In the first case an TBE (Transmission Buffer Empty) interrupt will be generated whereas in
the second case the CRC is evaluated, the closing flag and the postamble are generated.
When the last bit of the postamble (if any) or the flag or the last bit of abort sequence has
been transmitted the bit TEN is reset by hardware, the TMC (Transmission Message
Completed) interrupt is generated.
If the TEN bit is reset and the frame transmission is not completed yet, an abort sequence will
be generated.
If a TBE interrupt occurs and the previous one has not completed yet (bit TEN still set to ‘1’)
an error condition, that is the TDU(Transmission Data Underrun) interrupt, is generated and
the frame is aborted.
315/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
HW transmits CRC
n Flag,postamble;
TXCounter < TFBC Reg? Generates TMC IRQ
Clears TEN
y
HW Transmit byte
y
HW generates TBE IRQ
- Reception
As long as the REN (Receive ENable) bit in HDLC_PCR register is low no frame can be
received and the RBF interrupt is never generated.
When REN is written to ‘1’ the HDLC is able to receive a frame.
After the opening flag the HDLC checks the address and, if at least one among the Public and
Group addresses are valid or all address checks are disabled, it starts loading the data
(address included) into the Receive Buffer. Every time that half buffer is filled an RBF (Receive
Buffer Full) interrupt is generated.
When the last data has been loaded into the Receive Buffer and the postamble sequence (if
any) is completed an RMC(Receive Message Completed) or RME(Receive Message Error)
interrupt according to whether the frame has been successfully received(all checks are ok) or
not is generated. Furthermore the value of HDLC_RFBC (Receive Frame Byte Count) register
316/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
gives the total number of received bytes(FCS bytes are not loaded into the buffer) and the
HDLC_FSBR (Frame Status Byte) register gives information about the correctness of the
received frame.
An error condition can occur if an RBF interrupt occurs and the previous one has not been
completed (bit RBF still set to ‘1’). In this case the RFO(Receive Frame Overflow) interrupt is
generated.
As the RMC or RME occur the REN bit is reset by hardware and if the RMCE bit is set the
output trigger signal HRMC is activated.
SW sets REN
HW receives byte
Increments RXByte Count
HW checks frame
y Generates RMC (RME)
Closing Flag? Clears REN
y
HW generates RBF IRQ
317/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PAB3 PAB2
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
PAB1 PAB0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
318/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PAMB3 PAMB2
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
PAMB1 PAMB0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
319/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
BA GA2
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
GA1 GA0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
320/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
BAM GAM2
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
GAM1 GAM0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
321/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
PRESEQ
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
POSS
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
TCRC
HTEN SOC ITF TCOD PREE POSE NPREB NPOSB
I
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
322/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
rw rw rw rw rw rw rw rw rw rw rw rw rw
323/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
324/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
- - - TCKS BRG
rw rw rw rw rw rw rw rw rw rw rw rw rw
- - - - - - RCKS - PRS
rw rw rw rw rw rw rw rw rw rw
325/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
When a new receive clock source is selected the peripheral will be reset to avoid spurious
pulse generation and so any previous stored data will be lost.
Bit 8 = Reserved. This bit is read/write, but must always be written as '0'.
r r r r
326/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
r r r r
This register is updated when RMC (receive message completed) or RME (receive message
error) interrupt are generated.
TFBC
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
327/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
RFBC
r r r r r r r r r r r r r r r r
- - - - - - - - - - - - - - TEN REN
rw rw
328/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
rc rc rc rc rc rc rc
These bits are set by hardware and can be written only to ‘0’ by software.
329/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
rw rw rw rw rw rw rw
330/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
TCK
30 HDLC_BRR Reserved BRG
S
RCK
34 HDLC_PRSR Reserved - PSR
S
38 HDLC_PSR Reserved RBR TBR RLS
3C HDLC_FSBR Reserved RBC RDO CRC RAB
HDLC_TFBC
40 R
TFBC
HDLC_RFBC
44 R RFBC
331/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Two memory buffers,one for data reception and one for data transmission are mapped from
address offset 800h to 87Fh and from address offset 880h to 8FFh respectively.
Both the buffer sizes are 128 bytes in size and organized as 32 words of 32 bits.
32 words
LOW HALF Receive
83Fh buffer
840h
HIGH HALF
87Fh
880h
LOW HALF
32 words
8BFh Transmitter
buffer
8C0h
HIGH HALF
8FFh
The receive data must be read starting from the address offset 800h up to 83Fh or from 840h
up to 87Fh according to which half is full (RBR bit in PSR can be checked) and the data to be
transmitted must be loaded into transmitter buffer starting from the address offset 880h up to
8BFh or from 8C0h up to 8FFh according to which half is empty (TBR bit in PSR can be
checked).
The first received byte is the least significant byte of the buffer location at address offset 800h.
The first byte to be transmitted is the least significant byte of the buffer location at address off-
set 880h.
332/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
16.1 Introduction
The ADC is used to measure signal strength and other slowly-changing signals. Four input
channels are supported, with conversion rates of up to 1 kHz per channel.
Ch3 Data
Control/
Status IRQ
Prescaler
VCM
Bandgap Voltage Reference VRef
333/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
In its normal mode of operation, the converter samples each input channel for 512 cycles of
the oversampling clock. In the first clock cycle, the Sigma-Delta modulator is reset and the
digital filter cleared. The remaining 1-bit samples from the modulator are filtered by the Sinc3
filter and a 16 bit output sample supplied to the relevant data register after 511 clock cycles,
the period over which the Sinc3 filter has filled up and settled down. The channel select will
then switch to the next input channel, the reset will again be asserted on the first clock cycle,
and the filter will again fill up over 511 cycles to produce a sample. This process will be
repeated for each of the channels continually in a round-robin fashion.
When sampling a single channel, that channel alone will be selected as input to the analog
signal to the sigma-delta modulator. The functionality of the converter will remain the same as
above in that the converter will be reset every 512 cycles, once a valid sample is produced.
However, to maintain the same output frequency of the converter, only one of these samples
will be taken out of every four, i.e. a valid sample for the channel will be produced every 2048
clock cycles, as before.
Note:
In order to speed-up the ADC conversion of an input signal, you can use the Round-Robin
mode and connect the input signal to the four ADC input channels. Refer to AN1798: STR71x
ADC Conversion Speed-Up.
The Σ−∆ modulator must run at a clock frequency (fMod, oversampling rate) not greater than
2.1MHz for the ADC. Converter logic is clocked by PCLK2. Double clocked synchronization for
data crossing clock boundaries avoids any metastability issue. Based on the following
equations, it is up to the user to correctly program the prescaler in order to generate the
correct oversampling frequency based on the PCLK2 frequency:
fS = fMod /{512 * 4}
Example: If fPCLK2 is 16 MHz, and the desired input signal sampling frequency fs is 500 Hz,
the Σ−∆ modulator must run at 1.024MHz and the prescaler factor must be set to 0x8 (in the
ADC_CPR register) to get a prescaling of 16.
Note If the prescaler is set to generate a sampling frequency higher than specified,
conversion performance and accuracy is not guaranteed
334/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
An on-chip bandgap reference generates a 1.22V reference. This is used to generate two
voltages used by the modulator — VCM & VRef. VCM is designed to be 1.25V, the midpoint of
the converter’s voltage range and VRef is the feedback reference, 1.85V. As the bandgap
reference is not trimmed, absolute values of VCM & VRef could be inaccurate by up to ± 5%.
This will lead to gain and offset errors in the converter which can be calibrated out if
necessary by software.
To calibrate the converter, it is necessary to input the minimum and maximum inputs
supported — 0V and 2.5V. The digital output for a 0V input is the offset and the gain of the
converter is given by: G = ( 2.5Voutput – 0Voutput ) ⁄ 2.5 . The offset and gain correction
factors can be stored digitally and applied to all outputs from the converter, for all four input
channels.
The Σ−∆ converter produces a digital sample of each analog input channel every 512
oversampling clocks. The digital samples in output from the Sinc3 digital filter are stored in the
four ADC_DATA[n] registers as 16-bit samples of which only the first 12 MS bits are
significant. The converted value stored in ADC_DATA[n] is a signed two’s complent value and
proportional to the difference (VIN-VCM), being ideally 0 if the input voltage were VIN = VCM.
The folowing figure gives the ADC output (coded on 12 bits) versus the input voltage:
ADC_DATA
0xFFF
ADC_DATA(0V)
0x800
ADC_DATA(2.5V)
ADC_DATA(0V) and ADC_DATA(2.5V) are respectiveley the conversion results for 0V and
2.5V. These two values must be determined in order to calculate the ADC gain using the
following formula:
335/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Note The analog input voltage should not exceed twice the Center Voltage of the Σ-∆
Modulator (2 * VCM) otherwise converter performances cannot be guaranteed Also
the VCM Voltage has an accuracy of +/- 5% which imposes a calibration of the
converter.
The analog circuitry of the ADC block is switched on when bit “ADC_EN” in the
PCU_BOOTCR register is set. By default, this bit is cleared during reset and the power
consumption via AVDD / AVSS -pins is minimized. It is recommended to disable the ADC by
software before entering low power modes, if it was previously used.
Note Disabling the ADC with “ADC_EN” only switches, the analog section of the
Sigma-Delta Converter off. If ADC is not used, the digital section may be stopped as
well by means of “Bit 7” of the APB2_CKDIS register. This disables the clock for the
ADC.
The input equivalent circuit, due to the switching at fMod rate of the input capacitance where
the charge taken from the input signal to be measured is stored, can be represented as shown
in Figure 82.
where VS is the voltage under measurement, RS is the output resistance of the source, VPIN
the voltage that will actually be converted and RIN the input equivalent resistance of the ADC.
RIN is inversely proportional to the modulator oversampling clock. The constant K depends on
the operating mode of the converter and it is equal to:
336/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
337/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw
This register controls the operating mode of the ADC, sets the interrupt enables, contains
status flags for the availability of data and error flags in the event of data being overwritten
before being read.
338/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
This bit is set by hardware as soon as a new sample is available and must
be cleared by software by explicitly writing it to “0”. Writing it to “1” has no
effect. These bits also act as interrupt flags for the corresponding channels.
339/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved Presc[11:0]
340/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Four data registers, one for each of the analog input channels, are available. The 12 most
significant bits will contain the result of the conversion, while the 4 least significant bits of each
register should be ignored. The data registers will be filled in numerical sequence in the
round-robin channel mode. In single channel mode, only the selected channel will be
updated.
30 ADC_CPR - PRE[6:0]
341/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Each bridge has two 32-bit registers. Under software control, each peripheral can be
individually reset using the SWRES register. The PCLK signal to each peripheral (except the
Watchdog) also can be enabled/disabled individually using the CKDIS register. The CKDIS
register is also used to enable/disable the signal on the CKOUT pin. The clock output from this
pin is the PCLK2. The frequency, as programmed through the PRCCU (APBDIV register, see
Section 17)
Note: The APB Bridge registers MUST be accessed with 32-bit aligned operations (i.e. no
byte/half word cycles are allowed).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
342/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
Offset
9
8
7
6
5
4
3
2
1
0
00 Reserved reserved
04 Reserved reserved
08 Reserved reserved
0C Reserved reserved
10 APBn_CKDIS reserved Peripheral clock disable[14:0]
14 APBn_SWRES reserved Peripheral reset [14:0]
343/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
18 JTAG INTERFACE
18.1 Overview
STR71x is built around an ARM7TDMI core whose debug interface is Joint Test Action Group
(JTAG) based. ARM7TDMI contains hardware extensions for advanced debugging features.
The debug extensions allow the core to be stopped either on a given instruction fetch
(breakpoint) or data access (watchpoint) or asynchronously by a debug-request. When this
happens, ARM7TDMI® is said to be in debug state. At this point, the core’s internal state and
the system’s external state may be examined. Once examination is complete, the core and the
system may be restored and program execution resumed.
ARM7TDMI is forced into debug state either by a request on one of the external interface
signals or by an internal functional unit known as In-circuit Emulation Unit (ICE). Once in
debug state, the core isolates itself from the memory system. The core can then be examined
while all other system activity continues as normal.
ARM7TDMI’s internal state is examined via a JTAG-style serial interface, which allows
instructions to be serially inserted into the core’s pipeline without using the data bus. Thus,
when in debug state, a store-multiple (STM) could be inserted into the instruction pipeline and
this would dump the contents of the ARM7TDMI® registers. This data can be serially shifted
out without affecting the rest of the system.
The debug host is typically a computer running a software debugger. The debug host allows
the user to issue high level commands such as “set breakpoint at location XX” or “examine the
contents of memory from address 0x0 to 0x100”.
The debug host will be connected to the ARM7TDMI development system via an interface
(RS232, for example). The messages broadcast over this link must be converted to the
interface signals of the core. This function is performed by the protocol converter.
18.2.3 ARM7TDMI
The ARM7TDMI is the lowest level of the system. Its debug extensions allow the user to stall
the core from program execution, examine its internal state and the state of the memory
system and then resume the program execution.
344/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
DBGRQ
ICE
ARM CPU
TAP TAPSM[3:0]
Core
Controller IR[3:0]
Device
ID
SCANSEL
TCR
TLR
Test RSR
Logic
JTCK JTDI
nJTRST JTMS
TDO
According to IEEE 1149.1 standard (JTAG), the physical interface to the TAP controller is
based on five signals. Beyond their usage, the standard also gives a set of indications about
their reset status and the usage of pull-up resistors. These signals are:
345/349
1
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
• nJTRST: Test Reset. Active low reset signal for the TAP controller finite state machine.
This pin has to be held low at power-on in such a way so as to produce an initialization
(reset) of the controller. When out of reset, the pin must be pulled up. When the JTAG
interface is not in use, it may be held in its reset status, by grounding the nJTRST pin.
• JTDI: Test Data Input. To be pulled up by an external resistor.
• JTMS: Test Mode Select. To be pulled up by an external resistor. It must be high during ‘0’
to ‘1’ transition of nJTRST.
• JTCK: Test Clock. This clock is used to advance the TAP controller finite state machine.
The TAP state machine maintains its state indefinitely when JTCK is held low. Optionally,
similar behaviour is also obtained by holding the pin TCK high. The standard does not
impose any pull-up or pull-down resistor. A floating input is not recommended, to avoid
any static power consumption.
• JTDO: Test Data Output. This is the output from the boundary scan logic. This output is in
high impedance when not in use.
According to the standard, all interface signals should have an external pull-up or pull-down
resistor as follows:
• nJTRST Pull-up
• JTDI Pull-up
• JTMS Pull-up
• JTCK Pull-down or Pull up
• JTDO Floating or Pull-up/down (no static consumption anyway)
In STR71x, none of the previous resistors are implemented internally. Therefore, they need to
be implemented on the application board. In case, the JTAG interface is not used all the
interface pins can be grounded indefinitely. This will not introduce any additional power
consumption since there are no internal pull-up resistors. The following additional signals, not
part of the IEEE 1149.1 standard interface, are also made externally available to allow
external user logic to request debug events:
• DBGRQ. When high, the system requests the ARM7TDMI to unconditionally enter the
debug state. This pin must be kept LOW when emulation features are not enabled.
346/349
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
19 REVISION HISTORY
Table 65. Revision History
Date Revision Description of Changes
17-Mar-2004 1 First Release
Updated Figure 8.
02-Apr-2004 2 Changed name of BOOTCONF register to BOOTCR throughout document.
Modified Section 18.1: Pins and Reset status on page 391
08-Apr-2004 2.1 Corrected STR712F Pinout. Pins 43/42 swapped.
Corrected PDF links in Table of contents. Removed USB alternate function from
15-Apr-2004 2.2
P1.11 and P1.12 in
Corrected description of STDBY, V18, VSS18, V18BKP VSSBKP pins.
Updated BSPI max. baudrate.
Changed SystemMemory Boot mode to reserved
Changed APB registers to reserved
Removed duplicate I/O Schematics
Updated Flash Programming/Protection Section
Updated PRCCU section 3.7 on page 48
Updated Standby mode section 3.6.5 on page 44
19-Jul-2004 3 Added Voltage Regulator section 3.3 on page 37
Added LVD section 3.4 on page 38
Updated Power section 3.1 on page 33
Updated I2C frequency formula in Section 10.5
Updated ADC section 16 on page 347
Added Timer Special Features section 8.3 on page 133
Renamed FLASH POR bit to LVD RES in Section 3.7.5
Updated JTAG section 18 on page 359
Removed Emulation Section
Corrected Flash sector B1F0/F1 address in Figure 1 on page 16
Updated reset values in BCON1 and 2 registers in Figure 2.3.6 on page 31
Corrected Table 1, “Device Pin Description,” on page 22 TQFP64 TEST pin is
16 instead of 17.
Added TQPFP64 pin 7 BOOTEN and pin 17 V33IO-PLL
29-Oct-2004 4
Add table of definitions to section 3.7.5 on page 52
Added note in UART section 12.3.2 on page 255
Modified Note in UART section 12.3.5 on page 258
Added FrameError bit in UART section 12.4.3 on page 263
Changed UART RxBufFull Flag to RxBufNotEmpty in Section 12
347/349
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
348/349
STR71x MICROCONTROLLER FAMILY - REFERENCE MANUAL
Notes:
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences
of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted
by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject
to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not
authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics.
349/349