STM32F41120reference20manual.275109719 (2)
STM32F41120reference20manual.275109719 (2)
Reference manual
STM32F411xC/E advanced ARM®-based 32-bit MCUs
Introduction
This Reference manual targets application developers. It provides complete information on
how to use the memory and the peripherals of the STM32F411xC/E microcontroller.
STM32F411xC/E is part of the family of microcontrollers with different memory sizes,
packages and peripherals.
For ordering information, mechanical and electrical device characteristics refer to the
datasheets.
For information on the ARM® Cortex®-M4 with FPU core, refer to the Cortex®-M4 with FPU
Technical Reference Manual.
Related documents
Available from STMicroelectronics web site (http://www.st.com):
• STM32F411xC/E datasheet
For information on the ARM®-M4 core with FPU, refer to the STM32F3xx/F4xxx Cortex®-
M4 with FPU-M4 programming manual (PM0214).
Contents
1 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.1 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.2 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.3 Peripheral availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.5.5 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.6 Option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.6.1 Description of user option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.6.2 Programming user option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.6.3 Read protection (RDP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.6.4 Write protections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.6.5 Proprietary code readout protection (PCROP) . . . . . . . . . . . . . . . . . . . 56
3.7 One-time programmable bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.8 Flash interface registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.8.1 Flash access control register (FLASH_ACR) . . . . . . . . . . . . . . . . . . . . 58
3.8.2 Flash key register (FLASH_KEYR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.8.3 Flash option key register (FLASH_OPTKEYR) . . . . . . . . . . . . . . . . . . . 59
3.8.4 Flash status register (FLASH_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.8.5 Flash control register (FLASH_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.8.6 Flash option control register (FLASH_OPTCR) . . . . . . . . . . . . . . . . . . . 62
3.8.7 Flash interface register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
List of tables
List of figures
1 Documentation conventions
1.2 Glossary
This section gives a brief definition of acronyms and abbreviations used in this document:
• The CPU core integrates two debug ports:
– JTAG debug port (JTAG-DP) provides a 5-pin standard interface based on the
Joint Test Action Group (JTAG) protocol.
– SWD debug port (SWD-DP) provides a 2-pin (clock and data) interface based on
the Serial Wire Debug (SWD) protocol.
For both the JTAG and SWD protocols, please refer to the Cortex®-M4 with FPU
Technical Reference Manual
• Word: data/instruction of 32-bit length.
• Half word: data/instruction of 16-bit length.
• Byte: data of 8-bit length.
• Double word: data of 64-bit length.
• IAP (in-application programming): IAP is the ability to reprogram the Flash memory of a
microcontroller while the user program is running.
• ICP (in-circuit programming): ICP is the ability to program the Flash memory of a
microcontroller using the JTAG protocol, the SWD protocol or the bootloader while the
device is mounted on the user application board.
• I-Code: this bus connects the Instruction bus of the CPU core to the Flash instruction
interface. Prefetch is performed on this bus.
• D-Code: this bus connects the D-Code bus (literal load and debug access) of the CPU
to the Flash data interface.
• Option bytes: product configuration bits stored in the Flash memory.
• OBL: option byte loader.
• AHB: advanced high-performance bus.
• CPU: refers to the Cortex®-M4 with FPU core.
$50 *3 *3
&RUWH[0 '0$ '0$
'0$B0(0
'0$B3,
'0$B0(0
'0$B3
'EXV
6EXV
,EXV
6 6 6 6 6 6
0 ,&2'(
$&&(/
)ODVK
VHHQRWH
0 '&2'(
0 65$0
VHHQRWH
0 $+% $3%
SHULSK
0 $+%
SHULSK $3%
%XVPDWUL[6
069
2.1.1 I-bus
This bus connects the Instruction bus of the Cortex®-M4 with FPU core to the BusMatrix.
This bus is used by the core to fetch instructions. The target of this bus is a memory
containing code (internal Flash memory/SRAM).
2.1.2 D-bus
This bus connects the databus of the Cortex®-M4 with FPU to the BusMatrix. This bus is
used by the core for literal load and debug access. The target of this bus is a memory
containing code or data (internal Flash memory/SRAM).
2.1.3 S-bus
This bus connects the system bus of the Cortex®-M4 with FPU core to a BusMatrix. This
bus is used to access data located in a peripheral or in SRAM. Instructions may also be
fetch on this bus (less efficient than ICode). The targets of this bus are the internal SRAM,
the AHB1 peripherals including the APB peripherals and the AHB2 peripherals.
2.1.6 BusMatrix
The BusMatrix manages the access arbitration between masters. The arbitration uses a
round-robin algorithm.
0x4001 5000 - 0x4001 53FFF SPI5/I2S5 Section 20.5.10: SPI register map on page 602
0x4001 4800 - 0x4001 4BFF TIM11 Section 14.5.11: TIM10/11 register map on
0x4001 4400 - 0x4001 47FF TIM10 page 407
0x4001 4000 - 0x4001 43FF TIM9 Section 14.4.13: TIM9 register map on page 397
0x4001 3C00 - 0x4001 3FFF EXTI Section 10.3.7: EXTI register map on page 208
0x4001 3800 - 0x4001 3BFF SYSCFG Section 7.2.8: SYSCFG register map
0x4001 3400 - 0x4001 37FF SPI4/I2S4 APB2
Section 20.5.10: SPI register map on page 602
0x4001 3000 - 0x4001 33FF SPI1/I2S1
0x4001 2C00 - 0x4001 2FFF SDIO Section 21.9.16: SDIO register map on page 657
0x4001 2000 - 0x4001 23FF ADC1 Section 11.12.16: ADC register map on page 235
0x4001 1400 - 0x4001 17FF USART6
Section 19.6.8: USART register map on page 548
0x4001 1000 - 0x4001 13FF USART1
0x4001 0000 - 0x4001 03FF TIM1 Section 12.4.21: TIM1 register map on page 304
0x4000 7000 - 0x4000 73FF PWR Section 5.5: PWR register map on page 86
0x4000 5C00 - 0x4000 5FFF I2C3
0x4000 5800 - 0x4000 5BFF I2C2 Section 18.6.11: I2C register map on page 496
0x4000 5400 - 0x4000 57FF I2C1
0x4000 4400 - 0x4000 47FF USART2 Section 19.6.8: USART register map on page 548
0x4000 4000 - 0x4000 43FF I2S3ext
0x4000 3C00 - 0x4000 3FFF SPI3 / I2S3
Section 20.5.10: SPI register map on page 602
0x4000 3800 - 0x4000 3BFF SPI2 / I2S2
APB1
0x4000 3400 - 0x4000 37FF I2S2ext
0x4000 3000 - 0x4000 33FF IWDG Section 15.4.5: IWDG register map on page 415
0x4000 2C00 - 0x4000 2FFF WWDG Section 16.6.4: WWDG register map on page 422
0x4000 2800 - 0x4000 2BFF RTC & BKP Registers Section 17.6.21: RTC register map on page 459
0x4000 0C00 - 0x4000 0FFF TIM5
0x4000 0800 - 0x4000 0BFF TIM4
Section 13.4.21: TIMx register map on page 364
0x4000 0400 - 0x4000 07FF TIM3
0x4000 0000 - 0x4000 03FF TIM2
The CPU can access the embedded SRAM through the System Bus or through the I-
Code/D-Code buses when boot from SRAM is selected or when physical remap is selected
(Section 7.2.1: SYSCFG memory remap register (SYSCFG_MEMRMP) in the SYSCFG
controller). To get the max performance on SRAM execution, physical remap should be
selected (boot or software selection).
Example
The following example shows how to map bit 2 of the byte located at SRAM address
0x20000300 to the alias region:
0x22006008 = 0x22000000 + (0x300*32) + (2*4)
Writing to address 0x22006008 has the same effect as a read-modify-write operation on bit
2 of the byte at SRAM address 0x20000300.
Reading address 0x22006008 returns the value (0x01 or 0x00) of bit 2 of the byte at SRAM
address 0x20000300 (0x01: bit set; 0x00: bit reset).
For more information on bit-banding, please refer to the Cortex®-M4 with FPU programming
manual (see Related documents on page 1).
x 0 Main Flash memory Main Flash memory is selected as the boot space
0 1 System memory System memory is selected as the boot space
1 1 Embedded SRAM Embedded SRAM is selected as the boot space
The values on the BOOT pins are latched on the 4th rising edge of SYSCLK after a reset. It
is up to the user to set the BOOT1 and BOOT0 pins after reset to select the required boot
mode.
BOOT0 is a dedicated pin while BOOT1 is shared with a GPIO pin. Once BOOT1 has been
sampled, the corresponding GPIO pin is free and can be used for other purposes.
The BOOT pins are also resampled when the device exits the Standby mode. Consequently,
they must be kept in the required Boot mode configuration when the device is in the Standby
mode. After this startup delay is over, the CPU fetches the top-of-stack value from address
0x0000 0000, then starts code execution from the boot memory starting from 0x0000 0004.
Note: When the device boots from SRAM, in the application initialization code, you have to
relocate the vector table in SRAM using the NVIC exception table and the offset register.
Embedded bootloader
The embedded bootloader mode is used to reprogram the Flash memory using one of the
following serial interfaces:
• USART1 (PA9/PA10)
• USART2 (PD5/PD6)
• I2C1 (PB6/PB7)
• I2C2 (PB10/PB3)
• I2C3 (PA8/PB4)
• SPI1 (PA4/PA5/PA6/PA7)
• SPI2 (PB12/PB13/PB14/PB15)
• SPI3 (PA15/PC10/PC11/PC12)
• USB OTG FS (PA11/12) in Device mode (DFU: device firmware upgrade).
The USART peripherals operate at the internal 16 MHz oscillator (HSI) frequency, while the
USB OTG FS require an external clock (HSE) multiple of 1 MHz (ranging from 4 to 26 MHz).
The embedded bootloader code is located in system memory. It is programmed by ST
during production. For additional information, refer to application note AN2606.
0x2000 0000 - 0x2002 0000 SRAM1 (128 KB) SRAM1 (128KB) SRAM1 (128KB)
0x1FFF 0000 - 0x1FFF 77FF System memory System memory System memory
0x0804 0000 - 0x1FFE FFFF Reserved Reserved Reserved
0x0800 0000 - 0x0807 FFFF Flash memory Flash memory Flash memory
0x0400 000 - 0x07FF FFFF Reserved Reserved Reserved
SRAM1 (128 KB) System memory
0x0000 0000 - 0x0007 FFFF(1) Flash (512 KB) Aliased
Aliased (30 KB) Aliased
1. Even when aliased in the boot memory space, the related memory is still accessible at its original memory
space.
3.1 Introduction
The Flash memory interface manages CPU AHB I-Code and D-Code accesses to the Flash
memory. It implements the erase and program Flash memory operations and the read and
write protection mechanisms.
The Flash memory interface accelerates code execution with a system of instruction
prefetch and cache lines.
$+%
$+% SHULSK
ELW
'0$ V\VWHPEXV 65$0DQG
([WHUQDO
'0$ PHPRULHV
$+%
SHULSK
$FFHVVWRLQVWUXFWLRQLQ)ODVKPHPRU\
$FFHVVWRGDWDDQGOLWHUDOSRROLQ)ODVKPHPRU\
)/,7)UHJLVWHUDFFHVV
069
3.4.1 Relation between CPU clock frequency and Flash memory read time
To correctly read data from Flash memory, the number of wait states (LATENCY) must be
correctly programmed in the Flash access control register (FLASH_ACR) according to the
frequency of the CPU clock (HCLK) and the supply voltage of the device.
The prefetch buffer must be disabled when the supply voltage is below 2.1 V. The
correspondence between wait states and CPU clock frequency is given in Table 5.
- when VOS[1:0] = 0x01, the maximum value of fHCLK = 64 MHz.
- when VOS[1:0] = 0x10, the maximum value of fHCLK = 84 MHz.
- when VOS[1:0] = 0x11, the maximum value of fHCLK = 100 MHz.
0 WS (1 CPU cycle) 0 < HCLK≤ 30 0 < HCLK ≤ 24 0 < HCLK ≤ 18 0 < HCLK ≤ 16
1 WS (2 CPU cycles) 30 < HCLK ≤ 64 24 < HCLK ≤ 48 18 < HCLK ≤ 36 16 <HCLK ≤ 32
2 WS (3 CPU cycles) 64 < HCLK ≤ 90 48 < HCLK ≤ 72 36 < HCLK ≤ 54 32 < HCLK ≤ 48
3 WS (4 CPU cycles) 90 < HCLK ≤ 100 72 < HCLK ≤ 96 54 < HCLK ≤ 72 48 < HCLK ≤ 64
4 WS (5 CPU cycles) - 96 < HCLK ≤ 100 72 < HCLK ≤ 90 64 < HCLK ≤ 80
5 WS (6 CPU cycles) - - 90 < HCLK ≤ 100 80 < HCLK ≤ 96
6 WS (7 CPU cycles) - - - 96 < HCLK ≤ 100
After reset, the CPU clock frequency is 16 MHz and 0 wait state (WS) is configured in the
FLASH_ACR register.
It is highly recommended to use the following software sequences to tune the number of
wait states needed to access the Flash memory with the CPU frequency.
Instruction prefetch
Each Flash memory read operation provides 128 bits from either four instructions of 32 bits
or 8 instructions of 16 bits according to the program launched. So, in case of sequential
code, at least four CPU cycles are needed to execute the previous read instruction line.
Prefetch on the I-Code bus can be used to read the next sequential instruction line from the
Flash memory while the current instruction line is being requested by the CPU. Prefetch is
enabled by setting the PRFTEN bit in the FLASH_ACR register. This feature is useful if at
least one wait state is needed to access the Flash memory.
Figure 3 shows the execution of sequential 32-bit instructions with and without prefetch
when 3 WSs are needed to access the Flash memory.
& $ %
7!)4
7ITHOUT PREFETCH
& $ %
& $ %
& $ %
& $ %
7!)4
& $ %
& $
&
!(" PROTOCOL
INS INS INS INS INS INS INS INS
FETCH FETCH FETCH FETCH FETCH FETCH FETCH FETCH ADDRESS REQUESTED
& &ETCH STAGE
$ $ECODE STAGE
2EAD INS 'IVES INS 'IVES INS % %XECUTE STAGE
-36
When the code is not sequential (branch), the instruction may not be present in the currently
used instruction line or in the prefetched instruction line. In this case (miss), the penalty in
terms of number of cycles is at least equal to the number of wait states.
Data management
Literal pools are fetched from Flash memory through the D-Code bus during the execution
stage of the CPU pipeline. The CPU pipeline is consequently stalled until the requested
literal pool is provided. To limit the time lost due to literal pools, accesses through the AHB
databus D-Code have priority over accesses through the AHB instruction bus I-Code.
If some literal pools are frequently used, the data cache memory can be enabled by setting
the data cache enable (DCEN) bit in the FLASH_ACR register. This feature works like the
instruction cache memory, but the retained data size is limited to 8 rows of 128 bits.
Note: Data in user configuration sector are not cacheable.
Note: Any program or erase operation started with inconsistent program parallelism/voltage range
settings may lead to unpredicted results. Even if a subsequent read operation indicates that
the logical value was effectively written to the memory, this value may not be retained.
To use VPP, an external high-voltage supply (between 8 and 9 V) must be applied to the VPP
pad. The external supply must be able to sustain this voltage range even if the DC
consumption exceeds 10 mA. It is advised to limit the use of VPP to initial programming on
the factory line. The VPP supply must not be applied for more than an hour, otherwise the
Flash memory might be damaged.
3.5.3 Erase
The Flash memory erase operation can be performed at sector level or on the whole Flash
memory (Mass Erase). Mass Erase does not affect the OTP sector or the configuration
sector.
Sector Erase
To erase a sector, follow the procedure below:
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register
2. Set the SER bit and select the sector out of the 7 sectors (STM32F411xC/E) in the
main memory block you wish to erase (SNB) in the FLASH_CR register
3. Set the STRT bit in the FLASH_CR register
4. Wait for the BSY bit to be cleared
Mass Erase
To perform Mass Erase, the following sequence is recommended:
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register
2. Set the MER bit in the FLASH_CR register
3. Set the STRT bit in the FLASH_CR register
4. Wait for the BSY bit to be cleared
Note: If MERx and SER bits are both set in the FLASH_CR register, mass erase is performed.
If both MERx and SER bits are reset and the STRT bit is set, an unpredictable behavior may
occur without generating any error flag. This condition should be forbidden.
3.5.4 Programming
Standard programming
The Flash memory programming sequence is as follows:
1. Check that no main Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register.
2. Set the PG bit in the FLASH_CR register
3. Perform the data write operation(s) to the desired memory address (inside main
memory block or OTP area):
– Byte access in case of x8 parallelism
– Half-word access in case of x16 parallelism
– Word access in case of x32 parallelism
– Double word access in case of x64 parallelism
4. Wait for the BSY bit to be cleared.
Note: Successive write operations are possible without the need of an erase operation when
changing bits from ‘1’ to ‘0’. Writing ‘1’ requires a Flash memory erase operation.
If an erase and a program operation are requested simultaneously, the erase operation is
performed first.
Programming errors
It is not allowed to program data to the Flash memory that would cross the 128-bit row
boundary. In such a case, the write operation is not performed and a program alignment
error flag (PGAERR) is set in the FLASH_SR register.
The write access type (byte, half-word, word or double word) must correspond to the type of
parallelism chosen (x8, x16, x32 or x64). If not, the write operation is not performed and a
program parallelism error flag (PGPERR) is set in the FLASH_SR register.
If the standard programming sequence is not respected (for example, if there is an attempt
to write to a Flash memory address when the PG bit is not set), the operation is aborted and
a program sequence error flag (PGSERR) is set in the FLASH_SR register.
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
DCRST and ICRST bits in the FLASH_CR register.
Note: The I/D cache should be flushed only when it is disabled (I/DCEN = 0).
3.5.5 Interrupts
Setting the end of operation interrupt enable bit (EOPIE) in the FLASH_CR register enables
interrupt generation when an erase or program operation ends, that is when the busy bit
(BSY) in the FLASH_SR register is cleared (operation completed, correctly or not). In this
case, the end of operation (EOP) bit in the FLASH_SR register is set.
If an error occurs during a program, an erase, or a read operation request, one of the
following error flags is set in the FLASH_SR register:
• PGAERR, PGPERR, PGSERR (Program error flags)
• WRPERR (Protection error flag)
In this case, if the error interrupt enable bit (ERRIE) is set in the FLASH_SR register, an
interrupt is generated and the operation error bit (OPERR) is set in the FLASH_SR register.
Note: If several successive errors are detected (for example, in case of DMA transfer to the Flash
memory), the error flags cannot be cleared until the end of the successive write requests.
0x1FFF C000 Reserved ROP & user option bytes (RDP & USER)
Write protection nWRP bits for sectors 0 to 7
0x1FFF C008 Reserved
(STM32F411xC/E)
Bit 15:8 0xCC: Level 2, chip protection (debug and boot from RAM features
disabled)
Others: Level 1, read protection of memories (debug features limited)
USER: User option byte
This byte is used to configure the following features:
Select the watchdog event: Hardware or software
Reset event when entering the Stop mode
Reset event when entering the Standby mode
nRST_STDBY
Bit 7 0: Reset generated when entering the Standby mode
1: No reset generated
nRST_STOP
Bit 6 0: Reset generated when entering the Stop mode
1: No reset generated
WDG_SW
Bit 5 0: Hardware watchdog
1: Software watchdog
Bit 4 0x0: Not used. Always readout as “0”.
BOR_LEV: BOR reset Level
These bits contain the supply level threshold that activates/releases the reset.
They can be written to program a new BOR level value into Flash memory.
00: BOR Level 3 (VBOR3), brownout threshold level 3
Bits 3:2 01: BOR Level 2 (VBOR2), brownout threshold level 2
10: BOR Level 1 (VBOR1), brownout threshold level 1
11: BOR off, POR/PDR reset threshold level is applied
For full details on BOR characteristics, refer to the Electrical characteristics
section of the product datasheet.
Bits 1:0 0x1: Not used
Option bytes (word, address 0x1FFF C008)
SPRMOD: Selection of Protection Mode of nWPRi bits
Bit 15 0: nWPRi bits used for sector i write protection (Default)
1: nWPRi bits used for sector i PCROP protection (Sector)
Bits 14:6 Reserved
Flash memory are possible in all boot configurations (Flash user boot, debug or boot
from RAM).
• Level 1: read protection enabled
It is the default read protection level after option byte erase. The read protection Level
1 is activated by writing any value (except for 0xAA and 0xCC used to set Level 0 and
Level 2, respectively) into the RDP option byte. When the read protection Level 1 is set:
– No access (read, erase, program) to Flash memory can be performed while the
debug feature is connected or while booting from RAM or system memory
bootloader. A bus error is generated in case of read request.
– When booting from Flash memory, accesses (read, erase, program) to Flash
memory from user code are allowed.
When Level 1 is active, programming the protection option byte (RDP) to Level 0
causes the Flash memory to be mass-erased. As a result the user code area is cleared
before the read protection is removed. The mass erase only erases the user code area.
The other option bytes including write protections remain unchanged from before the
mass-erase operation. The OTP area is not affected by mass erase and remains
unchanged. Mass erase is performed only when Level 1 is active and Level 0
requested. When the protection level is increased (0->1, 1->2, 0->2) there is no mass
erase.
• Level 2: debug/chip read protection disabled
The read protection Level 2 is activated by writing 0xCC to the RDP option byte. When
the read protection Level 2 is set:
– All protections provided by Level 1 are active.
– Booting from RAM or system memory bootloader is no more allowed.
– JTAG, SWV (single-wire viewer), ETM, and boundary scan are disabled.
– User option bytes can no longer be changed.
– When booting from Flash memory, accesses (read, erase and program) to Flash
memory from user code are allowed.
Memory read protection Level 2 is an irreversible operation. When Level 2 is activated,
the level of protection cannot be decreased to Level 0 or Level 1.
Note: The JTAG port is permanently disabled when Level 2 is active (acting as a JTAG fuse). As a
consequence, boundary scan cannot be performed. STMicroelectronics is not able to
perform analysis on defective parts on which the Level 2 protection has been set.
--
,EVEL
2$0 !!H
2$0 ##H
7RITE OPTIONS DEFAULT 7RITE OPTIONS
INCLUDING INCLUDING
2$0 ##H 7RITE OPTIONSINCLUDING 2$0 !!H
2$0 ##H !!H
, EV E L , EV E L
2$0 ##H 2$0 !! H
7RITE OPTIONS
INCLUDING
2$0 ##H
/PTIONS WRITE 2$0 LEVEL DECREASE INCLUDES /PTIONS WRITE 2$0 LEVEL IDENTICAL INCLUDES
-ASS ERASE /PTIONS ERASE
/PTIONS ERASE .EW OPTIONS PROGRAM
.EW OPTIONS PROGRAM
AI
7RITE OPTIONS
30-/$ ACTIVE
AND VALID N720I
,EVEL
2$0 X!!
2$0 X##
7RITE OPTIONS DEFAULT 7RITE OPTIONS .O RESTRICTION ON
30-/$ ACTIVE 30-/$ ACTIVE 7RITE OPTIONS
AND VALID N720I AND VALID N720I
,EVEL ,EVEL
2$0 X## 2$0 X!!
7RITE OPTIONS
30-/$ ACTIVE
7RITE OPTIONS
AND VALID N720I
30-/$ ACTIVE
5SER OPTION SECTOR ERASE AND VALID N720I
0ROGRAM NEW OPTIONS
The deactivation of the SPRMOD and/or the unprotection of PCROPed user sectors can
only occur when, at the same time, the RDP level changes from 1 to 0. If this condition is not
respected, the user option byte modification is cancelled and the write error WRPERR flag
is set. The modification of the users option bytes (BOR_LEV, RST_STDBY, ..) is allowed
since none of the active nWRPi bits is reset and SPRMOD is kept active.
Note: The active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
If SPRMOD = 1 and nWRPi =1, then user sector i of bank 1, respectively bank 2 is
read/write protected (PCROP).
The OTP area is divided into 16 OTP data blocks of 32 bytes and one lock OTP block of 16
bytes. The OTP data and lock blocks cannot be erased. The lock block contains 16 bytes
LOCKBi (0 ≤i ≤15) to lock the corresponding OTP data block (blocks 0 to 15). Each OTP
data block can be programmed until the value 0x00 is programmed in the corresponding
OTP lock byte. The lock bytes must only contain 0x00 and 0xFF values, otherwise the OTP
bytes might not be taken into account correctly.
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
DCRST ICRST DCEN ICEN PRFTEN LATENCY
Reserved Reserved
rw w rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
KEY[31:16]
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
KEY[15:0]
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OPTKEYR[31:16
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
OPTKEYR[15:0]
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BSY
Reserved
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RDERR PGSERR PGPERR PGAERR WRPERR OPERR EOP
Reserved Reserved
rw rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LOCK ERRIE EOPIE STRT
Reserved Reserved
rs rw rw rs
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSIZE[1:0] SNB[3:0] MER SER PG
Reserved Res.
rw rw rw rw rw rw rw rw rw
Access: no wait state when no Flash memory operation is ongoing, word, half-word and
byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPR
nWRP[7:0]
MOD Reserved
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
nRST_ nRST_ WDG_ OPTST OPTLO
RDP[7:0] Reserv BOR_LEV
STDBY STOP SW RT CK
ed
rw rw rw rw rw rw rw rw rw rw rw rw rw rs rs
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PRFTEN
DCRST
ICRST
DCEN
ICEN
FLASH_ACR LATENCY
0x00 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FLASH_
OPTKEYR[31:16] OPTKEYR[15:0]
OPTKEYR
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
WRPERR
PGSERR
PGPERR
PGAERR
RDERR
OPERR
Reserved
EOP
BSY
FLASH_SR
0x0C Reserved Reserved
Reset value 0 0 0 0 0 0 0 0
PSIZE[1:0]
ERRIE
EOPIE
LOCK
STRT
MER
Reserved
SER
PG
FLASH_CR SNB[3:0]
0x10 Reserved Reserved Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0 0 0
nRST_STDBY
nRST_STOP
OPTLOCK
OPTSTRT
WDG_SW
BOR_LEV
SPRMOD
Reserved
FLASH_OPTCR nWRP[7:0] RDP[7:0]
0x14 Reserved
Reset value 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1
AHB bus
The CRC calculator can be reset to 0xFFFF FFFF with the RESET control bit in the
CRC_CR register. This operation does not affect the contents of the CRC_IDR register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DR [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
DR [15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RESET
Reserved
w
Table 13. CRC calculation unit register map and reset values
Offset Register 31-24 23-16 15-8 7 6 5 4 3 2 1 0
Khd
>ĞǀĞůƐŚŝĨƚĞƌ
/K
'W/KƐ
>ŽŐŝĐ
/E
sWͺϭ <ĞƌŶĞůůŽŐŝĐ
ϮпϮ͘Ϯђ&
sWͺϮ ;Wh͕ĚŝŐŝƚĂů
Žƌϭdžϰ͘ϳђ&
ΘZDͿ
s s
ϭ ͬϮ ͬ͘͘͘ ϲ sŽůƚĂŐĞ
ϲп ϭ ϬϬŶ& s^^ ƌĞŐƵůĂƚŽƌ
нϭпϰ͘ϳђ& ϭ ͬϮ ͬ͘͘͘ ϱ
zW^^ͺZ' &ůĂƐŚŵĞŵŽƌLJ
ZĞƐĞƚ
WZͺKE ĐŽŶƚƌŽůůĞƌ
s
s
sZ&
sZ&н
ŶĂůŽŐ͗
ϭϬϬŶ& ϭϬϬŶ& sZ&Ͳ ZƐ ͕
нϭђ& нϭђ& W>> ͕͘͘
s^^
069
If no external battery is used in the application, it is recommended to connect the VBAT pin to
VDD with a 100 nF external decoupling ceramic capacitor in parallel.
When the backup domain is supplied by VDD (analog switch connected to VDD), the
following functions are available:
• PC14 and PC15 can be used as either GPIO or LSE pins
• PC13 can be used as a GPIO or additional functions can be configured (refer to
Table 25: RTC additional functions for more details about this pin configuration)
Note: Due to the fact that the switch only sinks a limited amount of current (3 mA), the use of
GPIOs PC13 to PC15 are restricted: only one I/O at a time can be used as an output, the
speed has to be limited to 2 MHz with a maximum load of 30 pF and these I/Os must not be
used as a current source (e.g. to drive an LED).
When the backup domain is supplied by VBAT (analog switch connected to VBAT because
VDD is not present), the following functions are available:
• PC14 and PC15 can be used as LSE pins only
• PC13 can be used as the RTC additional function pin (refer to Table 25: RTC additional
functions for more details about this pin configuration)
content. The VOS register content is only taken into account once the PLL is
activated and the HSI or HSE is selected as clock source.
The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency.
• In Stop mode, the main regulator or the low-power regulator supplies low power to the
1.2 V domain, thus preserving the content of registers and internal SRAM. The voltage
regulator can be put either in main regulator mode (MR) or in low-power mode (LPR).
The programmed voltage scale remains the same during Stop mode:
Voltage scale 3 is automatically selected when the microcontroller enters Stop
mode (see Section 5.4.1: PWR power control register (PWR_CR)).
• In Standby mode, the regulator is powered down. The content of the registers and
SRAM are lost except for the Standby circuitry and the backup domain.
Note: For more details, refer to the voltage regulator section in the STM32F411xC/E datasheet.
0$2
M6
HYSTERESIS 0$2
4EMPORIZATION
T2344%-0/
2ESET
-36
2ESET
-36
A PVDO flag is available, in the PWR power control/status register (PWR_CSR), to indicate
if VDD is higher or lower than the PVD threshold. This event is internally connected to the
EXTI line16 and can generate an interrupt if enabled through the EXTI registers. The PVD
output interrupt can be generated when VDD drops below the PVD threshold and/or when
VDD rises above the PVD threshold depending on EXTI line16 rising/falling edge
configuration. As an example the service routine could perform emergency shutdown tasks.
06$ OUTPUT
-36
After waking up from Standby mode, program execution restarts in the same way as after a
Reset (boot pins sampling, vector reset is fetched, etc.). The SBF status flag in the PWR
power control/status register (PWR_CSR) indicates that the MCU was in Standby mode.
Refer to Table 19 for more details on how to exit Standby mode.
Debug mode
By default, the debug connection is lost if the application puts the MCU in Stop or Standby
mode while the debug features are used. This is due to the fact that the Cortex®-M4 with
FPU core is no longer clocked.
However, by setting some configuration bits in the DBGMCU_CR register, the software can
be debugged even when using the low-power modes extensively. For more details, refer to
Section 23.16.1: Debug support for low-power modes.
5.3.6 Programming the RTC alternate functions to wake up the device from
the Stop and Standby modes
The MCU can be woken up from a low-power mode by an RTC alternate function.
The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), RTC wakeup, RTC
tamper event detection and RTC time stamp event detection.
These RTC alternate functions can wake up the system from the Stop and Standby low-
power modes.
The system can also wake up from low-power modes without depending on an external
interrupt (Auto-wakeup mode), by using the RTC alarm or the RTC wakeup events.
The RTC provides a programmable time base for waking up from the Stop or Standby mode
at regular intervals.
For this purpose, two of the three alternate RTC clock sources can be selected by
programming the RTCSEL[1:0] bits in the Section 6.3.17: RCC Backup domain control
register (RCC_BDCR):
• Low-power 32.768 kHz external crystal oscillator (LSE OSC)
This clock source provides a precise time base with a very low-power consumption
(additional consumption of less than 1 µA under typical conditions)
• Low-power internal RC oscillator (LSI RC)
This clock source has the advantage of saving the cost of the 32.768 kHz crystal. This
internal RC oscillator is designed to use minimum power.
RTC alternate functions to wake up the device from the Stop mode
• To wake up the device from the Stop mode with an RTC alarm event, it is necessary to:
a) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt or Event
modes)
b) Enable the RTC Alarm Interrupt in the RTC_CR register
c) Configure the RTC to generate the RTC alarm
• To wake up the device from the Stop mode with an RTC tamper or time stamp event, it
is necessary to:
a) Configure the EXTI Line 21 to be sensitive to rising edges (Interrupt or Event
modes)
b) Enable the RTC time stamp Interrupt in the RTC_CR register or the RTC tamper
interrupt in the RTC_TAFCR register
c) Configure the RTC to detect the tamper or time stamp event
• To wake up the device from the Stop mode with an RTC wakeup event, it is necessary
to:
a) Configure the EXTI Line 22 to be sensitive to rising edges (Interrupt or Event
modes)
b) Enable the RTC wakeup interrupt in the RTC_CR register
c) Configure the RTC to generate the RTC Wakeup event
RTC alternate functions to wake up the device from the Standby mode
• To wake up the device from the Standby mode with an RTC alarm event, it is necessary
to:
a) Enable the RTC alarm interrupt in the RTC_CR register
b) Configure the RTC to generate the RTC alarm
• To wake up the device from the Standby mode with an RTC tamper or time stamp
event, it is necessary to:
a) Enable the RTC time stamp interrupt in the RTC_CR register or the RTC tamper
interrupt in the RTC_TAFCR register
b) Configure the RTC to detect the tamper or time stamp event
• To wake up the device from the Standby mode with an RTC wakeup event, it is
necessary to:
a) Enable the RTC wakeup interrupt in the RTC_CR register
b) Configure the RTC to generate the RTC wakeup event
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FISSR FMSSR
Reserved Reserved
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MRLV LPLV
VOS ADCDC1 FPDS DBP PLS[2:0] PVDE CSBF CWUF PDDS LPDS
Res DS DS
rw rw rw rw rw rw rw rw rw rw rw w w rw rw
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
VOS
BRE EWUP BRR PVDO SBF WUF
Res RDY Reserved Reserved
r rw rw r r r r
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ADCDC1
MRLVDS
VOS[1:0]
LPLVDS
FMSSR
CWUF
FISSR
PDDS
PVDE
FPDS
CSBF
LPDS
DBP
EWUP
PVDO
WUF
BRR
BRE
SBF
PWR_CSR
0x004 Reserved Reserved Reserved
Reset value 0 0 0 0 0 0 0
6.1 Reset
There are three types of reset, defined as system Reset, power Reset and backup domain
Reset.
Software reset
The reset source can be identified by checking the reset flags in the RCC clock control &
status register (RCC_CSR).
The SYSRESETREQ bit in Cortex®-M4 with FPU Application Interrupt and Reset Control
Register must be set to force a software reset on the device. Refer to the Cortex®-M4 with
FPU technical reference manual for more details.
9''9''$
538
([WHUQDO 6\VWHPUHVHW
UHVHW )LOWHU
1567
::'*UHVHW
3XOVH
,:'*UHVHW
JHQHUDWRU
3RZHUUHVHW
PLQV
6RIWZDUHUHVHW
/RZSRZHUPDQDJHPHQWUHVHW
DLF
6.2 Clocks
Three different clock sources can be used to drive the system clock (SYSCLK):
• HSI oscillator clock
• HSE oscillator clock
• Main PLL (PLL) clock
The devices have the two following secondary clock sources:
• 32 kHz low-speed internal RC (LSI RC) which drives the independent watchdog and,
optionally, the RTC used for Auto-wakeup from the Stop/Standby mode.
• 32.768 kHz low-speed external crystal (LSE crystal) which optionally drives the RTC
clock (RTCCLK)
Each clock source can be switched on or off independently when it is not used, to optimize
power consumption.
57&6(/>@
57&
HQDEOH 57&&/.
26&B,1 WR57&
/6(26& /6(
N+]
26&B287
6<6&/.
0&2 WR
+6(B57&
/6(
WR
0&2 WR
+&/.
0+]PD[ WR$+%EXVFRUH
0+] &ORFN 0HPRU\DQG'0$
+6,5& +6, (QDEOH
WR&RUWH[6\VWHPWLPHU
6:
)&/.&RUWH[
IUHHUXQQLQJFORFN
+6, $+%
+6( 35(6&
3//&/. 6<6&/.
0+]PD[ 3HULSKHUDO $3%[
$3%[ FORFNHQDEOH FORFNV
35(6&
3HULSKHUDO
FORFNHQDEOH $3%[
LI $3%[SUHVF [ WLPHU
26&B287 0+] +6( FORFNV
HOVH[
+6(26&
26&B,1
0
9&2 3 3HULSKHUDO
3//&. 0+]
FORFNHQDEOH
4 FORFNV
[1
3// 5
0
9&2 3
[1 4
,665&
3//,6&/. 3HULSKHUDO
3//,6 5
FORFNHQDEOH
([WFORFN ,6FORFNV
,6B&.,1
069
1. For full details about the internal and external clock source characteristics, refer to the Electrical characteristics section in
the device datasheet.
The clock controller provides a high degree of flexibility to the application in the choice of the
external crystal or the oscillator to run the core and peripherals at the highest frequency
and, guarantee the appropriate frequency for peripherals that need a specific clock like USB
OTG FS, I2S and SDIO.
Several prescalers are used to configure the AHB frequency, the high-speed APB (APB2)
and the low-speed APB (APB1) domains. The maximum frequency of the AHB domain is
100 MHz. The maximum allowed frequency of the high-speed APB2 domain is 100 MHz.
The maximum allowed frequency of the low-speed APB1 domain is 50 MHz
All peripheral clocks are derived from the system clock (SYSCLK) except for:
• The USB OTG FS clock (48 MHz) and the SDIO clock (≤48 MHz) which are coming
from a specific output of PLL (PLL48CLK)
• The I2S clock
To achieve high-quality audio performance, the I2S clock can be derived either from a
specific PLL (PLLI2S) or from an external clock mapped on the I2S_CKIN pin. For
more information about I2S clock frequency and precision, refer to Section 20.4.4:
Clock generator.
The RCC feeds the external clock of the Cortex System Timer (SysTick) with the AHB clock
(HCLK) divided by 8. The SysTick can work either with this clock or with the Cortex clock
(HCLK), configurable in the SysTick control and status register.
The timer clock frequencies for STM32F411xC/E are automatically set by hardware. There
are two cases:
1. If the APB prescaler is 1, the timer clock frequencies are set to the same frequency as
that of the APB domain to which the timers are connected.
2. Otherwise, they are set to twice (×2) the frequency of the APB domain to which the
timers are connected.
The timer clock frequencies are automatically set by hardware. There are two cases
depending on the value of TIMPRE bit in RCC_DCKCFGR register:
• If TIMPRE bit is reset:
If the APB prescaler is configured to a division factor of 1, the timer clock frequencies
(TIMxCLK) are set to HCLK. Otherwise, the timer clock frequencies are twice the
frequency of the APB domain to which the timers are connected: TIMxCLK = 2xPCLKx.
• If TIMPRE bit is set:
If the APB prescaler is configured to a division factor of 1 or 2, the timer clock
frequencies (TIMxCLK) are set to HCLK. Otherwise, the timer clock frequencies is four
times the frequency of the APB domain to which the timers are connected: TIMxCLK =
4xPCLKx.
FCLK acts as Cortex®-M4 with FPU free-running clock. For more details, refer to the
Cortex®-M4 with FPU technical reference manual.
The resonator and the load capacitors have to be placed as close as possible to the
oscillator pins in order to minimize output distortion and startup stabilization time. The
loading capacitance values must be adjusted according to the selected oscillator.
OSC_OUT
External clock
(HI-Z)
External
source
OSC_IN OSC_OUT
Crystal/ceramic
resonators
CL1 CL2
Load
capacitors
with calibration the frequency is less accurate than an external crystal oscillator or ceramic
resonator.
Calibration
RC oscillator frequencies can vary from one chip to another due to manufacturing process
variations, this is why each device is factory calibrated by ST for 1% accuracy at TA= 25 °C.
After reset, the factory calibration value is loaded in the HSICAL[7:0] bits in the RCC clock
control register (RCC_CR).
If the application is subject to voltage or temperature variations this may affect the RC
oscillator speed. You can trim the HSI frequency in the application using the HSITRIM[4:0]
bits in the RCC clock control register (RCC_CR).
The HSIRDY flag in the RCC clock control register (RCC_CR) indicates if the HSI RC is
stable or not. At startup, the HSI RC output clock is not released until this bit is set by
hardware.
The HSI RC can be switched on and off using the HSION bit in the RCC clock control
register (RCC_CR).
The HSI signal can also be used as a backup source (Auxiliary clock) if the HSE crystal
oscillator fails. Refer to Section 6.2.7: Clock security system (CSS) on page 94.
allowing the MCU to perform rescue operations. The CSSI is linked to the Cortex®-M4 with
FPU NMI (non-maskable interrupt) exception vector.
Note: When the CSS is enabled, if the HSE clock happens to fail, the CSS generates an interrupt,
which causes the automatic generation of an NMI. The NMI is executed indefinitely unless
the CSS interrupt pending bit is cleared. As a consequence, the application has to clear the
CSS interrupt in the NMI ISR by setting the CSSC bit in the Clock interrupt register
(RCC_CIR).
If the HSE oscillator is used directly or indirectly as the system clock (indirectly meaning that
it is directly used as PLL input clock, and that PLL clock is the system clock) and a failure is
detected, then the system clock switches to the HSI oscillator and the HSE oscillator is
disabled.
If the HSE oscillator clock was the clock source of PLL used as the system clock when the
failure occurred, PLL is also disabled. In this case, if the PLLI2S was enabled, it is also
disabled when the HSE fails.
with the same resolution, and trim the source to compensate for manufacturing-process
and/or temperature- and voltage-related frequency deviations.
The HSI oscillator has dedicated, user-accessible calibration bits for this purpose.
The basic concept consists in providing a relative measurement (e.g. HSI/LSE ratio): the
precision is therefore tightly linked to the ratio between the two clock sources. The greater
the ratio, the better the measurement.
It is also possible to measure the LSI frequency: this is useful for applications that do not
have a crystal. The ultralow-power LSI oscillator has a large manufacturing process
deviation: by measuring it versus the HSI clock source, it is possible to determine its
frequency with the precision of the HSI. The measured value can be used to have more
accurate RTC time base timeouts (when LSI is used as the RTC clock source) and/or an
IWDG timeout with an acceptable accuracy.
Use the following procedure to measure the LSI frequency:
1. Enable the TIM5 timer and configure channel4 in Input capture mode.
2. Set the TI4_RMP bits in the TIM5_OR register to 0x01 to connect the LSI clock
internally to TIM5 channel4 input capture for calibration purposes.
3. Measure the LSI clock frequency using the TIM5 capture/compare 4 event or interrupt.
4. Use the measured LSI frequency to update the prescaler of the RTC depending on the
desired time base and/or to compute the IWDG timeout.
4)-
4)?2-0;=
'0)/
24#?7AKE5P?)4 4)
,3%
,3)
AI6
4)-
4)?2-0;=
'0)/
4)
(3%?24# -(Z
AI
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLI2S PLLI2S CSS HSE HSE
PLLRDY PLLON HSE ON
Reserved RDY ON Reserved ON BYP RDY
r rw r rw rw rw r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HSI
HSICAL[7:0] HSITRIM[4:0] HSION
Res. RDY
r r r r r r r r rw rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLQ3 PLLQ2 PLLQ1 PLLQ0 Reserv PLLSRC PLLP1 PLLP0
Reserved Reserved
rw rw rw rw ed rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Bits 17:16 PLLP: Main PLL (PLL) division factor for main system clock
Set and cleared by software to control the frequency of the general PLL output clock. These
bits can be written only if PLL is disabled.
Caution: The software has to set these bits correctly not to exceed 100 MHz on this domain.
PLL output clock frequency = VCO frequency / PLLP with PLLP = 2, 4, 6, or 8
00: PLLP = 2
01: PLLP = 4
10: PLLP = 6
11: PLLP = 8
Bits 14:6 PLLN: Main PLL (PLL) multiplication factor for VCO
Set and cleared by software to control the multiplication factor of the VCO. These bits can
be written only when PLL is disabled. Only half-word and word accesses are allowed to
write these bits.
Caution: The software has to set these bits correctly to ensure that the VCO output
frequency is between 100 and 432 MHz. (check also Section 6.3.20: RCC PLLI2S
configuration register (RCC_PLLI2SCFGR))
VCO output frequency = VCO input frequency × PLLN with 50 ≤PLLN ≤432
000000000: PLLN = 0, wrong configuration
000000001: PLLN = 1, wrong configuration
...
000110010: PLLN = 50
...
001100011: PLLN = 99
001100100: PLLN = 100
...
110110000: PLLN = 432
110110001: PLLN = 433, wrong configuration
...
111111111: PLLN = 511, wrong configuration
Note: Multiplication factors possible for VCO input frequency higher than 1 MHz but care
must be taken to fulfill the minimum VCO output frequency as specified above.
Bits 5:0 PLLM: Division factor for the main PLL (PLL) input clock
Set and cleared by software to divide the PLL and PLLI2S input clock before the VCO.
These bits can be written only when the PLL and PLLI2S are disabled.
Caution: The software has to set these bits correctly to ensure that the VCO input frequency
ranges from 1 to 2 MHz. It is recommended to select a frequency of 2 MHz to limit
PLL jitter.
VCO input frequency = PLL input clock frequency / PLLM with 2 ≤PLLM ≤63
000000: PLLM = 0, wrong configuration
000001: PLLM = 1, wrong configuration
000010: PLLM = 2
000011: PLLM = 3
000100: PLLM = 4
...
111110: PLLM = 62
111111: PLLM = 63
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
I2SSC
MCO2 MCO2 PRE[2:0] MCO1 PRE[2:0] MCO1 RTCPRE[4:0]
R
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
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
PLLI2S PLL HSE HSI LSE LSI PLLI2S PLL HSE HSI LSE LSI
CSSF
RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYF RDYF RDYF RDYF RDYF RDYF
Reserved Reserved
rw rw rw rw rw rw r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DMA2 DMA1
Reserved RST RST Reserved
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GPIOH GPIOE GPIOD GPIOC GPIOB GPIOA
CRCRST
Reserved Reserved RST Reserved RST RST RST RST RST
rw rw rw rw rw rw rw
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
OTGFS
Reserved RST Reserved
rw
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPI5 TIM11 TIM10 TIM9
RST Reser- RST RST RST
Reserved
ved
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSCFG SPI4 SPI1 SDIO ADC1 USART6 USART1 TIM1
Reser- RST RST RST RST RST RST RST RST
Reserved Reserved Reserved
ved
rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DMA2EN DMA1EN
Reserved Reserved
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GPIOH GPIOD GPIOC GPIOB GPIOA
CRCEN GPIOEEN
Reserved Reserved EN Reserved EN EN EN EN
rw rw rw rw rw rw rw
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
OTGFS
Reserved EN Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PWR I2C3 I2C2 I2C1 USART2
EN EN EN EN EN Reser-
Reserved Reserved Reserved
ved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPI3 SPI2 WWDG TIM5 TIM4 TIM3 TIM2
EN EN Reserved EN Reserved EN EN EN EN
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIM11 TIM10 TIM9
SPI5EN Reser-
Reserved EN EN EN
ved
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSCF SPI1 SDIO ADC1 USART6 USART1 TIM1
Reser- G EN SPI4EN EN EN EN EN EN EN
Reserved Reserved Reserved
ved
rw rw rw rw rw rw rw rw
6.3.13 RCC AHB1 peripheral clock enable in low power mode register
(RCC_AHB1LPENR)
Address offset: 0x50
Reset value: 0x0061 900F
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DMA2 DMA1 SRAM1
Reserved LPEN LPEN Reserved LPEN
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FLITF CRC GPIOH GPIOE GPIOD GPIOC GPIOB GPIOA
LPEN Reserved LPEN Reserved LPEN Reserved LPEN LPEN LPEN LPEN LPEN
rw rw rw rw rw rw rw rw
6.3.14 RCC AHB2 peripheral clock enable in low power mode register
(RCC_AHB2LPENR)
Address offset: 0x54
Reset value: 0x0000 0080
Access: no wait state, word, half-word and byte access.
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
OTGFS
Reserved LPEN Reserved
rw
6.3.15 RCC APB1 peripheral clock enable in low power mode register
(RCC_APB1LPENR)
Address offset: 0x60
Reset value: 0x10E2 C80F
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PWR I2C3 I2C2 I2C1 USART2
LPEN LPEN LPEN LPEN LPEN Reser-
Reserved Reserved Reserved
ved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPI3 SPI2 WWDG TIM5 TIM4 TIM3 TIM2
LPEN LPEN Reserved LPEN Reserved LPEN LPEN LPEN LPEN
rw rw rw rw rw rw rw
6.3.16 RCC APB2 peripheral clock enabled in low power mode register
(RCC_APB2LPENR)
Address offset: 0x64
Reset value: 0x0007 7930
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPI5 TIM11 TIM10 TIM9
LPEN Reser- LPEN LPEN LPEN
Reserved
ved
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSC
SPI4LP SPI1 SDIO ADC1 USART6 USART1 TIM1
Reser- FG
EN LPEN LPEN Reserved LPEN Reserved LPEN LPEN Reserved LPEN
ved LPEN
rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BDRST
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTCEN RTCSEL[1:0] LSEMO LSEBYP LSERDY LSEON
Reserved Reserved
rw rw rw D rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LPWR WWDG IWDG SFT POR PIN BORRS
RMVF
RSTF RSTF RSTF RSTF RSTF RSTF TF Reserved
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LSIRDY LSION
Reserved
r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPR
SSCG
EAD INCSTEP
EN Reserved
SEL
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
INCSTEP MODPER
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLI2S PLLI2S PLLI2S
Reserved R2 R1 R0 Reserved
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLLI2SN[8:0] PLLI2SM[5:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIMPRE
Reserved Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
0x3C
0x2C
0x1C
0x0C
Addr.
offset
6.3.22
RM0383
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
name
RCC_CR
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
RCC_CIR
PLLCFGR
AHB2ENR
AHB1ENR
Register
APB2RSTR
APB1RSTR
AHB2RSTR
AHB1RSTR
RCC_CFGR
MCO2 1 31
Reserved MCO2 0 30
MCO2PRE2 29
Reserved
Reserved
PWRRST MCO2PRE1 28
MCO2PRE0 PLLQ 3 PLL I2SRDY 27
Reserved
MCO1PRE2 PLLQ 2 PLL I2SON
Reserved
Reserved
26
RCC register map
Reserved
25
Reserved
MCO1PRE0 PLLQ 0 PLL ON 24
I2C3RST CSSC I2SSRC Reserved 23
DMA2EN I2C2RST DMA2RST Reserved MCO1 1 PLLSRC 22
DMA1EN I2C1RST DMA1RST PLLI2SRDYC MCO1 0 21
Reserved
Reserved
Reserved
Reserved
Reserved
18
TIM10RST USART2RST LSERDYC RTCPRE 1 PLLP 1 HSERDY 17
TIM9RST Reserved LSIRDYC RTCPRE 0 PLLP 0 HSEON 16
DocID026448 Rev 1
Table 21 gives the register map and reset values
Reserved
Reserved
Reserved SPI3RST PPRE2 2 Reserved HSICAL 7 15
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
SYSCFGRST SPI2RST PPRE2 1 PLLN 8 HSICAL 6 14
SP45RST PLLI2SRDYIE PPRE2 0 PLLN 7 HSICAL 5 13
Reserved
CRCEN SPI1RST CRCRST PLLRDYIE PPRE1 2 PLLN 6 HSICAL 4 12
SDIORST WWDGRST HSERDYIE PPRE1 1 PLLN 5 HSICAL 3 11
HSIRDYIE PPRE1 0 PLLN 4 HSICAL 2 10
Reserved
LSERDYIE PLLN 3 HSICAL 1 9
Reserved
Reserved
Reserved
Reserved
Reserved 6
ved
5
GPIOEEN USART1RST GPIOERST PLLRDYF HPRE 0 PLLM 4 HSITRIM 1 4
GPIODEN TIM5RST GPIODRST HSERDYF SWS 1 PLLM 3 HSITRIM 0 3
GPIOCEN Reserved TIM4RST GPIOCRST HSIRDYF SWS 0 PLLM 2 Reserved
Reserved
Reserved
2
GPIOBEN TIM3RST GPIOBRST LSERDYF SW 1 PLLM 1 HSIRDY 1
GPIOAEN TIM1RST TIM2RST GPIOARST LSIRDYF SW 0 PLLM 0 HSION 0
Reset and clock control (RCC) for STM32F411xC/E
133/836
135
0x84
0x80
0x78
0x74
0x70
0x68
0x64
0x60
0x58
0x54
0x50
0x48
0x44
0x40
0x7C
0x6C
0x5C
0x4C
Addr.
offset
134/836
NR
NR
PENR
PENR
PENR
PENR
CFGR
name
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
RCC_CSR
Register
RCC_BDCR
RCC_APB2L
RCC_APB1L
RCC_AHB2L
RCC_AHB1L
RCC_APB2E
RCC_APB1E
RCC_PLLI2S
RCC_SSCGR
Reserved SSCGEN LPWRRSTF 31
SPREADSEL WWDGRSTF Reserved Reserved 30
WDGRSTF 29
Reserved
SFTRSTF PWRLPEN PWREN
PLLI2SRx
28
PORRSTF 27
PADRSTF
Reserved
Reserved 26
BORRSTF
Reserved
Reserved
25
Reserved
RMVF 24
I2C3LPEN I2C3EN
Reserved
23
I2C2LPEN DMA2LPEN I2C2EN 22
I2C1LPEN DMA1LPEN I2C1EN 21
SPI5LPEN SPI5EN
Reserved
20
Reserved Reserved Reserved Reserved
INCSTEP
19
Reserved
Reset and clock control (RCC) for STM32F411xC/E
TIM11LPEN TIM11EN 18
Reserved
DocID026448 Rev 1
RTCEN Reserved SPI3LPEN FLITFLPEN Reserved SPI3EN 15
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
SDIOLPEN WWDGLPEN SDIOEN WWDGEN
Reserved
11
Reserved Reserved 10
RTCSEL 1
PLLI2SNx
9
Reserved
Reserved 6
USART6LPEN USART6EN
MODPER
5
Reserved
USART1LPEN GPIOELPEN USART1EN
Table 21. RCC register map and reset values for STM32F411xC/E (continued)
4
LSEMOD TIM5LPEN GPIODLPEN TIM5EN 3
LSEBYP Reserved TIM4LPEN GPIOCLPEN Reserved TIM4EN
Reserved
PLLI2SMx
LSIRDY LSERDY TIM3LPEN GPIOBLPEN TIM3EN 1
LSION LSEON TIM1LPEN TIM2LPEN GPIOALPEN TIM1EN TIM2EN 0
RM0383
RM0383 Reset and clock control (RCC) for STM32F411xC/E
Table 21. RCC register map and reset values for STM32F411xC/E (continued)
Addr. Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
offset name
0x88 Reserved
TIMPRE
RCC_DCKCF
0x8C Reserved Reserved
GR
The system configuration controller is mainly used to remap the memory accessible in the
code area and manage the external interrupt line connection to the GPIOs.
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
MEM_MODE
Reserved
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADC1D
Reserved C2
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
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
EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
READY CMP_PD
Reserved Reserved
r rw
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
MEM_MODE
SYSCFG_
0x00 MEMRMP Reserved
Reset value x x
ADC1DC2
SYSCFG_PMC
0x04 Reserved Reserved
Reset value 0
SYSCFG_EXTICR1 EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR2 EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR3 EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR4 EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CMP_PD
READY
SYSCFG_CMPCR
0x20 Reserved Reserved
Reset value 0 0
GPIO F/G/H/I/J/K (except GPIOH0 and GPIOH1) are not available in STM32F411xC/E.
Each I/O port bit is freely programmable, however the I/O port registers have to be
accessed as 32-bit words, half-words or bytes. The purpose of the GPIOx_BSRR register is
to allow atomic read/modify accesses to any of the GPIO registers. In this way, there is no
risk of an IRQ occurring between the read and the modify access.
show the basic structure of a 5 V tolerant I/O port bit. Table 26 gives the possible port bit
configurations.
4O ON CHIP !NALOG
PERIPHERAL
!LTERNATE FUNCTION INPUT
ONOFF
)NPUT DATA REGISTER
2EAD
6$$ 6$$?&4
44, 3CHMITT
0ROTECTION
"IT SETRESET REGISTERS
TRIGGER ONOFF
0ULL DIODE
UP
)NPUT DRIVER )/ PIN
7RITE
/UTPUT DATA REGISTER
1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
0 0 0 GP output PP
0 0 1 GP output PP + PU
0 1 0 GP output PP + PD
0 SPEED 1 1 Reserved
01
1 [B:A] 0 0 GP output OD
1 0 1 GP output OD + PU
1 1 0 GP output OD + PD
1 1 1 Reserved (GP output OD)
0 0 0 AF PP
0 0 1 AF PP + PU
0 1 0 AF PP + PD
0 SPEED 1 1 Reserved
10
1 [B:A] 0 0 AF OD
1 0 1 AF OD + PU
1 1 0 AF OD + PD
1 1 1 Reserved
x x x 0 0 Input Floating
x x x 0 1 Input PU
00
x x x 1 0 Input PD
x x x 1 1 Reserved (input floating)
x x x 0 0 Input/output Analog
x x x 0 1
11
x x x 1 0 Reserved
x x x 1 1
1. GP = general-purpose, PP = push-pull, PU = pull-up, PD = pull-down, OD = open-drain, AF = alternate
function.
• GPIO
Configure the desired I/O as output or input in the GPIOx_MODER register.
• Peripheral alternate function
For the ADC, configure the desired I/O as analog in the GPIOx_MODER register.
For other peripherals:
– Configure the desired I/O as an alternate function in the GPIOx_MODER register
– Select the type, pull-up/pull-down and output speed via the GPIOx_OTYPER,
GPIOx_PUPDR and GPIOx_OSPEEDER registers, respectively
– Connect the I/O to the desired AFx in the GPIOx_AFRL or GPIOx_AFRH register
• EVENTOUT
Configure the I/O pin used to output the Cortex®-M4 with FPU EVENTOUT signal by
connecting it to AF15
Note: EVENTOUT is not mapped onto the following I/O pins: PC13, PC14, PC15, PH0 and PH1.
Please refer to the “Alternate function mapping” table in the datasheets for the detailed
mapping of the system and peripherals’ alternate function I/O pins.
&ŽƌƉŝŶƐϬƚŽϳ͕ƚŚĞ'W/Kdžͺ&Z>ϯϭ͗ϬƌĞŐŝƐƚĞƌƐĞůĞĐƚƐƚŚĞĚĞĚŝĐĂƚĞĚĂůƚĞƌŶĂƚĞĨƵŶĐƚŝŽŶ
&Ϭ;ƐLJƐƚĞŵͿ
&ϭ;d/Dϭͬd/DϮͿ
&Ϯ;d/Dϯ͘͘ϱͿ
&ϯ;d/Dϵ͘͘ϭϭͿ
&ϰ;/Ϯϭ͘͘ϯͿ
&ϱ;^W/ϭ͘͘ϰͿ
&ϲ;^W/ϯ͘͘ϱͿ WŝŶdž;džсϬ͘͘ϳͿ
&ϳ;h^Zdϭ͘͘ϮͿ
ϭ
&ϴ;h^ZdϲͿ
&ϵ;/ϮϮ͘͘ϯͿ
&ϭϬ;Kd'ͺ&^Ϳ
&ϭϭ
&ϭϮ;^/KͿ
&ϭϯ
&ϭϰ
&ϭϱ;sEdKhdͿ
&Z>ϯϭ͗Ϭ
&ŽƌƉŝŶƐϴƚŽϭϱ͕ƚŚĞ'W/Kdžͺ&Z,ϯϭ͗ϬƌĞŐŝƐƚĞƌƐĞůĞĐƚƐƚŚĞĚĞĚŝĐĂƚĞĚĂůƚĞƌŶĂƚĞĨƵŶĐƚŝŽŶ
&Ϭ;ƐLJƐƚĞŵͿ
&ϭ;d/Dϭͬd/DϮͿ
&Ϯ;d/Dϯ͘͘ϱͿ
&ϯ;d/Dϵ͘͘ϭϭͿ
&ϰ;/Ϯϭ͘͘ϯͿ
&ϱ;^W/ϭ͘͘ϰͿ
&ϲ;^W/ϯ͘͘ϱͿ WŝŶdž;džсϴ͘͘ϭϱͿ
&ϳ;h^Zdϭ͘͘ϮͿ
ϭ
&ϴ;h^ZdϲͿ
&ϵ;/ϮϮ͘͘ϯͿ
&ϭϬ;Kd'ͺ&^Ϳ
&ϭϭ
&ϭϮ;^/KͿ
&ϭϯ
&ϭϰ
&ϭϱ;sEdKhdͿ
&Z,ϯϭ͗Ϭ
D^ϯϯϬϰϭsϭ
1. Configured in FS.
ON
2EAD
6$$ 6$$
"IT SETRESET REGISTERS
AIB
ON
)NPUT DATA REGISTER
2EAD
TRIGGER
ONOFF
7RITE PROTECTION
)NPUT DRIVER DIODE
/UTPUT DATA REGISTER
PULL
UP
)/ PIN
/UTPUT DRIVER 6$$ ONOFF
AIB
0ULL PROTECTION
0 -/3 DOWN DIODE
/UTPUT
CONTROL 633 633
. -/3
2EADWRITE
633 PUSH PULL OR
OPEN DRAIN
&ROM ON CHIP
PERIPHERAL !LTERNATE FUNCTION OUTPUT
AIB
!NALOG
4O ON CHIP
PERIPHERAL
)NPUT DATA REGISTER
2EAD OFF
6$$
"IT SETRESET REGISTERS
44, 3CHMITT
TRIGGER PROTECTION
7RITE DIODE
/UTPUT DATA REGISTER
)NPUT DRIVER
)/ PIN
PROTECTION
DIODE
2EADWRITE 633
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 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
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
OT15 OT14 OT13 OT12 OT11 OT10 OT9 OT8 OT7 OT6 OT5 OT4 OT3 OT2 OT1 OT0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OSPEEDR15 OSPEEDR14 OSPEEDR13 OSPEEDR12 OSPEEDR11 OSPEEDR10 OSPEEDR9 OSPEEDR8
[1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0]
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
OSPEEDR1 OSPEEDR0
OSPEEDR7[1:0] OSPEEDR6[1:0] OSPEEDR5[1:0] OSPEEDR4[1:0] OSPEEDR3[1:0] OSPEEDR2[1:0]
[1:0] 1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PUPDR15[1:0] PUPDR14[1:0] PUPDR13[1:0] PUPDR12[1:0] PUPDR11[1:0] PUPDR10[1:0] PUPDR9[1:0] PUPDR8[1:0]
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
PUPDR7[1:0] PUPDR6[1:0] PUPDR5[1:0] PUPDR4[1:0] PUPDR3[1:0] PUPDR2[1:0] PUPDR1[1:0] PUPDR0[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
IDR15 IDR14 IDR13 IDR12 IDR11 IDR10 IDR9 IDR8 IDR7 IDR6 IDR5 IDR4 IDR3 IDR2 IDR1 IDR0
r r r r r r r r r r r r r r r r
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
ODR15 ODR14 ODR13 ODR12 ODR11 ODR10 ODR9 ODR8 ODR7 ODR6 ODR5 ODR4 ODR3 ODR2 ODR1 ODR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BR15 BR14 BR13 BR12 BR11 BR10 BR9 BR8 BR7 BR6 BR5 BR4 BR3 BR2 BR1 BR0
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
BS15 BS14 BS13 BS12 BS11 BS10 BS9 BS8 BS7 BS6 BS5 BS4 BS3 BS2 BS1 BS0
w w w w w w w w w w w w w w w w
LOCK sequence has been applied on a port bit, the value of this port bit can no longer be
modified until the next reset.
Note: A specific write sequence is used to write to the GPIOx_LCKR register. Only word access
(32-bit long) is allowed during this write sequence.
Each lock bit freezes a specific configuration register (control and alternate function
registers).
Address offset: 0x1C
Reset value: 0x0000 0000
Access: 32-bit word only, read/write register
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LCKK
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LCK15 LCK14 LCK13 LCK12 LCK11 LCK10 LCK9 LCK8 LCK7 LCK6 LCK5 LCK4 LCK3 LCK2 LCK1 LCK0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AFRL7[3:0] AFRL6[3:0] AFRL5[3:0] AFRL4[3:0]
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
AFRL3[3:0] AFRL2[3:0] AFRL1[3:0] AFRL0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 AFRLy: Alternate function selection for port x bit y (y = 0..7)
These bits are written by software to configure alternate function I/Os
AFRLy selection:
0000: AF0 1000: AF8
0001: AF1 1001: AF9
0010: AF2 1010: AF10
0011: AF3 1011: AF11
0100: AF4 1100: AF12
0101: AF5 1101: AF13
0110: AF6 1110: AF14
0111: AF7 1111: AF15
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AFRH15[3:0] AFRH14[3:0] AFRH13[3:0] AFRH12[3:0]
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
AFRH11[3:0] AFRH10[3:0] AFRH9[3:0] AFRH8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 AFRHy: Alternate function selection for port x bit y (y = 8..15)
These bits are written by software to configure alternate function I/Os
AFRHy selection:
0000: AF0 1000: AF8
0001: AF1 1001: AF9
0010: AF2 1010: AF10
0011: AF3 1011: AF11
0100: AF4 1100: AF12
0101: AF5 1101: AF13
0110: AF6 1110: AF14
0111: AF7 1111: AF15
160/836
8.4.11
andH)
and H)
and H)
GPIOx_
GPIOx_
MODER
MODER
GPIOB_
GPIOA_
GPIOB_
GPIOA_
OTYPER
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
OSPEEDER
OSPEEDER
OSPEEDER
(where x = A..E
(where x = C..E
(where x = C..E
GPIOx_MODER
0
0
0
0
0
0
31
OSPEEDR15[1:0] OSPEEDR15[1:0] OSPEEDR15[1:0] MODER15[1:0] MODER15[1:0] MODER15[1:0]
0
0
0
0
0
0
30
0
0
0
0
0
0
29
OSPEEDR14[1:0] OSPEEDR14[1:0] OSPEEDR14[1:0] MODER14[1:0] MODER14[1:0] MODER14[1:0]
0
0
0
0
0
0
General-purpose I/Os (GPIO)
28
0
1
0
0
0
1
27
OSPEEDR13[1:0] OSPEEDR13[1:0] OSPEEDR13[1:0] MODER13[1:0] MODER13[1:0] MODER13[1:0]
0
1
0
0
0
1
26
GPIO register map
0
0
0
0
0
OSPEEDR12[1:0] OSPEEDR12[1:0] OSPEEDR12[1:0] MODER12[1:0] MODER12[1:0] 0 MODER12[1:0]
25
0
0
0
0
0
0
24
0
0
0
0
0
0
23
Reserved
OSPEEDR11[1:0] OSPEEDR11[1:0] OSPEEDR11[1:0] MODER11[1:0] MODER11[1:0] MODER11[1:0]
0
0
0
0
0
0
22
0
0
0
0
0
0
21
OSPEEDR10[1:0] OSPEEDR10[1:0] OSPEEDR10[1:0] MODER10[1:0] MODER10[1:0] MODER10[1:0]
0
0
0
0
0
0
20
0
0
0
0
0
0
19
OSPEEDR9[1:0] OSPEEDR9[1:0] OSPEEDR9[1:0] MODER9[1:0] MODER9[1:0] MODER9[1:0]
0
0
0
0
0
0
18
0
0
0
0
0
0
17
OSPEEDR8[1:0] OSPEEDR8[1:0] OSPEEDR8[1:0] MODER8[1:0] MODER8[1:0] MODER8[1:0]
DocID026448 Rev 1
0
0
0
0
0
0
16
0
0
0
0
0
0
0
OT15 15
OSPEEDR7[1:0] OSPEEDR7[1:0] OSPEEDR7[1:0] MODER7[1:0] MODER7[1:0] MODER7[1:0]
0
0
0
0
0
0
0
OT14 14
0
0
0
0
0
0
0
OT13 13
OSPEEDR6[1:0] OSPEEDR6[1:0] OSPEEDR6[1:0] MODER6[1:0] MODER6[1:0] MODER6[1:0]
0
0
0
0
0
0
0
OT12 12
0
0
0
0
0
0
0
OT11 11
Table 26. GPIO register map and reset values
0
0
0
0
0
0
0
OT10 10
0
0
0
0
1
0
0
OT9 9
OSPEEDR4[1:0] OSPEEDR4[1:0] OSPEEDR4[1:0] MODER4[1:0] MODER4[1:0] MODER4[1:0]
The following table gives the GPIO register map and the reset values.
0
0
0
0
0
0
0 OT8 8
1
0
0
0
1
0
OT7 7
OSPEEDR3[1:0] OSPEEDR3[1:0] OSPEEDR3[1:0] MODER3[1:0] MODER3[1:0] MODER3[1:0]
1
0
0
0
0
0
OT6 6
0
0
0
0
0
0
OT5 5
OSPEEDR2[1:0] OSPEEDR2[1:0] OSPEEDR2[1:0] MODER2[1:0] MODER2[1:0] MODER2[1:0]
0
0
0
0
0
0
OT4 4
0
0
0
0
0
0
OT3 3
OSPEEDR1[1:0] OSPEEDR1[1:0] OSPEEDR1[1:0] MODER1[1:0] MODER1[1:0] MODER1[1:0]
0
0
0
0
0
0
OT2 2
0
0
0
0
0
0
OT1 1
OSPEEDR0[1:0] OSPEEDR0[1:0] OSPEEDR0[1:0] MODER0[1:0] MODER0[1:0] MODER0[1:0]
0
0
0
0
0
0
0
RM0383
OT0 0
RM0383 General-purpose I/Os (GPIO)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PUPDR15[1:0]
PUPDR14[1:0]
PUPDR13[1:0]
PUPDR12[1:0]
PUPDR10[1:0]
PUPDR11[1:0]
PUPDR9[1:0]
PUPDR8[1:0]
PUPDR7[1:0]
PUPDR6[1:0]
PUPDR5[1:0]
PUPDR4[1:0]
PUPDR3[1:0]
PUPDR2[1:0]
PUPDR1[1:0]
PUPDR0[1:0]
GPIOA_PUPDR
0x0C
Reset value 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PUPDR15[1:0]
PUPDR14[1:0]
PUPDR13[1:0]
PUPDR12[1:0]
PUPDR10[1:0]
PUPDR11[1:0]
PUPDR9[1:0]
PUPDR8[1:0]
PUPDR7[1:0]
PUPDR6[1:0]
PUPDR5[1:0]
PUPDR4[1:0]
PUPDR3[1:0]
PUPDR2[1:0]
PUPDR1[1:0]
PUPDR0[1:0]
GPIOB_PUPDR
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
PUPDR15[1:0]
PUPDR14[1:0]
PUPDR13[1:0]
PUPDR12[1:0]
PUPDR10[1:0]
PUPDR11[1:0]
PUPDR9[1:0]
PUPDR8[1:0]
PUPDR7[1:0]
PUPDR6[1:0]
PUPDR5[1:0]
PUPDR4[1:0]
PUPDR3[1:0]
PUPDR2[1:0]
PUPDR1[1:0]
PUPDR0[1:0]
GPIOx_PUPDR
(where x = C..E
0x0C and H)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_IDR
IDR15
IDR14
IDR13
IDR12
IDR10
IDR11
IDR9
IDR8
IDR7
IDR6
IDR5
IDR4
IDR3
IDR2
IDR1
IDR0
(where x = A..E
0x10 and H) Reserved
Reset value x x x x x x x x x x x x x x x x
GPIOx_ODR
ODR15
ODR14
ODR13
ODR12
ODR10
ODR11
ODR9
ODR8
ODR7
ODR6
ODR5
ODR4
ODR3
ODR2
ODR1
ODR0
(where x = A..E
0x14 and H) Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_BSRR
BR15
BR14
BR13
BR12
BR10
BS15
BS14
BS13
BS12
BS10
BR11
BS11
BR9
BR8
BR7
BR6
BR5
BR4
BR3
BR2
BR1
BR0
BS9
BS8
BS7
BS6
BS5
BS4
BS3
BS2
BS1
BS0
(where x = A..E
0x18 and H)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_LCKR
LCK15
LCK14
LCK13
LCK12
LCK10
LCK11
LCKK
LCK9
LCK8
LCK7
LCK6
LCK5
LCK4
LCK3
LCK2
LCK1
LCK0
(where x = A..E
0x1C and H) Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRL
(where x = A..E AFRL7[3:0] AFRL6[3:0] AFRL5[3:0] AFRL4[3:0] AFRL3[3:0] AFRL2[3:0] AFRL1[3:0] AFRL0[3:0]
0x20 and H)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRH
(where x = A..E AFRH15[3:0] AFRH14[3:0] AFRH13[3:0] AFRH12[3:0] AFRH11[3:0] AFRH10[3:0] AFRH9[3:0] AFRH8[3:0]
0x24 and H)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA controller
AHB master
REQ_STR0_CH0
REQ_STR0_CH1 Memory port
REQ_STR0_CH7
STREAM 3
STREAM 7
STREAM 0
STREAM 1
STREAM 2
STREAM 4
STREAM 5
STREAM 6
REQ_STR1_CH0
REQ_STR1_CH1
REQ_STREAM0
REQ_STREAM1
REQ_STR1_CH7 REQ_STREAM2
REQ_STREAM3
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
REQ_STREAM4 Arbiter
REQ_STREAM5
REQ_STREAM6
REQ_STREAM7
STREAM 0
STREAM 1
STREAM 2
STREAM 5
STREAM 7
STREAM 3
STREAM 4
STREAM 6
REQ_STR7_CH0
REQ_STR7_CH1
AHB master
REQ_STR7_CH7 Peripheral port
Channel
selection
AHB slave
programming Programming port
interface
ai15945
The DMA controller performs direct memory transfer: as an AHB master, it can take the
control of the AHB bus matrix to initiate AHB transactions.
It can carry out the following transactions:
• peripheral-to-memory
• memory-to-peripheral
• memory-to-memory
The DMA controller provides two AHB master ports: the AHB memory port, intended to be
connected to memories and the AHB peripheral port, intended to be connected to
peripherals. However, to allow memory-to-memory transfers, the AHB peripheral port must
also have access to the memories.
The AHB slave port is used to program the DMA controller (it supports only 32-bit
accesses).
See Figure 23 for the implementation of the system of two DMA controllers.
%XV0DWUL[
$+%PXOWLOD\HU '&2'(
)ODVK
,&2'(
PHPRU\
65$0
$+%SHULSKHUDOV
'0$FRQWUROOHU
$+%PHPRU\
SRUW
$+%$3%
SHULSKHUDOV
$3%
EULGJH $3%
7R$+%
$UELWHU
),)2
SHULSKHUDOV
$+%VODYH
GXDO$+%
$+%SHULSK
SRUW
$+%$3% $3%
$3%
EULGJH
SHULSKHUDOV
GXDO$+%
'0$UHTXHVW
0$33,1*
$+%PHPRU\
$+%SHULSKHUDOV
SRUW
SHULSKHUDOV
$UELWHU
7R$+%
$+%VODYH
),)2
$+%SHULSK
SRUW
'0$FRQWUROOHU
069
1. The DMA1 controller AHB peripheral port is not connected to the bus matrix like in the case of the DMA2 controller, thus
only DMA2 streams are able to perform memory-to-memory transfers.
DMA controller. The peripheral releases its request as soon as it gets the Acknowledge
signal from the DMA controller. Once the request has been deasserted by the peripheral,
the DMA controller releases the Acknowledge signal. If there are more requests, the
peripheral can initiate the next transaction.
31 29 27 0
DMA_SxCR CHSEL[2:0]
ai15947
The 8 requests from the peripherals (TIM, ADC, SPI, I2C, etc.) are independently connected
to each channel and their connection depends on the product implementation.
Table 79 and Table 81 give examples of DMA request mappings.
TIM3_CH4 TIM3_CH1
Channel 5 TIM3_CH2 TIM3_CH3
TIM3_UP TIM3_TRIG
Channel 1
TIM1_CH4
Channel 6 TIM1_TRIG TIM1_CH1 TIM1_CH2 TIM1_CH1 TIM1_TRIG TIM1_UP TIM1_CH3
TIM1_COM
9.3.4 Arbiter
An arbiter manages the 8 DMA stream requests based on their priority for each of the two
AHB master ports (memory and peripheral ports) and launches the peripheral/memory
access sequences.
Priorities are managed in two stages:
• Software: each stream priority can be configured in the DMA_SxCR register. There are
four levels:
– Very high priority
– High priority
– Medium priority
– Low priority
• Hardware: If two requests have the same software priority level, the stream with the
lower number takes priority over the stream with the higher number. For example,
Stream 2 takes priority over Stream 4.
AHB port. The register that contains the amount of data items to be transferred is
decremented after each transaction.
When the data width (programmed in the PSIZE or MSIZE bits in the DMA_SxCR register)
is a half-word or a word, respectively, the peripheral or memory address written into the
DMA_SxPAR or DMA_SxM0AR/M1AR registers has to be aligned on a word or half-word
address boundary, respectively.
Peripheral-to-memory mode
Figure 25 describes this mode.
When this mode is enabled (by setting the bit EN in the DMA_SxCR register), each time a
peripheral request occurs, the stream initiates a transfer from the source to fill the FIFO.
When the threshold level of the FIFO is reached, the contents of the FIFO are drained and
stored into the destination.
The transfer stops once the DMA_SxNDTR register reaches zero, when the peripheral
requests the end of transfers (in case of a peripheral flow controller) or when the EN bit in
the DMA_SxCR register is cleared by software.
In direct mode (when the DMDIS value in the DMA_SxFCR register is ‘0’), the threshold
level of the FIFO is not used: after each single data transfer from the peripheral to the FIFO,
the corresponding data are immediately drained and stored into the destination.
The stream has access to the AHB source or destination port only if the arbitration of the
corresponding stream is won. This arbitration is performed using the priority defined for
each stream using the PL[1:0] bits in the DMA_SxCR register.
DMA_SxM1AR(1)
Memory
destination
FIFO
Arbiter level
REQ_STREAMx FIFO
peripheral
DMA_SxPAR source
Memory-to-peripheral mode
Figure 26 describes this mode.
When this mode is enabled (by setting the EN bit in the DMA_SxCR register), the stream
immediately initiates transfers from the source to entirely fill the FIFO.
Each time a peripheral request occurs, the contents of the FIFO are drained and stored into
the destination. When the level of the FIFO is lower than or equal to the predefined
threshold level, the FIFO is fully reloaded with data from the memory.
The transfer stops once the DMA_SxNDTR register reaches zero, when the peripheral
requests the end of transfers (in case of a peripheral flow controller) or when the EN bit in
the DMA_SxCR register is cleared by software.
In direct mode (when the DMDIS value in the DMA_SxFCR register is '0'), the threshold
level of the FIFO is not used. Once the stream is enabled, the DMA preloads the first data to
transfer into an internal FIFO. As soon as the peripheral requests a data transfer, the DMA
transfers the preloaded value into the configured destination. It then reloads again the
empty internal FIFO with the next data to be transfer. The preloaded data size corresponds
to the value of the PSIZE bitfield in the DMA_SxCR register.
The stream has access to the AHB source or destination port only if the arbitration of the
corresponding stream is won. This arbitration is performed using the priority defined for
each stream using the PL[1:0] bits in the DMA_SxCR register.
DMA_SxM1AR(1)
Memory bus
AHB memory
port
Memory
source
FIFO
Arbiter
REQ_STREAMx level FIFO
Peripheral
DMA_SxPAR destination
ai15949
Memory-to-memory mode
The DMA channels can also work without being triggered by a request from a peripheral.
This is the memory-to-memory mode, described in Figure 27.
When the stream is enabled by setting the Enable bit (EN) in the DMA_SxCR register, the
stream immediately starts to fill the FIFO up to the threshold level. When the threshold level
is reached, the FIFO contents are drained and stored into the destination.
The transfer stops once the DMA_SxNDTR register reaches zero or when the EN bit in the
DMA_SxCR register is cleared by software.
The stream has access to the AHB source or destination port only if the arbitration of the
corresponding stream is won. This arbitration is performed using the priority defined for
each stream using the PL[1:0] bits in the DMA_SxCR register.
Note: When memory-to-memory mode is used, the Circular and direct modes are not allowed.
Only the DMA2 controller is able to perform memory-to-memory transfers.
DMA_SxM1AR(1)
Memory 2
destination
Arbiter FIFO
Stream enable level FIFO
Memory 1
DMA_SxPAR source
ai15950
When the circular mode is activated, the number of data items to be transferred is
automatically reloaded with the initial value programmed during the stream configuration
phase, and the DMA requests continue to be served.
Note: In the circular mode, it is mandatory to respect the following rule in case of a burst mode
configured for memory:
DMA_SxNDTR = Multiple of ((Mburst beat) × (Msize)/(Psize)), where:
– (Mburst beat) = 4, 8 or 16 (depending on the MBURST bits in the DMA_SxCR
register)
– ((Msize)/(Psize)) = 1, 2, 4, 1/2 or 1/4 (Msize and Psize represent the MSIZE and
PSIZE bits in the DMA_SxCR register. They are byte dependent)
– DMA_SxNDTR = Number of data items to transfer on the AHB peripheral port
For example: Mburst beat = 8 (INCR8), MSIZE = ‘00’ (byte) and PSIZE = ‘01’ (half-word), in
this case: DMA_SxNDTR must be a multiple of (8 × 1/2 = 4).
If this formula is not respected, the DMA behavior and data integrity are not guaranteed.
NDTR must also be a multiple of the Peripheral burst size multiplied by the peripheral data
size, otherwise this could result in a bad DMA behavior.
Table 30. Source and destination address registers in Double buffer mode (DBM=1)
Bits DIR[1:0] of the
Direction Source address Destination address
DMA_SxCR register
DMA_SxM0AR /
00 Peripheral-to-memory DMA_SxPAR
DMA_SxM1AR
DMA_SxM0AR /
01 Memory-to-peripheral DMA_SxPAR
DMA_SxM1AR
10 Not allowed(1)
11 Reserved - -
1. When the Double buffer mode is enabled, the Circular mode is automatically enabled. Since the memory-
to-memory mode is not compatible with the Circular mode, when the Double buffer mode is enabled, it is
not allowed to configure the memory-to-memory mode.
Note: Peripheral port may be the source or the destination (it could also be the memory source in
the case of memory-to-memory transfer).
PSIZE, MSIZE and NDT[15:0] have to be configured so as to ensure that the last transfer
will not be incomplete. This can occur when the data width of the peripheral port (PSIZE
bits) is lower than the data width of the memory port (MSIZE bits). This constraint is
summarized in Table 32.
9.3.12 FIFO
FIFO structure
The FIFO is used to temporarily store data coming from the source before transmitting them
to the destination.
Each stream has an independent 4-word FIFO and the threshold level is software-
configurable between 1/4, 1/2, 3/4 or full.
To enable the use of the FIFO threshold level, the direct mode must be disabled by setting
the DMDIS bit in the DMA_SxFCR register.
The structure of the FIFO differs depending on the source and destination data widths, and
is described in Figure 28: FIFO structure.
4 words
4 words
4-words
ai15951
1/4 forbidden
1/2 1 burst of 4 beats forbidden
Half-word
3/4 forbidden
Full 2 bursts of 4 beats 1 burst of 8 beats
forbidden
1/4
1/2 forbidden
Word forbidden
3/4
Full 1 burst of 4 beats
In all cases, the burst size multiplied by the data size must not exceed the FIFO size (data
size can be: 1 (byte), 2 (half-word) or 4 (word)).
Incomplete Burst transfer at the end of a DMA transfer may happen if one of the following
conditions occurs:
• For the AHB peripheral port configuration: the total number of data items (set in the
DMA_SxNDTR register) is not a multiple of the burst size multiplied by the data size
• For the AHB memory port configuration: the number of remaining data items in the
FIFO to be transferred to the memory is not a multiple of the burst size multiplied by the
data size
In such cases, the remaining data to be transferred will be managed in single mode by the
DMA, even if a burst transaction was requested during the DMA stream configuration.
Note: When burst transfers are requested on the peripheral AHB port and the FIFO is used
(DMDIS = 1 in the DMA_SxCR register), it is mandatory to respect the following rule to
avoid permanent underrun or overrun conditions, depending on the DMA stream direction:
If (PBURST × PSIZE) = FIFO_SIZE (4 words), FIFO_Threshold = 3/4 is forbidden with
PSIZE = 1, 2 or 4 and PBURST = 4, 8 or 16.
This rule ensures that enough FIFO space at a time will be free to serve the request from
the peripheral.
FIFO flush
The FIFO can be flushed when the stream is disabled by resetting the EN bit in the
DMA_SxCR register and when the stream is configured to manage peripheral-to-memory or
memory-to-memory transfers: If some data are still present in the FIFO when the stream is
disabled, the DMA controller continues transferring the remaining data to the destination
(even though stream is effectively disabled). When this flush is completed, the transfer
complete status bit (TCIFx) in the DMA_LISR or DMA_HISR register is set.
The remaining data counter DMA_SxNDTR keeps the value in this case to indicate how
many data items are currently available in the destination memory.
Note that during the FIFO flush operation, if the number of remaining data items in the FIFO
to be transferred to memory (in bytes) is less than the memory data width (for example 2
bytes in FIFO while MSIZE is configured to word), data will be sent with the data width set in
the MSIZE bit in the DMA_SxCR register. This means that memory will be written with an
undesired value. The software may read the DMA_SxNDTR register to determine the
memory area that contains the good data (start address and last address).
If the number of remaining data items in the FIFO is lower than a burst size (if the MBURST
bits in DMA_SxCR register are set to configure the stream to manage burst on the AHB
memory port), single transactions will be generated to complete the FIFO flush.
Direct mode
By default, the FIFO operates in direct mode (DMDIS bit in the DMA_SxFCR is reset) and
the FIFO threshold level is not used. This mode is useful when the system requires an
immediate and single transfer to or from the memory after each DMA request.
When the DMA is configured in direct mode (FIFO disabled), to transfer data in memory-to-
peripheral mode, the DMA preloads one data from the memory to the internal FIFO to
ensure an immediate data transfer as soon as a DMA request is triggered by a peripheral.
To avoid saturating the FIFO, it is recommended to configure the corresponding stream with
a high priority.
This mode is restricted to transfers where:
• The source and destination transfer widths are equal and both defined by the
PSIZE[1:0] bits in DMA_SxCR (MSIZE[1:0] bits are don’t care)
• Burst transfers are not possible (PBURST[1:0] and MBURST[1:0] bits in DMA_SxCR
are don’t care)
Direct mode must not be used when implementing memory-to-memory transfers.
be forced by hardware to 0xFFFF as soon as the stream is enabled, to respect the following
schemes:
• Anticipated stream interruption: EN bit in DMA_SxCR register is reset to 0 by the
software to stop the stream before the last data hardware signal (single or burst) is sent
by the peripheral. In such a case, the stream is switched off and the FIFO flush is
triggered in the case of a peripheral-to-memory DMA transfer. The TCIFx flag of the
corresponding stream is set in the status register to indicate the DMA completion. To
know the number of data items transferred during the DMA transfer, read the
DMA_SxNDTR register and apply the following formula:
– Number_of_data_transferred = 0xFFFF – DMA_SxNDTR
• Normal stream interruption due to the reception of a last data hardware signal: the
stream is automatically interrupted when the peripheral requests the last transfer
(single or burst) and when this transfer is complete. the TCIFx flag of the corresponding
stream is set in the status register to indicate the DMA transfer completion. To know the
number of data items transferred, read the DMA_SxNDTR register and apply the same
formula as above.
• The DMA_SxNDTR register reaches 0: the TCIFx flag of the corresponding stream is
set in the status register to indicate the forced DMA transfer completion. The stream is
automatically switched off even though the last data hardware signal (single or burst)
has not been yet asserted. The already transferred data will not be lost. This means
that a maximum of 65535 data items can be managed by the DMA in a single
transaction, even in peripheral flow control mode.
Note: When configured in memory-to-memory mode, the DMA is always the flow controller and
the PFCTRL bit is forced to 0 by hardware.
The Circular mode is forbidden in the peripheral flow controller mode.
single possible
DMA possible possible
Peripheral-to- AHB AHB burst forbidden
memory peripheral port memory port single possible
Peripheral forbidden forbidden
burst forbidden
single possible
DMA possible possible
Memory-to- AHB AHB burst forbidden
peripheral memory port peripheral port single possible
Peripheral forbidden forbidden
burst forbidden
Note: Before setting an Enable control bit to ‘1’, the corresponding event flag should be cleared,
otherwise an interrupt is immediately generated.
Bits 26, 20, 10, 4 HTIFx: Stream x half transfer interrupt flag (x=3..0)
This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the
DMA_LIFCR register.
0: No half transfer event on stream x
1: A half transfer event occurred on stream x
Bits 25, 19, 9, 3 TEIFx: Stream x transfer error interrupt flag (x=3..0)
This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the
DMA_LIFCR register.
0: No transfer error on stream x
1: A transfer error occurred on stream x
Bits 24, 18, 8, 2 DMEIFx: Stream x direct mode error interrupt flag (x=3..0)
This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the
DMA_LIFCR register.
0: No Direct Mode Error on stream x
1: A Direct Mode Error occurred on stream x
Bits 23, 17, 7, 1 Reserved, must be kept at reset value.
Bits 22, 16, 6, 0 FEIFx: Stream x FIFO error interrupt flag (x=3..0)
This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the
DMA_LIFCR register.
0: No FIFO Error event on stream x
1: A FIFO Error event occurred on stream x
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TCIF7 HTIF7 TEIF7 DMEIF7 Reserv FEIF7 TCIF6 HTIF6 TEIF6 DMEIF6 Reserv FEIF6
Reserved
ed ed
r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TCIF5 HTIF5 TEIF5 DMEIF5 Reserv FEIF5 TCIF4 HTIF4 TEIF4 DMEIF4 Reserv FEIF4
Reserved
ed ed
r r r r r r r r r r
Bits 25, 19, 9, 3 TEIFx: Stream x transfer error interrupt flag (x=7..4)
This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the
DMA_HIFCR register.
0: No transfer error on stream x
1: A transfer error occurred on stream x
Bits 24, 18, 8, 2 DMEIFx: Stream x direct mode error interrupt flag (x=7..4)
This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the
DMA_HIFCR register.
0: No Direct mode error on stream x
1: A Direct mode error occurred on stream x
Bits 23, 17, 7, 1 Reserved, must be kept at reset value.
Bits 22, 16, 6, 0 FEIFx: Stream x FIFO error interrupt flag (x=7..4)
This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the
DMA_HIFCR register.
0: No FIFO error event on stream x
1: A FIFO error event occurred on stream x
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBM or
CHSEL[3:0] MBURST [1:0] PBURST[1:0] Reserv CT PL[1:0]
Reserved reserved
ed
rw rw rw rw rw rw rw rw rw or r rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PINCOS MSIZE[1:0] PSIZE[1:0] MINC PINC CIRC DIR[1:0] PFCTRL TCIE HTIE TEIE DMEIE EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bit 0 EN: Stream enable / flag stream ready when read low
This bit is set and cleared by software.
0: Stream disabled
1: Stream enabled
This bit may be cleared by hardware:
– on a DMA end of transfer (stream ready to be configured)
– if a transfer error occurs on the AHB master buses
– when the FIFO threshold on memory AHB port is not compatible with the size of the
burst
When this bit is read as 0, the software is allowed to program the Configuration and FIFO
bits registers. It is forbidden to write these registers when the EN bit is read as 1.
Note: Before setting EN bit to '1' to start a new transfer, the event flags corresponding to the
stream in DMA_LISR or DMA_HISR register must be cleared.
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
NDT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PAR[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
PAR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
M0A[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
M0A[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
M1A[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
M1A[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 M1A[31:0]: Memory 1 address (used in case of Double buffer mode)
Base address of Memory area 1 from/to which the data will be read/written.
This register is used only for the Double buffer mode.
These bits are write-protected. They can be written only if:
– the stream is disabled (bit EN= '0' in the DMA_SxCR register) or
– the stream is enabled (EN=’1’ in DMA_SxCR register) and bit CT = '0' in the
DMA_SxCR register.
10
11
9
8
7
6
5
4
3
2
1
0
DMEIF3
DMEIF2
DMEIF1
DMEIF0
HTIF3
HTIF2
HTIF1
HTIF0
TCIF3
TCIF2
TCIF1
TCIF0
TEIF3
FEIF3
TEIF2
FEIF2
TEIF1
FEIF1
TEIF0
FEIF0
Reserved
Reserved
Reserved
Reserved
DMA_LISR
0x0000 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMEIF7
DMEIF6
DMEIF5
DMEIF4
TCIF7
HTIF7
TCIF6
HTIF6
TCIF5
HTIF5
TCIF4
HTIF4
TEIF7
FEIF7
TEIF6
FEIF6
TEIF5
FEIF5
TEIF4
FEIF4
Reserved
Reserved
Reserved
Reserved
DMA_HISR
0x0004 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CDMEIF3
CDMEIF2
CDMEIF1
CDMEIF0
CTCIF3
CHTIF3
CTCIF2
CHTIF2
CTCIF1
CHTIF1
CTCIF0
CHTIF0
CFEIF3
CTEIF2
CFEIF2
CTEIF1
CFEIF1
CTEIF0
CFEIF0
TEIF3
Reserved
Reserved
Reserved
Reserved
DMA_LIFCR
0x0008 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CDMEIF7
CDMEIF6
CDMEIF5
CDMEIF4
CTCIF7
CHTIF7
CTCIF6
CHTIF6
CTCIF5
CHTIF5
CTCIF4
CHTIF4
CTEIF7
CFEIF7
CTEIF6
CFEIF6
CTEIF5
CFEIF5
CTEIF4
CFEIF4
Reserved
Reserved
Reserved
Reserved
DMA_HIFCR
0x000C Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
Reserved
MINC
CIRC
PINC
TCIE
HTIE
TEIE
DBM
DMA_S0CR
EN
CT
0x0010 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S0NDTR NDT[15:.]
0x0014 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S0PAR PA[31:0]
0x0018
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S0M0AR M0A[31:0]
0x001C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S0M1AR M1A[31:0]
0x0020
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S0FCR FS[2:0]
0x0024 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
PBURST[1:0]
MBURST[1:]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
CHSEL
PL[1:0]
DMEIE
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
ACK
[2:0]
DMA_S1CR
EN
CT
0x0028 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S1NDTR NDT[15:.]
0x002C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S1PAR PA[31:0]
0x0030
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
DMA_S1M0AR M0A[31:0]
0x0034
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S1M1AR M1A[31:0]
0x0038
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S1FCR FS[2:0]
0x003C Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
CHSEL
PL[1:0]
DMEIE
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
ACK
[2:0]
[1:0]
DIR
DMA_S2CR
EN
CT
0x0040 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S2NDTR NDT[15:.]
0x0044 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S2PAR PA[31:0]
0x0048
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S2M0AR M0A[31:0]
0x004C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S2M1AR M1A[31:0]
0x0050
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S2FCR FS[2:0]
0x0054 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
MINC
CIRC
PINC
HTIE
TCIE
TEIE
DBM
ACK
DMA_S3CR
EN
CT
0x0058 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3NDTR NDT[15:.]
0x005C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3PAR PA[31:0]
0x0060
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3M0AR M0A[31:0]
0x0064
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3M1AR M1A[31:0]
0x0068
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S3FCR FS[2:0]
0x006C Reserved [1:0]
Reset value 0 1 0 0 0 0 1
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
PL[1:0]
DMEIE
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
ACK
[1:0]
DIR
DMA_S4CR
EN
CT
0x0070 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S4NDTR NDT[15:.]
0x0074 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S4PAR PA[31:0]
0x0078
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S4M0AR M0A[31:0]
0x007C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S4M1AR M1A[31:0]
0x0080
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S4FCR FS[2:0]
0x0084 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
MINC
CIRC
PINC
HTIE
TCIE
DBM
TEIE
ACK
DMA_S5CR
EN
CT
0x0088 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S5NDTR NDT[15:.]
0x008C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S5PAR PA[31:0]
0x0090
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S5M0AR M0A[31:0]
0x0094
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S5M1AR M1A[31:0]
0x0098
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S5FCR FS[2:0]
0x009C Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
ACK
DMA_S6CR
EN
CT
0x00A0 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S6NDTR NDT[15:.]
0x00A4 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S6PAR PA[31:0]
0x00A8
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S6M0AR M0A[31:0]
0x00AC
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S6M1AR M1A[31:0]
0x00B0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S6FCR FS[2:0]
0x00B4 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
ACK
DMA_S7CR
EN
CT
0x00B8 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S7NDTR NDT[15:.]
0x00BC Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S7PAR PA[31:0]
0x00C0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S7M0AR M0A[31:0]
0x00C4
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S7M1AR M1A[31:0]
0x00C8
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMDIS
FTH
Reserved
FEIE
DMA_S7FCR FS[2:0]
0x00CC Reserved [1:0]
Reset value 0 1 0 0 0 0 1
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
$0%$$3%EXV
3&/. 3HULSKHUDOLQWHUIDFH
7R19,&LQWHUUXSW
FRQWUROOHU
(YHQW
PDVN
UHJLVWHU
069
generated. The pending bit corresponding to the interrupt line is also set. This request is
reset by writing a ‘1’ in the pending register.
To generate the event, the event line should be configured and enabled. This is done by
programming the two trigger registers with the desired edge detection and by enabling the
event request by writing a ‘1’ to the corresponding bit in the event mask register. When the
selected edge occurs on the event line, an event pulse is generated. The pending bit
corresponding to the event line is not set.
An interrupt/event request can also be generated by software by writing a ‘1’ in the software
interrupt/event register.
3$
3%
3& (;7,
3'
3(
3+
(;7,>@ELWVLQWKH6<6&)*B(;7,&5UHJLVWHU
3$
3%
3&
(;7,
3'
3(
3+
(;7,>@ELWVLQWKH6<6&)*B(;7,&5UHJLVWHU
3$
3%
(;7,
3&
3'
3(
069
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MR22 MR21 MR18 MR17 MR16
Reserved Reserved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MR22 MR21 MR18 MR17 MR16
Reserved Reserved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TR22 TR21 TR18 TR17 TR16
Reserved Reserved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The external wakeup lines are edge triggered, no glitch must be generated on these lines.
If a rising edge occurs on the external interrupt line while writing to the EXTI_RTSR register,
the pending bit is be set.
Rising and falling edge triggers can be set for the same interrupt line. In this configuration,
both generate a trigger condition.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TR22 TR21 TR18 TR17 TR16
Reserved Reserved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The external wakeup lines are edge triggered, no glitch must be generated on these lines.
If a falling edge occurs on the external interrupt line while writing to the EXTI_FTSR register,
the pending bit is not set.
Rising and falling edge triggers can be set for the same interrupt line. In this configuration,
both generate a trigger condition.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SWIER SWIER SWIER SWIER SWIER
Reserved 22 21 Reserved 18 17 16
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PR22 PR21 PR18 PR17 PR16
Reserved Reserved
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PR15 PR14 PR13 PR12 PR11 PR10 PR9 PR8 PR7 PR6 PR5 PR4 PR3 PR2 PR1 PR0
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
Table 38. External interrupt/event controller register map and reset values
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
MR
EXTI_IMR MR[18:0]
0x00 Reserved [22:21] Reser
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MR
EXTI_EMR MR[18:0]
0x04 Reserved [22:21] Reser
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TR
EXTI_RTSR TR[18:0]
0x08 Reserved [22:21] Reser
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TR
EXTI_FTSR TR[18:0]
0x0C Reserved [22:21] Reser
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SWIER
EXTI_SWIER SWIER[18:0]
0x10 Reserved [22:21] Reser
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PR
EXTI_PR PR[18:0]
0x14 Reserved [22:21] Reser
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
!NALOG WATCHDOG
#OMPARE RESULT
!DDRESSDATA BUS
)NJECTED DATA REGISTERS
6 2%& X BITS
6 2%&
2EGULAR DATA REGISTER
6 $$! BITS
6 33!
!NALOG $-! REQUEST
MUX
!$#X?).
!$#X?).
'0)/ UP TO !$##,+
)NJECTED
PORTS CHANNELS !NALOG TO DIGITAL
UP TO 2EGULAR CONVERTER
!$#X?).
CHANNELS
4EMP SENSOR
6 2%&).4
6 "!4
4)-?#( 4)-?#(
4)-?42'/ *%84%. %84%. 4)-?#(
4)-?#( ;= BITS ;= BITS 4)-?#(
4)-?42'/ 4)-?#(
4)-?#( 4)-?#(
4)-?#( 4)-?#(
4)-?#( 4)-?42'/
4)-?#( 4)-?#(
4)-?#( 4)-?42'/
4)-?42'/ 4)-?#(
3TART TRIGGER 3TART TRIGGER
4)-?#( 4)-?#(
INJECTED GROUP REGULAR GROUP
4)-?42'/ 4)-?#(
4)-?#(
%84)?
%84)?
-36
Input, analog reference The higher/positive reference voltage for the ADC,
VREF+
positive 1.8 V ≤VREF+ ≤VDDA
Analog power supply equal to VDD and
VDDA Input, analog supply 2.4 V ≤VDDA ≤VDD (3.6 V) for full speed
1.8 V ≤VDDA ≤VDD (3.6 V) for reduced speed
Input, analog reference The lower/negative reference voltage for the ADC,
VREF–
negative VREF– = VSSA
Input, analog supply
VSSA Ground for analog power supply equal to VSS
ground
ADCx_IN[15:0] Analog input signals 16 analog input channels
The total number of conversions in the injected group must be written in the L[1:0] bits
in the ADC_JSQR register.
If the ADC_SQRx or ADC_JSQR registers are modified during a conversion, the current
conversion is reset and a new start pulse is sent to the ADC to convert the newly chosen
group.
Note: Injected channels cannot be converted continuously. The only exception is when an injected
channel is configured to be converted automatically after regular channels in continuous
mode (using JAUTO bit), refer to Auto-injection section).
!$#?#,+
!$/.
3734!24
*3734!24
!NALOG VOLTAGE
AI
None x 0 0
All injected channels 0 0 1
All regular channels 0 1 0
All regular and injected channels 0 1 1
(1)
Single injected channel 1 0 1
(1)
Single regular channel 1 1 0
Single (1) regular or injected channel 1 1 1
1. Selected by the AWDCH[4:0] bits
interrupted but the regular sequence is executed at the end of the injected sequence.
Figure 34 shows the corresponding timing diagram.
Note: When using triggered injection, one must ensure that the interval between trigger events is
longer than the injection sequence. For instance, if the sequence length is 30 ADC clock
cycles (that is two conversions with a sampling time of 3 clock periods), the minimum
interval between triggers must be 31 ADC clock cycles.
Auto-injection
If the JAUTO bit is set, then the channels in the injected group are automatically converted
after the regular group of channels. This can be used to convert a sequence of up to 20
conversions programmed in the ADC_SQRx and ADC_JSQR registers.
In this mode, external trigger on injected channels must be disabled.
If the CONT bit is also set in addition to the JAUTO bit, regular channels followed by injected
channels are continuously converted.
Note: It is not possible to use both the auto-injected and discontinuous modes simultaneously.
!$##,+
)NJECTION EVENT
2ESET !$#
MAX LATENCY
3/#
AI
1. The maximum latency value can be found in the electrical characteristics of the STM32F411xC/E
datasheets.
Example:
• n = 3, channels to be converted = 0, 1, 2, 3, 6, 7, 9, 10
• 1st trigger: sequence converted 0, 1, 2. An EOC event is generated at each
conversion.
• 2nd trigger: sequence converted 3, 6, 7. An EOC event is generated at each
conversion
• 3rd trigger: sequence converted 9, 10.An EOC event is generated at each conversion
• 4th trigger: sequence converted 0, 1, 2. An EOC event is generated at each conversion
Note: When a regular group is converted in discontinuous mode, no rollover occurs.
When all subgroups are converted, the next trigger starts the conversion of the first
subgroup. In the example above, the 4th trigger reconverts the channels 0, 1 and 2 in the
1st subgroup.
Injected group
This mode is enabled by setting the JDISCEN bit in the ADC_CR1 register. It can be used to
convert the sequence selected in the ADC_JSQR register, channel by channel, after an
external trigger event.
When an external trigger occurs, it starts the next channel conversions selected in the
ADC_JSQR registers until all the conversions in the sequence are done. The total sequence
length is defined by the JL[1:0] bits in the ADC_JSQR register.
Example:
n = 1, channels to be converted = 1, 2, 3
1st trigger: channel 1 converted
2nd trigger: channel 2 converted
3rd trigger: channel 3 converted and JEOC event generated
4th trigger: channel 1
Note: When all injected channels are converted, the next trigger starts the conversion of the first
injected channel. In the example above, the 4th trigger reconverts the 1st injected channel
1.
It is not possible to use both the auto-injected and discontinuous modes simultaneously.
Discontinuous mode must not be set for regular and injected groups at the same time.
Discontinuous mode must be enabled only for the conversion of one group.
)NJECTED GROUP
2EGULAR GROUP
$ $ $ $ $ $ $ $ $ $ $ $
AI
)NJECTED GROUP
2EGULAR GROUP
$ $ $ $ $ $ $ $ $ $ $ $
AI
Special case: when left-aligned, the data are aligned on a half-word basis except when the
resolution is set to 6-bit. in that case, the data are aligned on a byte basis as shown in
Figure 37.
)NJECTED GROUP
2EGULAR GROUP
$ $ $ $ $ $
AI
Note: The polarity of the external trigger can be changed on the fly.
The EXTSEL[3:0] and JEXTSEL[3:0] control bits are used to select which out of 16 possible
events can trigger conversion for the regular and injected groups.
Table 42 gives the possible external trigger for regular conversion.
Software source trigger events can be generated by setting SWSTART (for regular
conversion) or JSWSTART (for injected conversion) in ADC_CR2.
A regular group conversion can be interrupted by an injected trigger.
Note: The trigger selection can be changed on the fly. However, when the selection changes,
there is a time frame of 1 APB clock cycle during which the trigger detection is disabled.
This is to avoid spurious detection during transitions.
Main features
• Supported temperature range: –40 to 125 °C
• Precision: ±1.5 °C
4EMPERATURE 6 3%.3%
SENSOR !$#?).
!$#?).
!DDRESSDATA BUS
CONVERTED DATA
!$#
62%&).4
)NTERNAL
POWER BLOCK !$#?).
-36
Two other flags are present in the ADC_SR register, but there is no interrupt associated with
them:
• JSTRT (Start of conversion for channels of an injected group)
• STRT (Start of conversion for channels of a regular group)
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
OVR STRT JSTRT JEOC EOC AWD
Reserved
rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OVRIE RES AWDEN JAWDEN
Reserved Reserved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JDISCE DISC AWDSG
DISCNUM[2:0] JAUTO SCAN JEOCIE AWDIE EOCIE AWDCH[4:0]
N EN L
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SWST JSWST
EXTEN EXTSEL[3:0] JEXTEN JEXTSEL[3:0]
reserved ART reserved ART
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
ALIGN EOCS DDS DMA CONT ADON
reserved Reserved
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SMP18[2:0] SMP17[2:0] SMP16[2:0] SMP15[2:1]
Reserved
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
SMP15_0 SMP14[2:0] SMP13[2:0] SMP12[2:0] SMP11[2:0] SMP10[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SMP9[2:0] SMP8[2:0] SMP7[2:0] SMP6[2:0] SMP5[2:1]
Reserved
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
SMP
SMP4[2:0] SMP3[2:0] SMP2[2:0] SMP1[2:0] SMP0[2:0]
5_0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
JOFFSETx[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
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
HT[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
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
LT[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
L[3:0] SQ16[4:1]
Reserved
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SQ16_0 SQ15[4:0] SQ14[4:0] SQ13[4:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SQ12[4:0] SQ11[4:0] SQ10[4:1]
Reserved
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
SQ10_0 SQ9[4:0] SQ8[4:0] SQ7[4:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SQ6[4:0] SQ5[4:0] SQ4[4:1]
Reserved
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
SQ4_0 SQ3[4:0] SQ2[4:0] SQ1[4:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
JL[1:0] JSQ4[4:1]
Reserved
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JSQ4[0] JSQ3[4:0] JSQ2[4:0] JSQ1[4:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: When JL[1:0]=3 (4 injected conversions in the sequencer), the ADC converts the channels
in the following order: JSQ1[4:0], JSQ2[4:0], JSQ3[4:0], and JSQ4[4:0].
When JL=2 (3 injected conversions in the sequencer), the ADC converts the channels in the
following order: JSQ2[4:0], JSQ3[4:0], and JSQ4[4:0].
When JL=1 (2 injected conversions in the sequencer), the ADC converts the channels in
starting from JSQ3[4:0], and then JSQ4[4:0].
When JL=0 (1 injected conversion in the sequencer), the ADC converts only JSQ4[4:0]
channel.
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
JDATA[15:0]
r r r r r r r r r r r r r r r r
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
DATA[15:0]
r r r r r r r r r r r r r r r r
Table 46. ADC register map and reset values for each ADC
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
JSTRT
JEOC
STRT
AWD
OVR
EOC
ADC_SR
0x00 Reserved
Reset value 0 0 0 0 0 0
AWD SGL
JDISCEN
JAWDEN
RES[1:0]
DISCEN
AWDEN
JEOCIE
JAUTO
AWDIE
OVRIE
EOCIE
SCAN
DISC
ADC_CR1 AWDCH[4:0]
0x04 Reserved Reserved NUM [2:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
JEXTEN[1:0]
JSWSTART
EXTEN[1:0]
Re Re
SWSTART
ALIGN
ADON
EOCS
CONT
se se JEXTSEL
DMA
DDS
ADC_CR2 EXTSEL [3:0]
0x08 rv rv [3:0] Reserved Reserved
ed ed
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_SMPR1 Sample time bits SMPx_x
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_SMPR2 Sample time bits SMPx_x
0x10
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR1 JOFFSET1[11:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR2 JOFFSET2[11:0]
0x18 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR3 JOFFSET3[11:0]
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR4 JOFFSET4[11:0]
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_HTR HT[11:0]
0x24 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1
ADC_LTR LT[11:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_SQR1 L[3:0] Regular channel sequence SQx_x bits
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_SQR2 Regular channel sequence SQx_x bits
Reserved Reserved
0x30
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 47. ADC register map and reset values (common ADC registers)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ADCPRE[1:0]
TSVREFE
VBATE
ADC_CCR
0x04 Reserved Reserved Reserved
Reset value 0 0 0 0
7,)B('
7,)3 (QFRGHU
7,)3 ,QWHUIDFH
5(35HJLVWHU
8,
8 $XWR5HORDG5HJLVWHU
5HSHWLWLRQ
FRXQWHU 8
6WRS&OHDURU8S'RZQ
(75)
%5. %,
4)-X?"+). 3RODULW\6HOHFWLRQ
&ORFNIDLOXUHHYHQWIURPFORFNFRQWUROOHU
&66 &ORFN6HFXULW\V\VWHP
1RWHV
5HJ 3UHORDGUHJLVWHUVWUDQVIHUUHG
WRDFWLYHUHJLVWHUVRQ8HYHQW
DFFRUGLQJWRFRQWUROELW
HYHQW
LQWHUUXSW '0$RXWSXW
069
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit register (in the TIMx_PSC register).
It can be changed on the fly as this control register is buffered. The new prescaler ratio is
taken into account at the next update event.
Figure 40 and Figure 41 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 40. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
Figure 41. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 00 01
Prescaler buffer 0 3
Prescaler counter 0 0 1 2 3 0 1 2 3
preload registers. Then no update event occurs until the UDIS bit has been written to 0.
However, the counter restarts from 0, as well as the counter of the prescaler (but the
prescale rate does not change). In addition, if the URS bit (update request selection) in
TIMx_CR1 register is set, setting the UG bit generates an update event UEV but without
setting the UIF flag (thus no interrupt or DMA request is sent). This is to avoid generating
both update and capture interrupts when clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The repetition counter is reloaded with the content of TIMx_RCR register,
• The auto-reload shadow register is updated with the preload value (TIMx_ARR),
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
Counter register 1F 20 00
Counter overflow
Figure 46. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
CK_PSC
CEN
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Downcounting mode
In downcounting mode, the counter counts from the auto-reload value (content of the
TIMx_ARR register) down to 0, then restarts from the auto-reload value and generates a
counter underflow event.
If the repetition counter is used, the update event (UEV) is generated after downcounting is
repeated for the number of times programmed in the repetition counter register plus one
(TIMx_RCR+1). Else the update event is generated at each counter underflow.
Setting the UG bit in the TIMx_EGR register (by software or by using the slave mode
controller) also generates an update event.
The UEV update event can be disabled by software by setting the UDIS bit in TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until UDIS bit has been written to 0.
However, the counter restarts from the current auto-reload value, whereas the counter of the
prescaler restarts from 0 (but the prescale rate doesn’t change).
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The repetition counter is reloaded with the content of TIMx_RCR register
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register)
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that the auto-reload is updated before the counter is
reloaded, so that the next period is the expected one
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
CK_PSC
CNT_EN
Counter underflow
CK_PSC
CNT_EN
Counter underflow
CK_PSC
Counter register 20 1F 00 36
Counter underflow
Figure 52. Counter timing diagram, update event when repetition counter
is not used
CK_PSC
CEN
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload register FF 36
The UEV update event can be disabled by software by setting the UDIS bit in the TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until UDIS bit has been written to 0.
However, the counter continues counting up and down, based on the current auto-reload
value.
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an UEV update event but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The repetition counter is reloaded with the content of TIMx_RCR register
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register)
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that if the update source is a counter overflow, the auto-
reload is updated before the counter is reloaded, so that the next period is the expected
one (the counter is loaded with the new value).
The following figures show some examples of the counter behavior for different clock
frequencies.
Figure 53. Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6
CK_PSC
CNT_EN
Counter register 04 03 02 01 00 01 02 03 04 05 06 05 04 03
Counter underflow
Counter overflow
1. Here, center-aligned mode 1 is used (for more details refer to Section 12.4: TIM1 registers on page 278).
CK_PSC
CNT_EN
Counter underflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
Counter register 20 1F 01 00
Counter underflow
Figure 57. Counter timing diagram, update event with ARPE=1 (counter underflow)
CK_PSC
CEN
Counter register 06 05 04 03 02 01 00 01 02 03 04 05 06 07
Counter underflow
Figure 58. Counter timing diagram, Update event with ARPE=1 (counter overflow)
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 36 35 34 33 32 31 30 2F
Counter overflow
Figure 59. Update rate examples depending on mode and TIMx_RCR register settings
Upcounting Downcounting
Counter
TIMx_CNT
TIMx_RCR = 0 UEV
TIMx_RCR = 1 UEV
TIMx_RCR = 2 UEV
TIMx_RCR = 3 UEV
TIMx_RCR = 3
and
re-synchronization
UEV
(by SW) (by SW) (by SW)
UEV Update Event: Preload registers transferred to active registers and update interrupt generated
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
TI2F or
or
TI1F or encoder
ITRx 0xx mode
TI1_ED 100
TI1FP1 101 TRGI external clock
TI2F_Rising
mode 1 CK_PSC
0
TI2 Filter Edge TI2FP2 110
Detector TI2F_Falling ETRF external clock
1 ETRF 111 mode 2
ICF[3:0] CC2P CK_INT internal clock
TIMx_CCMR1 TIMx_CCER mode
(internal clock)
ECE SMS[2:0]
TIMx_SMCR
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in
the TIMx_CCMR1 register.
2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=0000).
3. Select rising edge polarity by writing CC2P=0 and CC2NP=0 in the TIMx_CCER
register.
4. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
5. Select TI2 as the trigger input source by writing TS=110 in the TIMx_SMCR register.
6. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
Note: The capture prescaler is not used for triggering, so you don’t need to configure it.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
TI2F or
or
TI1F or encoder
mode
For example, to configure the upcounter to count each 2 rising edges on ETR, use the
following procedure:
1. As no filter is needed in this example, write ETF[3:0]=0000 in the TIMx_SMCR register.
2. Set the prescaler by writing ETPS[1:0]=01 in the TIMx_SMCR register
3. Select rising edge detection on the ETR pin by writing ETP=0 in the TIMx_SMCR
register
4. Enable external clock mode 2 by writing ECE=1 in the TIMx_SMCR register.
5. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
The counter counts once each 2 ETR rising edges.
The delay between the rising edge on ETR and the actual clock of the counter is due to the
resynchronization circuit on the ETRP signal.
fCK_INT
CNT_EN
ETR
ETRP
ETRF
Counter register 34 35 36
TI1F_ED
to the slave mode controller
TI1F_Rising 0
TI1 TI1F
filter Edge TI1FP1
01
fDTS downcounter Detector TI1F_Falling
1
TI2FP1 IC1 divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP TRC
TIMx_CCER 11
TIMx_CCMR1 (from slave mode
controller)
TI2F_rising 0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
(if 16-bit)
8 8
high
low
S write CCR1H
read CCR1H S write_in_progress
read_in_progress
Capture/compare preload register write CCR1L
read CCR1L R
R CC1S[1]
output
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] input
mode OC1PE
Capture/compare shadow register OC1PE
CC1S[0] UEV
TIM1_CCMR1
comparator (from time
IC1PS capture base unit)
CC1E CNT>CCR1
Counter
CNT=CCR1
CC1G
TIM1_EGR
OC1CE OC1M[2:0] DTG[7:0] CC1NE CC1E CC1NP MOE OSSI OSSR TIM1_BDTR
TIM1_CCMR1 TIM1_BDTR TIM1_CCER TIM1_CCER
CC4P
CNT > CCR4
Output mode OC4 REF TIM1_CCER
CNT = CCR4 controller
CC4E TIM1_CCER
The capture/compare block is made of one preload register and one shadow register. Write
and read always access the preload register.
In capture mode, captures are actually done in the shadow register, which is copied into the
preload register.
In compare mode, the content of the preload register is copied into the shadow register
which is compared to the counter.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
• Select the active input: TIMx_CCR1 must be linked to the TI1 input, so write the CC1S
bits to 01 in the TIMx_CCMR1 register. As soon as CC1S becomes different from 00,
the channel is configured in input and the TIMx_CCR1 register becomes read-only.
• Program the input filter duration you need with respect to the signal you connect to the
timer (by programming ICxF bits in the TIMx_CCMRx register if the input is a TIx input).
Let’s imagine that, when toggling, the input signal is not stable during at must 5 internal
clock cycles. We must program a filter duration longer than these 5 clock cycles. We
can validate a transition on TI1 when 8 consecutive samples with the new level have
been detected (sampled at fDTS frequency). Then write IC1F bits to 0011 in the
TIMx_CCMR1 register.
• Select the edge of the active transition on the TI1 channel by writing CC1P and CC1NP
bits to 0 in the TIMx_CCER register (rising edge in this case).
• Program the input prescaler. In our example, we wish the capture to be performed at
each valid transition, so the prescaler is disabled (write IC1PS bits to ‘00’ in the
TIMx_CCMR1 register).
• Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
• If needed, enable the related interrupt request by setting the CC1IE bit in the
TIMx_DIER register, and/or the DMA request by setting the CC1DE bit in the
TIMx_DIER register.
When an input capture occurs:
• The TIMx_CCR1 register gets the value of the counter on the active transition.
• CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
• An interrupt is generated depending on the CC1IE bit.
• A DMA request is generated depending on the CC1DE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt and/or DMA requests can be generated by software by setting the
corresponding CCxG bit in the TIMx_EGR register.
For example, you can measure the period (in TIMx_CCR1 register) and the duty cycle (in
TIMx_CCR2 register) of the PWM applied on TI1 using the following procedure (depending
on CK_INT frequency and prescaler value):
• Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (TI1 selected).
• Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): write the CC1P and CC1NP bits to ‘0’ (active on rising edge).
• Select the active input for TIMx_CCR2: write the CC2S bits to 10 in the TIMx_CCMR1
register (TI1 selected).
• Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P
and CC2NP bits to ‘1’ (active on falling edge).
• Select the valid trigger input: write the TS bits to 101 in the TIMx_SMCR register
(TI1FP1 selected).
• Configure the slave mode controller in reset mode: write the SMS bits to 100 in the
TIMx_SMCR register.
• Enable the captures: write the CC1E and CC2E bits to ‘1’ in the TIMx_CCER register.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still
performed and allows the flag to be set. Interrupt and DMA requests can be sent
accordingly. This is described in the output compare mode section below.
oc1ref=OC1
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
• Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Section :
Downcounting mode on page 244
In PWM mode 1, the reference signal OCxRef is low as long as
TIMx_CNT > TIMx_CCRx else it becomes high. If the compare value in TIMx_CCRx is
greater than the auto-reload value in TIMx_ARR, then OCxREF is held at ‘1’. 0% PWM
is not possible in this mode.
#OUNTER REGISTER
/#X2%&
##2X
##X)& #-3
#-3
#-3
/#X2%&
##2X
#-3 OR
##X)&
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
AIB
OCxREF
OCx
delay
OCxN
delay
Figure 74. Dead-time waveforms with delay greater than the negative pulse.
OCxREF
OCx
delay
OCxN
Figure 75. Dead-time waveforms with delay greater than the positive pulse.
OCxREF
OCx
OCxN
delay
The dead-time delay is the same for each of the channels and is programmable with the
DTG bits in the TIMx_BDTR register. Refer to Section 12.4.18: TIM1 break and dead-time
register (TIMx_BDTR) on page 300 for delay calculation.
must insert a delay (dummy instruction) before reading it correctly. This is because you write
the asynchronous signal and read the synchronous signal.
When a break occurs (selected level on the break input):
• The MOE bit is cleared asynchronously, putting the outputs in inactive state, idle state
or in reset state (selected by the OSSI bit). This feature functions even if the MCU
oscillator is off.
• Each output channel is driven with the level programmed in the OISx bit in the
TIMx_CR2 register as soon as MOE=0. If OSSI=0 then the timer releases the enable
output else the enable output remains high.
• When complementary outputs are used:
– The outputs are first put in reset state inactive state (depending on the polarity).
This is done asynchronously so that it works even if no clock is provided to the
timer.
– If the timer clock is still present, then the dead-time generator is reactivated in
order to drive the outputs with the level programmed in the OISx and OISxN bits
after a dead-time. Even in this case, OCx and OCxN cannot be driven to their
active level together. Note that because of the resynchronization on MOE, the
dead-time duration is a bit longer than usual (around 2 ck_tim clock cycles).
– If OSSI=0 then the timer releases the enable outputs else the enable outputs
remain or become high as soon as one of the CCxE or CCxNE bits is high.
• The break status flag (BIF bit in the TIMx_SR register) is set. An interrupt can be
generated if the BIE bit in the TIMx_DIER register is set. A DMA request can be sent if
the BDE bit in the TIMx_DIER register is set.
• If the AOE bit in the TIMx_BDTR register is set, the MOE bit is automatically set again
at the next update event UEV. This can be used to perform a regulation, for instance.
Else, MOE remains low until you write it to ‘1’ again. In this case, it can be used for
security and you can connect the break input to an alarm from power drivers, thermal
sensors or any security components.
Note: The break inputs is acting on level. Thus, the MOE cannot be set while the break input is
active (neither automatically nor by software). In the meantime, the status flag BIF cannot
be cleared.
The break can be generated by the BRK input which has a programmable polarity and an
enable bit BKE in the TIMx_BDTR Register.
There are two solutions to generate a break:
• By using the BRK input which has a programmable polarity and an enable bit BKE in
the TIMx_BDTR register
• By software through the BG bit of the TIMx_EGR register.
In addition to the break input and the output management, a write protection has been
implemented inside the break circuit to safeguard the application. It allows you to freeze the
configuration of several parameters (dead-time duration, OCx/OCxN polarities and state
when disabled, OCxM configurations, break enable and polarity). You can choose from 3
levels of protection selected by the LOCK bits in the TIMx_BDTR register. Refer to
Section 12.4.18: TIM1 break and dead-time register (TIMx_BDTR) on page 300. The LOCK
bits can be written only once after an MCU reset.
Figure 76 shows an example of behavior of the outputs in response to a break.
OCxREF
OCx
(OCxN not implemented, CCxP=0, OISx=1)
OCx
(OCxN not implemented, CCxP=0, OISx=0)
OCx
(OCxN not implemented, CCxP=1, OISx=1)
OCx
(OCxN not implemented, CCxP=1, OISx=0)
OCx
OCx
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=0, CCxNE=0, CCxNP=0, OISxN=1)
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=1, CCxNE=0, CCxNP=0, OISxN=0)
OCx
OCxN
(CCxE=1, CCxP=0, CCxNE=0, CCxNP=0, OISx=OISxN=0 or OISx=OISxN=1)
(CCRx)
counter (CNT)
ETRF
OCxREF
(OCxCE=’0’)
OCxREF
(OCxCE=’1’)
ETRF ETRF
becomes high still high
Note: In case of a PWM with a 100% duty cycle (if CCRx>ARR), then OCxREF is enabled again at
the next counter overflow.
OCxREF
Write COM to 1
COM event
CCxE=1 write OCxM to 100 CCxE=1
CCxNE=0 CCxNE=0
OCxM=100 (forced inactive) OCxM=100
OCx
Example 1
OCxN
Write CCxNE to 1
and OCxM to 101 CCxE=0
CCxE=1 CCxNE=1
CCxNE=0 OCxM=101
OCx OCxM=100 (forced inactive)
Example 2
OCxN
write CCxNE to 0
CCxE=1
and OCxM to 100 CCxE=1
CCxNE=0 CCxNE=0
OCxM=100 (forced inactive) OCxM=100
OCx
Example 3
OCxN
ai14910
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY t
tPULSE
For example you may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
Let’s use TI2FP2 as trigger 1:
• Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
• TI2FP2 must detect a rising edge, write CC2P=’0’ and CC2NP=’0’ in the TIMx_CCER
register.
• Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=’110’ in
the TIMx_SMCR register.
• TI2FP2 is used to start the counter by writing SMS to ‘110’ in the TIMx_SMCR register
(trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the
clock frequency and the counter prescaler).
• The tDELAY is defined by the value written in the TIMx_CCR1 register.
• The tPULSE is defined by the difference between the auto-reload value and the compare
value (TIMx_ARR - TIMx_CCR1).
• Let’s say you want to build a waveform with a transition from ‘0’ to ‘1’ when a compare
match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload
value. To do this you enable PWM mode 2 by writing OC1M=111 in the TIMx_CCMR1
register. You can optionally enable the preload registers by writing OC1PE=’1’ in the
TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this case you have to
write the compare value in the TIMx_CCR1 register, the auto-reload value in the
TIMx_ARR register, generate an update by setting the UG bit and wait for external
trigger event on TI2. CC1P is written to ‘0’ in this example.
In our example, the DIR and CMS bits in the TIMx_CR1 register should be low.
You only want 1 pulse (Single mode), so you write '1 in the OPM bit in the TIMx_CR1
register to stop the counter at the next update event (when the counter rolls over from the
auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0', so the
Repetitive Mode is selected.
Particular case: OCx fast enable:
In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the
counter. Then the comparison between the counter and the compare value makes the
output toggle. But several clock cycles are needed for these operations and it limits the
minimum delay tDELAY min we can get.
If you want to output a waveform with the minimum delay, you can set the OCxFE bit in the
TIMx_CCMRx register. Then OCxRef (and OCx) are forced in response to the stimulus,
without taking in account the comparison. Its new level is the same as if a compare match
had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.
configure TIMx_ARR before starting. in the same way, the capture, compare, prescaler,
repetition counter, trigger output features continue to work as normal. Encoder mode and
External clock mode 2 are not compatible and must not be selected together.
In this mode, the counter is modified automatically following the speed and the direction of
the incremental encoder and its content, therefore, always represents the encoder’s
position. The count direction correspond to the rotation direction of the connected sensor.
The table summarizes the possible combinations, assuming TI1 and TI2 don’t switch at the
same time.
An external incremental encoder can be connected directly to the MCU without external
interface logic. However, comparators are normally be used to convert the encoder’s
differential outputs to digital signals. This greatly increases noise immunity. The third
encoder output which indicate the mechanical zero position, may be connected to an
external interrupt input and trigger a counter reset.
Figure 80 gives an example of counter operation, showing count signal generation and
direction control. It also shows how input jitter is compensated where both edges are
selected. This might occur if the sensor is positioned near to one of the switching points. For
this example we assume that the configuration is the following:
• CC1S=’01’ (TIMx_CCMR1 register, TI1FP1 mapped on TI1).
• CC2S=’01’ (TIMx_CCMR2 register, TI1FP2 mapped on TI2).
• CC1P=’0’, CC1NP=’0’, and IC1F = ‘0000’ (TIMx_CCER register, TI1FP1 non-inverted,
TI1FP1=TI1).
• CC2P=’0’, CC2NP=’0’, and IC2F = ‘0000’ (TIMx_CCER register, TI1FP2 non-inverted,
TI1FP2= TI2).
• SMS=’011’ (TIMx_SMCR register, both inputs are active on both rising and falling
edges).
• CEN=’1’ (TIMx_CR1 register, Counter enabled).
TI1
TI2
Counter
up down up
Figure 81 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=’1’).
Figure 81. Example of encoder interface mode with TI1FP1 polarity inverted.
forward jitter backward jitter forward
TI1
TI2
Counter
down up down
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. You can obtain dynamic information (speed, acceleration, deceleration) by
measuring the period between two encoder events using a second timer configured in
capture mode. The output of the encoder which indicates the mechanical zero can be used
for this purpose. Depending on the time between two events, the counter can also be read
at regular times. You can do this by latching the counter value into a third input capture
register if available (then the capture signal must be periodic and can be generated by
another timer). when available, it is also possible to read its value through a DMA request
generated by a real-time clock.
written after a COM event for the next step (this can be done in an interrupt subroutine
generated by the rising edge of OC2REF).
Figure 82 describes this example.
7,+
7,+
,QWHUIDFLQJWLPHU
7,+
&RXQWHU &17
&&5
75*2 2&5()
&20
2&
$GYDQFHGFRQWUROWLPHUV 7,0
2&1
2&
2&1
2&
2&1
:ULWH&&[(&&[1(
DQG2&[0IRUQH[WVWHS
069
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
TI1
CNT_EN
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
TI2
CNT_EN
Counter register 34 35 36 37 38
TIF
TI1
CEN/CNT_EN
ETR
Counter register 34 35 36
TIF
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CKD[1:0] ARPE CMS[1:0] DIR OPM URS UDIS CEN
Reserved
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
OIS4 OIS3N OIS3 OIS2N OIS2 OIS1N OIS1 TI1S MMS[2:0] CCDS CCUS CCPC
Res. Res.
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
ETP ECE ETPS[1:0] ETF[3:0] MSM TS[2:0] Res. SMS[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw Res. rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OC2 OC2 OC2 OC1 OC1 OC1
OC2M[2:0] OC1M[2:0]
CE PE FE CC2S[1:0] CE PE FE CC1S[1:0]
IC2F[3:0] IC2PSC[1:0] IC1F[3:0] IC1PSC[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Table 50. Output control bits for complementary OCx and OCxN channels with
break feature
Control bits Output states(1)
MOE OSSI OSSR CCxE CCxNE
OCx output state OCxN output state
bit bit bit bit bit
Output Disabled (not driven by Output Disabled (not driven by the
0 0 0 the timer) timer)
OCx=0, OCx_EN=0 OCxN=0, OCxN_EN=0
Output Disabled (not driven by
OCxREF + Polarity OCxN=OCxREF
0 0 1 the timer)
xor CCxNP, OCxN_EN=1
OCx=0, OCx_EN=0
OCxREF + Polarity Output Disabled (not driven by the
0 1 0 OCx=OCxREF xor CCxP, timer)
OCx_EN=1 OCxN=0, OCxN_EN=0
Complementary to OCREF (not
OCREF + Polarity + dead-time
0 1 1 OCREF) + Polarity + dead-time
OCx_EN=1
OCxN_EN=1
1 X
Output Disabled (not driven by Output Disabled (not driven by the
1 0 0 the timer) timer)
OCx=CCxP, OCx_EN=0 OCxN=CCxNP, OCxN_EN=0
Off-State (output enabled with OCxREF + Polarity
1 0 1 inactive state) OCxN=OCxREF xor CCxNP,
OCx=CCxP, OCx_EN=1 OCxN_EN=1
OCxREF + Polarity Off-State (output enabled with
1 1 0 OCx=OCxREF xor CCxP, inactive state)
OCx_EN=1 OCxN=CCxNP, OCxN_EN=1
Complementary to OCREF (not
OCREF + Polarity + dead-time
1 1 1 OCREF) + Polarity + dead-time
OCx_EN=1
OCxN_EN=1
Output Disabled (not driven by Output Disabled (not driven by the
0 0 0 the timer) timer)
OCx=CCxP, OCx_EN=0 OCxN=CCxNP, OCxN_EN=0
0 0 1 Output Disabled (not driven by the timer)
0 1 0 Asynchronously: OCx=CCxP, OCx_EN=0, OCxN=CCxNP,
OCxN_EN=0
Then if the clock is present: OCx=OISx and OCxN=OISxN after a
0 1 1 dead-time, assuming that OISx and OISxN do not correspond to OCX
and OCxN both in active state.
0 X
Output Disabled (not driven by Output Disabled (not driven by the
1 0 0 the timer) timer)
OCx=CCxP, OCx_EN=0 OCxN=CCxNP, OCxN_EN=0
1 0 1 Off-State (output enabled with inactive state)
1 1 0 Asynchronously: OCx=CCxP, OCx_EN=1, OCxN=CCxNP,
OCxN_EN=1
Then if the clock is present: OCx=OISx and OCxN=OISxN after a
1 1 1 dead-time, assuming that OISx and OISxN do not correspond to OCX
and OCxN both in active state
1. When both outputs of a channel are not used (CCxE = CCxNE = 0), the OISx, OISxN, CCxP and CCxNP bits must be kept
cleared.
Note: The state of the external I/O pins connected to the complementary OCx and OCxN channels
depends on the OCx and OCxN channel state and the GPIO registers.
Note: As the bits AOE, BKP, BKE, OSSI, OSSR and DTG[7:0] can be write-locked depending on
the LOCK configuration, it can be necessary to configure all of them during the first write
access to the TIMx_BDTR register.
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ARPE
CKD CMS
UDIS
OPM
CEN
URS
DIR
TIMx_CR1
0x00 Reserved [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0
OIS3N
OIS2N
OIS1N
Reserved
CCPC
CCDS
CCUS
OIS4
OIS3
OIS2
OIS1
TI1S
TIMx_CR2 MMS[2:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CC3IE Reserved
ETPS
MSM
ECE
ETP
TIMx_SMCR ETF[3:0] TS[2:0] SMS[2:0]
0x08 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COMDE
CC4DE
CC3DE
CC2DE
CC1DE
COMIE
CC4IE
CC2IE
CC1IE
UDE
TDE
UIE
BIE
TIE
TIMx_DIER
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CC4OF
CC3OF
CC2OF
CC1OF
COMIF
Reserved
CC4IF
CC3IF
CC2IF
CC1IF
UIF
BIF
TIF
TIMx_SR
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
COMG
CC4G
CC3G
CC2G
CC1G
UG
TIMx_EGR
BG
TG
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0
TIMx_CCMR1
OC2CE
OC1CE
OC2PE
OC1PE
OC2FE
OC1FE
OC2M CC2S OC1M CC1S
Output Compare [2:0] [1:0] [2:0] [1:0]
Reserved
mode
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 IC1
CC2S CC1S
Input Capture IC2F[3:0] PSC IC1F[3:0] PSC
Reserved [1:0] [1:0]
mode [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCMR2
OC3CE
OC4PE
OC3PE
OC4FE
OC3FE
O24CE
CC2NP
CC2NE
CC1NP
CC1NE
CC4P
CC4E
CC3P
CC3E
CC2P
CC2E
CC1P
CC1E
TIMx_CCER
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_RCR REP[7:0]
0x30 Reserved
Reset value 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
TIMx_CCR1 CCR1[15:0]
0x34 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR2 CCR2[15:0]
0x38 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR3 CCR3[15:0]
0x3C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR4 CCR4[15:0]
0x40 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OSSR
LOCK
OSSI
MOE
AOE
BKP
BKE
TIMx_BDTR DT[7:0]
0x44 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_DMAR DMAB[15:0]
0x4C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4)&0 (QFRGHU
4)&0 ,QWHUIDFH
5 $XWRUHORDGUHJLVWHU 5)
6WRSFOHDURUXSGRZQ
5
&.B36& &.B&17
36& &17
3UHVFDOHU FRXQWHU
##) ##)
4) 4)&0
;25
,QSXWILOWHU
)# )#03 5 /#2%& OUTPUT /#
4)&0 3UHVFDOHU &DSWXUHFRPSDUHUHJLVWHU 7,0[B&+
HGJHGHWHFWRU FRQWURO
7,0[B&+ 42#
##)
##)
4)&0 )# )#03 5
4) OUTPUT /#
7,0[B&+
7,0[B&+ ,QSXWILOWHU
HGJHGHWHFWRU 4)&0 3UHVFDOHU &DSWXUHFRPSDUHUHJLVWHU /#2%&
FRQWURO
42#
##)
##)
4)&0 )# 5 /#
)#03 OUTPUT
7,0[B&+
4) ,QSXWILOWHU
HGJHGHWHFWRU
4)&0 3UHVFDOHU &DSWXUHFRPSDUHUHJLVWHU
/#2%& 7,0[B&+
FRQWURO
42#
##)
##)
4)&0 )# 5
4) )#03 /#2%& OUTPUT /#
7,0[B&+ ,QSXWILOWHU
HGJHGHWHFWRU 4)&0 3UHVFDOHU &DSWXUHFRPSDUHUHJLVWHU
FRQWURO
7,0[B&+
42#
(75)
.OTES
2EG 0RELOAD REGISTERS TRANSFERRED
TO ACTIVE REGISTERS ON 5 EVENT
ACCORDING TO CONTROL BIT
EVENT
069
The auto-reload register is preloaded. Writing to or reading from the auto-reload register
accesses the preload register. The content of the preload register are transferred into the
shadow register permanently or at each update event (UEV), depending on the auto-reload
preload enable bit (ARPE) in TIMx_CR1 register. The update event is sent when the counter
reaches the overflow (or underflow when downcounting) and if the UDIS bit equals 0 in the
TIMx_CR1 register. It can also be generated by software. The generation of the update
event is described in detail for each configuration.
The counter is clocked by the prescaler output CK_CNT, which is enabled only when the
counter enable bit (CEN) in TIMx_CR1 register is set (refer also to the slave mode controller
description to get more details on counter enabling).
Note that the actual counter enable signal CNT_EN is set 1 clock cycle after CEN.
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit/32-bit register (in the TIMx_PSC
register). It can be changed on the fly as this control register is buffered. The new prescaler
ratio is taken into account at the next update event.
Figure 88 and Figure 89 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 88. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CNT_EN
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
Figure 89. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CNT_EN
Counter register F7 F8 F9 FA FB FC 00 01
Prescaler buffer 0 3
Prescaler counter 0 0 1 2 3 0 1 2 3
CK_INT
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_INT
CNT_EN
Counter overflow
CK_INT
CNT_EN
Counter overflow
CK_INT
Counter register 1F 20 00
Counter overflow
Figure 94. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_INT
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
Figure 95. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CNT_EN
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Downcounting mode
In downcounting mode, the counter counts from the auto-reload value (content of the
TIMx_ARR register) down to 0, then restarts from the auto-reload value and generates a
counter underflow event.
An Update event can be generate at each counter underflow or by setting the UG bit in the
TIMx_EGR register (by software or by using the slave mode controller)
The UEV update event can be disabled by software by setting the UDIS bit in TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until UDIS bit has been written to 0.
However, the counter restarts from the current auto-reload value, whereas the counter of the
prescaler restarts from 0 (but the prescale rate doesn’t change).
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that the auto-reload is updated before the counter is
reloaded, so that the next period is the expected one.
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_INT
CNT_EN
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
CK_INT
CNT_EN
Counter underflow
CK_INT
CNT_EN
Counter underflow
CK_INT
Counter register 20 1F 00 36
Counter underflow
CK_INT
CNT_EN
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload register FF 36
The UEV update event can be disabled by software by setting the UDIS bit in TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until the UDIS bit has been written to 0.
However, the counter continues counting up and down, based on the current auto-reload
value.
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupt when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that if the update source is a counter overflow, the auto-
reload is updated before the counter is reloaded, so that the next period is the expected
one (the counter is loaded with the new value).
The following figures show some examples of the counter behavior for different clock
frequencies.
CK_INT
CNT_EN
Counter register 04 03 02 01 00 01 02 03 04 05 06 05 04 03
Counter underflow
Counter overflow
1. Here, center-aligned mode 1 is used (for more details refer to Section 13.4.1: TIMx control register 1 (TIMx_CR1)
on page 342).
CK_INT
CNT_EN
Counter underflow
CK_INT
CNT_EN
CK_INT
Counter register 20 1F 01 00
Counter underflow
Figure 105. Counter timing diagram, Update event with ARPE=1 (counter underflow)
CK_INT
CNT_EN
Counter register 06 05 04 03 02 01 00 01 02 03 04 05 06 07
Counter underflow
Figure 106. Counter timing diagram, Update event with ARPE=1 (counter overflow)
CK_INT
CNT_EN
Counter register F7 F8 F9 FA FB FC 36 35 34 33 32 31 30 2F
Counter overflow
CK_INT
CEN=CNT_EN
UG
CNT_INIT
COUNTER REGISTER 31 32 33 34 35 36 00 01 02 03 04 05 06 07
TI2F or
or
TI1F or encoder
ITRx 001 mode
TI1F_ED 100
TI1FP1 101 TRGI external clock
TI2F_Rising
mode 1 CK_PSC
0
TI2 Filter Edge TI2FP2 110
Detector TI2F_Falling ETRF external clock
1 ETRF 111 mode 2
ICF[3:0] CC2P CK_INT internal clock
TIMx_CCMR1 TIMx_CCER mode
(internal clock)
ECE SMS[2:0]
TIMx_SMCR
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S= ‘01 in the
TIMx_CCMR1 register.
2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=0000).
Note: The capture prescaler is not used for triggering, so you don’t need to configure it.
3. Select rising edge polarity by writing CC2P=0 and CC2NP=0 in the TIMx_CCER
register.
4. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
5. Select TI2 as the input source by writing TS=110 in the TIMx_SMCR register.
6. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
TI2F or
or
TI1F or encoder
mode
For example, to configure the upcounter to count each 2 rising edges on ETR, use the
following procedure:
CK_INT
CNT_EN
ETR
ETRP
ETRF
Counter register 34 35 36
TI1F_ED
to the slave mode controller
TI1F_Rising
TI1 TI1F
filter Edge TI1FP1
01
fDTS downcounter Detector TI1F_Falling
TI2FP1 IC1 divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
controller)
TI2F_rising
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_falling
(from channel 2) TIMx_CCMR1 TIMx_CCER
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
(if 16-bit)
8 8
high
low
S write CCR1H
read CCR1H S write_in_progress
read_in_progress
Capture/Compare Preload Register write CCR1L
read CCR1L R
R CC1S[1]
output
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] input
mode OC1PE
Capture/Compare Shadow Register OC1PE
CC1S[0] UEV
TIMx_CCMR1
comparator (from time
IC1PS capture base unit)
CC1E CNT>CCR1
Counter
CNT=CCR1
CC1G
TIMx_EGR
KZ&ͺ>Z
Ϭ
KZ&ͺ>Zͺ/Ed
dZ& ϭ
dŽƚŚĞŵĂƐƚĞƌŵŽĚĞ Ϭ
ĐŽŶƚƌŽůůĞƌ KƵƚƉƵƚ Kϭ
K^ ŶĂďůĞ
ϭ ŝƌĐƵŝƚ
d/Ddžͺ^DZ
ϭW
EdхZϭ
KƵƚƉƵƚŵŽĚĞ ŽĐϭƌĞĨ d/DdžͺZ
EdсZϭ ĐŽŶƚƌŽůůĞƌ
ϭ
KϭDϮ͗Ϭ d/DdžͺZ
d/DdžͺDZϭ Ăŝϭϳϭϴϳ
The capture/compare block is made of one preload register and one shadow register. Write
and read always access the preload register.
In capture mode, captures are actually done in the shadow register, which is copied into the
preload register.
In compare mode, the content of the preload register is copied into the shadow register
which is compared to the counter.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
The TIMx_CCRx register can be updated at any time by software to control the output
waveform, provided that the preload register is not enabled (OCxPE=0, else TIMx_CCRx
shadow register is updated only at the next update event UEV). An example is given in
Figure 116.
OC1REF=OC1
Upcounting configuration
Upcounting is active when the DIR bit in the TIMx_CR1 register is low. Refer to Section :
Upcounting mode on page 309.
In the following example, we consider PWM mode 1. The reference PWM signal OCxREF is
high as long as TIMx_CNT <TIMx_CCRx else it becomes low. If the compare value in
TIMx_CCRx is greater than the auto-reload value (in TIMx_ARR) then OCxREF is held at ‘1.
If the compare value is 0 then OCxREF is held at ‘0. Figure 117 shows some edge-aligned
PWM waveforms in an example where TIMx_ARR=8.
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCxREF
CCRx=4
CCxIF
OCxREF
CCRx=8
CCxIF
OCxREF ‘1
CCRx>8
CCxIF
OCxREF ‘0
CCRx=0
CCxIF
Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Section :
Downcounting mode on page 312.
In PWM mode 1, the reference signal ocxref is low as long as TIMx_CNT>TIMx_CCRx else
it becomes high. If the compare value in TIMx_CCRx is greater than the auto-reload value in
TIMx_ARR, then ocxref is held at ‘1. 0% PWM is not possible in this mode.
#OUNTER REGISTER
/#X2%&
##2X
##X)& #-3
#-3
#-3
/#X2%&
##2X
#-3 OR
##X)&
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
AIB
in the TIMx_CR1 register. Moreover, the DIR and CMS bits must not be changed at the
same time by the software.
• Writing to the counter while running in center-aligned mode is not recommended as it
can lead to unexpected results. In particular:
– The direction is not updated if you write a value in the counter that is greater than
the auto-reload value (TIMx_CNT>TIMx_ARR). For example, if the counter was
counting up, it continues to count up.
– The direction is updated if you write 0 or write the TIMx_ARR value in the counter
but no Update Event UEV is generated.
• The safest way to use center-aligned mode is to generate an update by software
(setting the UG bit in the TIMx_EGR register) just before starting the counter and not to
write the counter while it is running.
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY
tPULSE t
For example you may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
1. The external trigger prescaler should be kept off: bits ETPS[1:0] in the TIMx_SMCR
register are cleared to 00.
2. The external clock mode 2 must be disabled: bit ECE in the TIM1_SMCR register is
cleared to 0.
3. The external trigger polarity (ETP) and the external trigger filter (ETF) can be
configured according to the application’s needs.
Figure 120 shows the behavior of the OCxREF signal when the ETRF input becomes high,
for both values of the OCxCE enable bit. In this example, the timer TIMx is programmed in
PWM mode.
(CCRx)
counter (CNT)
ETRF
OCxREF
(OCxCE=0)
OCxREF
(OCxCE=1)
ETRF ETRF
becomes high still high
1. In case of a PWM with a 100% duty cycle (if CCRx>ARR), OCxREF is enabled again at the next counter
overflow.
In this mode, the counter is modified automatically following the speed and the direction of
the incremental encoder and its content, therefore, always represents the encoder’s
position. The count direction correspond to the rotation direction of the connected sensor.
The table summarizes the possible combinations, assuming TI1 and TI2 don’t switch at the
same time.
An external incremental encoder can be connected directly to the MCU without external
interface logic. However, comparators are normally be used to convert the encoder’s
differential outputs to digital signals. This greatly increases noise immunity. The third
encoder output which indicate the mechanical zero position, may be connected to an
external interrupt input and trigger a counter reset.
Figure 121 gives an example of counter operation, showing count signal generation and
direction control. It also shows how input jitter is compensated where both edges are
selected. This might occur if the sensor is positioned near to one of the switching points. For
this example we assume that the configuration is the following:
• CC1S= ‘01’ (TIMx_CCMR1 register, TI1FP1 mapped on TI1)
• CC2S= ‘01’ (TIMx_CCMR2 register, TI2FP2 mapped on TI2)
• CC1P= ‘0’, CC1NP = ‘0’, IC1F =’0000’ (TIMx_CCER register, TI1FP1 noninverted,
TI1FP1=TI1)
• CC2P= ‘0’, CC2NP = ‘0’, IC2F =’0000’ (TIMx_CCER register, TI2FP2 noninverted,
TI2FP2=TI2)
• SMS= ‘011’ (TIMx_SMCR register, both inputs are active on both rising and falling
edges)
• CEN = 1 (TIMx_CR1 register, Counter is enabled)
TI1
TI2
Counter
up down up
Figure 122 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=1).
Figure 122. Example of encoder interface mode with TI1FP1 polarity inverted
forward jitter backward jitter forward
TI1
TI2
Counter
down up down
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. You can obtain dynamic information (speed, acceleration, deceleration) by
measuring the period between two encoder events using a second timer configured in
capture mode. The output of the encoder which indicates the mechanical zero can be used
for this purpose. Depending on the time between two events, the counter can also be read
at regular times. You can do this by latching the counter value into a third input capture
register if available (then the capture signal must be periodic and can be generated by
another timer). when available, it is also possible to read its value through a DMA request
generated by a Real-Time clock.
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
In the following example, the upcounter counts only when TI1 input is low:
• Configure the channel 1 to detect low levels on TI1. Configure the input filter duration
(in this example, we don’t need any filter, so we keep IC1F=0000). The capture
prescaler is not used for triggering, so you don’t need to configure it. The CC1S bits
select the input capture source only, CC1S=01 in TIMx_CCMR1 register. Write
CC1P=1 in TIMx_CCER register to validate the polarity (and detect low level only).
• Configure the timer in gated mode by writing SMS=101 in TIMx_SMCR register. Select
TI1 as the input source by writing TS=101 in TIMx_SMCR register.
• Enable the counter by writing CEN=1 in the TIMx_CR1 register (in gated mode, the
counter doesn’t start if CEN=0, whatever is the trigger input level).
The counter starts counting on the internal clock as long as TI1 is low and stops as soon as
TI1 becomes high. The TIF flag in the TIMx_SR register is set both when the counter starts
or stops.
The delay between the rising edge on TI1 and the actual stop of the counter is due to the
resynchronization circuit on TI1 input.
TI1
CNT_EN
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
1. The configuration “CCxP=CCxNP=1” (detection of both rising and falling edges) does not have any effect
in gated mode because gated mode acts on a level and not on an edge.
TI2
CNT_EN
Counter register 34 35 36 37 38
TIF
TI1
CEN/CNT_EN
ETR
Counter register 34 35 36
TIF
TIM1 TIM2
Input
trigger
selection
For example, you can configure Timer 1 to act as a prescaler for Timer 2. Refer to
Figure 127. To do this:
• Configure Timer 1 in master mode so that it outputs a periodic trigger signal on each
update event UEV. If you write MMS=010 in the TIM1_CR2 register, a rising edge is
output on TRGO1 each time an update event is generated.
• To connect the TRGO1 output of Timer 1 to Timer 2, Timer 2 must be configured in
slave mode using ITR0 as internal trigger. You select this through the TS bits in the
TIM2_SMCR register (writing TS=000).
• Then you put the slave mode controller in external clock mode 1 (write SMS=111 in the
TIM2_SMCR register). This causes Timer 2 to be clocked by the rising edge of the
periodic Timer 1 trigger signal (which correspond to the timer 1 counter overflow).
• Finally both timers must be enabled by setting their respective CEN bits (TIMx_CR1
register).
Note: If OCx is selected on Timer 1 as trigger output (MMS=1xx), its rising edge is used to clock
the counter of timer 2.
CK_INT
TIMER1-OC1REF
TIMER1-CNT FC FD FE FF 00 01
TIMER 2-TIF
Write TIF=0
In the example in Figure 162, the Timer 2 counter and prescaler are not initialized before
being started. So they start counting from their current value. It is possible to start from a
given value by resetting both timers before starting Timer 1. You can then write any value
you want in the timer counters. The timers can easily be reset by software using the UG bit
in the TIMx_EGR registers.
In the next example, we synchronize Timer 1 and Timer 2. Timer 1 is the master and starts
from 0. Timer 2 is the slave and starts from 0xE7. The prescaler ratio is the same for both
timers. Timer 2 stops when Timer 1 is disabled by writing ‘0 to the CEN bit in the TIM1_CR1
register:
• Configure Timer 1 master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIM1_CR2 register).
• Configure the Timer 1 OC1REF waveform (TIM1_CCMR1 register).
• Configure Timer 2 to get the input trigger from Timer 1 (TS=000 in the TIM2_SMCR
register).
• Configure Timer 2 in gated mode (SMS=101 in TIM2_SMCR register).
• Reset Timer 1 by writing ‘1 in UG bit (TIM1_EGR register).
• Reset Timer 2 by writing ‘1 in UG bit (TIM2_EGR register).
• Initialize Timer 2 to 0xE7 by writing ‘0xE7’ in the timer 2 counter (TIM2_CNTL).
• Enable Timer 2 by writing ‘1 in the CEN bit (TIM2_CR1 register).
• Start Timer 1 by writing ‘1 in the CEN bit (TIM1_CR1 register).
• Stop Timer 1 by writing ‘0 in the CEN bit (TIM1_CR1 register).
CK_INT
TIMER1-CEN=CNT_EN
TIMER1-CNT_INIT
TIMER1-CNT 75 00 01 02
TIMER2-CNT AB 00 E7 E8 E9
TIMER2-CNT_INIT
TIMER2
write CNT
TIMER 2-TIF
Write TIF=0
CK_INT
TIMER1-UEV
TIMER1-CNT FD FE FF 00 01 02
TIMER2-CNT 45 46 47 48
TIMER2-CEN=CNT_EN
TIMER 2-TIF
Write TIF=0
As in the previous example, you can initialize both counters before starting counting.
Figure 131 shows the behavior with the same configuration as in Figure 162 but in trigger
mode instead of gated mode (SMS=110 in the TIM2_SMCR register).
CK_INT
TIMER1-CEN=CNT_EN
TIMER1-CNT_INIT
TIMER1-CNT 75 00 01 02
TIMER2-CNT CD 00 E7 E8 E9 EA
TIMER2-CNT_INIT
TIMER2
write CNT
TIMER 2-TIF
Write TIF=0
CK_INT
TIMER 1-TI1
TIMER1-CEN=CNT_EN
TIMER 1-CK_PSC
TIMER1-CNT 00 01 02 03 04 05 06 07 08 09
TIMER1-TIF
TIMER2-CEN=CNT_EN
TIMER 2-CK_PSC
TIMER2-CNT 00 01 02 03 04 05 06 07 08 09
TIMER2-TIF
Note: The state of the external IO pins connected to the standard OCx channels depends on the
OCx channel state and the GPIO registers.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR1[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:16 CCR1[31:16]: High Capture/Compare 1 value (on TIM2 and TIM5).
Bits 15:0 CCR1[15:0]: Low Capture/Compare 1 value
If channel CC1 is configured as output:
CCR1 is the value to be loaded in the actual capture/compare 1 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR1 register
(bit OC1PE). Else the preload value is copied in the active capture/compare 1 register when
an update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signaled on OC1 output.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR2[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:16 CCR2[31:16]: High Capture/Compare 2 value (on TIM2 and TIM5).
Bits 15:0 CCR2[15:0]: Low Capture/Compare 2 value
If channel CC2 is configured as output:
CCR2 is the value to be loaded in the actual capture/compare 2 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR register (bit
OC2PE). Else the preload value is copied in the active capture/compare 2 register when an
update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signalled on OC2 output.
If channel CC2 is configured as input:
CCR2 is the counter value transferred by the last input capture 2 event (IC2).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR3[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:16 CCR3[31:16]: High Capture/Compare 3 value (on TIM2 and TIM5).
Bits 15:0 CCR3[15:0]: Low Capture/Compare value
If channel CC3 is configured as output:
CCR3 is the value to be loaded in the actual capture/compare 3 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR register (bit
OC3PE). Else the preload value is copied in the active capture/compare 3 register when an
update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signaled on OC3 output.
If channel CC3 is configured as input:
CCR3 is the counter value transferred by the last input capture 3 event (IC3).
Bits 31:16 CCR4[31:16]: High Capture/Compare 4 value (on TIM2 and TIM5).
Bits 15:0 CCR4[15:0]: Low Capture/Compare value
1. if CC4 channel is configured as output (CC4S bits):
CCR4 is the value to be loaded in the actual capture/compare 4 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR register
(bit OC4PE). Else the preload value is copied in the active capture/compare 4 register
when an update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signalled on OC4 output.
2. if CC4 channel is configured as input (CC4S bits in TIMx_CCMR4 register):
CCR4 is the counter value transferred by the last input capture 4 event (IC4).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ITR1_RMP
Reserved Reserved
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TI4_RMP
Reserved Reserved
rw rw
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ARPE
UDIS
CKD CMS
OPM
CEN
URS
DIR
TIMx_CR1
[1:0] [1:0]
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
CCDS
TI1S
TIMx_CR2 MMS[2:0]
0x04 Reserved Reserved
Reset value 0 0 0 0 0
ETPS
MSM
Reserved
ECE
ETP
TIMx_SMCR ETF[3:0] TS[2:0] SMS[2:0]
[1:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COMDE
CC4DE
CC3DE
CC2DE
CC1DE
CC4IE
CC3IE
CC2IE
CC1IE
Reserved
Reserved
UDE
TDE
UIE
TIE
TIMx_DIER
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
CC4OF
CC3OF
CC2OF
CC1OF
CC4IF
CC3IF
CC2IF
CC1IF
Reserved
Reserved
UIF
TIF
TIMx_SR
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
CC4G
CC3G
CC2G
CC1G
Reserved
UG
TG
TIMx_EGR
0x14 Reserved
Reset value 0 0 0 0 0 0
TIMx_CCMR1
OC2CE
OC1CE
OC2PE
OC1PE
OC2FE
OC1FE
OC2M CC2S OC1M CC1S
Output Compare
[2:0] [1:0] [2:0] [1:0]
mode Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 IC1
CC2S CC1S
Input Capture IC2F[3:0] PSC IC1F[3:0] PSC
Reserved [1:0] [1:0]
mode [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCMR2
OC3CE
OC4PE
OC3PE
OC4FE
OC3FE
O24CE
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x1C
TIMx_CCMR2 IC4 IC3
CC4S CC3S
Input Capture IC4F[3:0] PSC IC3F[3:0] PSC
[1:0] [1:0]
mode Reserved [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reserved
Reserved
Reserved
Reserved
CC4NP
CC3NP
CC2NP
CC1NP
CC4P
CC4E
CC3P
CC3E
CC2P
CC2E
CC1P
CC1E
TIMx_CCER
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
CNT[31:16]
TIMx_CNT CNT[15:0]
0x24 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 55. TIM2 to TIM5 register map and reset values (continued)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ARR[31:16]
TIMx_ARR ARR[15:0]
0x2C (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x30 Reserved
CCR1[31:16]
TIMx_CCR1 CCR1[15:0]
0x34 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CCR2[31:16]
TIMx_CCR2 CCR2[15:0]
0x38 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CCR3[31:16]
TIMx_CCR3 CCR3[15:0]
0x3C (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CCR4[31:16]
TIMx_CCR4 CCR4[15:0]
0x40 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x44 Reserved
TIMx_DMAR DMAB[15:0]
0x4C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ITR1_
TIM2_OR
0x50 RMP
Reserved Reserved Reserved
Reset value 0 0
IT4_
TIM5_OR
0x50 RMP
Reserved Reserved Reserved
Reset value 0 0
ITR0
Trigger
ITR1 TGI controller
ITR
ITR2 TRC TRGI
ITR3 Slave
Reset, Enable, Count
mode
TI1F_ED controller
TI1FP1
TI2FP2
U Auto-reload register UI
Stop, Clear
U
CK_PSC PSC CK_CNT CNT
+/-
Prescaler COUNTER
CC1I CC1I
TI1 TI1FP1
Input filter &
IC1 IC1PS U OC1REF output OC1
TIMx_CH1 TI1FP2 Prescaler Capture/Compare 1 register TIMx_CH1
Edge detector control
TRC
CC2I
CC2I
TI2FP1 IC2 IC2PS U
TI2 Input filter & OC2REF output OC2
TIMx_CH2
TIMx_CH2 TI2FP2 Prescaler Capture/Compare 2 register
Edge detector control
TRC
Notes:
Reg Preload registers transferred
to active registers on U event
according to control bit
event
interrupt
ai17190
5 !UTORELOAD REGISTER 5)
3TOP #LEAR
5
#+?03# 03# #+?#.4 #.4
PRESCALER COUNTER
##) ##)
4) 4)&0 )# 5
)NPUT FILTER )#03 /#2%& OUTPUT /#
4)-X?#( 0RESCALER #APTURE#OMPARE REGISTER 4)-X?#(
EDGE DETECTOR CONTROL
.OTES
EVENT
AIC
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit register (in the TIMx_PSC register).
It can be changed on the fly as this control register is buffered. The new prescaler ratio is
taken into account at the next update event.
Figure 135 and Figure 136 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 135. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
Figure 136. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 00 01
Prescaler buffer 0 3
Prescaler counter 0 0 1 2 3 0 1 2 3
setting the UIF flag (thus no interrupt is sent). This is to avoid generating both update and
capture interrupts when clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The auto-reload shadow register is updated with the preload value (TIMx_ARR),
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
Counter register 1F 20 00
Counter overflow
Figure 141. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
Figure 142. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
TI2F or
or
TI1F or
ITRx 0xx
TI1_ED
100
TI1FP1 101 TRGI external clock
TI2F_Rising 0
mode 1 CK_PSC
TI2 Filter Edge TI2FP2 110
Detector TI2F_Falling
1
CK_INT internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
SMS[2:0]
TIMx_SMCR
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in
the TIMx_CCMR1 register.
2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=’0000’).
3. Select the rising edge polarity by writing CC2P=’0’ and CC2NP=’0’ in the TIMx_CCER
register.
4. Configure the timer in external clock mode 1 by writing SMS=’111’ in the TIMx_SMCR
register.
5. Select TI2 as the trigger input source by writing TS=’110’ in the TIMx_SMCR register.
6. Enable the counter by writing CEN=’1’ in the TIMx_CR1 register.
Note: The capture prescaler is not used for triggering, so you don’t need to configure it.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
TI1F_ED
to the slave mode controller
TI1F_Rising 0
TI1 TI1F
filter Edge TI1FP1
01
fDTS downcounter Detector TI1F_Falling
1
TI2FP1 IC1 divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
controller)
TI2F_rising 0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
(if 16-bit)
8 8
high
low
S write CCR1H
read CCR1H S write_in_progress
read_in_progress
Capture/compare preload register write CCR1L
read CCR1L R
R CC1S[1]
output
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] input
mode OC1PE
Capture/compare shadow register OC1PE
CC1S[0] UEV
TIM1_CCMR1
comparator (from time
IC1PS capture base unit)
CC1E CNT>CCR1
Counter
CNT=CCR1
CC1G
TIM1_EGR
##0
#.4 ##2
/UTPUT MODE /#?2%& 4)-X?##%2
#.4 ##2 CONTROLLER
##% 4)-X?##%2
/#-;=
4)-X?##-2
AI
The capture/compare block is made of one preload register and one shadow register. Write
and read always access the preload register.
In capture mode, captures are actually done in the shadow register, which is copied into the
preload register.
In compare mode, the content of the preload register is copied into the shadow register
which is compared to the counter.
cleared by software by writing it to ‘0’ or by reading the captured data stored in the
TIMx_CCRx register. CCxOF is cleared when you write it to ‘0’.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
1. Select the active input: TIMx_CCR1 must be linked to the TI1 input, so write the CC1S
bits to ‘01’ in the TIMx_CCMR1 register. As soon as CC1S becomes different from ‘00’,
the channel is configured in input mode and the TIMx_CCR1 register becomes read-
only.
2. Program the input filter duration you need with respect to the signal you connect to the
timer (by programming the ICxF bits in the TIMx_CCMRx register if the input is one of
the TIx inputs). Let’s imagine that, when toggling, the input signal is not stable during at
must 5 internal clock cycles. We must program a filter duration longer than these 5
clock cycles. We can validate a transition on TI1 when 8 consecutive samples with the
new level have been detected (sampled at fDTS frequency). Then write IC1F bits to
‘0011’ in the TIMx_CCMR1 register.
3. Select the edge of the active transition on the TI1 channel by programming CC1P and
CC1NP bits to ‘00’ in the TIMx_CCER register (rising edge in this case).
4. Program the input prescaler. In our example, we wish the capture to be performed at
each valid transition, so the prescaler is disabled (write IC1PS bits to ‘00’ in the
TIMx_CCMR1 register).
5. Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
6. If needed, enable the related interrupt request by setting the CC1IE bit in the
TIMx_DIER register.
When an input capture occurs:
• The TIMx_CCR1 register gets the value of the counter on the active transition.
• CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
• An interrupt is generated depending on the CC1IE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt requests can be generated by software by setting the corresponding CCxG bit in
the TIMx_EGR register.
1. Select the active input for TIMx_CCR1: write the CC1S bits to ‘01’ in the TIMx_CCMR1
register (TI1 selected).
2. Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): program the CC1P and CC1NP bits to ‘00’ (active on rising edge).
3. Select the active input for TIMx_CCR2: write the CC2S bits to ‘10’ in the TIMx_CCMR1
register (TI1 selected).
4. Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): program the
CC2P and CC2NP bits to ‘11’ (active on falling edge).
5. Select the valid trigger input: write the TS bits to ‘101’ in the TIMx_SMCR register
(TI1FP1 selected).
6. Configure the slave mode controller in reset mode: write the SMS bits to ‘100’ in the
TIMx_SMCR register.
7. Enable the captures: write the CC1E and CC2E bits to ‘1’ in the TIMx_CCER register.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
1. The PWM input mode can be used only with the TIMx_CH1/TIMx_CH2 signals due to the fact that only
TI1FP1 and TI2FP2 are connected to the slave mode controller.
oc1ref=OC1
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF
CCRx>8
CCxIF
OCXREF
CCRx=0
CCxIF
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY
tPULSE t
For example you may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
Use TI2FP2 as trigger 1:
1. Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
2. TI2FP2 must detect a rising edge, write CC2P=’0’ and CC2NP = ‘0’ in the TIMx_CCER
register.
3. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=’110’ in
the TIMx_SMCR register.
4. TI2FP2 is used to start the counter by writing SMS to ‘110’ in the TIMx_SMCR register
(trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the
clock frequency and the counter prescaler).
• The tDELAY is defined by the value written in the TIMx_CCR1 register.
• The tPULSE is defined by the difference between the auto-reload value and the compare
value (TIMx_ARR - TIMx_CCR1).
• Let’s say you want to build a waveform with a transition from ‘0’ to ‘1’ when a compare
match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload
value. To do this you enable PWM mode 2 by writing OC1M=’111’ in the TIMx_CCMR1
register. You can optionally enable the preload registers by writing OC1PE=’1’ in the
TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this case you have to
write the compare value in the TIMx_CCR1 register, the auto-reload value in the
TIMx_ARR register, generate an update by setting the UG bit and wait for external
trigger event on TI2. CC1P is written to ‘0’ in this example.
You only want 1 pulse (Single mode), so you write '1 in the OPM bit in the TIMx_CR1
register to stop the counter at the next update event (when the counter rolls over from the
auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0', so the
Repetitive Mode is selected.
Particular case: OCx fast enable
In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the
counter. Then the comparison between the counter and the compare value makes the
output toggle. But several clock cycles are needed for these operations and it limits the
minimum delay tDELAY min we can get.
If you want to output a waveform with the minimum delay, you can set the OCxFE bit in the
TIMx_CCMRx register. Then OCxRef (and OCx) are forced in response to the stimulus,
without taking in account the comparison. Its new level is the same as if a compare match
had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
The counter starts counting on the internal clock as long as TI1 is low and stops as soon as
TI1 becomes high. The TIF flag in the TIMx_SR register is set both when the counter starts
or stops.
The delay between the rising edge on TI1 and the actual stop of the counter is due to the
resynchronization circuit on TI1 input.
TI1
cnt_en
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
TI2
cnt_en
Counter register 34 35 36 37 38
TIF
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSM TS[2:0] SMS[2:0]
Reserved Res.
rw rw rw rw rw rw rw
Note: The states of the external I/O pins connected to the standard OCx channels depend on the
state of the OCx channel and on the GPIO registers.
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ARPE
UDIS
CKD
OPM
URS
CEN
TIMx_CR1
[1:0]
0x00 Reserved Reserved
Reset value 0 0 0 0 0 0 0
MSM
Reserved
TIMx_SMCR TS[2:0] SMS[2:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0
CC2IE
CC1IE
UIE
TIE
TIMx_DIER
0x0C Reserved Reserved
Reset value 0 0 0 0
CC2OF
CC1OF
CC2IF
CC1IF
Reserved
UIF
TIF
TIMx_SR
0x10 Reserved Reserved
Reset value 0 0 0 0 0 0
CC2G
CC1G
UG
TG
TIMx_EGR
0x14 Reserved Reserved
Reset value 0 0 0 0
TIMx_CCMR1 CC1
OC2PE
OC1PE
OC2FE
OC1FE
OC2M CC2S OC1M
Reserved
Output Compare S
[2:0] [1:0] [2:0]
mode Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 IC1 CC1
CC2S
Input Capture IC2F[3:0] PSC IC1F[3:0] PSC S
Reserved [1:0]
mode [1:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x1C Reserved
CC2NP
CC1NP
CC2P
CC2E
CC1P
CC1E
Reserved
Reserved
TIMx_CCER
0x20 Reserved
Reset value 0 0 0 0 0 0
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x30 Reserved
TIMx_CCR1 CCR1[15:0]
0x34 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
TIMx_CCR2 CCR2[15:0]
0x38 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x3C to
Reserved
0x4C
Note: The state of the external I/O pins connected to the standard OCx channels depends on the
OCx channel state and the GPIO registers.
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ARPE
UDIS
CKD
URS
CEN
TIMx_CR1
[1:0]
0x00 Reserved Reserved
Reset value 0 0 0 0 0 0
TIMx_SMCR
0x08 Reserved
Reset value
CC1IE
UIE
TIMx_DIER
0x0C Reserved
Reset value 0 0
CC1OF
CC1IF
UIF
TIMx_SR
0x10 Reserved Reserved
Reset value 0 0 0
CC1G
UG
TIMx_EGR
0x14 Reserved
Reset value 0 0
TIMx_CCMR1
OC1PE
OC1FE
OC1M CC1S
Output compare [2:0] [1:0]
mode Reserved
Reset value 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC1
CC1S
Input capture IC1F[3:0] PSC
Reserved [1:0]
mode [1:0]
Reset value 0 0 0 0 0 0 0 0
0x1C Reserved
CC1NP
CC1P
CC1E
Reserved
TIMx_CCER
0x20 Reserved
Reset value 0 0 0
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x30 Reserved
TIMx_CCR1 CCR1[15:0]
0x34 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x38 to
Reserved
0x4C
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
TI1_RMP
TIMx_OR
0x50 Reserved
Reset value 0 0
A status register is available to indicate that an update of the prescaler or the down-counter
reload value is on going.
#/2%
0RESCALER REGISTER 3TATUS REGISTER 2ELOAD REGISTER +EY REGISTER
)7$'?02 )7$'?32 )7$'?2,2 )7$'?+2
-36
Note: The watchdog function is implemented in the VDD voltage domain that is still functional in
Stop and Standby modes.
/4 0 0.125 512
/8 1 0.25 1024
/16 2 0.5 2048
/32 3 1 4096
/64 4 2 8192
/128 5 4 16384
/256 6 32768
1. These timings are given for a 32 kHz clock but the microcontroller’s internal RC frequency can vary from 30
to 60 kHz. Moreover, given an exact RC oscillator frequency, the exact timings still depend on the phasing
of the APB interface clock versus the LSI clock so that there is always a full RC period of uncertainty.
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
RVU PVU
Reserved
r r
Note: If several reload values or prescaler values are used by application, it is mandatory to wait
until RVU bit is reset before changing the reload value and to wait until PVU bit is reset
before changing the prescaler value. However, after updating the prescaler and/or the
reload value it is not necessary to wait until RVU or PVU is reset before continuing code
execution (even in case of low-power mode entry, the write operation is taken into account
and will complete)
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
IWDG_KR KEY[15:0]
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
IWDG_PR PR[2:0]
0x04 Reserved
Reset value 0 0 0
IWDG_RLR RL[11:0]
0x08 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1
RVU
PVU
IWDG_SR
0x0C Reserved
Reset value 0 0
- W6 W5 W4 W3 W2 W1 W0
comparator
= 1 when
T6:0 > W6:0 CMP
Write WWDG_CR
Watchdog control register (WWDG_CR)
WDGA T6 T5 T4 T3 T2 T1 T0
6-bit downcounter (CNT)
PCLK1
(from RCC clock controller)
WDG prescaler
(WDGTB)
The application program must write in the WWDG_CR register at regular intervals during
normal operation to prevent an MCU reset. This operation must occur only when the counter
value is lower than the window register value. The value to be stored in the WWDG_CR
register must be between 0xFF and 0xC0:
case, the corresponding interrupt service routine (ISR) should reload the WWDG counter to
avoid the WWDG reset, then trigger the required actions.
The EWI interrupt is cleared by writing '0' to the EWIF bit in the WWDG_SR register.
Note: When the EWI interrupt cannot be served, e.g. due to a system lock in a higher priority task,
the WWDG reset will eventually be generated.
7;=
X&
4IME
2EFRESH NOT ALLOWED 2EFRESH ALLOWED
4 BIT
2%3%4
AIB
where:
tWWDG: WWDG timeout
tPCLK1: APB1 clock period measured in ms
Refer to the table below for the minimum and maximum values of the TWWDG.
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
WDGA T[6:0]
Reserved
rs rw
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
WDGTB[1:0]
EWI W[6:0]
Reserved
rs rw rw
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
EWIF
Reserved
rc_w0
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
WDGA
WWDG_CR T[6:0]
0x00 Reserved
Reset value 0 1 1 1 1 1 1 1
WDGTB1
WDGTB0
EWI
WWDG_CFR W[6:0]
0x04 Reserved
Reset value 0 0 0 1 1 1 1 1 1 1
EWIF
WWDG_SR
0x08 Reserved
Reset value 0
17.1 Introduction
The real-time clock (RTC) is an independent BCD timer/counter. The RTC provides a time-
of-day clock/calendar, two programmable alarm interrupts, and a periodic programmable
wakeup flag with interrupt capability. The RTC also includes an automatic wakeup unit to
manage low power modes.
Two 32-bit registers contain the seconds, minutes, hours (12- or 24-hour format), day (day
of week), date (day of month), month, and year, expressed in binary coded decimal format
(BCD). The sub-seconds value is also available in binary format
Compensations for 28-, 29- (leap year), 30-, and 31-day months are performed
automatically. Daylight saving time compensation can also be performed.
Additional 32-bit registers contain the programmable alarm subseconds, seconds, minutes,
hours, day, and date.
A digital calibration feature is available to compensate for any deviation in crystal oscillator
accuracy.
After backup domain reset, all RTC registers are protected against possible parasitic write
accesses.
As long as the supply voltage remains in the operating range, the RTC never stops,
regardless of the device status (Run mode, low power mode or under reset).
57&B76
7LPHVWDPS 76)
+] UHJLVWH UV
+]
57&B&$/,%
FNBDSUH 2XWSXW 57&B287
57&&/. GHIDXOW+] FRQWURO
57&B$)
$ODUP$
57&B$/50$5
57&B35(5 &RDUVH 57&B35(5 57&B$/50$665
FN VSUH UHJLVWHUV $/5$)
$V\Q FK &DOLEUDWLRQ 6\Q FKURQRXV GHIDXOW+]
ELWSUHVFDOHU 57&B&$/,%5 ELWSUHVFDOHU
GHIDXOW GHIDXOW &DOHQGDU
57&B$/$50
6KDGRZUHJLVWHUV
6KDGRZUHJLVWHU
/6( +] 57&B75
57&B665
6PRRWK 57&B'5
+6(B57& FDOLEUDWLRQ
0+]PD[ 57&B&$/5
/6,
$ODUP%
$/5%)
:8&.6(/>@ 57&B$/50%5
57&B$/50%665
3UHVFDOHU UHJLVWHUV
57&B:875
:87)
ELWZDNHXS
DXWRUHORDGWLPHU
%DFNXSDQG
57&B7$03
57&WDPSHU
FRQWUROUHJLVWHUV
7$03(
76(
069
The ck_apre clock is used to clock the binary RTC_SSR subseconds downcounter. When it
reaches 0, RTC_SSR is reloaded with the content of PREDIV_S.
fck_spre is given by the following formula:
f RTCCLK
f CK_SPRE = -----------------------------------------------------------------------------------------------
( PREDIV_S + 1 ) × ( PREDIV_A + 1 )
The ck_spre clock can be used either to update the calendar or as timebase for the 16-bit
wakeup auto-reload timer. To obtain short timeout periods, the 16-bit wakeup auto-reload
timer can also run with the RTCCLK divided by the programmable 4-bit asynchronous
prescaler (see Section 17.3.4: Periodic auto-wakeup for details).
Every two RTCCLK periods, the current calendar value is copied into the shadow registers,
and the RSF bit of RTC_ISR register is set (see Section 17.6.4). The copy is not performed
in Stop and Standby mode. When exiting these modes, the shadow registers are updated
after up to 2 RTCCLK periods.
When the application reads the calendar registers, it accesses the content of the shadow
registers. It is possible to make a direct access to the calendar registers by setting the
BYPSHAD control bit in the RTC_CR register. By default, this bit is cleared, and the user
accesses the shadow registers.
When reading the RTC_SSR, RTC_TR or RTC_DR registers in BYPSHAD=0 mode, the
frequency of the APB clock (fAPB) must be at least 7 times the frequency of the RTC clock
(fRTCCLK).
The shadow registers are reset by system reset.
complete (see Programming the wakeup timer on page 428), the timer starts
counting down.When the wakeup function is enabled, the down-counting remains
active in low power modes. In addition, when it reaches 0, the WUTF flag is set in
the RTC_ISR register, and the wakeup counter is automatically reloaded with its
reload value (RTC_WUTR register value).
The WUTF flag must then be cleared by software.
When the periodic wakeup interrupt is enabled by setting the WUTIE bit in the RTC_CR2
register, it can exit the device from low power modes.
The periodic wakeup flag can be routed to the RTC_ALARM output provided it has been
enabled through bits OSEL[1:0] of RTC_CR register. RTC_ALARMpolarity can be
configured through the POL bit in the RTC_CR register.
System reset, as well as low power modes (Sleep, Stop and Standby) have no influence on
the wakeup timer.
factor. Even if only one of the two fields needs to be changed, 2 separate write
accesses must be performed to the RTC_PRER register.
4. Load the initial time and date values in the shadow registers (RTC_TR and RTC_DR),
and configure the time format (12 or 24 hours) through the FMT bit in the RTC_CR
register.
5. Exit the initialization mode by clearing the INIT bit. The actual calendar counter value is
then automatically loaded and the counting restarts after 4 RTCCLK clock cycles.
When the initialization sequence is complete, the calendar starts counting.
Note: After a system reset, the application can read the INITS flag in the RTC_ISR register to
check if the calendar has been initialized or not. If this flag equals 0, the calendar has not
been initialized since the year field is set at its backup domain reset default value (0x00).
To read the calendar after initialization, the software must first check that the RSF flag is set
in the RTC_ISR register.
When the BYPSHAD control bit is set in the RTC_CR register (bypass shadow
registers)
Reading the calendar registers gives the values from the calendar counters directly, thus
eliminating the need to wait for the RSF bit to be set. This is especially useful after exiting
from low power modes (STOP or Standby), since the shadow registers are not updated
during these modes.
When the BYPSHAD bit is set to 1, the results of the different registers might not be
coherent with each other if an RTCCLK edge occurs between two read accesses to the
registers. Additionally, the value of one of the registers may be incorrect if an RTCCLK edge
occurs during the read operation. The software must read all the registers twice, and then
compare the results to confirm that the data is coherent and correct. Alternatively, the
software can just compare the two results of the least-significant calendar register.
Note: While BYPSHAD=1, instructions which read the calendar registers require one extra APB
cycle to complete.
When positive calibration is enabled (DCS = ‘0’), 2 ck_apre cycles are added every minute
(around 15360 ck_apre cycles) for 2xDC minutes. This causes the calendar to be updated
sooner, thereby adjusting the effective RTC frequency to be a bit higher.
When negative calibration is enabled (DCS = ‘1’), 1 ck_apre cycle is removed every minute
(around 15360 ck_apre cycles) for 2xDC minutes. This causes the calendar to be updated
later, thereby adjusting the effective RTC frequency to be a bit lower.
DC is configured through bits DC[4:0] of RTC_CALIBR register. This number ranges from 0
to 31 corresponding to a time interval (2xDC) ranging from 0 to 62.
The coarse digital calibration can be configured only in initialization mode, and starts when
the INIT bit is cleared. The full calibration cycle lasts 64 minutes. The first 2xDC minutes of
the 64 -minute cycle are modified as just described.
Negative calibration can be performed with a resolution of about 2 ppm while positive
calibration can be performed with a resolution of about 4 ppm. The maximum calibration
ranges from −63 ppm to 126 ppm.
The calibration can be performed either on the LSE or on the HSE clock.
Caution: Digital calibration may not work correctly if PREDIV_A < 6.
The smooth calibration register (RTC_CALR) specifies the number of RTCCLK clock cycles
to be masked during the 32-second cycle:
• Setting the bit CALM[0] to 1 causes exactly one pulse to be masked during the 32-
second cycle.
• Setting CALM[1] to 1 causes two additional cycles to be masked
• Setting CALM[2] to 1 causes four additional cycles to be masked
• and so on up to CALM[8] set to 1 which causes 256 clocks to be masked.
Note: CALM[8:0] (RTC_CALRx) specifies the number of RTCCLK pulses to be masked during the
32-second cycle. Setting the bit CALM[0] to ‘1’ causes exactly one pulse to be masked
during the 32-second cycle at the moment when cal_cnt[19:0] is 0x80000; CALM[1]=1
causes two other cycles to be masked (when cal_cnt is 0x40000 and 0xC0000); CALM[2]=1
causes four other cycles to be masked (cal_cnt = 0x20000/0x60000/0xA0000/ 0xE0000);
and so on up to CALM[8]=1 which causes 256 clocks to be masked (cal_cnt = 0xXX800).
While CALM allows the RTC frequency to be reduced by up to 487.1 ppm with fine
resolution, the bit CALP can be used to increase the frequency by 488.5 ppm. Setting CALP
to ‘1’ effectively inserts an extra RTCCLK pulse every 211 RTCCLK cycles, which means
that 512 clocks are added during every 32-second cycle.
Using CALM together with CALP, an offset ranging from -511 to +512 RTCCLK cycles can
be added during the 32-second cycle, which translates to a calibration range of -487.1 ppm
to +488.5 ppm with a resolution of about 0.954 ppm.
The formula to calculate the effective calibrated frequency (FCAL) given the input frequency
(FRTCCLK) is as follows:
FCAL = FRTCCLK x [1 + (CALP x 512 - CALM) / (220 + CALM - CALP x 512)]
Re-calibration on-the-fly
The calibration register (RTC_CALR) can be updated on-the-fly while RTC_ISR/INITF=0, by
using the follow process:
1. Poll the RTC_ISR/RECALPF (re-calibration pending flag).
2. If it is set to 0, write a new value to RTC_CALR, if necessary. RECALPF is then
automatically set to 1
3. Within three ck_apre cycles after the write operation to RTC_CALR, the new calibration
settings take effect.
Note: TSF is set 2 ck_apre cycles after the timestamp event occurs due to synchronization
process.
There is no delay in the setting of TSOVF. This means that if two timestamp events are
close together, TSOVF can be seen as '1' while TSF is still '0'. As a consequence, it is
recommended to poll TSOVF only after TSF has been set.
Caution: If a timestamp event occurs immediately after the TSF bit is supposed to be cleared, then
both TSF and TSOVF bits are set. To avoid masking a timestamp event occurring at the
same moment, the application must not write ‘0’ into TSF bit unless it has already read it to
‘1’.
Optionally, a tamper event can cause a timestamp to be recorded. See the description of the
TAMPTS control bit in Section 17.6.17: RTC tamper and alternate function configuration
register (RTC_TAFCR). If the timestamp event is on the same pin as a tamper event
configured in filtered mode (TAMPFLT set to a non-zero value), the timestamp on tamper
detection event mode must be selected by setting TAMPTS='1' in RTC_TAFCR register.
depending on the corresponding TAMPxTRG bit. The internal pull-up resistors on the
TAMPER input are deactivated when edge detection is selected.
Caution: To avoid losing tamper detection events, the signal used for edge detection is logically
ANDed with TAMPxE in order to detect a tamper detection event in case it occurs before the
TAMPERx pin is enabled.
• When TAMPxTRG = 0: if the TAMPERx additional function is already high before
tamper detection is enabled (TAMPxE bit set to 1), a tamper event is detected as soon
as TAMPERx is enabled, even if there was no rising edge on TAMPERx after TAMPxE
was set.
• When TAMPxTRG = 1: if the TAMPERx additional function is already low before
tamper detection is enabled, a tamper event is detected as soon as TAMPERx is
enabled (even if there was no falling edge on TAMPERx after TAMPxE was set.
After a tamper event has been detected and cleared, the TAMPERx additional function
should be disabled and then re-enabled (TAMPxE set to 1) before re-programming the
backup registers (RTC_BKPxR). This prevents the application from writing to the backup
registers while the TAMPERx value still indicates a tamper detection. This is equivalent to a
level detection on the TAMPERx additional function.
Note: Tamper detection is still active when VDD power is switched off. To avoid unwanted resetting
of the backup registers, the pin to which the TAMPER additional function is mapped should
be externally tied to the correct level.
No effect
Sleep
RTC interrupts cause the device to exit the Sleep mode.
The RTC remains active when the RTC clock source is LSE or LSI. RTC alarm, RTC
Stop tamper event, RTC time stamp event, and RTC Wakeup cause the device to exit the Stop
mode.
The RTC remains active when the RTC clock source is LSE or LSI. RTC alarm, RTC
Standby tamper event, RTC time stamp event, and RTC Wakeup cause the device to exit the
Standby mode.
1. Configure and enable the EXTI Line 17 in interrupt mode and select the rising edge
sensitivity.
2. Configure and enable the RTC_Alarm IRQ channel in the NVIC.
3. Configure the RTC to generate RTC alarms (Alarm A or Alarm B).
To enable the RTC Wakeup interrupt, the following sequence is required:
1. Configure and enable the EXTI Line 22 in interrupt mode and select the rising edge
sensitivity.
2. Configure and enable the RTC_WKUP IRQ channel in the NVIC.
3. Configure the RTC to generate the RTC wakeup timer event.
To enable the RTC Tamper interrupt, the following sequence is required:
1. Configure and enable the EXTI Line 21 in interrupt mode and select the rising edge
sensitivity.
2. Configure and Enable the TAMP_STAMP IRQ channel in the NVIC.
3. Configure the RTC to detect the RTC tamper event.
To enable the RTC TimeStamp interrupt, the following sequence is required:
1. Configure and enable the EXTI Line 21 in interrupt mode and select the rising edge
sensitivity.
2. Configure and Enable the TAMP_STAMP IRQ channel in the NVIC.
3. Configure the RTC to detect the RTC timestamp event.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PM HT[1:0] HU[3:0]
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
Res. Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
YT[3:0] YU[3:0]
Reserved
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WDU[2:0] MT MU[3:0] DT[1:0] DU[3:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
COE OSEL[1:0] POL BKP SUB1H ADD1H
Reserved
rw rw rw rw rw rw w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BYPS
TSIE WUTIE ALRBIE ALRAIE TSE WUTE ALRBE ALRAE DCE FMT REFCKON TSEDGE WUCKSEL[2:0]
HAD
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: WUT = Wakeup unit counter value. WUT = (0x0000 to 0xFFFF) + 0x10000 added when
WUCKSEL[2:1 = 11].
Bits 7, 6 and 4 of this register can be written in initialization mode only (RTC_ISR/INITF = 1).
Bits 2 to 0 of this register can be written only when RTC_CR WUTE bit = 0 and RTC_ISR
WUTWF bit = 1.
It is recommended not to change the hour during the calendar hour increment as it could
mask the incrementation of the calendar hour.
ADD1H and SUB1H changes are effective in the next second.
This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RECAL
PF
Reserved
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP WUT ALRB ALRA
Res. Res. TSOVF TSF WUTF ALRBF ALRAF INIT INITF RSF INITS SHPF
1F WF WF WF
rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rw r rc_w0 r r r r r
Note: The ALRAF, ALRBF, WUTF and TSF bits are cleared 2 APB clock cycles after programming
them to 0.
This register is write protected (except for RTC_ISR[13:8] bits). The write access procedure
is described in RTC register write protection on page 427.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PREDIV_A[6:0]
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PREDIV_S[14:0]
Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register must be written in initialization mode only. The initialization must be performed
in two separate write accesses. Refer to Calendar initialization and configuration on
page 427
This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
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
WUT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register can be written only when WUTWF is set to 1 in RTC_ISR.
This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
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
DCS DC[4:0]
Reserved Reserved
rw rw rw rw rw rw
Note: This register can be written in initialization mode only (RTC_ISR/INITF = ‘1’).
This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MSK4 WDSEL DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[3:0]
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
MSK2 MNT[2:0] MNU[3:0] MSK1 ST[2:0] SU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register can be written only when ALRAWF is set to 1 in RTC_ISR, or in initialization
mode.
This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MSK4 WDSEL DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[3:0]
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
MSK2 MNT[2:0] MNU[3:0] MSK1 ST[2:0] SU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register can be written only when ALRBWF is set to 1 in RTC_ISR, or in initialization
mode.
This register is write protected. The write access procedure is described in RTC register
write protection on page 427.
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
KEY
Reserved
w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SS[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADD1S Reserved
w r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. SUBFS[14:0]
r w w w w w w w w w w w w w w w
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 427
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PM HT[1:0] HU[3:0]
Reserved
r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
Res. Res.
r r r r r r r r r r r r r r
Note: The content of this register is valid only when TSF is set to 1 in RTC_ISR. It is cleared when
TSF bit is reset.
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
WDU[1:0] MT MU[3:0] DT[1:0] DU[3:0]
Reserved
r r r r r r r r r r r r r r
Note: The content of this register is valid only when TSF is set to 1 in RTC_ISR. It is cleared when
TSF bit is reset.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SS[15:0]
r r r r r r r r r r r r r r r r
Note: The content of this register is valid only when RTC_ISR/TSF is set. It is cleared when the
RTC_ISR/TSF bit is reset.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CALP CALW8 CALW16 Reserved CALM[8:0]
rw rw rw r r r r rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 427
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ALARMOUT TSIN TAMP1
Reserved TYPE SEL INSEL
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP- TAMP- TAMPT TAMP1 TAMP1
TAMPFLT[1:0] TAMPFREQ[2:0] TAMPIE
PUDIS PRCH[1:0] S Reserved TRG E
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved MASKSS[3:0] Reserved
r r r r rw rw rw rw r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved SS[14:0]
r rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
Note: This register can be written only when ALRAE is reset in RTC_CR register, or in initialization
mode.
This register is write protected. The write access procedure is described in RTC register
write protection on page 427
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved MASKSS[3:0] Reserved
r r r r rw rw rw rw r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved SS[14:0]
r rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
Note: This register can be written only when ALRBIE is reset in RTC_CR register, or in
initialization mode.
This register is write protected.The write access procedure is described in Section : RTC
register write protection
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BKP[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
BKP[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
HT
Reserved
Reserved
PM
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DT
Reserved
MT
Reset value 0 0 1 0 0 0 0 1 0 0 0 0 0 1
REFCKON
BYPSHAD
TSEDGE
ALRBIE
ALRAIE
COSEL
ADD1H
SUB1H
ALRBE
ALRAE
WUTIE
WUTE
OSEL WCKSEL
TSIE
COE
DCE
FMT
POL
BKP
TSE
RTC_CR
0x08 Reserved [1:0] [2:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ALRBWF
ALRAWF
TAMP1F
WUTWF
TSOVF
ALRBF
ALRAF
WUTF
SHPF
INITS
INITF
RSF
TSF
INIT
RTC_ISR
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 1 0 1
Reserved
RTC_WUTR WUT[15:0]
0x14 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
Reserved
DCS
RTC_CALIBR DC[4:0]
0x18 Reserved
Reset value 0 0 0 0 0 0
WDSEL
MSK4
MSK3
MSK2
MSK1
DT HT
PM
RTC_ALRMAR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
0x1C [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
WDSEL
MSK4
MSK3
MSK2
MSK2
DT HT
PM
RTC_ALRMBR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
0x20 [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_WPR KEY[7:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0
RTC_SSR SS[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MNT[2:0]
HT[1:0]
Reserved
Reserved
PM
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_TSSSR SS[15:0]
0x38 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CALW16
CALW8
CALP
Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ALARMOUTTYPE
TAMPPRCH[1:0]
TAMPFREQ[2:0]
TAMPFLT[1:0]
TAMP1INSEL
TAMP1ETRG
TAMPPUDIS
TSINSEL
TAMPTS
TAMP1E
TAMPIE
Reserved
RTC_TAFCR
0x40 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_
MASKSS[3:0] SS[14:0]
ALRMASSR
0x44 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_
MASKSS[3:0] SS[14:0]
ALRMBSSR
0x48 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
RTC_BKP0R BKP[31:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Note: Some of the above features may not be available in certain products. The user should refer
to the product data sheet, to identify the specific features supported by the I2C interface
implementation.
Communication flow
In Master mode, the I2C interface 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 software.
In Slave mode, the interface is capable of recognizing its own addresses (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 160.
SDA
MSB ACK
SCL
1 2 8 9
Start Stop
condition condition
Acknowledge may be enabled or disabled by software. The I2C interface addresses (dual
addressing 7-bit/ 10-bit and/or general call address) can be selected by software.
$ATA REGISTER
.OISE $ATA
3$! $ATA SHIFT REGISTER
FILTER CONTROL
#LOCK CONTROL
2EGISTER ##2
#ONTROL REGISTERS
#2#2
#ONTROL
3TATUS REGISTERS LOGIC
3232
3-"!
1. SMBA is an optional signal in SMBus mode. This signal is not applicable if SMBus is disabled.
Note: In 10-bit addressing mode, the comparison includes the header sequence (11110xx0),
where xx denotes the two most significant bits of the address.
Header or address not matched: the interface ignores it and waits for another Start
condition.
Header matched (10-bit mode only): the interface generates an acknowledge pulse if the
ACK bit is set and waits for the 8-bit slave address.
Address matched: the interface generates in sequence:
• An acknowledge pulse if the ACK bit is set
• The ADDR bit is set by hardware and an interrupt is generated if the ITEVFEN bit is
set.
• If ENDUAL=1, the software has to read the DUALF bit to check which slave address
has been acknowledged.
In 10-bit mode, after receiving the address sequence the slave is always in Receiver mode.
It will enter Transmitter mode on receiving a repeated Start condition followed by the header
sequence with matching address bits and the least significant bit set (11110xx1).
The TRA bit indicates whether the slave is in Receiver or Transmitter mode.
Slave transmitter
Following the address reception and after clearing ADDR, the slave sends bytes from the
DR register to the SDA line via the internal shift register.
The slave stretches SCL low until ADDR is cleared and DR filled with the data to be sent
(see Figure 162 Transfer sequencing EV1 EV3).
When the acknowledge pulse is received:
• The TxE bit is set by hardware with an interrupt if the ITEVFEN and the ITBUFEN bits
are set.
If TxE is set and some data were not written in the I2C_DR register before the end of the
next data transmission, the BTF bit is set and the interface waits until BTF is cleared by a
read to I2C_SR1 followed by a write to the I2C_DR register, stretching SCL low.
ai18209
1. The EV1 and EV3_1 events stretch SCL low until the end of the corresponding software sequence.
2. The EV3 event stretches SCL low if the software sequence is not completed before the end of the next byte
transmission
Slave receiver
Following the address reception and after clearing ADDR, the slave receives bytes from the
SDA line into the DR register via the internal shift register. After each byte the interface
generates in sequence:
• An acknowledge pulse if the ACK bit is set
• The RxNE bit is set by hardware and an interrupt is generated if the ITEVFEN and
ITBUFEN bit is set.
If RxNE is set and the data in the DR register is not read before the end of the next data
reception, the BTF bit is set and the interface waits until BTF is cleared by a read from the
I2C_DR register, stretching SCL low (see Figure 163 Transfer sequencing).
ai18208
1. The EV1 event stretches SCL low until the end of the corresponding software sequence.
2. The EV2 event stretches SCL low if the software sequence is not completed before the end of the next byte
reception.
3. After checking the SR1 register content, the user should perform the complete clearing sequence for each
flag found set.
Thus, for ADDR and STOPF flags, the following sequence is required inside the I2C interrupt routine:
READ SR1
if (ADDR == 1) {READ SR1; READ SR2}
if (STOPF == 1) {READ SR1; WRITE CR1}
The purpose is to make sure that both ADDR and STOPF flags are cleared if both are found set.
Start condition
Setting the START bit causes the interface to generate a Start condition and to switch to
Master mode (MSL bit set) when the BUSY bit is cleared.
Note: In master mode, setting the START bit causes the interface to generate a ReStart condition
at the end of the current byte transfer.
Once the Start condition is sent:
• The SB bit is set by hardware and an interrupt is generated if the ITEVFEN bit is set.
Then the master waits for a read of the SR1 register followed by a write in the DR register
with the Slave address (see Figure 164 and Figure 165 Transfer sequencing EV5).
The master can decide to enter Transmitter or Receiver mode depending on the LSB of the
slave address sent.
• In 7-bit addressing mode,
– To enter Transmitter mode, a master sends the slave address with LSB reset.
– To enter Receiver mode, a master sends the slave address with LSB set.
• In 10-bit addressing mode,
– To enter Transmitter mode, a master sends the header (11110xx0) and then the
slave address, (where xx denotes the two most significant bits of the address).
– To enter Receiver mode, a master sends the header (11110xx0) and then the
slave address. Then it should send a repeated Start condition followed by the
header (11110xx1), (where xx denotes the two most significant bits of the
address).
The TRA bit indicates whether the master is in Receiver or Transmitter mode.
Master transmitter
Following the address transmission and after clearing ADDR, the master sends bytes from
the DR register to the SDA line via the internal shift register.
The master waits until the first data byte is written into I2C_DR (see Figure 164 Transfer
sequencing EV8_1).
When the acknowledge pulse is received, the TxE bit is set by hardware and an interrupt is
generated if the ITEVFEN and ITBUFEN bits are set.
If TxE is set and a data byte was not written in the DR register before the end of the last data
transmission, BTF is set and the interface waits until BTF is cleared by a write to I2C_DR,
stretching SCL low.
Closing the communication
After the last byte is written to the DR register, the STOP bit is set by software to generate a
Stop condition (see Figure 164 Transfer sequencing EV8_2). The interface automatically
goes back to slave mode (MSL bit cleared).
Note: Stop condition should be programmed during EV8_2 event, when either TxE or BTF is set.
EV5: SB=1, cleared by reading SR1 register followed by writing DR register with Address.
EV6: ADDR=1, cleared by reading SR1 register followed by reading SR2.
EV8_1: TxE=1, shift register empty, data register empty, write Data1 in DR.
EV8: TxE=1, shift register not empty,.data register empty, cleared by writing DR register
EV8_2: TxE=1, BTF = 1, Program Stop request. TxE and BTF are cleared by hardware by the Stop condition
EV9: ADD10=1, cleared by reading SR1 register followed by writing DR register.
ai18210
1. The EV5, EV6, EV9, EV8_1 and EV8_2 events stretch SCL low until the end of the corresponding software sequence.
2. The EV8 event stretches SCL low if the software sequence is not complete before the end of the next byte transmission.
Master receiver
Following the address transmission and after clearing ADDR, the I2C interface enters
Master Receiver mode. In this mode the interface receives bytes from the SDA line into the
DR register via the internal shift register. After each byte the interface generates in
sequence:
1. An acknowledge pulse if the ACK bit is set
2. The RxNE bit is set and an interrupt is generated if the ITEVFEN and ITBUFEN bits are
set (see Figure 165 Transfer sequencing EV7).
If the RxNE bit is set and the data in the DR register is not read before the end of the last
data reception, the BTF bit is set by hardware and the interface waits until BTF is cleared by
a read in the DR register, stretching SCL low.
Closing the communication
The master sends a NACK for the last byte received from the slave. After receiving this
NACK, the slave releases the control of the SCL and SDA lines. Then the master can send
a Stop/Restart condition.
1. To generate the nonacknowledge pulse after the last received data byte, the ACK bit
must be cleared just after reading the second last data byte (after second last RxNE
event).
2. In order to generate the Stop/Restart condition, software must set the STOP/START bit
after reading the second last data byte (after the second last RxNE event).
3. In case a single byte has to be received, the Acknowledge disable is made during EV6
(before ADDR flag is cleared) and the STOP condition generation is made after EV6.
After the Stop condition generation, the interface goes automatically back to slave mode
(MSL bit cleared).
AID
Note: For each frequency range, the constraint is given based on the worst case which is the
minimum frequency of the range. Greater DNF values can be used if the system can
support maximum hold time violation.
18.3.7 SMBus
Introduction
The System Management Bus (SMBus) is a two-wire interface through which various
devices can communicate with each other and with the rest of the system. It is based on I2C
principles of operation. SMBus provides a control bus for system and power management
related tasks. A system may use SMBus to pass messages to and from devices instead of
toggling individual control lines.
The System Management Bus Specification refers to three types of devices. A slave is a
device that is receiving or responding to a command. A master is a device that issues
commands, generates the clocks, and terminates the transfer. A host is a specialized
master that provides the main interface to the system's CPU. A host must be a master-slave
and must support the SMBus host notify protocol. Only one host is allowed in a system.
Device identification
Any device that exists on the System Management Bus as a slave has a unique address
called the Slave Address. For the list of reserved slave addresses, refer to the SMBus
specification version. 2.0 (http://smbus.org/).
Bus protocols
The SMBus specification supports up to 9 bus protocols. For more details of these protocols
and SMBus address types, refer to SMBus specification version. 2.0 (http://smbus.org/).
These protocols should be implemented by the user software.
Timeout error
There are differences in the timing specifications between I2C and SMBus.
SMBus defines a clock low timeout, TIMEOUT of 35 ms. Also SMBus specifies TLOW:
SEXT as the cumulative clock low extend time for a slave device. SMBus specifies TLOW:
MEXT as the cumulative clock low extend time for a master device. For more details on
these timeouts, refer to SMBus specification version 2.0 (http://smbus.org/).
The status flag Timeout or Tlow Error in I2C_SR1 shows the status of this feature.
be set before the ACK of the CRC reception in slave mode. It must be set when
the ACK is set low in master mode.
• A PECERR error flag/interrupt is also available in the I2C_SR1 register.
• If DMA and PEC calculation are both enabled:-
– In transmission: when the I2C interface receives an EOT signal from the DMA
controller, it automatically sends a PEC after the last byte.
– In reception: when the I2C interface receives an EOT_1 signal from the DMA
controller, it will automatically consider the next byte as a PEC and will check it. A
DMA request is generated after PEC reception.
• To allow intermediate PEC transfers, a control bit is available in the I2C_CR2 register
(LAST bit) to determine if it is really the last DMA transfer or not. If it is the last DMA
request for a master receiver, a NACK is automatically sent after the last received byte.
• PEC calculation is corrupted by an arbitration loss.
Note: SB, ADDR, ADD10, STOPF, BTF, RxNE and TxE are logically ORed on the same interrupt
channel.
BERR, ARLO, AF, OVR, PECERR, TIMEOUT and SMBALERT are logically ORed on the
same interrupt channel.
STOPF
it_event
BTF
TxE
ITBUFEN
RxNE
ITERREN
BERR
ARLO
it_error
AF
OVR
PECERR
TIMEOUT
SMBALERT
Note: When the STOP, START or PEC bit is set, the software must not perform any write access
to I2C_CR1 before this bit is cleared by hardware. Otherwise there is a risk of setting a
second STOP, START or PEC request.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SMB SMBDE GEN
PEC[7:0] DUALF TRA BUSY MSL
HOST FAULT CALL Res.
r r r r r r r r r r r r r r r
Note: Reading I2C_SR2 after reading I2C_SR1 clears the ADDR flag, even if the ADDR flag was
set after reading I2C_SR1. Consequently, I2C_SR2 must be read only when ADDR is found
set in I2C_SR1 or when the STOPF bit is cleared.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
F/S DUTY CCR[11:0]
Reserved
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
ANOFF DNF[3:0]
Reserved
rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
NOSTRETCH
SMBTYPE
SWRST
SMBUS
ENPEC
ENARP
ALERT
START
ENGC
STOP
Reserved
Reserved
POS
ACK
PEC
PE
I2C_CR1
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ITERREN
ITBUFEN
ITEVTEN
DMAEN
LAST
Reserved
I2C_CR2 FREQ[5:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
ADDMODE
ADD0
I2C_OAR1 ADD[9:8] ADD[7:1]
0x08 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
ENDUAL
I2C_OAR2 ADD2[7:1]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0
I2C_DR DR[7:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0
SMBALERT
TIMEOUT
PECERR
STOPF
ADD10
ADDR
BERR
ARLO
RxNE
OVR
Reserved
Reserved
BTF
TxE
SB
AF
I2C_SR1
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SMBDEFAULT
SMBHOST
GENCALL
DUALF
BUSY
Reserved
MSL
TRA
I2C_SR2 PEC[7:0]
0x18 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUTY
Reserved
F/S
I2C_CCR CCR[11:0]
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I2C_TRISE TRISE[5:0]
0x20 Reserved
Reset value 0 0 0 0 1 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ANOFF
I2C_FLTR DNF[3:0]
0x24 Reserved
Reset value 0 0 0 0 0
PWDATA PRDATA
Write Read (Data register) DR
TX
IrDA
RX SIR
ENDEC Transmit Shift Register Receive Shift Register
SW_RX block
GTPR
GT PSC SCLK control SCLK
CR3 CR2
DMAT DMAR SCEN NACK HD IRLP IREN LINE STOP[1:0] CKEN CPOL CPHA LBCL
CR2 CR1
USART Address UE M WAKE PCE PS PEIE
nRTS Hardware
flow
nCTS controller
Wakeup Receiver
Transmit Receiver clock
control unit
control
CR1 SR
TXEIE TCIE RXNE
IE
IDLE TE RE RWU SBK CTS LBD TXE TC RXNE IDLE ORE NF FE PE
IE
USART
interrupt
control
CR1 USART_BRR
OVER8
TE Transmitter rate
Transmitter control
clock
/ [8 x (2 - OVER8)] /USARTDIV
SAMPLING
DIVIDER DIV_Mantissa DIV_Fraction
15 4 0
fPCLKx(x=1,2)
Receiver rate
RE control
Start
Idle frame bit
Start
Idle frame bit
19.3.2 Transmitter
The transmitter can send data words of either 8 or 9 bits depending on the M bit status.
When the transmit enable bit (TE) is set, the data in the transmit shift register is output on
the TX pin and the corresponding clock pulses are output on the SCLK pin.
Character transmission
During an USART transmission, data shifts out least significant bit first on the TX pin. In this
mode, the USART_DR register consists of a buffer (TDR) between the internal bus and the
transmit shift register (see Figure 167).
Every character is preceded by a start bit which is a logic level low for one bit period. The
character is terminated by a configurable number of stop bits.
The following stop bits are supported by USART: 0.5, 1, 1.5 and 2 stop bits.
Note: The TE bit should not be reset during transmission of data. Resetting the TE bit during the
transmission will corrupt the data on the TX pin as the baud rate counters will get frozen.
The current data being transmitted will be lost.
An idle frame will be sent after the TE bit is enabled.
a) 1 Stop Bit
Possible Next data frame
Parity
Data frame
Bit Next
Start start
Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 bit
1 1/2 stop bits
b) 1 1/2 stop Bits
Possible Next data frame
parity
Data frame
bit Next
Start 2 Stop Start
Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bits Bit
Procedure:
1. Enable the USART by writing the UE bit in USART_CR1 register to 1.
2. Program the M bit in USART_CR1 to define the word length.
3. Program the number of stop bits in USART_CR2.
4. Select DMA enable (DMAT) in USART_CR3 if Multi buffer Communication is to take
place. Configure the DMA register as explained in multibuffer communication.
5. Select the desired baud rate using the USART_BRR register.
6. Set the TE bit in USART_CR1 to send an idle frame as first transmission.
7. Write the data to send in the USART_DR register (this clears the TXE bit). Repeat this
for each data to be transmitted in case of single buffer.
8. After writing the last data into the USART_DR register, wait until TC=1. This indicates
that the transmission of the last frame is complete. This is required for instance when
the USART is disabled or enters the Halt mode to avoid corrupting the last
transmission.
When a transmission is taking place, a write instruction to the USART_DR register stores
the data in the TDR register and which is copied in the shift register at the end of the current
transmission.
When no transmission is taking place, a write instruction to the USART_DR register places
the data directly in the shift register, the data transmission starts, and the TXE bit is
immediately set.
If a frame is transmitted (after the stop bit) and the TXE bit is set, the TC bit goes high. An
interrupt is generated if the TCIE bit is set in the USART_CR1 register.
After writing the last data into the USART_DR register, it is mandatory to wait for TC=1
before disabling the USART or causing the microcontroller to enter the low power mode
(see Figure 170: TC/TXE behavior when transmitting).
The TC bit is cleared by the following software sequence:
1. A read from the USART_SR register
2. A write to the USART_DR register
Note: The TC bit can also be cleared by writing a ‘0 to it. This clearing sequence is recommended
only for Multibuffer communication.
TX line
USART_DR F1 F2 F3
TC flag set
by hardware
software software waits until TXE=1 TC is not set TC is not set TC is set because
enables the and writes F2 into DR because TXE=0 because TXE=0 TXE=1
USART
software waits until TXE=1 software waits until TXE=1 software waits until TC=1
and writes F1 into DR and writes F3 into DR
ai17121b
Break characters
Setting the SBK bit transmits a break character. The break frame length depends on the M
bit (see Figure 168).
If the SBK bit is set to ‘1 a break character is sent on the TX line after completing the current
character transmission. This bit is reset by hardware when the break character is completed
(during the stop bit of the break character). The USART inserts a logic 1 bit at the end of the
last break frame to guarantee the recognition of the start bit of the next frame.
Note: If the software resets the SBK bit before the commencement of break transmission, the
break character will not be transmitted. For two consecutive breaks, the SBK bit should be
set after the stop bit of the previous break.
Idle characters
Setting the TE bit drives the USART to send an idle frame before the first data frame.
19.3.3 Receiver
The USART can receive data words of either 8 or 9 bits depending on the M bit in the
USART_CR1 register.
RX line
Ideal
sample
clock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
sampled values
Real
sample X X X X X X X X 9 10 11 12 13 14 15 16
clock
6/16
7/16 7/16
One-bit time
Conditions
to validate 1 1 1 0 X 0 X 0 X 0 0 0 0 X X X X X X
the start bit
Falling edge At least 2 bits At least 2 bits
detection out of 3 at 0 out of 3 at 0 ai15471
Note: If the sequence is not complete, the start bit detection aborts and the receiver returns to the
idle state (no flag is set) where it waits for a falling edge.
The start bit is confirmed (RXNE flag set, interrupt generated if RXNEIE=1) if the 3 sampled
bits are at 0 (first sampling on the 3rd, 5th and 7th bits finds the 3 bits at 0 and second
sampling on the 8th, 9th and 10th bits also finds the 3 bits at 0).
The start bit is validated (RXNE flag set, interrupt generated if RXNEIE=1) but the NE noise
flag is set if, for both samplings, at least 2 out of the 3 sampled bits are at 0 (sampling on the
3rd, 5th and 7th bits and sampling on the 8th, 9th and 10th bits). If this condition is not met,
the start detection aborts and the receiver returns to the idle state (no flag is set).
If, for one of the samplings (sampling on the 3rd, 5th and 7th bits or sampling on the 8th, 9th
and 10th bits), 2 out of the 3 bits are found at 0, the start bit is validated but the NE noise
flag bit is set.
Character reception
During an USART reception, data shifts in least significant bit first through the RX pin. In this
mode, the USART_DR register consists of a buffer (RDR) between the internal bus and the
received shift register.
Procedure:
Break character
When a break character is received, the USART handles it as a framing error.
Idle character
When an idle frame is detected, there is the same procedure as a data received character
plus an interrupt if the IDLEIE bit is set.
Overrun error
An overrun error occurs when a character is received when RXNE has not been reset. Data
can not be transferred from the shift register to the RDR register until the RXNE bit is
cleared.
The RXNE flag is set after every byte received. An overrun error occurs if RXNE flag is set
when the next data is received or the previous DMA request has not been serviced. When
an overrun error occurs:
• The ORE bit is set.
• The RDR content will not be lost. The previous data is available when a read to
USART_DR is performed.
• The shift register will be overwritten. After that point, any data received during overrun
is lost.
• An interrupt is generated if either the RXNEIE bit is set or both the EIE and DMAR bits
are set.
• The ORE bit is reset by a read to the USART_SR register followed by a USART_DR
register read operation.
Note: The ORE bit, when set, indicates that at least 1 data has been lost. There are two
possibilities:
• if RXNE=1, then the last valid data is stored in the receive register RDR and can be
read,
• if RXNE=0, then it means that the last valid data has already been read and thus there
is nothing to be read in the RDR. This case can occur when the last valid data is read in
the RDR at the same time as the new (and lost) data is received. It may also occur
when the new data is received during the reading sequence (between the USART_SR
register read access and the USART_DR read access).
receiver tolerance to clock deviation on page 521). In this case the NF bit will
never be set.
When noise is detected in a frame:
• The NF bit is set at the rising edge of the RXNE bit.
• The invalid data is transferred from the Shift register to the USART_DR register.
• No interrupt is generated in case of single byte communication. However this bit rises
at the same time as the RXNE bit which itself generates an interrupt. In case of
multibuffer communication an interrupt will be issued if the EIE bit is set in the
USART_CR3 register.
The NF bit is reset by a USART_SR register read operation followed by a USART_DR
register read operation.
Note: Oversampling by 8 is not available in the Smartcard, IrDA and LIN modes. In those modes,
the OVER8 bit is forced to ‘0 by hardware.
RX LINE
sampled values
Sample
clock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
6/16
7/16 7/16
One bit time
RX LINE
sampled values
Sample
clock(x8) 1 2 3 4 5 6 7 8
2/8
3/8 3/8
One bit time
Framing error
A framing error is detected when:
The stop bit is not recognized on reception at the expected time, following either a de-
synchronization or excessive noise.
When the framing error is detected:
• The FE bit is set by hardware
• The invalid data is transferred from the Shift register to the USART_DR register.
• No interrupt is generated in case of single byte communication. However this bit rises
at the same time as the RXNE bit which itself generates an interrupt. In case of
multibuffer communication an interrupt will be issued if the EIE bit is set in the
USART_CR3 register.
The FE bit is reset by a USART_SR register read operation followed by a USART_DR
register read operation.
USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.
• When OVER8=0, the fractional part is coded on 4 bits and programmed by the
DIV_fraction[3:0] bits in the USART_BRR register
• When OVER8=1, the fractional part is coded on 3 bits and programmed by the
DIV_fraction[2:0] bits in the USART_BRR register, and bit DIV_fraction[3] must be kept
cleared.
Note: The baud counters are updated to the new value in the baud registers after a write operation
to USART_BRR. Hence the baud rate register value should not be changed during
communication.
Example 2:
To program USARTDIV = 0d25.62
This leads to:
DIV_Fraction = 16*0d0.62 = 0d9.92
The nearest real number is 0d10 = 0xA
DIV_Mantissa = mantissa (0d25.620) = 0d25 = 0x19
Then, USART_BRR = 0x19A hence USARTDIV = 0d25.625
Example 3:
To program USARTDIV = 0d50.99
This leads to:
Table 72. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 12 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8=0)
Table 72. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 12 MHz,
oversampling by 16(1) (continued)
Oversampling by 16 (OVER8=0)
Table 73. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK =12 MHz,
oversampling by 8(1)
Oversampling by 8 (OVER8 = 1)
% Error =
Value (Calculated - Value
programmed Desired) programmed
S.No Desired Actual Actual % Error
in the baud B.rate / in the baud
rate register Desired rate register
B.rate
Table 73. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK =12 MHz,
oversampling by 8(1) (continued)
Oversampling by 8 (OVER8 = 1)
% Error =
Value (Calculated - Value
programmed Desired) programmed
S.No Desired Actual Actual % Error
in the baud B.rate / in the baud
rate register Desired rate register
B.rate
10 921.6 KBps 888.889 KBps 1.125 3.55 923.077 KBps 1.625 0.16
11 2 MBps NA NA NA NA NA NA
12 3 MBps NA NA NA NA NA NA
1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can
be fixed with these data.
Table 74. Error calculation for programmed baud rates at fPCLK = 16 MHz or fPCLK = 24 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8 = 0)
Table 75. Error calculation for programmed baud rates at fPCLK = 16 MHz or fPCLK = 24 MHz,
oversampling by 8(1)
Oversampling by 8 (OVER8=1)
Table 76. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8=0)
Value
% Error = Value
programme
(Calculated - programmed
S.No Desired Actual d in the Actual % Error
Desired)B.Rate in the baud
baud rate
/Desired B.Rate rate register
register
1. 2.4 KBps 2.400 KBps 208.3125 0.00% 2.400 KBps 416.6875 0.00%
2. 9.6 KBps 9.604 KBps 52.0625 0.04% 9.598 KBps 104.1875 0.02%
3. 19.2 KBps 19.185 KBps 26.0625 0.08% 19.208 KBps 52.0625 0.04%
4. 57.6 KBps 57.554 KBps 8.6875 0.08% 57.554 KBps 17.3750 0.08%
5. 115.2 KBps 115.942 KBps 4.3125 0.64% 115.108 KBps 8.6875 0.08%
228.571
6. 230.4 KBps 2.1875 0.79% 231.884 KBps 4.3125 0.64%
KBps
Table 76. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 16(1) (continued)
Oversampling by 16 (OVER8=0)
Value
% Error = Value
programme
(Calculated - programmed
S.No Desired Actual d in the Actual % Error
Desired)B.Rate in the baud
baud rate
/Desired B.Rate rate register
register
470.588
7. 460.8 KBps 1.0625 2.12% 457.143 KBps 2.1875 0.79%
KBps
8. 896 KBps NA NA NA 888.889 KBps 1.1250 0.79%
9. 921.6 KBps NA NA NA 941.176 KBps 1.0625 2.12%
10. 1.792 MBps NA NA NA NA NA NA
11. 1.8432 MBps NA NA NA NA NA NA
12. 3.584 MBps NA NA NA NA NA NA
13. 3.6864 MBps NA NA NA NA NA NA
14. 7.168 MBps NA NA NA NA NA NA
15. 7.3728 MBps NA NA NA NA NA NA
1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can
be fixed with these data.
Table 77. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 8(1)
Oversampling by 8 (OVER8=1)
1. 2.4 KBps 2.400 KBps 416.625 0.01% 2.400 KBps 833.375 0.00%
2. 9.6 KBps 9.604 KBps 104.125 0.04% 9.598 KBps 208.375 0.02%
3. 19.2 KBps 19.185 KBps 52.125 0.08% 19.208 KBps 104.125 0.04%
4. 57.6 KBps 57.557 KBps 17.375 0.08% 57.554 KBps 34.750 0.08%
5. 115.2 KBps 115.942 KBps 8.625 0.64% 115.108 KBps 17.375 0.08%
6. 230.4 KBps 228.571 KBps 4.375 0.79% 231.884 KBps 8.625 0.64%
7. 460.8 KBps 470.588 KBps 2.125 2.12% 457.143 KBps 4.375 0.79%
8. 896 KBps 888.889 KBps 1.125 0.79% 888.889 KBps 2.250 0.79%
9. 921.6 KBps 888.889 KBps 1.125 3.55% 941.176 KBps 2.125 2.12%
10. 1.792 MBps NA NA NA 1.7777 MBps 1.125 0.79%
Table 77. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 8(1) (continued)
Oversampling by 8 (OVER8=1)
Table 78. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 16(1)(2)
Oversampling by 16 (OVER8=0)
Value
% Error = Value
programme
(Calculated - programmed %
S.No Desired Actual d in the Actual
Desired)B.Rate in the baud Error
baud rate
/Desired B.Rate rate register
register
1. 2.4 KBps 2.400 KBps 781.2500 0.00% 2.400 KBps 1562.5000 0.00%
2. 9.6 KBps 9.600 KBps 195.3125 0.00% 9.600 KBps 390.6250 0.00%
3. 19.2 KBps 19.194 KBps 97.6875 0.03% 19.200 KBps 195.3125 0.00%
4. 57.6 KBps 57.582KBps 32.5625 0.03% 57.582 KBps 65.1250 0.03%
5. 115.2 KBps 115.385 KBps 16.2500 0.16% 115.163 KBps 32.5625 0.03%
6. 230.4 KBps 230.769 KBps 8.1250 0.16% 230.769KBps 16.2500 0.16%
7. 460.8 KBps 461.538 KBps 4.0625 0.16% 461.538 KBps 8.1250 0.16%
8. 896 KBps 909.091 KBps 2.0625 1.46% 895.522 KBps 4.1875 0.05%
9. 921.6 KBps 909.091 KBps 2.0625 1.36% 923.077 KBps 4.0625 0.16%
10. 1.792 MBps 1.1764 MBps 1.0625 1.52% 1.8182 MBps 2.0625 1.36%
1.8432
11. 1.8750 MBps 1.0000 1.73% 1.8182 MBps 2.0625 1.52%
MBps
12. 3.584 MBps NA NA NA 3.2594 MBps 1.0625 1.52%
3.6864
13. NA NA NA 3.7500 MBps 1.0000 1.73%
MBps
Table 78. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 16(1)(2) (continued)
Oversampling by 16 (OVER8=0)
Value
% Error = Value
programme
(Calculated - programmed %
S.No Desired Actual d in the Actual
Desired)B.Rate in the baud Error
baud rate
/Desired B.Rate rate register
register
Table 79. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 8(1) (2)
Oversampling by 8 (OVER8=1)
Value
% Error = Value
programme
(Calculated - programmed %
S.No Desired Actual d in the Actual
Desired)B.Rate in the baud Error
baud rate
/Desired B.Rate rate register
register
1. 2.4 KBps 2.400 KBps 1562.5000 0.00% 2.400 KBps 3125.0000 0.00%
2. 9.6 KBps 9.600 KBps 390.6250 0.00% 9.600 KBps 781.2500 0.00%
3. 19.2 KBps 19.194 KBps 195.3750 0.03% 19.200 KBps 390.6250 0.00%
4. 57.6 KBps 57.582 KBps 65.1250 0.16% 57.582 KBps 130.2500 0.03%
5. 115.2 KBps 115.385 KBps 32.5000 0.16% 115.163 KBps 65.1250 0.03%
6. 230.4 KBps 230.769 KBps 16.2500 0.16% 230.769 KBps 32.5000 0.16%
7. 460.8 KBps 461.538 KBps 8.1250 0.16% 461.538 KBps 16.2500 0.16%
8. 896 KBps 909.091 KBps 4.1250 1.46% 895.522 KBps 8.3750 0.05%
9. 921.6 KBps 909.091 KBps 4.1250 1.36% 923.077 KBps 8.1250 0.16%
10. 1.792 MBps 1.7647 MBps 2.1250 1.52% 1.8182 MBps 4.1250 1.46%
11. 1.8432 MBps 1.8750 MBps 2.0000 1.73% 1.8182 MBps 4.1250 1.36%
12. 3.584 MBps 3.7500 MBps 1.0000 4.63% 3.5294 MBps 2.1250 1.52%
13. 3.6864 MBps 3.7500 MBps 1.0000 1.73% 3.7500 MBps 2.0000 1.73%
14. 7.168 MBps NA NA NA 7.5000 MBps 1.0000 4.63%
15. 7.3728 MBps NA NA NA 7.5000 MBps 1.0000 1.73%
1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can
be fixed with these data.
2. Only USART1 and USART6 are clocked with PCLK2. Other USARTs are clocked with PCLK1. Refer to the device
datasheets for the maximum values for PCLK1 and PCLK2.
Table 80. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 Hz,
oversampling by 16(1)(2)
Oversampling by 16 (OVER8=0)
Value
% Error = Value
programme
(Calculated - programmed %
S.No Desired Actual d in the Actual
Desired)B.Rate in the baud Error
baud rate
/Desired B.Rate rate register
register
Table 81. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 MHz,
oversampling by 8(1)(2)
Oversampling by 8 (OVER8=1)
Value
% Error = Value
programme
(Calculated - programmed %
S.No Desired Actual d in the Actual
Desired)B.Rate in the baud Error
baud rate
/Desired B.Rate rate register
register
Note: The figures specified in Table 82 and Table 83 may slightly differ in the special case when
the received frames contain some Idle frames of exactly 10-bit times when M=0 (11-bit times
when M=1).
RXNE RXNE
The RWU bit can be written to as 0 or 1 when the receiver buffer contains no data (RXNE=0
in the USART_SR register). Otherwise the write attempt is ignored.
An example of mute mode behavior using address mark detection is given in Figure 175.
In this example, the current address of the receiver is 1 RXNE RXNE RXNE
(programmed in the USART_CR2 register)
RX IDLE Addr=0 Data 1 Data 2 IDLE Addr=1 Data 3 Data 4 Addr=2 Data 5
RWU written to 1
(RXNE was cleared)
Even parity
The parity bit is calculated to obtain an even number of “1s” inside the frame made of the 7
or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.
E.g.: data=00110101; 4 bits set => parity bit will be 0 if even parity is selected (PS bit in
USART_CR1 = 0).
Odd parity
The parity bit is calculated to obtain an odd number of “1s” inside the frame made of the 7 or
8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.
E.g.: data=00110101; 4 bits set => parity bit will be 1 if odd parity is selected (PS bit in
USART_CR1 = 1).
LIN transmission
The same procedure explained in Section 19.3.2 has to be applied for LIN Master
transmission than for normal USART transmission with the following differences:
• Clear the M bit to configure 8-bit word length.
• Set the LINEN bit to enter LIN mode. In this case, setting the SBK bit sends 13 ‘0 bits
as a break character. Then a bit of value ‘1 is sent to allow the next start detection.
LIN reception
A break detection circuit is implemented on the USART interface. The detection is totally
independent from the normal USART receiver. A break can be detected whenever it occurs,
during Idle state or during a frame.
When the receiver is enabled (RE=1 in USART_CR1), the circuit looks at the RX input for a
start signal. The method for detecting start bits is the same when searching break
characters or data. After a start bit has been detected, the circuit samples the next bits
exactly like for the data (on the 8th, 9th and 10th samples). If 10 (when the LBDL = 0 in
USART_CR2) or 11 (when LBDL=1 in USART_CR2) consecutive bits are detected as ‘0,
and are followed by a delimiter character, the LBD flag is set in USART_SR. If the LBDIE
bit=1, an interrupt is generated. Before validating the break, the delimiter is checked for as it
signifies that the RX line has returned to a high level.
If a ‘1 is sampled before the 10 or 11 have occurred, the break detection circuit cancels the
current detection and searches for a start bit again.
If the LIN mode is disabled (LINEN=0), the receiver continues working as normal USART,
without taking into account the break detection.
If the LIN mode is enabled (LINEN=1), as soon as a framing error occurs (i.e. stop bit
detected at ‘0, which will be the case for any break frame), the receiver stops until the break
detection circuit receives either a ‘1, if the break word was not complete, or a delimiter
character if a break has been detected.
The behavior of the break detector state machine and the break flag is shown on the
Figure 176: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 525.
Examples of break frames are given on Figure 177: Break detection in LIN mode vs.
Framing error detection on page 526.
Figure 176. Break detection in LIN mode (11-bit break length - LBDL bit is set)
Case 1: break signal not long enough => break discarded, LBD is not set
Capture Strobe
Break State machine Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 Idle
Read Samples 0 0 0 0 0 0 0 0 0 0 1
Case 2: break signal just long enough => break detected, LBD is set
Capture Strobe
delimiter is immediate
Break State machine Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 B10 Idle
Read Samples 0 0 0 0 0 0 0 0 0 0 0
LBD
Case 3: break signal long enough => break detected, LBD is set
Capture Strobe
Break State machine Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 wait delimiter Idle
Read Samples 0 0 0 0 0 0 0 0 0 0 0
LBD
Figure 177. Break detection in LIN mode vs. Framing error detection
In these examples, we suppose that LBDL=1 (11-bit break length), M=0 (8-bit data)
RXNE / FE
LBD
RXNE / FE
LBD
has been written). This means that it is not possible to receive a synchronous data without
transmitting data.
The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the
receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. These
bits should not be changed while the transmitter or the receiver is enabled.
It is advised that TE and RE are set in the same instruction in order to minimize the setup
and the hold time of the receiver.
The USART supports master mode only: it cannot receive or send data related to an input
clock (SCLK is always an output).
RX Data out
TX Data in
SCLK Clock
Data on TX 0 1 2 3 4 5 6 7
(from master)
Start LSB MSB Stop
Data on RX 0 1 2 3 4 5 6 7
(from slave)
LSB MSB
*
Capture Strobe
Data on TX 0 1 2 3 4 5 6 7 8
(from master)
Start LSB MSB Stop
Data on RX 0 1 2 3 4 5 6 7 8
(from slave)
LSB MSB
*
Capture Strobe
tSETUP tHOLD
Note: The function of SCLK is different in Smartcard mode. Refer to the Smartcard mode chapter
for more details.
Apart from this, the communications are similar to what is done in normal USART mode.
The conflicts on the line must be managed by the software (by the use of a centralized
arbiter, for instance). In particular, the transmission is never blocked by hardware and
continue to occur as soon as a data is written in the data register while the TE bit is set.
19.3.11 Smartcard
The Smartcard mode is selected by setting the SCEN bit in the USART_CR3 register. In
smartcard mode, the following bits must be kept cleared:
• LINEN bit in the USART_CR2 register,
• HDSEL and IREN bits in the USART_CR3 register.
Moreover, the CLKEN bit may be set in order to provide a clock to the smartcard.
The Smartcard interface is designed to support asynchronous protocol Smartcards as
defined in the ISO 7816-3 standard. The USART should be configured as:
• 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
• 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2
register.
Note: It is also possible to choose 0.5 stop bit for receiving but it is recommended to use 1.5 stop
bits for both transmitting and receiving to avoid switching between the two configurations.
Figure 182 shows examples of what can be seen on the data line with and without parity
error.
S 0 1 2 3 4 5 6 7 P
Start
bit
S 0 1 2 3 4 5 6 7 P
When connected to a Smartcard, the TX output of the USART drives a bidirectional line that
is also driven by the Smartcard. The TX pin must be configured as open-drain.
Smartcard is a single wire half duplex communication protocol.
• Transmission of data from the transmit shift register is guaranteed to be delayed by a
minimum of 1/2 baud clock. In normal operation a full transmit shift register will start
shifting on the next baud clock edge. In Smartcard mode this transmission is further
delayed by a guaranteed 1/2 baud clock.
• If a parity error is detected during reception of a frame programmed with a 0.5 or 1.5
stop bit period, the transmit line is pulled low for a baud clock period after the
completion of the receive frame. This is to indicate to the Smartcard that the data
transmitted to USART has not been correctly received. This NACK signal (pulling
transmit line low for 1 baud clock) will cause a framing error on the transmitter side
(configured with 1.5 stop bits). The application can handle re-sending of data according
to the protocol. A parity error is ‘NACK’ed by the receiver if the NACK control bit is set,
otherwise a NACK is not transmitted.
• The assertion of the TC flag can be delayed by programming the Guard Time register.
In normal operation, TC is asserted when the transmit shift register is empty and no
further transmit requests are outstanding. In Smartcard mode an empty transmit shift
register triggers the guard time counter to count up to the programmed value in the
Guard Time register. TC is forced low during this time. When the guard time counter
reaches the programmed value TC is asserted high.
• The de-assertion of TC flag is unaffected by Smartcard mode.
• If a framing error is detected on the transmitter end (due to a NACK from the receiver),
the NACK will not be detected as a start bit by the receive block of the transmitter.
According to the ISO protocol, the duration of the received NACK can be 1 or 2 baud
clock periods.
• On the receiver side, if a parity error is detected and a NACK is transmitted the receiver
will not detect the NACK as a start bit.
Note: A break character is not significant in Smartcard mode. A 0x00 data with a framing error will
be treated as data and not as a break.
No Idle frame is transmitted when toggling the TE bit. The Idle frame (as defined for the
other configurations) is not defined by the ISO protocol.
Figure 183 details how the NACK signal is sampled by the USART. In this example the
USART is transmitting a data and is configured with 1.5 stop bits. The receiver part of the
USART is enabled in order to check the integrity of the data and the NACK signal.
Figure 183. Parity error detection using the 1.5 stop bits
sampling at sampling at
8th, 9th, 10th 16th, 17th, 18th
sampling at sampling at
8th, 9th, 10th 8th, 9th, 10th
The USART can provide a clock to the smartcard through the SCLK output. In smartcard
mode, SCLK is not associated to the communication but is simply derived from the internal
peripheral input clock through a 5-bit prescaler. The division ratio is configured in the
prescaler register USART_GTPR. SCLK frequency can be programmed from fCK/2 to
fCK/62, where fCK is the peripheral input clock.
TX
OR USART_TX
SIR
SIREN Transmit IrDA_OUT
USART Encoder
SIR
RX Receive IrDA_IN
Decoder
USART_RX
IrDA_IN
RX 0 0 1
0 1 0 1 0 1 1
48 LINE
SET
4# FLAG BY HARDWARE
$-! WRITES
53!24?$2
CLEAR
FLAG $-! 4#)& SET BY HARDWARE BY SOFTWARE
4RA NSFER COMPLETE
AIB
48 LINE
SET BY HARDWARE
28.% FLAG CLEARED BY $-! READ
$-! REQUEST
CLEARED
$-! 4#)& FLAG SET BY HARDWARE BY SOFTWARE
4RA NSFER COMPLETE
AIB
USART 1 USART 2
TX RX
RX TX
RTS and CTS flow control can be enabled independently by writing respectively RTSE and
CTSE bits to 1 (in the USART_CR3 register).
nRTS
nCTS
Note: Special behavior of break frames: when the CTS flow is enabled, the transmitter does not
check the nCTS input state to send a break.
The USART interrupt events are connected to the same interrupt vector (see Figure 191).
• During transmission: Transmission Complete, Clear to Send or Transmit Data Register
empty interrupt.
• While receiving: Idle Line detection, Overrun error, Receive Data register not empty,
Parity error, LIN break detection, Noise Flag (only in multi buffer communication) and
Framing Error (only in multi buffer communication).
These events generate an interrupt if the corresponding Enable Control Bit is set.
TC
TCIE
TXE
TXEIE
CTS
CTSIE
USART
IDLE
IDLEIE interrupt
RXNEIE
ORE
RXNEIE
RXNE
PE
PEIE
LBD
LBDIE
FE
NE
ORE EIE
DMAR
Asynchronous mode X X X
Hardware flow control X X X
Multibuffer communication (DMA) X X X
Multiprocessor communication X X X
Synchronous X X X
Smartcard X X X
Half-duplex (single-wire mode) X X X
IrDA X X X
LIN X X X
1. X = supported; NA = not applicable.
Note: These 3 bits (CPOL, CPHA, LBCL) should not be written while the transmitter is enabled.
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
RXNE
IDLE
ORE
CTS
TXE
LBD
TC
NF
PE
FE
USART_SR
0x00 Reserved
Reset value 0 0 1 1 0 0 0 0 0 0
USART_DR DR[8:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0
DIV_Fraction
USART_BRR DIV_Mantissa[15:4]
[3:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RXNEIE
OVER8
IDLEIE
WAKE
TXEIE
RWU
PEIE
TCIE
Reserved
PCE
SBK
UE
RE
PS
TE
USART_CR1
M
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CLKEN
LINEN
LBDIE
CPHA
CPOL
LBCL
LBDL
STOP
Reserved
Reserved
USART_CR2 ADD[3:0]
0x10 Reserved [1:0]
Reset value 0 0 0 0
ONEBIT 0 0 0 0 0 0 0 0 0
HDSEL
CTSIE
DMAR
SCEN
NACK
DMAT
CTSE
RTSE
IREN
IRLP
EIE
USART_CR3
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Warning: Since some SPI1 and SPI3/I2S3 pins may be mapped onto
some pins used by the JTAG interface (SPI1_NSS onto JTDI,
SPI3_NSS/I2S3_WS onto JTDI and SPI3_SCK/I2S3_CK onto
JTDO), you may either:
– map SPI/I2S onto other pins
– disable the JTAG and use the SWD interface prior to
configuring the pins listed as SPI I/Os (when debugging the
application) or
– disable both JTAG/SWD interfaces (for standalone
applications).
For more information on the configuration of the JTAG/SWD
interface pins, please refer to Section 8.3.2: I/O pin
multiplexer and mapping.
2EAD
2X BUFFER
-/3) 30)?#2
48% 28.% %22 48$- 28$-
33/% !%. !%.
)% )% )%
3HIFT REGISTER
-)3/
,3" FIRST 30)?32
-/$ #2#
"39 /62 %22 48% 28.%
4X BUFFER &
7RITE
#OMMUNICATION
CONTROL
3#+ "2;=
"AUD RATE GENERATOR
.33
AI
enters the master mode fault state: the MSTR bit is automatically cleared and the
device is configured in slave mode (refer to Section 20.3.10: Error flags on page 573).
A basic example of interconnections between a single master and a single slave is
illustrated in Figure 193.
MOSI MOSI
#0/,
OR BITS DEPENDING ON THE $ATA FRAME FORMAT BIT SEE $&& IN 30)?#2
.33
TO SLAVE
#APTURE STROBE
#0(!
#0/,
#0/,
OR BITS DEPENDING ON THE $ATA FRAME FORMAT BIT SEE $&& IN 30)?#2
-/3) -3"IT ,3"IT
.33
TO SLAVE
#APTURE STROBE
AIB
1. These timings are shown with the LSBFIRST bit reset in the SPI_CR1 register.
Procedure
1. Set the DFF bit to define 8- or 16-bit data frame format
2. Select the CPOL and CPHA bits to define one of the four relationships between the
data transfer and the serial clock (see Figure 194). For correct data transfer, the CPOL
and CPHA bits must be configured in the same way in the slave device and the master
device. This step is not required when the TI mode is selected through the FRF bit in
the SPI_CR2 register.
3. The frame format (MSB-first or LSB-first depending on the value of the LSBFIRST bit in
the SPI_CR1 register) must be the same as the master device. This step is not
required when TI mode is selected.
4. In Hardware mode (refer to Slave select (NSS) pin management on page 553), the
NSS pin must be connected to a low level signal during the complete byte transmit
sequence. In NSS software mode, set the SSM bit and clear the SSI bit in the SPI_CR1
register. This step is not required when TI mode is selected.
5. Set the FRF bit in the SPI_CR2 register to select the TI mode protocol for serial
communications.
6. Clear the MSTR bit and set the SPE bit (both in the SPI_CR1 register) to assign the
pins to alternate functions.
In this configuration the MOSI pin is a data input and the MISO pin is a data output.
Transmit sequence
The data byte is parallel-loaded into the Tx buffer during a write cycle.
The transmit sequence begins when the slave device receives the clock signal and the most
significant bit of the data on its MOSI pin. The remaining bits (the 7 bits in 8-bit data frame
format, and the 15 bits in 16-bit data frame format) are loaded into the shift-register. The
TXE flag in the SPI_SR register is set on the transfer of data from the Tx Buffer to the shift
register and an interrupt is generated if the TXEIE bit in the SPI_CR2 register is set.
Receive sequence
For the receiver, when data transfer is complete:
• The Data in shift register is transferred to Rx Buffer and the RXNE flag (SPI_SR
register) is set
• An Interrupt is generated if the RXNEIE bit is set in the SPI_CR2 register.
After the last sampling clock edge the RXNE bit is set, a copy of the data byte received in
the shift register is moved to the Rx buffer. When the SPI_DR register is read, the SPI
peripheral returns this buffered value.
Clearing of the RXNE bit is performed by reading the SPI_DR register.
In Slave mode (Figure 195: TI mode - Slave mode, single transfer and Figure 196: TI mode
- Slave mode, continuous transfer), the SPI baud rate prescaler is used to control the
moment when the MISO pin state changes to HI-Z. Any baud rate can be used thus allowing
to determine this moment with optimal flexibility. However, the baud rate is generally set to
the external master clock baud rate. The time for the MISO signal to become HI-Z (trelease)
depends on internal resynchronizations and on the baud rate value set in through BR[2:0] of
SPI_CR1 register. It is given by the formula:
t baud_rate t baud_rate
---------------------- + 4 × t pclk < t release < ---------------------
- + 6 × t pclk
2 2
Note: This feature is not available for Motorola SPI communications (FRF bit set to 0).
To detect TI frame errors in Slave transmitter only mode by using the Error interrupt (ERRIE
= 1), the SPI must be configured in 2-line unidirectional mode by setting BIDIMODE and
BIDIOE to 1 in the SPI_CR1 register. When BIDIMODE is set to 0, OVR is set to 1 because
the data register is never read and error interrupt are always generated, while when
BIDIMODE is set to 1, data are not received and OVR is never set.
.33
INPUT TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING
EDGE EDGE EDGE EDGE EDGE EDGE
3#+
INPUT T
2ELEASE
-)3/
OUTPUT OR -3"/54 ,3"/54
AI
.33
INPUT
TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING
3#+
INPUT
&2!-% &2!-%
AI
Procedure
1. Select the BR[2:0] bits to define the serial clock baud rate (see SPI_CR1 register).
2. Select the CPOL and CPHA bits to define one of the four relationships between the
data transfer and the serial clock (see Figure 194). This step is not required when the
TI mode is selected.
3. Set the DFF bit to define 8- or 16-bit data frame format
4. Configure the LSBFIRST bit in the SPI_CR1 register to define the frame format. This
step is not required when the TI mode is selected.
5. If the NSS pin is required in input mode, in hardware mode, connect the NSS pin to a
high-level signal during the complete byte transmit sequence. In NSS software mode,
set the SSM and SSI bits in the SPI_CR1 register. If the NSS pin is required in output
mode, the SSOE bit only should be set. This step is not required when the TI mode is
selected.
6. Set the FRF bit in SPI_CR2 to select the TI protocol for serial communications.
7. The MSTR and SPE bits must be set (they remain set only if the NSS pin is connected
to a high-level signal).
In this configuration the MOSI pin is a data output and the MISO pin is a data input.
Transmit sequence
The transmit sequence begins when a byte is written in the Tx Buffer.
The data byte is parallel-loaded into the shift register (from the internal bus) during the first
bit transmission and then shifted out serially to the MOSI pin MSB first or LSB first
depending on the LSBFIRST bit in the SPI_CR1 register. The TXE flag is set on the transfer
of data from the Tx Buffer to the shift register and an interrupt is generated if the TXEIE bit in
the SPI_CR2 register is set.
Receive sequence
For the receiver, when data transfer is complete:
• The data in the shift register is transferred to the RX Buffer and the RXNE flag is set
• An interrupt is generated if the RXNEIE bit is set in the SPI_CR2 register
At the last sampling clock edge the RXNE bit is set, a copy of the data byte received in the
shift register is moved to the Rx buffer. When the SPI_DR register is read, the SPI
peripheral returns this buffered value.
Clearing the RXNE bit is performed by reading the SPI_DR register.
A continuous transmit stream can be maintained if the next data to be transmitted is put in
the Tx buffer once the transmission is started. Note that TXE flag should be ‘1 before any
attempt to write the Tx buffer is made.
Note: When a master is communicating with SPI slaves which need to be de-selected between
transmissions, the NSS pin must be configured as GPIO or another GPIO must be used and
toggled by software.
.33
OUTPUT TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING
EDGE EDGE EDGE EDGE EDGE EDGE
3#+
OUTPUT
-)3/
OUTPUT OR -3"/54 ,3"/54
AI
.33
OUTPUT
TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING
3#+
OUTPUT
-/3)
$/.4#!2% -3"/54 ,3"/54 -3"/54 ,3"/54
OUTPUT
&2!-% &2!-%
AI
software must have written the data to be sent before the SPI master device
initiates the transfer.
– No data are received.
• In bidirectional mode, when receiving (BIDIMODE=1 and BIDIOE=0)
– The sequence begins when the slave device receives the clock signal and the first
bit of the data on its MISO pin.
– The received data on the MISO pin are shifted in serially to the 8-bit shift register
and then parallel loaded into the SPI_DR register (Rx buffer).
– The transmitter is not activated and no data are shifted out serially to the MISO
pin.
SCK
DATA1 = 0xF1 DATA2 = 0xF2 DATA3 = 0xF3
MISO/MOSI (out) b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7
software software waits software waits software waits software waits software waits
writes 0xF1 until TXE=1 and until RXNE=1 until TXE=1 and until RXNE=1 until RXNE=1
into SPI_DR writes 0xF2 into and reads 0xA1 writes 0xF3 into and reads 0xA2 and reads 0xA3
SPI_DR from SPI_DR SPI_DR from SPI_ DR from SPI_DR
ai17343
SCK
software software waits software waits software waits software waits software waits
writes 0xF1 until TXE=1 and until RXNE=1 until TXE=1 and until RXNE=1 until RXNE=1
into SPI_DR writes 0xF2 into and reads 0xA1 writes 0xF3 into and reads 0xA2 and reads 0xA3
SPI_DR from SPI_DR SPI_DR from SPI_ DR from SPI_DR
ai17344
Figure 201. TXE/BSY behavior in Master transmit-only mode (BIDIMODE=0 and RXONLY=0) in
case of continuous transfers
Example in Master mode with CPOL=1, CPHA=1
SCK
Figure 202. TXE/BSY in Slave transmit-only mode (BIDIMODE=0 and RXONLY=0) in the case of
continuous transfers
Example in slave mode with CPOL=1, CPHA=1
SCK
Figure 203. RXNE behavior in receive-only mode (BIDIRMODE=0 and RXONLY=1) in the case of
continuous transfers
Example with CPOL=1, CPHA=1, RXONLY=1
SCK
software waits until RXNE=1 software waits until RXNE=1 software waits until RXNE=1
and reads 0xA1 from SPI_DR and reads 0xA2 from SPI_DR and reads 0xA3 from SPI_DR
ai17347
Figure 204. TXE/BSY behavior when transmitting (BIDIRMODE=0 and RXONLY=0) in the case of
discontinuous transfers
Example with CPOL=1, CPHA=1
SCK
TXE flag
BSY flag
software writes 0xF1 software waits until TXE=1 but is software waits until TXE=1 but software waits software waits until BSY=0
into SPI_DR late to write 0xF2 into SPI_DR is late to write 0xF3 into until TXE=1
SPI_DR
ai17348
1. Program the CPOL, CPHA, LSBFirst, BR, SSM, SSI and MSTR values.
2. Program the polynomial in the SPI_CRCPR register.
3. Enable the CRC calculation by setting the CRCEN bit in the SPI_CR1 register. This
also clears the SPI_RXCRCR and SPI_TXCRCR registers.
4. Enable the SPI by setting the SPE bit in the SPI_CR1 register.
5. Start the communication and sustain the communication until all but one byte or half-
word have been transmitted or received.
– In full duplex or transmitter-only mode, when the transfers are managed by
software, when writing the last byte or half word to the Tx buffer, set the
CRCNEXT bit in the SPI_CR1 register to indicate that the CRC will be transmitted
after the transmission of the last byte.
– In receiver only mode, set the bit CRCNEXT just after the reception of the second
to last data to prepare the SPI to enter in CRC Phase at the end of the reception of
the last data. CRC calculation is frozen during the CRC transfer.
6. After the transfer of the last byte or half word, the SPI enters the CRC transfer and
check phase. In full duplex mode or receiver-only mode, the received CRC is
compared to the SPI_RXCRCR value. If the value does not match, the CRCERR flag in
SPI_SR is set and an interrupt can be generated when the ERRIE bit in the SPI_CR2
register is set.
Note: When the SPI is in slave mode, be careful to enable CRC calculation only when the clock is
stable, that is, when the clock is in the steady state. If not, a wrong CRC calculation may be
done. In fact, the CRC is sensitive to the SCK slave input clock as soon as CRCEN is set,
and this, whatever the value of the SPE bit.
With high bitrate frequencies, be careful when transmitting the CRC. As the number of used
CPU cycles has to be as low as possible in the CRC transfer phase, it is forbidden to call
software functions in the CRC transmission sequence to avoid errors in the last data and
CRC reception. In fact, CRCNEXT bit has to be written before the end of the
transmission/reception of the last data.
For high bit rate frequencies, it is advised to use the DMA mode to avoid the degradation of
the SPI speed performance due to CPU accesses impacting the SPI bandwidth.
When the devices are configured as slaves and the NSS hardware mode is used, the NSS
pin needs to be kept low between the data phase and the CRC phase.
When the SPI is configured in slave mode with the CRC feature enabled, CRC calculation
takes place even if a high level is applied on the NSS pin. This may happen for example in
case of a multislave environment where the communication master addresses slaves
alternately.
Between a slave deselection (high level on NSS) and a new slave selection (low level on
NSS), the CRC value should be cleared on both master and slave sides in order to
resynchronize the master and slave for their respective CRC calculation.
To clear the CRC, follow the procedure below:
1. Disable SPI (SPE = 0)
2. Clear the CRCEN bit
3. Set the CRCEN bit
4. Enable the SPI (SPE = 1)
BUSY flag
This BSY flag is set and cleared by hardware (writing to this flag has no effect). The BSY
flag indicates the state of the communication layer of the SPI.
When BSY is set, it indicates that the SPI is busy communicating. There is one exception in
master mode / bidirectional receive mode (MSTR=1 and BDM=1 and BDOE=0) where the
BSY flag is kept low during reception.
The BSY flag is useful to detect the end of a transfer if the software wants to disable the SPI
and enter Halt mode (or disable the peripheral clock). This avoids corrupting the last
transfer. For this, the procedure described below must be strictly respected.
The BSY flag is also useful to avoid write collisions in a multimaster system.
The BSY flag is set when a transfer starts, with the exception of master mode / bidirectional
receive mode (MSTR=1 and BDM=1 and BDOE=0).
It is cleared:
• when a transfer is finished (except in master mode if the communication is continuous)
• when the SPI is disabled
• when a master mode fault occurs (MODF=1)
When communication is not continuous, the BSY flag is low between each communication.
When communication is continuous:
• in master mode, the BSY flag is kept high during all the transfers
• in slave mode, the BSY flag goes low for one SPI clock cycle between each transfer
Note: Do not use the BSY flag to handle each data transmission or reception. It is better to use the
TXE and RXNE flags instead.
SCK
reset
BSY flag set by hardware by hardware
software configures the DMA writes DMA writes DMA writes DMA transfer is software waits software waits until BSY=0
DMA SPI Tx channel DATA1 into DATA2 into DATA3 into complete (TCIF=1 in until TXE=1
to send 3 data items SPI_DR SPI_DR SPI_DR DMA_ISR)
and enables the SPI
ai17349
SCK
DMA request
Rx buffer
0xA1 0xA2 0xA3
(read from SPI_DR)
software configures the DMA reads DMA reads DMA reads The DMA transfer is
DMA SPI Rx channel DATA1 from DATA2 from DATA3 from complete (TCIF=1 in
to receive 3 data items SPI_DR SPI_DR SPI_DR DMA_ISR)
and enables the SPI
ai17350
Overrun condition
An overrun condition occurs when the master device has sent data bytes and the slave
device has not cleared the RXNE bit resulting from the previous data byte transmitted.
When an overrun condition occurs:
• the OVR bit is set and an interrupt is generated if the ERRIE bit is set.
In this case, the receiver buffer contents will not be updated with the newly received data
from the master device. A read from the SPI_DR register returns this byte. All other
subsequently transmitted bytes are lost.
Clearing the OVR bit is done by a read from the SPI_DR register followed by a read access
to the SPI_SR register.
CRC error
This flag is used to verify the validity of the value received when the CRCEN bit in the
SPI_CR1 register is set. The CRCERR flag in the SPI_SR register is set if the value
received in the shift register does not match the receiver SPI_RXCRCR value.
.33
OUTPUT
TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING TRIGGER SAMPLING
3#+
OUTPUT
-/3)
$/.4#!2% -3"). ,3"). $/.4#!2% -3"). ,3").
INPUT
4)&2&%
AI
4X BUFFER
#(
"39 /62 -/$& #2# 5$2 4X% 2X.% &2%
%22 3)$%
BIT
-/3) 3$
-)3/
3HIFT REGISTER
)3EXT?3$
)3EXT?3$ ,3" FIRST #OMMUNICATION
BIT CONTROL
2X BUFFER
.3373
)3
-/$ )3%
30) ,3"
30% "2 "2 "2 -342 #0/, #0(!
BAUD RATE GENERATOR &IRST
#+
)3-/$
-#+
-#+/%/$$ )3$)6;= )3X#,+
-36
1. I2S2ext_SD and I2S3ext_SD are the extended SD pins that control the I2S full duplex mode.
The SPI could function as an audio I2S interface when the I2S capability is enabled (by
setting the I2SMOD bit in the SPI_I2SCFGR register). This interface uses almost the same
pins, flags and interrupts as the SPI.
The I2S shares three common pins with the SPI:
• SD: Serial Data (mapped on the MOSI pin) to transmit or receive the two time-
multiplexed data channels (in half-duplex mode only).
• WS: Word Select (mapped on the NSS pin) is the data control signal output in master
mode and input in slave mode.
• CK: Serial Clock (mapped on the SCK pin) is the serial clock output in master mode
and serial clock input in slave mode.
• I2S2ext_SD and I2S3ext_SD: additional pins (mapped on the MISO pin) to control the
I2S full duplex mode.
An additional pin could be used when a master clock output is needed for some external
audio devices:
• MCK: Master Clock (mapped separately) is used, when the I2S is configured in master
mode (and when the MCKOE bit in the SPI_I2SPR register is set), to output this
additional clock generated at a preconfigured frequency rate equal to 256 × FS, where
FS is the audio sampling frequency.
The I2S uses its own clock generator to produce the communication clock when it is set in
master mode. This clock generator is also the source of the master clock output. Two
additional registers are available in I2S mode. One is linked to the clock generator
configuration SPI_I2SPR and the other one is a generic I2S configuration register
SPI_I2SCFGR (audio standard, slave/master mode, data format, packet frame, clock
polarity, etc.).
The SPI_CR1 register and all CRC registers are not used in the I2S mode. Likewise, the
SSOE bit in the SPI_CR2 register and the MODF and CRCERR bits in the SPI_SR are not
used.
The I2S uses the same SPI register for data transfer (SPI_DR) in 16-bit wide mode.
30))3X 30)X?-/3))3X?3$INOUT
)3X?3#+
)3? 73
)3X?EXT )3X?EXT3$INOUT
-36
1. Where x can be 2 or 3.
I2Sx can operate in master mode. As a result:
• Only I2Sx can output SCK and WS in half duplex mode
• Only I2Sx can deliver SCK and WS to I2S2_ext and I2S3_ext in full duplex mode.
The extended I2Ss (I2Sx_ext) can be used only in full duplex mode. The I2Sx_ext operate
always in slave mode.
Both I2Sx and I2Sx_ext can be configured as transmitters or receivers.
Figure 210. I2S Philips protocol waveforms (16/32-bit full accuracy, CPOL = 0)
CK
WS
Transmission Reception
Channel left
Channel right
Data are latched on the falling edge of CK (for the transmitter) and are read on the rising
edge (for the receiver). The WS signal is also latched on the falling edge of CK.
Figure 211. I2S Philips standard waveforms (24-bit frame with CPOL = 0)
CK
WS
Transmission Reception
24-bit data 8-bit remaining
SD
0 forced
MSB LSB
This mode needs two write or read operations to/from the SPI_DR.
• In transmission mode:
if 0x8EAA33 has to be sent (24-bit):
0x8EAA 0x33XX
Only the 8 MSBs are sent to complete the 24 bits
8 LSB bits have no meaning and could be
anything
• In reception mode:
if data 0x8EAA33 is received:
First read from Data register Second read from Data register
0x8EAA 0x3300
Only the 8MSB are right
The 8 LSB will always be 00
Figure 214. I2S Philips standard (16-bit extended to 32-bit packet frame with
CPOL = 0)
CK
WS
Transmission Reception
16-bit data 16-bit remaining
SD
0 forced
MSB LSB
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, only one access to SPI_DR is required. The 16 remaining bits are
forced by hardware to 0x0000 to extend the data to 32-bit format.
If the data to transmit or the received data are 0x76A3 (0x76A30000 extended to 32-bit), the
operation shown in Figure 215 is required.
0X76A3
For transmission, each time an MSB is written to SPI_DR, the TXE flag is set and its
interrupt, if allowed, is generated to load SPI_DR with the new value to send. This takes
place even if 0x0000 have not yet been sent because it is done by hardware.
For reception, the RXNE flag is set and its interrupt, if allowed, is generated when the first
16 MSB half-word is received.
In this way, more time is provided between two write or read operations, which prevents
underrun or overrun conditions (depending on the direction of the data transfer).
Figure 216. MSB Justified 16-bit or 32-bit full-accuracy length with CPOL = 0
CK
WS
Transmission Reception
Channel left
Channel right
Data are latched on the falling edge of CK (for transmitter) and are read on the rising edge
(for the receiver).
CK
WS
Transmission Reception
Figure 218. MSB Justified 16-bit extended to 32-bit packet frame with CPOL = 0
CK
WS
Transmission Reception
CK
WS
Transmission Reception
Channel left
Channel right
CK
WS
Transmission Reception
• In transmission mode:
If data 0x3478AE have to be transmitted, two write operations to the SPI_DR register
are required from software or by DMA. The operations are shown below.
0xXX34 0x78AE
Only the 8 LSB bits of the half-word
are significant. Whatever the 8 MSBs
a field of 0x00 is forced instead
• In reception mode:
If data 0x3478AE are received, two successive read operations from SPI_DR are
required on each RXNE event.
0x0034 0x78AE
Only the 8 LSB bits of the half-word
are significant. Whatever the 8 MSBs,
a field of 0x00 is forced instead
Figure 223. LSB justified 16-bit extended to 32-bit packet frame with CPOL = 0
CK
WS
Transmission Reception
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, Only one access to SPI_DR is required. The 16 remaining bits are
forced by hardware to 0x0000 to extend the data to 32-bit format. In this case it corresponds
to the half-word MSB.
If the data to transmit or the received data are 0x76A3 (0x0000 76A3 extended to 32-bit),
the operation shown in Figure 224 is required.
Figure 224. Example of LSB justified 16-bit extended to 32-bit packet frame
0X76A3
In transmission mode, when TXE is asserted, the application has to write the data to be
transmitted (in this case 0x76A3). The 0x000 field is transmitted first (extension on 32-bit).
TXE is asserted again as soon as the effective data (0x76A3) is sent on SD.
In reception mode, RXNE is asserted as soon as the significant half-word is received (and
not the 0x0000 field).
In this way, more time is provided between two write or read operations to prevent underrun
or overrun conditions.
PCM standard
For the PCM standard, there is no need to use channel-side information. The two PCM
modes (short and long frame) are available and configurable using the PCMSYNC bit in
SPI_I2SCFGR.
WS
short
frame
fixed to 13-bit
WS
long
frame
SD 16-bit
MSB LSB MSB
For long frame synchronization, the WS signal assertion time is fixed 13 bits in master
mode.
For short frame synchronization, the WS synchronization signal is only one cycle long.
Figure 226. PCM standard waveforms (16-bit extended to 32-bit packet frame)
CK
WS
short
frame
fixed to 13-bit
WS
long
frame
SD 16-bit
MSB LSB
Note: For both modes (master and slave) and for both synchronizations (short and long), the
number of bits between two consecutive pieces of data (and so two synchronization signals)
needs to be specified (DATLEN and CHLEN bits in the SPI_I2SCFGR register) even in
slave mode.
32-bits or 64-bits
FS
sampling point
sampling point
When the master mode is configured, a specific action needs to be taken to properly
program the linear divider in order to communicate with the desired audio frequency.
MCK
0 CK
I2SxCLK 8-bit Linear
Divider by 4 Div2 0 1
Divider +
reshaping stage 1
MCKOE
1. Where x could be 2 or 3.
Figure 227 presents the communication clock architecture. To achieve high-quality audio
performance, the I2SxCLK clock source can be either the PLLI2S output (through R division
factor) or an external clock (mapped to I2S_CKIN pin).
The audio sampling frequency can be 192 kHz, 96 kHz, or 48 kHz. In order to reach the
desired frequency, the linear divider needs to be programmed according to the formulas
below:
When the master clock is generated (MCKOE in the SPI_I2SPR register is set):
FS = I2SxCLK / [(16*2)*((2*I2SDIV)+ODD)*8)] when the channel frame is 16-bit wide
FS = I2SxCLK / [(32*2)*((2*I2SDIV)+ODD)*4)] when the channel frame is 32-bit wide
When the master clock is disabled (MCKOE bit cleared):
FS = I2SxCLK / [(16*2)*((2*I2SDIV)+ODD))] when the channel frame is 16-bit wide
FS = I2SxCLK / [(32*2)*((2*I2SDIV)+ODD))] when the channel frame is 32-bit wide
Table 89 provides example precision values for different clock configurations.
Note: Other configurations are possible that allow optimum clock precision.
Table 89. Audio frequency precision (for PLLM VCO = 1 MHz or 2 MHz)(1)
Master Target fS Data
PLLI2SN PLLI2SR I2SDIV I2SODD Real fS (Hz) Error
clock (Hz) format
Procedure
1. Select the I2SDIV[7:0] bits in the SPI_I2SPR register to define the serial clock baud
rate to reach the proper audio sample frequency. The ODD bit in the SPI_I2SPR
register also has to be defined.
2. Select the CKPOL bit to define the steady level for the communication clock. Set the
MCKOE bit in the SPI_I2SPR register if the master clock MCK needs to be provided to
the external DAC/ADC audio component (the I2SDIV and ODD values should be
computed depending on the state of the MCK output, for more details refer to
Section 20.4.4: Clock generator).
3. Set the I2SMOD bit in SPI_I2SCFGR to activate the I2S functionalities and choose the
I2S standard through the I2SSTD[1:0] and PCMSYNC bits, the data length through the
DATLEN[1:0] bits and the number of bits per channel by configuring the CHLEN bit.
Select also the I2S master mode and direction (Transmitter or Receiver) through the
I2SCFG[1:0] bits in the SPI_I2SCFGR register.
4. If needed, select all the potential interruption sources and the DMA capabilities by
writing the SPI_CR2 register.
5. The I2SE bit in SPI_I2SCFGR register must be set.
WS and CK are configured in output mode. MCK is also an output, if the MCKOE bit in
SPI_I2SPR is set.
Transmission sequence
The transmission sequence begins when a half-word is written into the Tx buffer.
Assumedly, the first data written into the Tx buffer correspond to the channel Left data.
When data are transferred from the Tx buffer to the shift register, TXE is set and data
corresponding to the channel Right have to be written into the Tx buffer. The CHSIDE flag
indicates which channel is to be transmitted. It has a meaning when the TXE flag is set
because the CHSIDE flag is updated when TXE goes high.
A full frame has to be considered as a Left channel data transmission followed by a Right
channel data transmission. It is not possible to have a partial frame where only the left
channel is sent.
The data half-word is parallel loaded into the 16-bit shift register during the first bit
transmission, and then shifted out, serially, to the MOSI/SD pin, MSB first. The TXE flag is
set after each transfer from the Tx buffer to the shift register and an interrupt is generated if
the TXEIE bit in the SPI_CR2 register is set.
For more details about the write operations depending on the I2S standard mode selected,
refer to Section 20.4.3: Supported audio protocols).
To ensure a continuous audio data transmission, it is mandatory to write the SPI_DR with
the next data to transmit before the end of the current transmission.
To switch off the I2S, by clearing I2SE, it is mandatory to wait for TXE = 1 and BSY = 0.
Reception sequence
The operating mode is the same as for the transmission mode except for the point 3 (refer to
the procedure described in Section 20.4.5: I2S master mode), where the configuration
should set the master reception mode through the I2SCFG[1:0] bits.
Whatever the data or channel length, the audio data are received by 16-bit packets. This
means that each time the Rx buffer is full, the RXNE flag is set and an interrupt is generated
if the RXNEIE bit is set in SPI_CR2 register. Depending on the data and channel length
configuration, the audio value received for a right or left channel may result from one or two
receptions into the Rx buffer.
Clearing the RXNE bit is performed by reading the SPI_DR register.
CHSIDE is updated after each reception. It is sensitive to the WS signal generated by the
I2S cell.
For more details about the read operations depending on the I2S standard mode selected,
refer to Section 20.4.3: Supported audio protocols.
If data are received while the previously received data have not been read yet, an overrun is
generated and the OVR flag is set. If the ERRIE bit is set in the SPI_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S, specific actions are required to ensure that the I2S completes the
transfer cycle properly without initiating a new data transfer. The sequence depends on the
configuration of the data and channel lengths, and on the audio protocol mode selected. In
the case of:
• 16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1)
using the LSB justified mode (I2SSTD = 10)
a) Wait for the second to last RXNE = 1 (n – 1)
b) Then wait 17 I2S clock cycles (using a software loop)
c) Disable the I2S (I2SE = 0)
• 16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1) in
MSB justified, I2S or PCM modes (I2SSTD = 00, I2SSTD = 01 or I2SSTD = 11,
respectively)
a) Wait for the last RXNE
b) Then wait 1 I2S clock cycle (using a software loop)
c) Disable the I2S (I2SE = 0)
• For all other combinations of DATLEN and CHLEN, whatever the audio mode selected
through the I2SSTD bits, carry out the following sequence to switch off the I2S:
a) Wait for the second to last RXNE = 1 (n – 1)
b) Then wait one I2S clock cycle (using a software loop)
c) Disable the I2S (I2SE = 0)
Note: The BSY flag is kept low during transfers.
1. Set the I2SMOD bit in the SPI_I2SCFGR register to reach the I2S functionalities and
choose the I2S standard through the I2SSTD[1:0] bits, the data length through the
DATLEN[1:0] bits and the number of bits per channel for the frame configuring the
CHLEN bit. Select also the mode (transmission or reception) for the slave through the
I2SCFG[1:0] bits in SPI_I2SCFGR register.
2. If needed, select all the potential interrupt sources and the DMA capabilities by writing
the SPI_CR2 register.
3. The I2SE bit in SPI_I2SCFGR register must be set.
Transmission sequence
The transmission sequence begins when the external master device sends the clock and
when the NSS_WS signal requests the transfer of data. The slave has to be enabled before
the external master starts the communication. The I2S data register has to be loaded before
the master initiates the communication.
For the I2S, MSB justified and LSB justified modes, the first data item to be written into the
data register corresponds to the data for the left channel. When the communication starts,
the data are transferred from the Tx buffer to the shift register. The TXE flag is then set in
order to request the right channel data to be written into the I2S data register.
The CHSIDE flag indicates which channel is to be transmitted. Compared to the master
transmission mode, in slave mode, CHSIDE is sensitive to the WS signal coming from the
external master. This means that the slave needs to be ready to transmit the first data
before the clock is generated by the master. WS assertion corresponds to left channel
transmitted first.
Note: The I2SE has to be written at least two PCLK cycles before the first clock of the master
comes on the CK line.
The data half-word is parallel-loaded into the 16-bit shift register (from the internal bus)
during the first bit transmission, and then shifted out serially to the MOSI/SD pin MSB first.
The TXE flag is set after each transfer from the Tx buffer to the shift register and an interrupt
is generated if the TXEIE bit in the SPI_CR2 register is set.
Note that the TXE flag should be checked to be at 1 before attempting to write the Tx buffer.
For more details about the write operations depending on the I2S standard mode selected,
refer to Section 20.4.3: Supported audio protocols.
To secure a continuous audio data transmission, it is mandatory to write the SPI_DR
register with the next data to transmit before the end of the current transmission. An
underrun flag is set and an interrupt may be generated if the data are not written into the
SPI_DR register before the first clock edge of the next data communication. This indicates
to the software that the transferred data are wrong. If the ERRIE bit is set into the SPI_CR2
register, an interrupt is generated when the UDR flag in the SPI_SR register goes high. In
this case, it is mandatory to switch off the I2S and to restart a data transfer starting from the
left channel.
To switch off the I2S, by clearing the I2SE bit, it is mandatory to wait for TXE = 1 and BSY =
0.
Reception sequence
The operating mode is the same as for the transmission mode except for the point 1 (refer to
the procedure described in Section 20.4.6: I2S slave mode), where the configuration should
set the master reception mode using the I2SCFG[1:0] bits in the SPI_I2SCFGR register.
Whatever the data length or the channel length, the audio data are received by 16-bit
packets. This means that each time the RX buffer is full, the RXNE flag in the SPI_SR
register is set and an interrupt is generated if the RXNEIE bit is set in the SPI_CR2 register.
Depending on the data length and channel length configuration, the audio value received for
a right or left channel may result from one or two receptions into the RX buffer.
The CHSIDE flag is updated each time data are received to be read from SPI_DR. It is
sensitive to the external WS line managed by the external master component.
Clearing the RXNE bit is performed by reading the SPI_DR register.
For more details about the read operations depending the I2S standard mode selected, refer
to Section 20.4.3: Supported audio protocols.
If data are received while the precedent received data have not yet been read, an overrun is
generated and the OVR flag is set. If the bit ERRIE is set in the SPI_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S in reception mode, I2SE has to be cleared immediately after receiving
the last RXNE = 1.
Note: The external master components should have the capability of sending/receiving data in 16-
bit or 32-bit packets via an audio channel.
change. If the synchronization is lost, to recover from this state and resynchronize the
external master device with the I2S slave device, follow the steps below:
1. Disable the I2S
2. Re-enable it when the correct level is detected on the WS line (WS line is high in I2S
mode, or low for MSB- or LSB-justified or PCM modes).
Desynchronization between the master and slave device may be due to noisy environment
on the SCK communication clock or on the WS frame synchronization line. An error interrupt
can be generated if the ERRIE bit is set. The desynchronization flag (FRE) is cleared by
software when the status register is read.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
BIDIMODE
CRCNEXT
LSBFIRST
RXONLY
CRCEN
BIDIOE
MSTR
CPHA
CPOL
SSM
SPE
DFF
SSI
SPI_CR1 BR [2:0]
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CRCERR
CHSIDE
MODF
RXNE
OVR
UDR
FRE
BSY
TXE
SPI_SR
0x08 Reserved
Reset value 0 0 0 0 0 0 0 1 0
SPI_DR DR[15:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPI_CRCPR CRCPOLY[15:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
SPI_RXCRCR RxCRC[15:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPI_TXCRCR TxCRC[15:0]
0x18 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PCMSYNC
DATLEN
I2SMOD
I2SCFG
I2SSTD
CHLEN
CKPOL
I2SE
Reserved
SPI_I2SCFGR
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
MCKOE
ODD
SPI_I2SPR I2SDIV
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 1 0
Data transfers to/from SD/SDIO memory cards are done in data blocks. Data transfers
to/from MMC are done data blocks or streams. Data transfers to/from the CE-ATA Devices
are done in data blocks.
SDIO_D
ai14734
SDIO_D Data block crc Data block crc Data block crc
ai14735
SDIO_D Busy Data block crc Busy Data block crc Busy
ai14737
Note: The SDIO will not send any data as long as the Busy signal is asserted (SDIO_D0 pulled
low).
From host to
card(s) From card to host Stop command
stops data transfer
Data from card to host
ai14738
From host to
card(s) From card to host Stop command
stops data transfer
Data from host to card
ai14739
3$)/ 3$)/?#+
)NTERRUPTS AND
$-! REQUEST 3$)/?#-$
0#,+ 3$)/#,+
AI
By default SDIO_D0 is used for data transfer. After initialization, the host can change the
databus width.
If a MultiMediaCard is connected to the bus, SDIO_D0, SDIO_D[3:0] or SDIO_D[7:0] can be
used for data transfer. MMC V3.31 or previous, supports only 1 bit of data so only SDIO_D0
can be used.
If an SD or SD I/O card is connected to the bus, data transfer can be configured by the host
to use SDIO_D0 or SDIO_D[3:0]. All data lines are operating in push-pull mode.
SDIO_CMD has two operational modes:
• Open-drain for initialization (only for MMCV3.31 or previous)
• Push-pull for command transfer (SD/SD I/O card MMC4.2 use push-pull drivers also for
initialization)
SDIO_CK is the clock to the card: one bit is transferred on both command and data lines
with each clock cycle. The clock frequency can vary between 0 MHz and 20 MHz (for a
MultiMediaCard V3.31), between 0 and 48 MHz for a MultiMediaCard V4.0/4.2, or between
0 and 25 MHz (for an SD/SD I/O card).
The SDIO uses two clock signals:
• SDIO adapter clock (SDIOCLK = 48 MHz)
• APB2 bus clock (PCLK2)
PCLK2 and SDIO_CK clock frequencies must respect the following condition:
The signals shown in Table 92 are used on the MultiMediaCard/SD/SD I/O card bus.
3$)/ ADAPTER
#OMMAND
#ARD BUS
3$)/?#-$
PATH
!DAPTER
REGISTERS
4O !0"
INTERFACE $ATA PATH
3$)/?$;=
&)&/
The SDIO adapter is a multimedia/secure digital memory card bus master that provides an
interface to a multimedia card stack or to a secure digital memory card. It consists of five
subunits:
• Adapter register block
• Control unit
• Command path
• Data path
• Data FIFO
Note: The adapter registers and FIFO use the APB2 bus clock domain (PCLK2). The control unit,
command path and data path use the SDIO adapter clock domain (SDIOCLK).
Control unit
The control unit contains the power management functions and the clock divider for the
memory card clock.
There are three power phases:
• power-off
• power-up
• power-on
Control unit
Power management
ai14804
The control unit is illustrated in Figure 236. It consists of a power management subunit and
a clock management subunit.
The power management subunit disables the card bus output signals during the power-off
and power-up phases.
The clock management subunit generates and controls the SDIO_CK signal. The SDIO_CK
output can use either the clock divide or the clock bypass mode. The clock output is
inactive:
• after reset
• during the power-off or power-up phases
• if the power saving mode is enabled and the card bus is in the Idle state (eight clock
periods after both the command and data path subunits enter the Idle phase)
Command path
The command path unit sends commands to and receives responses from the cards.
!DAPTER REGISTERS
3$)/?#-$IN
#-$
!RGUMENT
#2# 3$)/?#-$OUT
3HIFT
#-$ REGISTER
AI
CE-ATA Command
On reset Completion signal
received or Wait_CPL
CPSM disabled or
Command CRC failed
Pend
Enabled and
CPSM Disabled or
command start Receive
CPSM disabled or command timeout
no response
Last Data
Response
started
Send
When the Wait state is entered, the command timer starts running. If the timeout is reached
before the CPSM moves to the Receive state, the timeout flag is set and the Idle state is
entered.
Note: The command timeout has a fixed value of 64 SDIO_CK clock periods.
If the interrupt bit is set in the command register, the timer is disabled and the CPSM waits
for an interrupt request from one of the cards. If a pending bit is set in the command register,
the CPSM enters the Pend state, and waits for a CmdPend signal from the data path
subunit. When CmdPend is detected, the CPSM moves to the Send state. This enables the
data counter to trigger the stop command transmission.
Note: The CPSM remains in the Idle state for at least eight SDIO_CK periods to meet the NCC and
NRC timing constraints. NCC is the minimum delay between two host commands, and NRC is
the minimum delay between the host command and the card response.
SDIO_CMD Hi-Z Controller drives Hi-Z Card drives Hi-Z Controller drives
ai14707
• Command format
– Command: a command is a token that starts an operation. Command are sent
from the host either to a single card (addressed command) or to all connected
cards (broadcast command are available for MMC V3.31 or previous). Commands
are transferred serially on the CMD line. All commands have a fixed length of 48
bits. The general format for a command token for MultiMediaCards, SD-Memory
cards and SDIO-Cards is shown in Table 93. CE-ATA commands are an extension
of MMC commands V4.2, and so have the same format.
The command path operates in a half-duplex mode, so that commands and
responses can either be sent or received. If the CPSM is not in the Send state, the
SDIO_CMD output is in the Hi-Z state, as shown in Figure 239 on page 611. Data
on SDIO_CMD are synchronous with the rising edge of SDIO_CK. Table shows
the command format.
47 1 0 Start bit
46 1 1 Transmission bit
[45:40] 6 - Command index
[39:8] 32 - Argument
[7:1] 7 - CRC7
0 1 1 End bit
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 - Command index
[39:8] 32 - Argument
[7:1] 7 - CRC7(or 1111111)
0 1 1 End bit
The command register contains the command index (six bits sent to a card) and the
command type. These determine whether the command requires a response, and whether
the response is 48 or 136 bits long (see Section 21.9.4 on page 646). The command path
implements the status flags shown in Table 96:
The CRC generator calculates the CRC checksum for all bits before the CRC code. This
includes the start bit, transmitter bit, command index, and command argument (or card
status). The CRC checksum is calculated for the first 120 bits of CID or CSD for the long
response format. Note that the start bit, transmitter bit and the six reserved bits are not used
in the CRC calculation.
The CRC checksum is a 7-bit value:
CRC[6:0] = Remainder [(M(x) * x7) / G(x)]
G(x) = x7 + x3 + 1
M(x) = (start bit) * x39 + ... + (last bit before CRC) * x0, or
M(x) = (start bit) * x119 + ... + (last bit before CRC) * x0
Data path
The data path subunit transfers data to and from cards. Figure 240 shows a block diagram
of the data path.
Data FIFO
SDIO_Din[7:0]
Transmit
CRC SDIO_Dout[7:0]
Shift
register
Receive
ai14808
The card databus width can be programmed using the clock control register. If the 4-bit wide
bus mode is enabled, data is transferred at four bits per clock cycle over all four data signals
(SDIO_D[3:0]). If the 8-bit wide bus mode is enabled, data is transferred at eight bits per
clock cycle over all eight data signals (SDIO_D[7:0]). If the wide bus mode is not enabled,
only one bit per clock cycle is transferred over SDIO_D0.
Depending on the transfer direction (send or receive), the data path state machine (DPSM)
moves to the Wait_S or Wait_R state when it is enabled:
• Send: the DPSM moves to the Wait_S state. If there is data in the transmit FIFO, the
DPSM moves to the Send state, and the data path subunit starts sending data to a
card.
• Receive: the DPSM moves to the Wait_R state and waits for a start bit. When it
receives a start bit, the DPSM moves to the Receive state, and the data path subunit
starts receiving data from a card.
Data path state machine (DPSM)
The DPSM operates at SDIO_CK frequency. Data on the card bus signals is synchronous to
the rising edge of SDIO_CK. The DPSM has six states, as shown in Figure 241: Data path
state machine (DPSM).
ReadWait Stop
Disabled or
end of data
Disabled or
Busy Rx FIFO empty or timeout or
start bit error
Not busy
Enable and send Data received and
Wait_R Read Wait Started and
SD I/O mode enabled
End of packet
Send
Receive
ai14809b
• Idle: the data path is inactive, and the SDIO_D[7:0] outputs are in Hi-Z. When the data
control register is written and the enable bit is set, the DPSM loads the data counter
with a new value and, depending on the data direction bit, moves to either the Wait_S
or the Wait_R state.
• Wait_R: if the data counter equals zero, the DPSM moves to the Idle state when the
receive FIFO is empty. If the data counter is not zero, the DPSM waits for a start bit on
SDIO_D. The DPSM moves to the Receive state if it receives a start bit before a
timeout, and loads the data block counter. If it reaches a timeout before it detects a
start bit, or a start bit error occurs, it moves to the Idle state and sets the timeout status
flag.
• Receive: serial data received from a card is packed in bytes and written to the data
FIFO. Depending on the transfer mode bit in the data control register, the data transfer
mode can be either block or stream:
– In block mode, when the data block counter reaches zero, the DPSM waits until it
receives the CRC code. If the received code matches the internally generated
CRC code, the DPSM moves to the Wait_R state. If not, the CRC fail status flag is
set and the DPSM moves to the Idle state.
– In stream mode, the DPSM receives data while the data counter is not zero. When
the counter is zero, the remaining data in the shift register is written to the data
FIFO, and the DPSM moves to the Wait_R state.
If a FIFO overrun error occurs, the DPSM sets the FIFO error flag and moves to the
Idle state:
• Wait_S: the DPSM moves to the Idle state if the data counter is zero. If not, it waits until
the data FIFO empty flag is deasserted, and moves to the Send state.
Note: The DPSM remains in the Wait_S state for at least two clock periods to meet the NWR timing
requirements, where NWR is the number of clock cycles between the reception of the card
response and the start of the data transfer from the host.
• Send: the DPSM starts sending data to a card. Depending on the transfer mode bit in
the data control register, the data transfer mode can be either block or stream:
– In block mode, when the data block counter reaches zero, the DPSM sends an
internally generated CRC code and end bit, and moves to the Busy state.
– In stream mode, the DPSM sends data to a card while the enable bit is high and
the data counter is not zero. It then moves to the Idle state.
If a FIFO underrun error occurs, the DPSM sets the FIFO error flag and moves to the
Idle state.
• Busy: the DPSM waits for the CRC status flag:
– If it does not receive a positive CRC status, it moves to the Idle state and sets the
CRC fail status flag.
– If it receives a positive CRC status, it moves to the Wait_S state if SDIO_D0 is not
low (the card is not busy).
If a timeout occurs while the DPSM is in the Busy state, it sets the data timeout flag and
moves to the Idle state.
The data timer is enabled when the DPSM is in the Wait_R or Busy state, and
generates the data timeout error:
– When transmitting data, the timeout occurs if the DPSM stays in the Busy state for
longer than the programmed timeout period
– When receiving data, the timeout occurs if the end of the data is not true, and if the
DPSM stays in the Wait_R state for longer than the programmed timeout period.
• Data: data can be transferred from the card to the host or vice versa. Data is
transferred via the data lines. They are stored in a FIFO of 32 words, each word is 32
bits wide.
Data FIFO
The data FIFO (first-in-first-out) subunit is a data buffer with a transmit and receive unit.
The FIFO contains a 32-bit wide, 32-word deep data buffer, and transmit and receive logic.
Because the data FIFO operates in the APB2 clock domain (PCLK2), all signals from the
subunits in the SDIO clock domain (SDIOCLK) are resynchronized.
Depending on the TXACT and RXACT flags, the FIFO can be disabled, transmit enabled, or
receive enabled. TXACT and RXACT are driven by the data path subunit and are mutually
exclusive:
– The transmit FIFO refers to the transmit logic and data buffer when TXACT is
asserted
– The receive FIFO refers to the receive logic and data buffer when RXACT is
asserted
• Transmit FIFO:
Data can be written to the transmit FIFO through the APB2 interface when the SDIO is
enabled for transmission.
The transmit FIFO is accessible via 32 sequential addresses. The transmit FIFO
contains a data output register that holds the data word pointed to by the read pointer.
When the data path subunit has loaded its shift register, it increments the read pointer
and drives new data out.
If the transmit FIFO is disabled, all status flags are deasserted. The data path subunit
asserts TXACT when it transmits data.
TXFIFOF Set to high when all 32 transmit FIFO words contain valid data.
TXFIFOE Set to high when the transmit FIFO does not contain valid data.
Set to high when 8 or more transmit FIFO words are empty. This flag can be used
TXFIFOHE
as a DMA request.
Set to high when the transmit FIFO contains valid data. This flag is the inverse of
TXDAVL
the TXFIFOE flag.
Set to high when an underrun error occurs. This flag is cleared by writing to the
TXUNDERR
SDIO Clear register.
• Receive FIFO
When the data path subunit receives a word of data, it drives the data on the write
databus. The write pointer is incremented after the write operation completes. On the
read side, the contents of the FIFO word pointed to by the current value of the read
pointer is driven onto the read databus. If the receive FIFO is disabled, all status flags
are deasserted, and the read and write pointers are reset. The data path subunit
asserts RXACT when it receives data. Table 99 lists the receive FIFO status flags. The
receive FIFO is accessible via 32 sequential addresses.
RXFIFOF Set to high when all 32 receive FIFO words contain valid data
RXFIFOE Set to high when the receive FIFO does not contain valid data.
Set to high when 8 or more receive FIFO words contain valid data. This flag can be
RXFIFOHF
used as a DMA request.
Set to high when the receive FIFO is not empty. This flag is the inverse of the
RXDAVL
RXFIFOE flag.
Set to high when an overrun error occurs. This flag is cleared by writing to the SDIO
RXOVERR
Clear register.
SDIO interrupts
The interrupt logic generates an interrupt request signal that is asserted when at least one
of the selected status flags is high. A mask register is provided to allow selection of the
conditions that will generate an interrupt. A status flag generates the interrupt request if a
corresponding mask flag is set.
SDIO/DMA interface - procedure for data transfers between the SDIO and
memory
In the example shown, the transfer is from the SDIO host controller to an MMC (512 bytes
using CMD24 (WRITE_BLOCK). The SDIO FIFO is filled by data stored in a memory using
the DMA controller.
1. Do the card identification process
2. Increase the SDIO_CK frequency
3. Select the card by sending CMD7
4. Configure the DMA2 as follows:
a) Enable DMA2 controller and clear any pending interrupts.
b) Program the DMA2_Stream3 or DMA2_Stream6 Channel4 source address
register with the memory location’s base address and DMA2_Stream3 or
Cards that store the card identification number (CID) and card specific data (CSD) in the
payload memory are able to communicate this information only under data-transfer VDD
conditions. When the SDIO card host module and the card have incompatible VDD ranges,
the card is not able to complete the identification cycle and cannot send CSD data. For this
purpose, the special commands, SEND_OP_COND (CMD1), SD_APP_OP_COND (ACMD41
for SD Memory), and IO_SEND_OP_COND (CMD5 for SD I/O), are designed to provide a
mechanism to identify and reject cards that do not match the VDD range desired by the
SDIO card host. The SDIO card host sends the required VDD voltage window as the
operand of these commands. Cards that cannot perform data transfer in the specified range
disconnect from the bus and go to the inactive state.
By using these commands without including the voltage range as the operand, the SDIO
card host can query each card and determine the common voltage range before placing out-
of-range cards in the inactive state. This query is used when the SDIO card host is able to
select a common voltage range or when the user requires notification that cards are not
usable.
select a different card), which will place the card in the Disconnect state and release the
SDIO_D line(s) without interrupting the write operation. When selecting the card again, it will
reactivate busy indication by pulling SDIO_D to low if programming is still in progress and
the write buffer is unavailable.
The maximum clock frequency for a stream write operation is given by the following
equation fields of the card-specific data register:
8 × 2 writebllen ) ( – NSAC ))
Maximumspeed = MIN (TRANSPEED,(-------------------------------------------------------------------------
TAAC × R2WFACTOR
The host can erase a contiguous range of Erase Groups. Starting the erase process is a
three-step sequence.
First the host defines the start address of the range using the ERASE_GROUP_START
(CMD35) command, next it defines the last address of the range using the
ERASE_GROUP_END (CMD36) command and, finally, it starts the erase process by issuing
the ERASE (CMD38) command. The address field in the erase commands is an Erase
Group address in byte units. The card ignores all LSBs below the Erase Group size,
effectively rounding the address down to the Erase Group boundary.
If an erase command is received out of sequence, the card sets the ERASE_SEQ_ERROR
bit in the status register and resets the whole sequence.
If an out-of-sequence (neither of the erase commands, except SEND_STATUS) command
received, the card sets the ERASE_RESET status bit in the status register, resets the erase
sequence and executes the last command.
If the erase range includes write protected blocks, they are left intact and only unprotected
blocks are erased. The WP_ERASE_SKIP status bit in the status register is set.
The card indicates that an erase is in progress by holding SDIO_D low. The actual erase
time may be quite long, and the host may issue CMD7 to deselect the card.
Password protect
The password protection feature enables the SDIO card host module to lock and unlock a
card with a password. The password is stored in the 128-bit PWD register and its size is set
in the 8-bit PWD_LEN register. These registers are nonvolatile so that a power cycle does
not erase them. Locked cards respond to and execute certain commands. This means that
the SDIO card host module is allowed to reset, initialize, select, and query for status,
however it is not allowed to access data on the card. When the password is set (as indicated
by a nonzero value of PWD_LEN), the card is locked automatically after power-up. As with
the CSD and CID register write commands, the lock/unlock commands are available in the
transfer state only. In this state, the command does not include an address argument and
the card must be selected before using it. The card lock/unlock commands have the
structure and bus transaction types of a regular single-block write command. The
transferred data block includes all of the required information for the command (the
password setting mode, the PWD itself, and card lock/unlock). The command data block
size is defined by the SDIO card host module before it sends the card lock/unlock
command, and has the structure shown in Table 113.
The bit settings are as follows:
• ERASE: setting it forces an erase operation. All other bits must be zero, and only the
command byte is sent
• LOCK_UNLOCK: setting it locks the card. LOCK_UNLOCK can be set simultaneously
with SET_PWD, however not with CLR_PWD
• CLR_PWD: setting it clears the password data
• SET_PWD: setting it saves the password data to memory
• PWD_LEN: it defines the length of the password in bytes
• PWD: the password (new or currently used, depending on the command)
The following sections list the command sequences to set/reset a password, lock/unlock the
card, and force an erase.
the new one, and the PWD field includes the old password (currently used) followed by
the new password.
4. When the password is matched, the new password and its size are saved into the PWD
and PWD_LEN fields, respectively. When the old password sent does not correspond
(in size and/or content) to the expected password, the LOCK_UNLOCK_FAILED error
bit is set in the card status register, and the password is not changed.
The password length field (PWD_LEN) indicates whether a password is currently set. When
this field is nonzero, there is a password set and the card locks itself after power-up. It is
possible to lock the card immediately in the current power session by setting the
LOCK_UNLOCK bit (while setting the password) or sending an additional command for card
locking.
Locking a card
1. Select a card (SELECT/DESELECT_CARD, CMD7), if none is already selected.
2. Define the block length (SET_BLOCKLEN, CMD16) to send, given by the 8-bit card
lock/unlock mode (byte 0 in Table 113), the 8-bit PWD_LEN, and the number of bytes
of the current password.
3. Send LOCK/UNLOCK (CMD42) with the appropriate data block size on the data line
including the 16-bit CRC. The data block indicates the mode (LOCK_UNLOCK = 1), the
length (PWD_LEN), and the password (PWD) itself.
4. When the password is matched, the card is locked and the CARD_IS_LOCKED status
bit is set in the card status register. When the password sent does not correspond (in
size and/or content) to the expected password, the LOCK_UNLOCK_FAILED error bit
is set in the card status register, and the lock fails.
It is possible to set the password and to lock the card in the same sequence. In this case,
the SDIO card host module performs all the required steps for setting the password (see
Setting the password on page 624), however it is necessary to set the LOCK_UNLOCK bit
in Step 3 when the new password command is sent.
When the password is previously set (PWD_LEN is not 0), the card is locked automatically
after power-on reset. An attempt to lock a locked card or to lock a card that does not have a
password fails and the LOCK_UNLOCK_FAILED error bit is set in the card status register.
Forcing erase
If the user has forgotten the password (PWD content), it is possible to access the card after
clearing all the data on the card. This forced erase operation erases all card data and all
password data.
1. Select a card (SELECT/DESELECT_CARD, CMD7), if none is already selected.
2. Set the block length (SET_BLOCKLEN, CMD16) to 1 byte. Only the 8-bit card
lock/unlock byte (byte 0 in Table 113) is sent.
3. Send LOCK/UNLOCK (CMD42) with the appropriate data byte on the data line including
the 16-bit CRC. The data block indicates the mode (ERASE = 1). All other bits must be
zero.
4. When the ERASE bit is the only bit set in the data field, all card contents are erased,
including the PWD and PWD_LEN fields, and the card is no longer locked. When any
other bits are set, the LOCK_UNLOCK_FAILED error bit is set in the card status
register and the card retains all of its data, and remains locked.
An attempt to use a force erase on an unlocked card fails and the LOCK_UNLOCK_FAILED
error bit is set in the card status register.
Type:
• E: error bit
• S: status bit
• R: detected and set for the actual command response
• X: detected and set during command execution. The SDIO card host must poll the card
by issuing the status command to read these bits.
Clear condition:
• A: according to the card current state
• B: always related to the previous command. Reception of a valid command clears it
(with a delay of one command)
• C: clear by read
‘0’ = card
When set, signals that the card is locked
25 CARD_IS_LOCKED SR unlocked A
by the host
‘1’ = card locked
Set when a sequence or password error
LOCK_UNLOCK_ ’0’= no error
24 EX has been detected in lock/unlock card C
FAILED ’1’= error
command
’0’= no error The CRC check of the previous command
23 COM_CRC_ERROR ER B
’1’= error failed.
’0’= no error
22 ILLEGAL_COMMAND ER Command not legal for the card state B
’1’= error
’0’= success Card internal ECC was applied but failed
21 CARD_ECC_FAILED EX C
’1’= failure to correct the data.
(Undefined by the standard) A card error
’0’= no error
20 CC_ERROR ER occurred, which is not related to the host C
’1’= error
command.
(Undefined by the standard) A generic
’0’= no error card error related to the (and detected
19 ERROR EX C
’1’= error during) execution of the last host
command (e.g. read or write failures).
18 Reserved
17 Reserved
Can be either of the following errors:
– The CID register has already been
written and cannot be overwritten
’0’= no error ‘1’= – The read-only section of the CSD does C
16 CID/CSD_OVERWRITE EX
error not match the card contents
– An attempt to reverse the copy (set as
original) or permanent WP
(unprotected) bits was made
0 = Idle
1 = Ready
2 = Ident
The state of the card when receiving the
3 = Stby
command. If the command execution
4 = Tran
causes a state change, it will be visible to
12:9 CURRENT_STATE SR 5 = Data B
the host in the response on the next
6 = Rcv
command. The four bits are interpreted as
7 = Prg
a binary number between 0 and 15.
8 = Dis
9 = Btst
10-15 = reserved
’0’= not ready ‘1’ Corresponds to buffer empty signalling on
8 READY_FOR_DATA SR -
= ready the bus
If set, the card did not switch to the
’0’= no error
7 SWITCH_ERROR EX expected mode as requested by the B
’1’= switch error
SWITCH command
6 Reserved
The card will expect ACMD, or an
‘0’ = Disabled
5 APP_CMD SR indication that the command has been C
‘1’ = Enabled
interpreted as ACMD
4 Reserved for SD I/O Card
’0’= no error Error in the sequence of the
3 AKE_SEQ_ERROR ER C
’1’= error authentication process
2 Reserved for application specific commands
1
Reserved for manufacturer test mode
0
Clear condition:
• A: according to the card current state
• B: always related to the previous command. Reception of a valid command clears it
(with a delay of one command)
• C: clear by read
SIZE_OF_PROTECTED_AREA
Setting this field differs between standard- and high-capacity cards. In the case of a
standard-capacity card, the capacity of protected area is calculated as follows:
Protected area = SIZE_OF_PROTECTED_AREA_* MULT * BLOCK_LEN.
SIZE_OF_PROTECTED_AREA is specified by the unit in MULT*BLOCK_LEN.
In the case of a high-capacity card, the capacity of protected area is specified in this field:
Protected area = SIZE_OF_PROTECTED_AREA
SIZE_OF_PROTECTED_AREA is specified by the unit in bytes.
SPEED_CLASS
This 8-bit field indicates the speed class and the value can be calculated by PW/2 (where
PW is the write performance).
00h Class 0
01h Class 2
02h Class 4
03h Class 6
04h – FFh Reserved
PERFORMANCE_MOVE
This 8-bit field indicates Pm (performance move) and the value can be set by 1 [MB/sec]
steps. If the card does not move used RUs (recording units), Pm should be considered as
infinity. Setting the field to FFh means infinity.
AU_SIZE
This 4-bit field indicates the AU size and the value can be selected in the power of 2 base
from 16 KB.
The maximum AU size, which depends on the card capacity, is defined in Table 105. The
card can be set to any AU size between RU size and maximum AU size.
ERASE_SIZE
This 16-bit field indicates NERASE. When NERASE numbers of AUs are erased, the
timeout value is specified by ERASE_TIMEOUT (Refer to ERASE_TIMEOUT). The host
should determine the proper number of AUs to be erased in one operation so that the host
can show the progress of the erase operation. If this field is set to 0, the erase timeout
calculation is not supported.
ERASE_TIMEOUT
This 6-bit field indicates TERASE and the value indicates the erase timeout from offset
when multiple AUs are being erased as specified by ERASE_SIZE. The range of
ERASE_OFFSET
This 2-bit field indicates TOFFSET and one of four values can be selected. This field is
meaningless if the ERASE_SIZE and ERASE_TIMEOUT fields are set to 0.
0h 0 [sec]
1h 1 [sec]
2h 2 [sec]
3h 3 [sec]
SD I/O ReadWait
The optional ReadWait (RW) operation is defined only for the SD 1-bit and 4-bit modes. The
ReadWait operation allows the MMC/SD module to signal a card that it is reading multiple
registers (IO_RW_EXTENDED, CMD53) to temporarily stall the data transfer while allowing
the MMC/SD module to send commands to any function within the SD I/O device. To
determine when a card supports the ReadWait protocol, the MMC/SD module must test
capability bits in the internal card registers. The timing for ReadWait is based on the
interrupt period.
Command types
Both application-specific and general commands are divided into the four following types:
• broadcast command (BC): sent to all cards; no responses returned.
• broadcast command with response (BCR): sent to all cards; responses received
from all cards simultaneously.
• addressed (point-to-point) command (AC): sent to the card that is selected; does
not include a data transfer on the SDIO_D line(s).
• addressed (point-to-point) data transfer command (ADTC): sent to the card that is
selected; includes a data transfer on the SDIO_D line(s).
Command formats
See Table 93 on page 611 for command formats.
CMD32
Reserved. These command indexes cannot be used in order to maintain backward compatibility with older
...
versions of the MultiMediaCard.
CMD34
Sets the address of the first erase
CMD35 ac [31:0] data address R1 ERASE_GROUP_START group within a range to be selected
for erase.
Sets the address of the last erase
CMD36 ac [31:0] data address R1 ERASE_GROUP_END group within a continuous range to be
selected for erase.
Reserved. This command index cannot be used in order to maintain backward compatibility with older
CMD37
versions of the MultiMediaCards
Erases all previously selected write
CMD38 ac [31:0] stuff bits R1 ERASE
blocks.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 X Command index
[39:8] 32 X Card status
[7:1] 7 X CRC7
0 1 1 End bit
21.5.2 R1b
It is identical to R1 with an optional busy signal transmitted on the data line. The card may
become busy after receiving these commands based on its state prior to the command
reception.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘111111’ Reserved
[39:8] 32 X OCR register
[7:1] 7 ‘1111111’ Reserved
0 1 1 End bit
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘100111’ CMD39
[31:16] 16 X RCA
[39:8] Argument field [15:8] 8 X register address
[7:0] 8 X read register contents
[7:1] 7 X CRC7
0 1 1 End bit
21.5.6 R4b
For SD I/O only: an SDIO card receiving the CMD5 will respond with a unique SDIO
response R4. The format is:
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 x Reserved
39 16 X Card is ready
[38:36] 3 X Number of I/O functions
[39:8] Argument field 35 1 X Present memory
[34:32] 3 X Stuff bits
[31:8] 24 X I/O ORC
[7:1] 7 X Reserved
0 1 1 End bit
Once an SD I/O card has received a CMD5, the I/O portion of that card is enabled to
respond normally to all further commands. This I/O enable of the function within the I/O card
will remain set until a reset, power cycle or CMD52 with write to I/O reset is received by the
card. Note that an SD memory-only card may respond to a CMD5. The proper response for
a memory-only card would be Present memory = 1 and Number of I/O functions = 0. A
memory-only card built to meet the SD Memory Card specification version 1.0 would detect
the CMD5 as an illegal command and not respond. The I/O aware host will send CMD5. If
the card responds with response R4, the host determines the card’s configuration based on
the data contained within the R4 response.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘101000’ CMD40
RCA [31:16] of winning
[31:16] 16 X
card or of the host
[39:8] Argument field
Not defined. May be used
[15:0] 16 X
for IRQ data
[7:1] 7 X CRC7
0 1 1 End bit
21.5.8 R6
Only for SD I/O. The normal response to CMD3 by a memory device. It is shown in
Table 121.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘101000’ CMD40
The card [23:8] status bits are changed when CMD3 is sent to an I/O-only card. In this case,
the 16 bits of response are the SD I/O-only values:
• Bit [15] COM_CRC_ERROR
• Bit [14] ILLEGAL_COMMAND
• Bit [13] ERROR
• Bits [12:0] Reserved
RWSTOP bit has to be cleared to start a new read wait operation. During the readwait
interval, the SDIO can detect SDIO interrupts on SDIO_D1.
The CPSM enters the Pend state, loading the command shift register with the disable
sequence “00001” and, the command counter with 43. Eight cycles after, a trigger moves
the CPSM to the Send state. When the command counter reaches 48, the CPSM becomes
Idle as no response is awaited.
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
PWRC
Reserved TRL
rw rw
Note: At least seven HCLK clock periods are needed between two write accesses to this register.
Note: After a data write, data cannot be written to this register for three SDIOCLK (48 MHz) clock
periods plus two PCLK2 clock periods.
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
NEGEDGE
HWFC_EN
PWRSAV
BYPASS
CLKEN
WID
CLKDIV
Reserved BUS
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: While the SD/SDIO card or MultiMediaCard is in identification mode, the SDIO_CK
frequency must be less than 400 kHz.
The clock frequency can be changed to the maximum card bus frequency when relative
card addresses are assigned to all cards.
After a data write, data cannot be written to this register for three SDIOCLK (48 MHz) clock
periods plus two PCLK2 clock periods. SDIO_CK can also be stopped during the read wait
interval for SD I/O cards: in this case the SDIO_CLKCR register does not control SDIO_CK.
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
CMDARG
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
SDIOSuspend
ENCMDcompl
CE-ATACMD
CMDINDEX
WAITPEND
WAITRESP
CPSMEN
WAITINT
nIEN
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: After a data write, data cannot be written to this register for three SDIOCLK (48 MHz) clock
periods plus two PCLK2 clock periods.
MultiMediaCards can send two kinds of response: short responses, 48 bits long, or long
responses,136 bits long. SD card and SD I/O card can send only short responses, the
argument can vary according to the type of response: the software will distinguish the type
of response according to the sent command. CE-ATA devices send only short responses.
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
RESPCMD
Reserved
r r r r r r
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
CARDSTATUSx
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
The Card Status size is 32 or 127 bits, depending on the response type.
The most significant bit of the card status is received first. The SDIO_RESP3 register LSB is
always 0b.
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
DATATIME
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: A data transfer must be written to the data timer register and the data length register before
being written to the data control register.
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
DATALENGTH
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: For a block data transfer, the value in the data length register must be a multiple of the block
size (see SDIO_DCTRL). A data transfer must be written to the data timer register and the
data length register before being written to the data control register.
For an SDIO multibyte transfer the value in the data length register must be between 1 and
512.
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
RWSTART
RWSTOP
DTMODE
RWMOD
SDIOEN
DMAEN
DTDIR
DTEN
DBLOCKSIZE
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
Bit 2 DTMODE: Data transfer mode selection 1: Stream or SDIO multibyte data transfer.
0: Block data transfer
1: Stream or SDIO multibyte data transfer
Bit 1 DTDIR: Data transfer direction selection
0: From controller to card.
1: From card to controller.
Bit 0 DTEN: Data transfer enabled bit
Data transfer starts if 1b is written to the DTEN bit. Depending on the direction bit, DTDIR,
the DPSM moves to the Wait_S, Wait_R state or Readwait if RW Start is set immediately at
the beginning of the transfer. It is not necessary to clear the enable bit after the end of a data
transfer but the SDIO_DCTRL must be updated to enable a new data transfer
Note: After a data write, data cannot be written to this register for three SDIOCLK (48 MHz) clock
periods plus two PCLK2 clock periods.
The meaning of the DTMODE bit changes according to the value of the SDIOEN bit. When
SDIOEN=0 and DTMODE=1, the MultiMediaCard stream mode is enabled, and when
SDIOEN=1 and DTMODE=1, the peripheral enables an SDIO multibyte transfer.
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
DATACOUNT
Reserved
r r r r r r r r r r r r r r r r r r r r r r r r r
Note: This register should be read only when the data transfer is complete.
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
TXUNDERR
CEATAEND
DTIMEOUT
CTIMEOUT
CMDREND
RXFIFOHF
RXOVERR
STBITERR
CMDSENT
TXFIFOHE
DCRCFAIL
CCRCFAIL
DBCKEND
DATAEND
RXFIFOE
RXFIFOF
CMDACT
TXFIFOE
TXFIFOF
RXDAVL
TXDAVL
RXACT
SDIOIT
TXACT
Reserved
r r r r r r r r r r r r r r r r r r r r r r r r
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
TXUNDERRC
CEATAENDC
DTIMEOUTC
CTIMEOUTC
CMDRENDC
STBITERRC
DCRCFAILC
CCRCFAILC
CMDSENTC
RXOVERRC
DBCKENDC
DATAENDC
SDIOITC
Reserved Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw
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
TXUNDERRIE
CEATAENDIE
DTIMEOUTIE
CTIMEOUTIE
CMDRENDIE
RXFIFOHFIE
STBITERRIE
CMDSENTIE
RXOVERRIE
DCRCFAILIE
CCRCFAILIE
TXFIFOHEIE
DBCKENDIE
DATAENDIE
RXFIFOEIE
RXFIFOFIE
CMDACTIE
TXFIFOEIE
TXFIFOFIE
RXDAVLIE
TXDAVLIE
RXACTIE
SDIOITIE
TXACTIE
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
FIFOCOUNT
Reserved
r r r r r r r r r r r r r r r r r r r r r r r r
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
FIF0Data
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PWRCTRL
Reserved
0x00 SDIO_POWER
NEGEDGE
HWFC_EN
Reserved
PWRSAV
WIDBUS
BYPASS
CLKDIV
CLKEN
0x04 SDIO_CLKCR
CMDINDEX
WAITPEND
WAITRESP
CPSMEN
Reserved
WAITINT
nIEN
0x0C SDIO_CMD
DTMODE
Reserved
RWMOD
SDIOEN
DMAEN
DTDIR
DTEN
0x2C SDIO_DCTRL
0x3C
Offset
658/836
SDIO_ICR
SDIO_STA
Register
SDIO_FIFO
SDIO_MASK
SDIO_FIFOCNT
31
30
29
Reserved Reserved Reserved
28
27
Reserved
26
25
24
CEATAENDIE CEATAENDC CEATAEND 23
SDIOITIE SDIOITC SDIOIT 22
Secure digital input/output interface (SDIO)
RXDAVLIE RXDAVL 21
TXDAVLIE TXDAVL 20
RXFIFOEIE RXFIFOE 19
TXFIFOEIE TXFIFOE 18
RXFIFOFIE RXFIFOF 17
DocID026448 Rev 1
TXFIFOFIE Reserved TXFIFOF 16
RXFIFOHFIE RXFIFOHF 15
FIF0Data
TXFIFOHEIE TXFIFOHE 14
RXACTIE RXACT 13
TXACTIE TXACT 12
Table 123. SDIO register map (continued)
CMDACTIE CMDACT 11
FIFOCOUNT
#ORTEX -
WITH &05
!(" 0ERIPHERAL
53" )NTERRUPT
53" /4' $0
0OWER
/4' &3 &3
#LOCK $-
#ORE 54-)&3 0(9
#42, 53" SUSPEND
)$
3YSTEM CLOCK 53" CLOCK
53" #LOCK AT -(Z DOMAIN DOMAIN 6"53
2!- BUS
+BYTES
53" DATA
&)&/S
-36
6$$
%.
34-03342
'0)/
#URRENT LIMITED 6 0WR
/VERCURRENT POWER DISTRIBUTION
'0)/ )21 SWITCH
34-&XX
34-&XX
-36
1. External voltage regulator only needed when building a VBUS powered device
2. STMPS2141STR needed only if the application has to support a VBUS powered device. A basic power
switch can be used if 5 V are available on the application board.
6$$
6 TO 6$$
6OLATGE REGULATOR
34-&XX
34-&XX
6"53
-36
Soft disconnect
The powered state can be exited by software with the soft disconnect feature. The DP pull-
up resistor is removed by setting the soft disconnect bit in the device control register (SDIS
bit in OTG_FS_DCTL), causing a device disconnect detection interrupt on the host side
even though the USB cable was not really removed from the host port.
Default state
In the Default state the OTG_FS expects to receive a SET_ADDRESS command from the
host. No other USB operation is possible. When a valid SET_ADDRESS command is
decoded on the USB, the application writes the corresponding number into the device
address field in the device configuration register (DAD bit in OTG_FS_DCFG). The
OTG_FS then enters the address state and is ready to answer host transactions at the
configured USB address.
Suspended state
The OTG_FS peripheral constantly monitors the USB activity. After counting 3 ms of USB
idleness, the early suspend interrupt (ESUSP bit in OTG_FS_GINTSTS) is issued, and
confirmed 3 ms later, if appropriate, by the suspend interrupt (USBSUSP bit in
OTG_FS_GINTSTS). The device suspend bit is then automatically set in the device status
register (SUSPSTS bit in OTG_FS_DSTS) and the OTG_FS enters the suspended state.
The suspended state may optionally be exited by the device itself. In this case the
application sets the remote wakeup signaling bit in the device control register (RWUSIG bit
in OTG_FS_DCTL) and clears it after 1 to 15 ms.
When a resume signaling is detected from the host, the resume interrupt (WKUPINT bit in
OTG_FS_GINTSTS) is generated and the device suspend bit is automatically cleared.
on which the transfer is not completed in the current frame. This interrupt is
asserted along with the end of periodic frame interrupt
(OTG_FS_GINTSTS/EOPF).
• 3 OUT endpoints
– Each of them can be configured to support the isochronous, bulk or interrupt
transfer type
– Each of them has a proper control (OTG_FS_DOEPCTLx), transfer configuration
(OTG_FS_DOEPTSIZx) and status-interrupt (OTG_FS_DOEPINTx) register
– Device Out endpoints common interrupt mask register (OTG_FS_DOEPMSK) is
available to enable/disable a single kind of endpoint interrupt source on all of the
OUT endpoints (EP0 included)
– Support for incomplete isochronous OUT transfer interrupt (INCOMPISOOUT bit
in OTG_FS_GINTSTS), asserted when there is at least one isochronous OUT
endpoint on which the transfer is not completed in the current frame. This interrupt
is asserted along with the end of periodic frame interrupt
(OTG_FS_GINTSTS/EOPF).
Endpoint control
• The following endpoint controls are available to the application through the device
endpoint-x IN/OUT control register (DIEPCTLx/DOEPCTLx):
– Endpoint enable/disable
– Endpoint activate in current configuration
– Program USB transfer type (isochronous, bulk, interrupt)
– Program supported packet size
– Program Tx-FIFO number associated with the IN endpoint
– Program the expected or transmitted data0/data1 PID (bulk/interrupt only)
– Program the even/odd frame during which the transaction is received or
transmitted (isochronous only)
– Optionally program the NAK bit to always negative-acknowledge the host
regardless of the FIFO status
– Optionally program the STALL bit to always stall host tokens to that endpoint
– Optionally program the SNOOP mode for OUT endpoint not to check the CRC
field of received data
Endpoint transfer
The device endpoint-x transfer size registers (DIEPTSIZx/DOEPTSIZx) allow the application
to program the transfer size parameters and read the transfer status. Programming must be
done before setting the endpoint enable bit in the endpoint control register. Once the
endpoint is enabled, these fields are read-only as the OTG FS core updates them with the
current transfer status.
The following transfer parameters can be programmed:
• Transfer size in bytes
• Number of packets that constitute the overall transfer size
Endpoint status/interrupt
The device endpoint-x interrupt registers (DIEPINTx/DOPEPINTx) indicate the status of an
endpoint with respect to USB- and AHB-related events. The application must read these
registers when the OUT endpoint interrupt bit or the IN endpoint interrupt bit in the core
interrupt register (OEPINT bit in OTG_FS_GINTSTS or IEPINT bit in OTG_FS_GINTSTS,
respectively) is set. Before the application can read these registers, it must first read the
device all endpoints interrupt (OTG_FS_DAINT) register to get the exact endpoint number
for the device endpoint-x interrupt register. The application must clear the appropriate bit in
this register to clear the corresponding bits in the DAINT and GINTSTS registers
The peripheral core provides the following status checks and interrupt generation:
• Transfer completed interrupt, indicating that data transfer was completed on both the
application (AHB) and USB sides
• Setup stage has been done (control-out only)
• Associated transmit FIFO is half or completely empty (in endpoints)
• NAK acknowledge has been transmitted to the host (isochronous-in only)
• IN token received when Tx-FIFO was empty (bulk-in/interrupt-in only)
• Out token received when endpoint was not yet enabled
• Babble error condition has been detected
• Endpoint disable by application is effective
• Endpoint NAK by application is effective (isochronous-in only)
• More than 3 back-to-back setup packets were received (control-out only)
• Timeout condition detected (control-in only)
• Isochronous out packet has been dropped, without generating an interrupt
the 5 V VBUS line. The external charge pump can be driven by any GPIO output. This is
required for the OTG A-host, A-device and host-only configurations.
The VBUS input ensures that valid VBUS levels are supplied by the charge pump during USB
operations while the charge pump overcurrent output can be input to any GPIO pin
configured to generate port interrupts. The overcurrent ISR must promptly disable the VBUS
generation.
%.
'0)/ 34-03342
#URRENT LIMITED 6 0WR
/VERCURRENT POWER DISTRIBUTION
'0)/ )21 SWITCH
34-&XX
34-&XX
6"53
-36
1. STMPS2141STR needed only if the application has to support a VBUS powered device. A basic power
switch can be used if 5 V are available on the application board.
2. VDD range is between 2 V and 3.6 V.
VBUS valid
When HNP or SRP is enabled the VBUS sensing pin (PA9) pin should be connected to
VBUS. The VBUS input ensures that valid VBUS levels are supplied by the charge pump
during USB operations. Any unforeseen VBUS voltage drop below the VBUS valid threshold
(4.25 V) leads to an OTG interrupt triggered by the session end detected bit (SEDET bit in
OTG_FS_GOTGINT). The application is then required to remove the VBUS power and clear
the port power bit.
When HNP and SRP are both disabled, the VBUS sensing pin (PA9) should not be
connected to VBUS. This pin can be can be used as GPIO.
The charge pump overcurrent flag can also be used to prevent electrical damage. Connect
the overcurrent flag output from the charge pump to any GPIO input and configure it to
generate a port interrupt on the active level. The overcurrent ISR must promptly disable the
VBUS generation and clear the port power bit.
Host enumeration
After detecting a peripheral connection the host must start the enumeration process by
sending USB reset and configuration commands to the new peripheral.
Before starting to drive a USB reset, the application waits for the OTG interrupt triggered by
the debounce done bit (DBCDNE bit in OTG_FS_GOTGINT), which indicates that the bus is
stable again after the electrical debounce caused by the attachment of a pull-up resistor on
DP (FS) or DM (LS).
The application drives a USB reset signaling (single-ended zero) over the USB by keeping
the port reset bit set in the host port control and status register (PRST bit in
OTG_FS_HPRT) for a minimum of 10 ms and a maximum of 20 ms. The application takes
care of the timing count and then of clearing the port reset bit.
Once the USB reset sequence has completed, the host port interrupt is triggered by the port
enable/disable change bit (PENCHNG bit in OTG_FS_HPRT). This informs the application
that the speed of the enumerated peripheral can be read from the port speed field in the
host port control and status register (PSPD bit in OTG_FS_HPRT) and that the host is
starting to drive SOFs (FS) or Keep alives (LS). The host is now ready to complete the
peripheral enumeration by sending peripheral configuration commands.
Host suspend
The application decides to suspend the USB activity by setting the port suspend bit in the
host port control and status register (PSUSP bit in OTG_FS_HPRT). The OTG_FS core
stops sending SOFs and enters the suspended state.
The suspended state can be optionally exited on the remote device’s initiative (remote
wakeup). In this case the remote wakeup interrupt (WKUPINT bit in OTG_FS_GINTSTS) is
generated upon detection of a remote wakeup signaling, the port resume bit in the host port
control and status register (PRES bit in OTG_FS_HPRT) self-sets, and resume signaling is
automatically driven over the USB. The application must time the resume window and then
clear the port resume bit to exit the suspended state and restart the SOF.
If the suspended state is exited on the host initiative, the application must set the port
resume bit to start resume signaling on the host port, time the resume window and finally
clear the port resume bit.
register. The application must clear the appropriate bit in this register to clear the
corresponding bits in the HAINT and GINTSTS registers. The mask bits for each interrupt
source of each channel are also available in the OTG_FS_HCINTMSK-x register.
• The host core provides the following status checks and interrupt generation:
– Transfer completed interrupt, indicating that the data transfer is complete on both
the application (AHB) and USB sides
– Channel has stopped due to transfer completed, USB transaction error or disable
command from the application
– Associated transmit FIFO is half or completely empty (IN endpoints)
– ACK response received
– NAK response received
– STALL response received
– USB transaction error due to CRC failure, timeout, bit stuff error, false EOP
– Babble error
– fraMe overrun
– dAta toggle error
To post a transaction request to the host scheduler (queue) the application must check that
there is at least 1 entry available in the periodic (nonperiodic) request queue by reading the
PTXQSAV bits in the OTG_FS_HNPTXSTS register or NPTQXSAV bits in the
OTG_FS_HNPTXSTS register.
34-&XX
34-&XX
0!
3/& PULSE OUTPUT TO
EXTERNAL AUDIO CONTROL
0! 6"53
633
-36
The OTG FS core provides means to monitor, track and configure SOF framing in the host
and peripheral, as well as an SOF pulse output connectivity feature.
Such utilities are especially useful for adaptive audio clock generation techniques, where
the audio peripheral needs to synchronize to the isochronous stream provided by the PC, or
the host needs to trim its framing rate according to the requirements of the audio peripheral.
from the device status register (FNSOF bit in OTG_FS_DSTS). An SOF pulse signal with a
width of 12 system clock cycles is also generated and can be made available externally on
the SOF pin by using the SOF output enable bit in the global control and configuration
register (SOFOUTEN bit in OTG_FS_GCCFG). The SOF pulse signal is also internally
connected to the TIM2 input trigger, so that the input capture feature, the output compare
feature and the timer can be triggered by the SOF pulse. The TIM2 connection is enabled .
The end of periodic frame interrupt (GINTSTS/EOPF) is used to notify the application when
80%, 85%, 90% or 95% of the time frame interval elapsed depending on the periodic frame
interval field in the device configuration register (PFIVL bit in OTG_FS_DCFG). This feature
can be used to determine if all of the isochronous traffic for that frame is complete.
PHY clock bit and then configuring the system deep sleep mode in the power control
system module (PWR).
The OTG_FS core automatically reactivates both system and USB clocks by
asynchronous detection of remote wakeup (as an host) or resume (as a device)
signaling on the USB.
To save dynamic power, the USB data FIFO is clocked only when accessed by the OTG_FS
core.
/4'?&3?(&)2
WRITE
/4'?&3?(&)2
VALUE
&RAME x x x x
TIMER
AI
ai15611
Rx packets RXFSIZ[31:16]
Any channel DFIFO pop
access from AHB Rx FIFO control
Rx start address
fixed to 0
MAC push A1 = 0
ai15610
Transmit FIFO RAM allocation: the minimum RAM space required for each IN Endpoint
Transmit FIFO is the maximum packet size for that particular IN endpoint.
Note: More space allocated in the transmit IN Endpoint FIFO results in better performance on the
USB.
OTG_FS to fill in the available RAM space at best regardless of the current USB sequence.
With these features:
• The application gains good margins to calibrate its intervention in order to optimize the
CPU bandwidth usage:
– It can accumulate large amounts of transmission data in advance compared to
when they are effectively sent over the USB
– It benefits of a large time margin to download data from the single receive FIFO
• The USB Core is able to maintain its full operating rate, that is to provide maximum full-
speed bandwidth with a great margin of autonomy versus application intervention:
– It has a large reserve of transmission data at its disposal to autonomously manage
the sending of data over the USB
– It has a lot of empty space available in the receive buffer to autonomously fill it in
with the data coming from the USB
As the OTG_FS core is able to fill in the 1.25 Kbyte RAM buffer very efficiently, and as
1.25 Kbyte of transmit/receive data is more than enough to cover a full speed frame, the
USB system is able to withstand the maximum full-speed data rate for up to one USB frame
(1 ms) without any CPU intervention.
OR
Global interrupt
mask (Bit 0)
AHB configuration
register
AND
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17:10 9 8 7:3 2 1 0
OTG
interrupt
Device all endpoints register
interrupt register
16:9 3:0 Device all endpoints
OUT endpoints IN endpoints interrupt mask register
ai15616b
1. The core interrupt register bits are shown in OTG_FS core interrupt register (OTG_FS_GINTSTS) on
page 697.
Reserved
2 0000h
DFIFO
debug read/
Direct access to data FIFO RAM
write to this
for debugging (128 Kbyte)
region
3 FFFFh
ai15615b
OTG_FS_GOTGCTL 0x000 OTG_FS control and status register (OTG_FS_GOTGCTL) on page 688
Table 124. Core global control and status registers (CSRs) (continued)
Address
Acronym Register name
offset
OTG_FS_GRXSTSR 0x01C OTG_FS Receive status debug read/OTG status read and pop registers
OTG_FS_GRXSTSP 0x020 (OTG_FS_GRXSTSR/OTG_FS_GRXSTSP) on page 704
OTG_FS_GRXFSIZ 0x024 OTG_FS Receive FIFO size register (OTG_FS_GRXFSIZ) on page 705
OTG_FS Host non-periodic transmit FIFO size register
OTG_FS_HNPTXFSIZ/
0x028 (OTG_FS_HNPTXFSIZ)/Endpoint 0 Transmit FIFO size
OTG_FS_DIEPTXF0(1)
(OTG_FS_DIEPTXF0)
OTG_FS_HFIR 0x404 OTG_FS Host frame interval register (OTG_FS_HFIR) on page 711
0x500
0x520 OTG_FS Host channel-x characteristics register (OTG_FS_HCCHARx)
OTG_FS_HCCHARx
... (x = 0..7, where x = Channel_number) on page 717
0x6E0h
OTG_FS Host channel-x interrupt register (OTG_FS_HCINTx) (x = 0..7,
OTG_FS_HCINTx 508h
where x = Channel_number) on page 718
OTG_FS Host channel-x interrupt mask register (OTG_FS_HCINTMSKx)
OTG_FS_HCINTMSKx 50Ch
(x = 0..7, where x = Channel_number) on page 719
OTG_FS Host channel-x transfer size register (OTG_FS_HCTSIZx)
OTG_FS_HCTSIZx 510h
(x = 0..7, where x = Channel_number) on page 720
0x920
0x940 OTG device endpoint-x control register (OTG_FS_DIEPCTLx) (x = 1..3,
OTG_FS_DIEPCTLx
... where x = Endpoint_number) on page 730
0xAE0
0xB20
0xB40
... OTG device endpoint-x control register (OTG_FS_DIEPCTLx) (x = 1..3,
OTG_FS_DOEPCTLx
0xCC0 where x = Endpoint_number) on page 730
0xCE0
0xCFD
Table 128. Power and clock gating control and status registers
Register name Acronym Offset address: 0xE00–0xFFF
Reserved 0xE05–0xFFF
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
HSHNPEN
HNGSCS
SRQSCS
DHNPEN
CIDSTS
HNPRQ
BSVLD
ASVLD
DBCT
SRQ
r r r r rw rw rw r rw r
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
HNSSCHG
ADTOCHG
SRSSCHG
DBCDNE
HNGDET
SEDET
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
PTXFELVL
GINTMSK
TXFELVL
Reserved Reserved
rw rw rw
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
r/rw HNPCAP
r/rw SRPCAP
PHYSEL
CTXPKT
FDMOD
FHMOD
TRDT TOCAL
Reserved Res. Reserved
rw rw rw rw wo rw
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
RXFFLSH
TXFFLSH
AHBIDL
HSRST
CSRST
FCRST
Reserved
TXFNUM
Reserved
r rw rs rs rs rs rs
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
IPXFR/INCOMPISOOUT
GOUTNAKEFF
ENUMDNE
GINAKEFF
USBSUSP
ISOODRP
CIDSCHG
HPRTINT
IISOIXFR
Reserved
USBRST
DISCINT
NPTXFE
WKUINT
SRQINT
OTGINT
OEPINT
RXFLVL
ESUSP
PTXFE
IEPINT
HCINT
CMOD
EOPF
MMIS
SOF
Reserved
Reserved
Reserved
rc_w1
rc_w1
rc_w1 r r r Res. rc_w1 r r rc_w1 r r r r r r
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
IPXFRM/IISOOXFRM
GONAKEFFM
ENUMDNEM
GINAKEFFM
USBSUSPM
ISOODRPM
CIDSCHGM
IISOIXFRM
NPTXFEM
RXFLVLM
ESUSPM
USBRST
PTXFEM
DISCINT
EPMISM
OTGINT
OEPINT
EOPFM
MMISM
SRQIM
IEPINT
PRTIM
SOFM
WUIM
HCIM
Reserved
Reserved
Reserved
Reserved
Reserved
rw rw rw rw rw rw r rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
OTG_FS Receive status debug read/OTG status read and pop registers
(OTG_FS_GRXSTSR/OTG_FS_GRXSTSP)
Address offset for Read: 0x01C
Address offset for Pop: 0x020
Reset value: 0x0000 0000
A read to the Receive status debug read register returns the contents of the top of the
Receive FIFO. A read to the Receive status read and pop register additionally pops the top
data entry out of the RxFIFO.
The receive status contents must be interpreted differently in host and device modes. The
core ignores the receive status pop/read when the receive FIFO is empty and returns a
value of 0x0000 0000. The application must only pop the Receive Status FIFO when the
Receive FIFO non-empty bit of the Core interrupt register (RXFLVL bit in
OTG_FS_GINTSTS) is asserted.
Host mode:
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
PKTSTS DPID BCNT CHNUM
Reserved
r r r r
Device mode:
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
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
RXFD
Reserved
r/rw
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
NPTXFD/TX0FD NPTXFSA/TX0FSA
r/rw r/rw
Host mode
Device mode
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
Reserved
r r r
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
NOVBUSSENS
SOFOUTEN
VBUSBSEN
VBUSASEN
.PWRDWN
Reserved
Reserved Reserved
rw rw rw rw rw
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
PRODUCT_ID
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
PTXFSIZ PTXSA
r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r
w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w
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
INEPTXFD INEPTXSA
r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r
w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w
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
FSLSPCS
FSLSS
Reserved
r rw rw
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
FRIVL
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
FTREM FRNUM
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
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
PTXQTOP PTXQSAV PTXFSAVL
r r r r r r r r r r r r r r r r rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
HAINT
Reserved
r r r r r r r r r r r r r r r r
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
HAINTM
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
POCCHNG
PENCHNG
PCDET
PSUSP
PCSTS
PLSTS
PPWR
POCA
PRES
PENA
PRST
Reserved
PSPD PTCTL
Reserved
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
DAD MCNT EPNUM MPSIZ
rs rs rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
FRMOR
DTERR
BBERR
TXERR
STALL
XFRC
CHH
ACK
NAK
Reserved
Reserved
Reserved
rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_
w1 w1 w1 w1 w1 w1 w1 w1 w1
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
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
CHHM
ACKM
NAKM
NYET
Reserved
Reserved
rw rw rw rw rw rw rw rw rw rw
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
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
NZLSOHSK
PFIVL
DSPD
Reserved
DAD
Reserved
rw rw rw rw rw rw rw rw rw rw rw
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
POPRGDNE
CGONAK
SGONAK
GONSTS
RWUSIG
CGINAK
SGINAK
GINSTS
TCTL
SDIS
Reserved
rw w w w w rw rw rw r r rw rw
Table 129 contains the minimum duration (according to device state) for which the Soft
disconnect (SDIS) bit must be set for the USB host to detect a device disconnect. To
accommodate clock jitter, it is recommended that the application add some extra delay to
the specified minimum duration.
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
ENUMSPD
SUSPSTS
EERR
FNSOF
Reserved Reserved
r r r r r r r r r r r r r r r r r r
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
ITTXFEMSK
INEPNMM
INEPNEM
XFRCM
EPDM
Reserved
TOM
Reserved
rw rw rw rw rw rw
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
OTEPDM
XFRCM
STUPM
EPDM
Reserved
Reserved
rw rw rw rw
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
OEPINT IEPINT
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
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
OEPM IEPM
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
VBUSDT
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
DVBUSP
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
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
INEPTXFEM
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
USBAEP
NAKSTS
EPENA
EPDIS
STALL
CNAK
SNAK
Reserved
Reserved
Reserved
TXFNUM EPTYP MPSIZ
Reserved
r r w w rw rw rw rw rs r r r r rw rw
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
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
CNAK
SNAK
Stall
Reserved
TXFNUM MPSIZ
Reserved
rw/
rs rs w w w w rw rw rw rw rw rw r r rw rw rw rw rw rw rw rw rw rw rw rw
rs
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
USBAEP
NAKSTS
EPENA
EPDIS
SNPM
CNAK
SNAK
Reserved
Reserved
Stall
EPTYP MPSIZ
Reserved Reserved
w r w w rs rw r r r r r r
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
SODDFRM/SD1PID
SD0PID/SEVNFRM
EONUM/DPID
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
Stall
MPSIZ
Reserved Reserved
rw/
rs rs w w w w rw rw rw r r rw rw rw rw rw rw rw rw rw rw rw rw
rs
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
EPDISD
INEPNE
ITTXFE
XFRC
TXFE
TOC
Reserved
Reserved
Reserved
rc_
rc_ rc_ rc_ rc_
r w1
w1 w1 w1 w1
/rw
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
B2BSTUP
OTEPDIS
EPDISD
XFRC
STUP
Reserved
Reserved
Reserved
Reserved
rc_
rc_ rc_ rc_ rc_
w1
w1 w1 w1 w1
/rw
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
PKTCNT XFRSIZ
Reserved Reserved
rw rw rw rw rw rw rw rw rw
PKTCNT
Reserved
STUPC
XFRSIZ
NT Reserved Reserved
rw rw rw rw rw rw rw rw rw rw
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
MCNT PKTCNT XFRSIZ
Reserved
rw/ rw/
r/r r/r rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
w w
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
INEPTFSAV
Reserved
r r r r r r r r r r r r r r r r
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
RXDPID/S
Reserved
PKTCNT XFRSIZ
TUPCNT
rw/r/ rw/r/
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw
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
GATEHCLK
PHYSUSP
STPPCLK
Reserved Reserved
rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
HSHNPEN
HNGSCS
DHNPEN
SRQSCS
CIDSTS
HNPRQ
BSVLD
ASVLD
DBCT
OTG_FS_GOT
SRQ
0x000 GCTL Reserved Reserved Reserved
Reset value 0 0 0 1 0 0 0 0 0 0
HNSSCHG
ADTOCHG
SRSSCHG
HNGDET
DBCDNE
SEDET
Reserved
OTG_FS_GOT
0x004 GINT Reserved Reserved Res.
Reset value 0 0 0 0 0 0
PTXFELVL
GINTMSK
TXFELVL
OTG_FS_GAH
0x008 BCFG Reserved Reserved
Reset value 0 0 0
HNPCAP
SRPCAP
CTXPKT
PHYSEL
FDMOD
FHMOD
Reserved
OTG_FS_GUS
TRDT TOCAL
0x00C BCFG Reserved Reserved
Reset value 0 1 0 1 0 0 1 0 0 0
RXFFLSH
Reserved
AHBIDL
HSRST
CSRST
FCRST
OTG_FS_GRST
TXFNUM
0x010 CTL Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0
IPXFR/INCOMPISOOUT
GOUTNAKEFF
ENUMDNE
GINAKEFF
USBSUSP
CIDSCHG
ISOODRP
HPRTINT
IISOIXFR
USBRST
DISCINT
WKUINT
NPTXFE
SRQINT
OTGINT
OEPINT
RXFLVL
ESUSP
IEPINT
PTXFE
HCINT
CMOD
Reserved
Reserved
Reserved
Reserved
EOPF
OTG_FS_GINT
MMIS
SOF
0x014 STS
Reset value 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
IPXFRM/IISOOXFRM
GONAKEFFM
ENUMDNEM
GINAKEFFM
USBSUSPM
ISOODRPM
CIDSCHGM
IISOIXFRM
NPTXFEM
RXFLVLM
ESUSPM
USBRST
PTXFEM
DISCINT
EPMISM
OTGINT
OEPINT
EOPFM
MMISM
SRQIM
IEPINT
PRTIM
Reserved
Reserved
Reserved
Reserved
Reserved
SOFM
WUIM
OTG_FS_GINT
HCIM
0x018 MSK
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_GRXS
TSR (host PKTSTS DPID BCNT CHNUM
mode) Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x01C
OTG_FS_GRXS
TSR (Device FRMNUM PKTSTS DPID BCNT EPNUM
Reserved
mode)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_GRXS
TSR (host PKTSTS DPID BCNT CHNUM
Reserved
mode)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x020
OTG_FS_GRXS
TSPR (Device FRMNUM PKTSTS DPID BCNT EPNUM
Reserved
mode)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
OTG_FS_GRXF
RXFD
0x024 SIZ Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
OTG_FS_HNPT
XFSIZ/
NPTXFD/TX0FD NPTXFSA/TX0FSA
0x028 OTG_FS_DIEP
TXF0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
OTG_FS_HNPT
NPTXQTOP NPTQXSAV NPTXFSAV
Res.
0x02C XSTS
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
NOVBUSSENS
SOFOUTEN
VBUSBSEN
VBUSASEN
.PWRDWN
Reserved
OTG_FS_
0x038 GCCFG Reserved Reserved
Reset value 0 0 0 0 0
OTG_FS_CID PRODUCT_ID
0x03C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0
OTG_FS_HPTX
PTXFSIZ PTXSA
0x100 FSIZ
Reset value 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0
OTG_FS_DIEP
INEPTXFD INEPTXSA
0x104 TXF1
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
OTG_FS_DIEP
INEPTXFD INEPTXSA
0x108 TXF2
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
OTG_FS_DIEP
INEPTXFD INEPTXSA
0x10C TXF3
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
FSLSPCS
FSLSS
OTG_FS_HCFG
0x400 Reserved
Reset value 0 0 0
OTG_FS_HFIR FRIVL
0x404 Reserved
Reset value 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0
OTG_FS_HFNU
FTREM FRNUM
0x408 M
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
OTG_FS_HPTX
PTXQTOP PTXQSAV PTXFSAVL
0x410 STS
Reset value 0 0 0 0 0 0 0 0 Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
OTG_FS_HAIN
HAINT
0x414 T Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_HAIN
HAINTM
0x418 TMSK Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
POCCHNG
PENCHNG
Reserved
PCDET
PSUSP
PCSTS
PLSTS
PPWR
POCA
PRES
PENA
PRST
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x500 HAR0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x520 HAR1
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x540 HAR2
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x560 HAR3
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x580 HAR4
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x5A0 HAR5
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x5C0 HAR6
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x5E0 HAR7
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FRMOR
BBERR
DTERR
TXERR
Reserved
STALL
Reserved
XFRC
OTG_FS_HCIN
CHH
ACK
NAK
0x508 T0 Reserved
Reset value 0 0
FRMOR 0 0 0 0 0 0 0
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
ACK
NAK
0x528 T1 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
STALL
Reserved
XFRC
OTG_FS_HCIN
CHH
ACK
0x548 T2 Reserved NAK
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
STALL
Reserved
XFRC
OTG_FS_HCIN
CHH
ACK
NAK
0x568 T3 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
ACK
NAK
0x588 T4 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
ACK
NAK
0x5A8 T5 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
STALL
Reserved
XFRC
OTG_FS_HCIN
CHH
ACK
NAK
0x5C8 T6 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
ACK
NAK
0x5E8 T7 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
ACKM
NAKM
NYET
OTG_FS_HCIN
0x50C TMSK0 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
ACKM
NAKM
NYET
OTG_FS_HCIN
0x52C TMSK1 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
ACKM
NAKM
NYET
OTG_FS_HCIN
0x54C TMSK2 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
ACKM
NAKM
NYET
OTG_FS_HCIN
0x56C TMSK3 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
ACKM
NAKM
NYET
OTG_FS_HCIN
0x58C TMSK4 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
BBERRM
DTERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
ACKM
NAKM
NYET
OTG_FS_HCIN
0x5AC TMSK5 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
ACKM
NAKM
NYET
OTG_FS_HCIN
0x5CC TMSK6 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
CHHM
Reserved
ACKM
NAKM
NYET
OTG_FS_HCIN
0x5EC TMSK7 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
OTG_FS_HCTS
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
NZLSOHSK
Reserved
PFIVL
DSPD
DAD
OTG_FS_DCFG
0x800 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
POPRGDNE
CGONAK
SGONAK
GONSTS
RWUSIG
CGINAK
SGINAK
GINSTS
TCTL
SDIS
OTG_FS_DCTL
0x804 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ENUMSPD
SUSPSTS
EERR
OTG_FS_DSTS FNSOF
0x808 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ITTXFEMSK
INEPNMM
INEPNEM
XFRCM
Reserved
EPDM
OTG_FS_DIEP
TOM
0x810 MSK Reserved
Reset value 0 0 0 0 0 0
OTEPDM
XFRCM
STUPM
Reserved
EPDM
OTG_FS_DOEP
0x814 MSK Reserved
Reset value 0 0 0 0
OTG_FS_DAIN
OEPINT IEPINT
0x818 T
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_DAIN
OEPM IEPM
0x81C TMSK
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_DVBU
VBUSDT
0x828 SDIS Reserved
Reset value 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1
OTG_FS_DVBU
DVBUSP
0x82C SPULSE Reserved
Reset value 0 1 0 1 1 0 1 1 1 0 0 0
OTG_FS_DIEP
INEPTXFEM
0x834 EMPMSK Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
USBAEP
NAKSTS
EPENA
Reserved
Reserved
Reserved
EPDIS
CNAK
SNAK
TXFNUM
0x900 CTL0 P Reserved Z
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
TG_FS_DTXFS
INEPTFSAV
0x918 TS0 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
SODDFRM/SD1PID
SD0PID/SEVNFRM
EONUM/DPID
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
Reserved
CNAK
SNAK
OTG_FS_DIEP
Stall
TXFNUM MPSIZ
0x920 CTL1 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TG_FS_DTXFS
INEPTFSAV
0x938 TS1 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
Reserved
EPDIS
CNAK
SNAK
OTG_FS_DIEP
Stall
TXFNUM MPSIZ
0x940 CTL2 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TG_FS_DTXFS
INEPTFSAV
0x958 TS2 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
Reserved
EPDIS
CNAK
SNAK
OTG_FS_DIEP
Stall
TXFNUM MPSIZ
0x960 CTL3 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TG_FS_DTXFS
INEPTFSAV
0x978 TS3 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
USBAEP
NAKSTS
EPENA
EPDIS
Reserved
Reserved
SNPM
CNAK
SNAK
Reset value 0 0 0 0 0 0 0 0 0 1 0 0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
OTG_FS_DOEP
Stall
MPSIZ
0xB20 CTL1 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
OTG_FS_DOEP
Stall
MPSIZ
0xB40 CTL2 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
OTG_FS_DOEP
Stall
MPSIZ
0xB60 CTL3 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EPDISD
INEPNE
ITTXFE
Reserved
Reserved
XFRC
OTG_FS_DIEPI
TXFE
TOC
Reset value 1 0 0 0 0 0
INEPNE
EPDISD
ITTXFE
Reserved
Reserved
XFRC
OTG_FS_DIEPI
TXFE
TOC
Reset value 1 0 0 0 0 0
EPDISD
INEPNE
ITTXFE
Reserved
Reserved
XFRC
OTG_FS_DIEPI
TXFE
TOC
Reset value 1 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
EPDISD
INEPNE
ITTXFE
Reserved
Reserved
XFRC
OTG_FS_DIEPI
TXFE
TOC
0x968 NT3 Reserved
Reset value 1 0 0 0 0 0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB08 INT0 Reserved
Reset value 0 0 0 0 0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB28 INT1 Reserved
Reset value 0 0 0 0 0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB48 INT2 Reserved
Reset value 0 0 0 0 0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB68 INT3 Reserved
Reset value 0 0 0 0 0
OTG_FS_DIEP PKTC
XFRSIZ
0x910 TSIZ0 Reserved NT Reserved
Reset value 0 0 0 0 0 0 0 0 0
OTG_FS_DIEP
Reserved Reserved Reserved Reserved
OTG_FS_DOEP STUP
XFRSIZ
0xB10 TSIZ0 CNT Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
STUPCNT
RXDPID/
Reserved
OTG_FS_DOEP
PKTCNT XFRSIZ
0xB30 TSIZ1
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
STUPCNT
RXDPID/
Reserved
OTG_FS_DOEP
PKTCNT XFRSIZ
0xB50 TSIZ2
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
STUPCNT
RXDPID/
Reserved
OTG_FS_DOEP
PKTCNT XFRSIZ
0xB70 TSIZ3
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GATEHCLK
PHYSUSP
STPPCLK
Reserved
OTG_FS_PCG
0xE00 CCTL Reserved
Reset value
register to determine the enumeration speed and perform the steps listed in Endpoint
initialization on enumeration completion on page 770.
At this point, the device is ready to accept SOF packets and perform control transfers on
control endpoint 0.
Halting a channel
The application can disable any channel by programming the OTG_FS_HCCHARx register
with the CHDIS and CHENA bits set to 1. This enables the OTG_FS host to flush the posted
requests (if any) and generates a channel halted interrupt. The application must wait for the
CHH interrupt in OTG_FS_HCINTx before reallocating the channel for other transactions.
The OTG_FS host does not interrupt the transaction that has already been started on the
USB.
Before disabling a channel, the application must ensure that there is at least one free space
available in the non-periodic request queue (when disabling a non-periodic channel) or the
periodic request queue (when disabling a periodic channel). The application can simply
flush the posted requests when the Request queue is full (before disabling the channel), by
programming the OTG_FS_HCCHARx register with the CHDIS bit set to 1, and the CHENA
bit cleared to 0.
The application is expected to disable a channel on any of the following conditions:
Operational model
The application must initialize a channel before communicating to the connected device.
This section explains the sequence of operation to be performed for different types of USB
transactions.
• Writing the transmit FIFO
The OTG_FS host automatically writes an entry (OUT request) to the periodic/non-
periodic request queue, along with the last DWORD write of a packet. The application
must ensure that at least one free space is available in the periodic/non-periodic
request queue before starting to write to the transmit FIFO. The application must
always write to the transmit FIFO in DWORDs. If the packet size is non-DWORD
aligned, the application must use padding. The OTG_FS host determines the actual
packet size based on the programmed maximum packet size and transfer size.
Start
Read GNPTXSTS/HPTXFSIZ
registers for available FIFO
and queue spaces
Yes
Write 1 packet
data to
transmit FIFO
More packets
to send?
No
Start
No
RXFLVL
interrupt ?
Yes
PKTSTS
No
0b0010?
No
Yes
Yes
BCNT > 0?
ai15674
SETUP transaction operates in the same way but has only one packet. The
assumptions are:
– The application is attempting to send two maximum-packet-size packets (transfer
size = 1, 024 bytes).
– The non-periodic transmit FIFO can hold two packets (128 bytes for FS).
– The non-periodic request queue depth = 4.
• Normal bulk and control OUT/SETUP operations
The sequence of operations in (channel 1) is as follows:
a) Initialize channel 1
b) Write the first packet for channel 1
c) Along with the last Word write, the core writes an entry to the non-periodic request
queue
d) As soon as the non-periodic queue becomes non-empty, the core attempts to
send an OUT token in the current frame
e) Write the second (last) packet for channel 1
f) The core generates the XFRC interrupt as soon as the last transaction is
completed successfully
g) In response to the XFRC interrupt, de-allocate the channel for other transfers
h) Handling non-ACK responses
ch_2 D AT A0
MPS
3
AC K
set _ch_en
(ch _2) IN
4
D AT A0
5
RXFLVL interrupt
ACK
1 ch_1
read_rx_sts
read_rx_fifo
MPS
O UT
ch_2
set _ch_en
(ch _2) ch_2 D AT A1
MPS
ch_2
7 ACK
XFRC interrupt
6
De-allocate IN
(ch_1)
D AT A1
RXFLVL interrupt
1 6 ACK
read_rx_stsre
MPS
ad_rx_fifo
Disable
(ch _2) 9
RXFLVL interrupt
read_rx_sts 11 10
CHH interrupt
r
De-allocate 12
(ch _2) 13
ai15675
The channel-specific interrupt service routine for bulk and control OUT/SETUP
transactions is shown in the following code samples.
• Interrupt service routine for bulk/control OUT/SETUP and bulk/control IN
transactions
a) Bulk/Control OUT/SETUP
Unmask (NAK/TXERR/STALL/XFRC)
if (XFRC)
{
Reset Error Count
Mask ACK
De-allocate Channel
}
else if (STALL)
{
Transfer Done = 1
Unmask CHH
Disable Channel
}
else if (NAK or TXERR )
{
Rewind Buffer Pointers
Unmask CHH
Disable Channel
if (TXERR)
{
Increment Error Count
Unmask ACK
}
else
{
Reset Error Count
}
}
else if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
{
Re-initialize Channel
}
}
else if (ACK)
{
Reset Error Count
Mask ACK
}
The application is expected to write the data packets into the transmit FIFO as and
when the space is available in the transmit FIFO and the Request queue. The
application can make use of the NPTXFE interrupt in OTG_FS_GINTSTS to find the
transmit FIFO space.
b) Bulk/Control IN
Unmask (TXERR/XFRC/BBERR/STALL/DTERR)
if (XFRC)
{
Reset Error Count
Unmask CHH
Disable Channel
ch_2 D AT A0
MPS
3
AC K
set _ch_en
(ch _2) IN
4
D AT A0
5
RXFLVL interrupt
ACK
1 ch_1
read_rx_sts
read_rx_fifo
MPS
O UT
ch_2
set _ch_en
(ch _2) ch_2 D AT A1
MPS
ch_2
7 ACK
XFRC interrupt
6
De-allocate IN
(ch_1)
D AT A1
RXFLVL interrupt
1 6 ACK
read_rx_stsre
MPS
ad_rx_fifo
Disable
(ch _2) 9
RXFLVL interrupt
read_rx_sts 11 10
CHH interrupt
r
De-allocate 12
(ch _2) 13
ai15675
f) The core generates the RXFLVL interrupt for the transfer completion status entry
in the receive FIFO.
g) The application must read and ignore the receive packet status when the receive
packet status is not an IN data packet (PKTSTS in GRXSTSR ≠ 0b0010).
h) The core generates the XFRC interrupt as soon as the receive packet status is
read.
i) In response to the XFRC interrupt, disable the channel and stop writing the
OTG_FS_HCCHAR2 register for further requests. The core writes a channel
disable request to the non-periodic request queue as soon as the
OTG_FS_HCCHAR2 register is written.
j) The core generates the RXFLVL interrupt as soon as the halt status is written to
the receive FIFO.
k) Read and ignore the receive packet status.
l) The core generates a CHH interrupt as soon as the halt status is popped from the
receive FIFO.
m) In response to the CHH interrupt, de-allocate the channel for other transfers.
n) Handling non-ACK responses
• Control transactions
Setup, Data, and Status stages of a control transfer must be performed as three
separate transfers. Setup-, Data- or Status-stage OUT transactions are performed
similarly to the bulk OUT transactions explained previously. Data- or Status-stage IN
transactions are performed similarly to the bulk IN transactions explained previously.
For all three stages, the application is expected to set the EPTYP field in
OTG_FS_HCCHAR1 to Control. During the Setup stage, the application is expected to
set the PID field in OTG_FS_HCTSIZ1 to SETUP.
• Interrupt OUT transactions
A typical interrupt OUT operation is shown in Figure 256. The assumptions are:
– The application is attempting to send one packet in every frame (up to 1 maximum
packet size), starting with the odd frame (transfer size = 1 024 bytes)
– The periodic transmit FIFO can hold one packet (1 KB)
– Periodic request queue depth = 4
The sequence of operations is as follows:
a) Initialize and enable channel 1. The application must set the ODDFRM bit in
OTG_FS_HCCHAR1.
b) Write the first packet for channel 1.
c) Along with the last Word write of each packet, the OTG_FS host writes an entry to
the periodic request queue.
d) The OTG_FS host attempts to send an OUT token in the next (odd) frame.
e) The OTG_FS host generates an XFRC interrupt as soon as the last packet is
transmitted successfully.
f) In response to the XFRC interrupt, reinitialize the channel for the next transfer.
OU T Odd
(micro)
DATA0
frame
M PS
5
6 XFRC interrupt ACK
init _reg(ch_1) 4 IN
write_tx_fifo
(ch_1) 1 5
MPS DATA0
RXFLVL interrupt
ACK
read_rx_sts
read_rx_fifo
1
6 MPS
RXFLVL interrupt
read_rx_sts ch_1
7 8
XFRC interrupt
ch_2
init_reg(ch _2)
9
set_ch_en
(ch_2)
Even
OU T (micro)
XFRC interrupt frame
DATA1
init _reg(ch_1)
MPS
write_tx_fifo 1
ACK
(ch_1) MPS
IN
DATA1
ai15676
Disable Channel
if (STALL)
{
Transfer Done = 1
}
}
else
if (NAK or TXERR)
{
Rewind Buffer Pointers
Reset Error Count
Mask ACK
Unmask CHH
Disable Channel
}
else
if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
{
Re-initialize Channel (in next b_interval - 1 Frame)
}
}
else
if (ACK)
{
Reset Error Count
Mask ACK
}
The application uses the NPTXFE interrupt in OTG_FS_GINTSTS to find the transmit
FIFO space.
b) Interrupt IN
Unmask (NAK/TXERR/XFRC/BBERR/STALL/FRMOR/DTERR)
if (XFRC)
{
Reset Error Count
Mask ACK
if (OTG_FS_HCTSIZx.PKTCNT == 0)
{
De-allocate Channel
}
else
{
Transfer Done = 1
Unmask CHH
Disable Channel
}
}
else
if (STALL or FRMOR or NAK or DTERR or BBERR)
{
Mask ACK
Unmask CHH
Disable Channel
if (STALL or BBERR)
{
Reset Error Count
Transfer Done = 1
}
else
if (!FRMOR)
{
Reset Error Count
}
}
else
if (TXERR)
{
Increment Error Count
Unmask ACK
Unmask CHH
Disable Channel
}
else
if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
Re-initialize Channel (in next b_interval - 1 /Frame)
}
}
else
if (ACK)
{
Reset Error Count
Mask ACK
}
• Interrupt IN transactions
The assumptions are:
– The application is attempting to receive one packet (up to 1 maximum packet size)
in every frame, starting with odd (transfer size = 1 024 bytes).
– The receive FIFO can hold at least one maximum-packet-size packet and two
status Words per packet (1 031 bytes).
– Periodic request queue depth = 4.
• Normal interrupt IN operation
The sequence of operations is as follows:
a) Initialize channel 2. The application must set the ODDFRM bit in
OTG_FS_HCCHAR2.
b) Set the CHENA bit in OTG_FS_HCCHAR2 to write an IN request to the periodic
request queue.
c) The OTG_FS host writes an IN request to the periodic request queue for each
OTG_FS_HCCHAR2 register write with the CHENA bit set.
d) The OTG_FS host attempts to send an IN token in the next (odd) frame.
e) As soon as the IN packet is received and written to the receive FIFO, the OTG_FS
host generates an RXFLVL interrupt.
f) In response to the RXFLVL interrupt, read the received packet status to determine
the number of bytes received, then read the receive FIFO accordingly. The
application must mask the RXFLVL interrupt before reading the receive FIFO, and
unmask after reading the entire packet.
g) The core generates the RXFLVL interrupt for the transfer completion status entry
in the receive FIFO. The application must read and ignore the receive packet
status when the receive packet status is not an IN data packet (PKTSTS in
GRXSTSR ≠ 0b0010).
h) The core generates an XFRC interrupt as soon as the receive packet status is
read.
i) In response to the XFRC interrupt, read the PKTCNT field in OTG_FS_HCTSIZ2.
If the PKTCNT bit in OTG_FS_HCTSIZ2 is not equal to 0, disable the channel
before re-initializing the channel for the next transfer, if any). If PKTCNT bit in
OTG_FS_HCTSIZ2 = 0, reinitialize the channel for the next transfer. This time, the
application must reset the ODDFRM bit in OTG_FS_HCCHAR2.
OU T Odd
(micro)
DATA0
frame
M PS
5
6 XFRC interrupt ACK
init _reg(ch_1) 4 IN
write_tx_fifo
(ch_1) 1 5
MPS DATA0
RXFLVL interrupt
ACK
read_rx_sts
read_rx_fifo
1
6 MPS
RXFLVL interrupt
read_rx_sts ch_1
7 8
XFRC interrupt
ch_2
init_reg(ch _2)
9
set_ch_en
(ch_2)
Even
OU T (micro)
XFRC interrupt frame
DATA1
init _reg(ch_1)
MPS
write_tx_fifo 1
ACK
(ch_1) MPS
IN
DATA1
ai15676
else
if (CHH)
{
Mask CHH
De-allocate Channel
}
Code sample: Isochronous IN
Unmask (TXERR/XFRC/FRMOR/BBERR)
if (XFRC or FRMOR)
{
if (XFRC and (OTG_FS_HCTSIZx.PKTCNT == 0))
{
Reset Error Count
De-allocate Channel
}
else
{
Unmask CHH
Disable Channel
}
}
else
if (TXERR or BBERR)
{
Increment Error Count
Unmask CHH
Disable Channel
}
else
if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
{
Re-initialize Channel
}
}
• Isochronous IN transactions
The assumptions are:
– The application is attempting to receive one packet (up to 1 maximum packet size)
in every frame starting with the next odd frame (transfer size = 1 024 bytes).
– The receive FIFO can hold at least one maximum-packet-size packet and two
status Word per packet (1 031 bytes).
– Periodic request queue depth = 4.
The sequence of operations is as follows:
a) Initialize channel 2. The application must set the ODDFRM bit in
OTG_FS_HCCHAR2.
b) Set the CHENA bit in OTG_FS_HCCHAR2 to write an IN request to the periodic
request queue.
c) The OTG_FS host writes an IN request to the periodic request queue for each
OTG_FS_HCCHAR2 register write with the CHENA bit set.
d) The OTG_FS host attempts to send an IN token in the next odd frame.
e) As soon as the IN packet is received and written to the receive FIFO, the OTG_FS
host generates an RXFLVL interrupt.
f) In response to the RXFLVL interrupt, read the received packet status to determine
the number of bytes received, then read the receive FIFO accordingly. The
application must mask the RXFLVL interrupt before reading the receive FIFO, and
unmask it after reading the entire packet.
g) The core generates an RXFLVL interrupt for the transfer completion status entry in
the receive FIFO. This time, the application must read and ignore the receive
packet status when the receive packet status is not an IN data packet (PKTSTS bit
in OTG_FS_GRXSTSR ≠ 0b0010).
h) The core generates an XFRC interrupt as soon as the receive packet status is
read.
i) In response to the XFRC interrupt, read the PKTCNT field in OTG_FS_HCTSIZ2.
If PKTCNT≠ 0 in OTG_FS_HCTSIZ2, disable the channel before re-initializing the
channel for the next transfer, if any. If PKTCNT = 0 in OTG_FS_HCTSIZ2,
reinitialize the channel for the next transfer. This time, the application must reset
the ODDFRM bit in OTG_FS_HCCHAR2.
• Selecting the queue depth
Choose the periodic and non-periodic request queue depths carefully to match the
number of periodic/non-periodic endpoints accessed.
The non-periodic request queue depth affects the performance of non-periodic
transfers. The deeper the queue (along with sufficient FIFO size), the more often the
core is able to pipeline non-periodic transfers. If the queue size is small, the core is
able to put in new requests only when the queue space is freed up.
The core’s periodic request queue depth is critical to perform periodic transfers as
scheduled. Select the periodic queue depth, based on the number of periodic transfers
scheduled in a microframe. If the periodic request queue depth is smaller than the
periodic transfers scheduled in a microframe, a frame overrun condition occurs.
• Handling babble conditions
OTG_FS controller handles two cases of babble: packet babble and port babble.
Packet babble occurs if the device sends more data than the maximum packet size for
the channel. Port babble occurs if the core continues to receive data from the device at
EOF2 (the end of frame 2, which is very close to SOF).
When OTG_FS controller detects a packet babble, it stops writing data into the Rx
buffer and waits for the end of packet (EOP). When it detects an EOP, it flushes already
written data in the Rx buffer and generates a Babble interrupt to the application.
When OTG_FS controller detects a port babble, it flushes the RxFIFO and disables the
port. The core then generates a Port disabled interrupt (HPRTINT in
OTG_FS_GINTSTS, PENCHNG in OTG_FS_HPRT). On receiving this interrupt, the
application must determine that this is not due to an overcurrent condition (another
cause of the Port Disabled interrupt) by checking POCA in OTG_FS_HPRT, then
perform a soft reset. The core does not send any more tokens after it has detected a
port babble condition.
At this point, the device is ready to receive SOF packets and is configured to perform control
transfers on control endpoint 0.
Endpoint activation
This section describes the steps required to activate a device endpoint or to configure an
existing device endpoint to a new type.
1. Program the characteristics of the required endpoint into the following fields of the
OTG_FS_DIEPCTLx register (for IN or bidirectional endpoints) or the
OTG_FS_DOEPCTLx register (for OUT or bidirectional endpoints).
– Maximum packet size
– USB active endpoint = 1
– Endpoint start data toggle (for interrupt and bulk endpoints)
– Endpoint type
– TxFIFO number
2. Once the endpoint is activated, the core starts decoding the tokens addressed to that
endpoint and sends out a valid handshake for each valid token received for the
endpoint.
Endpoint deactivation
This section describes the steps required to deactivate an existing endpoint.
1. In the endpoint to be deactivated, clear the USB active endpoint bit in the
OTG_FS_DIEPCTLx register (for IN or bidirectional endpoints) or the
OTG_FS_DOEPCTLx register (for OUT or bidirectional endpoints).
2. Once the endpoint is deactivated, the core ignores tokens addressed to that endpoint,
which results in a timeout on the USB.
Note: The application must meet the following conditions to set up the device core to handle
traffic:
NPTXFEM and RXFLVLM in the OTG_FS_GINTMSK register must be cleared.
completed. After this entry is popped from the receive FIFO, the core asserts a
Transfer Completed interrupt on the specified OUT endpoint.
5. After the data payload is popped from the receive FIFO, the RXFLVL interrupt
(OTG_FS_GINTSTS) must be unmasked.
6. Steps 1–5 are repeated every time the application detects assertion of the interrupt line
due to RXFLVL in OTG_FS_GINTSTS. Reading an empty receive FIFO can result in
undefined core behavior.
Figure 258 provides a flowchart of the above procedure.
Y rd_data.BCNT = 0 rcv_out_pkt ()
word_cnt =
packet mem[0: word_cnt – 1] = BCNT[11:2]
C +
store in rd_rxfifo(rd_data.EPNUM, (BCNT[1] | BCNT[1])
memory word_cnt)
ai15677b
• SETUP transactions
This section describes how the core handles SETUP packets and the application’s
sequence for handling SETUP transactions.
• Application requirements
1. To receive a SETUP packet, the STUPCNT field (OTG_FS_DOEPTSIZx) in a control
OUT endpoint must be programmed to a non-zero value. When the application
programs the STUPCNT field to a non-zero value, the core receives SETUP packets
and writes them to the receive FIFO, irrespective of the NAK status and EPENA bit
setting in OTG_FS_DOEPCTLx. The STUPCNT field is decremented every time the
control endpoint receives a SETUP packet. If the STUPCNT field is not programmed to
a proper value before receiving a SETUP packet, the core still receives the SETUP
packet and decrements the STUPCNT field, but the application may not be able to
determine the correct number of SETUP packets received in the Setup stage of a
control transfer.
– STUPCNT = 3 in OTG_FS_DOEPTSIZx
2. The application must always allocate some extra space in the Receive data FIFO, to be
able to receive up to three SETUP packets on a control endpoint.
– The space to be reserved is 10 Words. Three Words are required for the first
SETUP packet, 1 Word is required for the Setup stage done Word and 6 Words
are required to store two extra SETUP packets among all control endpoints.
– 3 Words per SETUP packet are required to store 8 bytes of SETUP data and 4
bytes of SETUP status (Setup packet pattern). The core reserves this space in the
receive data.
– FIFO to write SETUP data only, and never uses this space for data packets.
3. The application must read the 2 Words of the SETUP packet from the receive FIFO.
4. The application must read and discard the Setup stage done Word from the receive
FIFO.
• Internal data flow
5. When a SETUP packet is received, the core writes the received data to the receive
FIFO, without checking for available space in the receive FIFO and irrespective of the
endpoint’s NAK and STALL bit settings.
– The core internally sets the IN NAK and OUT NAK bits for the control IN/OUT
endpoints on which the SETUP packet was received.
6. For every SETUP packet received on the USB, 3 Words of data are written to the
receive FIFO, and the STUPCNT field is decremented by 1.
– The first Word contains control information used internally by the core
– The second Word contains the first 4 bytes of the SETUP command
– The third Word contains the last 4 bytes of the SETUP command
7. When the Setup stage changes to a Data IN/OUT stage, the core writes an entry
(Setup stage done Word) to the receive FIFO, indicating the completion of the Setup
stage.
8. On the AHB side, SETUP packets are emptied by the application.
9. When the application pops the Setup stage done Word from the receive FIFO, the core
interrupts the application with an STUP interrupt (OTG_FS_DOEPINTx), indicating it
can process the received SETUP packet.
– The core clears the endpoint enable bit for control OUT endpoints.
• Application programming sequence
1. Program the OTG_FS_DOEPTSIZx register.
– STUPCNT = 3
2. Wait for the RXFLVL interrupt (OTG_FS_GINTSTS) and empty the data packets from
the receive FIFO.
3. Assertion of the STUP interrupt (OTG_FS_DOEPINTx) marks a successful completion
of the SETUP Data Transfer.
– On this interrupt, the application must read the OTG_FS_DOEPTSIZx register to
determine the number of SETUP packets received and process the last received
SETUP packet.
rem_supcnt =
rd_reg(DOEPTSIZx)
2-stage
ai15678
1. To stop receiving any kind of data in the receive FIFO, the application must set the
Global OUT NAK bit by programming the following field:
– SGONAK = 1 in OTG_FS_DCTL
2. Wait for the assertion of the GONAKEFF interrupt in OTG_FS_GINTSTS. When
asserted, this interrupt indicates that the core has stopped receiving any type of data
except SETUP packets.
3. The application can receive valid OUT packets after it has set SGONAK in
OTG_FS_DCTL and before the core asserts the GONAKEFF interrupt
(OTG_FS_GINTSTS).
4. The application can temporarily mask this interrupt by writing to the GINAKEFFM bit in
the OTG_FS_GINTMSK register.
– GINAKEFFM = 0 in the OTG_FS_GINTMSK register
5. Whenever the application is ready to exit the Global OUT NAK mode, it must clear the
SGONAK bit in OTG_FS_DCTL. This also clears the GONAKEFF interrupt
(OTG_FS_GINTSTS).
– OTG_FS_DCTL = 1 in CGONAK
6. If the application has masked this interrupt earlier, it must be unmasked as follows:
– GINAKEFFM = 1 in GINTMSK
• Disabling an OUT endpoint
The application must use this sequence to disable an OUT endpoint that it has enabled.
Application programming sequence:
1. Before disabling any OUT endpoint, the application must enable Global OUT NAK
mode in the core.
– SGONAK = 1 in OTG_FS_DCTL
2. Wait for the GONAKEFF interrupt (OTG_FS_GINTSTS)
3. Disable the required OUT endpoint by programming the following fields:
– EPDIS = 1 in OTG_FS_DOEPCTLx
– SNAK = 1 in OTG_FS_DOEPCTLx
4. Wait for the EPDISD interrupt (OTG_FS_DOEPINTx), which indicates that the OUT
endpoint is completely disabled. When the EPDISD interrupt is asserted, the core also
clears the following bits:
– EPDIS = 0 in OTG_FS_DOEPCTLx
– EPENA = 0 in OTG_FS_DOEPCTLx
5. The application must clear the Global OUT NAK bit to start receiving data from other
non-disabled OUT endpoints.
– SGONAK = 0 in OTG_FS_DCTL
• Generic non-isochronous OUT data transfers
This section describes a regular non-isochronous OUT data transfer (control, bulk, or
interrupt).
Application requirements:
1. Before setting up an OUT transfer, the application must allocate a buffer in the memory
to accommodate all data to be received as part of the OUT transfer.
2. For OUT transfers, the transfer size field in the endpoint’s transfer size register must be
a multiple of the maximum packet size of the endpoint, adjusted to the Word boundary.
– transfer size[EPNUM] = n × (MPSIZ[EPNUM] + 4 – (MPSIZ[EPNUM] mod 4))
– packet count[EPNUM] = n
– n>0
3. On any OUT endpoint interrupt, the application must read the endpoint’s transfer size
register to calculate the size of the payload in the memory. The received payload size
can be less than the programmed transfer size.
– Payload size in memory = application programmed initial transfer size – core
updated final transfer size
– Number of USB packets in which this payload was received = application
programmed initial packet count – core updated final packet count
Internal data flow:
1. The application must set the transfer size and packet count fields in the endpoint-
specific registers, clear the NAK bit, and enable the endpoint to receive the data.
2. Once the NAK bit is cleared, the core starts receiving data and writes it to the receive
FIFO, as long as there is space in the receive FIFO. For every data packet received on
the USB, the data packet and its status are written to the receive FIFO. Every packet
(maximum packet size or short packet) written to the receive FIFO decrements the
packet count field for that endpoint by 1.
– OUT data packets received with bad data CRC are flushed from the receive FIFO
automatically.
– After sending an ACK for the packet on the USB, the core discards non-
isochronous OUT data packets that the host, which cannot detect the ACK, re-
sends. The application does not detect multiple back-to-back data OUT packets
on the same endpoint with the same data PID. In this case the packet count is not
decremented.
– If there is no space in the receive FIFO, isochronous or non-isochronous data
packets are ignored and not written to the receive FIFO. Additionally, non-
isochronous OUT tokens receive a NAK handshake reply.
– In all the above three cases, the packet count is not decremented because no data
are written to the receive FIFO.
3. When the packet count becomes 0 or when a short packet is received on the endpoint,
the NAK bit for that endpoint is set. Once the NAK bit is set, the isochronous or non-
isochronous data packets are ignored and not written to the receive FIFO, and non-
isochronous OUT tokens receive a NAK handshake reply.
4. After the data are written to the receive FIFO, the application reads the data from the
receive FIFO and writes it to external memory, one packet at a time per endpoint.
5. At the end of every packet write on the AHB to external memory, the transfer size for
the endpoint is decremented by the size of the written packet.
6. The OUT data transfer completed pattern for an OUT endpoint is written to the receive
FIFO on one of the following conditions:
– The transfer size is 0 and the packet count is 0
– The last OUT data packet written to the receive FIFO is a short packet
(0 ≤ packet size < maximum packet size)
7. When either the application pops this entry (OUT data transfer completed), a transfer
completed interrupt is generated for the endpoint and the endpoint enable is cleared.
Application programming sequence:
1. Program the OTG_FS_DOEPTSIZx register for the transfer size and the corresponding
packet count.
2. Program the OTG_FS_DOEPCTLx register with the endpoint characteristics, and set
the EPENA and CNAK bits.
– EPENA = 1 in OTG_FS_DOEPCTLx
– CNAK = 1 in OTG_FS_DOEPCTLx
3. Wait for the RXFLVL interrupt (in OTG_FS_GINTSTS) and empty the data packets
from the receive FIFO.
– This step can be repeated many times, depending on the transfer size.
4. Asserting the XFRC interrupt (OTG_FS_DOEPINTx) marks a successful completion of
the non-isochronous OUT data transfer.
5. Read the OTG_FS_DOEPTSIZx register to determine the size of the received data
payload.
• Generic isochronous OUT data transfer
This section describes a regular isochronous OUT data transfer.
Application requirements:
1. All the application requirements for non-isochronous OUT data transfers also apply to
isochronous OUT data transfers.
2. For isochronous OUT data transfers, the transfer size and packet count fields must
always be set to the number of maximum-packet-size packets that can be received in a
single frame and no more. Isochronous OUT data transfers cannot span more than 1
frame.
3. The application must read all isochronous OUT data packets from the receive FIFO
(data and status) before the end of the periodic frame (EOPF interrupt in
OTG_FS_GINTSTS).
4. To receive data in the following frame, an isochronous OUT endpoint must be enabled
after the EOPF (OTG_FS_GINTSTS) and before the SOF (OTG_FS_GINTSTS).
Internal data flow:
1. The internal data flow for isochronous OUT endpoints is the same as that for non-
isochronous OUT endpoints, but for a few differences.
2. When an isochronous OUT endpoint is enabled by setting the Endpoint Enable and
clearing the NAK bits, the Even/Odd frame bit must also be set appropriately. The core
receives data on an isochronous OUT endpoint in a particular frame only if the
following condition is met:
– EONUM (in OTG_FS_DOEPCTLx) = SOFFN[0] (in OTG_FS_DSTS)
3. When the application completely reads an isochronous OUT data packet (data and
status) from the receive FIFO, the core updates the RXDPID field in
OTG_FS_DOEPTSIZx with the data PID of the last isochronous OUT data packet read
from the receive FIFO.
Application programming sequence:
1. Program the OTG_FS_DOEPTSIZx register for the transfer size and the corresponding
packet count
2. Program the OTG_FS_DOEPCTLx register with the endpoint characteristics and set
the Endpoint Enable, ClearNAK, and Even/Odd frame bits.
– EPENA = 1
– CNAK = 1
– EONUM = (0: Even/1: Odd)
3. Wait for the RXFLVL interrupt (in OTG_FS_GINTSTS) and empty the data packets
from the receive FIFO
– This step can be repeated many times, depending on the transfer size.
4. The assertion of the XFRC interrupt (in OTG_FS_DOEPINTx) marks the completion of
the isochronous OUT data transfer. This interrupt does not necessarily mean that the
data in memory are good.
5. This interrupt cannot always be detected for isochronous OUT transfers. Instead, the
application can detect the IISOOXFRM interrupt in OTG_FS_GINTSTS.
6. Read the OTG_FS_DOEPTSIZx register to determine the size of the received transfer
and to determine the validity of the data received in the frame. The application must
treat the data received in memory as valid only if one of the following conditions is met:
– RXDPID = D0 (in OTG_FS_DOEPTSIZx) and the number of USB packets in
which this payload was received = 1
– RXDPID = D1 (in OTG_FS_DOEPTSIZx) and the number of USB packets in
which this payload was received = 2
– RXDPID = D2 (in OTG_FS_DOEPTSIZx) and the number of USB packets in
which this payload was received = 3
The number of USB packets in which this payload was received =
Application programmed initial packet count – Core updated final packet count
The application can discard invalid data packets.
• Incomplete isochronous OUT data transfers
This section describes the application programming sequence when isochronous OUT data
packets are dropped inside the core.
Internal data flow:
1. For isochronous OUT endpoints, the XFRC interrupt (in OTG_FS_DOEPINTx) may not
always be asserted. If the core drops isochronous OUT data packets, the application
could fail to detect the XFRC interrupt (OTG_FS_DOEPINTx) under the following
circumstances:
– When the receive FIFO cannot accommodate the complete ISO OUT data packet,
the core drops the received ISO OUT data
– When the isochronous OUT data packet is received with CRC errors
– When the isochronous OUT token received by the core is corrupted
– When the application is very slow in reading the data from the receive FIFO
2. When the core detects an end of periodic frame before transfer completion to all
isochronous OUT endpoints, it asserts the incomplete Isochronous OUT data interrupt
Examples
This section describes and depicts some fundamental transfer types and scenarios.
• Bulk OUT transaction
Figure 260 depicts the reception of a single Bulk OUT Data packet from the USB to the AHB
and describes the events involved in the process.
init_ out_ ep
XFRSIZ = 64 bytes
1 PKTCNT = 1
2 wr_reg (DOEPTSIZx)
O UT EPENA= 1
CNAK = 1
3 wr_reg(D OEPCTLx)
64 bytes
4 6
xact _1
AC K RXFLVL iintr
D OE P C idle until intr
T L x.N A
5 PKTCN K =1
T0
XFRSIZ
r =0 rcv_out _pkt()
On new xfer
OU T XF or RxFIFO
int r RC not empty
7
NA K
idle until intr
8
ai15679b
IN data transfers
• Packet write
This section describes how the application writes data packets to the endpoint FIFO when
dedicated transmit FIFOs are enabled.
1. The application can either choose the polling or the interrupt mode.
– In polling mode, the application monitors the status of the endpoint transmit data
FIFO by reading the OTG_FS_DTXFSTSx register, to determine if there is enough
space in the data FIFO.
– In interrupt mode, the application waits for the TXFE interrupt (in
OTG_FS_DIEPINTx) and then reads the OTG_FS_DTXFSTSx register, to
determine if there is enough space in the data FIFO.
– To write a single non-zero length data packet, there must be space to write the
entire packet in the data FIFO.
– To write zero length packet, the application must not look at the FIFO space.
2. Using one of the above mentioned methods, when the application determines that
there is enough space to write a transmit packet, the application must first write into the
endpoint control register, before writing the data into the data FIFO. Typically, the
application, must do a read modify write on the OTG_FS_DIEPCTLx register to avoid
modifying the contents of the register, except for setting the Endpoint Enable bit.
The application can write multiple packets for the same endpoint into the transmit FIFO, if
space is available. For periodic IN endpoints, the application must write packets only for one
microframe. It can write packets for the next periodic transaction only after getting transfer
complete for the previous transaction.
• Setting IN endpoint NAK
Internal data flow:
1. When the application sets the IN NAK for a particular endpoint, the core stops
transmitting data on the endpoint, irrespective of data availability in the endpoint’s
transmit FIFO.
2. Non-isochronous IN tokens receive a NAK handshake reply
– Isochronous IN tokens receive a zero-data-length packet reply
3. The core asserts the INEPNE (IN endpoint NAK effective) interrupt in
OTG_FS_DIEPINTx in response to the SNAK bit in OTG_FS_DIEPCTLx.
4. Once this interrupt is seen by the application, the application can assume that the
endpoint is in IN NAK mode. This interrupt can be cleared by the application by setting
the CNAK bit in OTG_FS_DIEPCTLx.
Application programming sequence:
1. To stop transmitting any data on a particular IN endpoint, the application must set the
IN NAK bit. To set this bit, the following field must be programmed.
– SNAK = 1 in OTG_FS_DIEPCTLx
2. Wait for assertion of the INEPNE interrupt in OTG_FS_DIEPINTx. This interrupt
indicates that the core has stopped transmitting data on the endpoint.
3. The core can transmit valid IN data on the endpoint after the application has set the
NAK bit, but before the assertion of the NAK Effective interrupt.
4. The application can mask this interrupt temporarily by writing to the INEPNEM bit in
DIEPMSK.
– INEPNEM = 0 in DIEPMSK
5. To exit Endpoint NAK mode, the application must clear the NAK status bit (NAKSTS) in
OTG_FS_DIEPCTLx. This also clears the INEPNE interrupt (in OTG_FS_DIEPINTx).
– CNAK = 1 in OTG_FS_DIEPCTLx
6. If the application masked this interrupt earlier, it must be unmasked as follows:
– INEPNEM = 1 in DIEPMSK
• IN endpoint disable
Use the following sequence to disable a specific IN endpoint that has been previously
enabled.
Application programming sequence:
1. The application must stop writing data on the AHB for the IN endpoint to be disabled.
2. The application must set the endpoint in NAK mode.
– SNAK = 1 in OTG_FS_DIEPCTLx
3. Wait for the INEPNE interrupt in OTG_FS_DIEPINTx.
4. Set the following bits in the OTG_FS_DIEPCTLx register for the endpoint that must be
disabled.
– EPDIS = 1 in OTG_FS_DIEPCTLx
– SNAK = 1 in OTG_FS_DIEPCTLx
5. Assertion of the EPDISD interrupt in OTG_FS_DIEPINTx indicates that the core has
completely disabled the specified endpoint. Along with the assertion of the interrupt, the
core also clears the following bits:
– EPENA = 0 in OTG_FS_DIEPCTLx
– EPDIS = 0 in OTG_FS_DIEPCTLx
6. The application must read the OTG_FS_DIEPTSIZx register for the periodic IN EP, to
calculate how much data on the endpoint were transmitted on the USB.
7. The application must flush the data in the Endpoint transmit FIFO, by setting the
following fields in the OTG_FS_GRSTCTL register:
– TXFNUM (in OTG_FS_GRSTCTL) = Endpoint transmit FIFO number
– TXFFLSH in (OTG_FS_GRSTCTL) = 1
The application must poll the OTG_FS_GRSTCTL register, until the TXFFLSH bit is cleared
by the core, which indicates the end of flush operation. To transmit new data on this
endpoint, the application can re-enable the endpoint at a later point.
handshake, the packet count for the endpoint is decremented by one, until the packet
count is zero. The packet count is not decremented on a timeout.
5. For zero length packets (indicated by an internal zero length flag), the core sends out a
zero-length packet for the IN token and decrements the packet count field.
6. If there are no data in the FIFO for a received IN token and the packet count field for
that endpoint is zero, the core generates an “IN token received when TxFIFO is empty”
(ITTXFE) Interrupt for the endpoint, provided that the endpoint NAK bit is not set. The
core responds with a NAK handshake for non-isochronous endpoints on the USB.
7. The core internally rewinds the FIFO pointers and no timeout interrupt is generated.
8. When the transfer size is 0 and the packet count is 0, the transfer complete (XFRC)
interrupt for the endpoint is generated and the endpoint enable is cleared.
Application programming sequence:
1. Program the OTG_FS_DIEPTSIZx register with the transfer size and corresponding
packet count.
2. Program the OTG_FS_DIEPCTLx register with the endpoint characteristics and set the
CNAK and EPENA (Endpoint Enable) bits.
3. When transmitting non-zero length data packet, the application must poll the
OTG_FS_DTXFSTSx register (where x is the FIFO number associated with that
endpoint) to determine whether there is enough space in the data FIFO. The
application can optionally use TXFE (in OTG_FS_DIEPINTx) before writing the data.
• Generic periodic IN data transfers
This section describes a typical periodic IN data transfer.
Application requirements:
1. Application requirements 1, 2, 3, and 4 of Generic non-periodic IN data transfers on
page 784 also apply to periodic IN data transfers, except for a slight modification of
requirement 2.
– The application can only transmit multiples of maximum-packet-size data packets
or multiples of maximum-packet-size packets, plus a short packet at the end. To
transmit a few maximum-packet-size packets and a short packet at the end of the
transfer, the following conditions must be met:
transfer size[EPNUM] = x × MPSIZ[EPNUM] + sp
(where x is an integer ≥ 0, and 0 ≤ sp < MPSIZ[EPNUM])
If (sp > 0), packet count[EPNUM] = x + 1
Otherwise, packet count[EPNUM] = x;
MCNT[EPNUM] = packet count[EPNUM]
– The application cannot transmit a zero-length data packet at the end of a transfer.
It can transmit a single zero-length data packet by itself. To transmit a single zero-
length data packet:
– transfer size[EPNUM] = 0
packet count[EPNUM] = 1
MCNT[EPNUM] = packet count[EPNUM]
2. The application can only schedule data transfers one frame at a time.
– (MCNT – 1) × MPSIZ ≤ XFERSIZ ≤ MCNT × MPSIZ
– PKTCNT = MCNT (in OTG_FS_DIEPTSIZx)
– If XFERSIZ < MCNT × MPSIZ, the last data packet of the transfer is a short
packet.
– Note that: MCNT is in OTG_FS_DIEPTSIZx, MPSIZ is in OTG_FS_DIEPCTLx,
PKTCNT is in OTG_FS_DIEPTSIZx and XFERSIZ is in OTG_FS_DIEPTSIZx
3. The complete data to be transmitted in the frame must be written into the transmit FIFO
by the application, before the IN token is received. Even when 1 Word of the data to be
transmitted per frame is missing in the transmit FIFO when the IN token is received, the
core behaves as when the FIFO is empty. When the transmit FIFO is empty:
– A zero data length packet would be transmitted on the USB for isochronous IN
endpoints
– A NAK handshake would be transmitted on the USB for interrupt IN endpoints
Internal data flow:
1. The application must set the transfer size and packet count fields in the endpoint-
specific registers and enable the endpoint to transmit the data.
2. The application must also write the required data to the associated transmit FIFO for
the endpoint.
3. Every time the application writes a packet to the transmit FIFO, the transfer size for that
endpoint is decremented by the packet size. The data are fetched from application
memory until the transfer size for the endpoint becomes 0.
4. When an IN token is received for a periodic endpoint, the core transmits the data in the
FIFO, if available. If the complete data payload (complete packet, in dedicated FIFO
mode) for the frame is not present in the FIFO, then the core generates an IN token
received when TxFIFO empty interrupt for the endpoint.
– A zero-length data packet is transmitted on the USB for isochronous IN endpoints
– A NAK handshake is transmitted on the USB for interrupt IN endpoints
5. The packet count for the endpoint is decremented by 1 under the following conditions:
– For isochronous endpoints, when a zero- or non-zero-length data packet is
transmitted
– For interrupt endpoints, when an ACK handshake is transmitted
– When the transfer size and packet count are both 0, the transfer completed
interrupt for the endpoint is generated and the endpoint enable is cleared.
6. At the “Periodic frame Interval” (controlled by PFIVL in OTG_FS_DCFG), when the
core finds non-empty any of the isochronous IN endpoint FIFOs scheduled for the
current frame non-empty, the core generates an IISOIXFR interrupt in
OTG_FS_GINTSTS.
application receives this interrupt, it must set the STALL bit in the corresponding endpoint
control register, and clear this interrupt.
1 2 3 4 5 6 7 8
HCLK
PCLK
tkn_rcvd
dsynced_tkn_rcvd
spr_read
spr_addr A1
spr_rdata D1
srcbuf_push
srcbuf_rdata D1
5 Clocks
ai15680
Suspend 6
DRV_VBUS 1
2 5
VBUS_VALID
4 7
D+ 3 Data line pulsing Connect
D- Low
ai15681
B_VALID 2
DISCHRG_VBUS
4
SESS_END
5 8
DP
Data line pulsing Connect
DM
Low
7
VBUS pulsing
CHRG_VBUS
ai15682
discharge time can be obtained from the transceiver vendor and varies from one
transceiver to another.
3. The USB OTG core informs the PHY to speed up VBUS discharge.
4. The application initiates SRP by writing the session request bit in the OTG Control and
status register. The OTG_FS controller perform data-line pulsing followed by VBUS
pulsing.
5. The host detects SRP from either the data-line or VBUS pulsing, and turns on VBUS.
The PHY indicates VBUS power-on to the device.
6. The OTG_FS controller performs VBUS pulsing.
The host starts a new session by turning on VBUS, indicating SRP success. The
OTG_FS controller interrupts the application by setting the session request success
status change bit in the OTG interrupt status register. The application reads the session
request success bit in the OTG control and status register.
7. When the USB is powered, the OTG_FS controller connects, completing the SRP
process.
Suspend 2 4 5 6 8
DM Traffic
DPPULLDOWN
DMPULLDOWN
ai15683
1. DPPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DP line inside the PHY.
DMPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DM line inside the PHY.
1. The OTG_FS controller sends the B-device a SetFeature b_hnp_enable descriptor to
enable HNP support. The B-device’s ACK response indicates that the B-device
supports HNP. The application must set host Set HNP Enable bit in the OTG Control
and status register to indicate to the OTG_FS controller that the B-device supports
HNP.
2. When it has finished using the bus, the application suspends by writing the Port
suspend bit in the host port control and status register.
3. When the B-device observes a USB suspend, it disconnects, indicating the initial
condition for HNP. The B-device initiates HNP only when it must switch to the host role;
otherwise, the bus continues to be suspended.
The OTG_FS controller sets the host negotiation detected interrupt in the OTG
interrupt status register, indicating the start of HNP.
The OTG_FS controller deasserts the DM pull down and DM pull down in the PHY to
indicate a device role. The PHY enables the OTG_FS_DP pull-up resistor to indicate a
connect for B-device.
The application must read the current mode bit in the OTG Control and status register
to determine device mode operation.
4. The B-device detects the connection, issues a USB reset, and enumerates the
OTG_FS controller for data traffic.
5. The B-device continues the host role, initiating traffic, and suspends the bus when
done.
The OTG_FS controller sets the early suspend bit in the Core interrupt register after 3
ms of bus idleness. Following this, the OTG_FS controller sets the USB Suspend bit in
the Core interrupt register.
6. In Negotiated mode, the OTG_FS controller detects the suspend, disconnects, and
switches back to the host role. The OTG_FS controller asserts the DM pull down and
DM pull down in the PHY to indicate its assumption of the host role.
7. The OTG_FS controller sets the Connector ID status change interrupt in the OTG
Interrupt Status register. The application must read the connector ID status in the OTG
Control and Status register to determine the OTG_FS controller operation as an A-
device. This indicates the completion of HNP to the application. The application must
read the Current mode bit in the OTG control and status register to determine host
mode operation.
8. The B-device connects, completing the HNP process.
Suspend 2 4 5 6 8
DM Traffic
DPPULLDOWN
DMPULLDOWN
ai15684
1. DPPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DP line inside the PHY.
DMPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DM line inside the PHY.
1. The A-device sends the SetFeature b_hnp_enable descriptor to enable HNP support.
The OTG_FS controller’s ACK response indicates that it supports HNP. The application
must set the device HNP enable bit in the OTG Control and status register to indicate
HNP support.
The application sets the HNP request bit in the OTG Control and status register to
indicate to the OTG_FS controller to initiate HNP.
2. When it has finished using the bus, the A-device suspends by writing the Port suspend
bit in the host port control and status register.
The OTG_FS controller sets the Early suspend bit in the Core interrupt register after 3
ms of bus idleness. Following this, the OTG_FS controller sets the USB suspend bit in
the Core interrupt register.
The OTG_FS controller disconnects and the A-device detects SE0 on the bus,
indicating HNP. The OTG_FS controller asserts the DP pull down and DM pull down in
the PHY to indicate its assumption of the host role.
The A-device responds by activating its OTG_FS_DP pull-up resistor within 3 ms of
detecting SE0. The OTG_FS controller detects this as a connect.
The OTG_FS controller sets the host negotiation success status change interrupt in the
OTG Interrupt status register, indicating the HNP status. The application must read the
host negotiation success bit in the OTG Control and status register to determine host
negotiation success. The application must read the current Mode bit in the Core
interrupt register (OTG_FS_GINTSTS) to determine host mode operation.
3. The application sets the reset bit (PRST in OTG_FS_HPRT) and the OTG_FS
controller issues a USB reset and enumerates the A-device for data traffic.
4. The OTG_FS controller continues the host role of initiating traffic, and when done,
suspends the bus by writing the Port suspend bit in the host port control and status
register.
5. In Negotiated mode, when the A-device detects a suspend, it disconnects and switches
back to the host role. The OTG_FS controller deasserts the DP pull down and DM pull
down in the PHY to indicate the assumption of the device role.
6. The application must read the current mode bit in the Core interrupt
(OTG_FS_GINTSTS) register to determine the host mode operation.
7. The OTG_FS controller connects, completing the HNP process.
23.1 Overview
The STM32F411xC/E is built around a Cortex®-M4 with FPU core which 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). When
stopped, 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.
The debug features are used by the debugger host when connecting to and debugging the
STM32F411xC/E MCUs.
Two interfaces for debug are available:
• Serial wire
• JTAG debug port
Figure 266. Block diagram of STM32 MCU and Cortex®-M4 with FPU-level
debug support
#ORTEX - $ATA
3YSTEM
CORE INTERFACE
D
*4-3
37$)/ %XTERNAL PRIVATE
TE
42!#%37/
PERIPHERAL BUS 00"
*4$) 4RACE PORT
"RIDGE 40)5 42!#%#+
*4$/
42!#%37/ 37* $0 !(" !0
42!#%$;=
IC
&0"
ES
)4-
-36
Note: The debug features embedded in the Cortex®-M4 with FPU core are a subset of the ARM®
CoreSight Design Kit.
The ARM® Cortex®-M4 with FPU core provides integrated on-chip debug support. It is
comprised of:
• SWJ-DP: Serial wire / JTAG debug port
• AHP-AP: AHB access port
• ITM: Instrumentation trace macrocell
• FPB: Flash patch breakpoint
• DWT: Data watchpoint trigger
• TPUI: Trace port unit interface (available on larger packages, where the corresponding
pins are mapped)
• ETM: Embedded Trace Macrocell (available on larger packages, where the
corresponding pins are mapped)
It also includes debug features dedicated to the STM32F411xC/E:
• Flexible debug pinout assignment
• MCU debug box (support for low-power modes, control over peripheral clocks, etc.)
Note: For further information on debug functionality supported by the ARM® Cortex®-M4 with FPU
core, refer to the Cortex®-M4 with FPU-r0p1 Technical Reference Manual and to the
CoreSight Design Kit-r0p1 TRM (see Section 23.2: Reference ARM® documentation).
SWJ-DP
JTDO TDO
TDO
TDI
JTDI TDI
nTRST
NJTRST nTRST
JTAG-DP
TCK
TMS
nPOTRST
SWD/JTAG From
power-on
select nPOTRST reset
DBGRESETn
SWDITMS
DBGDI
JTMS/SWDIO
SWDO
DBGDO
SW-DP
SWDOEN
DBGDOEN
SWCLKTCK
JTCK/SWCLK DBGCLK
ai17139
Figure 267 shows that the asynchronous TRACE output (TRACESWO) is multiplexed with
TDO. This means that the asynchronous trace can only be used with SW-DP, not JTAG-DP.
Note: When the APB bridge write buffer is full, it takes one extra APB cycle when writing the
GPIO_AFR register. This is because the deactivation of the JTAGSW pins is done in two
cycles to guarantee a clean level on the nTRST and TCK input signals of the core.
• Cycle 1: the JTAGSW input signals to the core are tied to 1 or 0 (to 1 for nTRST, TDI
and TMS, to 0 for TCK)
• Cycle 2: the GPIO controller takes the control signals of the SWJTAG IO pins (like
controls of direction, pull-up/down, Schmitt trigger activation, etc.).
23.4.4 Using serial wire and releasing the unused debug pins as GPIOs
To use the serial wire DP to release some GPIOs, the user software mustchange the GPIO
(PA15, PB3 and PB4) configuration mode in the GPIO_MODER register. This releases
PA15, PB3 and PB4 which now become available as GPIOs.
When debugging, the host performs the following actions:
• Under system reset, all SWJ pins are assigned (JTAG-DP + SW-DP).
• Under system reset, the debugger host sends the JTAG sequence to switch from the
JTAG-DP to the SW-DP.
• Still under system reset, the debugger sets a breakpoint on vector reset.
• The system reset is released and the Core halts.
• All the debug communications from this point are done using the SW-DP. The other
JTAG pins can then be reassigned as GPIOs by the user software.
Note: For user software designs, note that:
To release the debug pins, remember that they will be first configured either in input-pull-up
(nTRST, TMS, TDI) or pull-down (TCK) or output tristate (TDO) for a certain duration after
reset until the instant when the user software releases the pins.
When debug pins (JTAG or SW or TRACE) are mapped, changing the corresponding IO pin
configuration in the IOPORT controller has no effect.
34-&XXX
.*4234
*4-3
37 $0
3ELECTED
"OUNDARY SCAN
4!0 #ORTEX - 4!0
)2 IS BIT WIDE )2 IS BIT WIDE
*4$/
-36
DBGMCU_IDCODE
Address: 0xE004 2000
Only 32-bits access supported. Read-only.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
REV_ID
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DEV_ID
Reserved
r r r r r r r r r r r r
Only the DEV_ID(11:0) should be used for identification by the debugger/programmer tools.
BYPASS
1111
[1 bit]
IDCODE ID CODE
1110
[32 bits] 0x4BA00477 (ARM® Cortex®-M4 with FPU r0p1 ID Code)
Debug port access register
This initiates a debug port and allows access to a debug port register.
– When transferring data IN:
Bits 34:3 = DATA[31:0] = 32-bit data to transfer for a write request
Bits 2:1 = A[3:2] = 2-bit address of a debug port register.
Bit 0 = RnW = Read request (1) or write request (0).
DPACC – When transferring data OUT:
1010
[35 bits] Bits 34:3 = DATA[31:0] = 32-bit data which is read following a read
request
Bits 2:0 = ACK[2:0] = 3-bit Acknowledge:
010 = OK/FAULT
001 = WAIT
OTHER = reserved
Refer to Table 134 for a description of the A(3:2) bits
Table 134. 32-bit debug port registers addressed through the shifted value A[3:2]
Address A(3:2) value Description
Refer to the Cortex®-M4 with FPUr0p1 TRM for a detailed description of DPACC and
APACC registers.
The packet request is always followed by the turnaround time (default 1 bit) where neither
the host nor target drive the line.
001: FAULT
0..2 ACK 010: WAIT
100: OK
The ACK Response must be followed by a turnaround time only if it is a READ transaction
or if a WAIT or FAULT acknowledge has been received.
The DATA transfer must be followed by a turnaround time only if it is a READ transaction.
Note: Note that the SW-DP state machine is inactive until the target reads this ID code.
• The SW-DP state machine is in RESET STATE either after power-on reset, or after the
DP has switched from JTAG to SWD or after the line is high for more than 50 cycles
• The SW-DP state machine is in IDLE STATE if the line is low for at least two cycles
after RESET state.
• After RESET state, it is mandatory to first enter into an IDLE state AND to perform a
READ access of the DP-SW ID CODE register. Otherwise, the target will issue a
FAULT acknowledge response on another transactions.
Further details of the SW-DP state machine can be found in the Cortex®-M4 with FPU r0p1
TRM and the CoreSight Design Kit r0p1 TRM.
Purpose is to:
– request a system or debug power-up
– configure the transfer operation for AP
DP- accesses
01 Read/Write 0
CTRL/STAT – control the pushed compare and pushed
verify operations.
– read some status flags (overrun, power-
up acknowledges)
Purpose is to configure the physical serial
WIRE
01 Read/Write 1 port protocol (like the duration of the
CONTROL
turnaround time)
Enables recovery of the read data from a
READ
10 Read corrupted debugger transfer, without
RESEND
repeating the original AP transfer.
The purpose is to select the current access
10 Write SELECT
port and the active 4-words register window
This read buffer is useful because AP
accesses are posted (the result of a read AP
request is available on the next AP
READ
11 Read/Write transaction).
BUFFER
This read buffer captures data from the AP,
presented as the result of a previous read,
without initiating a new transaction
Refer to the Cortex®-M4 with FPU r0p1 TRM for further details.
Note: Important: these registers are not reset by a system reset. They are only reset by a power-
on reset.
Refer to the Cortex®-M4 with FPU r0p1 TRM for further details.
To Halt on reset, it is necessary to:
• enable the bit0 (VC_CORRESET) of the Debug and Exception Monitor Control
Register
• enable the bit0 (C_DEBUGEN) of the Debug Halting Control and Status Register.
For this, the DWT must be configured to trigger the ITM: the bit CYCCNTENA (bit0) of the
DWT Control Register must be set. In addition, the bit2 (SYNCENA) of the ITM Trace
Control Register must be set.
Note: If the SYNENA bit is not set, the DWT generates Synchronization triggers to the TPIU which
will send only TPIU synchronization packets and not ITM synchronization packets.
An overflow packet consists is a special timestamp packets which indicates that data has
been written but the FIFO was full.
Example of configuration
To output a simple value to the TPIU:
• Configure the TPIU and assign TRACE I/Os by configuring the DBGMCU_CR (refer to
Section 23.17.2: TRACE pin assignment and Section 23.16.3: Debug MCU
configuration register)
• Write 0xC5ACCE55 to the ITM Lock Access Register to unlock the write access to the
ITM registers
• Write 0x00010005 to the ITM Trace Control Register to enable the ITM with Sync
enabled and an ATB ID different from 0x00
• Write 0x1 to the ITM Trace Enable Register to enable the Stimulus Port 0
• Write 0x1 to the ITM Trace Privilege Register to unmask stimulus ports 7:0
• Write the value to output in the Stimulus Port Register 0: this can be done by software
(using a printf function)
DBGMCU_CR register
Address: 0xE004 2004
Only 32-bit access supported
POR Reset: 0x0000 0000 (not reset by system reset)
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
TRACE_ DBG_
TRACE DBG_ DBG_
MODE STAND
Reserved _IOEN Reserved STOP SLEEP
[1:0] BY
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG_I2C3_SMBUS_TIMEOUT
DBG_I2C2_SMBUS_TIMEOUT
DBG_I2C1_SMBUS_TIMEOUT
Reserved Reserved
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DBG_WWDG_STOP
DBG_IWDG_STOP
DBG_TIM5_STOP
DBG_TIM4_STOP
DBG_TIM3_STOP
DBG_TIM2_STOP
DBG_RTC_STOP
Reserved Reserved
This register is mapped on the external PPB bus at address 0xE004 200C
It is asynchronously reset by the POR (and not the system reset). It can be written by the
debugger under system reset.
Address: 0xE004 200C
Only 32-bit access is supported.
POR: 0x0000 0000 (not reset by system reset)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG_TIM11 DBG_TIM10 DBG_TIM9_
Reserved _STOP _STOP STOP
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DBG_TIM1_
Reserved STOP
rw
23.17.1 Introduction
The TPIU acts as a bridge between the on-chip trace data from the ITM and the ETM.
The output data stream encapsulates the trace source ID, that is then captured by a trace
port analyzer (TPA).
The core embeds a simple TPIU, especially designed for low-cost debug (consisting of a
special version of the CoreSight TPIU).
TPIU
TRACECLKIN
Asynchronous
ETM
FIFO
TRACECK
TPIU Trace out
formatter (serializer) TRACEDATA
[3:0]
ITM Asynchronous
FIFO
TRACESWO
ai17114
• Synchronous mode
The synchronous mode requires from 2 to 6 extra pins depending on the data trace
size and is only available in the larger packages. In addition it is available in JTAG
mode and in Serial Wire mode and provides better bandwidth output capabilities than
asynchronous trace.
No Trace
0 XX Released (1) -
(default state)
Asynchronous Released
1 00 TRACESWO - -
Trace (usable as GPIO)
Synchronous
1 01 TRACECK TRACED[0] - - -
Trace 1 bit
Synchronous
1 10 Released (1) TRACECK TRACED[0] TRACED[1] - -
Trace 2 bit
Synchronous
1 11 TRACECK TRACED[0] TRACED[1] TRACED[2] TRACED[3]
Trace 4 bit
1. When Serial Wire mode is used, it is released. But when JTAG is used, it is assigned to JTDO.
Note: By default, the TRACECLKIN input clock of the TPIU is tied to GND. It is assigned to HCLK
two clock cycles after the bit TRACE_IOEN has been set.
The debugger must then program the Trace Mode by writing the PROTOCOL[1:0] bits in the
SPP_R (Selected Pin Protocol) register of the TPIU.
• PROTOCOL=00: Trace Port Mode (synchronous)
• PROTOCOL=01 or 10: Serial Wire (Manchester or NRZ) Mode (asynchronous mode).
Default state is 01
It then also configures the TRACE port size by writing the bits [3:0] in the CPSPS_R
(Current Sync Port Size Register) of the TPIU:
• 0x1 for 1 pin (default state)
• 0x2 for 2 pins
• 0x8 for 4 pins
Note: Refer to the ARM® CoreSight Architecture Specification v1.0 (ARM® IHI 0029B) for further
information
Addr. Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
DBGMCU
REV_ID DEV_ID
0xE004 _IDCODE
2000
Reserved
Reset value(1) X X X X X X X X X X X X X X X X X X X X X X X X X X X X
Addr. Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
DBG_I2C2_SMBUS_TIMEOUT
DBG_TIM5_STOP
DBG_STANDBY
TRACE_IOEN
DBG_SLEEP
DBG_STOP
MODE[1:0]
TRACE_
Reserved
Reserved
DBGMCU_CR
0xE004
2004
Reserved Reserved
Reset value 0 0 0 0 0 0 0 0
DBG_I2C3_SMBUS_TIMEOUT
DBG_I2C2_SMBUS_TIMEOUT
DBG_I2C1_SMBUS_TIMEOUT
DBG_WWDG_STOP
DBG_IWDG_STOP
DBG_TIM5_STOP
DBG_TIM4_STOP
DBG_TIM3_STOP
DBG_TIM2_STOP
DBG_RTC_STOP
DBGMCU_
Reserved
0xE004 APB1_FZ
2008
Reserved Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
DBG_TIM10_STOP
DBG_TIM11_STOP
DBG_TIM9_STOP
DBG_TIM1_STOP
DBGMCU_
0xE004 APB2_FZ
200C
Reserved Reserved
Reset value 0 0 0 0
1. The reset value is product dependent. For more information, refer to Section 23.6.1: MCU device ID code.
The electronic signature is stored in the Flash memory area. It can be read using the
JTAG/SWD or the CPU. It contains factory-programmed identification data that allow the
user firmware or other external devices to automatically match its interface to the
characteristics of the STM32F4xx microcontrollers.
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
U_ID(31:0)
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
U_ID(63:48)
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U_ID(47:32)
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
U_ID(95:80)
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U_ID(79:64)
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
F_SIZE
r r r r r r r r r r r r r r r r
Index
A F
ADC_CCR . . . . . . . . . . . . . . . . . . . . . . . . . . .235 FLITF_FCR . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
ADC_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . .225 FLITF_FKEYR . . . . . . . . . . . . . . . . . . . . . . . . . 59
ADC_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . .227 FLITF_FOPTCR . . . . . . . . . . . . . . . . . . . . . . . 62
ADC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . .234 FLITF_FOPTKEYR . . . . . . . . . . . . . . . . . . . . . 59
ADC_HTR . . . . . . . . . . . . . . . . . . . . . . . . . . .230 FLITF_FSR . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ADC_JDRx . . . . . . . . . . . . . . . . . . . . . . . . . . .233
ADC_JOFRx . . . . . . . . . . . . . . . . . . . . . . . . .230
G
ADC_JSQR . . . . . . . . . . . . . . . . . . . . . . . . . .233
ADC_LTR . . . . . . . . . . . . . . . . . . . . . . . . . . . .231 GPIOx_AFRH . . . . . . . . . . . . . . . . . . . . . . . . 159
ADC_SMPR1 . . . . . . . . . . . . . . . . . . . . . . . . .229 GPIOx_AFRL . . . . . . . . . . . . . . . . . . . . . . . . 159
ADC_SMPR2 . . . . . . . . . . . . . . . . . . . . . . . . .229 GPIOx_BSRR . . . . . . . . . . . . . . . . . . . . . . . . 157
ADC_SQR1 . . . . . . . . . . . . . . . . . . . . . . . . . .231 GPIOx_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . 156
ADC_SQR2 . . . . . . . . . . . . . . . . . . . . . . . . . .232 GPIOx_LCKR . . . . . . . . . . . . . . . . . . . . . . . . 157
ADC_SQR3 . . . . . . . . . . . . . . . . . . . . . . . . . .232 GPIOx_MODER . . . . . . . . . . . . . . . . . . . . . . 153
ADC_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . . .224 GPIOx_ODR . . . . . . . . . . . . . . . . . . . . . . . . . 157
GPIOx_OSPEEDR . . . . . . . . . . . . . . . . . . . . 155
GPIOx_OTYPER . . . . . . . . . . . . . . . . . . . . . . 154
C GPIOx_PUPDR . . . . . . . . . . . . . . . . . . . . . . . 156
CRC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
CRC_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
I
I2C_CCR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
D I2C_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
DBGMCU_APB1 . . . . . . . . . . . . . . . . . . . . . .819 I2C_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
DBGMCU_APB2_FZ . . . . . . . . . . . . . . . . . . .820 I2C_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
DBGMCU_CR . . . . . . . . . . . . . . . . . . . . . . . .818 I2C_OAR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
DBGMCU_IDCODE . . . . . . . . . . . . . . . . . . . .804 I2C_OAR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
DMA_HIFCR . . . . . . . . . . . . . . . . . . . . . . . . .186 I2C_SR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
DMA_HISR . . . . . . . . . . . . . . . . . . . . . . . . . . .184 I2C_SR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
DMA_LIFCR . . . . . . . . . . . . . . . . . . . . . . . . . .185 I2C_TRISE . . . . . . . . . . . . . . . . . . . . . . . . . . 494
DMA_LISR . . . . . . . . . . . . . . . . . . . . . . . . . . .183 IWDG_KR . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
DMA_SxCR . . . . . . . . . . . . . . . . . . . . . . . . . .187 IWDG_PR . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
DMA_SxFCR . . . . . . . . . . . . . . . . . . . . . . . . .192 IWDG_RLR . . . . . . . . . . . . . . . . . . . . . . . . . . 413
DMA_SxM0AR . . . . . . . . . . . . . . . . . . . . . . . .191 IWDG_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
DMA_SxM1AR . . . . . . . . . . . . . . . . . . . . . . . .191
DMA_SxNDTR . . . . . . . . . . . . . . . . . . . . . . . .190
O
DMA_SxPAR . . . . . . . . . . . . . . . . . . . . . . . . .191
OTG_FS_CID . . . . . . . . . . . . . . . . . . . . . . . . 708
OTG_FS_DAINT . . . . . . . . . . . . . . . . . . . . . . 726
E OTG_FS_DAINTMSK . . . . . . . . . . . . . . . . . . 727
EXTI_EMR . . . . . . . . . . . . . . . . . . . . . . . . . . .205 OTG_FS_DCFG . . . . . . . . . . . . . . . . . . . . . . 721
EXTI_FTSR . . . . . . . . . . . . . . . . . . . . . . . . . .206 OTG_FS_DCTL . . . . . . . . . . . . . . . . . . . . . . . 722
EXTI_IMR . . . . . . . . . . . . . . . . . . . . . . . . . . . .205 OTG_FS_DIEPCTL0 . . . . . . . . . . . . . . . . . . . 729
EXTI_PR . . . . . . . . . . . . . . . . . . . . . . . . . . . .207 OTG_FS_DIEPEMPMSK . . . . . . . . . . . . . . . 728
EXTI_RTSR . . . . . . . . . . . . . . . . . . . . . . . . . .206 OTG_FS_DIEPINTx . . . . . . . . . . . . . . . . . . . 737
EXTI_SWIER . . . . . . . . . . . . . . . . . . . . . . . . .207 OTG_FS_DIEPMSK . . . . . . . . . . . . . . . . . . . 724
OTG_FS_DIEPTSIZ0 . . . . . . . . . . . . . . . . . . 739
OTG_FS_DIEPTSIZx . . . . . . . . . . . . . . . . . . 741
OTG_FS_DIEPTXFx . . . . . . . . . . . . . . . . . . . 710
OTG_FS_DOEPCTL0 . . . . . . . . . . . . . . . . . . 733
OTG_FS_DOEPCTLx . . . . . . . . . . . . . . . . . . 734
OTG_FS_DOEPINTx . . . . . . . . . . . . . . . . . . . 738
OTG_FS_DOEPMSK . . . . . . . . . . . . . . . . . . 725
OTG_FS_DOEPTSIZ0 . . . . . . . . . . . . . . . . . 740
OTG_FS_DOEPTSIZx . . . . . . . . . . . . . . . . . . 742
OTG_FS_DSTS . . . . . . . . . . . . . . . . . . . . . . . 723
OTG_FS_DTXFSTSx . . . . . . . . . . . . . . . . . . 742
OTG_FS_DVBUSDIS . . . . . . . . . . . . . . . . . . 727
OTG_FS_DVBUSPULSE . . . . . . . . . . . . . . . 728
OTG_FS_GAHBCFG . . . . . . . . . . . . . . . . . . . 692
OTG_FS_GCCFG . . . . . . . . . . . . . . . . . . . . . 707
OTG_FS_GINTMSK . . . . . . . . . . . . . . . . . . . 701
OTG_FS_GINTSTS . . . . . . . . . . . . . . . . . . . . 697
OTG_FS_GNPTXFSIZ . . . . . . . . . . . . . . . . . 706
OTG_FS_GNPTXSTS . . . . . . . . . . . . . . . . . . 706
OTG_FS_GOTGCTL . . . . . . . . . . . . . . . . . . . 688
OTG_FS_GOTGINT . . . . . . . . . . . . . . . . . . . 690
OTG_FS_GRSTCTL . . . . . . . . . . . . . . . . . . . 695
OTG_FS_GRXFSIZ . . . . . . . . . . . . . . . . . . . . 705
OTG_FS_GRXSTSP . . . . . . . . . . . . . . . . . . . 704
OTG_FS_GRXSTSR . . . . . . . . . . . . . . . . . . . 704
OTG_FS_GUSBCFG . . . . . . . . . . . . . . . . . . . 693
OTG_FS_HAINT . . . . . . . . . . . . . . . . . . . . . . 713
OTG_FS_HAINTMSK . . . . . . . . . . . . . . . . . . 714
OTG_FS_HCCHARx . . . . . . . . . . . . . . . . . . . 717
OTG_FS_HCFG . . . . . . . . . . . . . . . . . . . . . . 710
OTG_FS_HCINTMSKx . . . . . . . . . . . . . . . . . 719
OTG_FS_HCINTx . . . . . . . . . . . . . . . . . . . . . 718
OTG_FS_HCTSIZx . . . . . . . . . . . . . . . . . . . . 720
OTG_FS_HFIR . . . . . . . . . . . . . . . . . . . . . . . 711
OTG_FS_HFNUM . . . . . . . . . . . . . . . . . . . . . 712
OTG_FS_HPRT . . . . . . . . . . . . . . . . . . . . . . . 714
OTG_FS_HPTXFSIZ . . . . . . . . . . . . . . . . . . . 709
OTG_FS_HPTXSTS . . . . . . . . . . . . . . . . . . . 712
OTG_FS_PCGCCTL . . . . . . . . . . . . . . . . . . . 743
P
PWR_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
PWR_CSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
R
RCC_AHB1ENR . . . . . . . . . . . . . . . . . . . . . . 114
RCC_AHB1LPENR . . . . . . . . . . . . . . . . . . . . 120
RCC_AHB1RSTR . . . . . . . . . . . . . . . . . . . . . 108
RCC_AHB2ENR . . . . . . . . . . . . . . . . . . . . . . 115
RCC_AHB2LPENR . . . . . . . . . . . . . . . . . . . . 121
RCC_AHB2RSTR . . . . . . . . . . . . . . . . . . . . . 110
RCC_APB1ENR . . . . . . . . . . . . . . . . . . . . . . 115
RCC_APB1LPENR . . . . . . . . . . . . . . . . . . . . 122
RCC_APB2ENR . . . . . . . . . . . . . . . . . . . . . . 118
RCC_APB2LPENR . . . . . . . . . . . . . . . . . . . . 124
RCC_BDCR . . . . . . . . . . . . . . . . . . . . . . . . . . 126
RCC_CFGR . . . . . . . . . . . . . . . . . . . . . . . . . . 103
RCC_CIR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
RCC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
RCC_CSR . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
RCC_PLLCFGR . . . . . . . . . . . . . . . . . . . . . 101,130
RCC_SSCGR . . . . . . . . . . . . . . . . . . . . . . . . 129
RTC_ALRMAR . . . . . . . . . . . . . . . . . . . . . . . 447
RTC_ALRMBR . . . . . . . . . . . . . . . . . . . . . . . 448
RTC_ALRMBSSR . . . . . . . . . . . . . . . . . . . . . 457
RTC_BKxR . . . . . . . . . . . . . . . . . . . . . . . . . . 459
RTC_CALIBR . . . . . . . . . . . . . . . . . . . . . . . . 446
RTC_CALR . . . . . . . . . . . . . . . . . . . . . . . . . . 453
RTC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
RTC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
RTC_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
RTC_PRER . . . . . . . . . . . . . . . . . . . . . . . . . . 445
RTC_SHIFTR . . . . . . . . . . . . . . . . . . . . . . . . 451
RTC_SSR . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
RTC_TR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
RTC_TSDR . . . . . . . . . . . . . . . . . . . . . . . . . . 452
RTC_TSSSR . . . . . . . . . . . . . . . . . . . . . . . . . 453
RTC_TSTR . . . . . . . . . . . . . . . . . . . . . . . . . . 451
RTC_WPR . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
RTC_WUTR . . . . . . . . . . . . . . . . . . . . . . . . . . 446
S
SDIO_CLKCR . . . . . . . . . . . . . . . . . . . . . . . . 644
SDIO_DCOUNT . . . . . . . . . . . . . . . . . . . . . . . 650
SDIO_DCTRL . . . . . . . . . . . . . . . . . . . . . . . . 649
SDIO_DLEN . . . . . . . . . . . . . . . . . . . . . . . . . 648
SDIO_DTIMER . . . . . . . . . . . . . . . . . . . . . . . 648
SDIO_FIFO . . . . . . . . . . . . . . . . . . . . . . . . . . 657
SDIO_FIFOCNT . . . . . . . . . . . . . . . . . . . . . . 656
SDIO_ICR . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
SDIO_MASK . . . . . . . . . . . . . . . . . . . . . . . . . 654
SDIO_POWER . . . . . . . . . . . . . . . . . . . . . . . 643
SDIO_RESPCMD . . . . . . . . . . . . . . . . . . . . . 647
SDIO_RESPx . . . . . . . . . . . . . . . . . . . . . . . . 647
SDIO_STA . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
SPI_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
SPI_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
SPI_CRCPR . . . . . . . . . . . . . . . . . . . . . . . . . 598
SPI_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
SPI_I2SCFGR . . . . . . . . . . . . . . . . . . . . . . . . 599
SPI_I2SPR . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
SPI_RXCRCR . . . . . . . . . . . . . . . . . . . . . . . . 598
SPI_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
SPI_TXCRCR . . . . . . . . . . . . . . . . . . . . . . . . 598
SYSCFG_EXTICR1 . . . . . . . . . . . . . . . . . . . . 137
SYSCFG_EXTICR2 . . . . . . . . . . . . . . . . . . . . 138
SYSCFG_EXTICR3 . . . . . . . . . . . . . . . . . . . . 139
SYSCFG_EXTICR4 . . . . . . . . . . . . . . . . . . . . 139
SYSCFG_MEMRMP . . . . . . . . . . . . . . . . . . . 136
T
TIM2_OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
TIM5_OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
TIMx_ARR . . . . . . . . . . . . . . . . . . . . . . . . . . 358,396, 406
TIMx_BDTR . . . . . . . . . . . . . . . . . . . . . . . . . . 300
TIMx_CCER . . . . . . . . . . . . . . . . . . . . . . . . . 293,356, 395, 405
TIMx_CCMR1 . . . . . . . . . . . . . . . . . . . . . . . 289,352, 392, 402
TIMx_CCMR2 . . . . . . . . . . . . . . . . . . . . . . . 292,355
TIMx_CCR1 . . . . . . . . . . . . . . . . . . . . . . . . . 298,358, 397, 407
TIMx_CCR2 . . . . . . . . . . . . . . . . . . . . . . . . . 299,359, 397
TIMx_CCR3 . . . . . . . . . . . . . . . . . . . . . . . . . 299,359
TIMx_CCR4 . . . . . . . . . . . . . . . . . . . . . . . . . 300,360
TIMx_CNT . . . . . . . . . . . . . . . . . . . . . . . . . . 297,358, 396, 406
TIMx_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 278,342, 385, 400
TIMx_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . 279,344
TIMx_DCR . . . . . . . . . . . . . . . . . . . . . . . . . . 302,360
TIMx_DIER . . . . . . . . . . . . . . . . . . . . . . . . . 284,348, 388
TIMx_DMAR . . . . . . . . . . . . . . . . . . . . . . . . 303,361
TIMx_EGR . . . . . . . . . . . . . . . . . . . . . . . . . . 287,351, 390, 401
TIMx_PSC . . . . . . . . . . . . . . . . . . . . . . . . . . 297,358, 396, 406
TIMx_RCR . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
TIMx_SMCR . . . . . . . . . . . . . . . . . . . . . . . . 282,345, 387
TIMx_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . 286,349, 389, 401
U
USART_BRR . . . . . . . . . . . . . . . . . . . . . . . . . 541
USART_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . 541
USART_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . 544
USART_CR3 . . . . . . . . . . . . . . . . . . . . . . . . . 545
USART_DR . . . . . . . . . . . . . . . . . . . . . . . . . . 541
USART_GTPR . . . . . . . . . . . . . . . . . . . . . . . . 547
USART_SR . . . . . . . . . . . . . . . . . . . . . . . . . . 538
W
WWDG_CFR . . . . . . . . . . . . . . . . . . . . . . . . . 421
WWDG_CR . . . . . . . . . . . . . . . . . . . . . . . . . . 420
WWDG_SR . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.