ST STM32F405 Reference Manual
Hide thumbs Also See for STM32F405:
Table of Contents

Advertisement

Quick Links

RM0090
Reference manual
STM32F405/415, STM32F407/417, STM32F427/437 and
®
STM32F429/439 advanced Arm
-based 32-bit MCUs
Introduction
This reference manual targets application developers. It provides complete information on
how to use the STM32F405xx/07xx, STM32F415xx/17xx, STM32F42xxx and
STM32F43xxx microcontroller memory and peripherals.
The STM32F405xx/07xx, STM32F415xx/17xx, STM32F42xxx and STM32F43xxx constitute
a family of microcontrollers with different memory sizes, packages and peripherals.
For ordering information, mechanical and electrical device characteristics please refer to the
datasheets.
®
®
®
For information on the Arm
Cortex
-M4 with FPU core, please refer to the Cortex
-M4 with
FPU Technical Reference Manual.
Related documents
Available from STMicroelectronics web site (http://www.st.com):
• STM32F40x and STM32F41x datasheets
• STM32F42x and STM32F43x datasheets
®
®
• For information on the Arm
Cortex
-M4 with FPU, refer to the STM32F3xx/F4xxx
®
Cortex
-M4 with FPU programming manual (PM0214).
February 2019
RM0090 Rev 18
1/1749
www.st.com
1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM32F405 and is the answer not in the manual?

Questions and answers

Summary of Contents for ST STM32F405

  • Page 1 Cortex -M4 with FPU core, please refer to the Cortex -M4 with FPU Technical Reference Manual. Related documents Available from STMicroelectronics web site (http://www.st.com): • STM32F40x and STM32F41x datasheets • STM32F42x and STM32F43x datasheets ® ® • For information on the Arm...
  • Page 2: Table Of Contents

    Contents RM0090 Contents Documentation conventions ....... . . 57 List of abbreviations for registers ....... 57 Glossary .
  • Page 3 RM0090 Contents 3.5.2 Adaptive real-time memory accelerator (ART Accelerator™) ..82 Erase and program operations ....... . . 84 3.6.1 Unlocking the Flash control register .
  • Page 4 Contents RM0090 CRC introduction ......... . .113 CRC main features .
  • Page 5 RM0090 Contents PWR register map ......... 149 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) .
  • Page 6 Contents RM0090 6.3.16 RCC AHB2 peripheral clock enable in low power mode register (RCC_AHB2LPENR) ........192 6.3.17 RCC AHB3 peripheral clock enable in low power mode register (RCC_AHB3LPENR) .
  • Page 7 RM0090 Contents 7.3.4 RCC clock interrupt register (RCC_CIR) ..... . . 230 7.3.5 RCC AHB1 peripheral reset register (RCC_AHB1RSTR) ..233 7.3.6 RCC AHB2 peripheral reset register (RCC_AHB2RSTR) .
  • Page 8 Contents RM0090 8.3.8 External interrupt/wakeup lines ......275 8.3.9 Input configuration ........275 8.3.10 Output configuration .
  • Page 9 RM0090 Contents 9.2.7 Compensation cell control register (SYSCFG_CMPCR) ... 293 9.2.8 SYSCFG register maps for STM32F405xx/07xx and STM32F415xx/17xx ....294 SYSCFG registers for STM32F42xxx and STM32F43xxx .
  • Page 10 Contents RM0090 10.3.18 Error management ........323 10.4 DMA interrupts .
  • Page 11 RM0090 Contents 11.5.1 DMA2D control register (DMA2D_CR) ......352 11.5.2 DMA2D Interrupt Status Register (DMA2D_ISR) ....354 11.5.3 DMA2D interrupt flag clear register (DMA2D_IFCR) .
  • Page 12 Contents RM0090 12.3.2 Event mask register (EXTI_EMR) ......384 12.3.3 Rising trigger selection register (EXTI_RTSR) ....385 12.3.4 Falling trigger selection register (EXTI_FTSR) .
  • Page 13 RM0090 Contents 13.10 Temperature sensor ........412 13.11 Battery charge monitoring .
  • Page 14 Contents RM0090 14.4 Dual DAC channel conversion ....... . 440 14.4.1 Independent trigger without wave generation .
  • Page 15 RM0090 Contents 15.1 DCMI introduction ......... . 455 15.2 DCMI main features .
  • Page 16 Contents RM0090 16.3.1 LTDC block diagram ........481 16.3.2 LTDC reset and clocks .
  • Page 17 RM0090 Contents 16.7.23 LTDC Layerx Color Frame Buffer Length Register (LTDC_LxCFBLR) (where x=1..2) ......... . . 509 16.7.24 LTDC Layerx ColorFrame Buffer Line Number Register (LTDC_LxCFBLNR) (where x=1..2) .
  • Page 18 Contents RM0090 17.4.5 TIM1 and TIM8 status register (TIMx_SR) ..... . 569 17.4.6 TIM1 and TIM8 event generation register (TIMx_EGR) ... . 570 17.4.7 TIM1 and TIM8 capture/compare mode register 1 (TIMx_CCMR1) .
  • Page 19 RM0090 Contents 18.3.16 Debug mode ..........626 18.4 TIM2 to TIM5 registers .
  • Page 20 Contents RM0090 19.3.8 Output compare mode ........664 19.3.9 PWM mode .
  • Page 21 RM0090 Contents 20.3 TIM6 and TIM7 functional description ......697 20.3.1 Time-base unit ......... . . 697 20.3.2 Counting mode .
  • Page 22 Contents RM0090 22.6 WWDG registers ......... . 717 22.6.1 Control register (WWDG_CR) .
  • Page 23 RM0090 Contents 24.2 RNG main features ......... 767 24.3 RNG functional description .
  • Page 24 Contents RM0090 26.3 RTC functional description ........801 26.3.1 Clock and prescalers .
  • Page 25 RM0090 Contents 26.6.18 RTC alarm A sub second register (RTC_ALRMASSR) ... . 834 26.6.19 RTC alarm B sub second register (RTC_ALRMBSSR) ... . 835 26.6.20 RTC backup registers (RTC_BKPxR) .
  • Page 26 Contents RM0090 28.2.1 SPI features ..........874 28.2.2 S features .
  • Page 27 RM0090 Contents Serial audio interface (SAI) ........926 29.1 Introduction .
  • Page 28 Contents RM0090 29.17.4 SAI xSlot register (SAI_xSLOTR) where x is A or B ....957 29.17.5 SAI xInterrupt mask register (SAI_xIM) where x is A or B ..958 29.17.6 SAI xStatus register (SAI_xSR) where x is A or B .
  • Page 29 RM0090 Contents Secure digital input/output interface (SDIO) ....1019 31.1 SDIO main features ........1019 31.2 SDIO bus topology .
  • Page 30 Contents RM0090 31.7 CE-ATA specific operations ....... . . 1059 31.7.1 Command completion signal disable .
  • Page 31 RM0090 Contents 32.5 Test mode ..........1081 32.5.1 Silent mode .
  • Page 32 Contents RM0090 33.5.2 MAC frame transmission ........1137 33.5.3 MAC frame reception .
  • Page 33 RM0090 Contents 34.4 OTG dual role device (DRD) ....... . 1245 34.4.1 ID line detection .
  • Page 34 Contents RM0090 34.16.5 OTG_FS power and clock gating control register (OTG_FS_PCGCCTL) ........1325 34.16.6 OTG_FS register map .
  • Page 35 RM0090 Contents 35.7 SOF trigger ..........1396 35.7.1 Host SOFs .
  • Page 36 Contents RM0090 36.5 NOR Flash/PSRAM controller ....... 1549 36.5.1 External memory interface signals ......1550 36.5.2 Supported memories and transactions .
  • Page 37 RM0090 Contents 37.6.2 NAND Flash / PC Card supported memories and transactions ..1650 37.6.3 Timing diagrams for NAND Flash memory and PC Card ..1650 37.6.4 NAND Flash operations ........1651 37.6.5 NAND Flash prewait functionality .
  • Page 38 Contents RM0090 38.8.3 SW-DP state machine (reset, idle states, ID code) ....1694 38.8.4 DP and AP read/write accesses ......1694 38.8.5 SW-DP registers .
  • Page 39 RM0090 Contents Device electronic signature ....... . 1714 39.1 Unique device ID register (96 bits) ......1714 39.2 Flash size .
  • Page 40 List of tables RM0090 List of tables Table 1. STM32F4xx register boundary addresses ........64 Table 2.
  • Page 41 RM0090 List of tables Table 40. SYSCFG register map and reset values (STM32F405xx/07xx and STM32F415xx/17xx) 294 Table 41. SYSCFG register map and reset values (STM32F42xxx and STM32F43xxx) ..301 Table 42. DMA1 request mapping ..........307 Table 43.
  • Page 42 List of tables RM0090 Table 92. LTDC register map and reset values ........512 Table 93.
  • Page 43 RM0090 List of tables oversampling by 8............982 Table 138.
  • Page 44 List of tables RM0090 Table 183. Receive mailbox mapping..........1091 Table 184.
  • Page 45 RM0090 List of tables Table 234. FSMC_BCRx bit fields ..........1563 Table 235.
  • Page 46 List of tables RM0090 Table 286. FMC_BTRx bit fields ........... . 1637 Table 287.
  • Page 47 RM0090 List of figures List of figures Figure 1. System architecture for STM32F405xx/07xx and STM32F415xx/17xx devices..60 Figure 2. System architecture for STM32F42xxx and STM32F43xxx devices ....62 Figure 3.
  • Page 48 List of figures RM0090 Figure 46. Analog watchdog’s guarded area ......... . . 393 Figure 47.
  • Page 49 RM0090 List of figures Figure 98. Counter timing diagram, internal clock divided by N......525 Figure 99.
  • Page 50 List of figures RM0090 Figure 150. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 ....600 Figure 151. Counter timing diagram, internal clock divided by N......600 Figure 152.
  • Page 51 RM0090 List of figures Figure 202. Control circuit in trigger mode ..........670 Figure 203.
  • Page 52 List of figures RM0090 Figure 252. TI mode - master mode, continuous transfer ........884 Figure 253.
  • Page 53 RM0090 List of figures Figure 298. Configurable stop bits ........... . 971 Figure 299.
  • Page 54 List of figures RM0090 Figure 350. ETH block diagram ........... . . 1126 Figure 351.
  • Page 55 RM0090 List of figures Figure 402. Receive FIFO packet read ..........1356 Figure 403.
  • Page 56 List of figures RM0090 Figure 452. Synchronous multiplexed read mode - NOR, PSRAM (CRAM) ....1573 Figure 453. Synchronous multiplexed write mode - PSRAM (CRAM) ......1575 Figure 454.
  • Page 57: Documentation Conventions

    RM0090 Documentation conventions Documentation conventions ®(a) ® The STM32F401xx devices have an Arm Cortex -M4 with FPU. List of abbreviations for registers The following abbreviations are used in register descriptions: read/write (rw) Software can read and write to these bits. read-only (r) Software can only read these bits.
  • Page 58: Glossary

    Documentation conventions RM0090 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. –...
  • Page 59: Memory And Bus Architecture

    RM0090 Memory and bus architecture Memory and bus architecture System architecture In STM32F405xx/07xx and STM32F415xx/17xx, the main system consists of 32-bit multilayer AHB bus matrix that interconnects: The main system consists of 32-bit multilayer AHB bus matrix that interconnects: • Eight masters: ®...
  • Page 60: Figure 1. System Architecture For Stm32F405Xx/07Xx And Stm32F415Xx/17Xx Devices

    Memory and bus architecture RM0090 Figure 1. System architecture for STM32F405xx/07xx and STM32F415xx/17xx devices 64-Kbyte USB OTG Cortex-M4 DMA1 DMA2 Ethernet CCM data RAM ICODE Flash memory DCODE SRAM1 112 Kbyte SRAM2 16 Kbyte AHB1 APB1 peripherals AHB2 peripherals APB2 FSMC Static MemCtl Bus matrix-S...
  • Page 61 RM0090 Memory and bus architecture In the STM32F42xx and STM32F43xx devices, the main system consists of 32-bit multilayer AHB bus matrix that interconnects: • Ten masters: ® – Cortex -M4 with FPU core I-bus, D-bus and S-bus – DMA1 memory bus –...
  • Page 62: I-Bus

    Memory and bus architecture RM0090 Figure 2. System architecture for STM32F42xxx and STM32F43xxx devices Chrom ART Accelerator 64-Kbyte USB OTG LCD-TFT DMA1 Cortex-M4 DMA2 Ethernet CCM data RAM (DMA2D) ICODE Flash memory DCODE SRAM1 112 Kbyte SRAM2 16 Kbyte SRAM3 64 Kbyte AHB2 APB1...
  • Page 63: Dma Memory Bus

    RM0090 Memory and bus architecture 2.1.4 DMA memory bus This bus connects the DMA memory bus master interface to the BusMatrix. It is used by the DMA to perform transfer to/from memories. The targets of this bus are data memories: internal SRAMs (SRAM1, SRAM2 and SRAM3) and external memories through the FSMC/FMC.
  • Page 64: Ahb/Apb Bridges (Apb)

    Memory and bus architecture RM0090 2.1.11 AHB/APB bridges (APB) The two AHB/APB bridges, APB1 and APB2, provide full synchronous connections between the AHB and the two APB buses, allowing flexible selection of the peripheral frequency. Refer to the device datasheets for more details on APB1 and APB2 maximum frequencies, and to Table 1 for the address mapping of AHB and APB peripherals.
  • Page 65 RM0090 Memory and bus architecture Table 1. STM32F4xx register boundary addresses (continued) Boundary address Peripheral Register map 0x5006 0800 - 0x5006 0BFF Section 24.4.4: RNG register map on page 771 0x5006 0400 - 0x5006 07FF HASH Section 25.4.9: HASH register map on page 795 0x5006 0000 - 0x5006 03FF CRYP Section 23.6.13: CRYP register map on page 763...
  • Page 66 Memory and bus architecture RM0090 Table 1. STM32F4xx register boundary addresses (continued) Boundary address Peripheral Register map 0x4001 4800 - 0x4001 4BFF TIM11 Section 19.5.12: TIM10/11/13/14 register map on page 694 0x4001 4400 - 0x4001 47FF TIM10 Section 19.4.13: TIM9/12 register map on 0x4001 4000 - 0x4001 43FF TIM9 page 684...
  • Page 67 RM0090 Memory and bus architecture Table 1. STM32F4xx register boundary addresses (continued) Boundary address Peripheral Register map 0x4000 7400 - 0x4000 77FF Section 14.5.15: DAC register map on page 453 0x4000 7000 - 0x4000 73FF Section 5.6: PWR register map on page 149 0x4000 6800 - 0x4000 6BFF CAN2 Section 32.9.5: bxCAN register map on page 1118...
  • Page 68: Embedded Sram

    Memory and bus architecture RM0090 2.3.1 Embedded SRAM The STM32F405xx/07xx and STM32F415xx/17xx feature 4 Kbytes of backup SRAM (see Section 5.1.2: Battery backup domain) plus 192 Kbytes of system SRAM. The STM32F42xxx and STM32F43xxx feature 4 Kbytes of backup SRAM (see Section 5.1.2: Battery backup domain) plus 256 Kbytes of system SRAM.
  • Page 69: Boot Configuration

    RM0090 Memory and bus architecture ® are only available for Cortex -M4 with FPU accesses, and not from other bus masters (e.g. DMA). A mapping formula shows how to reference each word in the alias region to a corresponding bit in the bit-band region. The mapping formula is: bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number ×...
  • Page 70 CAN and 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.
  • Page 71: Table 3. Memory Mapping Vs. Boot Mode/Physical Remap In Stm32F405Xx/07Xx And Stm32F415Xx/17Xx

    RM0090 Memory and bus architecture Table 3. Memory mapping vs. Boot mode/physical remap in STM32F405xx/07xx and STM32F415xx/17xx Boot/Remap in Boot/Remap in Boot/Remap in Addresses Remap in FSMC main Flash memory embedded SRAM System memory 0x2001 C000 - 0x2001 FFFF SRAM2 (16 KB) SRAM2 (16 KB) SRAM2 (16 KB) SRAM2 (16 KB)
  • Page 72 Memory and bus architecture RM0090 Table 4. Memory mapping vs. Boot mode/physical remap in STM32F42xxx and STM32F43xxx (continued) Boot/Remap in Boot/Remap in Boot/Remap in Addresses Remap in FMC main Flash memory embedded SRAM System memory FMC bank 1 0x0400 0000 - 0x07FF FFFF Reserved Reserved Reserved...
  • Page 73: Embedded Flash Memory Interface

    RM0090 Embedded Flash memory interface Embedded Flash memory interface 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.
  • Page 74: Embedded Flash Memory In Stm32F405Xx/07Xx And Stm32F415Xx/17Xx

    Embedded Flash memory interface RM0090 Figure 4. Flash memory interface connection inside system architecture (STM32F42xxx and STM32F43xxx) Flash 32-bit memory Cortex-M4 with FPU Flash interface instruction I-Code 128 bits I-Code bus Flash D-Code Cortex memory core S bus 32-bit FLITF registers D-code bus data bus CCM data...
  • Page 75: Table 5. Flash Module Organization (Stm32F40X And Stm32F41X)

    RM0090 Embedded Flash memory interface Table 5. Flash module organization (STM32F40x and STM32F41x) Block Name Block base addresses Size Sector 0 0x0800 0000 - 0x0800 3FFF 16 Kbytes Sector 1 0x0800 4000 - 0x0800 7FFF 16 Kbytes Sector 2 0x0800 8000 - 0x0800 BFFF 16 Kbytes Sector 3 0x0800 C000 - 0x0800 FFFF...
  • Page 76: Embedded Flash Memory In Stm32F42Xxx And Stm32F43Xxx

    Embedded Flash memory interface RM0090 Embedded Flash memory in STM32F42xxx and STM32F43xxx The Flash memory has the following main features: • Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write capability (RWW) • 128 bits wide data read •...
  • Page 77: Table 6. Flash Module - 2 Mbyte Dual Bank Organization (Stm32F42Xxx And Stm32F43Xxx)

    RM0090 Embedded Flash memory interface Table 6. Flash module - 2 Mbyte dual bank organization (STM32F42xxx and STM32F43xxx) Block Bank Name Block base addresses Size Sector 0 0x0800 0000 - 0x0800 3FFF 16 Kbytes Sector 1 0x0800 4000 - 0x0800 7FFF 16 Kbytes Sector 2 0x0800 8000 - 0x0800 BFFF...
  • Page 78: Mbyte Flash Memory Single Bank Vs Dual Bank Organization (Stm32F42Xxx And Stm32F43Xxx)

    Embedded Flash memory interface RM0090 Table 7. 1 Mbyte Flash memory single bank vs dual bank organization (STM32F42xxx and STM32F43xxx) 1 Mbyte single bank Flash memory (default) 1 Mbyte dual bank Flash memory DB1M=0 DB1M=1 Main memory Sector number Sector size Main memory Sector number Sector size...
  • Page 79: Table 9. 1 Mbyte Dual Bank Flash Memory Organization (Stm32F42Xxx And Stm32F43Xxx)

    RM0090 Embedded Flash memory interface Table 8. 1 Mbyte single bank Flash memory organization (STM32F42xxx and STM32F43xxx) (continued) Block Bank Name Block base addresses Size System memory 0x1FFF 0000 - 0x1FFFF 77FF 30 Kbytes 0x1FFF 7800 - 0x1FFF 7A0F 528 bytes 0x1FFF C000 - 0x1FFF C00F 16 bytes Option bytes...
  • Page 80: Read Interface

    Embedded Flash memory interface RM0090 Read interface 3.5.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.
  • Page 81: Table 11. Number Of Wait States According To Cpu Clock (Hclk) Frequency (Stm32F42Xxx And Stm32F43Xxx)

    RM0090 Embedded Flash memory interface Table 11. Number of wait states according to CPU clock (HCLK) frequency (STM32F42xxx and STM32F43xxx) HCLK (MHz) Wait states (WS) Voltage range Voltage range Voltage range Voltage range (LATENCY) 1.8 V - 2.1 V 2.7 V - 3.6 V 2.4 V - 2.7 V 2.1 V - 2.4 V Prefetch OFF...
  • Page 82: Adaptive Real-Time Memory Accelerator (Art Accelerator™)

    Embedded Flash memory interface RM0090 Note: A change in CPU clock configuration or wait state (WS) configuration may not be effective straight away. To make sure that the current CPU clock frequency is the one you have configured, you can check the AHB prescaler factor and clock source status values. To make sure that the number of WS you have programmed is effective, you can read the FLASH_ACR register.
  • Page 83: Figure 5. Sequential 32-Bit Instruction Execution

    RM0090 Embedded Flash memory interface Figure 5. Sequential 32-bit instruction execution WAIT Without prefetch WAIT ins 1 ins 2 ins 3 ins 4 ins 5 ins 6 ins 7 ins 8 fetch fetch fetch fetch fetch fetch fetch fetch Read ins 1, 2, 3, 4 Gives ins 1, 2, 3, 4 Read ins 5, 6, 7, 8 Gives ins 5, 6, 7, 8 Wait data With prefetch...
  • Page 84: Erase And Program Operations

    Embedded Flash memory interface RM0090 Instruction cache memory To limit the time lost due to jumps, it is possible to retain 64 lines of 128 bits in an instruction cache memory. This feature can be enabled by setting the instruction cache enable (ICEN) bit in the FLASH_ACR register.
  • Page 85: Program/Erase Parallelism

    RM0090 Embedded Flash memory interface Note: The FLASH_CR register is not accessible in write mode when the BSY bit in the FLASH_SR register is set. Any attempt to write to it with the BSY bit set will cause the AHB bus to stall until the BSY bit is cleared.
  • Page 86: Programming

    Embedded Flash memory interface RM0090 Bank erase in STM32F42xxx and STM32F43xxx devices To erase bank 1 or bank 2, follow the procedure below: Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_SR register Set MER or MER1 bit accordingly in the FLASH_CR register Set the STRT bit in the FLASH_CR register Wait for the BSY bit to be reset.
  • Page 87: Read-While-Write (Rww)

    RM0090 Embedded Flash memory interface 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).
  • Page 88: Interrupts

    Embedded Flash memory interface RM0090 Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_SR register (BSY is active when erase/program operation is on going on bank 1 or bank 2) Set the PG bit in the FLASH_CR register Perform the data write operation(s) to the desired memory address inside main memory block or OTP area Wait for the BSY bit to be reset.
  • Page 89: Table 15. Description Of The Option Bytes (Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    RM0090 Embedded Flash memory interface Table 14. Option byte organization (continued) Address [63:16] [15:0] 0x1FFE C000 Reserved Reserved SPRMOD and Write protection nWRP bits for 0x1FFE C008 Reserved sectors 12 to 23 Table 15. Description of the option bytes (STM32F405xx/07xx and STM32F415xx/17xx) Option bytes (word, address 0x1FFF C000) RDP: Read protection option byte.
  • Page 90: Table 16. Description Of The Option Bytes (Stm32F42Xxx And Stm32F43Xxx)

    Embedded Flash memory interface RM0090 Table 15. Description of the option bytes (STM32F405xx/07xx and STM32F415xx/17xx) (continued) Option bytes (word, address 0x1FFF C008) Bits 15:12 0xF: Not used nWRP: Flash memory write protection option bytes Sectors 0 to 11 can be write protected. nWRPi Bits 11:0 0: Write protection active on selected sector...
  • Page 91 RM0090 Embedded Flash memory interface Table 16. Description of the option bytes (STM32F42xxx and STM32F43xxx) (continued) 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...
  • Page 92: Programming User Option Bytes

    Embedded Flash memory interface RM0090 Table 16. Description of the option bytes (STM32F42xxx and STM32F43xxx) (continued) Option bytes (word, address 0x1FFE C008) Bit 15:12 0xF: not used nWRP: Flash memory write protection option bytes for bank 2. Sectors 12 to 23 can be write protected.
  • Page 93: Read Protection (Rdp)

    RM0090 Embedded Flash memory interface Note: The value of an option byte is automatically modified by first erasing the user configuration sector (bank 1 and 2) and then programming all the option bytes with the values contained in the FLASH_OPTCR and FLASH_OPTCR1 registers. 3.7.3 Read protection (RDP) The user area in the Flash memory can be protected against read operations by an...
  • Page 94: Write Protections

    Embedded Flash memory interface RM0090 Table 17. Access versus read protection level Debug features, Boot from RAM or Booting from Flash memory Protection from System memory bootloader Memory area Level Read Write Erase Read Write Erase Level 1 Main Flash Memory and Backup SRAM Level 2 Level 1...
  • Page 95: Proprietary Code Readout Protection (Pcrop)

    RM0090 Embedded Flash memory interface cannot be erased or programmed. Consequently, a mass erase cannot be performed if one of the sectors is write-protected. If an erase/program operation to a write-protected part of the Flash memory is attempted (sector protected by write protection bit, OTP part locked or part of the Flash memory that can never be written like the ICP), the write protection error flag (WRPERR) is set in the FLASH_SR register.
  • Page 96: Figure 7. Pcrop Levels

    Embedded Flash memory interface RM0090 When a sector is readout protected (PCROP mode activated), it can only be accessed for code fetch through ICODE Bus on Flash interface: • Any read access performed through the D-bus triggers a RDERR flag error. •...
  • Page 97: One-Time Programmable Bytes

    RM0090 Embedded Flash memory interface One-time programmable bytes Table 18 shows the organization of the one-time programmable (OTP) part of the OTP area. Table 18. OTP area organization Block [128:96] [95:64] [63:32] [31:0] Address byte 0 OTP0 OTP0 OTP0 OTP0 0x1FFF 7800 OTP0 OTP0...
  • Page 98: Flash Interface Registers

    Embedded Flash memory interface RM0090 Flash interface registers 3.9.1 Flash access control register (FLASH_ACR) for STM32F405xx/07xx and STM32F415xx/17xx The Flash access control register is used to enable/disable the acceleration features and control the Flash memory access time according to CPU frequency. Address offset: 0x00 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access...
  • Page 99: Flash Access Control Register (Flash_Acr)

    RM0090 Embedded Flash memory interface 3.9.2 Flash access control register (FLASH_ACR) for STM32F42xxx and STM32F43xxx The Flash access control register is used to enable/disable the acceleration features and control the Flash memory access time according to CPU frequency. Address offset: 0x00 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access Reserved...
  • Page 100: Flash Key Register (Flash_Keyr)

    Embedded Flash memory interface RM0090 3.9.3 Flash key register (FLASH_KEYR) The Flash key register is used to allow access to the Flash control register and so, to allow program and erase operations. Address offset: 0x04 Reset value: 0x0000 0000 Access: no wait state, word access KEY[31:16] KEY[15:0] Bits 31:0 FKEYR[31:0]: FPEC key...
  • Page 101: Flash Status Register (Flash_Sr) For

    RM0090 Embedded Flash memory interface 3.9.5 Flash status register (FLASH_SR) for STM32F405xx/07xx and STM32F415xx/17xx The Flash status register gives information on ongoing program and erase operations. Address offset: 0x0C Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access Reserved PGSERR PGPERR PGAERR WRPERR OPERR...
  • Page 102: Stm32F42Xxx And Stm32F43Xxx

    Embedded Flash memory interface RM0090 Bits 3:2 Reserved, must be kept cleared. Bit 1 OPERR: Operation error Set by hardware when a flash operation (programming / erase /read) request is detected and can not be run because of parallelism, alignment, or write protection error. This bit is set only if error interrupts are enabled (ERRIE = 1).
  • Page 103: Flash Control Register (Flash_Cr) For

    RM0090 Embedded Flash memory interface Bit 6 PGPERR: Programming parallelism error Set by hardware when the size of the access (byte, half-word, word, double word) during the program sequence does not correspond to the parallelism configuration PSIZE (x8, x16, x32, x64).
  • Page 104 Embedded Flash memory interface RM0090 Bit 31 LOCK: Lock Write to 1 only. When it is set, this bit indicates that the FLASH_CR register is locked. It is cleared by hardware after detecting the unlock sequence. In the event of an unsuccessful unlock operation, this bit remains set until the next reset. Bits 30:26 Reserved, must be kept cleared.
  • Page 105: Flash Control Register (Flash_Cr) For

    RM0090 Embedded Flash memory interface 3.9.8 Flash control register (FLASH_CR) for STM32F42xxx and STM32F43xxx The Flash control register is used to configure and start Flash memory operations. Address offset: 0x10 Reset value: 0x8000 0000 Access: no wait state when no Flash memory operation is ongoing, word, half-word and byte access.
  • Page 106: Flash Option Control Register (Flash_Optcr) For

    Embedded Flash memory interface RM0090 Bits 7:3 SNB[3:0]: Sector number These bits select the sector to erase. 0000: sector 0 0001: sector 1 01011: sector 11 01100: not allowed 01101: not allowed 01110: not allowed 01111: not allowed 10000: section 12 10001: section 13 11011 sector 23 11100: not allowed...
  • Page 107 RM0090 Embedded Flash memory interface Bits 31:28 Reserved, must be kept cleared. Bits 27:16 nWRP[11:0]: Not write protect These bits contain the value of the write-protection option bytes after reset. They can be written to program a new write protect value into Flash memory. 0: Write protection active on selected sector 1: Write protection inactive on selected sector Bits 15:8 RDP[7:0]: Read protect...
  • Page 108: Flash Option Control Register (Flash_Optcr)

    Embedded Flash memory interface RM0090 3.9.10 Flash option control register (FLASH_OPTCR) for STM32F42xxx and STM32F43xxx The FLASH_OPTCR register is used to modify the user option bytes. Address offset: 0x14 Reset value: 0x0FFF AAED. The option bits are loaded with values from Flash memory at reset release.
  • Page 109 RM0090 Embedded Flash memory interface Bits 7:5 USER: User option bytes These bits contain the value of the user option byte after reset. They can be written to program a new user option byte value into Flash memory. Bit 7: nRST_STDBY Bit 6: nRST_STOP Bit 5: WDG_SW Note: When changing the WDG mode from hardware to software or from software to...
  • Page 110: Flash Option Control Register (Flash_Optcr1)

    Embedded Flash memory interface RM0090 3.9.11 Flash option control register (FLASH_OPTCR1) for STM32F42xxx and STM32F43xxx This register is available only on STM32F42xxx and STM32F43xxx. The FLASH_OPTCR1 register is used to modify the user option bytes for bank 2. Address offset: 0x18 Reset value: 0x0FFF 0000.
  • Page 111: Flash Interface Register Map

    RM0090 Embedded Flash memory interface 3.9.12 Flash interface register map Table 19. Flash register map and reset values (STM32F405xx/07xx and STM32F415xx/17xx) Offset Register LATENCY FLASH_ACR [2:0] 0x00 Reserved Reserved Reset value FLASH_ KEY[31:16] KEY[15:0] KEYR 0x04 Reset value FLASH_OPT OPTKEYR[31:16] OPTKEYR[15:0] KEYR 0x08...
  • Page 112 Embedded Flash memory interface RM0090 Table 20. Flash register map and reset values (STM32F42xxx and STM32F43xxx) (continued) Offset Register FLASH_CR SNB[4:0] 0x10 Reserved Reserved Reserved Reset value FLASH_OPTCR nWRP[11:0] RDP[7:0] 0x14 Reset value 1 0 1 FLASH_ nWRP[11:0] OPTCR1 0x18 Reserved Reset value 112/1749...
  • Page 113: Crc Calculation Unit

    RM0090 CRC calculation unit CRC calculation unit This section applies to the whole STM32F4xx family, unless otherwise specified. CRC introduction The CRC (cyclic redundancy check) calculation unit is used to get a CRC code from a 32-bit data word and a fixed generator polynomial. Among other applications, CRC-based techniques are used to verify data transmission or storage integrity.
  • Page 114: Crc Functional Description

    CRC calculation unit RM0090 CRC functional description The CRC calculation unit mainly consists of a single 32-bit data register, which: • is used as an input register to enter new data in the CRC calculator (when writing into the register) •...
  • Page 115: Control Register (Crc_Cr)

    RM0090 CRC calculation unit Bits 31:8 Reserved, must be kept at reset value. Bits 7:0 General-purpose 8-bit data register bits Can be used as a temporary storage location for one byte. This register is not affected by CRC resets generated by the RESET bit in the CRC_CR register.
  • Page 116: Power Controller (Pwr)

    Power controller (PWR) RM0090 Power controller (PWR) This section applies to the whole STM32F4xx family, unless otherwise specified. Power supplies The device requires a 1.8 to 3.6 V operating voltage supply (V ). An embedded linear voltage regulator is used to supply the internal 1.2 V digital power. The real-time clock (RTC), the RTC backup registers, and the backup SRAM (BKP SRAM) can be powered from the V voltage when the main V...
  • Page 117: Independent A/D Converter Supply And Reference Voltage

    RM0090 Power controller (PWR) Figure 10. Power supply overview for STM32F42xxx and STM32F43xxx V BAT Backup circuitry (OSC32K,RTC, Po wer swi tch VBAT = Wakeup logic 1.65 to 3.6V Backup registers, backup RAM) GP I/Os Logic Kernel logic (CPU, CAP_1 digital CAP_2 2 ×...
  • Page 118: Battery Backup Domain

    Power controller (PWR) RM0090 5.1.2 Battery backup domain Backup domain description To retain the content of the RTC backup registers, backup SRAM, and supply the RTC when is turned off, V pin can be connected to an optional standby voltage supplied by a battery or by another source.
  • Page 119 RM0090 Power controller (PWR) When the backup domain is supplied by V (analog switch connected to V because 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_AF1 pin (refer to Table 37: RTC_AF1 pin for more details about this pin configuration)
  • Page 120: Voltage Regulator For Stm32F405Xx/07Xx And Stm32F415Xx/17Xx

    Power controller (PWR) RM0090 by a dedicated bit, the BRE control bit of the PWR_CSR register (see Section 5.4.2: PWR power control/status register (PWR_CSR) for STM32F405xx/07xx and STM32F415xx/17xx). The backup SRAM is not mass erased by an tamper event. When the Flash memory is read protected, the backup SRAM is also read protected to prevent confidential data, such as cryptographic private key, from being accessed.
  • Page 121: Voltage Regulator For Stm32F42Xxx And Stm32F43Xxx

    RM0090 Power controller (PWR) 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: The programmed voltage scale remains the same during Stop mode (see Section 5.4.1: PWR power control register (PWR_CR) for STM32F405xx/07xx STM32F415xx/17xx).
  • Page 122: Table 22. Voltage Regulator Configuration Mode Versus Device Operating Mode

    Power controller (PWR) RM0090 scale 3 is automatically selected.(see Section 5.4.1: PWR power control register (PWR_CR) for STM32F405xx/07xx and STM32F415xx/17xx. 2 operating modes are available: – Normal mode: The CPU and core logic operate at maximum frequency at a given voltage scaling (scale 1, scale 2 or scale 3) –...
  • Page 123 RM0090 Power controller (PWR) Entering Over-drive mode It is recommended to enter Over-drive mode when the application is not running critical tasks and when the system clock source is either HSI or HSE. To optimize the configuration time, enable the Over-drive mode during the PLL lock phase. To enter Over-drive mode, follow the sequence below: Select HSI or HSE as system clock.
  • Page 124: Power Supply Supervisor

    Power controller (PWR) RM0090 Example of sequence 2: Select HSI or HSE as system clock source. Disable the peripheral clocks that are not generated by the System PLL (I2S clock, LCD-TFT clock, SAI1 clock, USB_48MHz clock,..). Reset the ODSW bit in the PWR_CR register to switch back the voltage regulator to Normal mode.
  • Page 125: Brownout Reset (Bor)

    RM0090 Power controller (PWR) 5.2.2 Brownout reset (BOR) During power on, the Brownout reset (BOR) keeps the device under reset until the supply voltage reaches the specified V threshold. is configured through device option bytes. By default, BOR is off. 3 programmable threshold levels can be selected: •...
  • Page 126: Low-Power Modes

    Power controller (PWR) RM0090 STM32F405xx/07xx and STM32F415xx/17xx PWR power control register (PWR_CR) for STM32F42xxx and STM32F43xxx. The PVD is enabled by setting the PVDE bit. A PVDO flag is available, in the PWR power control/status register (PWR_CSR) for STM32F405xx/07xx and STM32F415xx/17xx, to indicate if V is higher or lower than the PVD threshold.
  • Page 127 RM0090 Power controller (PWR) In addition, the power consumption in Run mode can be reduce by one of the following means: • Slowing down the system clocks • Gating the clocks to the APBx and AHBx peripherals when they are unused. Entering low-power mode Low-power modes are entered by the MCU by executing the WFI (Wait For Interrupt), or ®...
  • Page 128: Slowing Down System Clocks

    Power controller (PWR) RM0090 Only enabled NVIC interrupts with sufficient priority will wakeup and interrupt the MCU. Table 23. Low-power mode summary Effect on Effect on 1.2 V Mode name Entry Wakeup Voltage regulator domain clocks domain clocks WFI or Return Sleep CPU CLK OFF Any interrupt...
  • Page 129: Sleep Mode

    RM0090 Power controller (PWR) Peripheral clock gating is controlled by the AHB1 peripheral clock enable register (RCC_AHB1ENR), AHB2 peripheral clock enable register (RCC_AHB2ENR), AHB3 peripheral clock enable register (RCC_AHB3ENR) (see Section 7.3.10: RCC AHB1 peripheral clock enable register (RCC_AHB1ENR), Section 7.3.11: RCC AHB2 peripheral clock enable register (RCC_AHB2ENR), Section 7.3.12: RCC AHB3 peripheral clock...
  • Page 130: Stop Mode (Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    Power controller (PWR) RM0090 Table 24. Sleep-now entry and exit (continued) Sleep-now mode Description If WFI or Return from ISR was used for entry: Interrupt: Refer to Table 61: Vector table for STM32F405xx/07xx and STM32F415xx/17xx Table 62: Vector table for STM32F42xxx and STM32F43xxx If WFE was used for entry and SEVONPEND = 0 Mode exit...
  • Page 131: Table 26. Stop Operating Modes (Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    RM0090 Power controller (PWR) Table 26. Stop operating modes (STM32F405xx/07xx and STM32F415xx/17xx) Stop mode LPDS bit FPDS bit Wake-up latency STOP MR HSI RC startup time (Main regulator) HSI RC startup time + STOP MR-FPD Flash wakeup time from Power Down mode HSI RC startup time + STOP LP...
  • Page 132: Table 27. Stop Mode Entry And Exit (For Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    Power controller (PWR) RM0090 Note: If the application needs to disable the external clock before entering Stop mode, the HSEON bit must first be disabled and the system clock switched to HSI. Otherwise, if the HSEON bit is kept enabled while the external clock (external oscillator) can be removed before entering stop mode, the clock security system (CSS) feature must be enabled to detect any external oscillator failure and avoid a malfunction behavior when entering stop mode.
  • Page 133: Stop Mode (Stm32F42Xxx And Stm32F43Xxx)

    RM0090 Power controller (PWR) Table 27. Stop mode entry and exit (for STM32F405xx/07xx and STM32F415xx/17xx) Stop mode Description If WFI or Return from ISR was used for entry: Any EXTI lines configured in Interrupt mode (the corresponding EXTI Interrupt vector must be enabled in the NVIC). The interrupt source can be external interrupts or peripherals with wakeup capability.
  • Page 134: Table 28. Stop Operating Modes (Stm32F42Xxx And Stm32F43Xxx)

    Power controller (PWR) RM0090 Table 28. Stop operating modes (STM32F42xxx and STM32F43xxx) UDEN[1:0] MRUDS LPUDS LPDS FPDS Voltage Regulator Mode Wakeup latency bits STOP MR HSI RC startup time (Main Regulator) HSI RC startup time + STOP MR- FPD Flash wakeup time from power- down mode HSI RC startup time + Normal...
  • Page 135 RM0090 Power controller (PWR) In Stop mode, the following features can be selected by programming individual control bits: • Independent watchdog (IWDG): the IWDG is started by writing to its Key register or by hardware option. Once started it cannot be stopped except by a Reset. See Section 21.3 Section 21: Independent watchdog (IWDG).
  • Page 136: Standby Mode

    Power controller (PWR) RM0090 Table 29. Stop mode entry and exit (STM32F42xxx and STM32F43xxx) Stop mode Description WFI (Wait for Interrupt) or WFE (Wait for Event) while: – No interrupt or event is pending, ® – SLEEPDEEP bit is set in Cortex -M4 with FPU System Control register, –...
  • Page 137: Table 30. Standby Mode Entry And Exit

    RM0090 Power controller (PWR) Entering Standby mode The Standby mode is entered according to Section : Entering low-power mode, when the ® SLEEPDEEP bit in the Cortex -M4 with FPU System Control register is set. Refer to Table 30 for more details on how to enter Standby mode. In Standby mode, the following features can be selected by programming individual control bits: •...
  • Page 138: Programming The Rtc Alternate Functions To Wake Up The Device From The Stop And Standby Modes

    Power controller (PWR) RM0090 I/O states in Standby mode In Standby mode, all I/O pins are high impedance except for: • Reset pad (still available) • RTC_AF1 pin (PC13) if configured for tamper, time stamp, RTC Alarm out, or RTC clock calibration out •...
  • Page 139 RM0090 Power controller (PWR) 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: Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt or Event modes) Enable the RTC Alarm Interrupt in the RTC_CR register Configure the RTC to generate the RTC alarm...
  • Page 140 Power controller (PWR) RM0090 Clear the PWR Wakeup (WUF) flag Enable the RTC alarm interrupt Re-enter the low-power mode • When using RTC wakeup to wake up the device from the low-power modes: Disable the RTC Wakeup interrupt (WUTIE bit in the RTC_CR register) Clear the RTC Wakeup (WUTF) flag Clear the PWR Wakeup (WUF) flag Enable the RTC Wakeup interrupt...
  • Page 141: Power Control Registers (Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    RM0090 Power controller (PWR) Power control registers (STM32F405xx/07xx and STM32F415xx/17xx) 5.4.1 PWR power control register (PWR_CR) STM32F405xx/07xx and STM32F415xx/17xx Address offset: 0x00 Reset value: 0x0000 4000 (reset by wakeup from Standby mode) Reserved FPDS PLS[2:0] PVDE CSBF CWUF PDDS LPDS Res.
  • Page 142: Pwr Power Control/Status Register (Pwr_Csr)

    Power controller (PWR) RM0090 Bit 4 PVDE: Power voltage detector enable This bit is set and cleared by software. 0: PVD disabled 1: PVD enabled Bit 3 CSBF: Clear standby flag This bit is always read as 0. 0: No effect 1: Clear the SBF Standby Flag (write).
  • Page 143 RM0090 Power controller (PWR) Bits 13:10 Reserved, must be kept at reset value. Bit 9 BRE: Backup regulator enable When set, the Backup regulator (used to maintain backup SRAM content in Standby and modes) is enabled. If BRE is reset, the backup regulator is switched off. The backup SRAM can still be used but its content will be lost in the Standby and V modes.
  • Page 144: Power Control Registers (Stm32F42Xxx And Stm32F43Xxx)

    Power controller (PWR) RM0090 Power control registers (STM32F42xxx and STM32F43xxx) 5.5.1 PWR power control register (PWR_CR) for STM32F42xxx and STM32F43xxx Address offset: 0x00 Reset value: 0x0000 C000 (reset by wakeup from Standby mode) ODSWE UDEN[1:0] ODEN Reserved VOS[1:0] ADCDC1 MRUDS LPUDS FPDS PLS[2:0]...
  • Page 145 RM0090 Power controller (PWR) Bits 15:14 VOS[1:0]: Regulator voltage scaling output selection These bits control the main internal voltage regulator output voltage to achieve a trade-off between performance and power consumption when the device does not operate at the maximum frequency (refer to the STM32F42xx and STM32F43xx datasheets for more details).
  • Page 146 Power controller (PWR) RM0090 Bits 7:5 PLS[2:0]: PVD level selection These bits are written by software to select the voltage threshold detected by the Power Voltage Detector 000: 2.0 V 001: 2.1 V 010: 2.3 V 011: 2.5 V 100: 2.6 V 101: 2.7 V 110: 2.8 V 111: 2.9 V...
  • Page 147: Pwr Power Control/Status Register (Pwr_Csr)

    RM0090 Power controller (PWR) 5.5.2 PWR power control/status register (PWR_CSR) for STM32F42xxx and STM32F43xxx Address offset: 0x04 Reset value: 0x0000 0000 (not reset by wakeup from Standby mode) Additional APB cycles are needed to read this register versus a standard APB read. UDRDY[1:0] ODSWRDY ODRDY Reserved...
  • Page 148 Power controller (PWR) RM0090 Bit 8 EWUP: Enable WKUP pin This bit is set and cleared by software. 0: WKUP pin is used for general purpose I/O. An event on the WKUP pin does not wakeup the device from Standby mode. 1: WKUP pin is used for wakeup from Standby mode and forced in input pull down configuration (rising edge on WKUP pin wakes-up the system from Standby mode).
  • Page 149: Pwr Register Map

    RM0090 Power controller (PWR) PWR register map The following table summarizes the PWR registers. Table 31. PWR - register map and reset values for STM32F405xx/07xx and STM32F415xx/17xx Offset Register PWR_CR PLS[2:0] 0x000 Reserved Reserved Reset value PWR_CSR 0x004 Reserved Reserved Reserved Reset value Table 32.
  • Page 150: Reset And Clock Control For Stm32F42Xxx And Stm32F43Xxx (Rcc)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Reset There are three types of reset, defined as system Reset, power Reset and backup domain Reset. 6.1.1 System reset A system reset sets all registers to their reset values except the reset flags in the clock controller CSR register and the registers in the Backup domain (see Figure 15).
  • Page 151: Backup Domain Reset

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) These sources act on the NRST pin and it is always kept low during the delay phase. The RESET service routine vector is fixed at address in the memory map. 0x0000_0004 The system reset signal provided to the device is output on the NRST pin.
  • Page 152: Figure 16. Clock Tree

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Each clock source can be switched on or off independently when it is not used, to optimize power consumption. Figure 16. Clock tree Watchdog IWDGCLK To Independent enable LSI RC watchdog 32 kHz RTCSEL[1:0]...
  • Page 153 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 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 Ethernet, USB OTG FS and HS, I2S, SAI, LTDC, and SDIO.
  • Page 154: Hse Clock

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 ® FCLK acts as Cortex -M4 with FPU free-running clock. For more details, refer to the ® Cortex -M4 with FPU technical reference manual. 6.2.1 HSE clock The high speed external clock signal (HSE) can be generated from two possible clock sources: •...
  • Page 155: Hsi Clock

    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 T = 25 °C. After reset, the factory calibration value is loaded in the HSICAL[7:0] bits in the...
  • Page 156: Lse Clock

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 The three PLLs are disabled by hardware when entering Stop and Standby modes, or when an HSE failure occurs when HSE or PLL (clocked by HSE) are used as system clock. PLL configuration register (RCC_PLLCFGR),RCC clock configuration register (RCC_CFGR), and RCC Dedicated Clock Configuration Register (RCC_DCKCFGR)
  • Page 157: Clock Security System (Css)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.2.7 Clock security system (CSS) The clock security system can be activated by software. In this case, the clock detector is enabled after the HSE oscillator startup delay, and disabled when this oscillator is stopped. If a failure is detected on the HSE clock, this oscillator is automatically disabled, a clock failure event is sent to the break inputs of advanced-control timers TIM1 and TIM8, and an interrupt is generated to inform the software about the failure (clock security system...
  • Page 158: Watchdog Clock

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Note: To read the RTC calendar register when the APB1 clock frequency is less than seven times the RTC clock frequency (f < 7xf ), the software must read the calendar time and APB1 RTCLCK date registers twice.
  • Page 159: Figure 18. Frequency Measurement With Tim5 In Input Capture Mode

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) The primary purpose of having the LSE connected to the channel4 input capture is to be able to precisely measure the HSI (this requires to have the HSI used as the system clock source).
  • Page 160: Figure 19. Frequency Measurement With Tim11 In Input Capture Mode

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Figure 19. Frequency measurement with TIM11 in Input capture mode TIM11 TI1_RMP[1:0] GPIO HSE_RTC(1 MHz) ai18433 160/1749 RM0090 Rev 18...
  • Page 161: Rcc Registers

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RCC registers Refer to Section 1.1: List of abbreviations for registers for a list of abbreviations used in register descriptions. 6.3.1 RCC clock control register (RCC_CR) Address offset: 0x00 Reset value: 0x0000 XX83 where X is undefined. Access: no wait state, word, half-word and byte access PLLSAI PLLSAI...
  • Page 162 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bits 23:20 Reserved, must be kept at reset value. Bit 19 CSSON: Clock security system enable Set and cleared by software to enable the clock security system. When CSSON is set, the clock detector is enabled by hardware when the HSE oscillator is ready, and disabled by hardware if an oscillator failure is detected.
  • Page 163: Rcc Pll Configuration Register (Rcc_Pllcfgr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.3.2 RCC PLL configuration register (RCC_PLLCFGR) Address offset: 0x04 Reset value: 0x2400 3010 Access: no wait state, word, half-word and byte access. This register is used to configure the PLL clock outputs according to the formulas: •...
  • Page 164 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 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 180 MHz on this domain.
  • Page 165: Rcc Clock Configuration Register (Rcc_Cfgr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.3.3 RCC clock configuration register (RCC_CFGR) Address offset: 0x08 Reset value: 0x0000 0000 Access: 0 ≤ wait state ≤ 2, word, half-word and byte access 1 or 2 wait states inserted only if the access occurs during a clock source switch. I2SSC MCO2 MCO2 PRE[2:0]...
  • Page 166 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bits 22:21 MCO1: Microcontroller clock output 1 Set and cleared by software. Clock source selection may generate glitches on MCO1. It is highly recommended to configure these bits only after reset before enabling the external oscillators and PLL.
  • Page 167: Rcc Clock Interrupt Register (Rcc_Cir)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bits 7:4 HPRE: AHB prescaler Set and cleared by software to control AHB clock division factor. Caution: The clocks are divided with the new prescaler factor from 1 to 16 AHB cycles after HPRE write.
  • Page 168 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bits 31:24 Reserved, must be kept at reset value. Bit 23 CSSC: Clock security system interrupt clear This bit is set by software to clear the CSSF flag. 0: No effect 1: Clear CSSF flag Bit 22 PLLSAIRDYC: PLLSAI Ready Interrupt Clear This bit is set by software to clear PLLSAIRDYF flag.
  • Page 169 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 12 PLLRDYIE: Main PLL (PLL) ready interrupt enable This bit is set and cleared by software to enable/disable interrupt caused by PLL lock. 0: PLL lock interrupt disabled 1: PLL lock interrupt enabled Bit 11 HSERDYIE: HSE ready interrupt enable This bit is set and cleared by software to enable/disable interrupt caused by the HSE oscillator stabilization.
  • Page 170: Rcc Ahb1 Peripheral Reset Register (Rcc_Ahb1Rstr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 3 HSERDYF: HSE ready interrupt flag This bit is set by hardware when External High Speed clock becomes stable and HSERDYDIE is set. It is cleared by software by setting the HSERDYC bit. 0: No clock ready interrupt caused by the HSE oscillator 1: Clock ready interrupt caused by the HSE oscillator Bit 2 HSIRDYF: HSI ready interrupt flag...
  • Page 171 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 25 ETHMACRST: Ethernet MAC reset This bit is set and cleared by software. 0: does not reset Ethernet MAC 1: resets Ethernet MAC Bit 24 Reserved, must be kept at reset value. Bit 23 DMA2DRST: DMA2D reset This bit is set and reset by software.
  • Page 172 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 5 GPIOFRST: IO port F reset This bit is set and cleared by software. 0: does not reset IO port F 1: resets IO port F Bit 4 GPIOERST: IO port E reset This bit is set and cleared by software.
  • Page 173: Rcc Ahb2 Peripheral Reset Register (Rcc_Ahb2Rstr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.3.6 RCC AHB2 peripheral reset register (RCC_AHB2RSTR) Address offset: 0x14 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access Reserved OTGFS HASH CRYP DCMI Reserved Reserved Bits 31:8 Reserved, must be kept at reset value.
  • Page 174: Rcc Ahb3 Peripheral Reset Register (Rcc_Ahb3Rstr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 6.3.7 RCC AHB3 peripheral reset register (RCC_AHB3RSTR) Address offset: 0x18 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access. Reserved FMCRST Reserved Bits 31:1 Reserved, must be kept at reset value. Bit 0 FMCRST: Flexible memory controller module reset Set and cleared by software.
  • Page 175 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 31 UART8RST: UART8 reset Set and cleared by software. 0: does not reset UART8 1: resets UART8 Bit 30 UART7RST: UART7 reset Set and cleared by software. 0: does not reset UART7 1: resets UART7 Bit 29 DACRST: DAC reset Set and cleared by software.
  • Page 176 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 18 USART3RST: USART3 reset Set and cleared by software. 0: does not reset USART3 1: resets USART3 Bit 17 USART2RST: USART2 reset Set and cleared by software. 0: does not reset USART2 1: resets USART2 Bit 16 Reserved, must be kept at reset value.
  • Page 177 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 3 TIM5RST: TIM5 reset Set and cleared by software. 0: does not reset TIM5 1: resets TIM5 Bit 2 TIM4RST: TIM4 reset Set and cleared by software. 0: does not reset TIM4 1: resets TIM4 Bit 1 TIM3RST: TIM3 reset Set and cleared by software.
  • Page 178: Rcc Apb2 Peripheral Reset Register (Rcc_Apb2Rstr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 6.3.9 RCC APB2 peripheral reset register (RCC_APB2RSTR) Address offset: 0x24 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access. TIM11 TIM10 TIM9 SAI1 SPI6 SPI5 CRST Reserved Reserved Res.
  • Page 179 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 15 Reserved, must be kept at reset value. Bit 14 SYSCFGRST: System configuration controller reset This bit is set and cleared by software. 0: does not reset the System configuration controller 1: resets the System configuration controller Bit 13 SPI4RST: SPI4 reset This bit is set and cleared by software.
  • Page 180: Rcc Ahb1 Peripheral Clock Register (Rcc_Ahb1Enr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 6.3.10 RCC AHB1 peripheral clock register (RCC_AHB1ENR) Address offset: 0x30 Reset value: 0x0010 0000 Access: no wait state, word, half-word and byte access. OTGH ETHM ETHM ETHM OTGH ETHMA DMA2D DMA2E DMA1E CCMDAT...
  • Page 181 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 22 DMA2EN: DMA2 clock enable This bit is set and cleared by software. 0: DMA2 clock disabled 1: DMA2 clock enabled Bit 21 DMA1EN: DMA1 clock enable This bit is set and cleared by software. 0: DMA1 clock disabled 1: DMA1 clock enabled Bit 20 CCMDATARAMEN: CCM data RAM clock enable...
  • Page 182: Rcc Ahb2 Peripheral Clock Enable Register (Rcc_Ahb2Enr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 5 GPIOFEN: IO port F clock enable This bit is set and cleared by software. 0: IO port F clock disabled 1: IO port F clock enabled Bit 4 GPIOEEN: IO port E clock enable This bit is set and cleared by software.
  • Page 183: Rcc Ahb3 Peripheral Clock Enable Register (Rcc_Ahb3Enr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 5 HASHEN: Hash modules clock enable This bit is set and cleared by software. 0: Hash modules clock disabled 1: Hash modules clock enabled Bit 4 CRYPEN: Cryptographic modules clock enable This bit is set and cleared by software.
  • Page 184 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 31 UART8EN: UART8 clock enable This bit is set and cleared by software. 0: UART8 clock disabled 1: UART8 clock enabled Bit 30 UART7EN: UART7 clock enable This bit is set and cleared by software. 0: UART7 clock disabled 1: UART7 clock enabled Bit 29 DACEN: DAC interface clock enable...
  • Page 185 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 18 USART3EN: USART3 clock enable This bit is set and cleared by software. 0: USART3 clock disabled 1: USART3 clock enabled Bit 17 USART2EN: USART2 clock enable This bit is set and cleared by software. 0: USART2 clock disabled 1: USART2 clock enabled Bit 16 Reserved, must be kept at reset value.
  • Page 186 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 3 TIM5EN: TIM5 clock enable This bit is set and cleared by software. 0: TIM5 clock disabled 1: TIM5 clock enabled Bit 2 TIM4EN: TIM4 clock enable This bit is set and cleared by software. 0: TIM4 clock disabled 1: TIM4 clock enabled Bit 1 TIM3EN: TIM3 clock enable...
  • Page 187: Rcc Apb2 Peripheral Clock Enable Register (Rcc_Apb2Enr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.3.14 RCC APB2 peripheral clock enable register (RCC_APB2ENR) Address offset: 0x44 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access. TIM11 TIM10 TIM9 LTDC SAI1EN SPI6EN SPI5EN Reserved Reserved Res.
  • Page 188 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 14 SYSCFGEN: System configuration controller clock enable This bit is set and cleared by software. 0: System configuration controller clock disabled 1: System configuration controller clock enabled Bit 13 SPI4EN: SPI4 clock enable This bit is set and cleared by software.
  • Page 189: Rcc Ahb1 Peripheral Clock Enable In Low Power Mode Register (Rcc_Ahb1Lpenr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.3.15 RCC AHB1 peripheral clock enable in low power mode register (RCC_AHB1LPENR) Address offset: 0x50 Reset value: 0x7EEF 97FF Access: no wait state, word, half-word and byte access. OTGHS OTGH ETHPT ETHMA BKPSRA...
  • Page 190 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 23 DMA2DLPEN: DMA2D clock enable during Sleep mode This bit is set and cleared by software. 0: DMA2D clock disabled during Sleep mode 1: DMA2D clock enabled during Sleep mode Bit 22 DMA2LPEN: DMA2 clock enable during Sleep mode This bit is set and cleared by software.
  • Page 191 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 9 GPIOJLPEN: IO port J clock enable during Sleep mode This bit is set and cleared by software. 0: IO port J clock disabled during Sleep mode 1: IO port J clock enabled during Sleep mode Bit 8 GPIOILPEN: IO port I clock enable during Sleep mode This bit is set and cleared by software.
  • Page 192: Rcc Ahb2 Peripheral Clock Enable In Low Power Mode Register (Rcc_Ahb2Lpenr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 6.3.16 RCC AHB2 peripheral clock enable in low power mode register (RCC_AHB2LPENR) Address offset: 0x54 Reset value: 0x0000 00F1 Access: no wait state, word, half-word and byte access. Reserved OTGFS HASH CRYP DCMI...
  • Page 193: Rcc Ahb3 Peripheral Clock Enable In Low Power Mode Register (Rcc_Ahb3Lpenr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.3.17 RCC AHB3 peripheral clock enable in low power mode register (RCC_AHB3LPENR) Address offset: 0x58 Reset value: 0x0000 0001 Access: no wait state, word, half-word and byte access. Reserved LPEN Reserved Bits 31:1Reserved, must be kept at reset value.
  • Page 194 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 31 UART8LPEN: UART8 clock enable during Sleep mode This bit is set and cleared by software. 0: UART8 clock disabled during Sleep mode 1: UART8 clock enabled during Sleep mode Bit 30 UART7LPEN: UART7 clock enable during Sleep mode This bit is set and cleared by software.
  • Page 195 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 18 USART3LPEN: USART3 clock enable during Sleep mode This bit is set and cleared by software. 0: USART3 clock disabled during Sleep mode 1: USART3 clock enabled during Sleep mode Bit 17 USART2LPEN: USART2 clock enable during Sleep mode This bit is set and cleared by software.
  • Page 196 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 3 TIM5LPEN: TIM5 clock enable during Sleep mode This bit is set and cleared by software. 0: TIM5 clock disabled during Sleep mode 1: TIM5 clock enabled during Sleep mode Bit 2 TIM4LPEN: TIM4 clock enable during Sleep mode This bit is set and cleared by software.
  • Page 197: Rcc Apb2 Peripheral Clock Enabled In Low Power Mode Register (Rcc_Apb2Lpenr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) 6.3.19 RCC APB2 peripheral clock enabled in low power mode register (RCC_APB2LPENR) Address offset: 0x64 Reset value: 0x0x0477 7F33 Access: no wait state, word, half-word and byte access. LTDC SAI1 SPI6 SPI5 TIM11...
  • Page 198 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 16 TIM9LPEN: TIM9 clock enable during sleep mode This bit is set and cleared by software. 0: TIM9 clock disabled during Sleep mode 1: TIM9 clock enabled during Sleep mode Bit 15 Reserved, must be kept at reset value.
  • Page 199: Rcc Backup Domain Control Register (Rcc_Bdcr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bits 3:2 Reserved, must be kept at reset value. Bit 1 TIM8LPEN: TIM8 clock enable during Sleep mode This bit is set and cleared by software. 0: TIM8 clock disabled during Sleep mode 1: TIM8 clock enabled during Sleep mode Bit 0 TIM1LPEN: TIM1 clock enable during Sleep mode This bit is set and cleared by software.
  • Page 200: Rcc Clock Control & Status Register (Rcc_Csr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bits 9:8 RTCSEL[1:0]: RTC clock source selection These bits are set by software to select the clock source for the RTC. Once the RTC clock source has been selected, it cannot be changed anymore unless the Backup domain is reset.
  • Page 201 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bit 31 LPWRRSTF: Low-power reset flag This bit is set by hardware when a Low-power management reset occurs. Cleared by writing to the RMVF bit. 0: No Low-power management reset occurred 1: Low-power management reset occurred For further information on Low-power management reset, refer to Low-power management...
  • Page 202: Rcc Spread Spectrum Clock Generation Register (Rcc_Sscgr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bits 23:2 Reserved, must be kept at reset value. Bit 1 LSIRDY: Internal low-speed oscillator ready This bit is set and cleared by hardware to indicate when the internal RC 40 kHz oscillator is stable.
  • Page 203: Rcc Plli2S Configuration Register (Rcc_Plli2Scfgr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bits 29:28 Reserved, must be kept at reset value. Bits 27:13 INCSTEP: Incrementation step These bits are set and cleared by software. To write before setting CR[24]=PLLON bit. Configuration input for modulation profile amplitude. Bits 12:0 MODPER: Modulation period These bits are set and cleared by software.
  • Page 204 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bit 31 Reserved, must be kept at reset value. Bits 30:28 PLLI2SR: PLLI2S division factor for I2S clocks These bits are set and cleared by software to control the I2S clock frequency. These bits should be written only if the PLLI2S is disabled.
  • Page 205 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bits 23:15 Reserved, must be kept at reset value. Bits 14:6 PLLI2SN: PLLI2S multiplication factor for VCO These bits are set and cleared by software to control the multiplication factor of the VCO. These bits can be written only when PLLI2S is disabled.
  • Page 206: Rcc Pll Configuration Register (Rcc_Pllsaicfgr)

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 6.3.24 RCC PLL configuration register (RCC_PLLSAICFGR) Address offset: 0x88 Reset value: 0x2400 3000 Access: no wait state, word, half-word and byte access. This register is used to configure the PLLSAI clock outputs according to the formulas: •...
  • Page 207: Rcc Dedicated Clock Configuration Register (Rcc_Dckcfgr)

    RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bits 23:15 Reserved, must be kept at reset value. Bits 14:6 PLLSAIN: PLLSAI division factor for VCO These bits are set and cleared by software to control the multiplication factor of the VCO. These bits can be written only when PLLSAI is disabled.
  • Page 208 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Bits 31:25 Reserved, must be kept at reset value. Bit 24 TIMPRE: Timers clocks prescalers selection This bit is set and reset by software to control the clock frequency of all the timers connected to APB1 and APB2 domain.
  • Page 209 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Bits 12:8 PLLSAIDIVQ: PLLSAI division factor for SAI1 clock These bits are set and reset by software to control the SAI1 clock frequency. They should be written only if PLLSAI is disabled. SAI1 clock frequency = f(PLLSAI_Q) / PLLSAIDIVQ with 1 ≤...
  • Page 210: Rcc Register Map

    Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 6.3.26 RCC register map Table 33 gives the register map and reset values. Table 33. RCC register map and reset values for STM32F42xxx and STM32F43xxx Addr. Register offset name 0x00 RCC_CR Reserved RCC_PLLCFG...
  • Page 211 RM0090 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) Table 33. RCC register map and reset values for STM32F42xxx and STM32F43xxx (continued) Addr. Register offset name RCC_ 0x40 APB1ENR RCC_ 0x44 Reserved APB2ENR 0x48 Reserved Reserved 0x4C Reserved Reserved RCC_AHB1LP 0x50 RCC_AHB2LP...
  • Page 212 Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090 Table 33. RCC register map and reset values for STM32F42xxx and STM32F43xxx (continued) Addr. Register offset name RCC_PLLSAI 0x88 CFGR RCC_DCKCF 0x8C Reserved Reserved PLLSAIDIVQ Reserved PLLI2SDIVQ Refer to Section 2.3: Memory map for the register boundary addresses.
  • Page 213: Reset And Clock Control For Stm32F405Xx/07Xx And Stm32F415Xx/17Xx(Rcc)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Reset There are three types of reset, defined as system Reset, power Reset and backup domain Reset. 7.1.1 System reset A system reset sets all registers to their reset values except the reset flags in the clock controller CSR register and the registers in the Backup domain (see Figure 20).
  • Page 214: Power Reset

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Low-power management reset There are two ways of generating a low-power management reset: Reset generated when entering the Standby mode: This type of reset is enabled by resetting the nRST_STDBY bit in the user option bytes. In this case, whenever a Standby mode entry sequence is successfully executed, the device is reset instead of entering the Standby mode.
  • Page 215: Clocks

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) A backup domain reset is generated when one of the following events occurs: Software reset, triggered by setting the BDRST bit in the RCC Backup domain control register (RCC_BDCR). or V power on, if both supplies have previously been powered off.
  • Page 216: Figure 21. Clock Tree

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Figure 21. Clock tree Watchdog IWDGCLK enable to independent LSI RC watchdog 32 kHz RTC S E L[1:0] RTCCLK OSC32_IN enable to RTC LSE OS C 32.768 kHz OSC32_OUT SYSCLK MCO2 /1 to 5 HSE_RTC MCO1...
  • Page 217: Hse Clock

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 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 Ethernet, USB OTG FS and HS, I2S and SDIO.
  • Page 218: Hsi Clock

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Figure 22. HSE/ LSE clock sources Hardware configuration OSC_OUT External clock (HI-Z) External source OSC_IN OSC_OUT Crystal/ceramic resonators Load capacitors External source (HSE bypass) In this mode, an external clock source must be provided. You select this mode by setting the HSEBYP and HSEON bits in the RCC clock control register (RCC_CR).
  • Page 219: Pll Configuration

    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 T = 25 °C. After reset, the factory calibration value is loaded in the HSICAL[7:0] bits in the...
  • Page 220: Lsi Clock

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 The LSERDY flag in the RCC Backup domain control register (RCC_BDCR) indicates if the LSE crystal is stable or not. At startup, the LSE crystal output clock signal is not released until this bit is set by hardware.
  • Page 221: Rtc/Awu Clock

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 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.
  • Page 222: Clock-Out Capability

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.2.10 Clock-out capability Two microcontroller clock output (MCO) pins are available: • MCO1 You can output four different clock sources onto the MCO1 pin (PA8) using the configurable prescaler (from 1 to 5): –...
  • Page 223: Figure 23. Frequency Measurement With Tim5 In Input Capture Mode

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 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.
  • Page 224: Rcc Registers

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 RCC registers Refer to Section 1.1: List of abbreviations for registers for a list of abbreviations used in register descriptions. 7.3.1 RCC clock control register (RCC_CR) Address offset: 0x00 Reset value: 0x0000 XX83 where X is undefined. Access: no wait state, word, half-word and byte access PLLI2S PLLI2S...
  • Page 225 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 18 HSEBYP: HSE clock bypass Set and cleared by software to bypass the oscillator with an external clock. The external clock must be enabled with the HSEON bit, to be used by the device. The HSEBYP bit can be written only if the HSE oscillator is disabled.
  • Page 226: Rcc Pll Configuration Register (Rcc_Pllcfgr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.2 RCC PLL configuration register (RCC_PLLCFGR) Address offset: 0x04 Reset value: 0x2400 3010 Access: no wait state, word, half-word and byte access. This register is used to configure the PLL clock outputs according to the formulas: •...
  • Page 227 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 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 168 MHz on this domain.
  • Page 228: Rcc Clock Configuration Register (Rcc_Cfgr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.3 RCC clock configuration register (RCC_CFGR) Address offset: 0x08 Reset value: 0x0000 0000 Access: 0 ≤ wait state ≤ 2, word, half-word and byte access 1 or 2 wait states inserted only if the access occurs during a clock source switch. I2SSC MCO2 MCO2 PRE[2:0]...
  • Page 229 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bits 22:21 MCO1: Microcontroller clock output 1 Set and cleared by software. Clock source selection may generate glitches on MCO1. It is highly recommended to configure these bits only after reset before enabling the external oscillators and PLL.
  • Page 230: Rcc Clock Interrupt Register (Rcc_Cir)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bits 7:4 HPRE: AHB prescaler Set and cleared by software to control AHB clock division factor. Caution: The clocks are divided with the new prescaler factor from 1 to 16 AHB cycles after HPRE write.
  • Page 231 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bits 31:24 Reserved, must be kept at reset value. Bit 23 CSSC: Clock security system interrupt clear This bit is set by software to clear the CSSF flag. 0: No effect 1: Clear CSSF flag Bits 22 Reserved, must be kept at reset value.
  • Page 232 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 10 HSIRDYIE: HSI ready interrupt enable Set and cleared by software to enable/disable interrupt caused by the HSI oscillator stabilization. 0: HSI ready interrupt disabled 1: HSI ready interrupt enabled Bit 9 LSERDYIE: LSE ready interrupt enable Set and cleared by software to enable/disable interrupt caused by the LSE oscillator stabilization.
  • Page 233: Rcc Ahb1 Peripheral Reset Register (Rcc_Ahb1Rstr)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 2 HSIRDYF: HSI ready interrupt flag Set by hardware when the Internal High Speed clock becomes stable and HSIRDYDIE is set. Cleared by software setting the HSIRDYC bit. 0: No clock ready interrupt caused by the HSI oscillator 1: Clock ready interrupt caused by the HSI oscillator Bit 1 LSERDYF: LSE ready interrupt flag Set by hardware when the External Low Speed clock becomes stable and LSERDYDIE is...
  • Page 234 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 22 DMA2RST: DMA2 reset Set and cleared by software. 0: does not reset DMA2 1: resets DMA2 Bit 21 DMA1RST: DMA1 reset Set and cleared by software. 0: does not reset DMA1 1: resets DMA1 Bits 20:13 Reserved, must be kept at reset value.
  • Page 235 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 2 GPIOCRST: IO port C reset Set and cleared by software. 0: does not reset IO port C 1: resets IO port C Bit 1 GPIOBRST: IO port B reset Set and cleared by software.
  • Page 236: Rcc Ahb2 Peripheral Reset Register (Rcc_Ahb2Rstr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.6 RCC AHB2 peripheral reset register (RCC_AHB2RSTR) Address offset: 0x14 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access Reserved OTGFS HASH CRYP DCMI Reserved Reserved Bits 31:8 Reserved, must be kept at reset value. Bit 7 OTGFSRST: USB OTG FS module reset Set and cleared by software.
  • Page 237: Rcc Ahb3 Peripheral Reset Register (Rcc_Ahb3Rstr)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 7.3.7 RCC AHB3 peripheral reset register (RCC_AHB3RSTR) Address offset: 0x18 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access. Reserved FSMCRST Reserved Bits 31:1 Reserved, must be kept at reset value. Bit 0 FSMCRST: Flexible static memory controller module reset Set and cleared by software.
  • Page 238 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 26 CAN2RST: CAN2 reset Set and cleared by software. 0: does not reset CAN2 1: resets CAN2 Bit 25 CAN1RST: CAN1 reset Set and cleared by software. 0: does not reset CAN1 1: resets CAN1 Bit 24 Reserved, must be kept at reset value.
  • Page 239 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bits 13:12 Reserved, must be kept at reset value. Bit 11 WWDGRST: Window watchdog reset Set and cleared by software. 0: does not reset the window watchdog 1: resets the window watchdog Bits 10:9 Reserved, must be kept at reset value.
  • Page 240: Rcc Apb2 Peripheral Reset Register (Rcc_Apb2Rstr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.9 RCC APB2 peripheral reset register (RCC_APB2RSTR) Address offset: 0x24 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access. TIM11 TIM10 TIM9 Reserved USART USART SPI1 SDIO TIM8 TIM1 SYSCF...
  • Page 241 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 8 ADCRST: ADC interface reset (common to all ADCs) Set and cleared by software. 0: does not reset the ADC interface 1: resets the ADC interface Bits 7:6 Reserved, must be kept at reset value. Bit 5 USART6RST: USART6 reset Set and cleared by software.
  • Page 242: Rcc Ahb1 Peripheral Clock Enable Register (Rcc_Ahb1Enr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.10 RCC AHB1 peripheral clock enable register (RCC_AHB1ENR) Address offset: 0x30 Reset value: 0x0010 0000 Access: no wait state, word, half-word and byte access. OTGH ETHM ETHM ETHM OTGH ETHMA DMA2E DMA1E CCMDAT BKPSR...
  • Page 243 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 21 DMA1EN: DMA1 clock enable Set and cleared by software. 0: DMA1 clock disabled 1: DMA1 clock enabled Bit 20 CCMDATARAMEN: CCM data RAM clock enable Set and cleared by software. 0: CCM data RAM clock disabled 1: CCM data RAM clock enabled Bit 19 Reserved, must be kept at reset value.
  • Page 244: Rcc Ahb2 Peripheral Clock Enable Register (Rcc_Ahb2Enr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 2 GPIOCEN: IO port C clock enable Set and cleared by software. 0: IO port C clock disabled 1: IO port C clock enabled Bit 1 GPIOBEN: IO port B clock enable Set and cleared by software.
  • Page 245: Rcc Ahb3 Peripheral Clock Enable Register (Rcc_Ahb3Enr)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 4 CRYPEN: Cryptographic modules clock enable Set and cleared by software. 0: cryptographic module clock disabled 1: cryptographic module clock enabled Bits 3:1 Reserved, must be kept at reset value. Bit 0 DCMIEN: Camera interface enable Set and cleared by software.
  • Page 246 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bits 31:30 Reserved, must be kept at reset value. Bit 29 DACEN: DAC interface clock enable Set and cleared by software. 0: DAC interface clock disabled 1: DAC interface clock enable Bit 28 PWREN: Power interface clock enable Set and cleared by software.
  • Page 247 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 17 USART2EN: USART2 clock enable Set and cleared by software. 0: USART2 clock disabled 1: USART2 clock enabled Bit 16 Reserved, must be kept at reset value. Bit 15 SPI3EN: SPI3 clock enable Set and cleared by software.
  • Page 248: Rcc Apb2 Peripheral Clock Enable Register (Rcc_Apb2Enr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 2 TIM4EN: TIM4 clock enable Set and cleared by software. 0: TIM4 clock disabled 1: TIM4 clock enabled Bit 1 TIM3EN: TIM3 clock enable Set and cleared by software. 0: TIM3 clock disabled 1: TIM3 clock enabled Bit 0 TIM2EN: TIM2 clock enable Set and cleared by software.
  • Page 249 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 14 SYSCFGEN: System configuration controller clock enable Set and cleared by software. 0: System configuration controller clock disabled 1: System configuration controller clock enabled Bit 13 Reserved, must be kept at reset value. Bit 12 SPI1EN: SPI1 clock enable Set and cleared by software.
  • Page 250: Rcc Ahb1 Peripheral Clock Enable In Low Power Mode Register (Rcc_Ahb1Lpenr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.15 RCC AHB1 peripheral clock enable in low power mode register (RCC_AHB1LPENR) Address offset: 0x50 Reset value: 0x7E67 91FF Access: no wait state, word, half-word and byte access. OTGHS OTGH ETHPT ETHMA BKPSRA SRAM...
  • Page 251 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 22 DMA2LPEN: DMA2 clock enable during Sleep mode Set and cleared by software. 0: DMA2 clock disabled during Sleep mode 1: DMA2 clock enabled during Sleep mode Bit 21 DMA1LPEN: DMA1 clock enable during Sleep mode Set and cleared by software.
  • Page 252: Rcc Ahb2 Peripheral Clock Enable In Low Power Mode Register (Rcc_Ahb2Lpenr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 5 GPIOFLPEN: IO port F clock enable during Sleep mode Set and cleared by software. 0: IO port F clock disabled during Sleep mode 1: IO port F clock enabled during Sleep mode Bit 4 GPIOELPEN: IO port E clock enable during Sleep mode Set and cleared by software.
  • Page 253: Rcc Ahb3 Peripheral Clock Enable In Low Power Mode Register (Rcc_Ahb3Lpenr)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bits 31:8 Reserved, must be kept at reset value. Bit 7 OTGFSLPEN: USB OTG FS clock enable during Sleep mode Set and cleared by software. 0: USB OTG FS clock disabled during Sleep mode 1: USB OTG FS clock enabled during Sleep mode Bit 6 RNGLPEN: Random number generator clock enable during Sleep mode Set and cleared by software.
  • Page 254: Rcc Apb1 Peripheral Clock Enable In Low Power Mode Register (Rcc_Apb1Lpenr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.18 RCC APB1 peripheral clock enable in low power mode register (RCC_APB1LPENR) Address offset: 0x60 Reset value: 0x36FE C9FF Access: no wait state, word, half-word and byte access. USART USART CAN2 CAN1 I2C3 I2C2...
  • Page 255 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 21 I2C1LPEN: I2C1 clock enable during Sleep mode Set and cleared by software. 0: I2C1 clock disabled during Sleep mode 1: I2C1 clock enabled during Sleep mode Bit 20 UART5LPEN: UART5 clock enable during Sleep mode Set and cleared by software.
  • Page 256 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 6 TIM12LPEN: TIM12 clock enable during Sleep mode Set and cleared by software. 0: TIM12 clock disabled during Sleep mode 1: TIM12 clock enabled during Sleep mode Bit 5 TIM7LPEN: TIM7 clock enable during Sleep mode Set and cleared by software.
  • Page 257: Rcc Apb2 Peripheral Clock Enabled In Low Power Mode Register (Rcc_Apb2Lpenr)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 7.3.19 RCC APB2 peripheral clock enabled in low power mode register (RCC_APB2LPENR) Address offset: 0x64 Reset value: 0x0007 5F33 Access: no wait state, word, half-word and byte access. TIM11 TIM10 TIM9 LPEN LPEN LPEN...
  • Page 258 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 10 ADC3LPEN: ADC 3 clock enable during Sleep mode Set and cleared by software. 0: ADC 3 clock disabled during Sleep mode 1: ADC 3 clock disabled during Sleep mode Bit 9 ADC2LPEN: ADC2 clock enable during Sleep mode Set and cleared by software.
  • Page 259: Rcc Backup Domain Control Register (Rcc_Bdcr)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 7.3.20 RCC Backup domain control register (RCC_BDCR) Address offset: 0x70 Reset value: 0x0000 0000, reset by Backup domain reset. Access: 0 ≤ wait state ≤ 3, word, half-word and byte access Wait states are inserted in case of successive accesses to this register.
  • Page 260: Rcc Clock Control & Status Register (Rcc_Csr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bit 2 LSEBYP: External low-speed oscillator bypass Set and cleared by software to bypass the oscillator. This bit can be written only when the LSE clock is disabled. 0: LSE oscillator not bypassed 1: LSE oscillator bypassed Bit 1 LSERDY: External low-speed oscillator ready Set and cleared by hardware to indicate when the external 32 kHz oscillator is stable.
  • Page 261 RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) Bit 28 SFTRSTF: Software reset flag Set by hardware when a software reset occurs. Cleared by writing to the RMVF bit. 0: No software reset occurred 1: Software reset occurred Bit 27 PORRSTF: POR/PDR reset flag Set by hardware when a POR/PDR reset occurs.
  • Page 262: Rcc Spread Spectrum Clock Generation Register (Rcc_Sscgr)

    Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 7.3.22 RCC spread spectrum clock generation register (RCC_SSCGR) Address offset: 0x80 Reset value: 0x0000 0000 Access: no wait state, word, half-word and byte access. The spread spectrum clock generation is available only for the main PLL. The RCC_SSCGR register must be written either before the main PLL is enabled or after the main PLL disabled.
  • Page 263: Rcc Plli2S Configuration Register (Rcc_Plli2Scfgr)

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 7.3.23 RCC PLLI2S configuration register (RCC_PLLI2SCFGR) Address offset: 0x84 Reset value: 0x2000 3000 Access: no wait state, word, half-word and byte access. This register is used to configure the PLLI2S clock outputs according to the formulas: •...
  • Page 264 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Bits 27:15 Reserved, must be kept at reset value. Bits 14:6 PLLI2SN: PLLI2S multiplication factor for VCO These bits are set and cleared by software to control the multiplication factor of the VCO. These bits can be written only when PLLI2S is disabled.
  • Page 265: Rcc Register Map

    RM0090 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) 7.3.24 RCC register map Table 34 gives the register map and reset values. Table 34. RCC register map and reset values Addr. Register offset name 0x00 RCC_CR Reserved Reserved RCC_ 0x04 Reserved Reserved PLLCFGR...
  • Page 266 Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC) RM0090 Table 34. RCC register map and reset values (continued) Addr. Register offset name RCC_ 0x40 APB1ENR RCC_ 0x44 Reserved APB2ENR 0x48 Reserved Reserved 0x4C Reserved Reserved RCC_AHB1LP 0x50 RCC_AHB2LP 0x54 Reserved RCC_AHB3LP 0x58 Reserved...
  • Page 267: General-Purpose I/Os (Gpio)

    RM0090 General-purpose I/Os (GPIO) General-purpose I/Os (GPIO) This section applies to the whole STM32F4xx family, unless otherwise specified. GPIO introduction Each general-purpose I/O port has four 32-bit configuration registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR and GPIOx_PUPDR), two 32-bit data registers (GPIOx_IDR and GPIOx_ODR), a 32-bit set/reset register (GPIOx_BSRR), a 32-bit locking register (GPIOx_LCKR) and two 32-bit alternate function selection register (GPIOx_AFRH and GPIOx_AFRL).
  • Page 268: Table 35. Port Bit Configuration Table

    General-purpose I/Os (GPIO) RM0090 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.
  • Page 269: General-Purpose I/O (Gpio)

    RM0090 General-purpose I/Os (GPIO) Table 35. Port bit configuration table (continued) MODER(i) OSPEEDR(i) PUPDR(i) OTYPER(i) I/O configuration [1:0] [B:A] [1:0] PP + PU PP + PD Reserved SPEED [B:A] OD + PU OD + PD Reserved Input Floating Input Input Reserved (input floating) Input/output Analog...
  • Page 270: I/O Pin Multiplexer And Mapping

    General-purpose I/Os (GPIO) RM0090 8.3.2 I/O pin multiplexer and mapping The microcontroller I/O pins are connected to onboard peripherals/modules through a multiplexer that allows only one peripheral’s alternate function (AF) connected to an I/O pin at a time. In this way, there can be no conflict between peripherals sharing the same I/O pin. Each I/O pin has a multiplexer with sixteen alternate function inputs (AF0 to AF15) that can be configured through the GPIOx_AFRL (for pin 0 to 7) and GPIOx_AFRH (for pin 8 to 15) registers:...
  • Page 271: Table 36. Flexible Swj-Dp Pin Assignment

    RM0090 General-purpose I/Os (GPIO) Table 36. Flexible SWJ-DP pin assignment SWJ I/O pin assigned PA13 / PA14 / Available debug ports PA15 / PB3 / PB4/ JTMS/ JTCK/ JTDI JTDO NJTRST SWDIO SWCLK Full SWJ (JTAG-DP + SW-DP) - Reset state Full SWJ (JTAG-DP + SW-DP) but without NJTRST JTAG-DP Disabled and SW-DP Enabled...
  • Page 272: Figure 26. Selecting An Alternate Function On Stm32F405Xx/07Xx And Stm32F415Xx/17Xx

    General-purpose I/Os (GPIO) RM0090 Figure 26. Selecting an alternate function on STM32F405xx/07xx and STM32F415xx/17xx For pins 0 to 7, the GPIOx_AFRL[31:0] register selects the dedicated alternate function AF0 (system) AF1 (TIM1/TIM2) AF2 (TIM3..5) AF3 (TIM8..11) AF4 (I2C1..3) AF5 (SPI1/SPI2) AF6 (SPI3) Pin x (x = 0..7) AF7 (USART1..3) AF8 (USART4..6)
  • Page 273: Figure 27. Selecting An Alternate Function On Stm32F42Xxx And Stm32F43Xxx

    RM0090 General-purpose I/Os (GPIO) Figure 27. Selecting an alternate function on STM32F42xxx and STM32F43xxx For pins 0 to 7, the GPIOx_AFRL[31:0] register selects the dedicated alternate function AF0 (system) AF1 (TIM1/TIM2) AF2 (TIM3..5) AF3 (TIM8..11) AF4 (I2C1..3) AF5 (SPI1/2/3/4/5/6) AF6 (SPI2/3/SAI1) Pin x (x = 0..7) AF7 (USART1..3) AF8 (USART4..8)
  • Page 274: I/O Port Control Registers

    General-purpose I/Os (GPIO) RM0090 8.3.3 I/O port control registers Each of the GPIOs has four 32-bit memory-mapped control registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR) to configure up to 16 I/Os. The GPIOx_MODER register is used to select the I/O direction (input, output, AF, analog). The GPIOx_OTYPER and GPIOx_OSPEEDR registers are used to select the output type (push-pull or open-drain) and speed (the I/O speed pins are directly connected to the corresponding GPIOx_OSPEEDR register bits whatever the I/O direction).
  • Page 275: I/O Alternate Function Input/Output

    RM0090 General-purpose I/Os (GPIO) freezes the corresponding bit in the control registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH). The LOCK sequence (refer to Section 8.4.8: GPIO port configuration lock register (GPIOx_LCKR) (x = A..I/J/K)) can only be performed using a word (32-bit long) access to the GPIOx_LCKR register due to the fact that GPIOx_LCKR bit 16 has to be set at the same time as the [15:0] bits.
  • Page 276: Output Configuration

    General-purpose I/Os (GPIO) RM0090 Figure 28. Input floating/pull up/pull down configurations Read V DD V DD on/off TTL Schmitt protection trigger diode pull Write input driver I/O pin on/off output driver protection pull diode down V SS V SS Read/write ai15940b 8.3.10 Output configuration...
  • Page 277: Alternate Function Configuration

    RM0090 General-purpose I/Os (GPIO) Figure 29. Output configuration Read TTL Schmitt trigger on/off protection Write diode Input driver pull I/O pin Output driver on/off P-MOS protection pull down diode Output control Read/write N-MOS Push-pull or Open-drain ai15941b 8.3.11 Alternate function configuration When the I/O port is programmed as alternate function: •...
  • Page 278: Analog Configuration

    General-purpose I/Os (GPIO) RM0090 8.3.12 Analog configuration When the I/O port is programmed as analog configuration: • The output buffer is disabled • The Schmitt trigger input is deactivated, providing zero consumption for every analog value of the I/O pin. The output of the Schmitt trigger is forced to a constant value (0). •...
  • Page 279: Selection Of Rtc_Af1 And Rtc_Af2 Alternate Functions

    RM0090 General-purpose I/Os (GPIO) 8.3.15 Selection of RTC_AF1 and RTC_AF2 alternate functions The STM32F4xx feature two GPIO pins RTC_AF1 and RTC_AF2 that can be used for the detection of a tamper or time stamp event, or RTC_ALARM, or RTC_CALIB RTC outputs. •...
  • Page 280: Table 38. Rtc_Af2 Pin

    General-purpose I/Os (GPIO) RM0090 Table 38. RTC_AF2 pin TSINSEL Time TAMP1INSEL ALARMOUTTYPE Tamper TIMESTAMP Pin configuration and function stamp TAMPER1 RTC_ALARM enabled enabled pin selection configuration selection TAMPER1 input floating Don’t care Don’t care TIMESTAMP and TAMPER1 input Don’t care floating TIMESTAMP input floating Don’t care...
  • Page 281: Gpio Registers

    RM0090 General-purpose I/Os (GPIO) GPIO registers This section gives a detailed description of the GPIO registers. For a summary of register bits, register address offsets and reset values, refer to Table The GPIO registers can be accessed by byte (8 bits), half-words (16 bits) or words (32 bits). 8.4.1 GPIO port mode register (GPIOx_MODER) (x = A..I/J/K) Address offset: 0x00...
  • Page 282: (X = A

    General-purpose I/Os (GPIO) RM0090 8.4.3 GPIO port output speed register (GPIOx_OSPEEDR) (x = A..I/J/K) Address offset: 0x08 Reset values: • 0x0C00 0000 for port A • 0x0000 00C0 for port B • 0x0000 0000 for other ports OSPEEDR15 OSPEEDR14 OSPEEDR13 OSPEEDR12 OSPEEDR11 OSPEEDR10...
  • Page 283: Gpio Port Input Data Register (Gpiox_Idr) (X = A

    RM0090 General-purpose I/Os (GPIO) Bits 2y:2y+1 PUPDRy[1:0]: Port x configuration bits (y = 0..15) These bits are written by software to configure the I/O pull-up or pull-down 00: No pull-up, pull-down 01: Pull-up 10: Pull-down 11: Reserved 8.4.5 GPIO port input data register (GPIOx_IDR) (x = A..I/J/K) Address offset: 0x10 Reset value: 0x0000 XXXX (where X means undefined) Reserved...
  • Page 284: Gpio Port Bit Set/Reset Register (Gpiox_Bsrr) (X = A

    General-purpose I/Os (GPIO) RM0090 8.4.7 GPIO port bit set/reset register (GPIOx_BSRR) (x = A..I/J/K) Address offset: 0x18 Reset value: 0x0000 0000 BR15 BR14 BR13 BR12 BR11 BR10 BS15 BS14 BS13 BS12 BS11 BS10 Bits 31:16 BRy: Port x reset bit y (y = 0..15) These bits are write-only and can be accessed in word, half-word or byte mode.
  • Page 285: Gpio Alternate Function Low Register (Gpiox_Afrl) (X = A

    RM0090 General-purpose I/Os (GPIO) Bits 31:17 Reserved, must be kept at reset value. Bit 16 LCKK[16]: Lock key This bit can be read any time. It can only be modified using the lock key write sequence. 0: Port configuration lock key not active 1: Port configuration lock key active.
  • Page 286: (X = A

    General-purpose I/Os (GPIO) RM0090 8.4.10 GPIO alternate function high register (GPIOx_AFRH) (x = A..I/J) Address offset: 0x24 Reset value: 0x0000 0000 AFRH15[3:0] AFRH14[3:0] AFRH13[3:0] AFRH12[3:0] AFRH11[3:0] AFRH10[3:0] AFRH9[3:0] AFRH8[3:0] 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...
  • Page 287: Gpio Register Map

    RM0090 General-purpose I/Os (GPIO) 8.4.11 GPIO register map The following table gives the GPIO register map and the reset values. Table 39. GPIO register map and reset values Offset Register GPIOA_ MODER 0x00 Reset value GPIOB_ MODER 0x00 Reset value GPIOx_MODER (where x = 0x00...
  • Page 288 General-purpose I/Os (GPIO) RM0090 Table 39. GPIO register map and reset values (continued) Offset Register GPIOx_PUPDR (where x = 0x0C /J/K) Reset value GPIOx_IDR (where x = 0x10 Reserved A..I/J/K) Reset value GPIOx_ODR (where x = 0x14 Reserved A..I/J/K) Reset value GPIOx_BSRR (where x = 0x18...
  • Page 289: System Configuration Controller (Syscfg)

    RM0090 System configuration controller (SYSCFG) System configuration controller (SYSCFG) The system configuration controller is mainly used to remap the memory accessible in the code area, select the Ethernet PHY interface and manage the external interrupt line connection to the GPIOs. This section applies to the whole STM32F4xx family, unless otherwise specified.
  • Page 290: Syscfg Peripheral Mode Configuration Register (Syscfg_Pmc)

    System configuration controller (SYSCFG) RM0090 Bits 31:2 Reserved, must be kept at reset value. Bits 1:0 MEM_MODE: Memory mapping selection Set and cleared by software. This bit controls the memory internal mapping at address 0x0000 0000. After reset these bits take the value selected by the Boot pins (except for FSMC).
  • Page 291: Syscfg External Interrupt Configuration Register 1

    RM0090 System configuration controller (SYSCFG) 9.2.3 SYSCFG external interrupt configuration register 1 (SYSCFG_EXTICR1) Address offset: 0x08 Reset value: 0x0000 0000 Reserved EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0] Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 EXTIx[3:0]: EXTI x configuration (x = 0 to 3) These bits are written by software to select the source input for the EXTIx external interrupt.
  • Page 292: Syscfg External Interrupt Configuration Register 3

    System configuration controller (SYSCFG) RM0090 Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 EXTIx[3:0]: EXTI x configuration (x = 4 to 7) These bits are written by software to select the source input for the EXTIx external interrupt. 0000: PA[x] pin 0001: PB[x] pin 0010: PC[x] pin...
  • Page 293: Syscfg External Interrupt Configuration Register 4

    RM0090 System configuration controller (SYSCFG) 9.2.6 SYSCFG external interrupt configuration register 4 (SYSCFG_EXTICR4) Address offset: 0x14 Reset value: 0x0000 0000 Reserved EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0] Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 EXTIx[3:0]: EXTI x configuration (x = 12 to 15) These bits are written by software to select the source input for the EXTIx external interrupt.
  • Page 294: Table 40. Syscfg Register Map And Reset Values (Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    System configuration controller (SYSCFG) RM0090 9.2.8 SYSCFG register maps for STM32F405xx/07xx and STM32F415xx/17xx The following table gives the SYSCFG register map and the reset values. Table 40. SYSCFG register map and reset values (STM32F405xx/07xx and STM32F415xx/17xx) Offset Register SYSCFG_ MEMRMP 0x00 Reserved Reset value...
  • Page 295 RM0090 System configuration controller (SYSCFG) There are two possible FMC remap at address 0x0000 0000: • FMC Bank 1 (NOR/PSRAM 1 and 2) remap: Only the first two regions of Bank 1 memory controller (Bank1 NOR/PSRAM 1 and NOR/PSRAM 2) can be remapped. •...
  • Page 296 System configuration controller (SYSCFG) RM0090 Bit 8 FB_MODE: Flash Bank mode selection Set and cleared by software. This bit controls the Flash Bank 1/2 mapping. 0: Flash Bank 1 is mapped at 0x0800 0000 (and aliased at 0x0000 0000) and Flash Bank 2 is mapped at 0x0810 0000 (and aliased at 0x0010 0000) 1: Flash Bank 2 is mapped at 0x0800 0000 (and aliased at 0x0000 0000) and Flash Bank 1 is mapped at 0x0810 0000 (and aliased at 0x0010 0000)
  • Page 297 RM0090 System configuration controller (SYSCFG) Bits 22:19 Reserved, must be kept at reset value. Bits 18:16 ADCxDC2: 0: No effect. 1: Refer to AN4073 on how to use this bit. Note: These bits can be set only if the following conditions are met: - ADC clock higher or equal to 30 MHz.
  • Page 298 System configuration controller (SYSCFG) RM0090 9.3.4 SYSCFG external interrupt configuration register 2 (SYSCFG_EXTICR2) Address offset: 0x0C Reset value: 0x0000 0000 Reserved EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0] Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 EXTIx[3:0]: EXTI x configuration (x = 4 to 7) These bits are written by software to select the source input for the EXTIx external interrupt.
  • Page 299 RM0090 System configuration controller (SYSCFG) Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 EXTIx[3:0]: EXTI x configuration (x = 8 to 11) These bits are written by software to select the source input for the EXTIx external interrupt. 0000: PA[x] pin 0001: PB[x] pin 0010: PC[x] pin...
  • Page 300 System configuration controller (SYSCFG) RM0090 9.3.7 Compensation cell control register (SYSCFG_CMPCR) Address offset: 0x20 Reset value: 0x0000 0000 Reserved READY CMP_PD Reserved Reserved Bits 31:9 Reserved, must be kept at reset value. Bit 8 READY: Compensation cell ready flag 0: I/O compensation cell not ready 1: O compensation cell ready Bits 7:2 Reserved, must be kept at reset value.
  • Page 301: Table 41. Syscfg Register Map And Reset Values (Stm32F42Xxx And Stm32F43Xxx)

    RM0090 System configuration controller (SYSCFG) 9.3.8 SYSCFG register maps for STM32F42xxx and STM32F43xxx The following table gives the SYSCFG register map and the reset values. Table 41. SYSCFG register map and reset values (STM32F42xxx and STM32F43xxx) Offset Register SYSCFG_ MEM_ MEMRMP MODE 0x00...
  • Page 302 DMA controller (DMA) RM0090 DMA controller (DMA) This section applies to the whole STM32F4xx family, unless otherwise specified. 10.1 DMA introduction Direct memory access (DMA) is used in order to provide high-speed data transfer between peripherals and memory and between memory and memory. Data can be quickly moved by DMA without any CPU action.
  • Page 303 RM0090 DMA controller (DMA) FIFO to ensure an immediate data transfer as soon as a DMA request is triggered by a peripheral. • Each stream can be configured by hardware to be: – a regular channel that supports peripheral-to-memory, memory-to-peripheral and memory-to-memory transfers –...
  • Page 304: Figure 32. Dma Block Diagram

    DMA controller (DMA) RM0090 10.3 DMA functional description 10.3.1 General description Figure 32 shows the block diagram of a DMA. Figure 32. DMA block diagram DMA controller REQ_STR0_CH0 Memory port REQ_STR0_CH1 REQ_STR0_CH7 REQ_STR1_CH0 REQ_STR1_CH1 REQ_STREAM0 REQ_STREAM1 REQ_STR1_CH7 REQ_STREAM2 REQ_STREAM3 REQ_STREAM4 Arbiter REQ_STREAM5 REQ_STREAM6...
  • Page 305: Figure 33. System Implementation Of The Two Dma Controllers (Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    RM0090 DMA controller (DMA) Figure 33 Figure 34 for the implementation of the system of two DMA controllers. Figure 33. System implementation of the two DMA controllers (STM32F405xx/07xx and STM32F415xx/17xx) DCODE Bus matrix (AHB Flash ICODE multilayer) memory 112 KB SRAM 16 KB SRAM AHB1 peripherals DMA controller 2...
  • Page 306: Figure 34. System Implementation Of The Two Dma Controllers (Stm32F42Xxx And Stm32F43Xxx)

    DMA controller (DMA) RM0090 Figure 34. System implementation of the two DMA controllers (STM32F42xxx and STM32F43xxx) Bus Matrix DCODE (AHB multilayer) Flash ICODE memory 112 KB SRAM 16 KB SRAM 64 KB SRAM AHB1 peripherals DMA controller 2 AHB-APB APB2 APB2 bridge2 peripherals...
  • Page 307: Table 42. Dma1 Request Mapping

    RM0090 DMA controller (DMA) After an event, the peripheral sends a request signal to the DMA controller. The DMA controller serves the request depending on the channel priorities. As soon as the DMA controller accesses the peripheral, an Acknowledge signal is sent to the peripheral by the DMA controller.
  • Page 308: Table 43. Dma2 Request Mapping

    DMA controller (DMA) RM0090 Table 42. DMA1 request mapping (continued) Peripheral Stream 0 Stream 1 Stream 2 Stream 3 Stream 4 Stream 5 Stream 6 Stream 7 requests TIM5_CH3 TIM5_CH4 TIM5_CH4 Channel 6 TIM5_CH1 TIM5_CH2 TIM5_UP TIM5_UP TIM5_TRIG TIM5_TRIG Channel 7 TIM6_UP I2C2_RX I2C2_RX...
  • Page 309: Table 44. Source And Destination Address

    RM0090 DMA controller (DMA) 10.3.5 DMA streams Each of the 8 DMA controller streams provides a unidirectional transfer link between a source and a destination. Each stream can be configured to perform: • Regular type transactions: memory-to-peripherals, peripherals-to-memory or memory- to-memory transfers •...
  • Page 310: Figure 36. Peripheral-To-Memory Mode

    DMA controller (DMA) RM0090 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.
  • Page 311: Figure 37. Memory-To-Peripheral Mode

    RM0090 DMA controller (DMA) 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.
  • Page 312: Figure 38. Memory-To-Memory Mode

    DMA controller (DMA) RM0090 Figure 38. Memory-to-memory mode DMA_SxM0AR DMA controller DMA_SxM1AR AHB memory Memory bus port Memory 2 destination Arbiter FIFO FIFO level FIFO Stream enable AHB peripheral Peripheral bus port Memory 1 source DMA_SxPAR ai15950 1. For double-buffer mode. 10.3.7 Pointer incrementation Peripheral and memory pointers can optionally be automatically post-incremented or kept...
  • Page 313 RM0090 DMA controller (DMA) 10.3.8 Circular mode The Circular mode is available to handle circular buffers and continuous data flows (e.g. ADC scan mode). This feature can be enabled using the CIRC bit in the DMA_SxCR register. 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.
  • Page 314: Table 45. Source And Destination Address Registers In Double Buffer Mode (Dbm=1)

    DMA controller (DMA) RM0090 memory 0 to 1 (or from 1 to 0) depending on the value of CT in the DMA_SxCR register in accordance with one of the two above conditions. For all the other modes (except the Double buffer mode), the memory address registers are write-protected as soon as the stream is enabled.
  • Page 315: Table 46. Packing/Unpacking & Endian Behavior (Bit Pinc = Minc = 1)

    RM0090 DMA controller (DMA) Table 46. Packing/unpacking & endian behavior (bit PINC = MINC = 1) Number Peripheral port address / byte lane Peripher of data Memory Memory port memory peripheral items to transfer address / byte port transfer PINCOS = 1 PINCOS = 0 port width transfer...
  • Page 316: Table 47. Restriction On Ndt Versus Psize And Msize

    DMA controller (DMA) RM0090 Table 47. Restriction on NDT versus PSIZE and MSIZE PSIZE[1:0] of DMA_SxCR MSIZE[1:0] of DMA_SxCR NDT[15:0] of DMA_SxNDTR 00 (8-bit) 01 (16-bit) must be a multiple of 2 00 (8-bit) 10 (32-bit) must be a multiple of 4 01 (16-bit) 10 (32-bit) must be a multiple of 2...
  • Page 317: Figure 39. Fifo Structure

    RM0090 DMA controller (DMA) 10.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.
  • Page 318: Table 48. Fifo Threshold Configurations

    DMA controller (DMA) RM0090 FIFO threshold and burst configuration Caution is required when choosing the FIFO threshold (bits FTH[1:0] of the DMA_SxFCR register) and the size of the memory burst (MBURST[1:0] of the DMA_SxCR register): The content pointed by the FIFO threshold must exactly match to an integer number of memory burst transfers.
  • Page 319 RM0090 DMA controller (DMA) 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).
  • Page 320 DMA controller (DMA) RM0090 to-memory) all the remaining data have been flushed from the FIFO into the memory • In Peripheral flow controller mode: – The last external burst or single request has been generated from the peripheral and (when the DMA is operating in peripheral-to-memory mode) the remaining data have been transferred from the FIFO into the memory –...
  • Page 321 RM0090 DMA controller (DMA) 10.3.15 Flow controller The entity that controls the number of data to be transferred is known as the flow controller. This flow controller is configured independently for each stream using the PFCTRL bit in the DMA_SxCR register. The flow controller can be: •...
  • Page 322: Table 49. Possible Dma Configurations

    DMA controller (DMA) RM0090 10.3.16 Summary of the possible DMA configurations Table 49 summarizes the different possible DMA configurations. Table 49. Possible DMA configurations DMA transfer Flow Circular Transfer Direct Double Source Destination mode controller mode type mode buffer mode single possible possible...
  • Page 323 RM0090 DMA controller (DMA) Double buffer mode and interrupts after half and/or full transfer, and/or errors in the DMA_SxCR register. 10. Activate the stream by setting the EN bit in the DMA_SxCR register. As soon as the stream is enabled, it can serve any DMA request from the peripheral connected to the stream.
  • Page 324: Table 50. Dma Interrupt Requests

    DMA controller (DMA) RM0090 If the DMEIFx or the FEIFx flag is set due to an overrun or underrun condition, the faulty stream is not automatically disabled and it is up to the software to disable or not the stream by resetting the EN bit in the DMA_SxCR register.
  • Page 325 RM0090 DMA controller (DMA) 10.5 DMA registers The DMA registers have to be accessed by words (32 bits). 10.5.1 DMA low interrupt status register (DMA_LISR) Address offset: 0x00 Reset value: 0x0000 0000 Reserved TCIF3 HTIF3 TEIF3 DMEIF3 Reserv FEIF3 TCIF2 HTIF2 TEIF2 DMEIF2 Reserv...
  • Page 326 DMA controller (DMA) RM0090 10.5.2 DMA high interrupt status register (DMA_HISR) Address offset: 0x04 Reset value: 0x0000 0000 TCIF7 HTIF7 TEIF7 DMEIF7 Reserv FEIF7 TCIF6 HTIF6 TEIF6 DMEIF6 Reserv FEIF6 Reserved TCIF5 HTIF5 TEIF5 DMEIF5 Reserv FEIF5 TCIF4 HTIF4 TEIF4 DMEIF4 Reserv FEIF4 Reserved...
  • Page 327 RM0090 DMA controller (DMA) 10.5.3 DMA low interrupt flag clear register (DMA_LIFCR) Address offset: 0x08 Reset value: 0x0000 0000 CTCIF3 CHTIF3 CTEIF3 CDMEIF3 CFEIF3 CTCIF2 CHTIF2 CTEIF2 CDMEIF2 CFEIF2 Reserved Reserved Reserved CTCIF1 CHTIF1 CTEIF1 CDMEIF1 CFEIF1 CTCIF0 CHTIF0 CTEIF0 CDMEIF0 CFEIF0 Reserved Reserved...
  • Page 328 DMA controller (DMA) RM0090 Bits 24, 18, 8, 2 CDMEIFx: Stream x clear direct mode error interrupt flag (x = 7..4) Writing 1 to this bit clears the corresponding DMEIFx flag in the DMA_HISR register Bits 23, 17, 7, 1 Reserved, must be kept at reset value. Bits 22, 16, 6, 0 CFEIFx: Stream x clear FIFO error interrupt flag (x = 7..4) Writing 1 to this bit clears the corresponding CFEIFx flag in the DMA_HISR register 10.5.5...
  • Page 329 RM0090 DMA controller (DMA) Bit 19 CT: Current target (only in double buffer mode) This bits is set and cleared by hardware. It can also be written by software. 0: The current target memory is Memory 0 (addressed by the DMA_SxM0AR pointer) 1: The current target memory is Memory 1 (addressed by the DMA_SxM1AR pointer) This bit can be written only if EN is ‘0’...
  • Page 330 DMA controller (DMA) RM0090 Bit 9 PINC: Peripheral increment mode This bit is set and cleared by software. 0: Peripheral address pointer is fixed 1: Peripheral address pointer is incremented after each data transfer (increment is done according to PSIZE) This bit is protected and can be written only if EN is ‘0’.
  • Page 331 RM0090 DMA controller (DMA) 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) –...
  • Page 332 DMA controller (DMA) RM0090 10.5.7 DMA stream x peripheral address register (DMA_SxPAR) (x = 0..7) Address offset: 0x18 + 0x18 × stream number Reset value: 0x0000 0000 PAR[31:16] PAR[15:0] Bits 31:0 PAR[31:0]: Peripheral address Base address of the peripheral data register from/to which the data will be read/written. These bits are write-protected and can be written only when bit EN = '0' in the DMA_SxCR register.
  • Page 333 RM0090 DMA controller (DMA) 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.
  • Page 334 DMA controller (DMA) RM0090 Bits 5:3 FS[2:0]: FIFO status These bits are read-only. 000: 0 < fifo_level < 1/4 001: 1/4 ≤ fifo_level < 1/2 010: 1/2 ≤ fifo_level < 3/4 011: 3/4 ≤ fifo_level < full 100: FIFO is empty 101: FIFO is full others: no meaning These bits are not relevant in the direct mode (DMDIS bit is zero).
  • Page 335: Table 51. Dma Register Map And Reset Values

    RM0090 DMA controller (DMA) 10.5.11 DMA register map Table 51 summarizes the DMA registers. Table 51. DMA register map and reset values Offset Register DMA_LISR 0x0000 Reserved Reserved Reset value DMA_HISR 0x0004 Reserved Reserved Reset value DMA_LIFCR 0x0008 Reserved Reserved Reset value DMA_HIFCR 0x000C...
  • Page 336 DMA controller (DMA) RM0090 Table 51. DMA register map and reset values (continued) Offset Register DMA_S1PAR PA[31:0] 0x0030 Reset value DMA_S1M0AR M0A[31:0] 0x0034 Reset value DMA_S1M1AR M1A[31:0] 0x0038 Reset value DMA_S1FCR FS[2:0] [1:0] 0x003C Reserved Reset value DMA_S2CR 0x0040 Reserved Reset value DMA_S2NDTR NDT[15:.]...
  • Page 337 RM0090 DMA controller (DMA) Table 51. DMA register map and reset values (continued) Offset Register DMA_S3M1AR M1A[31:0] 0x0068 Reset value DMA_S3FCR FS[2:0] [1:0] 0x006C Reserved Reset value DMA_S4CR 0x0070 Reserved Reset value DMA_S4NDTR NDT[15:.] 0x0074 Reserved Reset value DMA_S4PAR PA[31:0] 0x0078 Reset value DMA_S4M0AR...
  • Page 338 DMA controller (DMA) RM0090 Table 51. DMA register map and reset values (continued) Offset Register DMA_S6M0AR M0A[31:0] 0x00AC Reset value DMA_S6M1AR M1A[31:0] 0x00B0 Reset value DMA_S6FCR FS[2:0] [1:0] 0x00B4 Reserved Reset value DMA_S7CR 0x00B8 Reserved Reset value DMA_S7NDTR NDT[15:.] 0x00BC Reserved Reset value DMA_S7PAR...
  • Page 339 RM0090 Chrom-Art Accelerator™ controller (DMA2D) Chrom-Art Accelerator™ controller (DMA2D) 11.1 DMA2D introduction The Chrom-Art Accelerator™ (DMA2D) is a specialized DMA dedicated to image manipulation. It can perform the following operations: • Filling a part or the whole of a destination image with a specific color •...
  • Page 340 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.2 DMA2D main features The main DMA2D features are: • Single AHB master bus architecture. • AHB slave programming interface supporting 8/16/32-bit accesses (except for CLUT accesses which are 32-bit). • User programmable working area size •...
  • Page 341 RM0090 Chrom-Art Accelerator™ controller (DMA2D) Figure 40. DMA2D block diagram AHB MASTER FG PFC mode Color mode 8-bit Expander Expander FIFO OUT PFC BLENDER Color Color mode CLUT itf Converter FIFO 256x32-bit 32/24/16 Green Blue BG PFC mode Color mode 8-bit Expander Expander...
  • Page 342: Table 52. Supported Color Mode In Input

    Chrom-Art Accelerator™ controller (DMA2D) RM0090 They are programmed through a set of control registers: • DMA2D foreground memory address register (DMA2D_FGMAR) • DMA2D foreground offset register (DMA2D_FGOR) • DMA2D background memory address register (DMA2D_BGMAR) • DMA2D background offset register (DMA2D_BGBOR) •...
  • Page 343: Table 53. Data Order In Memory

    RM0090 Chrom-Art Accelerator™ controller (DMA2D) The color format are coded as follows: • Alpha value field: transparency 0xFF value corresponds to an opaque pixel and 0x00 to a transparent one. • R field for Red • G field for Green •...
  • Page 344 Chrom-Art Accelerator™ controller (DMA2D) RM0090 The alpha channel can be: • kept as it is (no modification), • replaced by the ALPHA[7:0] value of DMA2D_FGPFCCR/DMA2D_BGPFCCR, • or replaced by the original alpha value multiplied by the ALPHA[7:0] value of DMA2D_FGPFCCR/DMA2D_BGPFCCR divided by 255. Table 54.
  • Page 345: Table 56. Clut Data Order In Memory

    RM0090 Chrom-Art Accelerator™ controller (DMA2D) Table 55. Supported CLUT color mode CLUT color mode 32-bit ARGB8888 24-bit RGB888 The way the CLUT data are organized in the system memory is specified in Table 56: CLUT data order in memory. Table 56. CLUT data order in memory CLUT Color Mode @ + 3 @ + 2...
  • Page 346: Table 57. Supported Color Mode In Output

    Chrom-Art Accelerator™ controller (DMA2D) RM0090 Table 57. Supported color mode in output CM[2:0] Color mode ARGB8888 RGB888 RGB565 ARGB1555 ARGB4444 11.3.8 DMA2D output FIFO The output FIFO programs the pixels according to the color format defined in the output PFC. The destination area is defined through a set of control registers: •...
  • Page 347 RM0090 Chrom-Art Accelerator™ controller (DMA2D) The timer enabling and the dead time value are configured through the AHB master port timer configuration register (DMA2D_AMPTCR). 11.3.10 DMA2D transactions DMA2D transactions consist of a sequence of a given number of data transfers. The number of data and the width can be programmed by software.
  • Page 348 Chrom-Art Accelerator™ controller (DMA2D) RM0090 The size of the area to be transferred is defined by the DMA2D_NLR and DMA2D_FGOR registers for the source, and by DMA2D_NLR and DMA2D_OOR registers for the destination. Memory-to-memory with PFC In this mode, the DMA2D performs a pixel format conversion of the source data and stores them in the destination memory location.
  • Page 349 RM0090 Chrom-Art Accelerator™ controller (DMA2D) Memory-to-memory with PFC and blending In this mode, 2 sources are fetched in the foreground FIFO and background FIFO from the memory locations defined by DMA2D_FGMAR and DMA2D_BGMAR. The two pixel format converters have to be configured as described in the memory-to- memory mode.
  • Page 350 Chrom-Art Accelerator™ controller (DMA2D) RM0090 The wrong configurations that can be detected are listed below: • Foreground CLUT automatic loading: MA bits of DMA2D_FGCMAR not aligned with CCM of DMA2D_FGPFCCR. • Background CLUT automatic loading: MA of DMA2D_BGCMAR not aligned with CCM of DMA2D_BGPFCCR •...
  • Page 351: Table 59. Dma2D Interrupt Requests

    RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.3.13 Watermark A watermark can be programmed to generate an interrupt when the last pixel of a given line has been written to the destination memory area. The line number is defined in the LW[15:0] field of the DMA2D_LWR register. When the last pixel of this line has been transferred, the TWIF flag of the DMA2D_ISR register is raised and an interrupt is generated if the TWIE bit of the DMA2D_CR is set.
  • Page 352 Chrom-Art Accelerator™ controller (DMA2D) RM0090 Table 59. DMA2D interrupt requests (continued) Interrupt event Event flag Enable control bit CLUT access error CAEIF CAEIE Transfer watermark TWIE Transfer complete TCIF TCIE Transfer error TEIF TEIE 11.5 DMA2D registers 11.5.1 DMA2D control register (DMA2D_CR) Address offset: 0x0000 Reset value: 0x0000 0000 MODE...
  • Page 353 RM0090 Chrom-Art Accelerator™ controller (DMA2D) Bit 10 TWIE: Transfer watermark interrupt enable This bit is set and cleared by software. 0: TW interrupt disable 1: TW interrupt enable Bit 9 TCIE: Transfer complete interrupt enable This bit is set and cleared by software. 0: TC interrupt disable 1: TC interrupt enable Bit 8 TEIE: Transfer error interrupt enable...
  • Page 354 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.5.2 DMA2D Interrupt Status Register (DMA2D_ISR) Address offset: 0x0004 Reset value: 0x0000 0000 Reserved CEIF CTCIF CAEIF TWIF TCIF TEIF Reserved Bits 31:6 Reserved, must be kept at reset value Bit 5 CEIF: Configuration error interrupt flag This bit is set when the START bit of DMA2D_CR, DMA2DFGPFCCR or DMA2D_BGPFCCR is set and a wrong configuration has been programmed.
  • Page 355 RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.5.3 DMA2D interrupt flag clear register (DMA2D_IFCR) Address offset: 0x0008 Reset value: 0x0000 0000 Reserved CCEIF CCTCIF CAECIF CTWIF CTCIF CTEIF Reserved rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 Bits 31:6 Reserved, must be kept at reset value Bit 5 CCEIF: Clear configuration error interrupt flag Programming this bit to 1 clears the CEIF flag in the DMA2D_ISR register Bit 4 CCTCIF: Clear CLUT transfer complete interrupt flag...
  • Page 356 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.5.4 DMA2D foreground memory address register (DMA2D_FGMAR) Address offset: 0x000C Reset value: 0x0000 0000 MA[31:16] MA[15:0] Bits 31:0 MA[31: 0]: Memory address Address of the data used for the foreground image. This register can only be written when data transfers are disabled.
  • Page 357 RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.5.6 DMA2D background memory address register (DMA2D_BGMAR) Address offset: 0x0014 Reset value: 0x0000 0000 MA[31:16] MA[15:0] Bits 31: 0 MA[31: 0]: Memory address Address of the data used for the background image. This register can only be written when data transfers are disabled.
  • Page 358 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.5.8 DMA2D foreground PFC control register (DMA2D_FGPFCCR) Address offset: 0x001C Reset value: 0x0000 0000 ALPHA[7:0] AM[1:0] Reserved CS[7:0] START CM[3:0] Reserved Bits 31:24 ALPHA[7: 0]: Alpha value These bits define a fixed alpha channel value which can replace the original alpha value or be multiplied by the original alpha value according to the alpha mode selected through the AM[1:0] bits.
  • Page 359 RM0090 Chrom-Art Accelerator™ controller (DMA2D) Bit 5 START: Start This bit can be set to start the automatic loading of the CLUT. It is automatically reset: – at the end of the transfer – when the transfer is aborted by the user application by setting the ABORT bit in DMA2D_CR –...
  • Page 360 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.5.9 DMA2D foreground color register (DMA2D_FGCOLR) Address offset: 0x0020 Reset value: 0x0000 0000 RED[7:0] Reserved GREEN[7:0] BLUE[7:0] Bits 31:24 Reserved, must be kept at reset value Bits 23:16 RED[7: 0]: Red Value These bits defines the red value for the A4 or A8 mode of the foreground image. They can only be written when data transfers are disabled.
  • Page 361 RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.5.10 DMA2D background PFC control register (DMA2D_BGPFCCR) Address offset: 0x0024 Reset value: 0x0000 0000 ALPHA[7:0] AM[1:0] Reserved CS[7:0] START CM[3:0] Reserved Bits 31:24 ALPHA[7: 0]: Alpha value These bits define a fixed alpha channel value which can replace the original alpha value or be multiplied with the original alpha value according to the alpha mode selected with bits AM[1: 0].
  • Page 362 Chrom-Art Accelerator™ controller (DMA2D) RM0090 Bit 5 START: Start This bit is set to start the automatic loading of the CLUT. This bit is automatically reset: – at the end of the transfer – when the transfer is aborted by the user application by setting the ABORT bit in the DMA2D_CR –...
  • Page 363 RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.5.11 DMA2D background color register (DMA2D_BGCOLR) Address offset: 0x0028 Reset value: 0x0000 0000 RED[7:0] Reserved GREEN[7:0] BLUE[7:0] Bits 31:24 Reserved, must be kept at reset value Bits 23:16 RED[7: 0]: Red Value These bits define the red value for the A4 or A8 mode of the background. These bits can only be written when data transfers are disabled.
  • Page 364 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.5.13 DMA2D background CLUT memory address register (DMA2D_BGCMAR) Address offset: 0x0030 Reset value: 0x0000 0000 MA[31:16] MA[15:0] Bits 31: 0 MA[31: 0]: Memory address Address of the data used for the CLUT address dedicated to the background image. This register can only be written when no transfer is on going.
  • Page 365 RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.5.15 DMA2D output color register (DMA2D_OCOLR) Address offset: 0x0038 Reset value: 0x0000 0000 ALPHA[7:0] RED[7:0] GREEN[7:0] BLUE[7:0] RED[4:0] GREEN[5:0] BLUE[4:0] RED[4:0] GREEN[4:0] BLUE[4:0] ALPHA[3:0] RED[3:0] GREEN[3:0] BLUE[3:0] Bits 31:24 ALPHA[7: 0]: Alpha Channel Value These bits define the alpha channel of the output color. These bits can only be written when data transfers are disabled.
  • Page 366 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.5.16 DMA2D output memory address register (DMA2D_OMAR) Address offset: 0x003C Reset value: 0x0000 0000 MA[31:16] MA[15:0] Bits 31: 0 MA[31: 0]: Memory Address Address of the data used for the output FIFO. These bits can only be written when data transfers are disabled.
  • Page 367 RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.5.17 DMA2D output offset register (DMA2D_OOR) Address offset: 0x0040 Reset value: 0x0000 0000 Reserved LO[13:0] Reserved Bits 31:14 Reserved, must be kept at reset value Bits 13:0 LO[13: 0]: Line Offset Line offset used for the output (expressed in pixels). This value is used for the address generation.
  • Page 368 Chrom-Art Accelerator™ controller (DMA2D) RM0090 11.5.19 DMA2D line watermark register (DMA2D_LWR) Address offset: 0x0048 Reset value: 0x0000 0000 Reserved LW[15:0] Bits 31:16 Reserved, must be kept at reset value Bits 15:0 LW[15:0]: Line watermark These bits allow to configure the line watermark for interrupt generation. An interrupt is raised when the last pixel of the watermarked line has been transferred.
  • Page 369: Table 60. Dma2D Register Map And Reset Values

    RM0090 Chrom-Art Accelerator™ controller (DMA2D) 11.5.21 DMA2D register map The following table summarizes the DMA2D registers. Refer to Section 2.3: Memory map for the DMA2D register base address. Table 60. DMA2D register map and reset values Offset Register DMA2D_CR 0x0000 Reserved Reserved Reserved...
  • Page 370 Chrom-Art Accelerator™ controller (DMA2D) RM0090 Table 60. DMA2D register map and reset values (continued) Offset Register DMA2D_OOR LO[13:0] 0x0040 Reserved Reset value DMA2D_NLR PL[13:0] NL[15:0] 0x0044 Reset value DMA2D_LWR LW[15:0] 0x0048 Reserved Reset value DMA2D_AMTCR DT[7:0] 0x004C Reserved Reserved Reset value 0x0050- Reserved Ox03FF...
  • Page 371 RM0090 Interrupts and events Interrupts and events This Section applies to the whole STM32F4xx family, unless otherwise specified. 12.1 Nested vectored interrupt controller (NVIC) 12.1.1 NVIC features The nested vector interrupt controller NVIC includes the following features: • 82 maskable interrupt channels for STM32F405xx/07xx and STM32F415xx/17xx, and up to 91 maskable interrupt channels for STM32F42xxx and STM32F43xxx (not ®...
  • Page 372: Table 61. Vector Table For Stm32F405Xx/07Xx And Stm32F415Xx/17Xx

    Interrupts and events RM0090 Table 61. Vector table for STM32F405xx/07xx and STM32F415xx/17xx Type of Acronym Description Address priority Reserved 0x0000 0000 fixed Reset Reset 0x0000 0004 Non maskable interrupt. The RCC fixed Clock Security System (CSS) is linked 0x0000 0008 to the NMI vector.
  • Page 373 RM0090 Interrupts and events Table 61. Vector table for STM32F405xx/07xx and STM32F415xx/17xx (continued) Type of Acronym Description Address priority settable DMA1_Stream1 DMA1 Stream1 global interrupt 0x0000 0070 settable DMA1_Stream2 DMA1 Stream2 global interrupt 0x0000 0074 settable DMA1_Stream3 DMA1 Stream3 global interrupt 0x0000 0078 settable DMA1_Stream4...
  • Page 374 Interrupts and events RM0090 Table 61. Vector table for STM32F405xx/07xx and STM32F415xx/17xx (continued) Type of Acronym Description Address priority settable EXTI15_10 EXTI Line[15:10] interrupts 0x0000 00E0 RTC Alarms (A and B) through EXTI settable RTC_Alarm 0x0000 00E4 line interrupt USB On-The-Go FS Wakeup through settable OTG_FS_WKUP 0x0000 00E8...
  • Page 375: Table 62. Vector Table For Stm32F42Xxx And Stm32F43Xxx

    RM0090 Interrupts and events Table 61. Vector table for STM32F405xx/07xx and STM32F415xx/17xx (continued) Type of Acronym Description Address priority settable CAN2_RX1 CAN2 RX1 interrupt 0x0000 0144 settable CAN2_SCE CAN2 SCE interrupt 0x0000 0148 settable OTG_FS USB On The Go FS global interrupt 0x0000 014C settable DMA2_Stream5...
  • Page 376 Interrupts and events RM0090 Table 62. Vector table for STM32F42xxx and STM32F43xxx (continued) Type of Acronym Description Address priority fixed HardFault All class of fault 0x0000 000C settable MemManage Memory management 0x0000 0010 settable BusFault Pre-fetch fault, memory access fault 0x0000 0014 settable UsageFault...
  • Page 377 RM0090 Interrupts and events Table 62. Vector table for STM32F42xxx and STM32F43xxx (continued) Type of Acronym Description Address priority settable ADC1, ADC2 and ADC3 global interrupts 0x0000 0088 settable CAN1_TX CAN1 TX interrupts 0x0000 008C settable CAN1_RX0 CAN1 RX0 interrupts 0x0000 0090 settable CAN1_RX1...
  • Page 378 Interrupts and events RM0090 Table 62. Vector table for STM32F42xxx and STM32F43xxx (continued) Type of Acronym Description Address priority TIM8 Update interrupt and TIM13 global settable TIM8_UP_TIM13 0x0000 00F0 interrupt TIM8_TRG_COM_TIM1 TIM8 Trigger and Commutation interrupts settable 0x0000 00F4 and TIM14 global interrupt settable TIM8_CC TIM8 Capture Compare interrupt...
  • Page 379 RM0090 Interrupts and events Table 62. Vector table for STM32F42xxx and STM32F43xxx (continued) Type of Acronym Description Address priority settable I2C3_EV C3 event interrupt 0x0000 0160 settable I2C3_ER C3 error interrupt 0x0000 0164 USB On The Go HS End Point 1 Out global settable OTG_HS_EP1_OUT 0x0000 0168...
  • Page 380: Figure 41. External Interrupt/Event Controller Block Diagram

    Interrupts and events RM0090 12.2.2 EXTI block diagram Figure 41 shows the block diagram. Figure 41. External interrupt/event controller block diagram AMBA APB bus PCLK2 Peripheral interface Software Rising Falling Pending Interrupt interrupt trigger trigger request mask event selection selection register register register...
  • Page 381 RM0090 Interrupts and events 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’...
  • Page 382: Figure 42. External Interrupt/Event Gpio Mapping (Stm32F405Xx/07Xx And Stm32F415Xx/17Xx)

    Interrupts and events RM0090 12.2.5 External interrupt/event line mapping Up to 140 GPIOs (STM32F405xx/07xx and STM32F415xx/17xx), 168 GPIOs (STM32F42xxx and STM32F43xxx) are connected to the 16 external interrupt/event lines in the following manner: Figure 42. External interrupt/event GPIO mapping (STM32F405xx/07xx and STM32F415xx/17xx) EXTI0[3:0] bits in the SYSCFG_EXTICR1 register EXTI0...
  • Page 383: Figure 43. External Interrupt/Event Gpio Mapping (Stm32F42Xxx And Stm32F43Xxx)

    RM0090 Interrupts and events Figure 43. External interrupt/event GPIO mapping (STM32F42xxx and STM32F43xxx) EXTI0[3:0] bits in the SYSCFG_EXTICR1 register EXTI0 EXTI1[3:0] bits in the SYSCFG_EXTICR1 register EXTI1 EXTI15[3:0] bits in the SYSCFG_EXTICR4 register PA15 PB15 PC15 PD15 EXTI15 PE15 PF15 PG15 PH15 PJ15...
  • Page 384 Interrupts and events RM0090 12.3 registers EXTI Refer to Section 1.1: List of abbreviations for registers for a list of abbreviations used in register descriptions. 12.3.1 Interrupt mask register (EXTI_IMR) Address offset: 0x00 Reset value: 0x0000 0000 MR22 MR21 MR20 MR19 MR18 MR17...
  • Page 385 RM0090 Interrupts and events 12.3.3 Rising trigger selection register (EXTI_RTSR) Address offset: 0x08 Reset value: 0x0000 0000 TR22 TR21 TR20 TR19 TR18 TR17 TR16 Reserved TR15 TR14 TR13 TR12 TR11 TR10 Bits 31:23 Reserved, must be kept at reset value. Bits 22:0 TRx: Rising trigger event configuration bit of line x 0: Rising trigger disabled (for Event and Interrupt) for input line 1: Rising trigger enabled (for Event and Interrupt) for input line...
  • Page 386 Interrupts and events RM0090 12.3.5 Software interrupt event register (EXTI_SWIER) Address offset: 0x10 Reset value: 0x0000 0000 SWIER SWIER SWIER SWIER SWIER SWIER SWIER Reserved SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER Bits 31:23 Reserved, must be kept at reset value.
  • Page 387: Table 63. External Interrupt/Event Controller Register Map And Reset Values

    RM0090 Interrupts and events 12.3.7 EXTI register map Table 64 gives the EXTI register map and the reset values. Table 63. External interrupt/event controller register map and reset values Offset Register EXTI_IMR MR[22:0] 0x00 Reserved Reset value EXTI_EMR MR[22:0] 0x04 Reserved Reset value EXTI_RTSR...
  • Page 388 Analog-to-digital converter (ADC) RM0090 Analog-to-digital converter (ADC) This section applies to the whole STM32F4xx family, unless otherwise specified. 13.1 ADC introduction The 12-bit ADC is a successive approximation analog-to-digital converter. It has up to 19 multiplexed channels allowing it to measure signals from 16 external sources, two internal sources, and the V channel.
  • Page 389: Figure 44. Single Adc Block Diagram

    RM0090 Analog-to-digital converter (ADC) 13.3 ADC functional description Figure 44 shows a single ADC block diagram and Table 65 gives the ADC pin description. Figure 44. Single ADC block diagram Interrupt Flags enable bits DMA overrun OVRIE End of conversion EOCIE ADC Interrupt to NVIC End of injected conversion...
  • Page 390: Table 65. Adc Pins

    Analog-to-digital converter (ADC) RM0090 Table 65. ADC pins Name Signal type Remarks Input, analog reference The higher/positive reference voltage for the ADC, REF+ ≤ ≤ positive 1.8 V REF+ Analog power supply equal to V ≤ ≤ Input, analog supply 2.4 V (3.6 V) for full speed ≤...
  • Page 391 RM0090 Analog-to-digital converter (ADC) 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.
  • Page 392: Figure 45. Timing Diagram

    Analog-to-digital converter (ADC) RM0090 13.3.5 Continuous conversion mode In continuous conversion mode, the ADC starts a new conversion as soon as it finishes one. This mode is started with the CONT bit at 1 either by external trigger or by setting the SWSTRT bit in the ADC_CR2 register (for regular channels only).
  • Page 393: Table 66. Analog Watchdog Channel Selection

    RM0090 Analog-to-digital converter (ADC) Figure 46. Analog watchdog’s guarded area Analog voltage Higher threshold Guarde d area Lower threshold LT R ai16048 Table 66. Analog watchdog channel selection ADC_CR1 register control bits (x = don’t care) Channels guarded by the analog watchdog AWDSGL bit AWDEN bit...
  • Page 394: Figure 47. Injected Conversion Latency

    Analog-to-digital converter (ADC) RM0090 13.3.9 Injected channel management Triggered injection To use triggered injection, the JAUTO bit must be cleared in the ADC_CR1 register. Start the conversion of a group of regular channels either by external trigger or by setting the SWSTART bit in the ADC_CR2 register. If an external injected trigger occurs or if the JSWSTART bit is set during the conversion of a regular group of channels, the current conversion is reset and the injected channel sequence switches to Scan-once mode.
  • Page 395 RM0090 Analog-to-digital converter (ADC) 13.3.10 Discontinuous mode Regular group This mode is enabled by setting the DISCEN bit in the ADC_CR1 register. It can be used to convert a short sequence of n conversions (n ≤ 8) that is part of the sequence of conversions selected in the ADC_SQRx registers.
  • Page 396: Figure 48. Right Alignment Of 12-Bit Data

    Analog-to-digital converter (ADC) RM0090 13.4 Data alignment The ALIGN bit in the ADC_CR2 register selects the alignment of the data stored after conversion. Data can be right- or left-aligned as shown in Figure 48 Figure The converted data value from the injected group of channels is decreased by the user- defined offset written in the ADC_JOFRx registers so the result can be a negative value.
  • Page 397: Table 67. Configuring The Trigger Polarity

    RM0090 Analog-to-digital converter (ADC) 13.5 Channel-wise programmable sampling time The ADC samples the input voltage for a number of ADCCLK cycles that can be modified using the SMP[2:0] bits in the ADC_SMPR1 and ADC_SMPR2 registers. Each channel can be sampled with a different sampling time. The total conversion time is calculated as follows: = Sampling time + 12 cycles conv...
  • Page 398: Table 68. External Trigger For Regular Channels

    Analog-to-digital converter (ADC) RM0090 Table 68. External trigger for regular channels Source Type EXTSEL[3:0] TIM1_CH1 event 0000 TIM1_CH2 event 0001 TIM1_CH3 event 0010 TIM2_CH2 event 0011 TIM2_CH3 event 0100 TIM2_CH4 event 0101 TIM2_TRGO event 0110 Internal signal from on-chip TIM3_CH1 event 0111 timers TIM3_TRGO event...
  • Page 399: Table 69. External Trigger For Injected Channels

    RM0090 Analog-to-digital converter (ADC) Table 69. External trigger for injected channels Source Connection type JEXTSEL[3:0] TIM1_CH4 event 0000 TIM1_TRGO event 0001 TIM2_CH1 event 0010 TIM2_TRGO event 0011 TIM3_CH2 event 0100 TIM3_CH4 event 0101 TIM4_CH1 event 0110 Internal signal from on-chip TIM4_CH2 event 0111 timers...
  • Page 400 Analog-to-digital converter (ADC) RM0090 13.8 Data management 13.8.1 Using the DMA Since converted regular channel values are stored into a unique data register, it is useful to use DMA for conversion of more than one regular channel. This avoids the loss of the data already stored in the ADC_DR register.
  • Page 401 RM0090 Analog-to-digital converter (ADC) 13.8.3 Conversions without DMA and without overrun detection It may be useful to let the ADC convert one or more channels without reading the data each time (if there is an analog watchdog for instance). For that, the DMA must be disabled (DMA = 0) and the EOC bit must be set at the end of a sequence only (EOCS = 0).
  • Page 402 Analog-to-digital converter (ADC) RM0090 Figure 51. Multi ADC block diagram Regular data register (12 bits) (16 bits) Injected data registers Regular (4 x 16 bits) channels ADC3 (Slave) Injected channels Regular data register (12 bits) (16 bits) Injected data registers Regular (4 x 16 bits) channels...
  • Page 403 RM0090 Analog-to-digital converter (ADC) • DMA requests in Multi ADC mode: In Multi ADC mode the DMA may be configured to transfer converted data in three different modes. In all cases, the DMA streams to use are those connected to the ADC: –...
  • Page 404 Analog-to-digital converter (ADC) RM0090 representing two ADC converted data items are transferred as a half-word. The data transfer order is similar to that of the DMA mode 2. DMA mode 3 is used in interleaved mode in 6-bit and 8-bit resolutions (dual and triple mode).
  • Page 405: Figure 52. Injected Simultaneous Mode On 4 Channels: Dual Adc Mode

    RM0090 Analog-to-digital converter (ADC) Dual ADC mode At the end of conversion event on ADC1 or ADC2: • The converted data are stored into the ADC_JDRx registers of each ADC interface. • A JEOC interrupt is generated (if enabled on one of the two ADC interfaces) when the ADC1/ADC2’s injected channels have all been converted.
  • Page 406: Figure 54. Regular Simultaneous Mode On 16 Channels: Dual Adc Mode

    Analog-to-digital converter (ADC) RM0090 Dual ADC mode At the end of conversion event on ADC1 or ADC2: • A 32-bit DMA transfer request is generated (if DMA[1:0] bits in the ADC_CCR register are equal to 0b10). This request transfers the ADC2 converted data stored in the upper half-word of the ADC_CDR 32-bit register to the SRAM and then the ADC1 converted data stored in the lower half-word of ADC_CDR to the SRAM.
  • Page 407: Figure 56. Interleaved Mode On 1 Channel In Continuous Conversion Mode: Dual Adc Mode

    RM0090 Analog-to-digital converter (ADC) 13.9.3 Interleaved mode This mode can be started only on a regular group (usually one channel). The external trigger source comes from the regular channel multiplexer of ADC1. Dual ADC mode After an external trigger occurs: •...
  • Page 408: Figure 57. Interleaved Mode On 1 Channel In Continuous Conversion Mode: Triple Adc Mode

    Analog-to-digital converter (ADC) RM0090 a given time). In this case, the delay becomes the sampling time + 2 ADC clock cycles. For instance, if DELAY = 5 clock cycles and the sampling takes 15 clock cycles on the three ADCs, then 17 clock cycles will separate the conversions on ADC1, ADC2 and ADC3). If the CONT bit is set on ADC1, ADC2 and ADC3, the selected regular channels of all ADCs are continuously converted.
  • Page 409: Figure 58. Alternate Trigger: Injected Group Of Each Adc

    RM0090 Analog-to-digital converter (ADC) ADC has to perform an injected conversion. It is resumed when the injected conversion is finished. If the conversion sequence is interrupted (for instance when DMA end of transfer occurs), the multi-ADC sequencer must be reset by configuring it in independent mode first (bits DUAL[4:0] = 00000) before reprogramming the interleaved mode.
  • Page 410: Figure 59. Alternate Trigger: 4 Injected Channels (Each Adc) In Discontinuous Mode

    Analog-to-digital converter (ADC) RM0090 Figure 59. Alternate trigger: 4 injected channels (each ADC) in discontinuous mode 1st trigger 3rd trigger 5th trigger 7th trigger Sampling JEOC on ADC1 Conversion ADC1 ADC2 JEOC on ADC2 2nd trigger 4th trigger 6th trigger 8th trigger ai16060 Triple ADC mode...
  • Page 411: Figure 61. Alternate + Regular Simultaneous

    RM0090 Analog-to-digital converter (ADC) ADC with the shortest sequence may restart while the ADC with the longest sequence is completing the previous conversions. 13.9.6 Combined regular simultaneous + alternate trigger mode It is possible to interrupt the simultaneous conversion of a regular group to start the alternate trigger conversion of an injected group.
  • Page 412: Figure 62. Case Of Trigger Occurring During Injected Conversion

    Analog-to-digital converter (ADC) RM0090 Figure 62. Case of trigger occurring during injected conversion 1st trigger 3rd trigger ADC1 reg ADC1 inj ADC2 reg ADC2 inj 2nd trigger 2nd trigger ai16063 13.10 Temperature sensor The temperature sensor can be used to measure the ambient temperature (T ) of the device.
  • Page 413: Figure 63. Temperature Sensor And Vrefint Channel Block Diagram

    RM0090 Analog-to-digital converter (ADC) Figure 63. Temperature sensor and V channel block diagram REFINT TSVREFE control bit Temperature V SENSE ADC1_IN16/ sensor ADC1_IN18 (1) converted data ADC1 V REFINT Internal ADC1_IN17 power block MS31830V1 1. V is input to ADC1_IN16 for the STM23F40x and STM32F41x devices and to ADC1_IN18 for the SENSE STM32F42x and STM32F43x devices.
  • Page 414: Table 70. Adc Interrupts

    Analog-to-digital converter (ADC) RM0090 The internal temperature sensor is more suited for applications that detect temperature variations instead of absolute temperatures. If accurate temperature reading is required, an external temperature sensor should be used. 13.11 Battery charge monitoring The VBATE bit in the ADC_CCR register is used to switch to the battery voltage. As the voltage could be higher than V , to ensure the correct operation of the ADC, the pin is internally connected to a bridge divider.
  • Page 415 RM0090 Analog-to-digital converter (ADC) 13.13 ADC registers Refer to Section 1.1: List of abbreviations for registers for registers for a list of abbreviations used in register descriptions. The peripheral registers must be written at word level (32 bits). Read accesses can be done by bytes (8 bits), half-words (16 bits) or words (32 bits).
  • Page 416 Analog-to-digital converter (ADC) RM0090 13.13.2 ADC control register 1 (ADC_CR1) Address offset: 0x04 Reset value: 0x0000 0000 OVRIE AWDEN JAWDEN Reserved Reserved JDISCE DISC AWDSG DISCNUM[2:0] JAUTO SCAN JEOCIE AWDIE EOCIE AWDCH[4:0] Bits 31:27 Reserved, must be kept at reset value. Bit 26 OVRIE: Overrun interrupt enable This bit is set and cleared by software to enable/disable the Overrun interrupt.
  • Page 417 RM0090 Analog-to-digital converter (ADC) Bit 11 DISCEN: Discontinuous mode on regular channels This bit is set and cleared by software to enable/disable Discontinuous mode on regular channels. 0: Discontinuous mode on regular channels disabled 1: Discontinuous mode on regular channels enabled Bit 10 JAUTO: Automatic injected group conversion This bit is set and cleared by software to enable/disable automatic injected group conversion after regular group conversion.
  • Page 418 Analog-to-digital converter (ADC) RM0090 13.13.3 ADC control register 2 (ADC_CR2) Address offset: 0x08 Reset value: 0x0000 0000 SWST JSWST EXTEN EXTSEL[3:0] JEXTEN JEXTSEL[3:0] reserved reserved ALIGN EOCS CONT ADON reserved Reserved Bit 31 Reserved, must be kept at reset value. Bit 30 SWSTART: Start conversion of regular channels This bit is set by software to start conversion and cleared by hardware as soon as the conversion starts.
  • Page 419 RM0090 Analog-to-digital converter (ADC) Bit 22 JSWSTART: Start conversion of injected channels This bit is set by software and cleared by hardware as soon as the conversion starts. 0: Reset state 1: Starts conversion of injected channels Note: This bit can be set only when ADON = 1 otherwise no conversion is launched. Bits 21:20 JEXTEN: External trigger enable for injected channels These bits are set and cleared by software to select the external trigger polarity and enable the trigger of an injected group.
  • Page 420 Analog-to-digital converter (ADC) RM0090 Bits 7:2 Reserved, must be kept at reset value. Bit 1 CONT: Continuous conversion This bit is set and cleared by software. If it is set, conversion takes place continuously until it is cleared. 0: Single conversion mode 1: Continuous conversion mode Bit 0 ADON: A/D Converter ON / OFF This bit is set and cleared by software.
  • Page 421 RM0090 Analog-to-digital converter (ADC) Bits 31:30 Reserved, must be kept at reset value. Bits 29:0 SMPx[2:0]: Channel x sampling time selection These bits are written by software to select the sampling time individually for each channel. During sample cycles, the channel selection bits must remain unchanged. Note: 000: 3 cycles 001: 15 cycles 010: 28 cycles...
  • Page 422 Analog-to-digital converter (ADC) RM0090 Note: The software can write to these registers when an ADC conversion is ongoing. The programmed value will be effective when the next conversion is complete. Writing to this register is performed with a write delay that can create uncertainty on the effective time at which the new value is programmed.
  • Page 423 RM0090 Analog-to-digital converter (ADC) Bits 14:10 SQ15[4:0]: 15th conversion in regular sequence Bits 9:5 SQ14[4:0]: 14th conversion in regular sequence Bits 4:0 SQ13[4:0]: 13th conversion in regular sequence 13.13.10 ADC regular sequence register 2 (ADC_SQR2) Address offset: 0x30 Reset value: 0x0000 0000 SQ12[4:0] SQ11[4:0] SQ10[4:1]...
  • Page 424 Analog-to-digital converter (ADC) RM0090 Bits 19:15 SQ4[4:0]: 4th conversion in regular sequence Bits 14:10 SQ3[4:0]: 3rd conversion in regular sequence Bits 9:5 SQ2[4:0]: 2nd conversion in regular sequence Bits 4:0 SQ1[4:0]: 1st conversion in regular sequence 13.13.12 ADC injected sequence register (ADC_JSQR) Address offset: 0x38 Reset value: 0x0000 0000 JL[1:0]...
  • Page 425 RM0090 Analog-to-digital converter (ADC) 13.13.13 ADC injected data register x (ADC_JDRx) (x= 1..4) Address offset: 0x3C - 0x48 Reset value: 0x0000 0000 Reserved JDATA[15:0] Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 JDATA[15:0]: Injected data These bits are read-only. They contain the conversion result from injected channel x. The data are left -or right-aligned as shown in Figure 48 Figure...
  • Page 426 Analog-to-digital converter (ADC) RM0090 13.13.15 ADC Common status register (ADC_CSR) Address offset: 0x00 (this offset address is relative to ADC1 base address + 0x300) Reset value: 0x0000 0000 This register provides an image of the status bits of the different ADCs. Nevertheless it is read-only and does not allow to clear the different status bits.
  • Page 427 RM0090 Analog-to-digital converter (ADC) Bits 7:6 Reserved, must be kept at reset value. Bit 5 OVR1: Overrun flag of ADC1 This bit is a copy of the OVR bit in the ADC1_SR register. Bit 4 STRT1: Regular channel Start flag of ADC1 This bit is a copy of the STRT bit in the ADC1_SR register.
  • Page 428 Analog-to-digital converter (ADC) RM0090 Bits 17:16 ADCPRE: ADC prescaler Set and cleared by software to select the frequency of the clock to the ADC. The clock is common for all the ADCs. Note: 00: PCLK2 divided by 2 01: PCLK2 divided by 4 10: PCLK2 divided by 6 11: PCLK2 divided by 8 Bits 15:14 DMA: Direct memory access mode for multi ADC mode...
  • Page 429 RM0090 Analog-to-digital converter (ADC) Bit 11:8 DELAY: Delay between 2 sampling phases Set and cleared by software. These bits are used in dual or triple interleaved modes. 0000: 5 * T ADCCLK 0001: 6 * T ADCCLK 0010: 7 * T ADCCLK 1111: 20 * T ADCCLK...
  • Page 430: Table 71. Adc Global Register Map

    Analog-to-digital converter (ADC) RM0090 13.13.17 ADC common regular data register for dual and triple modes (ADC_CDR) Address offset: 0x08 (this offset address is relative to ADC1 base address + 0x300) Reset value: 0x0000 0000 DATA2[15:0] DATA1[15:0] Bits 31:16 DATA2[15:0]: 2nd data item of a pair of regular conversions –...
  • Page 431: Table 72. Adc Register Map And Reset Values For Each Adc

    RM0090 Analog-to-digital converter (ADC) Table 72. ADC register map and reset values for each ADC Offset Register ADC_SR 0x00 Reserved Reset value DISC ADC_CR1 AWDCH[4:0] NUM [2:0] 0x04 Reserved Reserved Reset value JEXTSEL ADC_CR2 EXTSEL [3:0] [3:0] 0x08 Reserved Reserved Reset value ADC_SMPR1 Sample time bits SMPx_x...
  • Page 432: Table 73. Adc Register Map And Reset Values (Common Adc Registers)

    Analog-to-digital converter (ADC) RM0090 Table 73. ADC register map and reset values (common ADC registers) Offset Register ADC_CSR 0x00 Reserved Reset value ADC3 ADC2 ADC1 ADC_CCR DELAY [3:0] MULTI [4:0] 0x04 Reserved Reserved Reserved Reset value ADC_CDR Regular DATA2[15:0] Regular DATA1[15:0] 0x08 Reset value Refer to...
  • Page 433 RM0090 Digital-to-analog converter (DAC) Digital-to-analog converter (DAC) This section applies to the whole STM32F4xx family, unless otherwise specified. 14.1 DAC introduction The DAC module is a 12-bit, voltage output digital-to-analog converter. The DAC can be configured in 8- or 12-bit mode and may be used in conjunction with the DMA controller. In 12-bit mode, the data could be left- or right-aligned.
  • Page 434: Table 74. Dac Pins

    Digital-to-analog converter (DAC) RM0090 Figure 64. DAC channel block diagram DAC control register TSELx[2:0] bits SWTR IGx TIM2_T RGO DMAENx TIM4_T RGO TIM5_T RGO TIM6_T RGO TIM7_T RGO TIM8_T RGO EXTI_9 DM A req ue stx Control logicx TENx 12-bit DHRx MAMPx[3:0] bits trianglex...
  • Page 435 RM0090 Digital-to-analog converter (DAC) 14.3 DAC functional description 14.3.1 DAC channel enable Each DAC channel can be powered on by setting its corresponding ENx bit in the DAC_CR register. The DAC channel is then enabled after a startup time t WAKEUP Note: The ENx bit enables the analog DAC Channelx macrocell only.
  • Page 436: Figure 65. Data Registers In Single Dac Channel Mode

    Digital-to-analog converter (DAC) RM0090 Figure 65. Data registers in single DAC channel mode 8-bit right aligned 12-bit left aligned 12-bit right aligned ai14710b • Dual DAC channels, there are three possibilities: – 8-bit right alignment: data for DAC channel1 to be loaded into the DAC_DHR8RD [7:0] bits (stored into the DHR1[11:4] bits) and data for DAC channel2 to be loaded into the DAC_DHR8RD [15:8] bits (stored into the DHR2[11:4] bits) –...
  • Page 437: Table 75. External Triggers

    RM0090 Digital-to-analog converter (DAC) When DAC_DORx is loaded with the DAC_DHRx contents, the analog output voltage becomes available after a time t that depends on the power supply voltage and the SETTLING analog output load. Figure 67. Timing diagram for conversion with trigger disabled TEN = 0 APB1_CLK 0x1AC Output voltage...
  • Page 438 Digital-to-analog converter (DAC) RM0090 If the software trigger is selected, the conversion starts once the SWTRIG bit is set. SWTRIG is reset by hardware once the DAC_DORx register has been loaded with the DAC_DHRx register contents. Note: TSELx[2:0] bit cannot be changed when the ENx bit is set. When software trigger is selected, the transfer from the DAC_DHRx register to the DAC_DORx register takes only one APB1 clock cycle.
  • Page 439: Figure 68. Dac Lfsr Register Calculation Algorithm

    RM0090 Digital-to-analog converter (DAC) Figure 68. DAC LFSR register calculation algorithm ai14713c The LFSR value, that may be masked partially or totally by means of the MAMPx[3:0] bits in the DAC_CR register, is added up to the DAC_DHRx contents without overflow and this value is then stored into the DAC_DORx register.
  • Page 440: Figure 70. Dac Triangle Wave Generation

    Digital-to-analog converter (DAC) RM0090 It is possible to reset triangle wave generation by resetting the WAVEx[1:0] bits. Figure 70. DAC triangle wave generation MAMPx[3:0] max amplitude + DAC_DHRx base value DAC_DHRx base value ai14715c Figure 71. DAC conversion (SW trigger enabled) with triangle wave generation APB1_CLK 0x00 0xAAA...
  • Page 441 RM0090 Digital-to-analog converter (DAC) 14.4.1 Independent trigger without wave generation To configure the DAC in this conversion mode, the following sequence is required: • Set the two DAC channel trigger enable bits TEN1 and TEN2 • Configure different trigger sources by setting different values in the TSEL1[2:0] and TSEL2[2:0] bits •...
  • Page 442 Digital-to-analog converter (DAC) RM0090 14.4.4 Independent trigger with single triangle generation To configure the DAC in this conversion mode, the following sequence is required: • Set the two DAC channel trigger enable bits TEN1 and TEN2 • Configure different trigger sources by setting different values in the TSEL1[2:0] and TSEL2[2:0] bits •...
  • Page 443 RM0090 Digital-to-analog converter (DAC) 14.4.7 Simultaneous trigger without wave generation To configure the DAC in this conversion mode, the following sequence is required: • Set the two DAC channel trigger enable bits TEN1 and TEN2 • Configure the same trigger source for both DAC channels by setting the same value in the TSEL1[2:0] and TSEL2[2:0] bits •...
  • Page 444 Digital-to-analog converter (DAC) RM0090 14.4.10 Simultaneous trigger with single triangle generation To configure the DAC in this conversion mode, the following sequence is required: • Set the two DAC channel trigger enable bits TEN1 and TEN2 • Configure the same trigger source for both DAC channels by setting the same value in the TSEL1[2:0] and TSEL2[2:0] bits •...
  • Page 445 RM0090 Digital-to-analog converter (DAC) 14.5 DAC registers Refer to Section 1.1: List of abbreviations for registers for registers for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by words (32 bits). 14.5.1 DAC control register (DAC_CR) Address offset: 0x00 Reset value: 0x0000 0000 DMAU...
  • Page 446 Digital-to-analog converter (DAC) RM0090 Bits 21:19 TSEL2[2:0]: DAC channel2 trigger selection These bits select the external event used to trigger DAC channel2 000: Timer 6 TRGO event 001: Timer 8 TRGO event 010: Timer 7 TRGO event 011: Timer 5 TRGO event 100: Timer 2 TRGO event 101: Timer 4 TRGO event 110: External line9...
  • Page 447 RM0090 Digital-to-analog converter (DAC) Bits 11:8 MAMP1[3:0]: DAC channel1 mask/amplitude selector These bits are written by software to select mask in wave generation mode or amplitude in triangle generation mode. 0000: Unmask bit0 of LFSR/ triangle amplitude equal to 1 0001: Unmask bits[1:0] of LFSR/ triangle amplitude equal to 3 0010: Unmask bits[2:0] of LFSR/ triangle amplitude equal to 7 0011: Unmask bits[3:0] of LFSR/ triangle amplitude equal to 15...
  • Page 448 Digital-to-analog converter (DAC) RM0090 14.5.2 DAC software trigger register (DAC_SWTRIGR) Address offset: 0x04 Reset value: 0x0000 0000 Reserved SWTRIG2 SWTRIG1 Reserved Bits 31:2 Reserved, must be kept at reset value. Bit 1 SWTRIG2: DAC channel2 software trigger This bit is set and cleared by software to enable/disable the software trigger. 0: Software trigger disabled 1: Software trigger enabled Note: This bit is cleared by hardware (one APB1 clock cycle later) once the DAC_DHR2...
  • Page 449 RM0090 Digital-to-analog converter (DAC) 14.5.4 DAC channel1 12-bit left aligned data holding register (DAC_DHR12L1) Address offset: 0x0C Reset value: 0x0000 0000 Reserved DACC1DHR[11:0] Reserved Bits 31:16 Reserved, must be kept at reset value. Bits 15:4 DACC1DHR[11:0]: DAC channel1 12-bit left-aligned data These bits are written by software which specifies 12-bit data for DAC channel1.
  • Page 450 Digital-to-analog converter (DAC) RM0090 14.5.6 DAC channel2 12-bit right aligned data holding register (DAC_DHR12R2) Address offset: 0x14 Reset value: 0x0000 0000 Reserved DACC2DHR[11:0] Reserved Bits 31:12 Reserved, must be kept at reset value. Bits 11:0 DACC2DHR[11:0]: DAC channel2 12-bit right-aligned data These bits are written by software which specifies 12-bit data for DAC channel2.
  • Page 451 RM0090 Digital-to-analog converter (DAC) 14.5.9 Dual DAC 12-bit right-aligned data holding register (DAC_DHR12RD) Address offset: 0x20 Reset value: 0x0000 0000 DACC2DHR[11:0] Reserved DACC1DHR[11:0] Reserved Bits 31:28 Reserved, must be kept at reset value. Bits 27:16 DACC2DHR[11:0]: DAC channel2 12-bit right-aligned data These bits are written by software which specifies 12-bit data for DAC channel2.
  • Page 452 Digital-to-analog converter (DAC) RM0090 14.5.11 DUAL DAC 8-bit right aligned data holding register (DAC_DHR8RD) Address offset: 0x28 Reset value: 0x0000 0000 Reserved DACC2DHR[7:0] DACC1DHR[7:0] Bits 31:16 Reserved, must be kept at reset value. Bits 15:8 DACC2DHR[7:0]: DAC channel2 8-bit right-aligned data These bits are written by software which specifies 8-bit data for DAC channel2.
  • Page 453: Table 76. Dac Register Map

    RM0090 Digital-to-analog converter (DAC) 14.5.14 DAC status register (DAC_SR) Address offset: 0x34 Reset value: 0x0000 0000 DMAUDR2 Reserved Reserved rc_w1 DMAUDR1 Reserved Reserved rc_w1 Bits 31:30 Reserved, must be kept at reset value. Bit 29 DMAUDR2: DAC channel2 DMA underrun flag This bit is set by hardware and cleared by software (by writing it to 1).
  • Page 454 Digital-to-analog converter (DAC) RM0090 Table 76. DAC register map (continued) Offset Register DAC_ 0x1C Reserved DACC2DHR[7:0] DHR8R2 DAC_ 0x20 Reserved DACC2DHR[11:0] Reserved DACC1DHR[11:0] DHR12RD DAC_ 0x24 DACC2DHR[11:0] Reserved DACC1DHR[11:0] Reserved DHR12LD DAC_ 0x28 Reserved DACC2DHR[7:0] DACC1DHR[7:0] DHR8RD DAC_ 0x2C Reserved DACC1DOR[11:0] DOR1 DAC_...
  • Page 455: Table 77. Dcmi Pins

    RM0090 Digital camera interface (DCMI) Digital camera interface (DCMI) This section applies to all STM32F4xx devices, unless otherwise specified. 15.1 DCMI introduction The digital camera is a synchronous parallel interface able to receive a high-speed data flow from an external 8-, 10-, 12- or 14-bit CMOS camera module. It supports different data formats: YCbCr4:2:2/RGB565 progressive video and compressed data (JPEG).
  • Page 456: Figure 72. Dcmi Block Diagram

    Digital camera interface (DCMI) RM0090 15.5 DCMI functional overview The digital camera interface is a synchronous parallel interface that can receive high-speed (up to 54 Mbytes/s) data flows. It consists of up to 14 data lines (D13-D0) and a pixel clock line (PIXCLK).
  • Page 457: Table 78. Dcmi Signals

    RM0090 Digital camera interface (DCMI) Figure 73. Top-level block diagram DCMI_D[0:13] DCMI_PIXCLK External HCLK interface DCMI_HSYNC DCMI_VSYNC DCMI Interrupt DCMI_IT controller DMA_REQ ai15603b 15.5.1 DMA interface The DMA interface is active when the CAPTURE bit in the DCMI_CR register is set. A DMA request is generated each time the camera interface receives a complete 32-bit data block in its register.
  • Page 458: Table 79. Positioning Of Captured Data Bytes In 32-Bit Words (8-Bit Width)

    Digital camera interface (DCMI) RM0090 Figure 74. DCMI signal waveforms DCMI_PIXCLK DCMI_HSYNC DCMI_VSYNC ai15606b 1. The capture edge of DCMI_PIXCLK is the falling edge, the active state of DCMI_HSYNC and DCMI_VSYNC is 1. 1. DCMI_HSYNC and DCMI_VSYNC can change states at the same time. 8-bit data When EDM[1:0] in DCMI_CR are programmed to “00”...
  • Page 459: Table 81. Positioning Of Captured Data Bytes In 32-Bit Words (12-Bit Width)

    RM0090 Digital camera interface (DCMI) 12-bit data When EDM[1:0] in DCMI_CR are programmed to “10”, the camera interface captures the 12-bit data at its input D[0..11] and stores them as the 12 least significant bits of a 16-bit word. The remaining most significant bits are cleared to zero. So, in this case a 32-bit data word is made up every two pixel clock cycles.
  • Page 460: Figure 75. Timing Diagram

    Digital camera interface (DCMI) RM0090 Figure 75. Timing diagram Padding data at the end of the JPEG stream Beginning of JPEG stream Programmable JPEG packet size JPEG data End of JPEG stream DCMI_HSYNC DCMI_VSYNC Packet dispatching depends on the image content. This results in a variable blanking duration.
  • Page 461 RM0090 Digital camera interface (DCMI) Hardware synchronization mode In hardware synchronisation mode, the two synchronization signals (HSYNC/VSYNC) are used. Depending on the camera module/mode, data may be transmitted during horizontal/vertical synchronisation periods. The HSYNC/VSYNC signals act like blanking signals since all the data received during HSYNC/VSYNC active periods are ignored.
  • Page 462: Figure 76. Frame Capture Waveforms In Snapshot Mode

    Digital camera interface (DCMI) RM0090 This mode can be supported by programming the following codes: • FS ≤ 0xFF • FE ≤ 0xFF • LS ≤ SAV (active) • LE ≤ EAV (active) An embedded unmask code is also implemented for frame/line start and frame/line end codes.
  • Page 463: Figure 77. Frame Capture Waveforms In Continuous Grab Mode

    RM0090 Digital camera interface (DCMI) Continuous grab mode In this mode (CM bit = ‘0’ in DCMI_CR), once the CAPTURE bit has been set in DCMI_CR, the grabbing process starts on the next VSYNC or embedded frame start depending on the mode.
  • Page 464: Figure 78. Coordinates And Size Of The Window After Cropping

    Digital camera interface (DCMI) RM0090 Figure 78. Coordinates and size of the window after cropping VST bit in DCMI_CSTRT VLINE bit in DCMI_CSIZE HOFFCNT bit in DCMI_CSTRT CAPCNT bit in DCMI_CSIZE ai15834 These registers specify the coordinates of the starting point of the capture window as a line number (in the frame, starting from 0) and a number of pixel clocks (on the line, starting from 0), and the size of the window as a line number and a number of pixel clocks.
  • Page 465: Figure 80. Pixel Raster Scan Order

    RM0090 Digital camera interface (DCMI) 15.5.6 JPEG format To allow JPEG image reception, it is necessary to set the JPEG bit in the DCMI_CR register. JPEG images are not stored as lines and frames, so the VSYNC signal is used to start the capture while HSYNC serves as a data enable signal.
  • Page 466: Table 83. Data Storage In Monochrome Progressive Video Format

    Digital camera interface (DCMI) RM0090 15.6.2 Monochrome format Characteristics: • Raster format • 8 bits per pixel Table 83 shows how the data are stored. Table 83. Data storage in monochrome progressive video format Byte address 31:24 23:16 15:8 n + 3 n + 2 n + 1 n + 7...
  • Page 467: Table 85. Data Storage In Ycbcr Progressive Video Format

    RM0090 Digital camera interface (DCMI) Table 85. Data storage in YCbCr progressive video format Byte address 31:24 23:16 15:8 Y n + 1 Cr n Cb n Y n + 3 Cr n + 2 Y n + 2 Cb n + 2 15.7 DCMI interrupts Five interrupts are generated.
  • Page 468 Digital camera interface (DCMI) RM0090 Bits 11:10 EDM[1:0]: Extended data mode 00: Interface captures 8-bit data on every pixel clock 01: Interface captures 10-bit data on every pixel clock 10: Interface captures 12-bit data on every pixel clock 11: Interface captures 14-bit data on every pixel clock Bits 9:8 FCRC[1:0]: Frame capture rate control These bits define the frequency of frame capture.
  • Page 469 RM0090 Digital camera interface (DCMI) Bit 1 CM: Capture mode 0: Continuous grab mode - The received data are transferred into the destination memory through the DMA. The buffer location and mode (linear or circular buffer) is controlled through the system DMA. 1: Snapshot mode (single frame) - Once activated, the interface waits for the start of frame and then transfers a single frame through the DMA.
  • Page 470 Digital camera interface (DCMI) RM0090 15.8.2 DCMI status register (DCMI_SR) Address offset: 0x04 Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 Reserved Bits 31:3 Reserved, must be kept at reset value.
  • Page 471 RM0090 Digital camera interface (DCMI) 15.8.3 DCMI raw interrupt status register (DCMI_RIS) Address offset: 0x08 Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 DCMI_RIS gives the raw interrupt status and is accessible in read only.
  • Page 472 Digital camera interface (DCMI) RM0090 15.8.4 DCMI interrupt enable register (DCMI_IER) Address offset: 0x0C Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 Reserved rw rw rw rw rw The DCMI_IER register is used to enable interrupts.
  • Page 473 RM0090 Digital camera interface (DCMI) 15.8.5 DCMI masked interrupt status register (DCMI_MIS) This DCMI_MIS register is a read-only register. When read, it returns the current masked status value (depending on the value in DCMI_IER) of the corresponding interrupt. A bit in this register is set if the corresponding enable bit in DCMI_IER is set and the corresponding bit in DCMI_RIS is set.
  • Page 474 Digital camera interface (DCMI) RM0090 15.8.6 DCMI interrupt clear register (DCMI_ICR) Address offset: 0x14 Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 Reserved w w w w w The DCMI_ICR register is write-only.
  • Page 475 RM0090 Digital camera interface (DCMI) 15.8.7 DCMI embedded synchronization code register (DCMI_ESCR) Address offset: 0x18 Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 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 Bits 31:24 FEC: Frame end delimiter code This byte specifies the code of the frame end delimiter.
  • Page 476 Digital camera interface (DCMI) RM0090 15.8.8 DCMI embedded synchronization unmask register (DCMI_ESUR) Address offset: 0x1C Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 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 Bits 31:24 FEU: Frame end delimiter unmask This byte specifies the mask to be applied to the code of the frame end delimiter.
  • Page 477 RM0090 Digital camera interface (DCMI) 15.8.9 DCMI crop window start (DCMI_CWSTRT) Address offset: 0x20 Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 VST[12:0 HOFFCNT[13:0] Reserv...
  • Page 478: Table 87. Dcmi Register Map And Reset Values

    Digital camera interface (DCMI) RM0090 15.8.11 DCMI data register (DCMI_DR) Address offset: 0x28 Reset value: 0x0000 0x0000 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 Byte3 Byte2 Byte1 Byte0...
  • Page 479 RM0090 Digital camera interface (DCMI) Table 87. DCMI register map and reset values (continued) Offset Register DCMI_ICR 0x14 Reserved Reset value DCMI_ESCR 0x18 Reset value DCMI_ESUR 0x1C Reset value DCMI_CWSTR VST[12:0 HOFFCNT[13:0] Reserve 0x20 Reset value DCMI_CWSIZ VLINE13:0] CAPCNT[13:0] 0x24 Reset value Byte3 Byte2...
  • Page 480 LCD-TFT controller (LTDC) RM0090 LCD-TFT controller (LTDC) This section applies only to STM32F429xx/439xx devices. 16.1 Introduction The LCD-TFT (Liquid Crystal Display - Thin Film Transistor) display controller provides a parallel digital RGB (Red, Green, Blue) and signals for horizontal, vertical synchronisation, Pixel Clock and Data Enable as output to interface directly to a variety of LCD and TFT panels.
  • Page 481: Figure 81. Ltdc Block Diagram

    RM0090 LCD-TFT controller (LTDC) 16.3 LTDC functional description 16.3.1 LTDC block diagram The block diagram of the LTDC is shown in Figure 81: LTDC block diagram. Figure 81. LTDC block diagram Pixel clock domain Layer1 LCD_HSYNC FIFO LCD_VSYNC Dithering Blending unit interface unit...
  • Page 482: Table 88. Ltdc Registers Versus Clock Domain

    LCD-TFT controller (LTDC) RM0090 Table 88. LTDC registers versus clock domain LTDC registers Clock domain LTDC_LxCR LTDC_LxCFBAR HCLK LTDC_LxCFBLR LTDC_LxCFBLNR LTDC_SRCR LTDC_IER PCLK2 LTDC_ISR LTDC_ICR LTDC_SSCR LTDC_BPCR LTDC_AWCR LTDC_TWCR LTDC_GCR LTDC_BCCR LTDC_LIPCR LTDC_CPSR LTDC_CDSR Pixel Clock (LCD_CLK) LTDC_LxWHPCR LTDC_LxWVPCR LTDC_LxCKCR LTDC_LxPFCR LTDC_LxCACR LTDC_LxDCCR...
  • Page 483: Table 89. Lcd-Tft Pins And Signal Interface

    RM0090 LCD-TFT controller (LTDC) 16.3.3 LCD-TFT pins and signal interface The Table below summarizes the LTDC signal interface: Table 89. LCD-TFT pins and signal interface LCD-TFT Description signals LCD_CLK Clock Output LCD_HSYNC Horizontal Synchronization LCD_VSYNC Vertical Synchronization LCD_DE Not Data Enable LCD_R[7:0] Data: 8-bit Red data LCD_G[7:0]...
  • Page 484: Figure 82. Lcd-Tft Synchronous Timings

    LCD-TFT controller (LTDC) RM0090 Figure 82. LCD-TFT Synchronous timings Total width Active width VSYNC width Data1, Line1 Active display area Active height Data(n), Line(n) MSv19674V1 Note: The HBP and HFP are respectively the Horizontal back porch and front porch period. The VBP and the VFP are respectively the Vertical back porch and front porch period.
  • Page 485 RM0090 LCD-TFT controller (LTDC) When the LTDC is disabled, the timing generator block is reset to X=Total Width - 1, Y=Total Height - 1 and held the last pixel before the vertical synchronization phase and the FIFO are flushed. Therefore only blanking data is output continuously. Example of Synchronous timings configuration TFT-LCD timings (should be extracted from Panel datasheet): •...
  • Page 486 LCD-TFT controller (LTDC) RM0090 Reload Shadow registers Some configuration registers are shadowed. The shadow registers values can be reloaded immediately to the active registers when writing to these registers or at the beginning of the vertical blanking period following the configuration in the LTDC_SRCR register. If the immediate reload configuration is selected, the reload should be only activated when all new registers have been written.
  • Page 487: Table 90. Pixel Data Mapping Versus Color Format

    RM0090 LCD-TFT controller (LTDC) Figure 83. Layer window programmable parameters: Active data area WVSTPOS bits in LTDC_LxWVPCR WVSPPOS bits in WHSTPOS bits in LTDC_LxWVPCR LTDC_LxWHPCR Window WHSPPOS bits in LTDC_LxWHPCR MSv19676V3 Pixel input Format The programmable pixel format is used for the data stored in the frame buffer of a layer. Up to 8 input pixel formats can be configured for every layer through the LTDC_LxPFCR register The pixel data is read from the frame buffer and then transformed to the internal 8888...
  • Page 488 LCD-TFT controller (LTDC) RM0090 Table 90. Pixel Data mapping versus Color Format (continued) ARGB8888 [4:0] G [5:3] [2:0] B [4:0] [4:0] G [5:3] [2:0] B [4:0] ARGB1555 [0]R [4:0] [2:0] B [4:0] [0] R [4:0] G [4:3] [2:0] B [4:0] [4:3] [0]R [4:0]...
  • Page 489 RM0090 LCD-TFT controller (LTDC) The R, G and B values and their own respective address are programmed through the LTDC_LxCLUTWR register. • In case of L8 and AL88 input pixel format, the CLUT has to be loaded by 256 colors. The address of each color is configured in the CLUTADD bits in the LTDC_LxCLUTWR register.
  • Page 490: Figure 84. Blending Two Layers With Background

    LCD-TFT controller (LTDC) RM0090 Figure 84. Blending two layers with background Layer 2 Layer 1 Layer 2 Layer 2 + Layer 1 + BG Layer 1 + BG MS19677V1 Default color Every layer can have a default color in the format ARGB which is used outside the defined layer window or when a layer is disabled.
  • Page 491: Table 91. Ltdc Interrupt Requests

    RM0090 LCD-TFT controller (LTDC) Figure 85. Interrupt events Line LTDC global interrupt Register reload FIFO underrun LTDC global error interrupt Transfer error MS19678V1 Table 91. LTDC interrupt requests Interrupt event Event flag Enable Control bit Line Register Reload RRIF RRIEN FIFO Underrun FUDERRIF FUDERRIE...
  • Page 492 LCD-TFT controller (LTDC) RM0090 16.6 LTDC programming procedure • Enable the LTDC clock in the RCC register • Configure the required Pixel clock following the panel datasheet • Configure the Synchronous timings: VSYNC, HSYNC, Vertical and Horizontal back porch, active data area and the front porch timings following the panel datasheet as described in the Section 16.4.1: LTDC Global configuration parameters •...
  • Page 493 RM0090 LCD-TFT controller (LTDC) 16.7 LTDC registers 16.7.1 LTDC Synchronization Size Configuration Register (LTDC_SSCR) This register defines the number of Horizontal Synchronization pixels minus 1 and the number of Vertical Synchronization lines minus 1. Refer to Figure 82 Section 16.4: LTDC programmable parameters for an example of configuration.
  • Page 494 LCD-TFT controller (LTDC) RM0090 Bits 31:28 Reserved, must be kept at reset value Bits 27:16 AHBP[11:0]: Accumulated Horizontal back porch (in units of pixel clock period) These bits define the Accumulated Horizontal back porch width which includes the Horizontal Synchronization and Horizontal back porch pixels minus 1. The Horizontal back porch is the period between Horizontal Synchronization going inactive and the start of the active display part of the next scan line.
  • Page 495 RM0090 LCD-TFT controller (LTDC) 16.7.4 LTDC Total Width Configuration Register (LTDC_TWCR) This register defines the accumulated number of Horizontal Synchronization, back porch, Active and front porch pixels minus 1 (HSYNC Width + HBP + Active Width + HFP - 1) and the accumulated number of Vertical Synchronization, back porch lines, Active and Front lines minus 1 (VSYNC Height+ BVBP + Active Height + VFP - 1).
  • Page 496 LCD-TFT controller (LTDC) RM0090 Bit 31 HSPOL: Horizontal Synchronization Polarity This bit is set and cleared by software. 0: Horizontal Synchronization polarity is active low 1: Horizontal Synchronization polarity is active high Bit 30 VSPOL: Vertical Synchronization Polarity This bit is set and cleared by software. 0: Vertical Synchronization is active low 1: Vertical Synchronization is active high Bit 29 DEPOL: Data Enable Polarity...
  • Page 497 RM0090 LCD-TFT controller (LTDC) 16.7.6 LTDC Shadow Reload Configuration Register (LTDC_SRCR) This register allows to reload either immediately or during the vertical blanking period, the shadow registers values to the active registers. The shadow registers are all Layer1 and Layer2 registers except the LTDC_L1CLUTWR and the LTDC_L2CLUTWR. Address offset: 0x24 Reset value: 0x0000 0000 Reserved...
  • Page 498 LCD-TFT controller (LTDC) RM0090 Bits 31:24 Reserved, must be kept at reset value Bits 23:16 BCRED[7:0]: Background Color Red value These bits configure the background red value Bits 15:8 BCGREEN[7:0]: Background Color Green value These bits configure the background green value Bits 7:0 BCBLUE[7:0]: Background Color Blue value These bits configure the background blue value 16.7.8...
  • Page 499 RM0090 LCD-TFT controller (LTDC) 16.7.9 LTDC Interrupt Status Register (LTDC_ISR) This register returns the interrupt status flag Address offset: 0x38 Reset value: 0x0000 0000 Reserved RRIF TERRIF FUIF Reserved Bits 31:24 Reserved, must be kept at reset value Bit 3 RRIF: Register Reload Interrupt Flag 0: No Register Reload interrupt generated 1: Register Reload interrupt generated when a vertical blanking reload occurs (and the first line after the active area is reached)
  • Page 500 LCD-TFT controller (LTDC) RM0090 Bits 31:24 Reserved, must be kept at reset value Bit 3 CRRIF: Clears Register Reload Interrupt Flag 0: No effect 1: Clears the RRIF flag in the LTDC_ISR register Bit 2 CTERRIF: Clears the Transfer Error Interrupt Flag 0: No effect 1: Clears the TERRIF flag in the LTDC_ISR register.
  • Page 501 RM0090 LCD-TFT controller (LTDC) Bits 31:16: CXPOS[15:0]: Current X Position These bits return the current X position Bits 15:0 CYPOS[15:0]: Current Y Position These bits return the current Y position 16.7.13 LTDC Current Display Status Register (LTDC_CDSR) This register returns the status of the current display phase which is controlled by the HSYNC, VSYNC, and Horizontal/Vertical DE signals.
  • Page 502 LCD-TFT controller (LTDC) RM0090 16.7.14 LTDC Layerx Control Register (LTDC_LxCR) (where x=1..2) Address offset: 0x84 + 0x80 x (Layerx -1), Layerx = 1 or 2 Reset value: 0x0000 0000 Reserved CLUTEN COLKEN Reserved Reserved Bits 31:5 Reserved, must be kept at reset value Bit 4 CLUTEN: Color Look-Up Table Enable This bit is set and cleared by software.
  • Page 503 RM0090 LCD-TFT controller (LTDC) 16.7.15 LTDC Layerx Window Horizontal Position Configuration Register (LTDC_LxWHPCR) (where x=1..2) This register defines the Horizontal Position (first and last pixel) of the layer 1 or 2 window. The first visible pixel of a line is the programmed value of AHBP[10:0] bits + 1 in the LTDC_BPCR register.
  • Page 504 LCD-TFT controller (LTDC) RM0090 16.7.16 LTDC Layerx Window Vertical Position Configuration Register (LTDC_LxWVPCR) (where x=1..2) This register defines the vertical position (first and last line) of the layer1 or 2 window. The first visible line of a frame is the programmed value of AVBP[10:0] bits + 1 in the register LTDC_BPCR register.
  • Page 505 RM0090 LCD-TFT controller (LTDC) 16.7.17 LTDC Layerx Color Keying Configuration Register (LTDC_LxCKCR) (where x=1..2) This register defines the color key value (RGB), which is used by the Color Keying. Address offset: 0x90 + 0x80 x (Layerx -1), Layerx = 1 or 2 Reset value: 0x0000 0000 CKRED[7:0] Reserved...
  • Page 506 LCD-TFT controller (LTDC) RM0090 Bits 31:3 Reserved, must be kept at reset value Bits 2:0 PF[2:0]: Pixel Format These bits configures the Pixel format 000: ARGB8888 001: RGB888 010: RGB565 011: ARGB1555 100: ARGB4444 101: L8 (8-Bit Luminance) 110: AL44 (4-Bit Alpha, 4-Bit Luminance) 111: AL88 (8-Bit Alpha, 8-Bit Luminance) 16.7.19 LTDC Layerx Constant Alpha Configuration Register (LTDC_LxCACR)
  • Page 507 RM0090 LCD-TFT controller (LTDC) DCALPHA[7:0] DCRED[7:0] DCGREEN[7:0] DCBLUE[7:0] Bits 31:24 DCALPHA[7:0]: Default Color Alpha These bits configure the default alpha value Bits 23:16 DCRED[7:0]: Default Color Red These bits configure the default red value Bits 15:8 DCGREEN[7:0]: Default Color Green These bits configure the default green value Bits 7:0 DCBLUE[7:0]: Default Color Blue These bits configure the default blue value...
  • Page 508 LCD-TFT controller (LTDC) RM0090 16.7.21 LTDC Layerx Blending Factors Configuration Register (LTDC_LxBFCR) (where x=1..2) This register defines the blending factors F1 and F2. The general blending formula is: BC = BF1 x C + BF2 x Cs • BC = Blended color •...
  • Page 509 RM0090 LCD-TFT controller (LTDC) Note: The Constant Alpha value, is the programmed value in the LxCACR register divided by 255 by hardware. Example: Only layer1 is enabled, BF1 configured to Constant Alpha BF2 configured to Constant Alpha Constant Alpha: The Constant Alpha programmed in the LxCACR register is 240 (0xF0). Thus, the Constant Alpha value is 240/255 = 0.94 C: Current Layer Color is 128 Cs: Background color is 48...
  • Page 510 LCD-TFT controller (LTDC) RM0090 Bits 31:29 Reserved, must be kept at reset valuer Bits 28:16 CFBP[12:0]: Color Frame Buffer Pitch in bytes These bits define the pitch which is the increment from the start of one line of pixels to the start of the next line in bytes.
  • Page 511 RM0090 LCD-TFT controller (LTDC) 16.7.25 LTDC Layerx CLUT Write Register (LTDC_LxCLUTWR) (where x=1..2) This register defines the CLUT address and the RGB value. Address offset: 0xC4 + 0x80 x (Layerx -1), Layerx = 1 or 2 Reset value: 0x0000 0000 CLUTADD[7:0] RED[7:0] GREEN[7:0]...
  • Page 512: Table 92. Ltdc Register Map And Reset Values

    LCD-TFT controller (LTDC) RM0090 16.7.26 LTDC register map The following table summarizes the LTDC registers. Refer to the register boundary addresses table for the LTDC register base address. Table 92. LTDC register map and reset values Offset Register LTDC_SSCR HSW[9:0] VSH[10:0] 0x0008 Reserved...
  • Page 513 RM0090 LCD-TFT controller (LTDC) Table 92. LTDC register map and reset values (continued) Offset Register LTDC_L1WVPCR WVSPPOS[10:0] WVSTPOS[10:0] 0x008C Reserved Reserved Reset value LTDC_L1CKCR CKRED[7:0] CKGREEN[7:0] CKBLUE[7:0] 0x0090 Reserved Reset value LTDC_L1PFCR PF[2:0] 0x0094 Reserved Reset value LTDC_L1CACR CONSTA[7:0] 0x0098 Reserved Reset value LTDC_L1DCCR...
  • Page 514 LCD-TFT controller (LTDC) RM0090 Table 92. LTDC register map and reset values (continued) Offset Register LTDC_L2CFBLNR CFBLNBR[10:0] 0x0134 Reserved Reset value LTDC_L2CLUTWR CLUTADD[7:0] RED[7:0] GREEN[7:0] BLUE[7:0] 0x0144 Reset value 514/1749 RM0090 Rev 18...
  • Page 515 RM0090 Advanced-control timers (TIM1 and TIM8) Advanced-control timers (TIM1 and TIM8) This section applies to the whole STM32F4xx family, unless otherwise specified. 17.1 TIM1 and TIM8 introduction The advanced-control timers (TIM1 and TIM8) consist of a 16-bit auto-reload counter driven by a programmable prescaler.
  • Page 516 Advanced-control timers (TIM1 and TIM8) RM0090 17.2 TIM1 and TIM8 main features TIM1 and TIM8 timer features include: • 16-bit up, down, up/down auto-reload counter. • 16-bit programmable prescaler allowing dividing (also “on the fly”) the counter clock frequency either by any factor between 1 and 65536. •...
  • Page 517: Figure 86. Advanced-Control Timer Block Diagram

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 86. Advanced-control timer block diagram Internal clock (CK_INT) CK_TIM18 from RCC Trigger Polarity selection, ETRF controller Edge detector and Prescaler ETRP TRGO To other timers To DAC and ADC Input filter ITR0 ITR1 TRGI Slave mode ITR2...
  • Page 518 Advanced-control timers (TIM1 and TIM8) RM0090 17.3 TIM1 and TIM8 functional description 17.3.1 Time-base unit The main block of the programmable advanced-control timer is a 16-bit counter with its related auto-reload register. The counter can count up, down or both up and down. The counter clock can be divided by a prescaler.
  • Page 519: Figure 87. Counter Timing Diagram With Prescaler Division Change From 1 To 2

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 87. Counter timing diagram with prescaler division change from 1 to 2 CK_PSC Timerclock = CK_CNT FA FB Counter register Update event (UEV) Prescaler control register Write a new value in TIMx_PSC Prescaler buffer Prescaler counter MS31076V2 Figure 88.
  • Page 520: Figure 89. Counter Timing Diagram, Internal Clock Divided By 1

    Advanced-control timers (TIM1 and TIM8) RM0090 17.3.2 Counter modes Upcounting mode In upcounting mode, the counter counts from 0 to the auto-reload value (content of the TIMx_ARR register), then restarts from 0 and generates a counter overflow event. If the repetition counter is used, the update event (UEV) is generated after upcounting is repeated for the number of times programmed in the repetition counter register plus one (TIMx_RCR+1).
  • Page 521: Figure 90. Counter Timing Diagram, Internal Clock Divided By 2

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 90. Counter timing diagram, internal clock divided by 2 CK_PSC CNT_EN Timerclock = CK_CNT Counter register 0034 0035 0036 0000 0001 0002 0003 Counter overflow Update event (UEV) Update interrupt flag (UIF) MS31079V3 Figure 91.
  • Page 522: Figure 93. Counter Timing Diagram, Update Event When Arpe=0 (Timx_Arr Not Preloaded)

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 93. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not preloaded) CK_PSC Timerclock = CK_CNT Counter register Counter overflow Update event (UEV) Update interrupt flag (UIF) Auto-reload preload register Write a new value in TIMx_ARR MS31082V3 Figure 94.
  • Page 523 RM0090 Advanced-control timers (TIM1 and TIM8) 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).
  • Page 524: Figure 95. Counter Timing Diagram, Internal Clock Divided By 1

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 95. Counter timing diagram, internal clock divided by 1 CK_PSC CNT_EN Timerclock = CK_CNT Counter register 01 00 34 33 32 Counter underflow (cnt_udf) Update event (UEV) Update interrupt flag (UIF) MS31184V1 Figure 96. Counter timing diagram, internal clock divided by 2 CK_PSC CNT_EN Timerclock = CK_CNT...
  • Page 525: Figure 97. Counter Timing Diagram, Internal Clock Divided By 4

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 97. Counter timing diagram, internal clock divided by 4 CK_PSC CNT_EN Timerclock = CK_CNT Counter register 0001 0000 0036 0035 Counter underflow Update event (UEV) Update interrupt flag (UIF) MS40510V1 Figure 98. Counter timing diagram, internal clock divided by N CK_PSC Timerclock = CK_CNT Counter register...
  • Page 526: Figure 99. Counter Timing Diagram, Update Event When Repetition Counter Is Not Used

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 99. Counter timing diagram, update event when repetition counter is not used CK_PSC Timerclock = CK_CNT 30 2F Counter register Counter underflow Update event (UEV) Update interrupt flag (UIF) Auto-reload preload register Write a new value in TIMx_ARR MS31188V1 Center-aligned mode (up/down counting) In center-aligned mode, the counter counts from 0 to the auto-reload value (content of the...
  • Page 527: Figure 100. Counter Timing Diagram, Internal Clock Divided By 1, Timx_Arr = 0X6

    RM0090 Advanced-control timers (TIM1 and TIM8) 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 •...
  • Page 528: Figure 102. Counter Timing Diagram, Internal Clock Divided By 4, Timx_Arr=0X36

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 102. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 CK_PSC CNT_EN Timerclock = CK_CNT 0034 0035 0036 0035 Counter register Counter overflow Update event (UEV) Update interrupt flag (UIF) MS31191V2 Center-aligned mode 2 or 3 is used with an UIF on overflow. Figure 103.
  • Page 529: Figure 104. Counter Timing Diagram, Update Event With Arpe=1 (Counter Underflow)

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 104. Counter timing diagram, update event with ARPE=1 (counter underflow) CK_PSC Timer clock = CK_CNT Counter register 04 03 02 03 05 06 07 Counter overflow Update event (UEV) Update interrupt flag (UIF) Auto-reload preload register Write a new value in TIMx_ARR Auto-reload active register...
  • Page 530 Advanced-control timers (TIM1 and TIM8) RM0090 The repetition counter is decremented: • At each counter overflow in upcounting mode, • At each counter underflow in downcounting mode, • At each counter overflow and at each counter underflow in center-aligned mode. Although this limits the maximum number of repetition to 128 PWM cycles, it makes it possible to update the duty cycle twice per PWM period.
  • Page 531: Figure 106. Update Rate Examples Depending On Mode And Timx_Rcr Register Settings

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 106. Update rate examples depending on mode and TIMx_RCR register settings Edge-aligned mode Counter-aligned mode Upcounting Downcounting Counter TIMx_CNT TIMx_RCR = 0 TIMx_RCR = 1 TIMx_RCR = 2 TIMx_RCR = 3 TIMx_RCR = 3 re-synchronization (by SW) (by SW)
  • Page 532: Figure 107. Control Circuit In Normal Mode, Internal Clock Divided By 1

    Advanced-control timers (TIM1 and TIM8) RM0090 17.3.4 Clock selection The counter clock can be provided by the following clock sources: • Internal clock (CK_INT) • External clock mode1: external input pin • External clock mode2: external trigger input ETR • Internal trigger inputs (ITRx): using one timer as prescaler for another timer, for example, the user can configure Timer 1 to act as a prescaler for Timer 2.
  • Page 533: Figure 108. Ti2 External Clock Connection Example

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 108. TI2 external clock connection example TIMx_SMCR TS[2:0] TI2F TI1F Encoder ITRx mode TI1_ED TRGI External clock TI1FP1 CK_PSC mode 1 TI2F_Rising Edge TI2FP2 External clock ETRF Filter detector mode 2 ETRF TI2F_Falling CK_INT Internal clock mode...
  • Page 534: Figure 109. Control Circuit In External Clock Mode 1

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 109. Control circuit in external clock mode 1 CNT_EN Counter clock = CK_CNT = CK_PSC Counter register Write TIF=0 MS31087V2 External clock source mode 2 This mode is selected by writing ECE=1 in the TIMx_SMCR register. The counter can count at each rising or falling edge on the external trigger input ETR.
  • Page 535: Figure 111. Control Circuit In External Clock Mode 2

    RM0090 Advanced-control timers (TIM1 and TIM8) For example, to configure the upcounter to count each 2 rising edges on ETR, use the following procedure: As no filter is needed in this example, write ETF[3:0]=0000 in the TIMx_SMCR register. Set the prescaler by writing ETPS[1:0]=01 in the TIMx_SMCR register Select rising edge detection on the ETR pin by writing ETP=0 in the TIMx_SMCR register Enable external clock mode 2 by writing ECE=1 in the TIMx_SMCR register.
  • Page 536: Figure 112. Capture/Compare Channel (Example: Channel 1 Input Stage)

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 112. Capture/compare channel (example: channel 1 input stage) TI1F_ED To the slave mode controller TI1F_Rising TI1FP1 Filter TI1F Edge TI1F_Falling downcounter detector IC1PS Divider TI2FP1 /1, /2, /4, /8 CC1P/CC1NP ICF[3:0] TIMx_CCER TIMx_CCMR1 (from slave mode controller) TI2F_Rising...
  • Page 537: Figure 114. Output Stage Of Capture/Compare Channel (Channel 1 To 3)

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 114. Output stage of capture/compare channel (channel 1 to 3) To the master mode controller ETRF Output enable ‘0’ circuit OC1REFC OC1REF OC1_DT CC1P CNT>CCR1 Output Output Dead-time TIM1_CCER mode CNT=CCR1 selector generator controller OC1N_DT Output...
  • Page 538 Advanced-control timers (TIM1 and TIM8) RM0090 17.3.6 Input capture mode In Input capture mode, the Capture/Compare Registers (TIMx_CCRx) are used to latch the value of the counter after a transition detected by the corresponding ICx signal. When a capture occurs, the corresponding CCXIF flag (TIMx_SR register) is set and an interrupt or a DMA request can be sent if they are enabled.
  • Page 539: Figure 116. Pwm Input Mode Timing

    RM0090 Advanced-control timers (TIM1 and TIM8) 17.3.7 PWM input mode This mode is a particular case of input capture mode. The procedure is the same except: • Two ICx signals are mapped on the same TIx input. • These 2 ICx signals are active on edges with opposite polarity. •...
  • Page 540 Advanced-control timers (TIM1 and TIM8) RM0090 forced high (OCxREF is always active high) and OCx get opposite value to CCxP polarity bit. For example: CCxP=0 (OCx active high) => OCx is forced to high level. The OCxREF signal can be forced low by writing the OCxM bits to 100 in the TIMx_CCMRx register.
  • Page 541: Figure 117. Output Compare Mode, Toggle On Oc1

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 117. Output compare mode, toggle on OC1. Write B201h in the CC1R register TIM1_CNT 0039 003A 003B B200 B201 TIM1_CCR1 003A B201 OC1REF= OC1 Match detected on CCR1 Interrupt generated if enabled MS31092V2 17.3.10 PWM mode Pulse Width Modulation mode allows generating a signal with a frequency determined by...
  • Page 542: Figure 118. Edge-Aligned Pwm Waveforms (Arr=8)

    Advanced-control timers (TIM1 and TIM8) RM0090 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 118 shows some edge-aligned PWM waveforms in an example where TIMx_ARR=8.
  • Page 543: Figure 119. Center-Aligned Pwm Waveforms (Arr=8)

    RM0090 Advanced-control timers (TIM1 and TIM8) TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to Center-aligned mode (up/down counting). Figure 119 shows some center-aligned PWM waveforms in an example where: • TIMx_ARR=8, • PWM mode is the PWM mode 1, •...
  • Page 544 Advanced-control timers (TIM1 and TIM8) RM0090 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.
  • Page 545: Figure 120. Complementary Output With Dead-Time Insertion

    RM0090 Advanced-control timers (TIM1 and TIM8) Figure 120. Complementary output with dead-time insertion. OCxREF delay OCxN delay MS31095V1 Figure 121. Dead-time waveforms with delay greater than the negative pulse. OCxREF delay OCxN MS31096V1 Figure 122. Dead-time waveforms with delay greater than the positive pulse. OCxREF OCxN delay...
  • Page 546 Advanced-control timers (TIM1 and TIM8) RM0090 have both outputs at inactive level or both outputs active and complementary with dead-time. Note: When only OCxN is enabled (CCxE=0, CCxNE=1), it is not complemented and becomes active as soon as OCxREF is high. For example, if CCxNP=0 then OCxN=OCxRef. On the other hand, when both OCx and OCxN are enabled (CCxE=CCxNE=1) OCx becomes active when OCxREF is high whereas OCxN is complemented and becomes active when OCxREF is low.
  • Page 547 RM0090 Advanced-control timers (TIM1 and TIM8) 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.
  • Page 548: Figure 123. Output Behavior In Response To A Break

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 123 shows an example of behavior of the outputs in response to a break. Figure 123. Output behavior in response to a break. BREAK (MOE OCxREF (OCxN not implemented, CCxP=0, OISx=1) (OCxN not implemented, CCxP=0, OISx=0) (OCxN not implemented, CCxP=1, OISx=1) (OCxN not implemented, CCxP=1, OISx=0) delay...
  • Page 549: Figure 124. Clearing Timx Ocxref

    RM0090 Advanced-control timers (TIM1 and TIM8) 17.3.13 Clearing the OCxREF signal on an external event The OCxREF signal for a given channel can be driven Low by applying a High level to the ETRF input (OCxCE enable bit of the corresponding TIMx_CCMRx register set to ‘1’). The OCxREF signal remains Low until the next update event, UEV, occurs.
  • Page 550: Figure 125. 6-Step Generation, Com Example (Ossr=1)

    Advanced-control timers (TIM1 and TIM8) RM0090 17.3.14 6-step PWM generation When complementary outputs are used on a channel, preload bits are available on the OCxM, CCxE and CCxNE bits. The preload bits are transferred to the shadow bits at the COM commutation event.
  • Page 551: Figure 126. Example Of One Pulse Mode

    RM0090 Advanced-control timers (TIM1 and TIM8) 17.3.15 One-pulse mode One-pulse mode (OPM) is a particular case of the previous modes. It allows the counter to be started in response to a stimulus and to generate a pulse with a programmable length after a programmable delay.
  • Page 552 Advanced-control timers (TIM1 and TIM8) RM0090 The OPM waveform is defined by writing the compare registers (taking into account the clock frequency and the counter prescaler). • The t is defined by the value written in the TIMx_CCR1 register. DELAY •...
  • Page 553: Table 93. Counting Direction Versus Encoder Signals

    RM0090 Advanced-control timers (TIM1 and TIM8) TIMx_ARR register (0 to ARR or ARR down to 0 depending on the direction). So user must 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.
  • Page 554: Figure 127. Example Of Counter Operation In Encoder Interface Mode

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 127. Example of counter operation in encoder interface mode. forward jitter backward jitter forward Counter down MS33107V1 Figure 128 gives an example of counter behavior when TI1FP1 polarity is inverted (same configuration as above except CC1P=’1’). Figure 128.
  • Page 555 RM0090 Advanced-control timers (TIM1 and TIM8) 17.3.17 Timer input XOR function The TI1S bit in the TIMx_CR2 register, allows the input filter of channel 1 to be connected to the output of a XOR gate, combining the three input pins TIMx_CH1, TIMx_CH2 and TIMx_CH3.
  • Page 556: Figure 129. Example Of Hall Sensor Interface

    Advanced-control timers (TIM1 and TIM8) RM0090 Figure 129 describes this example. Figure 129. Example of Hall sensor interface TIH1 TIH2 TIH3 Counter (CNT) (CCR2) CCR1 C7A3 C7A8 C794 C7A5 C7AB C796 TRGO=OC2REF OC1N OC2N OC3N Write CCxE, CCxNE and OCxM for next step ai17335b 556/1749 RM0090 Rev 18...
  • Page 557: Figure 130. Control Circuit In Reset Mode

    RM0090 Advanced-control timers (TIM1 and TIM8) 17.3.19 TIMx and external trigger synchronization The TIMx timer can be synchronized with an external trigger in several modes: Reset mode, Gated mode and Trigger mode. Slave mode: Reset mode The counter and its prescaler can be reinitialized in response to an event on a trigger input. Moreover, if the URS bit from the TIMx_CR1 register is low, an update event UEV is generated.
  • Page 558: Figure 131. Control Circuit In Gated Mode

    Advanced-control timers (TIM1 and TIM8) RM0090 Slave mode: Gated mode The counter can be enabled depending on the level of a selected input. 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).
  • Page 559: Figure 132. Control Circuit In Trigger Mode

    RM0090 Advanced-control timers (TIM1 and TIM8) Slave mode: Trigger mode The counter can start in response to an event on a selected input. In the following example, the upcounter starts in response to a rising edge on TI2 input: • Configure the channel 2 to detect rising edges on TI2.
  • Page 560: Figure 133. Control Circuit In External Clock Mode 2 + Trigger Mode

    Advanced-control timers (TIM1 and TIM8) RM0090 – CC1P=0 and CC1NP=’0’ in TIMx_CCER register to validate the polarity (and detect rising edge only). Configure the timer in trigger mode by writing SMS=110 in TIMx_SMCR register. Select TI1 as the input source by writing TS=101 in TIMx_SMCR register. A rising edge on TI1 enables the counter and sets the TIF flag.
  • Page 561 RM0090 Advanced-control timers (TIM1 and TIM8) 17.4 TIM1 and TIM8 registers Refer to Section 1.1 for a list of abbreviations used in register descriptions. The peripheral registers must be written by half-words (16 bits) or words (32 bits). Read accesses can be done by bytes (8 bits), half-word (16 bits) or words (32 bits). 17.4.1 TIM1 and TIM8 control register 1 (TIMx_CR1) Address offset: 0x00...
  • Page 562 Advanced-control timers (TIM1 and TIM8) RM0090 Bit 2 URS: Update request source This bit is set and cleared by software to select the UEV event sources. 0: Any of the following events generate an update interrupt or DMA request if enabled. These events can be: –...
  • Page 563 RM0090 Advanced-control timers (TIM1 and TIM8) Bit 9 OIS1N: Output Idle state 1 (OC1N output) 0: OC1N=0 after a dead-time when MOE=0 1: OC1N=1 after a dead-time when MOE=0 Note: This bit can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIMx_BDTR register).
  • Page 564 Advanced-control timers (TIM1 and TIM8) RM0090 Bit 2 CCUS: Capture/compare control update selection 0: When capture/compare control bits are preloaded (CCPC=1), they are updated by setting the COMG bit only 1: When capture/compare control bits are preloaded (CCPC=1), they are updated by setting the COMG bit or when an rising edge occurs on TRGI Note: This bit acts only on channels that have a complementary output.
  • Page 565 RM0090 Advanced-control timers (TIM1 and TIM8) 17.4.3 TIM1 and TIM8 slave mode control register (TIMx_SMCR) Address offset: 0x08 Reset value: 0x0000 ETPS[1:0] ETF[3:0] TS[2:0] Res. SMS[2:0] Res. Bit 15 ETP: External trigger polarity This bit selects whether ETR or ETR is used for trigger operations 0: ETR is non-inverted, active at high level or rising edge.
  • Page 566 Advanced-control timers (TIM1 and TIM8) RM0090 Bits 11:8 ETF[3:0]: External trigger filter This bit-field then defines the frequency used to sample ETRP signal and the length of the digital filter applied to ETRP. The digital filter is made of an event counter in which N consecutive events are needed to validate a transition on the output: 0000: No filter, sampling is done at f 0001: f...
  • Page 567: Table 94. Timx Internal Trigger Connection

    RM0090 Advanced-control timers (TIM1 and TIM8) Bits 2:0 SMS: Slave mode selection When external signals are selected the active edge of the trigger signal (TRGI) is linked to the polarity selected on the external input (see Input Control register and Control Register description.
  • Page 568 Advanced-control timers (TIM1 and TIM8) RM0090 Bit 12 CC4DE: Capture/Compare 4 DMA request enable 0: CC4 DMA request disabled 1: CC4 DMA request enabled Bit 11 CC3DE: Capture/Compare 3 DMA request enable 0: CC3 DMA request disabled 1: CC3 DMA request enabled Bit 10 CC2DE: Capture/Compare 2 DMA request enable 0: CC2 DMA request disabled 1: CC2 DMA request enabled...
  • Page 569 RM0090 Advanced-control timers (TIM1 and TIM8) 17.4.5 TIM1 and TIM8 status register (TIMx_SR) Address offset: 0x10 Reset value: 0x0000 CC4OF CC3OF CC2OF CC1OF Res. COMIF CC4IF CC3IF CC2IF CC1IF Reserved rc_w0 rc_w0 rc_w0 rc_w0 Res. rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0...
  • Page 570 Advanced-control timers (TIM1 and TIM8) RM0090 Bit 2 CC2IF: Capture/Compare 2 interrupt flag refer to CC1IF description Bit 1 CC1IF: Capture/Compare 1 interrupt flag If channel CC1 is configured as output: This flag is set by hardware when the counter matches the compare value, with some exception in center-aligned mode (refer to the CMS bits in the TIMx_CR1 register description).
  • Page 571 RM0090 Advanced-control timers (TIM1 and TIM8) Bit 5 COMG: Capture/Compare control update generation This bit can be set by software, it is automatically cleared by hardware 0: No action 1: When CCPC bit is set, it allows to update CCxE, CCxNE and OCxM bits Note: This bit acts only on channels having a complementary output.
  • Page 572 Advanced-control timers (TIM1 and TIM8) RM0090 17.4.7 TIM1 and TIM8 capture/compare mode register 1 (TIMx_CCMR1) Address offset: 0x18 Reset value: 0x0000 The channels can be used in input (capture mode) or in output (compare mode). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function in input and in output mode.
  • Page 573 RM0090 Advanced-control timers (TIM1 and TIM8) Bits 6:4 OC1M: Output Compare 1 mode These bits define the behavior of the output reference signal OC1REF from which OC1 and OC1N are derived. OC1REF is active high whereas OC1 and OC1N active level depends on CC1P and CC1NP bits.
  • Page 574 Advanced-control timers (TIM1 and TIM8) RM0090 Bits 1:0 CC1S: Capture/Compare 1 selection This bit-field defines the direction of the channel (input/output) as well as the used input. 00: CC1 channel is configured as output 01: CC1 channel is configured as input, IC1 is mapped on TI1 10: CC1 channel is configured as input, IC1 is mapped on TI2 11: CC1 channel is configured as input, IC1 is mapped on TRC.
  • Page 575 RM0090 Advanced-control timers (TIM1 and TIM8) Bits 1:0 CC1S: Capture/Compare 1 Selection This bit-field defines the direction of the channel (input/output) as well as the used input. 00: CC1 channel is configured as output 01: CC1 channel is configured as input, IC1 is mapped on TI1 10: CC1 channel is configured as input, IC1 is mapped on TI2 11: CC1 channel is configured as input, IC1 is mapped on TRC.
  • Page 576 Advanced-control timers (TIM1 and TIM8) RM0090 Input capture mode Bits 15:12 IC4F: Input capture 4 filter Bits 11:10 IC4PSC: Input capture 4 prescaler Bits 9:8 CC4S: Capture/Compare 4 selection This bit-field defines the direction of the channel (input/output) as well as the used input. 00: CC4 channel is configured as output 01: CC4 channel is configured as input, IC4 is mapped on TI4 10: CC4 channel is configured as input, IC4 is mapped on TI3...
  • Page 577 RM0090 Advanced-control timers (TIM1 and TIM8) Bit 7 CC2NP: Capture/Compare 2 complementary output polarity refer to CC1NP description Bit 6 CC2NE: Capture/Compare 2 complementary output enable refer to CC1NE description Bit 5 CC2P: Capture/Compare 2 output polarity refer to CC1P description Bit 4 CC2E: Capture/Compare 2 output enable refer to CC1E description Bit 3 CC1NP: Capture/Compare 1 complementary output polarity...
  • Page 578 Advanced-control timers (TIM1 and TIM8) RM0090 Bit 1 CC1P: Capture/Compare 1 output polarity CC1 channel configured as output: 0: OC1 active high 1: OC1 active low CC1 channel configured as input: CC1NP/CC1P bits select the active polarity of TI1FP1 and TI2FP1 for trigger or capture operations.
  • Page 579: Table 95. Output Control Bits For Complementary Ocx And Ocxn Channels With

    RM0090 Advanced-control timers (TIM1 and TIM8) Table 95. Output control bits for complementary OCx and OCxN channels with break feature Control bits Output states OSSI OSSR CCxE CCxNE OCx output state OCxN output state Output Disabled (not driven by Output Disabled (not driven by the the timer), OCx=0, OCx_EN=0 timer), OCxN=0, OCxN_EN=0 Output Disabled (not driven by...
  • Page 580 Advanced-control timers (TIM1 and TIM8) RM0090 17.4.10 TIM1 and TIM8 counter (TIMx_CNT) Address offset: 0x24 Reset value: 0x0000 CNT[15:0] Bits 15:0 CNT[15:0]: Counter value 17.4.11 TIM1 and TIM8 prescaler (TIMx_PSC) Address offset: 0x28 Reset value: 0x0000 PSC[15:0] Bits 15:0 PSC[15:0]: Prescaler value The counter clock frequency (CK_CNT) is equal to f / (PSC[15:0] + 1).
  • Page 581 RM0090 Advanced-control timers (TIM1 and TIM8) 17.4.13 TIM1 and TIM8 repetition counter register (TIMx_RCR) Address offset: 0x30 Reset value: 0x0000 REP[7:0] Reserved Bits 15:8 Reserved, must be kept at reset value. Bits 7:0 REP[7:0]: Repetition counter value These bits allow the user to set-up the update rate of the compare registers (i.e. periodic transfers from preload to active registers) when preload registers are enable, as well as the update interrupt generation rate, if this interrupt is enable.
  • Page 582 Advanced-control timers (TIM1 and TIM8) RM0090 17.4.15 TIM1 and TIM8 capture/compare register 2 (TIMx_CCR2) Address offset: 0x38 Reset value: 0x0000 CCR2[15:0] rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro Bits 15:0 CCR2[15:0]: 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).
  • Page 583 RM0090 Advanced-control timers (TIM1 and TIM8) 17.4.17 TIM1 and TIM8 capture/compare register 4 (TIMx_CCR4) Address offset: 0x40 Reset value: 0x0000 CCR4[15:0] rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro Bits 15:0 CCR4[15:0]: Capture/Compare value If channel CC4 is configured as output: CCR4 is the value to be loaded in the actual capture/compare 4 register (preload value).
  • Page 584 Advanced-control timers (TIM1 and TIM8) RM0090 Bit 13 BKP: Break polarity 0: Break input BRK is active low 1: Break input BRK is active high Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).
  • Page 585 RM0090 Advanced-control timers (TIM1 and TIM8) Bits 7:0 DTG[7:0]: Dead-time generator setup This bit-field defines the duration of the dead-time inserted between the complementary outputs. DT correspond to this duration. DTG[7:5]=0xx => DT=DTG[7:0]x t with t DTG[7:5]=10x => DT=(64+DTG[5:0])xt with T =2xt DTG[7:5]=110 =>...
  • Page 586 Advanced-control timers (TIM1 and TIM8) RM0090 17.4.20 TIM1 and TIM8 DMA address for full transfer (TIMx_DMAR) Address offset: 0x4C Reset value: 0x0000 0000 DMAB[31:16] DMAB[15:0] Bits 31:0 DMAB[31:0]: DMA register for burst accesses A read or write operation to the DMAR register accesses the register located at the address (TIMx_CR1 address) + (DBA + DMA index) x 4 where TIMx_CR1 address is the address of the control register 1, DBA is the DMA base address configured in TIMx_DCR register, DMA index is automatically controlled by the...
  • Page 587: Table 96. Tim1 And Tim8 Register Map And Reset Values

    RM0090 Advanced-control timers (TIM1 and TIM8) 17.4.21 TIM1 and TIM8 register map TIM1 and TIM8 registers are mapped as 16-bit addressable registers as described in the table below: Table 96. TIM1 and TIM8 register map and reset values Offset Register TIMx_CR1 [1:0] [1:0]...
  • Page 588 Advanced-control timers (TIM1 and TIM8) RM0090 Table 96. TIM1 and TIM8 register map and reset values (continued) Offset Register TIMx_ARR ARR[15:0] 0x2C Reserved Reset value TIMx_RCR REP[7:0] 0x30 Reserved Reset value TIMx_CCR1 CCR1[15:0] 0x34 Reserved Reset value TIMx_CCR2 CCR2[15:0] 0x38 Reserved Reset value TIMx_CCR3...
  • Page 589 RM0090 General-purpose timers (TIM2 to TIM5) General-purpose timers (TIM2 to TIM5) This section applies to the whole STM32F4xx family, unless otherwise specified. 18.1 TIM2 to TIM5 introduction The general-purpose timers consist of a 16-bit or 32-bit auto-reload counter driven by a programmable prescaler.
  • Page 590: Figure 134. General-Purpose Timer Block Diagram

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 134. General-purpose timer block diagram Internal clock (CK_INT) TIMxCLK from RCC Trigger ETRF controller TRGO Polarity selection & edge ETRP TIMx_ETR Input filter detector & prescaler to other timers to DAC/ADC ITR0 ITR1 Slave ITR2 TRGI...
  • Page 591 RM0090 General-purpose timers (TIM2 to TIM5) 18.3 TIM2 to TIM5 functional description 18.3.1 Time-base unit The main block of the programmable timer is a 16-bit/32-bit counter with its related auto- reload register. The counter can count up. The counter clock can be divided by a prescaler. The counter, the auto-reload register and the prescaler register can be written or read by software.
  • Page 592: Figure 135. Counter Timing Diagram With Prescaler Division Change From 1 To 2

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 135. Counter timing diagram with prescaler division change from 1 to 2 CK_PSC CNT_EN Timerclock = CK_CNT Counter register F8 F9 FA FB Update event (UEV) Prescaler control register Write a new value in TIMx_PSC Prescaler buffer Prescaler counter MS35833V1...
  • Page 593: Figure 137. Counter Timing Diagram, Internal Clock Divided By 1

    RM0090 General-purpose timers (TIM2 to TIM5) 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.
  • Page 594: Figure 139. Counter Timing Diagram, Internal Clock Divided By 4

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 139. Counter timing diagram, internal clock divided by 4 CK_INT CNT_EN Timerclock = CK_CNT Counter register 0035 0036 0000 0001 Counter overflow Update event (UEV) Update interrupt flag (UIF) MSv37301V1 Figure 140. Counter timing diagram, internal clock divided by N CK_INT Timerclock = CK_CNT Counter register...
  • Page 595: Figure 141. Counter Timing Diagram, Update Event When Arpe=0 (Timx_Arr Not Preloaded)

    RM0090 General-purpose timers (TIM2 to TIM5) Figure 141. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not preloaded) CK_INT CNT_EN Timerclock = CK_CNT Counter register 32 33 34 35 36 02 03 04 05 06 07 Counter overflow Update event (UEV) Update interrupt flag (UIF) Auto-reload register Write a new value in TIMx_ARR...
  • Page 596: Figure 143. Counter Timing Diagram, Internal Clock Divided By 1

    General-purpose timers (TIM2 to TIM5) RM0090 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).
  • Page 597: Figure 144. Counter Timing Diagram, Internal Clock Divided By 2

    RM0090 General-purpose timers (TIM2 to TIM5) Figure 144. Counter timing diagram, internal clock divided by 2 CK_INT CNT_EN Timerclock = CK_CNT Counter register 0002 0001 0000 0036 0035 0034 0033 Counter underflow Update event (UEV) Update interrupt flag (UIF) MSv37306V1 Figure 145.
  • Page 598: Figure 147. Counter Timing Diagram, Update Event

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 147. Counter timing diagram, Update event CK_INT CNT_EN Timerclock = CK_CNT Counter register 04 03 02 00 36 35 34 33 32 31 30 2F Counter overflow Update event (UEV) Update interrupt flag (UIF) Auto-reload preload register Write a new value in TIMx_ARR MS37341V1...
  • Page 599: Figure 148. Counter Timing Diagram, Internal Clock Divided By 1, Timx_Arr=0X6

    RM0090 General-purpose timers (TIM2 to TIM5) 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).
  • Page 600: Figure 150. Counter Timing Diagram, Internal Clock Divided By 4, Timx_Arr=0X36

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 150. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 CK_INT CNT_EN Timerclock = CK_CNT Counter register 0034 0035 0036 0035 Counter overflow (cnt_ovf) Update event (UEV) Update interrupt flag (UIF) MS37344V1 1. Center-aligned mode 2 or 3 is used with an UIF on overflow. Figure 151.
  • Page 601: Figure 152. Counter Timing Diagram, Update Event With Arpe=1 (Counter Underflow)

    RM0090 General-purpose timers (TIM2 to TIM5) Figure 152. Counter timing diagram, Update event with ARPE=1 (counter underflow) CK_INT CNT_EN Timerclock = CK_CNT Counter register 05 04 03 02 02 03 04 05 06 07 Counter underflow Update event (UEV) Update interrupt flag (UIF) Auto-reload preload register Write a new value in TIMx_ARR Auto-reload active register...
  • Page 602: Figure 154. Control Circuit In Normal Mode, Internal Clock Divided By 1

    General-purpose timers (TIM2 to TIM5) RM0090 18.3.3 Clock selection The counter clock can be provided by the following clock sources: • Internal clock (CK_INT) • External clock mode1: external input pin (TIx) • External clock mode2: external trigger input (ETR) available on TIM2, TIM3 and TIM4 only.
  • Page 603: Figure 155. Ti2 External Clock Connection Example

    RM0090 General-purpose timers (TIM2 to TIM5) Figure 155. TI2 external clock connection example TIMx_SMCR TS[2:0] TI2F TI1F Encoder ITRx mode TI1_ED TRGI External clock TI1FP1 CK_PSC mode 1 TI2F_Rising Edge TI2FP2 External clock ETRF Filter detector mode 2 ETRF TI2F_Falling CK_INT Internal clock mode...
  • Page 604: Figure 156. Control Circuit In External Clock Mode 1

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 156. Control circuit in external clock mode 1 CNT_EN Counter clock = CK_CNT = CK_PSC Counter register Write TIF=0 MS31087V2 External clock source mode 2 This mode is selected by writing ECE=1 in the TIMx_SMCR register. The counter can count at each rising or falling edge on the external trigger input ETR.
  • Page 605: Figure 158. Control Circuit In External Clock Mode 2

    RM0090 General-purpose timers (TIM2 to TIM5) 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. Figure 158. Control circuit in external clock mode 2 CK_INT CNT_EN ETRP...
  • Page 606: Figure 160. Capture/Compare Channel 1 Main Circuit

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 160. Capture/compare channel 1 main circuit APB Bus MCU-peripheral interface write CCR1H Read CCR1H write_in_progress read_in_progress write CCR1L Capture/compare preload register Read CCR1L Output CC1S[1] compare_transfer mode capture_transfer CC1S[0] Input CC1S[1] OC1PE mode OC1PE Capture /compare shadow register CC1S[0]...
  • Page 607 RM0090 General-purpose timers (TIM2 to TIM5) 18.3.5 Input capture mode In Input capture mode, the Capture/Compare Registers (TIMx_CCRx) are used to latch the value of the counter after a transition detected by the corresponding ICx signal. When a capture occurs, the corresponding CCXIF flag (TIMx_SR register) is set and an interrupt or a DMA request can be sent if they are enabled.
  • Page 608: Figure 162. Pwm Input Mode Timing

    General-purpose timers (TIM2 to TIM5) RM0090 18.3.6 PWM input mode This mode is a particular case of input capture mode. The procedure is the same except: • Two ICx signals are mapped on the same TIx input. • These 2 ICx signals are active on edges with opposite polarity. •...
  • Page 609 RM0090 General-purpose timers (TIM2 to TIM5) 18.3.7 Forced output mode In output mode (CCxS bits = 00 in the TIMx_CCMRx register), each output compare signal (OCxREF and then OCx) can be forced to active or inactive level directly by software, independently of any comparison between the output compare register and the counter.
  • Page 610: Figure 163. Output Compare Mode, Toggle On Oc1

    General-purpose timers (TIM2 to TIM5) RM0090 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 163.
  • Page 611: Figure 164. Edge-Aligned Pwm Waveforms (Arr=8)

    RM0090 General-purpose timers (TIM2 to TIM5) The timer is able to generate PWM in edge-aligned mode or center-aligned mode depending on the CMS bits in the TIMx_CR1 register. PWM edge-aligned mode Upcounting configuration Upcounting is active when the DIR bit in the TIMx_CR1 register is low. Refer to Upcounting mode.
  • Page 612: Figure 165. Center-Aligned Pwm Waveforms (Arr=8)

    General-purpose timers (TIM2 to TIM5) RM0090 up and down depending on the CMS bits configuration. The direction bit (DIR) in the TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to Center-aligned mode (up/down counting). Figure 165 shows some center-aligned PWM waveforms in an example where: •...
  • Page 613: Figure 166. Example Of One-Pulse Mode

    RM0090 General-purpose timers (TIM2 to TIM5) 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.
  • Page 614 General-purpose timers (TIM2 to TIM5) RM0090 Let’s use TI2FP2 as trigger 1: • Map TI2FP2 on 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.
  • Page 615: Figure 167. Clearing Timx Ocxref

    RM0090 General-purpose timers (TIM2 to TIM5) The external trigger prescaler should be kept off: bits ETPS[1:0] in the TIMx_SMCR register are cleared to 00. The external clock mode 2 must be disabled: bit ECE in the TIM1_SMCR register is cleared to 0. The external trigger polarity (ETP) and the external trigger filter (ETF) can be configured according to the application’s needs.
  • Page 616: Table 97. Counting Direction Versus Encoder Signals

    General-purpose timers (TIM2 to TIM5) RM0090 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.
  • Page 617: Figure 168. Example Of Counter Operation In Encoder Interface Mode

    RM0090 General-purpose timers (TIM2 to TIM5) Figure 168. Example of counter operation in encoder interface mode forward jitter backward jitter forward Counter down MS33107V1 Figure 169 gives an example of counter behavior when TI1FP1 polarity is inverted (same configuration as above except CC1P=1). Figure 169.
  • Page 618: Figure 170. Control Circuit In Reset Mode

    General-purpose timers (TIM2 to TIM5) RM0090 18.3.13 Timer input XOR function The TI1S bit in the TIM_CR2 register, allows the input filter of channel 1 to be connected to the output of a XOR gate, combining the three input pins TIMx_CH1 to TIMx_CH3. The XOR output can be used with all the timer input functions such as trigger or input capture.
  • Page 619: Figure 171. Control Circuit In Gated Mode

    RM0090 General-purpose timers (TIM2 to TIM5) Slave mode: Gated mode The counter can be enabled depending on the level of a selected input. 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).
  • Page 620: Figure 172. Control Circuit In Trigger Mode

    General-purpose timers (TIM2 to TIM5) RM0090 When a rising edge occurs on TI2, the counter starts counting on the internal clock and the TIF flag is set. The delay between the rising edge on TI2 and the actual start of the counter is due to the resynchronization circuit on TI2 input.
  • Page 621: Figure 173. Control Circuit In External Clock Mode 2 + Trigger Mode

    RM0090 General-purpose timers (TIM2 to TIM5) Figure 173. Control circuit in external clock mode 2 + trigger mode CEN/CNT_EN Counter clock = CK_CNT = CK_PSC Counter register MS33110V1 18.3.15 Timer synchronization The TIMx timers are linked together internally for timer synchronization or chaining. When one Timer is configured in Master Mode, it can reset, start, stop or clock the counter of another Timer configured in Slave Mode.
  • Page 622: Figure 175. Gating Timer 2 With Oc1Ref Of Timer 1

    General-purpose timers (TIM2 to TIM5) RM0090 For example, the user can configure Timer 1 to act as a prescaler for Timer 2 (see Figure 174). To do this: • Configure Timer 1 in master mode so that it outputs a periodic trigger signal on each update event UEV.
  • Page 623: Figure 176. Gating Timer 2 With Enable Of Timer 1

    RM0090 General-purpose timers (TIM2 to TIM5) 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.
  • Page 624: Figure 177. Triggering Timer 2 With Update Of Timer 1

    General-purpose timers (TIM2 to TIM5) RM0090 Using one timer to start another timer In this example, we set the enable of Timer 2 with the update event of Timer 1. Refer to Figure 174 for connections. Timer 2 starts counting from its current value (which can be nonzero) on the divided internal clock as soon as the update event is generated by Timer 1.
  • Page 625: Figure 178. Triggering Timer 2 With Enable Of Timer 1

    RM0090 General-purpose timers (TIM2 to TIM5) Figure 178. Triggering timer 2 with Enable of timer 1 CK_INT TIMER1-CEN=CNT_EN TIMER1-CNT_INIT TIMER1-CNT TIMER2-CNT TIMER2-CNT_INIT TIMER2-write CNT TIMER2-TIF Write TIF = 0 MS37391V1 Starting 2 timers synchronously in response to an external trigger In this example, we set the enable of timer 1 when its TI1 input rises, and the enable of Timer 2 with the enable of Timer 1.
  • Page 626: Figure 179. Triggering Timer 1 And 2 With Timer 1 Ti1 Input

    General-purpose timers (TIM2 to TIM5) RM0090 Figure 179. Triggering timer 1 and 2 with timer 1 TI1 input CK_INT TIMER1-TI1 TIMER1-CEN=CNT_EN TIMER1-CK_PSC TIMER1-CNT 02 03 04 05 06 07 08 09 TIMER1-TIF TIMER2-CEN=CNT_EN TIMER2-CK_PSC TIMER2-CNT 01 02 03 04 05 06 07 08 09 TIMER2-TIF MS37392V1 18.3.16...
  • Page 627 RM0090 General-purpose timers (TIM2 to TIM5) 18.4 TIM2 to TIM5 registers Refer to Section 1.1 for a list of abbreviations used in register descriptions. The 32-bit peripheral registers have to be written by words (32 bits). All other peripheral registers have to be written by half-words (16 bits) or words (32 bits). Read accesses can be done by bytes (8 bits), half-words (16 bits) or words (32 bits).
  • Page 628 General-purpose timers (TIM2 to TIM5) RM0090 Bit 2 URS: Update request source This bit is set and cleared by software to select the UEV event sources. 0: Any of the following events generate an update interrupt or DMA request if enabled. These events can be: –...
  • Page 629 RM0090 General-purpose timers (TIM2 to TIM5) 18.4.2 TIMx control register 2 (TIMx_CR2) Address offset: 0x04 Reset value: 0x0000 TI1S MMS[2:0] CCDS Reserved Reserved Bits 15:8 Reserved, must be kept at reset value. Bit 7 TI1S: TI1 selection 0: The TIMx_CH1 pin is connected to TI1 input 1: The TIMx_CH1, CH2 and CH3 pins are connected to the TI1 input (XOR combination) Bits 6:4 MMS[2:0]: Master mode selection These bits allow to select the information to be sent in master mode to slave timers for...
  • Page 630 General-purpose timers (TIM2 to TIM5) RM0090 18.4.3 TIMx slave mode control register (TIMx_SMCR) Address offset: 0x08 Reset value: 0x0000 ETPS[1:0] ETF[3:0] TS[2:0] SMS[2:0] Res. Bit 15 ETP: External trigger polarity This bit selects whether ETR or ETR is used for trigger operations 0: ETR is noninverted, active at high level or rising edge 1: ETR is inverted, active at low level or falling edge Bit 14 ECE: External clock enable...
  • Page 631 RM0090 General-purpose timers (TIM2 to TIM5) Bit 7 MSM: Master/Slave mode 0: No action 1: The effect of an event on the trigger input (TRGI) is delayed to allow a perfect synchronization between the current timer and its slaves (through TRGO). It is useful if we want to synchronize several timers on a single external event.
  • Page 632: Table 98. Timx Internal Trigger Connection

    General-purpose timers (TIM2 to TIM5) RM0090 Table 98. TIMx internal trigger connection Slave TIM ITR0 (TS = 000) ITR1 (TS = 001) ITR2 (TS = 010) ITR3 (TS = 011) TIM2 TIM1_TRGO TIM8_TRGO TIM3_TRGO TIM4_TRGO TIM3 TIM1_TRGO TIM2_TRGO TIM5_TRGO TIM4_TRGO TIM4 TIM1_TRGO TIM2_TRGO...
  • Page 633 RM0090 General-purpose timers (TIM2 to TIM5) Bit 3 CC3IE: Capture/Compare 3 interrupt enable 0: CC3 interrupt disabled 1: CC3 interrupt enabled Bit 2 CC2IE: Capture/Compare 2 interrupt enable 0: CC2 interrupt disabled 1: CC2 interrupt enabled Bit 1 CC1IE: Capture/Compare 1 interrupt enable 0: CC1 interrupt disabled 1: CC1 interrupt enabled Bit 0 UIE: Update interrupt enable...
  • Page 634 General-purpose timers (TIM2 to TIM5) RM0090 Bit 3 CC3IF: Capture/Compare 3 interrupt flag refer to CC1IF description Bit 2 CC2IF: Capture/Compare 2 interrupt flag refer to CC1IF description Bit 1 CC1IF: Capture/compare 1 interrupt flag If channel CC1 is configured as output: This flag is set by hardware when the counter matches the compare value, with some exception in center-aligned mode (refer to the CMS bits in the TIMx_CR1 register description).
  • Page 635 RM0090 General-purpose timers (TIM2 to TIM5) 18.4.6 TIMx event generation register (TIMx_EGR) Address offset: 0x14 Reset value: 0x0000 CC4G CC3G CC2G CC1G Reserved Res. Bits 15:7 Reserved, must be kept at reset value. Bit 6 TG: Trigger generation This bit is set by software in order to generate an event, it is automatically cleared by hardware.
  • Page 636 General-purpose timers (TIM2 to TIM5) RM0090 18.4.7 TIMx capture/compare mode register 1 (TIMx_CCMR1) Address offset: 0x18 Reset value: 0x0000 The channels can be used in input (capture mode) or in output (compare mode). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function in input and in output mode.
  • Page 637 RM0090 General-purpose timers (TIM2 to TIM5) Bits 6:4 OC1M: Output compare 1 mode These bits define the behavior of the output reference signal OC1REF from which OC1 and OC1N are derived. OC1REF is active high whereas OC1 and OC1N active level depends on CC1P and CC1NP bits.
  • Page 638 General-purpose timers (TIM2 to TIM5) RM0090 Input capture mode Bits 15:12 IC2F: Input capture 2 filter Bits 11:10 IC2PSC[1:0]: Input capture 2 prescaler Bits 9:8 CC2S: Capture/compare 2 selection This bit-field defines the direction of the channel (input/output) as well as the used input. 00: CC2 channel is configured as output.
  • Page 639 RM0090 General-purpose timers (TIM2 to TIM5) 18.4.8 TIMx capture/compare mode register 2 (TIMx_CCMR2) Address offset: 0x1C Reset value: 0x0000 Refer to the above CCMR1 register description. OC4CE OC4M[2:0] OC4PE OC4FE OC3CE OC3M[2:0] OC3PE OC3FE CC4S[1:0] CC3S[1:0] IC4F[3:0] IC4PSC[1:0] IC3F[3:0] IC3PSC[1:0] Output compare mode Bit 15 OC4CE: Output compare 4 clear enable Bits 14:12 OC4M: Output compare 4 mode...
  • Page 640 General-purpose timers (TIM2 to TIM5) RM0090 Input capture mode Bits 15:12 IC4F: Input capture 4 filter Bits 11:10 IC4PSC: Input capture 4 prescaler Bits 9:8 CC4S: Capture/Compare 4 selection This bit-field defines the direction of the channel (input/output) as well as the used input. 00: CC4 channel is configured as output 01: CC4 channel is configured as input, IC4 is mapped on TI4 10: CC4 channel is configured as input, IC4 is mapped on TI3...
  • Page 641: Table 99. Output Control Bit For Standard Ocx Channels

    RM0090 General-purpose timers (TIM2 to TIM5) Bit 8 CC3E: Capture/Compare 3 output enable. refer to CC1E description Bit 7 CC2NP: Capture/Compare 2 output Polarity. refer to CC1NP description Bit 6 Reserved, must be kept at reset value. Bit 5 CC2P: Capture/Compare 2 output Polarity. refer to CC1P description Bit 4 CC2E: Capture/Compare 2 output enable.
  • Page 642 General-purpose timers (TIM2 to TIM5) RM0090 Note: The state of the external IO pins connected to the standard OCx channels depends on the OCx channel state and the GPIO registers. 18.4.10 TIMx counter (TIMx_CNT) Address offset: 0x24 Reset value: 0x0000 0000 CNT[31:16] (depending on timers) CNT[15:0] Bits 31:16 CNT[31:16]: High counter value (on TIM2 and TIM5).
  • Page 643 RM0090 General-purpose timers (TIM2 to TIM5) Bits 31:16 ARR[31:16]: High auto-reload value (on TIM2 and TIM5). Bits 15:0 ARR[15:0]: Auto-reload value ARR is the value to be loaded in the actual auto-reload register. Refer to the Section 18.3.1: Time-base unit for more details about ARR update and behavior.
  • Page 644 General-purpose timers (TIM2 to TIM5) RM0090 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).
  • Page 645 RM0090 General-purpose timers (TIM2 to TIM5) 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 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).
  • Page 646 General-purpose timers (TIM2 to TIM5) RM0090 18.4.18 TIMx DMA address for full transfer (TIMx_DMAR) Address offset: 0x4C Reset value: 0x0000 DMAB[15:0] Bits 15:0 DMAB[15:0]: DMA register for burst accesses A read or write operation to the DMAR register accesses the register located at the address (TIMx_CR1 address) + (DBA + DMA index) x 4 where TIMx_CR1 address is the address of the control register 1, DBA is the DMA base address configured in TIMx_DCR register, DMA index is automatically controlled by the...
  • Page 647 RM0090 General-purpose timers (TIM2 to TIM5) 18.4.19 TIM2 option register (TIM2_OR) Address offset: 0x50 Reset value: 0x0000 ITR1_RMP Reserved Reserved Bits 15:12 Reserved, must be kept at reset value. Bits 11:10 ITR1_RMP: Internal trigger 1 remap Set and cleared by software. 00: TIM8_TRGOUT 01: PTP trigger output is connected to TIM2_ITR1 10: OTG FS SOF is connected to the TIM2_ITR1 input...
  • Page 648: Table 100. Tim2 To Tim5 Register Map And Reset Values

    General-purpose timers (TIM2 to TIM5) RM0090 18.4.21 TIMx register map TIMx registers are mapped as described in the table below: Table 100. TIM2 to TIM5 register map and reset values Offset Register TIMx_CR1 [1:0] [1:0] 0x00 Reserved Reset value TIMx_CR2 MMS[2:0] 0x04 Reserved...
  • Page 649 RM0090 General-purpose timers (TIM2 to TIM5) Table 100. TIM2 to TIM5 register map and reset values (continued) Offset Register ARR[31:16] TIMx_ARR ARR[15:0] (TIM2 and TIM5 only, reserved on the other timers) 0x2C Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0x30 Reserved CCR1[31:16]...
  • Page 650 General-purpose timers (TIM9 to TIM14) RM0090 General-purpose timers (TIM9 to TIM14) This section applies to the whole STM32F4xx family, unless otherwise specified. 19.1 TIM9 to TIM14 introduction The TIM9 to TIM14 general-purpose timers consist of a 16-bit auto-reload counter driven by a programmable prescaler.
  • Page 651: Figure 180. General-Purpose Timer Block Diagram (Tim9 And Tim12)

    RM0090 General-purpose timers (TIM9 to TIM14) Figure 180. General-purpose timer block diagram (TIM9 and TIM12) Internal clock (CK_INT) Trigger controller ITR0 Slave ITR1 Reset, enable, up, count controller ITR2 TRGI mode ITR3 TI1F_ED TI1FP1 TI2FP2 Auto-reload register Stop, Clear CK_PSC CK_CNT CNT counter prescaler...
  • Page 652: Figure 181. General-Purpose Timer Block Diagram (Tim10/11/13/14)

    General-purpose timers (TIM9 to TIM14) RM0090 Figure 181. General-purpose timer block diagram (TIM10/11/13/14) Internal clock (CK_INT) Enable Trigger counter Controller Autoreload register Stop, Clear CK_PSC CK_CNT prescaler counter CC1I CC1I TI1FP1 output Input filter & IC1PS OC1REF Prescaler Capture/Compare 1 register TIMx_CH1 TIMx_CH1 edge detector...
  • Page 653 RM0090 General-purpose timers (TIM9 to TIM14) 19.3 TIM9 to TIM14 functional description 19.3.1 Time-base unit The main block of the timer is a 16-bit counter with its related auto-reload register. The counters counts up. The counter clock can be divided by a prescaler. The counter, the auto-reload register and the prescaler register can be written or read by software.
  • Page 654: Figure 182. Counter Timing Diagram With Prescaler Division Change From 1 To 2

    General-purpose timers (TIM9 to TIM14) RM0090 Figure 182. Counter timing diagram with prescaler division change from 1 to 2 CK_PSC Timerclock = CK_CNT FA FB Counter register Update event (UEV) Prescaler control register Write a new value in TIMx_PSC Prescaler buffer Prescaler counter MS31076V2 Figure 183.
  • Page 655: Figure 184. Counter Timing Diagram, Internal Clock Divided By 1

    RM0090 General-purpose timers (TIM9 to TIM14) 19.3.2 Counter modes Upcounting mode In upcounting mode, the counter counts from 0 to the auto-reload value (content of the TIMx_ARR register), then restarts from 0 and generates a counter overflow event. Setting the UG bit in the TIMx_EGR register (by software or by using the slave mode controller on TIM9 and TIM12) also generates an update event.
  • Page 656: Figure 185. Counter Timing Diagram, Internal Clock Divided By 2

    General-purpose timers (TIM9 to TIM14) RM0090 Figure 185. Counter timing diagram, internal clock divided by 2 CK_PSC CNT_EN Timerclock = CK_CNT Counter register 0034 0035 0036 0000 0001 0002 0003 Counter overflow Update event (UEV) Update interrupt flag (UIF) MS31079V3 Figure 186.
  • Page 657: Figure 188. Counter Timing Diagram, Update Event When Arpe=0 (Timx_Arr Not Preloaded)

    RM0090 General-purpose timers (TIM9 to TIM14) Figure 188. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not preloaded) CK_PSC Timerclock = CK_CNT Counter register Counter overflow Update event (UEV) Update interrupt flag (UIF) Auto-reload preload register Write a new value in TIMx_ARR MS31082V3 Figure 189.
  • Page 658: Figure 190. Control Circuit In Normal Mode, Internal Clock Divided By 1

    General-purpose timers (TIM9 to TIM14) RM0090 19.3.3 Clock selection The counter clock can be provided by the following clock sources: • Internal clock (CK_INT) • External clock mode1 (for TIM9 and TIM12): external input pin (TIx) • Internal trigger inputs (ITRx) (for TIM9 and TIM12): connecting the trigger output from another timer.
  • Page 659: Figure 191. Ti2 External Clock Connection Example

    RM0090 General-purpose timers (TIM9 to TIM14) Figure 191. TI2 external clock connection example TIMx_SMCR TS[2:0] TI2F TI1F ITRx TI1_ED CK_PSC TRGI External clock TI1FP1 mode 1 TI2F_Rising Edge TI2FP2 Filter detector TI2F_Falling CK_INT Internal clock mode (internal clock) ICF[3:0] CC2P TIMx_CCER TIMx_CCMR1 SMS[2:0]...
  • Page 660: Figure 193. Capture/Compare Channel (Example: Channel 1 Input Stage)

    General-purpose timers (TIM9 to TIM14) RM0090 19.3.4 Capture/compare channels Each Capture/Compare channel is built around a capture/compare register (including a shadow register), a input stage for capture (with digital filter, multiplexing and prescaler) and an output stage (with comparator and output control). Figure 193 Figure 195 give an overview of a capture/compare channel.
  • Page 661: Figure 194. Capture/Compare Channel 1 Main Circuit

    RM0090 General-purpose timers (TIM9 to TIM14) Figure 194. Capture/compare channel 1 main circuit APB Bus MCU-peripheral interface write CCR1H Read CCR1H write_in_progress read_in_progress write CCR1L Capture/compare preload register Read CCR1L Output CC1S[1] compare_transfer capture_transfer mode CC1S[0] Input CC1S[1] OC1PE mode OC1PE Capture /compare shadow register CC1S[0]...
  • Page 662 General-purpose timers (TIM9 to TIM14) RM0090 cleared by software by writing it to ‘0’ or by reading the captured data stored in the TIMx_CCRx register. CCxOF is cleared when the user writes it to ‘0’. The following example shows how to capture the counter value in TIMx_CCR1 when TI1 input rises.
  • Page 663: Figure 196. Pwm Input Mode Timing

    RM0090 General-purpose timers (TIM9 to TIM14) 19.3.6 PWM input mode (only for TIM9/12) This mode is a particular case of input capture mode. The procedure is the same except: • Two ICx signals are mapped on the same TIx input. •...
  • Page 664 General-purpose timers (TIM9 to TIM14) RM0090 19.3.7 Forced output mode In output mode (CCxS bits = ‘00’ in the TIMx_CCMRx register), each output compare signal (OCxREF and then OCx) can be forced to active or inactive level directly by software, independently of any comparison between the output compare register and the counter.
  • Page 665: Figure 197. Output Compare Mode, Toggle On Oc1

    RM0090 General-purpose timers (TIM9 to TIM14) 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 197.
  • Page 666: Figure 198. Edge-Aligned Pwm Waveforms (Arr=8)

    General-purpose timers (TIM9 to TIM14) RM0090 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 198 shows some edge- aligned PWM waveforms in an example where TIMx_ARR=8. Figure 198.
  • Page 667: Figure 199. Example Of One Pulse Mode

    RM0090 General-purpose timers (TIM9 to TIM14) Figure 199. Example of one pulse mode. OC1REF TIM1_ARR TIM1_CCR1 DELAY PULSE MS31099V1 For example the user may want to generate a positive pulse on OC1 with a length of t PULSE and after a delay of t as soon as a positive edge is detected on the TI2 input pin.
  • Page 668 General-purpose timers (TIM9 to TIM14) RM0090 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.
  • Page 669: Figure 200. Control Circuit In Reset Mode

    RM0090 General-purpose timers (TIM9 to TIM14) Figure 200. Control circuit in reset mode Counter clock = ck_cnt = ck_psc Counter register 32 33 34 35 36 01 02 03 00 01 02 03 MS31401V2 Slave mode: Gated mode The counter can be enabled depending on the level of a selected input. In the following example, the upcounter counts only when TI1 input is low: Configure the channel 1 to detect low levels on TI1.
  • Page 670: Figure 201. Control Circuit In Gated Mode

    General-purpose timers (TIM9 to TIM14) RM0090 Figure 201. Control circuit in gated mode cnt_en Counter clock = ck_cnt = ck_psc Counter register 35 36 32 33 Write TIF=0 MS31402V1 Slave mode: Trigger mode The counter can start in response to an event on a selected input. In the following example, the upcounter starts in response to a rising edge on TI2 input: Configure the channel 2 to detect rising edges on TI2.
  • Page 671 RM0090 General-purpose timers (TIM9 to TIM14) 19.3.12 Timer synchronization (TIM9/12) The TIM timers are linked together internally for timer synchronization or chaining. Refer to Section 18.3.15: Timer synchronization for details. Note: The clock of the slave timer must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the master timer.
  • Page 672 General-purpose timers (TIM9 to TIM14) RM0090 19.4 TIM9 and TIM12 registers Refer to Section 1.1 for a list of abbreviations used in register descriptions. The peripheral registers have to be written by half-words (16 bits) or words (32 bits). Read accesses can be done by bytes (8 bits), half-words (16 bits) or words (32 bits).
  • Page 673 RM0090 General-purpose timers (TIM9 to TIM14) 19.4.2 TIM9/12 slave mode control register (TIMx_SMCR) Address offset: 0x08 Reset value: 0x0000 TS[2:0] SMS[2:0] Reserved Res. Bits 15:8 Reserved, must be kept at reset value. Bit 7 MSM: Master/Slave mode 0: No action 1: The effect of an event on the trigger input (TRGI) is delayed to allow a perfect synchronization between the current timer and its slaves (through TRGO).
  • Page 674: Table 101. Timx Internal Trigger Connection

    General-purpose timers (TIM9 to TIM14) RM0090 Bit 3 Reserved, must be kept at reset value. Bits 2:0 SMS: Slave mode selection When external signals are selected, the active edge of the trigger signal (TRGI) is linked to the polarity selected on the external input (see Input control register and Control register descriptions.
  • Page 675 RM0090 General-purpose timers (TIM9 to TIM14) Bit 2 CC2IE: Capture/Compare 2 interrupt enable 0: CC2 interrupt disabled. 1: CC2 interrupt enabled. Bit 1 CC1IE: Capture/Compare 1 interrupt enable 0: CC1 interrupt disabled. 1: CC1 interrupt enabled. Bit 0 UIE: Update interrupt enable 0: Update interrupt disabled.
  • Page 676 General-purpose timers (TIM9 to TIM14) RM0090 19.4.4 TIM9/12 status register (TIMx_SR) Address offset: 0x10 Reset value: 0x0000 CC2OF CC1OF CC2IF CC1IF Reserved Reserved Reserved rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 Bits 15:11 Reserved, must be kept at reset value. Bit 10 CC2OF: Capture/compare 2 overcapture flag refer to CC1OF description Bit 9 CC1OF: Capture/Compare 1 overcapture flag This flag is set by hardware only when the corresponding channel is configured in input...
  • Page 677 RM0090 General-purpose timers (TIM9 to TIM14) Bit 0 UIF: Update interrupt flag This bit is set by hardware on an update event. It is cleared by software. 0: No update occurred. 1: Update interrupt pending. This bit is set by hardware when the registers are updated: –...
  • Page 678 General-purpose timers (TIM9 to TIM14) RM0090 19.4.6 TIM9/12 capture/compare mode register 1 (TIMx_CCMR1) Address offset: 0x18 Reset value: 0x0000 The channels can be used in input (capture mode) or in output (compare mode). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits in this register have different functions in input and output modes.
  • Page 679 RM0090 General-purpose timers (TIM9 to TIM14) Bits 6:4 OC1M: Output compare 1 mode These bits define the behavior of the output reference signal OC1REF from which OC1 and OC1N are derived. OC1REF is active high whereas the active levels of OC1 and OC1N depend on the CC1P and CC1NP bits, respectively.
  • Page 680 General-purpose timers (TIM9 to TIM14) RM0090 Input capture mode Bits 15:12 IC2F: Input capture 2 filter Bits 11:10 IC2PSC[1:0]: Input capture 2 prescaler Bits 9:8 CC2S: Capture/compare 2 selection This bitfield defines the direction of the channel (input/output) as well as the used input. 00: CC2 channel is configured as output 01: CC2 channel is configured as input, IC2 is mapped on TI2 10: CC2 channel is configured as input, IC2 is mapped on TI1...
  • Page 681 RM0090 General-purpose timers (TIM9 to TIM14) 19.4.7 TIM9/12 capture/compare enable register (TIMx_CCER) Address offset: 0x20 Reset value: 0x0000 CC2NP CC2P CC2E CC1NP CC1P CC1E Reserved Res. Res. Bits 15:8 Reserved, must be kept at reset value. Bit 7 CC2NP: Capture/Compare 2 output Polarity refer to CC1NP description Bits 6 Reserved, must be kept at reset value.
  • Page 682: Table 102. Output Control Bit For Standard Ocx Channels

    General-purpose timers (TIM9 to TIM14) RM0090 Table 102. Output control bit for standard OCx channels CCxE bit OCx output state Output disabled (OCx=’0’, OCx_EN=’0’) OCx=OCxREF + Polarity, OCx_EN=’1’ 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.
  • Page 683 RM0090 General-purpose timers (TIM9 to TIM14) 19.4.11 TIM9/12 capture/compare register 1 (TIMx_CCR1) Address offset: 0x34 Reset value: 0x0000 CCR1[15:0] rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro Bits 15:0 CCR1[15:0]: Capture/Compare 1 value If channel CC1 is configured as output: CCR1 is the value to be loaded into the actual capture/compare 1 register (preload value).
  • Page 684: Table 103. Tim9/12 Register Map And Reset Values

    General-purpose timers (TIM9 to TIM14) RM0090 19.4.13 TIM9/12 register map TIM9/12 registers are mapped as 16-bit addressable registers as described below. The reserved memory areas are highlighted in gray in the table. Table 103. TIM9/12 register map and reset values Offset Register TIMx_CR1...
  • Page 685 RM0090 General-purpose timers (TIM9 to TIM14) Table 103. TIM9/12 register map and reset values (continued) Offset Register TIMx_CCR2 CCR2[15:0] 0x38 Reserved Reset value 0x3C to Reserved 0x4C Refer to Section 2.3: Memory map for the register boundary addresses. RM0090 Rev 18 685/1749...
  • Page 686 General-purpose timers (TIM9 to TIM14) RM0090 19.5 TIM10/11/13/14 registers The peripheral registers have to be written by half-words (16 bits) or words (32 bits). Read accesses can be done by bytes (8 bits), half-words (16 bits) or words (32 bits). 19.5.1 TIM10/11/13/14 control register 1 (TIMx_CR1) Address offset: 0x00...
  • Page 687 RM0090 General-purpose timers (TIM9 to TIM14) 19.5.2 TIM10/11/13/14 Interrupt enable register (TIMx_DIER) Address offset: 0x0C Reset value: 0x0000 CC1IE Reserved Bits 15:2 Reserved, must be kept at reset value. Bit 1 CC1IE: Capture/Compare 1 interrupt enable 0: CC1 interrupt disabled 1: CC1 interrupt enabled Bit 0 UIE: Update interrupt enable 0: Update interrupt disabled...
  • Page 688 General-purpose timers (TIM9 to TIM14) RM0090 Bit 0 UIF: Update interrupt flag This bit is set by hardware on an update event. It is cleared by software. 0: No update occurred. 1: Update interrupt pending. This bit is set by hardware when the registers are updated: –...
  • Page 689 RM0090 General-purpose timers (TIM9 to TIM14) Output compare mode Bits 15:7 Reserved, must be kept at reset value. Bits 6:4 OC1M: Output compare 1 mode These bits define the behavior of the output reference signal OC1REF from which OC1 is derived.
  • Page 690 General-purpose timers (TIM9 to TIM14) RM0090 Input capture mode Bits 15:8 Reserved, must be kept at reset value. Bits 7:4 IC1F: Input capture 1 filter This bit-field defines the frequency used to sample TI1 input and the length of the digital filter applied to TI1.
  • Page 691: Table 104. Output Control Bit For Standard Ocx Channels

    RM0090 General-purpose timers (TIM9 to TIM14) 19.5.6 TIM10/11/13/14 capture/compare enable register (TIMx_CCER) Address offset: 0x20 Reset value: 0x0000 CC1NP CC1P CC1E Reserved Res. Bits 15:4 Reserved, must be kept at reset value. Bit 3 CC1NP: Capture/Compare 1 complementary output Polarity. CC1 channel configured as output: CC1NP must be kept cleared.
  • Page 692 General-purpose timers (TIM9 to TIM14) RM0090 19.5.7 TIM10/11/13/14 counter (TIMx_CNT) Address offset: 0x24 Reset value: 0x0000 CNT[15:0] Bits 15:0 CNT[15:0]: Counter value 19.5.8 TIM10/11/13/14 prescaler (TIMx_PSC) Address offset: 0x28 Reset value: 0x0000 PSC[15:0] Bits 15:0 PSC[15:0]: Prescaler value The counter clock frequency CK_CNT is equal to f / (PSC[15:0] + 1).
  • Page 693 RM0090 General-purpose timers (TIM9 to TIM14) 19.5.10 TIM10/11/13/14 capture/compare register 1 (TIMx_CCR1) Address offset: 0x34 Reset value: 0x0000 CCR1[15:0] rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro Bits 15:0 CCR1[15:0]: 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).
  • Page 694: Table 105. Tim10/11/13/14 Register Map And Reset Values

    General-purpose timers (TIM9 to TIM14) RM0090 19.5.12 TIM10/11/13/14 register map TIMx registers are mapped as 16-bit addressable registers as described in the table below. Table 105. TIM10/11/13/14 register map and reset values Offset Register TIMx_CR1 Reserve [1:0] 0x00 Reserved Reset value TIMx_SMCR 0x08 Reserved...
  • Page 695 RM0090 General-purpose timers (TIM9 to TIM14) Table 105. TIM10/11/13/14 register map and reset values (continued) Offset Register TIMx_OR 0x50 Reserved Reset value Refer to Section 2.3: Memory map for the register boundary addresses. RM0090 Rev 18 695/1749...
  • Page 696: Figure 203. Basic Timer Block Diagram

    Basic timers (TIM6 and TIM7) RM0090 Basic timers (TIM6 and TIM7) This section applies to the whole STM32F4xx family, unless otherwise specified. 20.1 TIM6 and TIM7 introduction The basic timers TIM6 and TIM7 consist of a 16-bit auto-reload counter driven by a programmable prescaler.
  • Page 697 RM0090 Basic timers (TIM6 and TIM7) 20.3 TIM6 and TIM7 functional description 20.3.1 Time-base unit The main block of the programmable timer is a 16-bit upcounter with its related auto-reload register. The counter clock can be divided by a prescaler. The counter, the auto-reload register and the prescaler register can be written or read by software.
  • Page 698: Figure 204. Counter Timing Diagram With Prescaler Division Change From 1 To 2

    Basic timers (TIM6 and TIM7) RM0090 Figure 204. Counter timing diagram with prescaler division change from 1 to 2 CK_PSC CNT_EN Timerclock = CK_CNT Counter register FA FB Update event (UEV) Prescaler control register Write a new value in TIMx_PSC Prescaler buffer Prescaler counter MS31076V3...
  • Page 699: Figure 206. Counter Timing Diagram, Internal Clock Divided By 1

    RM0090 Basic timers (TIM6 and TIM7) 20.3.2 Counting mode The counter counts from 0 to the auto-reload value (contents of the TIMx_ARR register), then restarts from 0 and generates a counter overflow event. An update event can be generate at each counter overflow or by setting the UG bit in the TIMx_EGR register (by software or by using the slave mode controller).
  • Page 700: Figure 207. Counter Timing Diagram, Internal Clock Divided By 2

    Basic timers (TIM6 and TIM7) RM0090 Figure 207. Counter timing diagram, internal clock divided by 2 CK_INT CNT_EN Timerclock = CK_CNT Counter register 0034 0035 0036 0000 0001 0002 0003 Counter overflow Update event (UEV) Update interrupt flag (UIF) MS35835V1 Figure 208.
  • Page 701: Preloaded)

    RM0090 Basic timers (TIM6 and TIM7) Figure 210. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not preloaded) CK_INT CNT_EN Timerclock = CK_CNT Counter register 32 33 34 35 36 02 03 04 05 06 07 Counter overflow Update event (UEV) Update interrupt flag (UIF) Auto-reload register Write a new value in TIMx_ARR...
  • Page 702: Figure 212. Control Circuit In Normal Mode, Internal Clock Divided By 1

    Basic timers (TIM6 and TIM7) RM0090 Figure 212. Control circuit in normal mode, internal clock divided by 1 Internal clock CEN=CNT_EN CNT_INIT Counter clock = CK_CNT = CK_PSC Counter register 33 34 35 36 03 04 05 MS31085V2 20.3.4 Debug mode ®...
  • Page 703 RM0090 Basic timers (TIM6 and TIM7) Bit 2 URS: Update request source This bit is set and cleared by software to select the UEV event sources. 0: Any of the following events generates an update interrupt or DMA request if enabled. These events can be: –...
  • Page 704 Basic timers (TIM6 and TIM7) RM0090 20.4.2 TIM6 and TIM7 control register 2 (TIMx_CR2) Address offset: 0x04 Reset value: 0x0000 MMS[2:0] Reserved Reserved Bits 15:7 Reserved, must be kept at reset value. Bits 6:4 MMS[2:0]: Master mode selection These bits are used to select the information to be sent in master mode to slave timers for synchronization (TRGO).
  • Page 705 RM0090 Basic timers (TIM6 and TIM7) 20.4.4 TIM6 and TIM7 status register (TIMx_SR) Address offset: 0x10 Reset value: 0x0000 Reserved rc_w0 Bits 15:1 Reserved, must be kept at reset value. Bit 0 UIF: Update interrupt flag This bit is set by hardware on an update event. It is cleared by software. 0: No update occurred.
  • Page 706 Basic timers (TIM6 and TIM7) RM0090 20.4.7 TIM6 and TIM7 prescaler (TIMx_PSC) Address offset: 0x28 Reset value: 0x0000 PSC[15:0] Bits 15:0 PSC[15:0]: Prescaler value The counter clock frequency CK_CNT is equal to f / (PSC[15:0] + 1). CK_PSC PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).
  • Page 707: Table 106. Tim6 And Tim7 Register Map And Reset Values

    RM0090 Basic timers (TIM6 and TIM7) 20.4.9 TIM6 and TIM7 register map TIMx registers are mapped as 16-bit addressable registers as described in the table below. Table 106. TIM6 and TIM7 register map and reset values Offset Register TIMx_CR1 0x00 Reserved Reset value TIMx_CR2...
  • Page 708 Independent watchdog (IWDG) RM0090 Independent watchdog (IWDG) This section applies to the whole STM32F4xx family, unless otherwise specified. 21.1 IWDG introduction The devices have two embedded watchdog peripherals which offer a combination of high safety level, timing accuracy and flexibility of use. Both watchdog peripherals (Independent and Window) serve to detect and resolve malfunctions due to software failure, and to trigger system reset or an interrupt (window watchdog only) when the counter reaches a given timeout value.
  • Page 709: Table 107. Min/Max Iwdg Timeout Period (In Ms) At 32 Khz (Lsi)

    RM0090 Independent watchdog (IWDG) different value will break the sequence and register access will be protected again. This implies that it is the case of the reload operation (writing 0xAAAA). A status register is available to indicate that an update of the prescaler or the down-counter reload value is on going.
  • Page 710 Independent watchdog (IWDG) RM0090 21.4 IWDG registers Refer to Section 1.1 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by half-words (16 bits) or words (32 bits). 21.4.1 Key register (IWDG_KR) Address offset: 0x00 Reset value: 0x0000 0000 (reset by Standby mode) 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 KEY[15:0]...
  • Page 711 RM0090 Independent watchdog (IWDG) 21.4.3 Reload register (IWDG_RLR) Address offset: 0x08 Reset value: 0x0000 0FFF (reset by Standby mode) 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 RL[11:0] Reserved rw rw rw...
  • Page 712: Table 108. Iwdg Register Map And Reset Values

    Independent watchdog (IWDG) RM0090 21.4.5 IWDG register map The following table gives the IWDG register map and reset values. Table 108. IWDG register map and reset values Offset Register IWDG_KR KEY[15:0] Reserved 0x00 Reset value IWDG_PR PR[2:0] Reserved 0x04 Reset value IWDG_RLR RL[11:0] Reserved...
  • Page 713 RM0090 Window watchdog (WWDG) Window watchdog (WWDG) This section applies to the whole STM32F4xx family, unless otherwise specified. 22.1 WWDG introduction The window watchdog is used to detect the occurrence of a software fault, usually generated by external interference or by unforeseen logical conditions, which causes the application program to abandon its normal sequence.
  • Page 714: Figure 214. Watchdog Block Diagram

    Window watchdog (WWDG) RM0090 Figure 214. Watchdog block diagram 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.
  • Page 715: Figure 215. Window Watchdog Timing Diagram

    RM0090 Window watchdog (WWDG) In some applications, the EWI interrupt can be used to manage a software system check and/or system recovery/graceful degradation, without generating a WWDG reset. In this case, the corresponding interrupt service routine (ISR) should reload the WWDG counter to avoid the WWDG reset, then trigger the required actions.
  • Page 716: Table 109. Minimum And Maximum Timeout Values At 30 Mhz (F Pclk1 )

    Window watchdog (WWDG) RM0090 As an example, let us assume APB1 frequency is equal to 24 MHz, WDGTB[1:0] is set to 3 and T[5:0] is set to 63: ⁄ × × × t WWDG 24000 4096 21.85ms Refer to Table 109 for the minimum and maximum values of the t WWDG Table 109.
  • Page 717 RM0090 Window watchdog (WWDG) 22.6 WWDG registers Refer to Section 1.1 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by half-words (16 bits) or words (32 bits). 22.6.1 Control register (WWDG_CR) Address offset: 0x00 Reset value: 0x0000 007F Reserved WDGA...
  • Page 718 Window watchdog (WWDG) RM0090 22.6.2 Configuration register (WWDG_CFR) Address offset: 0x04 Reset value: 0x0000 007F Reserved WDGTB[1:0] W[6:0] Reserved Bit 31:10 Reserved, must be kept at reset value. Bit 9 EWI: Early wakeup interrupt When set, an interrupt occurs whenever the counter reaches the value 0x40. This interrupt is only cleared by hardware after a reset.
  • Page 719: Table 110. Wwdg Register Map And Reset Values

    RM0090 Window watchdog (WWDG) 22.6.4 WWDG register map The following table gives the WWDG register map and reset values. Table 110. WWDG register map and reset values Offset Register WWDG_CR T[6:0] 0x00 Reserved Reset value WWDG_CFR W[6:0] 0x04 Reserved Reset value WWDG_SR 0x08 Reserved...
  • Page 720: Table 111. Number Of Cycles Required To Process Each 128-Bit Block

    Cryptographic processor (CRYP) RM0090 Cryptographic processor (CRYP) This section applies to STM32F415/417xx and STM32F43xxx devices. 23.1 CRYP introduction The cryptographic processor can be used to both encipher and decipher data using the DES, Triple-DES or AES (128, 192, or 256) algorithms. It is a fully compliant implementation of the following standards: •...
  • Page 721 RM0090 Cryptographic processor (CRYP) Table 112. Number of cycles required to process each 128-bit block (STM32F43xxx) 192b 256b • DES/TDES – Direct implementation of simple DES algorithms (a single key, K1, is used) – Supports the ECB and CBC chaining algorithms –...
  • Page 722: Figure 216. Block Diagram (Stm32F415/417Xx)

    Cryptographic processor (CRYP) RM0090 23.3 CRYP functional description The cryptographic processor implements a Triple-DES (TDES, that also supports DES) core and an AES cryptographic core. Section 23.3.1 Section 23.3.2 provide details on these cores. Since the TDES and the AES algorithms use block ciphers, incomplete input data blocks have to be padded prior to encryption (extra bits should be appended to the trailing end of the data string).
  • Page 723: Figure 217. Block Diagram (Stm32F43Xxx)

    RM0090 Cryptographic processor (CRYP) Figure 217. Block diagram (STM32F43xxx) 32-bit AHB2 bus Status CRYP_SR CRYP_DIN CRYP_DOUT DMA control register CRYP_DMACR Interrupt registers 8 × 32-bit 8 × 32-bit IN FIFO OUT FIFO CRYP_IMSCR CRYP_RIS CRYP_MISR Control register swappi ng swappin g CRYP_CR Initialization vectors Context swapping...
  • Page 724 Cryptographic processor (CRYP) RM0090 The TDES allows three different keying options: • Three independent keys The first option specifies that all the keys are independent, that is, K1, K2 and K3 are independent. FIPS PUB 46-3 – 1999 (and ANSI X9.52 – 1998) refers to this option as the Keying Option 1 and, to the TDES as 3-key TDES.
  • Page 725: Figure 218. Des/Tdes-Ecb Mode Encryption

    RM0090 Cryptographic processor (CRYP) Figure 218. DES/TDES-ECB mode encryption IN FIFO plaintext P P, 64 bits DATATYPE swapping DEA, encrypt DEA, decrypt DEA, encrypt O, 64 bits DATATYPE swapping C, 64 bits OUT FIFO ciphertext C ai16069b 1. K: key; C: cipher text; I: input block; O: output block; P: plain text. Figure 219.
  • Page 726 Cryptographic processor (CRYP) RM0090 DES and TDES Cipher block chaining (DES/TDES-CBC) mode • DES/TDES-CBC mode encryption Figure 220 illustrates the DES and Triple-DES Cipher block chaining (DES/TDES- CBC) mode encryption. This mode begins by dividing a plaintext message into 64-bit data blocks.
  • Page 727: Figure 220. Des/Tdes-Cbc Mode Encryption

    RM0090 Cryptographic processor (CRYP) Figure 220. DES/TDES-CBC mode encryption IN FIFO plaintext P P, 64 bits DATATYPE swapping AHB2 data write (before CRYP is enabled) Ps, 64 bits IV0(L/R) I, 64 bits DEA, encrypt O is written back into IV at the DEA, decrypt same time as it is pushed into...
  • Page 728: Figure 221. Des/Tdes-Cbc Mode Decryption

    Cryptographic processor (CRYP) RM0090 Figure 221. DES/TDES-CBC mode decryption IN FIFO ciphertext C C, 64 bits DATATYPE swapping I, 64 bits DEA, decrypt I is written back into IV at the same time as P is pushed into DEA, encrypt the OUT FIFO DEA, decrypt AHB2 data write...
  • Page 729: Figure 222. Aes-Ecb Mode Encryption

    RM0090 Cryptographic processor (CRYP) ECB decryption, AES-CBC encryption and AES-CBC decryption.This reference manual only gives a brief explanation of each mode. AES Electronic codebook (AES-ECB) mode • AES-ECB mode encryption Figure 222 illustrates the AES Electronic codebook (AES-ECB) mode encryption. In AES-ECB encryption, a 128- bit plaintext data block (P) is used after bit/byte/half- word swapping (refer to Section 23.3.3: Data type on page...
  • Page 730: Figure 223. Aes-Ecb Mode Decryption

    Cryptographic processor (CRYP) RM0090 Figure 223. AES-ECB mode decryption IN FIFO ciphertext C C, 128 bits DATATYPE swapping I, 128 bits 128/192 or 256 K 0...3 (1) AEA, decrypt O, 128 bits DATATYPE swapping P, 128 bits OUT FIFO plaintext P MS19023V1 1.
  • Page 731: Figure 224. Aes-Cbc Mode Encryption

    RM0090 Cryptographic processor (CRYP) block of data.) The AES-CBC decryption process continues in this manner until the last complete ciphertext block has been decrypted. Ciphertext representing a partial data block must be decrypted in a manner specified for the application. Figure 224.
  • Page 732: Figure 225. Aes-Cbc Mode Decryption

    Cryptographic processor (CRYP) RM0090 Figure 225. AES-CBC mode decryption IN FIFO ciphertext C C, 128 bits DATATYPE swapping I, 128 bits 128, 192 or 256 AEA, decrypt K 0... I is written back into IV at the same time as P is pushed into the OUT FIFO AHB2 data write (before CRYP...
  • Page 733: Figure 226. Aes-Ctr Mode Encryption

    RM0090 Cryptographic processor (CRYP) Figure 226 Figure 227 illustrate AES-CTR encryption and decryption, respectively. Figure 226. AES-CTR mode encryption IN FIFO plaintext P P, 128 bits DATATYPE AHB2 data write swapping (before CRYP is enabled) IV0...1(L/R) Ps, 128 bits I, 128 bits 128, 192 or 256 AEA, encrypt...
  • Page 734: Figure 227. Aes-Ctr Mode Decryption

    Cryptographic processor (CRYP) RM0090 Figure 227. AES-CTR mode decryption IN FIFO ciphertext P C, 128 bits DATATYPE AHB2 data write swapping (before CRYP is enabled) IV0...1(L/R) Cs, 128 bits I, 128 bits 128, 192 or 256 AEA, encrypt K0...3 (I + 1) is written O, 128 bits back into IV at same time...
  • Page 735 RM0090 Cryptographic processor (CRYP) AES Galois/counter mode (GCM) The AES Galois/counter mode (GCM) allows encrypting and authenticating the plaintext, and generating the correspondent ciphertext and tag (also known as message authentication code or message integrity check). This algorithm is based on AES counter mode to ensure confidentiality.
  • Page 736 Cryptographic processor (CRYP) RM0090 GCM init phase During this first step, the HASH key is calculated and saved internally to be used for processing all the blocks. It is recommended to follow the sequence below: Make sure that the cryptographic processor is disabled by clearing the CRYPEN bit in the CRYP_CR register.
  • Page 737 RM0090 Cryptographic processor (CRYP) OFNE/OFFU flag of the CRYP_DOUT register can be monitored to check if the output FIFO is not empty. Repeat the previous step until all payload blocks have been encrypted or decrypted. Alternatively, DMA could be used. GCM final phase This step generates the authentication tag: Configure GCM_CCMPH[1:0] to ‘11’...
  • Page 738 Cryptographic processor (CRYP) RM0090 Note: The header part must precede the payload and the two parts cannot be mixed together. In CCM mode, 4 steps are required to perform and encryption or decryption: CCM init phase In this first step, the B0 packet of the CCM message (1st packet) is programmed into the CRYP_DIN register.
  • Page 739 RM0090 Cryptographic processor (CRYP) Note: The first block B1 must be formatted with the header length. This task should be handled by software. Once all header data have been supplied, wait until the BUSY flag is cleared. CCM payload phase (encryption/decryption) This step must be performed after the CCM header phase.
  • Page 740: Table 113. Data Types

    Cryptographic processor (CRYP) RM0090 The system memory organization is little-endian: whatever the data type (bit, byte, 16-bit half-word, 32-bit word) used, the least-significant data occupy the lowest address locations. A bit, byte, or half-word swapping operation (depending on the kind of data to be encrypted) therefore has to be performed on the data read from the IN FIFO before they enter the CRYP processor.
  • Page 741: Figure 229. 64-Bit Block Construction According To Datatype

    RM0090 Cryptographic processor (CRYP) cryptographic algorithm (for the AES, the block length is four 32-bit words, but swapping only takes place at word level, so it is identical to the one described here for the TDES). Note: The same swapping is performed between the IN FIFO and the CRYP data block, and between the CRYP data block and the OUT FIFO.
  • Page 742 Cryptographic processor (CRYP) RM0090 23.3.4 Initialization vectors - CRYP_IV0...1(L/R) Initialization vectors are considered as two 64-bit data items. They therefore do not have the same data format and representation in system memory as plaintext or cypher data, and they are not affected by the DATATYPE value. Initialization vectors are defined by two consecutive 32-bit words, CRYP_IVL (left part, noted as bits IV1...32) and CRYP_IVR (right part, noted as bits IV33...64).
  • Page 743: Figure 230. Initialization Vectors Use In The Tdes-Cbc Encryption

    RM0090 Cryptographic processor (CRYP) Figure 230. Initialization vectors use in the TDES-CBC encryption TDES-CBC en cryption ex ample, DATATYPE = 11b second word written into the CRYP_DIN register bit 31 bit 30 bit 2 bit 1 bit 0 bit 31 bit 30 bit 2 bit 1...
  • Page 744 Cryptographic processor (CRYP) RM0090 the CBC, CTR mode, the initialization vectors CRYP_IVx(L/R)R (x = 0..3) are updated as well. A write operation to the key registers (CRYP_Kx(L/R)R, x = 0..3), the initialization registers (CRYP_IVx(L/R)R, x = 0..3), or to bits [9:2] in the CRYP_CR register are ignored when the cryptographic processor is busy (bit BUSY = 1b in the CRYP_SR register), and the registers are not modified.
  • Page 745 RM0090 Cryptographic processor (CRYP) the DES/TDES. The DMA should be configured to set an interrupt on transfer completion of the output data to indicate that the processing is finished. Enable the cryptographic processor by writing the CRYPEN bit to 1. Enable the DMA requests by setting the DIEN and DOEN bits in the CRYP_DMACR register.
  • Page 746 Cryptographic processor (CRYP) RM0090 Case of the AES and DES Context saving Stop DMA transfers on the IN FIFO by clearing the DIEN bit in the CRYP_DMACR register. Wait until both the IN and OUT FIFOs are empty (IFEM=1 and OFNE=0 in the CRYP_SR register) and the BUSY bit is cleared.
  • Page 747 RM0090 Cryptographic processor (CRYP) the IN FIFO that have not been processed and save them in the memory until the FIFO is empty. Note: In GCM/GMAC or CCM/CMAC mode, bits [17:16] of the CRYP_CR register should also be saved. Configure and execute the other processing. Context restoration Configure the processor as in Section 23.3.6: Procedure to perform an encryption...
  • Page 748: Figure 231. Cryp Interrupt Mapping Diagram

    Cryptographic processor (CRYP) RM0090 Figure 231. CRYP interrupt mapping diagram CRYPEN IN FIFO Interrupt - INMIS INRIS INMIS INIM Global Interrupt OUTRIS OUTMIS OUT FIFO Interrupt - OUTMIS OUTIM ai16077 23.5 CRYP DMA interface The cryptographic processor provides an interface to connect to the DMA controller. The DMA operation is controlled through the CRYP DMA control register, CRYP_DMACR.
  • Page 749 RM0090 Cryptographic processor (CRYP) Bits 31:18 Reserved, must be kept at reset value Bits 17:16 Reserved, must be kept at reset value Bit 15 CRYPEN: Cryptographic processor enable 0: CRYP processor is disabled 1: CRYP processor is enabled Note: The CRYPEN bit is automatically cleared by hardware when the key preparation process ends (ALGOMODE=111b) or GCM_CCM init Phase Bit 14 FFLUSH: FIFO flush When CRYPEN = 0, writing this bit to 1 flushes the IN and OUT FIFOs (that is...
  • Page 750 Cryptographic processor (CRYP) RM0090 Bits 5:3 ALGOMODE[2:0]: Algorithm mode 000: TDES-ECB (triple-DES Electronic codebook): no feedback between blocks of data. Initialization vectors (CRYP_IV0(L/R)) are not used, three key vectors (K1, K2, and K3) are used (K0 is not used). 001: TDES-CBC (triple-DES Cipher block chaining): output block is XORed with the subsequent input block before its entry into the algorithm.
  • Page 751 RM0090 Cryptographic processor (CRYP) ALGO MODE GCM_CCMPH Reserved Res. CRYPEN FFLUSH KEYSIZE DATATYPE ALGOMODE[2:0] ALGODIR Reserved Reserved Bits 31:20 Reserved, forced by hardware to 0. Bit 18 Reserved, forced by hardware to 0. Bits 17:16 GCM_CCMPH[1:0]: no effect if “GCM or CCM algorithm” is not set 00: GCM_CCM init Phase 01: GCM_CCM header phase 10: GCM_CCM payload phase...
  • Page 752 Cryptographic processor (CRYP) RM0090 Bits 19 and 5:3 ALGOMODE[3:0]: Algorithm mode 0000: TDES-ECB (triple-DES Electronic codebook): no feedback between blocks of data. Initialization vectors (CRYP_IV0(L/R)) are not used, three key vectors (K1, K2, and K3) are used (K0 is not used). 0001: TDES-CBC (triple-DES Cipher block chaining): output block is XORed with the subsequent input block before its entry into the algorithm.
  • Page 753 RM0090 Cryptographic processor (CRYP) 23.6.3 CRYP status register (CRYP_SR) Address offset: 0x04 Reset value: 0x0000 0003 Reserved BUSY OFFU OFNE IFNF IFEM Reserved Bits 31:5 Reserved, must be kept at reset value Bit 4 BUSY: Busy bit 0: The CRYP Core is not processing any data. The reason is either that: –...
  • Page 754 Cryptographic processor (CRYP) RM0090 23.6.4 CRYP data input register (CRYP_DIN) Address offset: 0x08 Reset value: 0x0000 0000 The CRYP_DIN register is the data input register. It is 32-bit wide. It is used to enter up to four 64-bit (TDES) or two 128-bit (AES) plaintext (when encrypting) or ciphertext (when decrypting) blocks into the input FIFO, one 32-bit word at a time.
  • Page 755 RM0090 Cryptographic processor (CRYP) 23.6.5 CRYP data output register (CRYP_DOUT) Address offset: 0x0C Reset value: 0x0000 0000 The CRYP_DOUT register is the data output register. It is read-only and 32-bit wide. It is used to retrieve up to four 64-bit (TDES mode) or two 128-bit (AES mode) ciphertext (when encrypting) or plaintext (when decrypting) blocks from the output FIFO, one 32-bit word at a time.
  • Page 756 Cryptographic processor (CRYP) RM0090 23.6.6 CRYP DMA control register (CRYP_DMACR) Address offset: 0x10 Reset value: 0x0000 0000 Reserved DOEN DIEN Reserved Bits 31:2 Reserved, must be kept at reset value Bit 1 DOEN: DMA output enable 0: DMA for outgoing data transfer is disabled 1: DMA for outgoing data transfer is enabled Bit 0 DIEN: DMA input enable 0: DMA for incoming data transfer is disabled...
  • Page 757 RM0090 Cryptographic processor (CRYP) 23.6.8 CRYP raw interrupt status register (CRYP_RISR) Address offset: 0x18 Reset value: 0x0000 0001 The CRYP_RISR register is the raw interrupt status register. It is a read-only register. On a read, this register gives the current raw status of the corresponding interrupt prior to masking.
  • Page 758 Cryptographic processor (CRYP) RM0090 Bits 31:2 Reserved, must be kept at reset value Bit 1 OUTMIS: Output FIFO service masked interrupt status Gives the interrupt state after masking of the output FIFO service interrupt. 0: Interrupt not pending 1: Interrupt pending Bit 0 INMIS: Input FIFO service masked interrupt status Gives the interrupt state after masking of the input FIFO service interrupt.
  • Page 759 RM0090 Cryptographic processor (CRYP) CRYP_K1LR (address offset: 0x28) k1.1 k1.2 k1.3 k1.4 k1.5 k1.6 k1.7 k1.8 k1.9 k1.10 k1.11 k1.12 k1.13 k1.14 k1.15 k1.16 b191 b190 b189 b188 b187 b186 b185 b184 b183 b182 b181 b180 b179 b178 b177 b176 k1.17 k1.18 k1.19...
  • Page 760 Cryptographic processor (CRYP) RM0090 CRYP_K3RR (address offset: 0x3C) k3.33 k3.34 k3.35 k3.36 k3.37 k3.38 k3.39 k3.40 k3.41 k3.42 k3.43 k3.44 k3.45 k3.46 k3.47 k3.48 k3.49 k3.50 k3.51 k3.52 k3.53 k3.54 k3.55 k3.56 k3.57 k3.58 k3.59 k3.60 k3.61 k3.62 k3.63 k3.64 Note: Write accesses to these registers are disregarded when the cryptographic processor is busy (bit BUSY = 1 in the CRYP_SR register).
  • Page 761 RM0090 Cryptographic processor (CRYP) CRYP_IV1LR (address offset: 0x48) IV64 IV65 IV66 IV67 IV68 IV69 IV70 IV71 IV72 IV73 IV74 IV75 IV76 IV77 IV78 IV79 IV80 IV81 IV82 IV83 IV84 IV85 IV86 IV87 IV88 IV89 IV90 IV91 IV92 IV93 IV94 IV95 CRYP_IV1RR (address offset: 0x4C) IV96 IV97...
  • Page 762 Cryptographic processor (CRYP) RM0090 23.6.12 CRYP context swap registers (CRYP_CSGCMCCM0..7R and CRYP_CSGCM0..7R) for STM32F42xxx and STM32F43xxx Address offset: • CRYP_CSGCMCCM0..7: 0x050 to 0x06C: used for GCM/GMAC or CCM/CMAC alogrithm only • CRYP_CSGCM0..7: 0x070 to 0x08C: used for GCM/GMAC algorithm only Reset value: 0x0000 0000 These registers contain the complete internal register states of the CRYP processor when the GCM/GMAC or CCM/CMAC algorithm is selected.
  • Page 763: Table 114. Cryp Register Map And Reset Values For Stm32F415/417Xx

    RM0090 Cryptographic processor (CRYP) 23.6.13 CRYP register map Table 114. CRYP register map and reset values for STM32F415/417xx Register Offset name and reset value CRYP_CR 0x00 Reserved Reserved 0x00 Reset value 0 0 0 0 0 0 0 0 CRYP_SR 0x04 Reserved Reset value...
  • Page 764: Table 115. Cryp Register Map And Reset Values For Stm32F43Xxx

    Cryptographic processor (CRYP) RM0090 Table 114. CRYP register map and reset values for STM32F415/417xx (continued) Register Offset name and reset value CRYP_IV0RR CRYP_IV0RR 0x44 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 CRYP_IV1LR CRYP_IV1LR 0x48...
  • Page 765 RM0090 Cryptographic processor (CRYP) Table 115. CRYP register map and reset values for STM32F43xxx (continued) Register name Offset reset value CRYP_MISR 0x1C Reserved Reset value CRYP_K0LR CRYP_K0LR 0x20 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 CRYP_K0RR CRYP_K0RR 0x24...
  • Page 766 Cryptographic processor (CRYP) RM0090 Table 115. CRYP register map and reset values for STM32F43xxx (continued) Register name Offset reset value CRYP_ CSGCMCCM CRYP_CSGCMCCM4R 0x60 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 CRYP_ CSGCMCCM CRYP_CSGCMCCM5R...
  • Page 767: Figure 232. Block Diagram

    RM0090 Random number generator (RNG) Random number generator (RNG) This section applies to the whole STM32F4xx family, unless otherwise specified. 24.1 RNG introduction The RNG processor is a random number generator, based on a continuous analog noise, that provides a random 32-bit value to the host when read. The RNG passed the FIPS PUB 140-2 (2001 October 10) tests with a success ratio of 99%.
  • Page 768 Random number generator (RNG) RM0090 The analog circuit is made of several ring oscillators whose outputs are XORed to generate the seeds. The RNG_LFSR is clocked by a dedicated clock (RNG_CLK) at a constant frequency, so that the quality of the random number is independent of the HCLK frequency. The contents of the RNG_LFSR are transferred into the data register (RNG_DR) when a significant number of seeds have been introduced into the RNG_LFSR.
  • Page 769 RM0090 Random number generator (RNG) 24.4.1 RNG control register (RNG_CR) Address offset: 0x00 Reset value: 0x0000 0000 Reserved RNGEN Reserved Reserved Bits 31:4 Reserved, must be kept at reset value Bit 3 IE: Interrupt enable 0: RNG Interrupt is disabled 1: RNG Interrupt is enabled.
  • Page 770 Random number generator (RNG) RM0090 Bit 2 SECS: Seed error current status 0: No faulty sequence has currently been detected. If the SEIS bit is set, this means that a faulty sequence was detected and the situation has been recovered. 1: One of the following faulty sequences has been detected: –...
  • Page 771: Table 116. Rng Register Map And Reset Map

    RM0090 Random number generator (RNG) 24.4.4 RNG register map Table 116 gives the RNG register map and reset values. Table 116. RNG register map and reset map Register size Register name Offset reset value RNG_CR 0x00 Reserved 0x0000000 RNG_SR 0x04 Reserved 0x0000000 RNG_DR...
  • Page 772 Hash processor (HASH) RM0090 Hash processor (HASH) This section applies to STM32F415/417xx and STM32F43xxx devices. 25.1 HASH introduction The hash processor is a fully compliant implementation of the secure hash algorithm (SHA-1, SHA-224, SHA-256), the MD5 (message-digest algorithm 5) hash algorithm and the HMAC (keyed-hash message authentication code) algorithm suitable for a variety of applications.
  • Page 773: Figure 233. Block Diagram For Stm32F415/417Xx

    RM0090 Hash processor (HASH) 25.3 HASH functional description Figure 1 shows the block diagram of the hash processor. Figure 233. Block diagram for STM32F415/417xx 32-bit AHB2 bus IN buffer Data register Control and status HASH_DIN registers write into HASH_DIN or write DCAL bit to 1 Interrupt registers or 1 complete block transferred by the DMA...
  • Page 774: Figure 234. Block Diagram For Stm32F43Xxx

    Hash processor (HASH) RM0090 Figure 234. Block diagram for STM32F43xxx 32-bit AHB2 bus IN buffer Data register Control and status HASH_DIN registers write into HASH_DIN or write DCAL bit to 1 Interrupt registers or 1 complete block transferred by the DMA HASH_IMR 16 ×...
  • Page 775 RM0090 Hash processor (HASH) has length 0). You can consider that 32 bits of this bit string forms a 32-bit word. Note that the FIPS PUB 180-1 standard uses the convention that bit strings grow from left to right, and bits can be grouped as bytes (8 bits) or words (32 bits) (but some implementations also use half-words (16 bits), and implicitly, uses the big-endian byte (half-word) ordering.
  • Page 776: Figure 235. Bit, Byte And Half-Word Swapping

    Hash processor (HASH) RM0090 Figure 235. Bit, byte and half-word swapping A-In case of binary data hash, all bits should be swapped as below Bit s w a p pi n g ope r a t i o n D A T A TYPE = bx 1 1 Bits entred with little-Endian format H A S H_D I N b i t 3 1...
  • Page 777 RM0090 Hash processor (HASH) The least significant bit of the message has to be at position 0 (right) in the first word entered into the hash processor, the 32nd bit of the bit string has to be at position 0 in the second word entered into the hash processor and so on.
  • Page 778 Hash processor (HASH) RM0090 Once this is done, writing into HASH_STR with bit DCAL = 1 starts the processing of the last entered block of message by the hash processor. This processing consists in: • Automatically performing the message padding operation: the purpose of this operation is to make the total length of a padded message a multiple of 512.
  • Page 779 RM0090 Hash processor (HASH) value 0x0000 0001. Then an all zero word (0x0000 0000) is added and the message length in a two-word representation, to get a block of 16 x 32-bit words. The HASH computing is performed, and the message digest is then available in the HASH_Hx registers (x = 0...4) for the SHA-1 algorithm.
  • Page 780 Hash processor (HASH) RM0090 The block is initialized by writing the INIT bit to ‘1’ with the MODE bit at ‘1’ and the ALGO bits set to the value corresponding to the desired algorithm. The LKEY bit must also be set during this phase if the key being used is longer than 64 bytes (in this case, the HMAC specifications specify that the hash of the key should be used in place of the real key).
  • Page 781 RM0090 Hash processor (HASH) Procedure where the data are loaded by software The context can be saved only when no block is currently being processed. That is, you must wait for DINIS = 1 (the last block has been processed and the input FIFO is empty) or NBW ≠...
  • Page 782: Figure 236. Hash Interrupt Mapping Diagram

    Hash processor (HASH) RM0090 25.3.8 HASH interrupt There are two individual maskable interrupt sources generated by the HASH processor. They are connected to the same interrupt vector. You can enable or disable the interrupt sources individually by changing the mask bits in the HASH_IMR register.
  • Page 783 RM0090 Hash processor (HASH) Bit 12 DINNE: DIN not empty This bit is set when the HASH_DIN register holds valid data (that is after being written at least once). It is cleared when either the INIT bit (initialization) or the DCAL bit (completion of the previous message processing) is written to 1.
  • Page 784 Hash processor (HASH) RM0090 Bit 3 DMAE: DMA enable 0: DMA transfers disabled 1: DMA transfers enabled. A DMA request is sent as soon as the HASH core is ready to receive data. Note: 1: This bit is cleared by hardware when the DMA asserts the DMA terminal count signal (while transferring the last data of the message).
  • Page 785 RM0090 Hash processor (HASH) 25.4.2 HASH control register (HASH_CR) for STM32F43xxx Address offset: 0x00 Reset value: 0x0000 0000 ALGO[1] LKEY Reserved MDMAT DINNE ALGO[0] MODE DATATYPE DMAE INIT Reserved Reserved Bits 31:19 Reserved, forced by hardware to 0. Bit 17 Reserved, forced by hardware to 0. Bit 16 LKEY: Long key selection This bit selects between short key (≤...
  • Page 786 Hash processor (HASH) RM0090 Bits 11:8 NBW: Number of words already pushed This bitfield reflects the number of words in the message that have already been pushed into the IN FIFO. NBW increments (+1) when a write access is performed to the HASH_DIN register while DINNE = 1.
  • Page 787 RM0090 Hash processor (HASH) Bit 3 DMAE: DMA enable 0: DMA transfers disabled 1: DMA transfers enabled. A DMA request is sent as soon as the HASH core is ready to receive data. Note: 1: This bit is cleared by hardware when the DMA asserts the DMA terminal count signal (while transferring the last data of the message).
  • Page 788 Hash processor (HASH) RM0090 25.4.3 HASH data input register (HASH_DIN) Address offset: 0x04 Reset value: 0x0000 0000 HASH_DIN is the data input register. It is 32-bit wide. It is used to enter the message by blocks of 512 bits. When the HASH_DIN register is written to, the value presented on the AHB databus is ‘pushed’...
  • Page 789 RM0090 Hash processor (HASH) 25.4.4 HASH start register (HASH_STR) Address offset: 0x08 Reset value: 0x0000 0000 The HASH_STR register has two functions: • It is used to define the number of valid bits in the last word of the message entered in the hash processor (that is the number of valid least significant bits in the last data written into the HASH_DIN register) •...
  • Page 790 Hash processor (HASH) RM0090 25.4.5 HASH digest registers (HASH_HR0..4/5/6/7) Address offset: 0x0C to 0x1C (STM32F415/417xx), plus 0x310 to 0x32C (STM32F43xxx) Reset value: 0x0000 0000 These registers contain the message digest result named as: H0, H1, H2, H3 and H4, respectively, in the SHA1 algorithm description Note that in this case, the HASH_H5 to HASH_H7 register is not used, and is read as zero.
  • Page 791 RM0090 Hash processor (HASH) HASH_HR3 Address offset: 0x18 and 0x31C HASH_HR4 Address offset: 0x1C and 0x320 HASH_HR5 Address offset: 0x324 HASH_HR6 Address offset: 0x328 HASH_HR7 Address offset: 0x32C RM0090 Rev 18 791/1749...
  • Page 792 Hash processor (HASH) RM0090 Note: When starting a digest computation for a new bit stream (by writing the INIT bit to 1), these registers assume their reset values. 25.4.6 HASH interrupt enable register (HASH_IMR) Address offset: 0x20 Reset value: 0x0000 0000 Reserved DCIE DINIE...
  • Page 793 RM0090 Hash processor (HASH) 25.4.7 HASH status register (HASH_SR) Address offset: 0x24 Reset value: 0x0000 0001 Reserved BUSY DMAS DCIS DINIS Reserved rc_w0 rc_w0 Bits 31:4 Reserved, forced by hardware to 0. Bit 3 BUSY: Busy bit 0: No block is currently being processed 1: The hash core is processing a block of data Bit 2 DMAS: DMA Status This bit provides information on the DMA interface activity.
  • Page 794 Hash processor (HASH) RM0090 25.4.8 HASH context swap registers (HASH_CSRx) Address offset: 0x0F8 to 0x1C0 • For HASH_CSR0 register: Reset value is 0x0000 0002. • For others registers: Reset value is 0x0000 0000 , except for STM32F43xxx devices where the HASH_CSR2 register reset value is 0x2000 0000 Additional registers are available from 0x1C1 to 0x1CC on STM32F43xxx: •...
  • Page 795: Table 117. Hash Register Map And Reset Values On Stm32F415/417Xx

    RM0090 Hash processor (HASH) 25.4.9 HASH register map Table 9 gives the summary HASH register map and reset values. Table 117. HASH register map and reset values on STM32F415/417xx Register size Register name Offset reset value HASH_CR 0x00 Reserved Reset value 0 0 0 0 0 0 0 0 0 0 0 HASH_DIN DATAIN...
  • Page 796: Table 118. Hash Register Map And Reset Values On Stm32F43Xxx

    Hash processor (HASH) RM0090 Table 117. HASH register map and reset values on STM32F415/417xx (continued) Register size Register name Offset reset value HASH_HR2 0x318 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 HASH_HR3 0x31C Reset value...
  • Page 797 RM0090 Hash processor (HASH) Table 118. HASH register map and reset values on STM32F43xxx (continued) Register size Register name Offset reset value HASH_CSR0 CSR0 0xF8 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 1 0 HASH_CSR53 CSR53 0x1CC...
  • Page 798 Real-time clock (RTC) RM0090 Real-time clock (RTC) This section applies to the whole STM32F4xx family, unless otherwise specified. 26.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.
  • Page 799 RM0090 Real-time clock (RTC) 26.2 RTC main features The RTC unit main features are the following (see Figure 237: RTC block diagram): • Calendar with subseconds, seconds, minutes, hours (12 or 24 format), day (day of week), date (day of month), month, and year. •...
  • Page 800 Real-time clock (RTC) RM0090 Figure 237. RTC block diagram RTC_TAMP3 Backup registers TAMPxF RTC_TAMP2 and RTC tamper control register RTC_TAMP1 Time stamp RTC_TS registers RTC_REFIN LSE (32.768 Hz) HSE/32 RTCCLK ck_apre ck_spre RTC_CALR RTC_PRER RTC_PRER (default 256 Hz (default 1 Hz) Asynchronous Synchronous Smooth...
  • Page 801 RM0090 Real-time clock (RTC) 26.3 RTC functional description 26.3.1 Clock and prescalers The RTC clock source (RTCCLK) is selected through the clock controller among the LSE clock, the LSI oscillator clock, and the HSE clock. For more information on the RTC clock source configuration, refer to Section 7: Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC)
  • Page 802 Real-time clock (RTC) RM0090 26.3.2 Real-time clock and calendar The RTC calendar time and date registers are accessed through shadow registers which are synchronized with PCLK1 (APB1 clock). They can also be accessed directly in order to avoid waiting for the synchronization duration. •...
  • Page 803 RM0090 Real-time clock (RTC) The wakeup timer clock input can be: • RTC clock (RTCCLK) divided by 2, 4, 8, or 16. When RTCCLK is LSE(32.768kHz), this allows configuring the wakeup interrupt period from 122 µs to 32 s, with a resolution down to 61µs. •...
  • Page 804 Real-time clock (RTC) RM0090 Calendar initialization and configuration To program the initial time and date calendar values, including the time format and the prescaler configuration, the following sequence is required: Set INIT bit to 1 in the RTC_ISR register to enter initialization mode. In this mode, the calendar counter is stopped and its value can be updated.
  • Page 805 RM0090 Real-time clock (RTC) Programming the wakeup timer The following sequence is required to configure or change the wakeup timer auto-reload value (WUT[15:0] in RTC_WUTR): Clear WUTE in RTC_CR to disable the wakeup timer. Poll WUTWF until it is set in RTC_ISR to make sure the access to wakeup auto-reload counter and to WUCKSEL[2:0] bits is allowed.
  • Page 806 Real-time clock (RTC) RM0090 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.
  • Page 807 RM0090 Real-time clock (RTC) However, increasing PREDIV_S means that PREDIV_A must be decreased in order to maintain the synchronous prescaler’s output at 1 Hz. In this way, the frequency of the asynchronous prescaler’s output increases, which may increase the RTC dynamic consumption.
  • Page 808 Real-time clock (RTC) RM0090 When the reference clock detection is enabled, PREDIV_A and PREDIV_S must be set to their default values: • PREDIV_A = 0x007F • PREDIV_S = 0x00FF Note: The reference clock detection is not available in Standby mode. Caution: The reference clock detection feature cannot be used in conjunction with the coarse digital calibration: RTC_CALIBR must be kept at 0x0000 0000 when REFCKON=1.
  • Page 809 RM0090 Real-time clock (RTC) either shortened by 256 or lengthened by 128 RTCCLK cycles, given that each ck_apre cycle represents 128 RTCCLK cycles (with PREDIV_A+1=128). Therefore each calibration step has the effect of adding 512 or subtracting 256 oscillator cycles for every 125829120 RTCCLK cycles (64min x 60 s/min x 32768 cycles/s). This is equivalent to +4.069 ppm or -2.035 ppm per calibration step.
  • Page 810 Real-time clock (RTC) RM0090 set to a value less than 3, CALP is ignored and the calibration operates as if CALP was equal to 0. To perform a calibration with PREDIV_A less than 3, the synchronous prescaler value (PREDIV_S) should be reduced so that each second is accelerated by 8 RTCCLK clock cycles, which is equivalent to adding 256 clock cycles every 32 seconds.
  • Page 811 RM0090 Real-time clock (RTC) Poll the RTC_ISR/RECALPF (re-calibration pending flag). If it is set to 0, write a new value to RTC_CALR, if necessary. RECALPF is then automatically set to 1 Within three ck_apre cycles after the write operation to RTC_CALR, the new calibration settings take effect.
  • Page 812 Real-time clock (RTC) RM0090 when the V power is switched off. They are not reset by system reset or when the device wakes up from Standby mode. They are reset by a backup domain reset The backup registers are reset when a tamper detection event occurs (see Section 26.6.20: RTC backup registers (RTC_BKPxR) Tamper detection initialization on page...
  • Page 813 RM0090 Real-time clock (RTC) samples are observed at the level designated by the TAMPxTRG bits (TAMP1TRG/TAMP2TRG). The TAMPER inputs are pre-charged through the I/O internal pull-up resistance before its state is sampled, unless disabled by setting TAMPPUDIS to 1,The duration of the precharge is determined by the TAMPPRCH bits, allowing for larger capacitances on the tamper inputs.
  • Page 814: Table 119. Effect Of Low-Power Modes On Rtc

    Real-time clock (RTC) RM0090 The polarity of the output is determined by the POL control bit in RTC_CR so that the opposite of the selected flag bit is output when POL is set to 1. Alarm alternate function output RTC_ALARM can be configured in output open drain or output push-pull using the control bit ALARMOUTTYPE in the RTC_TAFCR register.
  • Page 815: Table 120. Interrupt Control Bits

    RM0090 Real-time clock (RTC) Configure and enable the EXTI Line 21 in interrupt mode and select the rising edge sensitivity. Configure and Enable the TAMP_STAMP IRQ channel in the NVIC. Configure the RTC to detect the RTC timestamp event. Table 120. Interrupt control bits Enable Exit the Exit the...
  • Page 816 Bits 14:12 MNT[2:0]: Minute tens in BCD format Bit 11:8 MNU[3:0]: Minute units in BCD format Bit 7 Reserved, must be kept at reset value. Bits 6:4 ST[2:0]: Second tens in BCD format Bits 3:0 SU[3:0]: Second units in BCD format Note: This register is write protected.
  • Page 817 RM0090 Real-time clock (RTC) 26.6.2 RTC date register (RTC_DR) The RTC_DR is the calendar date shadow register. This register must be written in initialization mode only. Refer to Calendar initialization and configuration on page 804 Reading the calendar on page 805.
  • Page 818 Real-time clock (RTC) RM0090 26.6.3 RTC control register (RTC_CR) Address offset: 0x08 Backup domain reset value: 0x0000 0000 System reset: not affected OSEL[1:0] COSEL SUB1H ADD1H Reserved BYPS TSIE WUTIE ALRBIE ALRAIE WUTE ALRBE ALRAE REFCKON TSEDGE WUCKSEL[2:0] Bits 31:24 Reserved, must be kept at reset value. Bit 23 COE: Calibration output enable This bit enables the RTC_CALIB output 0: Calibration output disabled...
  • Page 819 RM0090 Real-time clock (RTC) Bit 16 ADD1H: Add 1 hour (summer time change) When this bit is set, 1 hour is added to the calendar time. This bit is always read as 0. 0: No effect 1: Adds 1 hour to the current time. This can be used for summer time change outside initialization mode.
  • Page 820 Real-time clock (RTC) RM0090 Bit 4 REFCKON: Reference clock detection enable (50 or 60 Hz) 0: Reference clock detection disabled 1: Reference clock detection enabled Note: PREDIV_S must be 0x00FF. Bit 3 TSEDGE: Timestamp event active edge 0: TIMESTAMP rising edge generates a timestamp event 1: TIMESTAMP falling edge generates a timestamp event TSE must be reset when TSEDGE is changed to avoid unwanted TSF setting Bits 2:0 WUCKSEL[2:0]: Wakeup clock selection...
  • Page 821 RM0090 Real-time clock (RTC) Bits 31:17 Reserved Bit 16 RECALPF: Recalibration pending Flag The RECALPF status flag is automatically set to ‘1’ when software writes to the RTC_CALR register, indicating that the RTC_CALR register is blocked. When the new calibration settings are taken into account, this bit returns to ‘0’.
  • Page 822 Real-time clock (RTC) RM0090 Bit 5 RSF: Registers synchronization flag This bit is set by hardware each time the calendar registers are copied into the shadow registers (RTC_SSRx, RTC_TRx and RTC_DRx). This bit is cleared by hardware in initialization mode, while a shift operation is pending (SHPF=1), or when in bypass shadow register mode (BYPSHAD=1).
  • Page 823 RM0090 Real-time clock (RTC) 26.6.5 RTC prescaler register (RTC_PRER) Address offset: 0x10 Backup domain reset value: 0x007F 00FF System reset: not affected PREDIV_A[6:0] Reserved PREDIV_S[14:0] Res. Bits 31:24 Reserved Bit 23 Reserved, must be kept at reset value. Bits 22:16 PREDIV_A[6:0]: Asynchronous prescaler factor This is the asynchronous division factor: ck_apre frequency = RTCCLK frequency/(PREDIV_A+1) Bit 15 Reserved, must be kept at reset value.
  • Page 824 Real-time clock (RTC) RM0090 Bits 31:16 Reserved Bits 15:0 WUT[15:0]: Wakeup auto-reload value bits When the wakeup timer is enabled (WUTE set to 1), the WUTF flag is set every (WUT[15:0] + 1) ck_wut cycles. The ck_wut period is selected through WUCKSEL[2:0] bits of the RTC_CR register When WUCKSEL[2] = 1, the wakeup timer becomes 17-bits and WUCKSEL[1] effectively becomes WUT[16] the most-significant bit to be reloaded into the timer.
  • Page 825 Bit 7 MSK1: Alarm A seconds mask 0: Alarm A set if the seconds match 1: Seconds don’t care in Alarm A comparison Bits 6:4 ST[2:0]: Second tens in BCD format. Bits 3:0 SU[3:0]: Second units in BCD format. RM0090 Rev 18...
  • Page 826 Bit 7 MSK1: Alarm B seconds mask 0: Alarm B set if the seconds match 1: Seconds don’t care in Alarm B comparison Bits 6:4 ST[2:0]: Second tens in BCD format Bits 3:0 SU[3:0]: Second units in BCD format 826/1749...
  • Page 827 RM0090 Real-time clock (RTC) 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 803.
  • Page 828 Real-time clock (RTC) RM0090 26.6.12 RTC shift control register (RTC_SHIFTR) Address offset: 0x2C Backup domain reset value: 0x0000 0000 System reset: not affected ADD1S Reserved Res. SUBFS[14:0] Bit 31 ADD1S: Add one second 0: No effect 1: Add one second to the clock/calendar This bit is write only and is always read as zero.
  • Page 829 Bits 14:12 MNT[2:0]: Minute tens in BCD format. Bits 11:8 MNU[3:0]: Minute units in BCD format. Bit 7 Reserved, must be kept at reset value. Bits 6:4 ST[2:0]: Second tens in BCD format. Bits 3:0 SU[3:0]: Second units in BCD format. Note: The content of this register is valid only when TSF is set to 1 in RTC_ISR.
  • Page 830 Real-time clock (RTC) RM0090 26.6.15 RTC timestamp sub second register (RTC_TSSSR) Address offset: 0x38 Backup domain reset value: 0x0000 0000 System reset: not affected Reserved SS[15:0] Bits 31:16 Reserved Bits 15:0 SS: Sub second value SS[15:0] is the value of the synchronous prescaler’s counter when the timestamp event occurred.
  • Page 831 RM0090 Real-time clock (RTC) Bits 31:16 Reserved Bit 15 CALP: Increase frequency of RTC by 488.5 ppm 0: No RTCCLK pulses are added. 1: One RTCCLK pulse is effectively inserted every 2 pulses (frequency increased by 488.5 ppm). This feature is intended to be used in conjunction with CALM, which lowers the frequency of the calendar with a fine resolution.
  • Page 832 Real-time clock (RTC) RM0090 26.6.17 RTC tamper and alternate function configuration register (RTC_TAFCR) Address offset: 0x40 Backup domain reset value: 0x0000 0000 System reset: not affected ALARMOUT TSIN TAMP1 TYPE INSEL Reserved TAMP- TAMP- TAMPT TAMP2 TAMP2 TAMP1 TAMP1 TAMPFLT[1:0] TAMPFREQ[2:0] TAMPIE PUDIS...
  • Page 833 RM0090 Real-time clock (RTC) Bits 12:11 TAMPFLT[1:0]: Tamper filter count These bits determines the number of consecutive samples at the specified level (TAMP*TRG) necessary to activate a Tamper event. TAMPFLT is valid for each of the tamper inputs. 0x0: Tamper is activated on edge of tamper input transitions to the active level (no internal pull-up on tamper input).
  • Page 834 Real-time clock (RTC) RM0090 Bit 1 TAMP1TRG: Active level for tamper 1 if TAMPFLT != 00 0: TAMPER1 staying low triggers a tamper detection event. 1: TAMPER1 staying high triggers a tamper detection event. if TAMPFLT = 00: 0: TAMPER1 rising edge triggers a tamper detection event. 1: TAMPER1 falling edge triggers a tamper detection event.
  • Page 835 RM0090 Real-time clock (RTC) 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 803 26.6.19 RTC alarm B sub second register (RTC_ALRMBSSR) Address offset: 0x48...
  • Page 836: Table 121. Rtc Register Map And Reset Values

    This register is reset on a tamper detection event, as long as TAMPxF=1. 26.6.21 RTC register map Table 121. RTC register map and reset values Offset Register RTC_TR HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0] [1:0] 0x00 Reserved Reset value RTC_DR YT[3:0] YU[3:0] WDU[2:0]...
  • Page 837 RM0090 Real-time clock (RTC) Table 121. RTC register map and reset values (continued) Offset Register RTC_ALRMAR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0] [1:0] [1:0] 0x1C Reset value RTC_ALRMBR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0] [1:0] [1:0] 0x20 Reset value RTC_WPR...
  • Page 838 Real-time clock (RTC) RM0090 Refer to Section 2.3: Memory map for the register boundary addresses. Caution: Table 121, the reset value is the value after a backup domain reset. The majority of the registers are not affected by a system reset. For more information, please refer to Section 26.3.7: Resetting the RTC.
  • Page 839 RM0090 Inter-integrated circuit (I2C) interface Inter-integrated circuit (I2C) interface This section applies to the whole STM32F4xx family, unless otherwise specified. 27.1 C introduction C (inter-integrated circuit) bus Interface serves as an interface between the microcontroller and the serial I C bus. It provides multimaster capability, and controls all I C bus-specific sequencing, protocol, arbitration and timing.
  • Page 840 Inter-integrated circuit (I2C) interface RM0090 – 1 Interrupt for successful address/ data communication – 1 Interrupt for error condition • Optional clock stretching • 1-byte buffer with DMA capability • Configurable PEC (packet error checking) generation or verification: – PEC value can be transmitted as last byte in Tx mode –...
  • Page 841: Figure 238. I2C Bus Protocol

    RM0090 Inter-integrated circuit (I2C) interface 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.
  • Page 842: Figure 239. I2C Block Diagram For Stm32F40X/41X

    Inter-integrated circuit (I2C) interface RM0090 Figure 239. I C block diagram for STM32F40x/41x Data register Data Noise Data shift register control filter PEC calculation Comparator Own address register Dual address register Clock Noise PEC register control filter Clock control Register (CCR) Control registers (CR1&CR2) Control...
  • Page 843: Figure 240. I2C Block Diagram For Stm32F42X/43X

    RM0090 Inter-integrated circuit (I2C) interface Figure 240. I C block diagram for STM32F42x/43x Data register Data Noise Data shift register control filter PEC calculation Comparator Own address register Dual address register Clock Noise PEC register control filter Clock control Register (CCR) Control registers (CR1&CR2) Control...
  • Page 844 Inter-integrated circuit (I2C) interface RM0090 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: •...
  • Page 845: Figure 241. Transfer Sequence Diagram For Slave Transmitter

    RM0090 Inter-integrated circuit (I2C) interface Figure 241. Transfer sequence diagram for slave transmitter 7-bit slave transmitter S Address Data1 Data2 DataN NA P ..EV1 EV3-1 EV3 EV3-2 10-bit slave transmitter S Header Address Header A Data1 ..DataN NA P EV1 EV3_1 EV3-2 Legend: S= Start, S...
  • Page 846: Figure 242. Transfer Sequence Diagram For Slave Receiver

    Inter-integrated circuit (I2C) interface RM0090 Figure 242. Transfer sequence diagram for slave receiver 7-bit slave receiver S Address Data1 Data2 DataN ..10-bit slav e receiver S Header Address Data1 DataN ..Legend: S= Start, S = Repeated Start, P= Stop, A= Acknowledge, EVx= Event (with interrupt if ITEVFEN=1) EV1: ADDR=1, cleared by reading SR1 followed by reading SR2 EV2: RxNE=1 cleared by reading DR register.
  • Page 847 RM0090 Inter-integrated circuit (I2C) interface SCL master clock generation The CCR bits are used to generate the high and low level of the SCL clock, starting from the generation of the rising and falling edge (respectively). As a slave may stretch the SCL line, the peripheral checks the SCL input from the bus at the end of the time programmed in TRISE bits after rising edge generation.
  • Page 848 Inter-integrated circuit (I2C) interface RM0090 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. –...
  • Page 849: Figure 243. Transfer Sequence Diagram For Master Transmitter

    RM0090 Inter-integrated circuit (I2C) interface Figure 243. Transfer sequence diagram for master transmitter 7-bit master transmitter Address Data1 Data2 DataN ..EV6 EV8_1 EV8_2 10-bit master transmitter Header Address Data1 DataN ..EV8_1 EV8_2 Legend: S= Start, S = Repeated Start, P= Stop, A= Acknowledge, EVx= Event (with interrupt if ITEVFEN = 1) EV5: SB=1, cleared by reading SR1 register followed by writing DR register with Address.
  • Page 850: Figure 244. Transfer Sequence Diagram For Master Receiver

    Inter-integrated circuit (I2C) interface RM0090 Figure 244. Transfer sequence diagram for master receiver 7-bit master receiver Address Data1 Data2 DataN ..EV7_1 10-bit master receiver Header Address Data1 Data2 DataN Header ..EV7_1 Leg end : S= Start, S = Repeated Start, P= Stop, A= Acknowledge, NA= Non-acknowledge, EVx= Event (with interrupt if ITEVFEN=1) EV5: SB=1, cleared by reading SR1 register followed by writing DR register.
  • Page 851 RM0090 Inter-integrated circuit (I2C) interface For N >2 -byte reception, from N-2 data reception • Wait until BTF = 1 (data N-2 in DR, data N-1 in shift register, SCL stretched low until data N-2 is read) • Set ACK low •...
  • Page 852: Table 122. Maximum Dnf[3:0] Value To Be Compliant With Thd:dat(Max)

    Inter-integrated circuit (I2C) interface RM0090 Overrun/underrun error (OVR) An overrun error can occur in slave mode when clock stretching is disabled and the I interface is receiving data. The interface has received a byte (RxNE=1) and the data in DR has not been read, before the next byte is received by the interface.
  • Page 853 RM0090 Inter-integrated circuit (I2C) interface Table 122. Maximum DNF[3:0] value to be compliant with Thd:dat(max) (continued) Maximum DNF value PCLK1 frequency Sm mode Fm mode 30 < F <= 40 PCLK1 40 < F <= 50 PCLK1 Note: For each frequency range, the constraint is given based on the worst case which is the minimum frequency of the range.
  • Page 854: Table 123. Smbus Vs. I2C

    Inter-integrated circuit (I2C) interface RM0090 Differences between SMBus and I The following table describes the differences between SMBus and I Table 123. SMBus vs. I SMBus Max. speed 100 kHz Max. speed 400 kHz Min. clock speed 10 kHz No minimum clock speed 35 ms clock low timeout No timeout Logic levels are fixed...
  • Page 855 RM0090 Inter-integrated circuit (I2C) interface For the details on 128-bit UDID and more information on ARP, refer to SMBus specification version 2.0. SMBus alert mode SMBus Alert is an optional signal with an interrupt line for devices that want to trade their ability to master for a pin.
  • Page 856 Inter-integrated circuit (I2C) interface RM0090 27.3.8 DMA requests DMA requests (when enabled) are generated only for data transfer. DMA requests are generated by Data Register becoming empty in transmission and Data Register becoming full in reception. The DMA must be initialized and enabled before the I2C data transfer. The DMAEN bit must be set in the I2C_CR2 register before the ADDR event.
  • Page 857 RM0090 Inter-integrated circuit (I2C) interface Reception using DMA DMA mode can be enabled for reception by setting the DMAEN bit in the I2C_CR2 register. Data will be loaded from the I2C_DR register to a Memory area configured using the DMA peripheral (refer to the DMA specification) whenever a data byte is received.
  • Page 858: Table 124. I2C Interrupt Requests

    Inter-integrated circuit (I2C) interface RM0090 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. •...
  • Page 859: Figure 245. I2C Interrupt Mapping Diagram

    RM0090 Inter-integrated circuit (I2C) interface Figure 245. I C interrupt mapping diagram ITEVFEN ADDR ADD10 STOPF it_event ITBUFEN RxNE ITERREN BERR ARLO it_error PECERR TIMEOUT SMBALERT MS42082V1 RM0090 Rev 18 859/1749...
  • Page 860 Inter-integrated circuit (I2C) interface RM0090 27.5 C debug mode ® When the microcontroller enters the debug mode (Cortex -M4 with FPU core halted), the SMBUS timeout either continues to work normally or stops, depending on the DBG_I2Cx_SMBUS_TIMEOUT configuration bits in the DBG module. For more details, refer to Section 38.16.2: Debug support for timers, watchdog, bxCAN and I 27.6...
  • Page 861 RM0090 Inter-integrated circuit (I2C) interface Bit 10 ACK: Acknowledge enable This bit is set and cleared by software and cleared by hardware when PE=0. 0: No acknowledge returned 1: Acknowledge returned after a byte is received (matched address or data) Bit 9 STOP: Stop generation The bit is set and cleared by software, cleared by hardware when a Stop condition is detected, set by hardware when a timeout error is detected.
  • Page 862 Inter-integrated circuit (I2C) interface RM0090 Bit 2 Reserved, must be kept at reset value Bit 1 SMBUS: SMBus mode 0: I C mode 1: SMBus mode Bit 0 PE: Peripheral enable 0: Peripheral disable 1: Peripheral enable Note: If this bit is reset while a communication is on going, the peripheral is disabled at the end of the current communication, when back to IDLE state.
  • Page 863 RM0090 Inter-integrated circuit (I2C) interface Bit 9 ITEVTEN: Event interrupt enable 0: Event interrupt disabled 1: Event interrupt enabled This interrupt is generated when: – SB = 1 (Master) – ADDR = 1 (Master/Slave) – ADD10= 1 (Master) – STOPF = 1 (Slave) –...
  • Page 864 Inter-integrated circuit (I2C) interface RM0090 27.6.3 C Own address register 1 (I2C_OAR1) Address offset: 0x08 Reset value: 0x0000 ADD[9:8] ADD[7:1] ADD0 MODE Reserved Bit 15 ADDMODE Addressing mode (slave mode) 0: 7-bit slave address (10-bit address not acknowledged) 1: 10-bit slave address (7-bit address not acknowledged) Bit 14 Should always be kept at 1 by software.
  • Page 865 RM0090 Inter-integrated circuit (I2C) interface 27.6.5 C Data register (I2C_DR) Address offset: 0x10 Reset value: 0x0000 DR[7:0] Reserved Bits 15:8 Reserved, must be kept at reset value Bits 7:0 DR[7:0] 8-bit data register Byte received or to be transmitted to the bus. –...
  • Page 866 Inter-integrated circuit (I2C) interface RM0090 Bit 14 TIMEOUT: Timeout or Tlow error 0: No timeout error 1: SCL remained LOW for 25 ms (Timeout) Master cumulative clock low extend time more than 10 ms (Tlow:mext) Slave cumulative clock low extend time more than 25 ms (Tlow:sext) –...
  • Page 867 RM0090 Inter-integrated circuit (I2C) interface Bit 8 BERR: Bus error 0: No misplaced Start or Stop condition 1: Misplaced Start or Stop condition – Set by hardware when the interface detects an SDA rising or falling edge while SCL is high, occurring in a non-valid position during a byte transfer.
  • Page 868 Inter-integrated circuit (I2C) interface RM0090 Bit 2 BTF: Byte transfer finished 0: Data byte transfer not done 1: Data byte transfer succeeded – Set by hardware when NOSTRETCH=0 and: – In reception when a new byte is received (including ACK pulse) and DR has not been read yet (RxNE=1).
  • Page 869 RM0090 Inter-integrated circuit (I2C) interface Bits 15:8 PEC[7:0] Packet error checking register This register contains the internal PEC when ENPEC=1. Bit 7 DUALF: Dual flag (Slave mode) 0: Received address matched with OAR1 1: Received address matched with OAR2 – Cleared by hardware after a Stop condition or repeated Start condition, or when PE=0. Bit 6 SMBHOST: SMBus host header (Slave mode) 0: No SMBus Host address 1: SMBus Host address received when SMBTYPE=1 and ENARP=1.
  • Page 870 Inter-integrated circuit (I2C) interface RM0090 27.6.8 C Clock control register (I2C_CCR) Address offset: 0x1C Reset value: 0x0000 Note: must be at least 2 MHz to achieve Sm mode I²C frequencies. It must be at least 4 PCLK1 MHz to achieve Fm mode I²C frequencies. It must be a multiple of 10MHz to reach the 400 kHz maximum I²C Fm mode clock.
  • Page 871 RM0090 Inter-integrated circuit (I2C) interface 27.6.9 C TRISE register (I2C_TRISE) Address offset: 0x20 Reset value: 0x0002 TRISE[5:0] Reserved Bits 15:6 Reserved, must be kept at reset value Bits 5:0 TRISE[5:0]: Maximum rise time in Fm/Sm mode (Master mode) These bits should provide the maximum duration of the SCL feedback loop in master mode. The purpose is to keep a stable SCL frequency whatever the SCL rising edge duration.
  • Page 872: Table 125. I2C Register Map And Reset Values

    Inter-integrated circuit (I2C) interface RM0090 27.6.11 C register map The table below provides the I C register map and reset values. Table 125. I C register map and reset values Offset Register I2C_CR1 0x00 Reserved Reset value I2C_CR2 FREQ[5:0] 0x04 Reserved Reset value I2C_OAR1...
  • Page 873 RM0090 Serial peripheral interface (SPI) Serial peripheral interface (SPI) This section applies to the whole STM32F4xx family, unless otherwise specified. 28.1 SPI introduction The SPI interface provides two main functions, supporting either the SPI protocol or the I audio protocol. By default, it is the SPI function that is selected. It is possible to switch the interface from SPI to I S by software.
  • Page 874 Serial peripheral interface (SPI) RM0090 28.2 SPI and I S main features 28.2.1 SPI features • Full-duplex synchronous transfers on three lines • Simplex synchronous transfers on two lines with or without a bidirectional data line • 8- or 16-bit transfer frame format selection •...
  • Page 875 RM0090 Serial peripheral interface (SPI) 28.2.2 S features • Full duplex communication • Half-duplex communication (only transmitter or receiver) • Master or slave operations • 8-bit programmable linear prescaler to reach accurate audio sample frequencies (from 8 kHz to 192 kHz) •...
  • Page 876: Figure 246. Spi Block Diagram

    Serial peripheral interface (SPI) RM0090 28.3 SPI functional description 28.3.1 General description The block diagram of the SPI is shown in Figure 246. Figure 246. SPI block diagram Address and data bus Read Rx buffer SPI_CR2 MOSI RXNE TXDM RXDM SSOE Shift register MISO...
  • Page 877: Figure 247. Single Master/ Single Slave Application

    RM0090 Serial peripheral interface (SPI) Figure 247. Single master/ single slave application Master Slave MSBit LSBit MSBit LSBit MISO MISO 8-bit shift register 8-bit shift register MOSI MOSI SPI clock generator Not used if NSS is managed by software ai14745 1.
  • Page 878 Serial peripheral interface (SPI) RM0090 Clock phase and clock polarity Four possible timing relationships may be chosen by software, using the CPOL and CPHA bits in the SPI_CR1 register. The CPOL (clock polarity) bit controls the steady state value of the clock when no data is being transferred.
  • Page 879: Figure 248. Data Clock Timing Diagram

    RM0090 Serial peripheral interface (SPI) Figure 248. Data clock timing diagram CPHA =1 CPOL = 1 CPOL = 0 MOSI LSBit MSBit MISO LSBit MSBit (to slave) Capture strobe CPHA =0 CPOL = 1 CPOL = 0 MOSI LSBit MSBit MISO MSBit LSBit...
  • Page 880 Serial peripheral interface (SPI) RM0090 28.3.2 Configuring the SPI in slave mode In the slave configuration, the serial clock is received on the SCK pin from the master device. The value set in the BR[2:0] bits in the SPI_CR1 register, does not affect the data transfer rate.
  • Page 881: Figure 249. Ti Mode - Slave Mode, Single Transfer

    RM0090 Serial peripheral interface (SPI) 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.
  • Page 882: Figure 250. Ti Mode - Slave Mode, Continuous Transfer

    Serial peripheral interface (SPI) RM0090 Figure 250. TI mode - Slave mode, continuous transfer input trigger sampling trigger sampling trigger sampling input DONTCARE MSBIN LSBIN MSBIN LSBIN DONTCARE MOSI input MISO LSBOUT MSBOUT LSBOUT 1 or 0 MSBOUT output FRAME 1 FRAME 2 ai18435 28.3.3...
  • Page 883: Figure 251. Ti Mode - Master Mode, Single Transfer

    RM0090 Serial peripheral interface (SPI) 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.
  • Page 884: Figure 252. Ti Mode - Master Mode, Continuous Transfer

    Serial peripheral interface (SPI) RM0090 Figure 252. TI mode - master mode, continuous transfer output trigger sampling trigger sampling trigger sampling output MOSI DONTCARE MSBOUT LSBOUT MSBOUT LSBOUT output MISO LSBIN MSBIN LSBIN DONTCARE 1 or 0 MSBIN intput FRAME 1 FRAME 2 ai18437 28.3.4...
  • Page 885 RM0090 Serial peripheral interface (SPI) 28.3.5 Data transmission and reception procedures Rx and Tx buffers In reception, data are received and then stored into an internal Rx buffer while In transmission, data are first stored into an internal Tx buffer before being transmitted. A read access of the SPI_DR register returns the Rx buffered value whereas a write access to the SPI_DR stores the written data into the Tx buffer.
  • Page 886 Serial peripheral interface (SPI) RM0090 pin. The software must have written the data to be sent before the SPI master device initiates the transfer. • In unidirectional receive-only mode (BIDIMODE=0 and RXONLY=1) – The sequence begins when the slave device receives the clock signal and the first bit of the data on its MOSI pin.
  • Page 887: Figure 253. Txe/Rxne/Bsy Behavior In Master / Full-Duplex Mode

    RM0090 Serial peripheral interface (SPI) Enable the SPI by setting the SPE bit to 1. Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag). Wait until TXE=1 and write the second data item to be transmitted. Then wait until RXNE=1 and read the SPI_DR to get the first received data item (this clears the RXNE bit).
  • Page 888: Figure 254. Txe/Rxne/Bsy Behavior In Slave / Full-Duplex Mode

    Serial peripheral interface (SPI) RM0090 Figure 254. TXE/RXNE/BSY behavior in Slave / full-duplex mode (BIDIMODE=0, RXONLY=0) in case of continuous transfers Example in Slave mode with CPOL=1, CPHA=1 DATA 1 = 0xF1 DATA 2 = 0xF2 DATA 3 = 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 set by hardware...
  • Page 889: Figure 255. Txe/Bsy Behavior In Master Transmit-Only Mode (Bidimode=0 And Rxonly=0)

    RM0090 Serial peripheral interface (SPI) Figure 255. 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 DATA 1 = 0xF1 DATA 2 = 0xF2 DATA 3 = 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 set by hardware...
  • Page 890: Figure 257. Rxne Behavior In Receive-Only Mode (Bidirmode=0 And Rxonly=1)

    Serial peripheral interface (SPI) RM0090 Set the RXONLY bit in the SPI_CR1 register. Enable the SPI by setting the SPE bit to 1: In master mode, this immediately activates the generation of the SCK clock, and data are serially received until the SPI is disabled (SPE=0). In slave mode, data are received when the SPI master device drives NSS low and generates the SCK clock.
  • Page 891: Figure 258. Txe/Bsy Behavior When Transmitting (Bidirmode=0 And Rxonly=0)

    RM0090 Serial peripheral interface (SPI) In slave mode, the continuity of the communication is decided by the SPI master device. In any case, even if the communication is continuous, the BSY flag goes low between each transfer for a minimum duration of one SPI clock cycle (see Figure 256).
  • Page 892 Serial peripheral interface (SPI) RM0090 Program the CPOL, CPHA, LSBFirst, BR, SSM, SSI and MSTR values. Program the polynomial in the SPI_CRCPR register. Enable the CRC calculation by setting the CRCEN bit in the SPI_CR1 register. This also clears the SPI_RXCRCR and SPI_TXCRCR registers. Enable the SPI by setting the SPE bit in the SPI_CR1 register.
  • Page 893 RM0090 Serial peripheral interface (SPI) 28.3.7 Status flags Four status flags are provided for the application to completely monitor the state of the SPI bus. Tx buffer empty flag (TXE) When it is set, this flag indicates that the Tx buffer is empty and the next data to be transmitted can be loaded into the buffer.
  • Page 894 Serial peripheral interface (SPI) RM0090 28.3.8 Disabling the SPI When a transfer is terminated, the application can stop the communication by disabling the SPI peripheral. This is done by clearing the SPE bit. For some configurations, disabling the SPI and entering the Halt mode while a transfer is ongoing can cause the current transfer to be corrupted and/or the BSY flag might become unreliable.
  • Page 895 RM0090 Serial peripheral interface (SPI) In slave receive-only mode (MSTR=0, BIDIMODE=0, RXONLY=1) or bidirectional receive mode (MSTR=0, BIDIMODE=1, BIDOE=0) You can disable the SPI (write SPE=1) at any time: the current transfer will complete before the SPI is effectively disabled Then, if you want to enter the Halt mode, you must first wait until BSY = 0 before entering the Halt mode (or disabling the peripheral clock).
  • Page 896: Figure 259. Transmission Using Dma

    Serial peripheral interface (SPI) RM0090 Figure 259. Transmission using DMA Example with CPOL=1, CPHA=1 DATA 1 = 0xF1 DATA 2 = 0xF2 DATA 3 = 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 set by hardware set by hardware cleared by DMA write...
  • Page 897 RM0090 Serial peripheral interface (SPI) DMA capability with CRC When SPI communication is enabled with CRC communication and DMA mode, the transmission and reception of the CRC at the end of communication are automatic that is without using the bit CRCNEXT. After the CRC reception, the CRC must be read in the SPI_DR register to clear the RXNE flag.
  • Page 898: Table 126. Spi Interrupt Requests

    Serial peripheral interface (SPI) RM0090 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.
  • Page 899: Figure 262. I

    RM0090 Serial peripheral interface (SPI) 28.4 S functional description 28.4.1 S general description The block diagram of the I S is shown in Figure 262. Figure 262. I S block diagram Address and data bus Tx buffer BSY OVR MODF CRC TxE RxNE SIDE 16-bit...
  • Page 900: Figure 263. I2S Full Duplex Block Diagram

    Serial peripheral interface (SPI) RM0090 The I S 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.
  • Page 901 RM0090 Serial peripheral interface (SPI) 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.
  • Page 902: Figure 264. I 2 S Philips Protocol Waveforms (16/32-Bit Full Accuracy, Cpol = 0)

    Serial peripheral interface (SPI) RM0090 Figure 264. I S Philips protocol waveforms (16/32-bit full accuracy, CPOL = 0) transmission reception Can be 16-bit or 32-bit Channel left Channel right MS19591V1 Data are latched on the falling edge of CK (for the transmitter) and are read on the rising edge (for the receiver).
  • Page 903: Figure 267. Receiving 0X8Eaa33

    RM0090 Serial peripheral interface (SPI) Figure 267. Receiving 0x8EAA33 First read to Data register Second read to Data register 0x8EAA 0x33XX Only the 8 MSB are sent to compare the 24 bits 8 LSBs have no meaning and can be anything MS19594V1 Figure 268.
  • Page 904: Figure 270. Msb Justified 16-Bit Or 32-Bit Full-Accuracy Length With Cpol = 0

    Serial peripheral interface (SPI) RM0090 Figure 270. MSB justified 16-bit or 32-bit full-accuracy length with CPOL = 0 Transmission Reception 16- or 32 bit data Channel left Channel right MS30100 V1 Data are latched on the falling edge of CK (for transmitter) and are read on the rising edge (for the receiver).
  • Page 905: Figure 273. Lsb Justified 16-Bit Or 32-Bit Full-Accuracy With Cpol = 0

    RM0090 Serial peripheral interface (SPI) Figure 273. LSB justified 16-bit or 32-bit full-accuracy with CPOL = 0 Transmission Reception 16- or 32-bit data Channel left Channel right MS30103V1 Figure 274. LSB justified 24-bit frame length with CPOL = 0 Reception Transmission 8-bit data 24-bit remaining...
  • Page 906: Figure 276. Operations Required To Receive 0X3478Ae

    Serial peripheral interface (SPI) RM0090 Figure 276. Operations required to receive 0x3478AE First read from Data register Second read from Data register conditioned by RXNE=1 conditioned by RXNE=1 0xXX34 0x78AE Only the 8 LSB of the half-word are significant. A field of 0x00 is forced instead of the 8 MSBs.
  • Page 907: Figure 279. Pcm Standard Waveforms (16-Bit)

    RM0090 Serial peripheral interface (SPI) 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. Figure 279. PCM standard waveforms (16-bit) short frame 13-bits long frame...
  • Page 908: Figure 281. Audio Sampling Frequency Definition

    Serial peripheral interface (SPI) RM0090 Figure 281. Audio sampling frequency definition 16-or 32-bit 16-or 32-bit left right channel channel 32- or 64-bits sampling point sampling point : audio sampling frequency MS30108V1 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.
  • Page 909: Table 127. Audio Frequency Precision (For Pllm Vco = 1 Mhz Or 2 Mhz)

    RM0090 Serial peripheral interface (SPI) Table 127. Audio frequency precision (for PLLM VCO = 1 MHz or 2 MHz) Master Target f Data PLLI2SN PLLI2SR I2SDIV I2SODD Real f (Hz) Error clock (Hz) format 16-bit 8000 0.0000% 8000 32-bit 8000 0.0000% 16-bit 16000...
  • Page 910 Serial peripheral interface (SPI) RM0090 Procedure 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. Select the CKPOL bit to define the steady level for the communication clock.
  • Page 911 RM0090 Serial peripheral interface (SPI) 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.
  • Page 912 Serial peripheral interface (SPI) RM0090 Set the I2SMOD bit in the SPI_I2SCFGR register to reach the I S functionalities and choose the I S 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.
  • Page 913 RM0090 Serial peripheral interface (SPI) 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.
  • Page 914 Serial peripheral interface (SPI) RM0090 Tx buffer empty flag (TXE) When set, this flag indicates that the Tx buffer is empty and the next data to be transmitted can then be loaded into it. The TXE flag is reset when the Tx buffer already contains data to be transmitted.
  • Page 915: Table 128. I 2 S Interrupt Requests

    RM0090 Serial peripheral interface (SPI) 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: Disable the I2S 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).
  • Page 916 Serial peripheral interface (SPI) RM0090 28.5 SPI and I S registers The peripheral registers have to be accessed by half-words (16 bits) or words (32 bits). 28.5.1 SPI control register 1 (SPI_CR1) (not used in I S mode) Address offset: 0x00 Reset value: 0x0000 BIDI BIDI...
  • Page 917 RM0090 Serial peripheral interface (SPI) Bit 10 RXONLY: Receive only This bit combined with the BIDImode bit selects the direction of transfer in 2-line unidirectional mode. This bit is also useful in a multislave system in which this particular slave is not accessed, the output from the accessed slave is not corrupted. 0: Full duplex (Transmit and receive) 1: Output disabled (Receive-only mode) Note: This bit is not used in I...
  • Page 918 Serial peripheral interface (SPI) RM0090 Bit1 CPOL: Clock polarity 0: CK to 0 when idle 1: CK to 1 when idle Note: This bit should not be changed when communication is ongoing. It is not used in I S mode and SPI TI mode. Bit 0 CPHA: Clock phase 0: The first clock transition is the first data capture edge 1: The second clock transition is the first data capture edge...
  • Page 919 RM0090 Serial peripheral interface (SPI) Bit 1 TXDMAEN: Tx buffer DMA enable When this bit is set, the DMA request is made whenever the TXE flag is set. 0: Tx buffer DMA disabled 1: Tx buffer DMA enabled Bit 0 RXDMAEN: Rx buffer DMA enable When this bit is set, the DMA request is made whenever the RXNE flag is set.
  • Page 920 Serial peripheral interface (SPI) RM0090 Bit 3 UDR: Underrun flag 0: No underrun occurred 1: Underrun occurred Section 28.4.8: This flag is set by hardware and reset by a software sequence. Refer to Error flags for the software sequence. Note: This bit is not used in SPI mode. Bit 2 CHSIDE: Channel side 0: Channel Left has to be transmitted or has been received 1: Channel Right has to be transmitted or has been received...
  • Page 921 RM0090 Serial peripheral interface (SPI) 28.5.5 SPI CRC polynomial register (SPI_CRCPR) (not used in I mode) Address offset: 0x10 Reset value: 0x0007 CRCPOLY[15:0] Bits 15:0 CRCPOLY[15:0]: CRC polynomial register This register contains the polynomial for the CRC calculation. The CRC polynomial (0007h) is the reset value of this register. Another polynomial can be configured as required.
  • Page 922 Serial peripheral interface (SPI) RM0090 28.5.7 SPI TX CRC register (SPI_TXCRCR) (not used in I S mode) Address offset: 0x18 Reset value: 0x0000 TXCRC[15:0] Bits 15:0 TXCRC[15:0]: Tx CRC register When CRC calculation is enabled, the TxCRC[7:0] bits contain the computed CRC value of the subsequently transmitted bytes.
  • Page 923 RM0090 Serial peripheral interface (SPI) Bit 7 PCMSYNC: PCM frame synchronization 0: Short frame synchronization 1: Long frame synchronization Note: This bit has a meaning only if I2SSTD = 11 (PCM standard is used) It is not used in SPI mode. Bit 6 Reserved: forced at 0 by hardware Bits 5:4 I2SSTD: I2S standard selection 00: I...
  • Page 924 Serial peripheral interface (SPI) RM0090 Bits 15:10 Reserved, must be kept at reset value. Bit 9 MCKOE: Master clock output enable 0: Master clock output is disabled 1: Master clock output is enabled Note: This bit should be configured when the I S is disabled.
  • Page 925: Table 129. Spi Register Map And Reset Values

    RM0090 Serial peripheral interface (SPI) 28.5.10 SPI register map The table provides shows the SPI register map and reset values. Table 129. SPI register map and reset values Offset Register SPI_CR1 BR [2:0] 0x00 Reserved Reset value SPI_CR2 0x04 Reserved Reset value SPI_SR 0x08...
  • Page 926 Serial audio interface (SAI) RM0090 Serial audio interface (SAI) This section applies to the STM32F42xxx and STM32F43xxx family. 29.1 Introduction The SAI interface (serial audio interface) offers a wide set of audio protocols due to its flexibility and wide range of configurations. Many stereo or mono audio applications may be targeted.
  • Page 927 RM0090 Serial audio interface (SAI) 29.2 Main features • Two independent audio sub-blocks which can be transmitters or receivers with their respective FIFO. • 8-word integrated FIFOs for each audio sub-block. • Synchronous or asynchronous mode between the audio sub-blocks. •...
  • Page 928: Figure 283. Functional Block Diagram

    Serial audio interface (SAI) RM0090 29.3 Functional block diagram The block diagram of the SAI is shown in Figure 283. Figure 283. Functional block diagram Serial Audio Interface (SAI) APB interface SAI_XCR1 Audio block A int_sck synchro FIFO ctrl int_FS ctrl out FIFO FS_A...
  • Page 929 RM0090 Serial audio interface (SAI) mode definition. In AC’97 protocol, it will be an SAI output even if the SAI (link controller) is set-up to consume the SCK clock (and so to be in Slave mode). 29.4 Main SAI modes Each audio sub-block of the SAI can be configured to be master or slave via bit MODE[0] in the SAI_xCR1 register of the selected audio block.
  • Page 930: Figure 284. Audio Frame

    Serial audio interface (SAI) RM0090 29.5 SAI synchronization mode Internal synchronization An audio block can be declared synchronous with the second audio block. In this case, the bit clock and the frame synchronization signals are shared to reduce the number of external pins used for the communication.
  • Page 931 RM0090 Serial audio interface (SAI) In AC’97 mode (bit PRTCFG[1:0] = 10 in the SAI_xCR1 register), the frame synchronization shape is forced to be configured to target these protocols. The SAI_xFRCR register value is ignored. Each audio block is independent and so each requires a specific configuration. 29.7.1 Frame length •...
  • Page 932 Serial audio interface (SAI) RM0090 described in Section 29.13), but there will be no interruption in the audio communication flow. 29.7.3 Frame synchronization active level length Bit FSALL[6:0] in the SAI_xFRCR register configures the length of the active level of the Frame synchronization signal.
  • Page 933: Figure 285. Fs Role Is Start Of Frame + Channel Side Identification (Fsdef = Tris = 1)

    RM0090 Serial audio interface (SAI) Figure 285. FS role is start of frame + channel side identification (FSDEF = TRIS = 1) Number of slots not aligned with the audio frame Audio frame Half of frame slot Slot 0 ON Slot 1 OFF Slot 2 ON Slot 3 ON Slot 4 OFF Slot 5 ON Number of slots aligned with the audio frame...
  • Page 934: Figure 287. Slot Size Configuration With Fboff = 0 In Sai_Xslotr

    Serial audio interface (SAI) RM0090 Each slot can be defined as a valid slot, or not, by setting bit SLOTEN[15:0] in the SAI_xSLOTR register. In an audio frame, during the transfer of a non-valid slot, 0 value will be forced on the data line or the SD data line will be released to HI-z (refer to Section 29.12.4) if the audio block is transmitter, or the received value from the end of this slot will be ignored.
  • Page 935: Figure 289. Audio Block Clock Generator Overview

    RM0090 Serial audio interface (SAI) It is mandatory to respect the following conditions in order to avoid bad SAI behavior: FBOFF ≤ (SLOTSZ - DS), DS ≤ SLOTSZ, NBSLOT x SLOTSZ ≤ FRL (frame length), The number of slots should be even when bit FSDEF in the SAI_xFRCR register is set. In AC’97 (bit PRTCFG[1:0] = 10), the slot size is automatically set as defined in Section 29.11.
  • Page 936: Table 130. Example Of Possible Audio Frequency Sampling Range

    Serial audio interface (SAI) RM0090 Table 130. Example of possible audio frequency sampling range Input SAI_CK_x clock Most usual audio frequency MCKDIV[3:0] frequency sampling achievable 192 kHz MCKDIV[3:0] = 0000 96 kHz MCKDIV[3:0] = 0001 192 kHz x 256 48 kHz MCKDIV[3:0] = 0010 16 kHz MCKDIV[3:0] = 0100...
  • Page 937 RM0090 Serial audio interface (SAI) An interrupt is generated if FREQIE bit is enabled in the SAI_xIM register. This depends on: • FIFO threshold setting (FLTH bits in SAI_CR2) • Communication direction transmitter or receiver (see Section : Interrupt generation in transmitter mode Section : Interrupt generation in reception mode)
  • Page 938 Serial audio interface (SAI) RM0090 (FLTH[2:0] bits in SAI_xSR is higher or equal to 010b). This Interrupt (FREQ bit in SAI_XSR register) is cleared by hardware when less than a quarter of the FIFO data locations become available (FLTH[2:0] bits in SAI_xSR is less than 010b). •...
  • Page 939: Figure 290. Ac'97 Audio Frame

    RM0090 Serial audio interface (SAI) 29.11 AC’97 link controller The SAI is able to work as an AC’97 link controller. In this protocol: • The slot number and the slot size are fixed. • The frame synchronization signal is perfectly defined and has a fixed shape. To select this protocol, set bit PRTCFG[1:0] in the SAI_xCR1 register to 10.
  • Page 940 Serial audio interface (SAI) RM0090 29.12 Specific features The SAI has some specific functions which can be useful depending on the audio protocol selected. These functions are accessible through specific bits in the SAI_xCR2 register. 29.12.1 Mute mode Mute mode may be used when the audio block is a transmitter or receiver. Transmitter In transmitter mode, Mute mode can be selected at anytime.
  • Page 941: Figure 291. Data Companding Hardware In An Audio Block In The Sai

    RM0090 Serial audio interface (SAI) with a distinct and different left and right data, bit MONO has no meaning. The conversion from the output stereo file to the equivalent mono file is done by software. Note: To enable Mono mode, NBSLOT and SLOTEN must equal two and MONO bit set to 1. 29.12.3 Companding mode Telecommunication applications may require to process the data to transmit or to receive...
  • Page 942 Serial audio interface (SAI) RM0090 Expansion or compression mode is automatically selected by the SAI configuration. • If the SAI audio block is configured to be a transmitter, and if the COMP[1] bit is set in the SAI_xCR2 register, the compression mode will be applied. •...
  • Page 943: Figure 292. Tristate Strategy On Sd Output Line On An Inactive Slot

    RM0090 Serial audio interface (SAI) Figure 292. Tristate strategy on SD output line on an inactive slot Bit TRIS = 1 in the SAI_xCR1 and frame length = number of slots Audio frame Slot size = data size slot Slot 0 ON Slot 1 OFF Slot 2 OFF Slot 3 ON...
  • Page 944: Figure 293. Tristate On Output Data Line In A Protocol Like I2S

    Serial audio interface (SAI) RM0090 Figure 293. Tristate on output data line in a protocol like I2S Slot size = data size slot Slot 0 ON Slot 1 OFF Slot 2 ON Slot 3 ON Slot 4 OFF Slot 5 ON SD (output) Data 0 Data 1...
  • Page 945: Figure 294. Overrun Detection Error

    RM0090 Serial audio interface (SAI) was stored internally when the overrun condition was detected, and this, to avoid data slot de-alignment in the destination memory (refer to Figure 294). The OVRUDR flag is cleared when bit COVRUDR is set in the SAI_xCLRFR register. Figure 294.
  • Page 946: Figure 295. Fifo Underrun Event

    Serial audio interface (SAI) RM0090 Figure 295. FIFO underrun event Example: FIFO underrun on Slot 1 Audio frame Audio frame Slot size = data size data Slot 0 ON MUTE MUTE MUTE Slot 1 ON ... ON Slot 0 ON SD (output) FIFO empty OVRUND...
  • Page 947 RM0090 Serial audio interface (SAI) The late frame synchronisation detection flag is set when the error is detected, SAI needs to be resynchronized with the master (the four steps described above should be respected). This detection and flag assertion can detect glitches on the SCK clock in a noisy environment, detected by the state machine of the audio block.
  • Page 948: Table 131. Interrupt Sources

    Serial audio interface (SAI) RM0090 29.14 Interrupt sources The SAI has 7 possible interrupt sources as illustrated by Table Table 131. Interrupt sources Interru Interrupt Audio block mode Interrupt enable Interrupt clear source group Depend on: - FIFO threshold setting (FLTH bits in SAI_CR2) Master or Slave FREQIE in...
  • Page 949 RM0090 Serial audio interface (SAI) If there is an audio block in the SAI synchronous with the other one, the one which is the master must be disabled first. 29.16 SAI DMA interface In order to free the CPU and to optimize the bus bandwidth, each SAI audio block has an independent DMA interface in order to read or to write into the SAI_xDR register (to hit the internal FIFO).
  • Page 950 Serial audio interface (SAI) RM0090 29.17 SAI registers 29.17.1 SAI xConfiguration register 1 (SAI_xCR1) where x is A or B Address offset: Block A: 0x004 Address offset: Block B: 0x024 Reset value: 0x0000 0040 MCKDIV[3:0] NODIV DMAEN SAIxEN Reserved Res. OutDri LSBFIR MONO...
  • Page 951 RM0090 Serial audio interface (SAI) Bit 12 MONO: Mono mode. This bit is set and cleared by software. 0: Stereo mode 1: Mono mode. This bit has a meaning only when the number of slots is equal to 2. When the Mono mode is selected, the data of the slot 0 data is duplicated on the slot 1 when the audio block is a transmitter.
  • Page 952 Serial audio interface (SAI) RM0090 Bit 4 Reserved, always read as 0. Bits 3:2 PRTCFG[1:0]: Protocol configuration. These bits are set and cleared by software. 00: Free protocol 01: Not used 10: AC’97 protocol 11: Not used Free protocol selection allows to use the powerful configuration of the audio block to address a specific audio protocol (like I2S, LSB/MSB justified, TDM, PCM/DSP...) setting most of the configuration register bits as well as frame configuration register.
  • Page 953 RM0090 Serial audio interface (SAI) 29.17.2 SAI xConfiguration register 2 (SAI_xCR2) where x is A or B Address offset: Block A: 0x008 Address offset: Block B: 0x028 Reset value: 0x0000 0000 Reserved MUTE COMP[1:0] MUTECNT[5:0] Mute TRIS FFLUS Bits 31:16 Reserved, always read as 0 Bits 15:14 COMP[1:0]: Companding mode.
  • Page 954 Serial audio interface (SAI) RM0090 Bit 6 MUTEVAL: Mute value. This bit is set and cleared by software.This bit has to be written before enabling the audio block: SAIxEN. 0: Bit value 0 is sent during the MUTE mode. 1: Last values are sent during the MUTE mode. This bit has a meaning only when the audio block is a transmitter and when the number of slots is lower or equal to 2 and if the MUTE bit is set.
  • Page 955 RM0090 Serial audio interface (SAI) 29.17.3 SAI xFrame configuration register (SAI_XFRCR) where x is A or B Address offset: Block A: 0x00C Address offset: Block B: 0x02C Reset value: 0x0000 0007 Note: This register has no meaning in AC’97 audio protocol FSOFF FSPOL FSDEF Reserved FSALL[6:0]...
  • Page 956 Serial audio interface (SAI) RM0090 Bit 15 Reserved, always read as 0. Bits 14:8 FSALL[6:0]: Frame synchronization active level length. These bits are set and cleared by software The value set in these bits specifies the length in number of bit clock (SCK) + 1 (FSALL[6:0] + 1) of the active level of the FS signal in the audio frame These bits have no meaning and are not used in AC’97 audio block configuration.
  • Page 957 RM0090 Serial audio interface (SAI) 29.17.4 SAI xSlot register (SAI_xSLOTR) where x is A or B Address offset: Block A: 0x010 Address offset: Block B: 0x030 Reset value: 0x0000 0000 Note: This register has no meaning in AC’97 audio protocol SLOTEN[15:0] NBSLOT[3:0] SLOTSZ[1:0]...
  • Page 958 Serial audio interface (SAI) RM0090 29.17.5 SAI xInterrupt mask register (SAI_xIM) where x is A or B Address offset: blockA: 0x014 Address offset: block B: 0x034 Reset value: 0x0000 0000 Reserved LFSDETI AFSDET CNRDY FREQI WCKC OVRU EDET FGIE DRIE Reserved Bits 31:7 Reserved, always read as 0.
  • Page 959 RM0090 Serial audio interface (SAI) Bit 2 WCKCFGIE: Wrong clock configuration interrupt enable. This bit is set and cleared by software. 0: Interrupt is disabled 1: Interrupt is enabled This bit is considered only if the audio block is configured as master (MODE[1] = 0 in the SAI_ACR1 register) and bit NODIV = 0 in the SAI_xCR1 register.
  • Page 960 Serial audio interface (SAI) RM0090 29.17.6 SAI xStatus register (SAI_xSR) where x is A or B Address offset: block A: 0x018 Address offset: block B: 0x038 Reset value: 0x0000 0008 FLTH Reserved MUTED LFSDET AFSDET CNRDY FREQ WCKCFG OVRUDR Reserved Bits 31:19 Reserved, always read as 0.
  • Page 961 RM0090 Serial audio interface (SAI) Bit 4 CNRDY: Codec not ready. This bit is read only. 0: The external AC’97 codec is ready 1: The external AC’97 codec is not ready This bit is used only when the AC’97 audio protocol is selected in the SAI_xCR1 register and is configured in receiver mode.
  • Page 962 Serial audio interface (SAI) RM0090 29.17.7 SAI xClear flag register (SAI_xCLRFR) where X is A or B Address offset: block A: 0x01C Address offset: block B: 0x03C Reset value: 0x0000 0000 Reserved CAFSDE CMUTE COVRUD CLFSDET CCNRDY CWCKCFG Reserved Reserved Bits 31:7 Reserved, always read as 0.
  • Page 963: Table 132. Sai Register Map And Reset Values

    RM0090 Serial audio interface (SAI) 29.17.8 SAI xData register (SAI_xDR) where x is A or B Address offset: block A: 0x020 Address offset: block B: 0x040 Reset value: 0x0000 0000 DATA[31:16] DATA[15:0] Bits 31:0 DATA[31:0]: Data A write into this register has the effect of loading the FIFO if the FIFO is not full. A read from this register has to effect of draining-up the FIFO if the FIFO is not empty.
  • Page 964 Serial audio interface (SAI) RM0090 Table 132. SAI register map and reset values (continued) Register Offset and reset value 0x001C SAI_xCLRFR or 0x003C Reset value 0x0020 SAI_xDR DATA[31:0] Reset value or 0x0040 Refer to Section 2.3: Memory map for the register boundary addresses. 964/1749 RM0090 Rev 18...
  • Page 965 RM0090 Universal synchronous asynchronous receiver transmitter (USART) Universal synchronous asynchronous receiver transmitter (USART) This section applies to the whole STM32F4xx family, unless otherwise specified. 30.1 USART introduction The universal synchronous asynchronous receiver transmitter (USART) offers a flexible means of full-duplex data exchange with external equipment requiring an industry standard NRZ asynchronous serial data format.
  • Page 966 Universal synchronous asynchronous receiver transmitter (USART) RM0090 • Transfer detection flags: – Receive buffer full – Transmit buffer empty – End of transmission flags • Parity control: – Transmits parity bit – Checks parity of received data byte • Four error detection flags: –...
  • Page 967 RM0090 Universal synchronous asynchronous receiver transmitter (USART) Through these pins, serial data is transmitted and received in normal USART mode as frames comprising: • An Idle Line prior to transmission or reception • A start bit • A data word (8 or 9 bits) least significant bit first •...
  • Page 968: Figure 296. Usart Block Diagram

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Figure 296. USART block diagram PRDATA PWDATA Write Read (Data register) DR (CPU or DMA) (CPU or DMA) Receive data register (RDR) Transmit data register (TDR) IrDA SW_RX Receive Shift Register Transmit Shift Register ENDEC block IRDA_OUT...
  • Page 969: Figure 297. Word Length Programming

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) 30.3.1 USART character description Word length may be selected as being either 8 or 9 bits by programming the M bit in the USART_CR1 register (see Figure 297). The TX pin is in low state during the start bit. It is in high state during the stop bit. An Idle character is interpreted as an entire frame of “1”s followed by the start bit of the next frame which contains data (The number of “1”...
  • Page 970 Universal synchronous asynchronous receiver transmitter (USART) RM0090 30.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 CK pin.
  • Page 971: Figure 298. Configurable Stop Bits

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Figure 298. Configurable stop bits 8-bit Word length (M bit is reset) Possible Next data frame parity Data frame Next Start start Stop Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 CLOCK **** ** LBCL bit controls last data clock pulse a) 1 Stop Bit Possible...
  • Page 972: Figure 299. Tc/Txe Behavior When Transmitting

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 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.
  • Page 973: Figure 300. Start Bit Detection When Oversampling By 16 Or 8

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Idle characters Setting the TE bit drives the USART to send an idle frame before the first data frame. 30.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.
  • Page 974 Universal synchronous asynchronous receiver transmitter (USART) RM0090 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.
  • Page 975 RM0090 Universal synchronous asynchronous receiver transmitter (USART) 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.
  • Page 976: Figure 301. Data Sampling When Oversampling By 16

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Programming the ONEBIT bit in the USART_CR3 register selects the method used to evaluate the logic level. There are two options: • the majority vote of the three samples in the center of the received bit. In this case, when the 3 samples used for the majority vote are not equal, the NF bit is set •...
  • Page 977: Table 133. Noise Detection From Sampled Data

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Figure 302. Data sampling when oversampling by 8 RX line sampled values Sample clock (x8) One bit time MSv31153V1 Table 133. Noise detection from sampled data Sampled value NE status Received bit value Framing error A framing error is detected when: The stop bit is not recognized on reception at the expected time, following either a de-...
  • Page 978 Universal synchronous asynchronous receiver transmitter (USART) RM0090 Configurable stop bits during reception The number of stop bits to be received can be configured through the control bits of Control Register 2 - it can be either 1 or 2 in normal mode and 0.5 or 1.5 in Smartcard mode. 0.5 stop bit (reception in Smartcard mode): No sampling is done for 0.5 stop bit.
  • Page 979 RM0090 Universal synchronous asynchronous receiver transmitter (USART) How to derive USARTDIV from USART_BRR register values when OVER8=0 Example 1: If DIV_Mantissa = 0d27 and DIV_Fraction = 0d12 (USART_BRR = 0x1BC), then Mantissa (USARTDIV) = 0d27 Fraction (USARTDIV) = 12/16 = 0d0.75 Therefore USARTDIV = 0d27.75 Example 2: To program USARTDIV = 0d25.62...
  • Page 980: Table 134. Error Calculation For Programmed Baud Rates At F

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Then, USART_BRR = 0x195 => USARTDIV = 0d25.625 Example 3: To program USARTDIV = 0d50.99 This leads to: DIV_Fraction = 8*0d0.99 = 0d7.92 The nearest real number is 0d8 = 0x8 => overflow of the DIV_frac[2:0] => carry must be added up to the mantissa DIV_Mantissa = mantissa (0d50.990 + carry) = 0d51 = 0x33 Then, USART_BRR = 0x0330 =>...
  • Page 981: Oversampling By 8

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Table 135. Error calculation for programmed baud rates at f = 8 MHz or f =12 MHz, PCLK PCLK oversampling by 8 Oversampling by 8 (OVER8 = 1) Baud rate = 8 MHz = 12 MHz PCLK PCLK...
  • Page 982: Oversampling By 8

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Table 136. Error calculation for programmed baud rates at f = 16 MHz or f = 24 MHz, PCLK PCLK oversampling by 16 (continued) Oversampling by 16 (OVER8 = 0) Baud rate = 16 MHz = 24 MHz f PCLK f PCLK...
  • Page 983: Oversampling By 16

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Table 138. Error calculation for programmed baud rates at f = 8 MHz or f = 16 MHz, PCLK PCLK oversampling by 16 Oversampling by 16 (OVER8=0) Baud rate = 8 MHz = 16 MHz PCLK PCLK Value...
  • Page 984: Oversampling By 16

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Table 139. Error calculation for programmed baud rates at f = 8 MHz or f = 16 MHz, PCLK PCLK oversampling by 8 (continued) Oversampling by 8 (OVER8=1) Baud rate = 8 MHz = 16 MHz PCLK PCLK...
  • Page 985: Oversampling By 8

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Table 140. Error calculation for programmed baud rates at f = 30 MHz or f = 60 MHz, PCLK PCLK (1)(2) oversampling by 16 (continued) Oversampling by 16 (OVER8=0) Baud rate = 30 MHz = 60 MHz PCLK PCLK...
  • Page 986: Oversampling By 16

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Table 141. Error calculation for programmed baud rates at f = 30 MHz or f = 60 MHz, PCLK PCLK (1) (2) oversampling by 8 (continued) Oversampling by 8 (OVER8=1) Baud rate = 30 MHz =60 MHz PCLK PCLK...
  • Page 987: Oversampling By 8

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Table 142. Error calculation for programmed baud rates at f = 42 MHz or f = 84 Hz, PCLK PCLK (1)(2) oversampling by 16 (continued) Oversampling by 16 (OVER8=0) Baud rate = 42 MHz = 84 MHz PCLK PCLK...
  • Page 988: Table 144. Usart Receiver's Tolerance When Div Fraction Is 0

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Table 143. Error calculation for programmed baud rates at f = 42 MHz or f = 84 MHz, PCLK PCLK (1)(2) oversampling by 8 (continued) Oversampling by 8 (OVER8=1) Baud rate = 42 MHz = 84 MHz PCLK PCLK...
  • Page 989: Table 145. Usart Receiver Tolerance When Div_Fraction Is Different From 0

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Table 145. USART receiver tolerance when DIV_Fraction is different from 0 OVER8 bit = 0 OVER8 bit = 1 M bit ONEBIT=0 ONEBIT=1 ONEBIT=0 ONEBIT=1 3.33% 3.88% 3.03% 3.53% 1.82% 2.73% Note: The figures specified in Table 144 Table 145 may slightly differ in the special case when...
  • Page 990: Figure 303. Mute Mode Using Idle Line Detection

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Figure 303. Mute mode using Idle line detection RXNE RXNE Data 1 Data 2 Data 3 Data 4 IDLE Data 5 Data 6 Mute mode Normal mode RWU written to 1 Idle frame detected MSv40881V1 Address mark detection (WAKE=1) In this mode, bytes are recognized as addresses if their MSB is a ‘1 else they are...
  • Page 991: Table 146. Frame Formats

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) 30.3.7 Parity control Parity control (generation of parity bit in transmission and parity checking in reception) can be enabled by setting the PCE bit in the USART_CR1 register. Depending on the frame length defined by the M bit, the possible USART frame formats are as listed in Table 146.
  • Page 992 Universal synchronous asynchronous receiver transmitter (USART) RM0090 30.3.8 LIN (local interconnection network) mode The LIN mode is selected by setting the LINEN bit in the USART_CR2 register. In LIN mode, the following bits must be kept cleared: • STOP[1:0] and CLKEN in the USART_CR2 register •...
  • Page 993: Figure 305. Break Detection In Lin Mode (11-Bit Break Length - Lbdl Bit Is Set)

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) Figure 305. 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 Break frame RX line Capture strobe Break state Idle...
  • Page 994: Figure 306. Break Detection In Lin Mode Vs. Framing Error Detection

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Figure 306. Break detection in LIN mode vs. Framing error detection Case 1: break occurring after an Idle RX line data 1 IDLE BREAK data 2 (0x55) data 3 (header) 1 data time 1 data time RXNE /FE LBDF...
  • Page 995: Figure 307. Usart Example Of Synchronous Transmission

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) 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.
  • Page 996: Figure 309. Usart Data Clock Timing Diagram (M=1)

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 Figure 309. USART data clock timing diagram (M=1) Idle or Idle or next preceding Start M=1 (9 data bits) Stop transmission transmission Clock (CPOL=0, CPHA=0 Clock (CPOL=0, CPHA=1 Clock (CPOL=1, CPHA=0 Clock (CPOL=1, CPHA=1 Data on TX (from master)
  • Page 997: Figure 311. Iso 7816-3 Asynchronous Protocol

    RM0090 Universal synchronous asynchronous receiver transmitter (USART) As soon as HDSEL is written to 1: • the TX and RX lines are internally connected • the RX pin is no longer used • the TX pin is always released when no data is transmitted. Thus, it acts as a standard I/O in idle or in reception.
  • Page 998: Figure 312. Parity Error Detection Using The 1.5 Stop Bits

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 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.
  • Page 999 RM0090 Universal synchronous asynchronous receiver transmitter (USART) prescaler register USART_GTPR. CK frequency can be programmed from f /2 to f /62, where f is the peripheral input clock. 30.3.12 IrDA SIR ENDEC block The IrDA mode is selected by setting the IREN bit in the USART_CR3 register. In IrDA mode, the following bits must be kept cleared: •...
  • Page 1000: Figure 313. Irda Sir Endec- Block Diagram

    Universal synchronous asynchronous receiver transmitter (USART) RM0090 IrDA low-power mode Transmitter: In low-power mode the pulse width is not maintained at 3/16 of the bit period. Instead, the width of the pulse is 3 times the low-power baud rate which can be a minimum of 1.42 MHz. Generally this value is 1.8432 MHz (1.42 MHz <...

Table of Contents

Save PDF