Page 4
Contents RM0444 Power supplies ..........119 4.1.1 ADC and DAC reference voltage .
Page 5
RM0444 Contents 4.4.17 Power Port E pull-down control register (PWR_PDCRE) ..156 4.4.18 Power Port F pull-up control register (PWR_PUCRF) ... . . 156 4.4.19 Power Port F pull-down control register (PWR_PDCRF) .
Page 7
RM0444 Contents 6.7.2 CRS configuration register (CRS_CFGR) ..... . 227 6.7.3 CRS interrupt and status register (CRS_ISR) ....228 6.7.4 CRS interrupt flag clear register (CRS_ICR) .
Page 8
Contents RM0444 7.4.8 GPIO port configuration lock register (GPIOx_LCKR) (x = A to F) ..........244 7.4.9 GPIO alternate function low register (GPIOx_AFRL) (x = A to F) .
Page 9
RM0444 Contents 8.1.28 SYSCFG interrupt line 25 status register (SYSCFG_ITLINE25) ..264 8.1.29 SYSCFG interrupt line 26 status register (SYSCFG_ITLINE26) ..264 8.1.30 SYSCFG interrupt line 27 status register (SYSCFG_ITLINE27) ..264 8.1.31 SYSCFG interrupt line 28 status register (SYSCFG_ITLINE28) .
Page 32
Contents RM0444 34.4.3 LPUART character description ......1090 34.4.4 LPUART FIFOs and thresholds ......1091 34.4.5 LPUART transmitter .
Page 33
RM0444 Contents 35.5.2 Communications between one master and one slave ... . 1142 35.5.3 Standard multi-slave communication ......1144 35.5.4 Multi-master communication .
Page 34
Contents RM0444 FD controller area network (FDCAN) ......1196 36.1 Introduction ..........1196 36.2 FDCAN main features .
Page 39
RM0444 List of tables List of tables Table 1. Peripherals versus products ..........54 Table 2.
Page 40
List of tables RM0444 Table 52. DMAMUX: assignment of multiplexer inputs to resources ......300 Table 53. DMAMUX: assignment of trigger inputs to resources .
Page 41
RM0444 List of tables Table 104. GCM last block definition ..........493 Table 105.
Page 42
List of tables RM0444 Table 154. RTC register map and reset values ......... 910 Table 155.
Page 43
RM0444 List of tables Table 205. Rx FIFO element ............1220 Table 206.
Page 44
List of figures RM0444 List of figures Figure 1. System architecture ............56 Figure 2.
Page 45
RM0444 List of figures Figure 49. Analog watchdog guarded area ..........369 Figure 50.
Page 46
List of figures RM0444 Figure 101. Advanced-control timer block diagram ........525 Figure 102.
Page 47
RM0444 List of figures Figure 153. Example of counter operation in encoder interface mode......573 Figure 154. Example of encoder interface mode with TI1FP1 polarity inverted....574 Figure 155.
Page 48
List of figures RM0444 Figure 204. Master/Slave timer example ..........663 Figure 205.
Page 49
RM0444 List of figures Figure 250. Capture/compare channel (example: channel 1 input stage) ..... . 755 Figure 251. Capture/compare channel 1 main circuit ........755 Figure 252.
Page 50
List of figures RM0444 Figure 299. 10-bit address read access with HEAD10R=0 ....... . . 952 Figure 300.
Page 51
RM0444 List of figures Figure 347. Mute mode using address mark detection ........1103 Figure 348.
Page 52
List of figures RM0444 Figure 396. Pin control in Bus Monitoring mode ........1207 Figure 397.
RM0444 Documentation conventions Documentation conventions General information ® ®(a) The STM32G0x1 devices have an Arm Cortex -M0+ core. List of abbreviations for registers The following abbreviations are used in register descriptions: read/write (rw) Software can read and write to this bit. read-only (r) Software can only read this bit.
Documentation conventions RM0444 Glossary This section gives a brief definition of acronyms and abbreviations used in this document: • Word: data of 32-bit length. • Half-word: data of 16-bit length. • Byte: data of 8-bit length. • SWD-DP (SWD DEBUG PORT): SWD-DP provides a 2-pin (clock and data) interface ®...
Memory and bus architecture RM0444 Memory and bus architecture System architecture The main system consists of: • Two masters: ® – Cortex -M0+ core – General-purpose DMA • Three slaves: – Internal SRAM – Internal Flash memory – AHB with AHB-to-APB bridge that connects all the APB peripherals These are interconnected using a multilayer AHB bus architecture as shown in Figure Figure 1.
Page 57
RM0444 Memory and bus architecture Bus matrix The bus matrix manages the access arbitration between the core system bus and the DMA master bus. The arbitration uses a Round Robin algorithm. The bus matrix is composed of masters (CPU, DMA) and slaves (Flash memory interface, SRAM and AHB-to-APB bridge). AHB peripherals are connected on system bus through the bus matrix to allow DMA access.
RM0444 Memory organization 2.2.1 Introduction Program memory, data memory, registers and I/O ports are organized within the same linear 4-Gbyte address space. The bytes are coded in memory in Little Endian format. The lowest numbered byte in a word is considered the word’s least significant byte and the highest numbered byte the most significant.
RM0444 The SRAM can be accessed by bytes, half-words (16 bits) or full words (32 bits), at maximum system clock frequency without wait state and thus by both CPU and DMA. Parity check The user can enable the parity check using the option bit RAM_PARITY_CHECK in the user option byte (refer to Section 3.4: FLASH option bytes).
Page 66
RM0444 Table 8. Boot modes (continued) Boot mode configuration Selected boot area BOOT_ nBOOT1 BOOT0 nBOOT_SEL nBOOT0 LOCK bit Embedded SRAM Main Flash memory System memory Embedded SRAM Main Flash memory forced The boot mode configuration is latched on the 4th rising edge of SYSCLK after a reset. It is up to the user to set boot mode configuration related to the required boot mode.
Page 67
This modification is performed by programming the MEM_MODE bits in SYSCFG configuration register 1 (SYSCFG_CFGR1). Embedded boot loader The embedded boot loader is located in the System memory, programmed by ST during production. It is used to reprogram the Flash memory using one of the following serial interfaces: •...
Embedded Flash memory (FLASH) RM0444 Embedded Flash memory (FLASH) FLASH Introduction ® The Flash memory interface manages CPU (Cortex -M0+) AHB to the Flash memory. It implements erase and program Flash memory operations, read and write protection, and security mechanisms. The Flash memory interface accelerates code execution with a system of instruction prefetch and cache lines.
(DFU) and FDCAN2 (applies to STM32G0B1xx and STM32G0C1xx). On the manufacturing line, the devices are programmed and protected against spurious write/erase operations. For further details, refer to the AN2606 available from www.st.com. – 1 Kbyte (128 double words) OTP (one-time programmable) for user data. The OTP data cannot be erased and can be written only once.
Embedded Flash memory (FLASH) RM0444 Note: For a virgin data: 0xFF FFFF FFFF FFFF FFFF, one error is detected and corrected, but two errors detection is not supported. When an ECC error is reported, a new read at the failing address may not generate an ECC error if the data is still present in the current buffer, even if ECCC and ECCD are cleared.
RM0444 Embedded Flash memory (FLASH) Decreasing the CPU frequency Modify the system clock source by writing the SW bits of the RCC_CFGR register. If needed, modify the core clock prescaler by writing the HPRE bits of RCC_CFGR. Check that the new system clock source or/and the new core clock prescaler value is/are taken into account by reading the clock source status (SWS bits) of the RCC_CFGR register, or/and the AHB prescaler value (HPREF bit), of the RCC_CFGR register, and wait until the programmed new system clock source or/and new Flash...
Embedded Flash memory (FLASH) RM0444 3.3.6 FLASH program and erase operations The device-embedded Flash memory can be programmed using in-circuit programming or in-application programming. The in-circuit programming (ICP) method is used to update the entire contents of the Flash memory, using SWD protocol or the supported interfaces by the system boot loader, to load the user application for the CPU, into the microcontroller.
RM0444 Embedded Flash memory (FLASH) Table 13. Page erase overview SEC_PROT PCROP WRP PCROP_RDP Comment WRPERR CPU bus error Page is erased Page erase aborted (no page erase started) Protected pages only To erase a page (2 Kbytes), follow the procedure below: Check that no Flash memory operation is ongoing by checking the BSY1 bit of the FLASH status register (FLASH_SR).
Embedded Flash memory (FLASH) RM0444 Note: The internal oscillator HSI16 (16 MHz) is enabled automatically when STRT bit is set, and disabled automatically when STRT bit is cleared, except if the HSI16 is previously enabled with HSION in RCC_CR register. 3.3.8 FLASH Main memory programming sequences The Flash memory is programmed 72 bits (64-bit data plus 8-bit ECC) at a time.
Page 77
RM0444 Embedded Flash memory (FLASH) The Main Flash memory programming sequence in standard mode is described below: Perform a mass or page erase. If not, PGSERR is set. Check that no Main Flash memory operation is ongoing by checking the BSY1 bit of the FLASH status register (FLASH_SR)..
Page 78
Embedded Flash memory (FLASH) RM0444 – In fast programming: the data to program doesn’t belong to the same row than the previous programmed double words, or the address to program is not greater than the previous one. • PGSERR: Programming Sequence Error PGSERR is set if one of the following conditions occurs: –...
RM0444 Embedded Flash memory (FLASH) Programming and cache If an erase operation in Flash memory also concerns data in the instruction cache, the user has to ensure that these data are rewritten before they are accessed during code execution. Note: The cache should be flushed only when it is disabled (ICEN = 0).
Embedded Flash memory (FLASH) RM0444 The word write operation is completed when the corresponding busy flag (BSY1 or BSY2) is back to low. The EOP interrupt can be used to indicate that event to the application software. FLASH option bytes 3.4.1 FLASH option byte description The option bytes are configured by the end user depending on the application requirements.
SEC_SIZE 1. The upper 32-bits of the double-word address contain the inverted data from the lower 32 bits. User and read protection option bytes Flash memory address: 0x1FFF 7800 Reset value: 0xFFFF FEAA (ST production value) RAM_ IWGD NRST_MODE nBOOT...
Page 82
Embedded Flash memory (FLASH) RM0444 Bits 31:30 Reserved, must be kept at reset value. Bit 29 IRHEN: Internal reset holder enable bit 0: Internal resets are propagated as simple pulse on NRST pin 1: Internal resets drives NRST pin low until it is seen as low level Bits 28: 27 NRST_MODE[1:0] 00: Reserved 01: Reset Input only: a low level on the NRST pin generates system reset, internal RESET...
Page 83
0xAA: Level 0, read protection not active 0xCC: Level 2, chip read protection active Others: Level 1, memories read protection active PCROP1A start address option bytes Flash memory address: 0x1FFF 7808 Reset value: 0xFFFF FFFF (ST production value) Res. Res. Res. Res.
Page 86
Note: Values corresponding to addresses outside the Main memory are not allowed. PCROP2A start address option bytes Flash memory address: 0x1FFF 7838 Reset value: 0xFFFF FFFF (ST production value) The register pertains to dual-bank devices only. In single-bank devices, it is reserved. Res.
Page 87
PCROP2A_END contains the offset of the last PCROP subpage of the PCROP2A area in Bank 2 of dual-bank devices. Note: Values corresponding to addresses outside the Main memory are not allowed. WRP2A address option bytes Flash memory address: 0x1FFF 7848 Reset value: 0x0000 00FF (ST production value) Res. Res. Res. Res.
Page 88
Note: Values corresponding to addresses outside the Main memory are not allowed. PCROP2B start address option bytes Flash memory address: 0x1FFF 7858 Reset value: 0xFFFF FFFF (ST production value) The register pertains to dual-bank devices only. In single-bank devices, it is reserved. Res.
PCROP2B_END contains the offset of the last PCROP subpage of the PCROP2B area in Bank 2 of dual-bank devices. Note: Values corresponding to addresses outside the Main memory are not allowed. Security option bytes Flash memory address: 0x1FFF 7870 Reset value: 0x0000 0000 (ST production value) Res. Res. Res. Res.
Page 90
Embedded Flash memory (FLASH) RM0444 Any wrong sequence locks up the Flash memory option registers until the next system reset. In the case of a wrong key sequence, a bus error is detected and a Hard Fault interrupt is generated. The user options can be protected against unwanted erase/program operations by setting the OPTLOCK bit by software.
RM0444 Embedded Flash memory (FLASH) If the word and its complement are matching, the option word/byte is copied into the option register. If the comparison between the word and its complement fails, a status bit OPTVERR is set. Mismatch values are forced into the option registers: –...
Embedded Flash memory (FLASH) RM0444 Table 17. Flash memory read protection status RDP byte value RDP complement byte value Read protection level 0xAA 0x55 Level 0 Any values except the combinations [0xAA, 0x55] and [0xCC, 0x33] Level 1 (default) 0xCC 0x33 Level 2 The System memory area is read-accessible whatever the protection level.
Page 93
RM0444 Embedded Flash memory (FLASH) Once in Level 2, it is no more possible to modify the read protection level. With the PCROP_RDP bit of the FLASH PCROP area A end address register (FLASH_PCROP1AER) set, the change from Level 1 to Level 0 triggers full mass erase of the Main Flash memory.
Page 95
RM0444 Embedded Flash memory (FLASH) The protected area is execute-only: it can only be reached by the STM32 CPU, with an instruction code, while all other accesses (DMA, debug and CPU data read, write and erase) are strictly prohibited. The PCROP areas have subpage (512-byte) granularity. An additional option bit (PCROP_RDP) allows to select if the PCROP area is erased or not when the RDP protection is changed from Level 1 to Level 0 (refer to Changing the read...
RM0444 Embedded Flash memory (FLASH) If an erase/program operation to a write-protected part of the Flash memory is attempted, the write protection error flag (WRPERR) of the FLASH_SR register is set. This flag is also set for any write access to: –...
Embedded Flash memory (FLASH) RM0444 Table 22. Securable memory erase at RDP Level 1 to Level 0 change Securable memory size PCROP_RDP Erased pages (SEC_SIZEx[7:0]) All (mass erase) All but PCROP > 0 All (mass erase) All but PCROP outside the >...
RM0444 Embedded Flash memory (FLASH) Bit 8 PRFTEN: CPU Prefetch enable 0: CPU Prefetch disabled 1: CPU Prefetch enabled Bits 7:3 Reserved, must be kept at reset value. Bits 2:0 LATENCY[2:0]: Flash memory access latency The value in this bitfield represents the ratio of the HCLK clock period to the Flash memory access time.
Page 103
RM0444 Embedded Flash memory (FLASH) Bit 8 MISSERR: Fast programming data miss error In Fast programming mode, 32 double words (256 bytes) must be sent to Flash memory successively, and the new data must be sent to the logic control before the current data is fully programmed.
Embedded Flash memory (FLASH) RM0444 3.7.5 FLASH control register (FLASH_CR) Address offset: 0x014 Reset value: 0xC000 0000 Access: no wait state when no Flash memory operation is on going, word, half-word and byte access This register cannot be modified when CFGBSY in FLASH status register (FLASH_SR) set.
Page 105
RM0444 Embedded Flash memory (FLASH) Bit 25 ERRIE: Error interrupt enable This bit enables the interrupt generation upon setting the OPERR flag in the FLASH_SR register. 0: Disable 1: Enable Bit 24 EOPIE: End-of-operation interrupt enable This bit enables the interrupt generation upon setting the EOP flag in the FLASH_SR register. 0: Disable 1: Enable Bits 23:19 Reserved, must be kept at reset value.
Embedded Flash memory (FLASH) RM0444 3.7.6 FLASH ECC register (FLASH_ECCR) Address offset: 0x018 Reset value: 0x0000 0000 Access: no wait state when no Flash memory operation is on going, word, half-word and byte access This register applies to single-bank products and to Bank 1 of dual-bank products. SYSF_ ECCD ECCC...
RM0444 Embedded Flash memory (FLASH) 3.7.7 FLASH ECC register 2 (FLASH_ECCR2) Address offset: 0x01C Reset value: 0x0000 0000 Access: no wait state when no Flash memory operation is on going, word, half-word and byte access This register applies to Bank 2 of dual-bank products. SYSF_ ECCD ECCC...
Embedded Flash memory (FLASH) RM0444 3.7.8 FLASH option register (FLASH_OPTR) Address offset: 0x020 Reset value: 0b11XX XXXX 1X1X XXXX XXXX XXXX XXXX XXXX (The option bits are loaded with values from Flash memory at power-on reset release.) Access: no wait state when no Flash memory operation is on going, word, half-word and byte access IWGD NRST_MODE...
Page 109
RM0444 Embedded Flash memory (FLASH) Bit 20 nSWAP_BANK: Empty check boot configuration This bit selects the bank that is the subject of empty check upon boot. 0: Bank 1 1: Bank 2 The bit is ignored when the BOOT_LOCK bit is set. Bit 19 WWDG_SW: Window watchdog selection 0: Hardware window watchdog 1: Software window watchdog...
Embedded Flash memory (FLASH) RM0444 3.7.9 FLASH PCROP area A start address register (FLASH_PCROP1ASR) Address offset: 0x024 Reset value: 0b0000 0000 0000 0000 0000 000X XXXX XXXX (The option bits are loaded with values from Flash memory at power-on reset release.) Access: no wait state when no Flash memory operation is on going, word, half-word access This register applies to single-bank devices and to Bank 1 of dual-bank devices.
RM0444 Embedded Flash memory (FLASH) Bit 31 PCROP_RDP: PCROP area erase upon RDP level regression This bit determines whether the PCROP area (and the totality of the PCROP area boundary pages) is erased by the mass erase triggered by the RDP level regression from Level 1 to Level 0: 0: Not erased 1: Erased...
Embedded Flash memory (FLASH) RM0444 3.7.12 FLASH WRP area B address register (FLASH_WRP1BR) Address offset: 0x030 Reset value: 0b0000 0000 0XXX XXXX 0000 0000 0XXX XXXX (The option bits are loaded with values from Flash memory at power-on reset release.) Access: no wait state when no Flash memory operation is on going, word, half-word and byte access.
RM0444 Embedded Flash memory (FLASH) 3.7.14 FLASH PCROP area B end address register (FLASH_PCROP1BER) Address offset: 0x038 Reset value: ‘b0000 0000 0000 0000 0000 000X XXXX XXXX (The option bits are loaded with values from Flash memory at power-on reset release.) Access: no wait state when no Flash memory operation is on going, word, half-word access Res.
Embedded Flash memory (FLASH) RM0444 3.7.16 FLASH PCROP2 area A end address register (FLASH_PCROP2AER) Address offset: 0x048 Reset value: 0bX000 0000 0000 0000 0000 000X XXXX XXXX (The option bits are loaded with values from Flash memory at power-on reset release.) Access: no wait state when no Flash memory operation is on going, word, half-word access.
RM0444 Embedded Flash memory (FLASH) 3.7.18 FLASH WRP2 area B address register (FLASH_WRP2BR) Address offset: 0x050 Reset value: 0b0000 0000 0XXX XXXX 0000 0000 0XXX XXXX (The option bits are loaded with values from Flash memory at power-on reset release.) Access: no wait state when no Flash memory operation is on going, word, half-word and byte access.
Embedded Flash memory (FLASH) RM0444 3.7.20 FLASH PCROP2 area B end address register (FLASH_PCROP2BER) Address offset: 0x058 Reset value: ‘b0000 0000 0000 0000 0000 000X XXXX XXXX (The option bits are loaded with values from Flash memory at power-on reset release.) Access: no wait state when no Flash memory operation is on going, word, half-word access Res.
RM0444 Embedded Flash memory (FLASH) 3.7.22 FLASH register map Table 24. FLASH register map and reset values Offset Register LATENCY FLASH_ACR [2:0] 0x000 Reset value Reserved 0x004 Reset value FLASH_KEYR KEYR[31:0] 0x008 Reset value FLASH_OPT OPTKEY[31:0] KEYR 0x00C Reset value FLASH_SR 0x010 Reset value...
Page 118
Embedded Flash memory (FLASH) RM0444 Table 24. FLASH register map and reset values (continued) Offset Register FLASH_ PCROP1B_END[8:0] PCROP1BER 0x038 Reset value X X X X X X X X X 0x03C - Reserved 0x043 FLASH_ PCROP2A_STRT[8:0] PCROP2ASR 0x044 Reset value X X X X X X X X X FLASH_ PCROP2A_END[8:0]...
RM0444 Power control (PWR) Power control (PWR) Power supplies The STM32G0x1 devices require a 1.7 V to 3.6 V operating supply voltage (V ). Several different power supplies are provided to specific peripherals: • = 1.7 V (1.60 V) to 3.6 V is the external power supply for the internal regulator and the system analog such as reset, power management and internal clocks.
Power control (PWR) RM0444 Figure 5. Power supply overview domain REF+ VREF+ A/D converter Comparators D/A converter Voltage reference buffer DDIO1 domain I/O ring DDIO1 DDIO2 domain VDDIO2 I/O ring DDIO2 domain Reset block domain Temp. sensor CORE PLL, HSI Core Standby circuitry VSS/VSSA...
Page 121
RM0444 Power control (PWR) Warning: During (temporization at V startup) or after a PDR RSTTEMPO has been detected, the power switch between V and V remains connected to V During the startup phase, if V is established in less than (refer to the datasheet for the value of t RSTTEMPO RSTTEMPO...
Power control (PWR) RM0444 VBAT battery charging When V is present, it is possible to charge the external battery on VBAT through an internal resistance. The VBAT charging is done either through a 5 kΩ resistor or through a 1.55 kΩ resistor depending on the VBRS bit value in the PWR_CR4 register.
RM0444 Power control (PWR) 4.1.4 Dynamic voltage scaling management The dynamic voltage scaling is a power management technique which consists in increasing or decreasing the voltage used for the digital peripherals (V ), according to CORE the application performance and power consumption needs. Dynamic voltage scaling to increase V is known as overvolting.
Power control (PWR) RM0444 Power supply supervisor 4.2.1 Power-on reset (POR) / power-down reset (PDR) / brown-out reset (BOR) The device features an integrated power-on reset (POR) / power-down reset (PDR), coupled with a brown-out reset (BOR) circuitry. The POR/PDR is active in all power modes. The BOR can be enabled or disabled only through option bytes.
RM0444 Power control (PWR) For more details on the brown-out reset thresholds, refer to the electrical characteristics section in the datasheet. 4.2.2 Programmable voltage detector (PVD) The PVD can be used to monitor the V power supply by comparing it to the thresholds selected through PVDRT[2:0] bits (rising thresholds) and PVDFT[2:0] bits (falling thresholds) in the Power control register 2...
Power control (PWR) RM0444 Low-power modes By default, the microcontroller is in Run mode after a system or a power Reset. Several low- power modes are available to save power when the CPU does not need to be kept running, for example when waiting for an external event.
RM0444 Power control (PWR) behavior is not guaranteed in case of a power voltage drop. Refer to Section 4.3.9: Shutdown mode. In addition, the power consumption in Run mode can be reduced by one of the following means: • Slowing down the system clocks •...
Power control (PWR) RM0444 Table 25. Low-power mode summary Voltage Wakeup Wakeup regulators Mode name Entry Effect on clocks source system clock WFI or Return Sleep CPU clock OFF Same as before Any interrupt from ISR entering Sleep (Sleep-now or no effect on other clocks mode Sleep-on-exit)
RM0444 Power control (PWR) Table 26. Functionalities depending on the working mode Stop 0/1 Standby Shutdown Function Sleep VBAT Flash memory SRAM Backup Registers DMA1/2 HSI16 HSI48 CSS on LSE RTC / Auto wakeup TAMP1/2/3 USART1/2 USART3/4/5/6 LPUART1/2 I2C1 I2C2/3 SPI1/2/3 VREFBUF COMP1/2/3...
Page 130
Power control (PWR) RM0444 Table 26. Functionalities depending on the working mode (continued) Stop 0/1 Standby Shutdown Function Sleep VBAT Temperature sensor TIMx LPTIM1/2 IWDG WWDG SysTick timer FDCAN1/2 up to up to (10) (12) GPIOs pins pins (11) (11) 1.
RM0444 Power control (PWR) Debug mode By default, the debug connection is lost if the user application puts the MCU in Stop 0, Stop1, Shutdown, or Standby mode while the debug features are used. This is due to the ® fact that the Cortex -M0+ core is no longer clocked.
Power control (PWR) RM0444 Exiting Low-power run mode To exit Low-power run mode, proceed as follows: Force the regulator in main mode by clearing the LPR bit in the Power control register 1 (PWR_CR1). Wait until REGLPF bit is cleared in the Power status register 2 (PWR_SR2).
RM0444 Power control (PWR) ® When SEVONPEND = 1 in the Cortex -M0+ system control register: by enabling an interrupt in the peripheral control register and optionally in the NVIC. When the MCU resumes from WFE, the peripheral interrupt pending bit and when enabled the NVIC peripheral IRQ channel pending bit (in the NVIC interrupt clear pending register) have to be cleared.
Power control (PWR) RM0444 Table 28. Sleep mode summary (continued) Characteristic Description If WFI or return from ISR was used for entry Interrupt: refer to Table 58: Vector table If WFE was used for entry and SEVONPEND = 0: Mode exit Wakeup event: refer to Section 13.3.2: EXTI direct event input wakeup If WFE was used for entry and SEVONPEND = 1:...
RM0444 Power control (PWR) Table 29. Low-power sleep mode summary Characteristic Description Low-power sleep mode is entered from the Low-power run mode. WFI (Wait for Interrupt) or WFE (Wait for Event) while: – SLEEPDEEP = 0 – No interrupt (for WFI) or event (for WFE) is pending ®...
Page 136
Power control (PWR) RM0444 Entering Stop 0 mode The MCU enters Stop 0 mode according to section Entering low-power modes, when the ® SLEEPDEEP bit in the Cortex -M0+ System Control register is set. Refer to Table 30: Stop 0 mode summary for details on how to enter Stop 0 mode.
RM0444 Power control (PWR) Table 30. Stop 0 mode summary Characteristic Description WFI (Wait for Interrupt) or WFE (Wait for Event) while: ® – SLEEPDEEP bit is set in Cortex -M0+ System Control register – No interrupt (for WFI) or event (for WFE) is pending –...
Power control (PWR) RM0444 4.3.7 Stop 1 mode The Stop 1 mode is the same as Stop 0 mode except that the main regulator is off, and only the low-power regulator is on. Stop 1 mode can be entered from Run mode and from Low- power run mode.
RM0444 Power control (PWR) 4.3.8 Standby mode The Standby mode allows to achieve the lowest power consumption with BOR. It is based ® on the Cortex -M0+ deepsleep mode, with the voltage regulators disabled (except when the SRAM content is preserved). The PLL, the HSI16 and the HSE oscillators are also switched off.
Power control (PWR) RM0444 Exiting Standby mode The MCU exits Standby mode according to section Entering low-power modes. The SBF status flag in the Power control register 3 (PWR_CR3) indicates that the MCU was in Standby mode. All registers are reset after wakeup from Standby except for Power control register 3 (PWR_CR3).
RM0444 Power control (PWR) 4.3.9 Shutdown mode The Shutdown mode allows to achieve the lowest power consumption. It is based on the deepsleep mode, with the voltage regulator disabled. The V domain is consequently CORE powered off. The PLL, the HSI16, the LSI and the HSE oscillators are also switched off. SRAM and register contents are lost except for registers in the RTC domain.
Power control (PWR) RM0444 Exiting Shutdown mode The MCU exits Shutdown mode according to section Exiting low-power modes. A power-on reset occurs when exiting from Shutdown mode. All registers (except for the ones in the RTC domain) are reset after wakeup from Shutdown. Refer to Table 33: Shutdown mode summary for more details on how to exit Shutdown...
RM0444 Power control (PWR) PWR registers The peripheral registers can be accessed by half-words (16-bit) or words (32-bit). 4.4.1 Power control register 1 (PWR_CR1) Address offset: 0x00 Reset value: 0x0000 0208. This register is reset after wakeup from Standby mode. Res.
Power control (PWR) RM0444 Bit 4 FPD_LPRUN: Flash memory powered down during Low-power run mode This bit determines whether the Flash memory is put in power-down mode or remains in idle mode when the device enters Low-power run mode. The Flash memory can be put in power- down mode only when the user code is executed from SRAM.
Page 145
RM0444 Power control (PWR) Bit 8 PVMENUSB: USB supply voltage monitoring enable This bit enables the monitoring of the USB supply with respect to 1.2 V threshold. 0: Disable 1: Enable Bit 7 PVMENDAC: DAC supply voltage monitoring enable This bit enables the monitoring of the DAC supply with respect to 1.8 V threshold. 0: Disable 1: Enable Bits 6:4 PVDRT[2:0]: Power voltage detector rising threshold selection.
Power control (PWR) RM0444 4.4.3 Power control register 3 (PWR_CR3) Address offset: 0x08 Reset value: 0x0000 8000. This register is not reset when exiting Standby modes and with the PWRRST bit in the APB peripheral reset register 1 (RCC_APBRSTR1). Access: Additional APB cycles are needed to access this register vs. a standard APB access (3 for a write and 2 for a read).
RM0444 Power control (PWR) Bit 4 EWUP5: Enable WKUP5 wakeup pin When this bit is set, the WKUP5 external wakeup pin is enabled and triggers a wakeup from Standby or Shutdown mode when a rising or a falling edge occurs.The active edge is configured via the WP5 bit in the PWR_CR4 register.
Power control (PWR) RM0444 Bit 5 WP6: WKUP6 wakeup pin polarity WKUP6 external wakeup signal polarity (level or edge) triggering wakeup event: 0: High level or rising edge 1: Low level or falling edge Bit 4 WP5: WKUP5 wakeup pin polarity WKUP5 external wakeup signal polarity (level or edge) triggering wakeup event: 0: High level or rising edge 1: Low level or falling edge...
RM0444 Power control (PWR) Bit 8 SBF: Standby flag This bit is set by hardware when the device enters Standby mode and is cleared by setting the CSBF bit in the PWR_SCR register, or by a power-on reset. It is not cleared by the system reset.
Page 150
Power control (PWR) RM0444 Bits 31:16 Reserved, must be kept at reset value. Bit 15 PVMODAC: V monitoring output flag This flag indicates the readiness of the V supply voltage (excess of PVM threshold of about 1.8 V). 0: V not ready 1: V ready...
RM0444 Power control (PWR) 4.4.7 Power status clear register (PWR_SCR) Address offset: 0x18 Reset value: 0x0000 0000. Access: three additional APB cycles are needed to write this register, compared to a standard APB write. Res. Res. Res. Res. Res. Res. Res.
Power control (PWR) RM0444 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU15 PU14 PU13 PU12 PU11 PU10 Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 PUy: Port A pull-up bit y (y = 0 to 15) Setting PUy bit while the corresponding PDy bit is zero and the APC bit of the PWR_CR3 register is set activates a pull-up device on the PA[y] I/O.
RM0444 Power control (PWR) Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU15 PU14 PU13 PU12 PU11 PU10 Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 PUy: Port B pull-up bit y (y = 0 to 15) Setting PUy bit while the corresponding PDy bit is zero and the APC bit of the PWR_CR3 register is set activates a pull-up device on the PB[y] I/O.
Power control (PWR) RM0444 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU15 PU14 PU13 PU12 PU11 PU10 Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 PUy: Port C pull-up bit y (y = 0 to 15) Setting PUy bit while the corresponding PDy bit is zero and the APC bit of the PWR_CR3 register is set activates a pull-up device on the PC[y] I/O.
RM0444 Power control (PWR) Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU15 PU14 PU13 PU12 PU11 PU10 Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 PUy: Port D pull-up bit y (y = 0 to 15) Setting PUy bit while the corresponding PDy bit is zero and the APC bit of the PWR_CR3 register is set activates a pull-up device on the PD[y] I/O.
Power control (PWR) RM0444 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU15 PU14 PU13 PU12 PU11 PU10 Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 PUy: Port E pull-up bit y (y = 0 to 15) Setting PUy bit while the corresponding PDy bit is zero and the APC bit of the PWR_CR3 register is set activates a pull-up device on the PE[y] I/O.
RM0444 Power control (PWR) Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU13 PU12 PU11 PU10 Bits 31:14 Reserved, must be kept at reset value. Bits 13:0 PUy: Port F pull-up bit y (y = 0 to 13) Setting PUy bit while the corresponding PDy bit is zero and the APC bit of the PWR_CR3 register is set activates a pull-up device on the PF[y] I/O.
Power control (PWR) RM0444 4.4.20 PWR register map Table 34. PWR register map and reset values Offset Register LPMS PWR_CR1 [1:0] [2:0] 0x000 Reset value PVDRT PVDFT PWR_CR2 [2:0] [2:0] 0x004 Reset value PWR_CR3 0x008 Reset value PWR_CR4 0x00C Reset value PWR_SR1 0x010 Reset value...
Page 159
RM0444 Power control (PWR) Table 34. PWR register map and reset values (continued) Offset Register PWR_PUCRD 0x038 Reset value PWR_PDCRD 0x03C Reset value PWR_PUCRE 0x040 Reset value PWR_PDCRE 0x044 Reset value PWR_PUCRF 0x048 Reset value PWR_PDCRF 0x04C Reset value Refer to Section 2.2 on page 58 for the register boundary addresses.
Reset and clock control (RCC) RM0444 Reset and clock control (RCC) Reset There are three types of reset, defined as system reset, power reset and RTC domain reset. 5.1.1 Power reset A power reset is generated when one of the following events occurs: •...
RM0444 Reset and clock control (RCC) detection of internal reset sources by external components when the line faces a significant capacitive load. • Reset input In this mode, any valid reset signal on the NRST pin is propagated to device internal logic, but resets generated internally by the device are not visible on the pin.
Reset and clock control (RCC) RM0444 Low-power mode security reset To prevent that critical applications mistakenly enter a low-power mode, three low-power mode security resets are available. If enabled in option bytes, the resets are generated in the following conditions: •...
RM0444 Reset and clock control (RCC) Clocks The device provides the following clock sources producing primary clocks: • HSI16 RC - a high-speed fully-integrated RC oscillator producing HSI16 clock (about 16 MHz) • HSI48 RC - a high-speed fully-integrated RC oscillator producing HSI48 clock for USB (about 48 MHz) •...
Page 164
Reset and clock control (RCC) RM0444 The peripherals are clocked with the clocks from the bus they are attached to (HCLK for AHB, PCLK for APB) except: • TIMx, with these clock sources to select from: – TIMPCLK (selectable for all timers) running at PCLK frequency if the APB prescaler division factor is set to 1, or at twice the PCLK frequency otherwise –...
Page 165
RM0444 Reset and clock control (RCC) • CEC, with these clock sources to select from: – HSI16 clock divided by 488 – • RTC, with these clock sources to select from: – – – HSE clock divided by 32 The functionality in Stop mode (including wakeup) is supported only when the clock is LSI or LSE.
Reset and clock control (RCC) RM0444 Figure 10. Clock tree to IWDG LSI RC 32 kHz RTC WAKEUP from RTC RTCCLK LSCO to RTC OSC32_OUT LSE OSC 32.768 kHz to CEC OSC32_IN Clock HSI16 / 488 detector to UCPD1/2 HSI16 to PWR SYSCLK to AHB bus, core, memory and DMA...
RM0444 Reset and clock control (RCC) 5.2.1 HSE clock The high speed external clock signal (HSE) can be generated from two possible clock sources: • HSE external crystal/ceramic resonator • HSE user external clock The resonator and the load capacitors have to be placed as close as possible to the oscillator pins in order to minimize output distortion and startup stabilization time.
Reset and clock control (RCC) RM0444 External crystal/ceramic resonator (HSE crystal) The 4 to 48 MHz external oscillator has the advantage of producing a very accurate rate on the main clock. The associated hardware configuration is shown in Figure 11. Refer to the electrical characteristics section of the datasheet for more details.
RM0444 Reset and clock control (RCC) For more details on how to measure the HSI16 frequency variation, refer to Section 5.2.16: Internal/external clock measurement with TIM14/TIM16/TIM17. The HSIRDY flag in the Clock control register (RCC_CR) indicates if the HSI16 RC is stable or not.
Reset and clock control (RCC) RM0444 An interrupt can be generated when the PLL is ready, if enabled in the Clock interrupt enable register (RCC_CIER). The enable bit of each PLL output clock (PLLPEN, PLLQEN, and PLLREN) can be modified at any time without stopping the PLL.
RM0444 Reset and clock control (RCC) 5.2.7 System clock (SYSCLK) selection One of the following clocks can be selected as system clock (SYSCLK): • • • HSISYS • • PLLRCLK The system clock maximum frequency is 64 MHz. Upon system reset, the HSISYS clock derived from HSI16 oscillator is selected as system clock.
Reset and clock control (RCC) RM0444 Note: If the CSS is enabled and the HSE clock fails, the CSSI occurs and an NMI is automatically generated. The NMI is executed infinitely unless the CSS interrupt pending bit is cleared. It is therefore necessary that the NMI ISR clears the CSSI by setting the CSSC bit in the Clock interrupt clear register...
RM0444 Reset and clock control (RCC) The LSE clock is in the RTC domain, whereas the HSE and LSI clocks are not. Consequently: • If LSE is selected as RTC clock: – The RTC continues to work even if the V supply is switched off, provided the supply is maintained.
Reset and clock control (RCC) RM0444 The multiplexers for MCO and MCO2, respectively, are controlled by the MCOSEL[3:0] and MCO2SEL[3:0] bitfields of the Clock configuration register (RCC_CFGR). Their outputs are further divided by a factor set through the MCOPRE[2:0] and MCO2PRE[2:0] bitfields of the Clock configuration register (RCC_CFGR).
RM0444 Reset and clock control (RCC) TIM16 By setting the TI1SEL[3:0] field of the TIM16_TISEL register, the clock selected for the input capture channel1 of TIM16 can be one of: • GPIO (refer to the alternate function mapping in the device datasheets). •...
Reset and clock control (RCC) RM0444 Calibration of the HSI16 oscillator For TIM14, TIM15 and TIM17, the primary purpose of connecting the LSE to the channel 1 input capture is to precisely measure HSISYS (derived from HSI16) selected as system clock.
RM0444 Reset and clock control (RCC) Low-power modes • AHB and APB peripheral clocks, including DMA clock, can be disabled by software. • Sleep and Low Power Sleep modes stops the CPU clock. The memory interface clocks (Flash memory and SRAM interfaces) can be stopped by software during sleep mode. The AHB to APB bridge clocks are disabled by hardware during Sleep mode when all the clocks of the peripherals connected to them are disabled.
Reset and clock control (RCC) RM0444 RCC registers Unless otherwise specified, the RCC registers support word, half-word, and byte access, without any wait state. 5.4.1 Clock control register (RCC_CR) Address offset: 0x00 Power-on reset value: 0x0000 0500 Other types of reset: same as power-on reset, except HSEBYP bit that keeps its previous value.
Page 179
RM0444 Reset and clock control (RCC) Bit 18 HSEBYP: HSE crystal oscillator bypass Set and cleared by software to bypass the oscillator with an external clock. The external clock must be enabled with the HSEON bit set, to be used by the device. The HSEBYP bit can be written only if the HSE oscillator is disabled.
Reset and clock control (RCC) RM0444 Bit 8 HSION: HSI16 clock enable Set and cleared by software. Cleared by hardware to stop the HSI16 oscillator when entering Stop, Standby, or Shutdown mode. Forced by hardware to keep the HSI16 oscillator ON when it is used directly or indirectly as system clock (also when leaving Stop, Standby, or Shutdown modes, or in case of failure of the HSE oscillator used for system clock).
Page 181
RM0444 Reset and clock control (RCC) MCOPRE[3:0] MCOSEL[3:0] MCO2PRE[3:0] MCO2SEL[3:0] Res. PPRE[2:0] HPRE[3:0] Res. Res. SWS[2:0] SW[2:0] 1. Only significant on devices integrating the corresponding output, otherwise reserved. Refer to Section 1.4: Availability of peripherals. Bits 31:28 MCOPRE[3:0]: Microcontroller clock output prescaler This bitfield is controlled by software.
Page 182
Reset and clock control (RCC) RM0444 Bits 23:20 MCO2PRE[3:0]: Microcontroller clock output 2 prescaler This bitfield is controlled by software. It sets the division factor of the clock sent to the MCO2 output as follows: 0000: 1 0001: 2 0010: 4 0111: 128 1000: 256 1001: 512...
RM0444 Reset and clock control (RCC) Bits 11:8 HPRE[3:0]: AHB prescaler This bitfield is controlled by software. To produce HCLK clock, it sets the division factor of SYSCLK clock as follows: 0xxx: 1 1000: 2 1001: 4 1010: 8 1011: 16 1100: 64 1101: 128 1110: 256...
Page 184
Reset and clock control (RCC) RM0444 where f is the PLL input clock frequency, f is the PLL VCO frequency, and P, Q and PLLIN R are f division factors and f and f the clock frequencies of the PLLPCLK, PLLP PLLQ PLLR...
Page 185
RM0444 Reset and clock control (RCC) Bits 21:17 PLLP[4:0]: PLL VCO division factor P for PLLPCLK clock output This bitfield is controlled by software. It sets the PLL VCO division factor P as follows: 00000: Reserved 00001: 2 11111: 32 The bitfield can be written only when the PLL is disabled.
Reset and clock control (RCC) RM0444 Bits 1:0 PLLSRC: PLL input clock source This bit is controlled by software to select PLL clock source, as follows: 00: No clock 01: Reserved 10: HSI16 11: HSE The bitfield can be written only when the PLL is disabled. When the PLL is not used, selecting 00 allows saving power.
RM0444 Reset and clock control (RCC) Bits 31:6 Reserved, must be kept at reset value. Bit 5 PLLRDYIE: PLL ready interrupt enable Set and cleared by software to enable/disable interrupt caused by PLL lock: 0: Disable 1: Enable Bit 4 HSERDYIE: HSE ready interrupt enable Set and cleared by software to enable/disable interrupt caused by the HSE oscillator stabilization: 0: Disable...
Page 188
Reset and clock control (RCC) RM0444 Bits 31:10 Reserved, must be kept at reset value. Bit 9 LSECSSF: LSE clock security system interrupt flag Set by hardware when a failure is detected in the LSE oscillator. Cleared by software by setting the LSECSSC bit. 0: No clock security interrupt caused by LSE clock failure 1: Clock security interrupt caused by LSE clock failure Bit 8 CSSF: HSE clock security system interrupt flag...
RM0444 Reset and clock control (RCC) Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMA2 FLASH DMA1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability peripherals.
Page 192
Reset and clock control (RCC) RM0444 UCPD DAC1 UCPD1 I2C3 USART4 USART3 CRSR LPTIM1 LPTIM2 I2C2 I2C1 USART2 UART1 FDCA SPI3 USART6 USART5 UART2 TIM7 TIM6 TIM4 SPI2 TIM3 TIM2 Res. Res. Res. Res. 1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability peripherals.
Page 193
RM0444 Reset and clock control (RCC) Bit 23 I2C3RST: I2C3 reset Set and cleared by software. 0: No effect 1: Reset I2C3 Bit 22 I2C2RST: I2C2 reset Set and cleared by software. 0: No effect 1: Reset I2C2 Bit 21 I2C1RST: I2C1 reset Set and cleared by software.
Reset and clock control (RCC) RM0444 Bit 12 FDCAN: FDCAN reset Set and cleared by software. 0: No effect 1: Reset FDCAN Bits 11:10 Reserved, must be kept at reset value. Bit 9 USART6RST: USART3 reset Set and cleared by software. 0: No effect 1: Reset USART6 Bit 8 USART5RST: USART3 reset...
Page 195
RM0444 Reset and clock control (RCC) TIM15 TIM17 TIM16 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TIM14 USART1 SPI1 TIM1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability peripherals.
Reset and clock control (RCC) RM0444 Bit 11 TIM1RST: TIM1 timer reset Set and cleared by software. 0: No effect 1: Reset TIM1 timer Bits 10:1 Reserved, must be kept at reset value. Bit 0 SYSCFGRST: SYSCFG, COMP and VREFBUF reset Set and cleared by software.
RM0444 Reset and clock control (RCC) Bit 2 GPIOCEN: I/O port C clock enable This bit is set and cleared by software. 0: Disable 1: Enable Bit 1 GPIOBEN: I/O port B clock enable This bit is set and cleared by software. 0: Disable 1: Enable Bit 0 GPIOAEN: I/O port A clock enable...
Reset and clock control (RCC) RM0444 Bit 8 FLASHEN: Flash memory interface clock enable Set and cleared by software. 0: Disable 1: Enable This bit can only be cleared when the Flash memory is in power down mode. Bits 7:2 Reserved, must be kept at reset value. Bit 1 DMA2EN: DMA2 and DMAMUX clock enable Set and cleared by software.
Page 199
RM0444 Reset and clock control (RCC) Bit 28 PWREN: Power interface clock enable Set and cleared by software. 0: Disable 1: Enable Bit 27 DBGEN: Debug support clock enable Set and cleared by software. 0: Disable 1: Enable Bit 26 UCPD2EN: UCPD2 clock enable Set and cleared by software.
Page 200
Reset and clock control (RCC) RM0444 Bit 17 USART2EN: USART2 clock enable Set and cleared by software. 0: Disable 1: Enable Bit 16 CRSEN: CRS clock enable Set and cleared by software. 0: Disable 1: Enable Bit 15 SPI3EN: SPI3 clock enable Set and cleared by software.
RM0444 Reset and clock control (RCC) Bit 6 Reserved, must be kept at reset value. Bit 5 TIM7EN: TIM7 timer clock enable Set and cleared by software. 0: Disable 1: Enable Bit 4 TIM6EN: TIM6 timer clock enable Set and cleared by software. 0: Disable 1: Enable Bit 2 TIM4EN: TIM4 timer clock enable...
Reset and clock control (RCC) RM0444 Bit 18 TIM17EN: TIM16 timer clock enable Set and cleared by software. 0: Disable 1: Enable Bit 17 TIM16EN: TIM16 timer clock enable Set and cleared by software. 0: Disable 1: Enable Bit 16 TIM15EN: TIM15 timer clock enable Set and cleared by software.
RM0444 Reset and clock control (RCC) Bits 7:2 Reserved, must be kept at reset value. Bit 1 DMA2SMEN: DMA2 and DMAMUX clock enable during Sleep mode Set and cleared by software. 0: Disable 1: Enable Clock to DMAMUX during Sleep mode is enabled as long as the clock in Sleep mode is enabled to at least one DMA peripheral.
Page 206
Reset and clock control (RCC) RM0444 Bit 28 PWRSMEN: Power interface clock enable during Sleep mode Set and cleared by software. 0: Disable 1: Enable Bit 27 DBGSMEN: Debug support clock enable during Sleep mode Set and cleared by software. 0: Disable 1: Enable Bit 26 UCPD2SMEN: UCPD2 clock enable during Sleep mode...
Page 207
RM0444 Reset and clock control (RCC) Bit 17 USART2SMEN: USART2 clock enable during Sleep and Stop modes Set and cleared by software. 0: Disable 1: Enable Bit 16 CRSSMEN: CRS clock enable during Sleep and Stop modes Set and cleared by software. 0: Disable 1: Enable Bit 15 SPI3SMEN: SPI3 clock enable during Sleep mode...
Reset and clock control (RCC) RM0444 Bit 5 TIM7SMEN: TIM7 timer clock enable during Sleep mode Set and cleared by software. 0: Disable 1: Enable Bit 4 TIM6SMEN: TIM6 timer clock enable during Sleep mode Set and cleared by software. 0: Disable 1: Enable Bit 3 Reserved, must be kept at reset value.
RM0444 Reset and clock control (RCC) Bit 18 TIM17SMEN: TIM16 timer clock enable during Sleep mode Set and cleared by software. 0: Disable 1: Enable Bit 17 TIM16SMEN: TIM16 timer clock enable during Sleep mode Set and cleared by software. 0: Disable 1: Enable Bit 16 TIM15SMEN: TIM15 timer clock enable during Sleep mode...
Page 210
Reset and clock control (RCC) RM0444 TIM15 TIM1 ADCSEL[1:0] Res. Res. LPTIM2SEL[1:0] LPTIM1SEL[1:0] Res. Res. RNGDIV[1:0] RNGSEL[1:0] LPUART2SEL USART3SEL USART2SEL LPUART1SEL USART1SEL I2C2I2S1SEL[1:0] I2C1SEL[1:0] Res. [1:0] [1:0] [1:0] [1:0] [1:0] 1. Only significant on devices integrating the corresponding peripheral supporting independent clock selection (or supporting the corresponding function), otherwise reserved.
Page 211
RM0444 Reset and clock control (RCC) Bits 19:18 LPTIM1SEL[1:0]: LPTIM1 clock source selection This bitfield is controlled by software to select LPTIM1 clock source as follows: 00: PCLK 01: LSI 10: HSI16 11: LSE Bits 17:16 Reserved, must be kept at reset value. Bits 15:14 I2C2I2S1SEL[1:0]: I2C2/I2S1 clock source selection This bitfield is controlled by software to select I2S1/I2C2 clock source as follows: 00: PCLK/SYSCLK...
Reset and clock control (RCC) RM0444 Bits 5:4 USART3SEL[1:0]: USART3 clock source selection This bitfield is controlled by software to select USART2 clock source as follows: 00: PCLK 01: SYSCLK 10: HSI16 11: LSE Bits 3:2 USART2SEL[1:0]: USART2 clock source selection This bitfield is controlled by software to select USART2 clock source as follows: 00: PCLK 01: SYSCLK...
RM0444 Reset and clock control (RCC) Bits 9:8 FDCANSEL[1:0]: FDCAN clock source selection This bitfield is controlled by software to select the FDCAN clock as follows: 00: PCLK 01: PLLQCLK 10: HSE 11: Reserved Bits 7:4 Reserved, must be kept at reset value. Bits 3:2 I2S2SEL[1:0]: I2S2 clock source selection This bitfield is controlled by software to select I2S2 clock source as follows: 00: SYSCLK...
Page 214
Reset and clock control (RCC) RM0444 Bits 31:26 Reserved, must be kept at reset value. Bit 25 LSCOSEL: Low-speed clock output selection Set and cleared by software to select the low-speed output clock: 0: LSI 1: LSE Bit 24 LSCOEN: Low-speed clock output (LSCO) enable Set and cleared by software.
RM0444 Reset and clock control (RCC) Bits 4:3 LSEDRV[1:0] LSE oscillator drive capability Set by software to select the LSE oscillator drive capability as follows: 00: low driving capability 01: medium-low driving capability 10: medium-high driving capability 11: high driving capability Applicable when the LSE oscillator is in Xtal mode, as opposed to bypass mode.
Page 216
Reset and clock control (RCC) RM0444 Bit 31 LPWRRSTF: Low-power reset flag Set by hardware when a reset occurs due to illegal Stop, Standby, or Shutdown mode entry. Cleared by setting the RMVF bit. 0: No illegal mode reset occurred 1: Illegal mode reset occurred This operates only if nRST_STOP, nRST_STDBY or nRST_SHDW option bits are cleared.
RM0444 Reset and clock control (RCC) Bits 22:2 Reserved, must be kept at reset value. Bit 1 LSIRDY: LSI oscillator ready Set and cleared by hardware to indicate when the LSI oscillator is ready (stable): 0: Not ready 1: Ready After the LSION bit is cleared, LSIRDY goes low after 3 LSI oscillator clock cycles.
Page 218
Reset and clock control (RCC) RM0444 Table 36. RCC register map and reset values (continued) Off- Register RCC_CIER 0x18 0 0 0 0 0 0 Reset value RCC_CIFR 0x1C 0 0 0 0 0 0 Reset value RCC_CICR 0x20 0 0 0 0 0 0 Reset value RCC_ IOPRSTR...
RM0444 Clock recovery system (CRS) Clock recovery system (CRS) This section applies to STM32G0B1 and STM32G0C1 devices only. Introduction The clock recovery system (CRS) is an advanced digital controller acting on the internal fine-granularity trimmable RC oscillator HSI48. The CRS provides powerful means for oscillator output frequency evaluation, based on comparison with a selectable synchronization signal.
Clock recovery system (CRS) RM0444 Table 38. CRS internal input/output signals Internal signal name Signal type Description crs_sync_in_1 Input 00: GPIO AF selected as SYNC signal source crs_sync_in_2 Input 01: LSE selected as SYNC signal source crs_sync_in_3 Input 10: USB SOF selected as SYNC signal source (default) crs_sync_in_4 Input 11: Reserved...
RM0444 Clock recovery system (CRS) It is also possible to generate a synchronization event by software, by setting the SWSYNC bit in the CRS_CR register. 6.4.3 Frequency error measurement The frequency error counter is a 16-bit down/up counter which is reloaded with the RELOAD value on each SYNC event.
Clock recovery system (CRS) RM0444 6.4.4 Frequency error evaluation and automatic trimming The measured frequency error is evaluated by comparing its value with a set of limits: – TOLERANCE LIMIT, given directly in the FELIM field of the CRS_CFGR register –...
RM0444 Clock recovery system (CRS) FELIM value The selection of the FELIM value is closely coupled with the HSI48 oscillator characteristics and its typical trimming step size. The optimal value corresponds to half of the trimming step size, expressed as a number of HSI48 oscillator clock ticks. The following formula can be used: FELIM = (f ) * STEP[%] / 100% / 2...
Clock recovery system (CRS) RM0444 CRS registers Refer to Section 1.2 on page 53 for a list of abbreviations used in register descriptions. The peripheral registers can be accessed only by words (32-bit). 6.7.1 CRS control register (CRS_CR) Address offset: 0x00 Reset value: 0x0000 X000 (X=4 for products supporting 7-bit TRIM width, otherwise X=2) Res.
Clock recovery system (CRS) RM0444 Bits 26:24 SYNCDIV[2:0]: SYNC divider These bits are set and cleared by software to control the division factor of the SYNC signal. 000: SYNC not divided (default) 001: SYNC divided by 2 010: SYNC divided by 4 011: SYNC divided by 8 100: SYNC divided by 16 101: SYNC divided by 32...
Page 229
RM0444 Clock recovery system (CRS) Bit 9 SYNCMISS: SYNC missed This flag is set by hardware when the frequency error counter reached value FELIM * 128 and no SYNC was detected, meaning either that a SYNC pulse was missed or that the frequency error is too big (internal frequency too high) to be compensated by adjusting the TRIM value, and that some other action has to be taken.
General-purpose I/Os (GPIO) RM0444 General-purpose I/Os (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) and a 32-bit set/reset register (GPIOx_BSRR). In addition all GPIOs have a 32-bit locking register (GPIOx_LCKR) and two 32-bit alternate function selection registers (GPIOx_AFRH and GPIOx_AFRL).
RM0444 General-purpose I/Os (GPIO) Figure 17 shows the basic structures of a standard I/O port bit. Table 42 gives the possible port bit configurations. Figure 17. Basic structure of an I/O port bit To/from on-chip Analog input/output peripherals, power control Digital input and EXTI On/off...
RM0444 General-purpose I/Os (GPIO) Each I/O pin has a multiplexer with up to eight alternate function inputs (AF0 to AF7) that can be configured through the GPIOx_AFRL (for pin 0 to 7) and GPIOx_AFRH (for pin 8 to 15) registers: •...
General-purpose I/Os (GPIO) RM0444 Section 7.4.5: GPIO port input data register (GPIOx_IDR) (x = A to F) Section 7.4.6: GPIO port output data register (GPIOx_ODR) (x = A to F) for the register descriptions. 7.3.5 I/O data bitwise handling The bit set reset register (GPIOx_BSRR) is a 32-bit register which allows the application to set and reset each individual bit in the output data register (GPIOx_ODR).
RM0444 General-purpose I/Os (GPIO) thus select any one of the possible functions for each I/O. The AF selection signal being common to the alternate function input and alternate function output, a single channel is selected for the alternate function input/output of a given I/O. To know which functions are multiplexed on each GPIO pin refer to the device datasheet.
General-purpose I/Os (GPIO) RM0444 7.3.10 Output configuration When the I/O port is programmed as output: • The output buffer is enabled: – Open drain mode: A “0” in the Output register activates the N-MOS whereas a “1” in the Output register leaves the port in Hi-Z (the P-MOS is never activated) –...
General-purpose I/Os (GPIO) RM0444 7.3.13 Using the HSE or LSE oscillator pins as GPIOs When the HSE or LSE oscillator is switched OFF (default state after reset), the related oscillator pins can be used as normal GPIOs. When the HSE or LSE oscillator is switched ON (by setting the HSEON or LSEON bit in the RCC_CSR register) the oscillator takes control of its associated pins and the GPIO configuration of these pins has no effect.
RM0444 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 peripheral registers can be written in word, half word or byte mode. 7.4.1 GPIO port mode register (GPIOx_MODER) (x =A to F)
General-purpose I/Os (GPIO) RM0444 BS15 BS14 BS13 BS12 BS11 BS10 Bits 31:16 BR[15:0]: Port x reset I/O pin y (y = 15 to 0) These bits are write-only. A read to these bits returns the value 0x0000. 0: No action on the corresponding ODRx bit 1: Resets the corresponding ODRx bit Note: If both BSx and BRx are set, BSx has priority.
RM0444 General-purpose I/Os (GPIO) Bits 31:17 Reserved, must be kept at reset value. Bit 16 LCKK: 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.
General-purpose I/Os (GPIO) RM0444 7.4.10 GPIO alternate function high register (GPIOx_AFRH) (x = A to F) Address offset: 0x24 Reset value: 0x0000 0000 AFSEL15[3:0] AFSEL14[3:0] AFSEL13[3:0] AFSEL12[3:0] AFSEL11[3:0] AFSEL10[3:0] AFSEL9[3:0] AFSEL8[3:0] Bits 31:0 AFSELy[3:0]: Alternate function selection for port x pin y (y = 8..15) These bits are written by software to configure alternate function I/Os AFSELy selection: 1000: Reserved...
System configuration controller (SYSCFG) RM0444 System configuration controller (SYSCFG) The devices feature a set of configuration registers. The main purposes of the system configuration controller are the following: • Enabling/disabling I C Fast Mode Plus on some I/O ports • Enabling/disabling the analog switch booster •...
Page 249
RM0444 System configuration controller (SYSCFG) Bits 31:25 Reserved, must be kept at reset value. Bit 24 I2C3_FMP: Fast Mode Plus (FM+) enable for I2C3 This bit is set and cleared by software. It enables I C FM+ driving capability on I/O ports configured as I2C3 through GPIOx_AFR registers.
Page 250
System configuration controller (SYSCFG) RM0444 Bit 18 I2C_PB8_FMP: Fast Mode Plus (FM+) enable for PB8 This bit is set and cleared by software. It enables I C FM+ driving capability on PB8 I/O port. 0: Disable 1: Enable With this bit in disable state, the I C FM+ driving capability on this I/O port can be enabled through one of I2Cx_FMP bits.
RM0444 System configuration controller (SYSCFG) Bit 5 IR_POL: IR output polarity selection 0: Output of IRTIM (IR_OUT) is not inverted 1: Output of IRTIM (IR_OUT) is inverted Bit 4 PA12_RMP: PA12 pin remapping This bit is set and cleared by software. When set, it remaps the PA12 pin to operate as PA10 GPIO port, instead as PA12 GPIO port.
Page 252
System configuration controller (SYSCFG) RM0444 Bits 31:24 Reserved, must be kept at reset value Bit 23 PB2_CDEN: PB2 clamping diode enable bit This bit is set and cleared by software. It enables (connects) a clamping diode to V on PB2 pin.
RM0444 System configuration controller (SYSCFG) Bits 7:4 Reserved, must be kept at reset value. Bit 3 ECC_LOCK: ECC error lock bit This bit is set by software and cleared by a system reset. It can be used to enable and lock the Flash ECC 2-bit error detection signal connection to TIM1/15/16/17 Break input.
RM0444 System configuration controller (SYSCFG) Bits 31:12 Reserved, must be kept at reset value. Bit 11 EXTI15: EXTI line 15 interrupt request pending Bit 10 EXTI14: EXTI line 14 interrupt request pending Bit 9 EXTI13: EXTI line 13 interrupt request pending Bit 8 EXTI12: EXTI line 12 interrupt request pending Bit 7 EXTI11: EXTI line 11 interrupt request pending Bit 6 EXTI10: EXTI line 10 interrupt request pending...
Page 267
RM0444 System configuration controller (SYSCFG) Table 44. SYSCFG register map and reset values (continued) Offset Register SYSCFG_CFGR2 0x18 Reset value 0x1D to Reserved Reserved 0x7F SYSCFG_ITLINE0 0x80 Reset value SYSCFG_ITLINE1 0x84 Reset value SYSCFG_ITLINE2 0x88 Reset value SYSCFG_ITLINE3 0x8C Reset value SYSCFG_ITLINE4 0x90 Reset value...
Page 268
System configuration controller (SYSCFG) RM0444 Table 44. SYSCFG register map and reset values (continued) Offset Register SYSCFG_ITLINE11 0xAC Reset value SYSCFG_ITLINE12 0xB0 Reset value SYSCFG_ITLINE13 0xB4 Reset value SYSCFG_ITLINE14 0xB8 Reset value SYSCFG_ITLINE15 0xBC Reset value SYSCFG_ITLINE16 0xC0 Reset value SYSCFG_ITLINE17 0xC4 Reset value...
Page 269
RM0444 System configuration controller (SYSCFG) Table 44. SYSCFG register map and reset values (continued) Offset Register SYSCFG_ITLINE26 0xE8 Reset value SYSCFG_ITLINE27 0xEC Reset value SYSCFG_ITLINE28 0xF0 Reset value SYSCFG_ITLINE29 0xF4 Reset value SYSCFG_ITLINE30 0xF8 Reset value SYSCFG_ITLINE31 0xFC Reset value Refer to Section 2.2 on page 58 for the register boundary addresses.
Interconnect matrix RM0444 Interconnect matrix Introduction Several peripherals have direct connections between them. This allows autonomous communication and/or synchronization between peripherals, saving CPU resources thus power consumption. In addition, these hardware connections remove software latency and allow design of predictable systems. Depending on peripherals, these interconnections can operate in Run, Sleep, Low-power run, Low-power sleep, Stop 0, and Stop 1 modes.
Interconnect matrix RM0444 Triggering signals The output (from master) is on signal TIMx_TRGO (and TIMx_TRGOx), following a configurable timer event. With TIM14, TIM16, and TIM17 timers that do not have a trigger output, the output compare 1 is used instead. The input (to slave) is on signals TIMx_ITR0/ITR1/ITR2/ITR3.
RM0444 Interconnect matrix Triggering signals The output (from ADC) is on signals ADCn_AWDx_OUT n = 1, 2, 3 (for ADC) x = 1, 2, 3 (three watchdogs per ADC) and the input (to timer) on signal TIMx_ETR (external trigger). Relevant power modes This interconnection operates in Run, Sleep, Low-power run, and Low-power sleep power modes.
Interconnect matrix RM0444 9.3.6 From RTC, TAMP, COMP1, COMP2, and COMP3 to LPTIM1 and LPTIM2 Purpose RTC alarm A/B, TAMP1/2 input detection, COMP1/2_OUT and GPIO alternate function can be used as trigger to start LPTIM counters LPTIM1/2. Triggering signals This trigger feature is described in Section 26.4.7: Trigger multiplexer (and following sections).
RM0444 Interconnect matrix More information is in: • Section 15.2: ADC main features • Section 15.3.8: Channel selection (CHSEL, SCANDIR, CHSELRMOD) • Figure 15.9: Temperature sensor and internal reference voltage • Figure 15.10: Battery voltage monitoring Relevant power modes These interconnections operate in Run, Sleep, Low-power run, and Low-power sleep power modes.
Interconnect matrix RM0444 List of possible source of break are described in: • Section 21.3.16: Using the break function (TIM1) • Section 25.4.13: Using the break function (TIM15/TIM16/TIM17) • Figure 236: TIM15 block diagram • Figure 237: TIM16/TIM17 block diagram Relevant power modes These interconnections operate in Run, Sleep, Low-power run, and Low-power sleep power modes.
RM0444 Direct memory access controller (DMA) Direct memory access controller (DMA) 10.1 Introduction The direct memory access (DMA) controller is a bus master and system peripheral. The DMA is used to perform programmable data transfers between memory-mapped peripherals and/or memories, upon the control of an off-loaded CPU. The DMA controller features a single AHB master architecture.
Direct memory access controller (DMA) RM0444 10.3 DMA implementation 10.3.1 The devices incorporate one or two DMA controller instances. The following implementation table shows the number of DMA channels for either instance. A dash indicates that the instance is not implemented. Table 46.
RM0444 Direct memory access controller (DMA) The DMA block diagram is shown in the figure below. Figure 22. DMA block diagram Ch 1 Ch 2 AHB master interface Ch 7 dma_req [1..7] Arbiter dma_ack [1..7] Interrupt AHB slave interface interface dma_it[1..7] MSv48187V1 The DMA controller performs direct memory transfer by sharing the AHB system bus with...
Direct memory access controller (DMA) RM0444 A DMA block transfer may be requested from a peripheral, or triggered by the software in case of memory-to-memory transfer. After an event, the following steps of a single DMA transfer occur: The peripheral sends a single DMA request signal to the DMA controller. The DMA controller serves the request, depending on the priority of the channel associated to this peripheral request.
RM0444 Direct memory access controller (DMA) The priorities are managed in two stages: • software: priority of each channel is configured in the DMA_CCRx register, to one of the four different levels: – very high – high – medium – •...
Page 282
Direct memory access controller (DMA) RM0444 Channel configuration procedure The following sequence is needed to configure a DMA channel x: Set the peripheral register address in the DMA_CPARx register. The data is moved from/to this address to/from the memory after the peripheral event, or after the channel is enabled in memory-to-memory mode.
Page 283
RM0444 Direct memory access controller (DMA) register content may not correctly reflect the remaining data transfers versus the aborted source and destination buffer/register. • Abort and restart a channel This corresponds to the software sequence: disable an active channel, then reconfigure the channel and enable it again.
Direct memory access controller (DMA) RM0444 Peripheral-to-peripheral mode Any DMA channel can operate in peripheral-to-peripheral mode: • when the hardware request from a peripheral is selected to trigger the DMA channel This peripheral is the DMA initiator and paces the data transfer from/to this peripheral to/from a register belonging to another memory-mapped peripheral (this one being not configured in DMA mode).
RM0444 Direct memory access controller (DMA) Table 48. Programmable data width and endian behavior (when PINC = MINC = 1) Source Destinat Destination port ion port Source content: Number width content: width address / data of data (PSIZE address / data (MSIZE items to DMA transfers...
Direct memory access controller (DMA) RM0444 Assuming the AHB/APB bridge is an AHB 32-bit slave peripheral that does not take into account the HSIZE data, any AHB byte or half-word transfer is changed into a 32-bit APB transfer as described below: •...
RM0444 Direct memory access controller (DMA) 10.6.1 DMA interrupt status register (DMA_ISR) Address offset: 0x00 Reset value: 0x0000 0000 Every status bit is cleared by hardware when the software sets the corresponding clear bit or the corresponding global clear bit CGIFx, in the DMA_IFCR register. Res.
Page 288
Direct memory access controller (DMA) RM0444 Bit 17 TCIF5: transfer complete (TC) flag for channel 5 0: no TC event 1: a TC event occurred Bit 16 GIF5: global interrupt flag for channel 5 0: no TE, HT or TC event 1: a TE, HT or TC event occurred Bit 15 TEIF4: transfer error (TE) flag for channel 4 0: no TE event...
RM0444 Direct memory access controller (DMA) Bit 2 HTIF1: half transfer (HT) flag for channel 1 0: no HT event 1: a HT event occurred Bit 1 TCIF1: transfer complete (TC) flag for channel 1 0: no TC event 1: a TC event occurred Bit 0 GIF1: global interrupt flag for channel 1 0: no TE, HT or TC event 1: a TE, HT or TC event occurred...
Direct memory access controller (DMA) RM0444 Bit 17 CTCIF5: transfer complete flag clear for channel 5 Bit 16 CGIF5: global interrupt flag clear for channel 5 Bit 15 CTEIF4: transfer error flag clear for channel 4 Bit 14 CHTIF4: half transfer flag clear for channel 4 Bit 13 CTCIF4: transfer complete flag clear for channel 4 Bit 12 CGIF4: global interrupt flag clear for channel 4 Bit 11 CTEIF3: transfer error flag clear for channel 3...
Page 291
RM0444 Direct memory access controller (DMA) Bits 31:15 Reserved, must be kept at reset value. Bit 14 MEM2MEM: memory-to-memory mode 0: disabled 1: enabled Note: this bit is set and cleared by software. It must not be written when the channel is enabled (EN = 1). It is read-only when the channel is enabled (EN = 1).
Page 292
Direct memory access controller (DMA) RM0444 Bit 7 MINC: memory increment mode Defines the increment mode for each DMA transfer to the identified memory. In memory-to-memory mode, this field identifies the memory source if DIR = 1 and the memory destination if DIR = 0. In peripheral-to-peripheral mode, this field identifies the peripheral source if DIR = 1 and the peripheral destination if DIR = 0.
RM0444 Direct memory access controller (DMA) Bit 2 HTIE: half transfer interrupt enable 0: disabled 1: enabled Note: this bit is set and cleared by software. It must not be written when the channel is enabled (EN = 1). It is not read-only when the channel is enabled (EN = 1). Bit 1 TCIE: transfer complete interrupt enable 0: disabled 1: enabled...
Direct memory access controller (DMA) RM0444 10.6.5 DMA channel x peripheral address register (DMA_CPARx) Address offset: 0x10 + 0x14 * (x - 1), (x = 1 to 7) Reset value: 0x0000 0000 PA[31:16] PA[15:0] Bits 31:0 PA[31:0]: peripheral address It contains the base address of the peripheral data register from/to which the data will be read/written.
RM0444 Direct memory access controller (DMA) Bits 31:0 MA[31:0]: peripheral address It contains the base address of the memory from/to which the data will be read/written. When MSIZE[1:0] = 01 (16 bits), bit 0 of MA[31:0] is ignored. Access is automatically aligned to a half-word address.
Page 296
Direct memory access controller (DMA) RM0444 Table 50. DMA register map and reset values (continued) Offset Register DMA_CCR3 0x030 Reset value DMA_CNDTR3 NDTR[15:0] 0x034 Reset value DMA_CPAR3 PA[31:0] 0x038 Reset value DMA_CMAR3 MA[31:0] 0x03C Reset value 0x040 Reserved Reserved. DMA_CCR4 0x044 Reset value DMA_CNDTR4...
Page 297
RM0444 Direct memory access controller (DMA) Table 50. DMA register map and reset values (continued) Offset Register DMA_CNDTR7 NDTR[15:0] 0x084 Reset value DMA_CPAR7 PA[31:0] 0x088 Reset value DMA_CMAR7 MA[31:0] 0x08C Reset value Refer to Section 2.2 for the register boundary addresses. RM0444 Rev 5 297/1390...
DMA request multiplexer (DMAMUX) RM0444 DMA request multiplexer (DMAMUX) 11.1 Introduction A peripheral indicates a request for DMA transfer by setting its DMA request signal. The DMA request is pending until it is served by the DMA controller that generates a DMA acknowledge signal, and the corresponding DMA request signal is deasserted.
Page 304
DMA request multiplexer (DMAMUX) RM0444 Caution: A same non-null DMAREQ_ID can be assigned to two different channels only if the application ensures that these channels are not requested to be served at the same time. In other words, if two different channels receive a same asserted hardware request at the same time, an unpredictable DMA hardware behavior occurs.
DMA request multiplexer (DMAMUX) RM0444 Note: If EGE is enabled and NBREQ = 0, an event is generated after each served DMA request. Note: A synchronization event (edge) is detected if the state following the edge remains stable for more than two AHB clock cycles. Upon writing into DMAMUX_CxCR register, the synchronization events are masked during three AHB clock cycles.
RM0444 DMA request multiplexer (DMAMUX) Note: The GNBREQ field value must be written by software only when the enable GE bit of the corresponding generator channel x is disabled. A trigger event (edge) is detected if the state following the edge remains stable for more than two AHB clock cycles.
DMA request multiplexer (DMAMUX) RM0444 11.6 DMAMUX registers Refer to the table containing register boundary addresses for the DMAMUX base address. DMAMUX registers may be accessed per (8-bit) byte, (16-bit) half-word, or (32-bit) word. The address must be aligned with the data size. 11.6.1 DMAMUX request line multiplexer channel x configuration register (DMAMUX_CxCR)
RM0444 DMA request multiplexer (DMAMUX) Bit 7 Reserved, must be kept at reset value. Bits 6:0 DMAREQ_ID[6:0]: DMA request identification Selects the input DMA request. See the DMAMUX table about assignments of multiplexer inputs to resources. 11.6.2 DMAMUX request line multiplexer interrupt channel status register (DMAMUX_CSR) Address offset: 0x080 Reset value: 0x0000 0000...
DMA request multiplexer (DMAMUX) RM0444 11.6.7 DMAMUX register map The following table summarizes the DMAMUX registers and reset values. Refer to the register boundary address table for the DMAMUX register base address. Table 57. DMAMUX register map and reset values Offset Register DMAREQ_ID[6:0]...
RM0444 Extended interrupt and event controller (EXTI) Extended interrupt and event controller (EXTI) The Extended interrupt and event controller (EXTI) manages the CPU and system wakeup through configurable and direct event inputs (lines). It provides wakeup requests to the power control, and generates an interrupt request to the CPU NVIC and events to the CPU event input.
RM0444 Extended interrupt and event controller (EXTI) 13.2.1 EXTI connections between peripherals and CPU The peripherals able to generate wakeup or interrupt events when the system is in Stop mode are connected to the EXTI. • Peripheral wakeup signals that generate a pulse or that do not have an interrupt status bits in the peripheral, are connect to an EXTI configurable line.
Extended interrupt and event controller (EXTI) RM0444 Table 61. EXTI event input configurations and register control Event input Logic implementation type Configurable Configurable event input wakeup logic Direct Direct event input wakeup logic 13.3.1 EXTI configurable event input wakeup Figure 27 is a detailed representation of the logic associated with configurable event inputs which wake up the CPU sub-system bus clocks and generated an EXTI pending flag and interrupt to the CPU and or a CPU wakeup event.
RM0444 Extended interrupt and event controller (EXTI) Note: A detected configurable event interrupt pending request can be cleared by the CPU. The system cannot enter low-power modes as long as an interrupt pending request is active. 13.3.2 EXTI direct event input wakeup Figure 28 is a detailed representation of the logic associated with direct event inputs waking up the system.
Extended interrupt and event controller (EXTI) RM0444 Figure 29. EXTI GPIO mux EXTI_EXTICR1.EXTI0 EXTI_EXTICR1.EXTI1 EXTI_EXTICR4.EXTI15 PA15 PB15 PC15 EXTI0 EXTI1 EXTI15 Px15 MS44726V1 The EXTIs mux outputs are available as output signals from the EXTI, to trigger other functional blocks. The EXTI mux outputs are available independently of mask setting through the EXTI_IMR and EXTI_EMR registers.
RM0444 Extended interrupt and event controller (EXTI) Table 62. EXTI line connections (continued) EXTI line Line source Line type monitoring configurable Direct DDIO2 LPUART2 wakeup Direct 13.4 EXTI functional behavior The direct event inputs are enabled in the respective peripheral generating the wakeup event.
Extended interrupt and event controller (EXTI) RM0444 13.5 EXTI registers The EXTI register map is divided in the following sections: Table 64. EXTI register map sections Address Description 0x000 - 0x01C General configurable event [31:0] configuration 0x060 - 0x06C EXTI I/O port multiplexer 0x080 - 0x0BC CPU input event configuration All the registers can be accessed with word (32-bit), half-word (16-bit) and byte (8-bit)
RM0444 Extended interrupt and event controller (EXTI) 2. The configurable lines are edge triggered, no glitch must be generated on these inputs. If a rising edge on the configurable line occurs during writing of the register, the associated pending bit is not set. Rising edge trigger can be set for a line with falling edge trigger enabled.
Extended interrupt and event controller (EXTI) RM0444 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SWI9 SWI8 SWI7 SWI6 SWI5 SWI4 SWI3 SWI2 SWI1 SWI0 Bits 31:21 Reserved, must be kept at reset value. Bit 20 SWI20: Software rising edge event trigger on line 20 Setting this bit by software triggers a rising edge event on the corresponding line, resulting in an interrupt, independently of EXTI_RTSR1 and EXTI_FTSR1 settings.
RM0444 Extended interrupt and event controller (EXTI) Bits 31:21 Reserved, must be kept at reset value. Bit 20 RPIF20: Rising edge event pending for configurable line 20 This bit is set upon a rising edge event generated by hardware or by software (through the EXTI_SWIER1 register) on the corresponding line.
Extended interrupt and event controller (EXTI) RM0444 Bit 20 FPIF20: Falling edge event pending for configurable line 20 This bit is set upon a falling edge event generated by hardware or by software (through the EXTI_SWIER1 register) on the corresponding line. This bit is cleared by writing 1 into it. 0: No falling edge trigger request occurred 1: Falling edge trigger request occurred The FPIF20 bit is only available in STM32G0B1xx and STM32G0C1xx.
RM0444 Extended interrupt and event controller (EXTI) Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Bits 31:3 Reserved, must be kept at reset value. Bit 2 FT2: Falling trigger event configuration bit of configurable line 34 This bit enables/disables the falling edge trigger for the event and interrupt on the corresponding line.
Page 331
RM0444 Extended interrupt and event controller (EXTI) Reset value: 0x0000 0000 EXTIm fields contain only the number of bits in line with the nb_ioport configuration. EXTIm+3[7:0] EXTIm+2[7:0] EXTIm+1[7:0] EXTIm[7:0] Bits 31:24 EXTIm+3[7:0]: EXTIm+3 GPIO port selection (m = 4 * (x - 1)) These bits are written by software to select the source input for EXTIm+3 external interrupt.
Extended interrupt and event controller (EXTI) RM0444 13.5.12 EXTI CPU wakeup with interrupt mask register (EXTI_IMR1) Address offset: 0x080 (EXTI_IMR1) Reset value: 0xFFF8 0000 Contains register bits for configurable events and direct events. The reset value is set such as to, by default, enable interrupt from direct lines, and disable interrupt from configurable lines.
RM0444 Extended interrupt and event controller (EXTI) 13.5.14 EXTI CPU wakeup with interrupt mask register (EXTI_IMR2) Address offset: 0x090 (EXTI_IMR2) Reset value: 0xFFFF FFFF Contains register bits for configurable events and direct events. The reset value is set such as to, by default, enable interrupt from direct lines, and disable interrupt from configurable lines.
Extended interrupt and event controller (EXTI) RM0444 Bits 31:4 Reserved, must be kept at reset value. Bits 3:0 EMx: CPU wakeup with event generation mask on line x (x = 35 to 32) Setting/clearing each bit unmasks/masks the CPU wakeup with event generation on the corresponding line.
Page 335
RM0444 Extended interrupt and event controller (EXTI) Table 65. EXTI controller register map and reset values (continued) Offset Register EXTI_EXTICR1 EXTI3[7:0] EXTI2[7:0] EXTI1[7:0] EXTI0[7:0] 0x060 Reset value EXTI_EXTICR2 EXTI7[7:0] EXTI6[7:0] EXTI5[7:0] EXTI4[7:0] 0x064 Reset value EXTI_EXTICR3 EXTI11[7:0] EXTI10[7:0] EXTI9[7:0] EXTI8[7:0] 0x068 Reset value EXTI_EXTICR4...
Cyclic redundancy check calculation unit (CRC) RM0444 Cyclic redundancy check calculation unit (CRC) 14.1 Introduction The CRC (cyclic redundancy check) calculation unit is used to get a CRC code from 8-, 16- or 32-bit data word and a generator polynomial. Among other applications, CRC-based techniques are used to verify data transmission or storage integrity.
RM0444 Cyclic redundancy check calculation unit (CRC) 14.3 CRC functional description 14.3.1 CRC block diagram Figure 30. CRC calculation unit block diagram 32-bit AHB bus 32-bit (read access) Data register (output) crc_hclk CRC computation 32-bit (write access) Data register (input) MS19882V2 14.3.2 CRC internal signals...
Page 338
Cyclic redundancy check calculation unit (CRC) RM0444 The input data can be reversed, to manage the various endianness schemes. The reversing operation can be performed on 8 bits, 16 bits and 32 bits depending on the REV_IN[1:0] bits in the CRC_CR register. For example: input data 0x1A2B3C4D is used for CRC calculation as: •...
RM0444 Cyclic redundancy check calculation unit (CRC) 14.4 CRC registers 14.4.1 CRC data register (CRC_DR) Address offset: 0x00 Reset value: 0xFFFF FFFF DR[31:16] DR[15:0] Bits 31:0 DR[31:0]: Data register bits This register is used to write new data to the CRC calculator. It holds the previous CRC calculation result when it is read.
RM0444 Analog-to-digital converter (ADC) Analog-to-digital converter (ADC) 15.1 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 and 3 internal sources. A/D conversion of the various channels can be performed in single, continuous, scan or discontinuous mode.
Analog-to-digital converter (ADC) RM0444 15.2 ADC main features • High performance – 12-bit, 10-bit, 8-bit or 6-bit configurable resolution – ADC conversion time: 0.4 µs for 12-bit resolution (2.5Msps), faster conversion times can be obtained by lowering resolution. – Self-calibration –...
Analog-to-digital converter (ADC) RM0444 Table 69. ADC internal input/output signals Internal signal Signal type Description name Analog Input Connected either to internal channels or to ADC_INi channels external channels TRGx Input ADC conversion triggers Input Internal temperature sensor output voltage SENSE Input Internal voltage reference output voltage...
RM0444 Analog-to-digital converter (ADC) If the main voltage regulator enters low-power mode (such as Low-power run mode), this buffer is disabled and the ADC cannot be used. ADC Voltage regulator enable sequence To enable the ADC voltage regulator, set ADVREGEN bit to 1 in ADC_CR register. ADC voltage regulator disable sequence To disable the ADC voltage regulator, follow the sequence below: Make sure that the ADC is disabled (ADEN = 0).
Analog-to-digital converter (ADC) RM0444 Figure 32. ADC calibration t CAB ADCAL ADC State Startup CALIBRATE CALIBRATION 0x00 ADC_DR[6:0] FACTOR ADC_CALFACT[6:0] by S/W by H/W MS33703V1 Calibration factor forcing Software Procedure Ensure that ADEN = 1 and ADSTART = 0 (ADC started with no conversion ongoing) Write ADC_CALFACT with the saved calibration factor The calibration factor is used as soon as a new conversion is launched.
RM0444 Analog-to-digital converter (ADC) Follow this procedure to enable the ADC: Clear the ADRDY bit in ADC_ISR register by programming this bit to 1. Set ADEN = 1 in the ADC_CR register. Wait until ADRDY = 1 in the ADC_ISR register (ADRDY is set after the ADC startup time).
Analog-to-digital converter (ADC) RM0444 15.3.5 ADC clock (CKMODE, PRESC[3:0]) The ADC has a dual clock-domain architecture, so that the ADC can be fed with a clock (ADC asynchronous clock) independent from the APB clock (PCLK). Figure 35. ADC clock scheme ADITF (Reset &...
RM0444 Analog-to-digital converter (ADC) (1)(2) Table 71. Latency between trigger and start of conversion Latency between the trigger event ADC clock source CKMODE[1:0] and the start of conversion HSI16, SYSCLK, or Latency is not deterministic (jitter) PLLPCLK Latency is deterministic (no jitter) and equal to PCLK divided by 2 3.25 ADC clock cycles Latency is deterministic (no jitter) and equal to...
RM0444 Analog-to-digital converter (ADC) 15.3.7 Configuring the ADC Software must write to the ADCAL and ADEN bits in the ADC_CR register if the ADC is disabled (ADEN must be 0). Software must only write to the ADSTART and ADDIS bits in the ADC_CR register only if the ADC is enabled and there is no pending request to disable the ADC (ADEN = 1 and ADDIS = 0).
Analog-to-digital converter (ADC) RM0444 – Any channel can belong to in these sequences • Sequencer fully configurable The CHSELRMOD bit is set in ADC_CFGR1 register. – Sequencer length is up to 8 channels – The order in which the channels are scanned is independent from the channel number.
RM0444 Analog-to-digital converter (ADC) 15.3.10 Single conversion mode (CONT In Single conversion mode, the ADC performs a single sequence of conversions, converting all the channels once. This mode is selected when CONT = 0 in the ADC_CFGR1 register. Conversion is started by either: •...
Analog-to-digital converter (ADC) RM0444 15.3.12 Starting conversions (ADSTART) Software starts ADC conversions by setting ADSTART = 1. When ADSTART is set, the conversion: • Starts immediately if EXTEN = 00 (software trigger) • At the next active edge of the selected hardware trigger if EXTEN ≠ 00 The ADSTART bit is also used to indicate whether an ADC operation is currently ongoing.
RM0444 Analog-to-digital converter (ADC) 15.3.13 Timings The elapsed time between the start of a conversion and the end of conversion is the sum of the configured sampling time plus the successive approximation time depending on data resolution: = [1.5 + 12.5 ] x t CONV SMPL...
Analog-to-digital converter (ADC) RM0444 15.3.14 Stopping an ongoing conversion (ADSTP) The software can decide to stop any ongoing conversions by setting ADSTP = 1 in the ADC_CR register. This resets the ADC operation and the ADC is idle, ready for a new operation. When the ADSTP bit is set by software, any ongoing conversion is aborted and the result is discarded (ADC_DR register is not updated with the current conversion).
RM0444 Analog-to-digital converter (ADC) Refer to Table 70: External triggers Section 15.3.1: ADC pins and internal signals for the list of all the external triggers that can be used for regular conversion. The software source trigger events can be generated by setting the ADSTART bit in the ADC_CR register.
RM0444 Analog-to-digital converter (ADC) 15.4.6 Low frequency trigger mode Once the ADC is enabled or the last ADC conversion is complete, the ADC is ready to start a new conversion. The ADC needs to be started at a predefined time (t ) otherwise ADC idle converted data might be corrupted due to the transistor leakage (refer to the device...
Analog-to-digital converter (ADC) RM0444 When an overrun condition occurs, the ADC keeps operating and can continue to convert unless the software decides to stop and reset the sequence by setting the ADSTP bit in the ADC_CR register. The OVR flag is cleared by software by writing 1 to it. It is possible to configure if the data is preserved or overwritten when an overrun event occurs by programming the OVRMOD bit in the ADC_CFGR1 register: •...
RM0444 Analog-to-digital converter (ADC) 15.5.3 Managing a sequence of data converted without using the DMA If the conversions are slow enough, the conversion sequence can be handled by software. In this case the software must use the EOC flag and its associated interrupt to handle each data result.
Analog-to-digital converter (ADC) RM0444 When the DMA transfer is complete (all the transfers configured in the DMA controller have been done): • The content of the ADC data register is frozen. • Any ongoing conversion is aborted and its partial result discarded •...
RM0444 Analog-to-digital converter (ADC) 15.7 Analog window watchdog (AWD1EN, AWD1SGL, AWD1CH, ADC_AWDxCR, ADC_AWDxTR) The three AWD analog watchdogs monitor whether some channels remain within a configured voltage range (window). 15.7.1 Description of analog watchdog 1 AWD1 analog watchdog is enabled by setting the AWD1EN bit in the ADC_CFGR1 register. It is used to monitor that either one selected channel or all enabled channels (see Table 75: Analog watchdog 1 channel...
Analog-to-digital converter (ADC) RM0444 Table 75. Analog watchdog 1 channel selection Channels guarded by the analog watchdog AWD1SGL bit AWD1EN bit None All channels Single channel 1. Selected by the AWD1CH[4:0] bits 15.7.2 Description of analog watchdog 2 and 3 The second and third analog watchdogs are more flexible and can guard several selected channels by programming the AWDxCHy in ADC_AWDxCR (x = 2, 3).
RM0444 Analog-to-digital converter (ADC) The AWD comparison is performed at the end of each ADC conversion. The ADC_AWDx_OUT rising edge and falling edge occurs two ADC_CLK clock cycles after the comparison. As ADC_AWDx_OUT is generated by the ADC_CLK domain and AWD flag is generated by the APB clock domain, the rising edges of these signals are not synchronized.
Analog-to-digital converter (ADC) RM0444 Figure 52. ADC_AWDx_OUT signal generation (on a single channel) ADC STATE Conversion1 Conversion2 Conversion1 Conversion2 Conversion1 Conversion2 Conversion1 Conversion2 outside inside outside outside EOC FLAG EOS FLAG Cleared Cleared by SW by SW AWDx FLAG ADCy_AWDx_OUT - Converted channels: 1 and 2 - Only channel 1 is guarded MSv45364V1...
RM0444 Analog-to-digital converter (ADC) 15.8 Oversampler The oversampling unit performs data preprocessing to offload the CPU. It can handle multiple conversions and average them into a single data with increased data width, up to 16-bit. It provides a result with the following form, where N and M can be adjusted: –...
Analog-to-digital converter (ADC) RM0444 Figure 55. Numerical example with 5-bits shift and rounding Raw 20-bit data: Final result after 5-bits shift and rounding to nearest MS31929V1 Table 76 below gives the data format for the various N and M combination, for a raw conversion data equal to 0xFFF.
RM0444 Analog-to-digital converter (ADC) 15.8.1 ADC operating modes supported when oversampling In oversampling mode, most of the ADC operating modes are available: • Single or continuous mode conversions, forward or backward scanned sequences and up to 8 channels programmed sequence •...
ADC V [13] input channel. REFINT The precise voltage of V is individually measured for each part by ST during REFINT production test and stored in the system memory area. Figure 57 shows the block diagram of connections between the temperature sensor, the internal voltage reference and the ADC.
RM0444 Analog-to-digital converter (ADC) Main features • Supported temperature range: –40 to 125 °C • Linearity: ±2 °C max., precision depending on calibration Figure 57. Temperature sensor and V channel block diagram REFINT TSEN control bit Temperature SENSE sensor ADC V [12] converted data VREFEN control bit...
Analog-to-digital converter (ADC) RM0444 Calculating the actual V voltage using the internal reference voltage REF+ voltage may be subject to variation or not precisely known. The embedded internal REF+ reference voltage (V ) and its calibration data acquired by the ADC during the REFINT manufacturing process at V can be used to evaluate the actual V...
RM0444 Analog-to-digital converter (ADC) the correct operation of the ADC, the V pin is internally connected to a bridge divider. This bridge is automatically enabled when VBATEN is set, to connect V to the ADC [14] input channel. As a consequence, the converted digital value is half the V voltage.
Page 380
Analog-to-digital converter (ADC) RM0444 Table 77. ADC interrupts (continued) Interrupt event Event flag Enable control bit Analog watchdog 2 status bit is set AWD2 AWD2IE Analog watchdog 3 status bit is set AWD3 AWD3IE Channel Configuration Ready CCRDY CCRDYIE End of sampling phase EOSMP EOSMPIE Overrun...
RM0444 Analog-to-digital converter (ADC) 15.12 ADC registers Refer to Section 1.2 for a list of abbreviations used in register descriptions. 15.12.1 ADC interrupt and status register (ADC_ISR) Address offset: 0x00 Reset value: 0x0000 0000 Res. Res. Res. Res. Res. Res. Res.
Page 382
Analog-to-digital converter (ADC) RM0444 Bit 7 AWD1: Analog watchdog 1 flag This bit is set by hardware when the converted voltage crosses the values programmed in ADC_TR1 and ADC_HR1 registers. It is cleared by software by programming it to 1. 0: No analog watchdog event occurred (or the flag event was already acknowledged and cleared by software) 1: Analog watchdog event occurred...
Page 384
Analog-to-digital converter (ADC) RM0444 Bit 4 OVRIE: Overrun interrupt enable This bit is set and cleared by software to enable/disable the overrun interrupt. 0: Overrun interrupt disabled 1: Overrun interrupt enabled. An interrupt is generated when the OVR bit is set. Note: The software is allowed to write this bit only when ADSTART bit is cleared to 0 (this ensures that no conversion is ongoing).
Page 386
Analog-to-digital converter (ADC) RM0444 Bit 2 ADSTART: ADC start conversion command This bit is set by software to start ADC conversion. Depending on the EXTEN [1:0] configuration bits, a conversion either starts immediately (software trigger configuration) or once a hardware trigger event occurs (hardware trigger configuration).
Page 388
Analog-to-digital converter (ADC) RM0444 Bit 21 CHSELRMOD: Mode selection of the ADC_CHSELR register This bit is set and cleared by software to control the ADC_CHSELR feature: 0: Each bit of the ADC_CHSELR register enables an input 1: ADC_CHSELR register is able to sequence up to 8 channels Note: The software is allowed to write this bit only when ADSTART bit is cleared to 0 (this ensures that no conversion is ongoing).
Page 389
RM0444 Analog-to-digital converter (ADC) Bits 11:10 EXTEN[1:0]: External trigger enable and polarity selection These bits are set and cleared by software to select the external trigger polarity and enable the trigger. 00: Hardware trigger detection disabled (conversions can be started by software) 01: Hardware trigger detection on the rising edge 10: Hardware trigger detection on the falling edge 11: Hardware trigger detection on both the rising and falling edges...
Page 390
Analog-to-digital converter (ADC) RM0444 Bit 2 SCANDIR: Scan sequence direction This bit is set and cleared by software to select the direction in which the channels is scanned in the sequence. It is effective only if CHSELMOD bit is cleared to 0. 0: Upward scan (from CHSEL0 to CHSEL18) 1: Backward scan (from CHSEL18 to CHSEL0) Note: The software is allowed to write this bit only when ADSTART bit is cleared to 0 (this...
Analog-to-digital converter (ADC) RM0444 Bits 8:5 OVSS[3:0]: Oversampling shift This bit is set and cleared by software. 0000: No shift 0001: Shift 1-bit 0010: Shift 2-bits 0011: Shift 3-bits 0100: Shift 4-bits 0101: Shift 5-bits 0110: Shift 6-bits 0111: Shift 7-bits 1000: Shift 8-bits Others: Reserved Note: The software is allowed to write this bit only when ADSTART = 0 (which ensures that no...
RM0444 Analog-to-digital converter (ADC) Bits 31:27 Reserved, must be kept at reset value. Bits 26:8 SMPSEL[18:0] Channel-x sampling time selection These bits are written by software to define which sampling time is used. 0: Sampling time of CHANNELx use the setting of SMP1[2:0] register. 1: Sampling time of CHANNELx use the setting of SMP2[2:0] register.
Analog-to-digital converter (ADC) RM0444 Bits 31:28 Reserved, must be kept at reset value. Bits 27:16 HT1[11:0]: Analog watchdog 1 higher threshold These bits are written by software to define the higher threshold for the analog watchdog. Refer to Section 15.7: Analog window watchdog (AWD1EN, AWD1SGL, AWD1CH, ADC_AWDxCR, ADC_AWDxTR) on page 369.
RM0444 Analog-to-digital converter (ADC) 15.12.9 ADC channel selection register [alternate] (ADC_CHSELR) Address offset: 0x28 Reset value: 0x0000 0000 The same register can be used in two different modes: – Each ADC_CHSELR bit enables an input (CHSELRMOD = 0 in ADC_CFGR1). Refer to the current section.
Analog-to-digital converter (ADC) RM0444 15.12.10 ADC channel selection register [alternate] (ADC_CHSELR) Address offset: 0x28 Reset value: 0x0000 0000 The same register can be used in two different modes: – Each ADC_CHSELR bit enables an input (CHSELRMOD = 0 in ADC_CFGR1). Refer to the current previous section.
Page 397
RM0444 Analog-to-digital converter (ADC) Bits 19:16 SQ5[3:0]: 5th conversion of the sequence These bits are programmed by software with the channel number (0...14) assigned to the 8th conversion of the sequence. 0b1111 indicates end of the sequence. When 0b1111 (end of sequence) is programmed to the lower sequence channels, these bits are ignored.
Analog-to-digital converter (ADC) RM0444 15.12.11 ADC watchdog threshold register (ADC_AWD3TR) Address offset: 0x2C Reset value: 0x0FFF 0000 Res. Res. Res. Res. HT3[11:0] Res. Res. Res. Res. LT3[11:0] Bits 31:28 Reserved, must be kept at reset value. Bits 27:16 HT3[11:0]: Analog watchdog 3 higher threshold These bits are written by software to define the higher threshold for the analog watchdog.
Page 401
RM0444 Analog-to-digital converter (ADC) Bits 31:25 Reserved, must be kept at reset value. Bit 24 VBATEN: V enable This bit is set and cleared by software to enable/disable the V channel. 0: V channel disabled, DAC_OUT2 connected to ADC channel 14 1: V channel enabled Note: The software is allowed to write this bit only when ADSTART = 0 (which ensures that no...
Digital-to-analog converter (DAC) RM0444 Digital-to-analog converter (DAC) 16.1 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.
RM0444 Digital-to-analog converter (DAC) 16.3 DAC implementation Table 79. DAC features DAC features DAC1 Dual channel Output buffer I/O connection DAC1_OUT1 on PA4, DAC1_OUT2 on PA5 Maximum sampling time 1MSPS Autonomous mode 1. There is no DAC on STM32G031xx and STM32G041xx. RM0444 Rev 5 405/1390...
RM0444 Digital-to-analog converter (DAC) 16.4.2 DAC pins and internal signals The DAC includes: • Up to two output channels • The DAC_OUTx can be disconnected from the output pin and used as an ordinary GPIO • The dac_outx can use an internal pin connection to on-chip peripherals such as comparator, operational amplifier and ADC (if available).
Digital-to-analog converter (DAC) RM0444 Table 82. DAC interconnection Signal name Source Type dac_hold_ck ck_lsi (selected in the RCC) LSI clock selected in the RCC dac_chx_trg1 (x = 1, 2) tim1_trgo Internal signal from on-chip timers dac_chx_trg2 (x = 1, 2) tim2_trgo Internal signal from on-chip timers dac_chx_trg3 (x = 1, 2)
RM0444 Digital-to-analog converter (DAC) Figure 60. Data registers in single DAC channel mode 8-bit right aligned 12-bit left aligned 12-bit right aligned ai14710b • Dual DAC channels (when available) 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) –...
Digital-to-analog converter (DAC) RM0444 16.4.5 DAC conversion The DAC_DORx cannot be written directly and any data transfer to the DAC channelx must be performed by loading the DAC_DHRx register (write operation to DAC_DHR8Rx, DAC_DHR12Lx, DAC_DHR12Rx, DAC_DHR8RD, DAC_DHR12RD or DAC_DHR12LD). Data stored in the DAC_DHRx register are automatically transferred to the DAC_DORx register after one dac_pclk clock cycle, if no hardware trigger is selected (TENx bit in DAC_CR register is reset).
RM0444 Digital-to-analog converter (DAC) 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[3: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 dac_pclk clock cycle.
Digital-to-analog converter (DAC) RM0444 Figure 63. 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 transferred into the DAC_DORx register.
RM0444 Digital-to-analog converter (DAC) 16.4.10 Triangle-wave generation It is possible to add a small-amplitude triangular waveform on a DC or slowly varying signal. DAC triangle-wave generation is selected by setting WAVEx[1:0] to 10”. The amplitude is configured through the MAMPx[3:0] bits in the DAC_CR register. An internal triangle counter is incremented three dac_pclk clock cycles after each trigger event.
Digital-to-analog converter (DAC) RM0444 16.4.11 DAC channel modes Each DAC channel can be configured in Normal mode or Sample and hold mode. The output buffer can be enabled to allow a high drive capability. Before enabling output buffer, the voltage offset needs to be calibrated. This calibration is performed at the factory (loaded after reset) and can be adjusted by software during application operation.
RM0444 Digital-to-analog converter (DAC) The timings for the three phases above are in units of LSI clock periods. As an example, to configure a sample time of 350 µs, a hold time of 2 ms and a refresh time of 100 µs assuming LSI ~32 KHz is selected: 12 cycles are required for sample phase: TSAMPLEx[9:0] = 11, 62 cycles are required for hold phase: THOLDx[9:0] = 62,...
Digital-to-analog converter (DAC) RM0444 Figure 67. DAC Sample and hold mode phase diagram Sampling phase Hold phase Sampling phase Refresh dac_hold phase MSv45340V3 Like in Normal mode, the Sample and hold mode has different configurations. To enable the output buffer, MODEx[2:0] bits in DAC_MCR register must be set to: •...
RM0444 Digital-to-analog converter (DAC) Table 84. Channel output modes summary (continued) MODE [2:0] Mode Buffer Output connections Connected to external pin Enabled Connected to external pin and to on chip peripherals (such as comparators) Sample and hold mode Connected to external pin and to on chip peripherals (such as comparators) Disabled Connected to on chip peripherals (such as comparators)
Digital-to-analog converter (DAC) RM0444 If the DAC channel is active, write 0 to ENx bit in DAC_CR to disable the channel. Select a mode where the buffer is enabled, by writing to DAC_MCR register, MODEx[2:0] = 000b or 001b or 100b or 101b. Start the DAC channelx calibration, by setting the CENx bit in DAC_CR register to 1.
Page 419
RM0444 Digital-to-analog converter (DAC) When a DAC channel1 trigger arrives, the DHR1 register is transferred into DAC_DOR1 (three dac_pclk clock cycles later). When a DAC channel2 trigger arrives, the DHR2 register is transferred into DAC_DOR2 (three dac_pclk clock cycles later). Independent trigger with single LFSR 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.
Page 420
Digital-to-analog converter (DAC) RM0444 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 and TSEL2 bitfields.
Page 421
RM0444 Digital-to-analog converter (DAC) 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 and TSEL2 bitfields. Load the dual DAC channel data to the desired DHR register (DAC_DHR12RD, DAC_DHR12LD or DAC_DHR8RD).
Digital-to-analog converter (DAC) RM0444 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 and TSEL2 bitfields. Configure the two DAC channel WAVEx[1:0] bits as 1x and the same maximum amplitude value using the MAMPx[3:0] bits.
Digital-to-analog converter (DAC) RM0444 16.7 DAC registers Refer to Section 1 on page 53 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by words (32-bit). 16.7.1 DAC control register (DAC_CR) Address offset: 0x00 Reset value: 0x0000 0000 DMAU DMAE...
Page 425
RM0444 Digital-to-analog converter (DAC) Bits 27:24 MAMP2[3:0]: DAC channel2 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 426
Digital-to-analog converter (DAC) RM0444 Bit 16 EN2: DAC channel2 enable This bit is set and cleared by software to enable/disable DAC channel2. 0: DAC channel2 disabled 1: DAC channel2 enabled Note: These bits are available only on dual-channel DACs. Refer to Section 16.3: DAC implementation.
RM0444 Digital-to-analog converter (DAC) Bits 5:2 TSEL1[3:0]: DAC channel1 trigger selection These bits select the external event used to trigger DAC channel1 0000: SWTRIG1 0001: dac_ch1_trg1 0010: dac_ch1_trg2 1111: dac_ch1_trg15 Refer to the trigger selection tables in Section 16.4.2: DAC pins and internal signals details on trigger configuration and mapping.
Digital-to-analog converter (DAC) RM0444 Bits 31:2 Reserved, must be kept at reset value. Bit 1 SWTRIG2: DAC channel2 software trigger This bit is set by software to trigger the DAC in software trigger mode. 0: No trigger 1: Trigger Note: This bit is cleared by hardware (one dac_pclk clock cycle later) once the DAC_DHR2 register value has been loaded into the DAC_DOR2 register.
RM0444 Digital-to-analog converter (DAC) 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. They specify 12-bit data for DAC channel1. Bits 3:0 Reserved, must be kept at reset value. 16.7.5 DAC channel1 8-bit right aligned data holding register (DAC_DHR8R1)
RM0444 Digital-to-analog converter (DAC) 16.7.9 Dual DAC 12-bit right-aligned data holding register (DAC_DHR12RD) Address offset: 0x20 Reset value: 0x0000 0000 Res. Res. Res. Res. DACC2DHR[11:0] Res. Res. Res. Res. DACC1DHR[11:0] 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.
RM0444 Digital-to-analog converter (DAC) 16.7.13 DAC channel2 data output register (DAC_DOR2) This register is available only on dual-channel DACs. Refer to Section 16.3: DAC implementation. Address offset: 0x30 Reset value: 0x0000 0000 Res. Res. Res. Res. Res. Res. Res. Res. Res.
Page 434
Digital-to-analog converter (DAC) RM0444 Bit 31 BWST2: DAC channel2 busy writing sample time flag This bit is systematically set just after Sample and hold mode enable. It is set each time the software writes the register DAC_SHSR2, It is cleared by hardware when the write operation of DAC_SHSR2 is complete.
Page 436
Digital-to-analog converter (DAC) RM0444 Bits 18:16 MODE2[2:0]: DAC channel2 mode These bits can be written only when the DAC is disabled and not in the calibration mode (when bit EN2=0 and bit CEN2 =0 in the DAC_CR register). If EN2=1 or CEN2 =1 the write operation is ignored.
Digital-to-analog converter (DAC) RM0444 16.7.19 DAC sample and hold time register (DAC_SHHR) Address offset: 0x48 Reset value: 0x0001 0001 Res. Res. Res. Res. Res. Res. THOLD2[9:0] Res. Res. Res. Res. Res. Res. THOLD1[9:0] Bits 31:26 Reserved, must be kept at reset value. Bits 25:16 THOLD2[9:0]: DAC channel2 hold time (only valid in Sample and hold mode).
Page 439
RM0444 Digital-to-analog converter (DAC) Bits 31:24 Reserved, must be kept at reset value. Bits 23:16 TREFRESH2[7:0]: DAC channel2 refresh time (only valid in Sample and hold mode) Refresh time= (TREFRESH[7:0]) x LSI clock period Note: This register can be modified only when EN2=0. These bits are available only on dual-channel DACs.
Digital-to-analog converter (DAC) RM0444 16.7.21 DAC register map Table 87 summarizes the DAC registers. Table 87. DAC register map and reset values Register Offset name DAC_CR 0x00 Reset value DAC_ SWTRGR 0x04 Reset value DAC_ DACC1DHR[11:0] DHR12R1 0x08 Reset value DAC_ DACC1DHR[11:0] DHR12L1...
Page 441
RM0444 Digital-to-analog converter (DAC) Table 87. DAC register map and reset values (continued) Register Offset name DAC_CCR OTRIM2[4:0] OTRIM1[4:0] 0x38 Reset value X X X X MODE2 MODE1 DAC_MCR [2:0] [2:0] 0x3C Reset value DAC_ TSAMPLE1[9:0] SHSR1 0x40 Reset value DAC_ TSAMPLE2[9:0] SHSR2...
Voltage reference buffer (VREFBUF) RM0444 Voltage reference buffer (VREFBUF) 17.1 Introduction The devices embed a voltage reference buffer which can be used as voltage reference for ADC, DAC and also as voltage reference for external components through the VREF+ pin. When the VREF+ pin is double-bonded with VDDA pin in a package, the voltage reference buffer is not available and must be kept disabled (refer to datasheet for packages pinout description).
RM0444 Comparator (COMP) Comparator (COMP) 18.1 Introduction The devices embed COMP1, COMP2, and COMP3 (the last on STM32G0B1xx and STM32G0C1xx only) ultra-low-power comparators. The comparators can be used for a variety of functions including: • Wakeup from low-power mode triggered by an analog signal, •...
RM0444 Comparator (COMP) 18.3.5 Window comparator The purpose of window comparator is to monitor the analog voltage if it is within specified voltage range defined by lower and upper threshold. COMP1 and COMP2 or COMP2 and COMP3 can combine to create a window comparator. The monitored analog voltage is connected to the non-inverting (plus) inputs of comparators connected together and the upper and lower threshold voltages are connected to the inverting (minus) inputs of the comparators.
Comparator (COMP) RM0444 18.3.7 Comparator output blanking function The purpose of the blanking function is to prevent the current regulation to trip upon short current spikes at the beginning of the PWM period (typically the recovery current in power switches anti parallel diodes).It consists of a selection of a blanking window which is a timer output compare signal.
RM0444 Comparator (COMP) 18.4 COMP low-power modes Table 96. Comparator behavior in the low power modes Mode Description No effect on the comparators. Sleep Comparator interrupts cause the device to exit the Sleep mode. Low-power run No effect. Low-power sleep No effect. COMP interrupts cause the device to exit the Low-power sleep mode. Stop 0 No effect on the comparators.
Page 452
Comparator (COMP) RM0444 System reset value: 0x0000 0000 LOCK VALUE Res. Res. Res. Res. Res. BLANKSEL PWRMODE HYST POLARITY WINOUT Res. Res. WINMODE Res. INPSEL INMSEL Res. Res. Res. Bit 31 LOCK: COMP1_CSR register lock This bit is set by software and cleared by a system reset. It locks the comparator 3 control bits.
RM0444 Comparator (COMP) Bit 11 WINMODE: Comparator 1 non-inverting input selector for window mode This bit is controlled by software (if not locked). It selects the signal for COMP1_INP input of the comparator 1: 0: Signal selected with INPSEL[1:0] bitfield of this register 1: COMP2_INP signal of the comparator 2 (required for window mode, see Figure Bit 10 Reserved, must be kept at reset value...
Page 454
Comparator (COMP) RM0444 Bit 31 LOCK: COMP2_CSR register lock This bit is set by software and cleared by a system reset. It locks the comparator 3 control bits. When locked, all register bits are read-only. 0: Not locked 1: Locked Bit 30 VALUE: Comparator 2 output status This bit is read-only.
RM0444 Comparator (COMP) Bits 9:8 INPSEL[1:0]: Comparator 2 signal selector for non-inverting input This bitfield is controlled by software (if not locked). It selects the signal for the non-inverting input COMP2_INP of the comparator 2 (also see the WINMODE bit): 00: PB4 01: PB6 10: PA3...
Page 456
Comparator (COMP) RM0444 Bit 24:20 BLANKSEL[4:0]: Comparator 3 blanking source selector This bitfield is controlled by software (if not locked). It selects the blanking source: 00000: None (no blanking) xxxx1: TIM1 OC4 xxx1x: TIM1 OC5 xx1xx: TIM2 OC3 x1xxx: TIM3 OC3 1xxxx: TIM15 OC2 Bit 19:18 PWRMODE[1:0]: Comparator 3 power mode selector This bitfield is controlled by software (if not locked).
Page 457
RM0444 Comparator (COMP) Bits 7:4 INMSEL[3:0]: Comparator 3 signal selector for inverting input INM This bitfield is controlled by software (if not locked). It selects the signal for the inverting input COMP3_INM of the comparator 3: 0000: 1/4 V REFINT 0001: 1/2 V REFINT 0010: 3/4 V...
RM0444 True random number generator (RNG) True random number generator (RNG) 19.1 Introduction The RNG is a true random number generator that provides full entropy outputs to the application as 32-bit samples. It is composed of a live entropy source (analog) and an internal conditioning component.
RM0444 True random number generator (RNG) 19.3.3 Random number generation The true random number generator (RNG) delivers truly random data through its AHB interface at deterministic intervals. Within its boundary the RNG implements the entropy source model pictured on Figure It includes an analog noise source, a digitization stage with post-processing, a conditioning algorithm, a health monitoring block and two interfaces that are used to interact with the entropy source: GetEntropy and HealthTest.
Page 462
True random number generator (RNG) RM0444 Post processing The sample values obtained from a true random noise source consist of 2-bit bitstrings. Because this noise source output is biased, the RNG implements a post-processing component that reduces that bias to a tolerable level. More specifically, for each of the two noise source bits the RNG takes half of the bits from the sampled noise source, and half of the bits from inverted sampled noise source.
RM0444 True random number generator (RNG) Health checks This component ensures that the entire entropy source (with its noise source) starts then operates as expected, obtaining assurance that failures are caught quickly and with a high probability and reliability. The RNG implements the following health check features. Continuous health tests, running indefinitely on the output of the noise source –...
True random number generator (RNG) RM0444 The associated initialization time can be found in Section 19.5: RNG processing time. Figure 74. RNG initialization overview Noise source enable RNGEN=0, then RNGEN=1 Conditioning hardware init Drop samples then check again Error state Generate samples Continuous test(s) not OK...
RM0444 True random number generator (RNG) To run the RNG in polling mode following steps are recommended: Enable the random number generation by setting the RNGEN bit to “1” in the RNG_CR register. Read the RNG_SR register and check that: –...
True random number generator (RNG) RM0444 correctly (see Section 19.3.6: RNG clocking) and then it must clear the CEIS bit interrupt flag. The CECS bit is automatically cleared when clocking condition is normal. Note: The clock error has no impact on generated random numbers, i.e. application can still read RNG_DR register.
RM0444 True random number generator (RNG) 19.4 RNG interrupts In the RNG an interrupt can be produced on the following events: • Data ready flag • Seed error, see Section 19.3.7: Error management • Clock error, see Section 19.3.7: Error management Dedicated interrupt enable control bits are available as shown in Table 100.
True random number generator (RNG) RM0444 19.6.3 Data collection In order to run statistical tests it is required to collect samples from the entropy source at raw data level as well as at the output of the entropy source. Contact STMicroelectronics if above samples need to be retrieved for your product. 468/1390 RM0444 Rev 5...
RM0444 True random number generator (RNG) 19.7 RNG registers The RNG is associated with a control register, a data register and a status register. 19.7.1 RNG control register (RNG_CR) Address offset: 0x000 Reset value: 0x0000 0000 Res. Res. Res. Res. Res.
RM0444 True random number generator (RNG) 19.7.3 RNG data register (RNG_DR) Address offset: 0x008 Reset value: 0x0000 0000 The RNG_DR register is a read-only register that delivers a 32-bit random value when read. After being read this register delivers a new random value after 216 periods of AHB clock if the output FIFO is empty.
RM0444 AES hardware accelerator (AES) AES hardware accelerator (AES) 20.1 Introduction The AES hardware accelerator (AES) encrypts or decrypts data, using an algorithm and implementation fully compliant with the advanced encryption standard (AES) defined in Federal information processing standards (FIPS) publication 197. The peripheral supports CTR, GCM, GMAC, CCM, ECB, and CBC chaining modes for key sizes of 128 or 256 bits.
AES hardware accelerator (AES) RM0444 Chaining modes The following chaining modes are supported by AES, selected through the CHMOD[2:0] bitfield of the AES_CR register: • Electronic code book (ECB) • Cipher block chaining (CBC) • Counter (CTR) • Galois counter mode (GCM) •...
AES hardware accelerator (AES) RM0444 GMAC is similar to GCM, except that it is applied on a message composed only by plaintext authenticated data (that is, only header, no payload). Counter with CBC-MAC (CCM) principle Figure 81. CCM encryption and authentication principle Count 1 Count 2 Count 3...
Page 481
RM0444 AES hardware accelerator (AES) Initialization of AES To initialize AES, first disable it by clearing the EN bit of the AES_CR register. Then perform the following steps in any order: • Configure the AES mode, by programming the MODE[1:0] bitfield of the AES_CR register.
Page 482
AES hardware accelerator (AES) RM0444 Data append using interrupt The method uses interrupt from the AES peripheral to control the data append, through the following sequence: Enable interrupts from AES by setting the CCFIE bit of the AES_CR register. Enable the AES peripheral by setting the EN bit of the AES_CR register. Write first four input data words into the AES_DINR register.
RM0444 AES hardware accelerator (AES) 20.4.5 AES decryption round key preparation Internal key schedule is used to generate AES round keys. In AES encryption, the round 0 key is the one stored in the key registers. AES decryption must start using the last round key.
AES hardware accelerator (AES) RM0444 20.4.7 AES task suspend and resume A message can be suspended if another message with a higher priority must be processed. When this highest priority message is sent, the suspended message can resume in both encryption or decryption mode.
RM0444 AES hardware accelerator (AES) The second ciphertext block is processed in the same way as the first block, except that the I1 data from the first block is used in place of the initialization vector. The decryption continues in this way until the last complete ciphertext block is decrypted. If the message size is not a multiple of 128 bits, the final partial data block is decrypted in the way explained in Section 20.4.6: AES ciphertext stealing and data...
AES hardware accelerator (AES) RM0444 register to 000 or 001, respectively. Data type can also be defined, using DATATYPE[1:0] bitfield. KEYSIZE bitfield must be kept as-is. Write the AES_IVRx registers with the initialization vector (required in CBC mode only). Enable AES by setting the EN bit of the AES_CR register. Write the AES_DINR register four times to input the cipher text (MSB first), as shown in Figure Wait until the CCF flag is set in the AES_SR register.
RM0444 AES hardware accelerator (AES) To resume the processing of a message, proceed as follows: If DMA is used, configure the DMA controller so as to complete the rest of the FIFO IN and FIFO OUT transfers. Ensure that AES is disabled (the EN bit of the AES_CR must be 0). Restore AES_CR register (with correct KEYSIZE) then restore AES_KEYRx registers.
AES hardware accelerator (AES) RM0444 Figure 89. Message construction in CTR mode 16-byte boundaries Zero padding Ciphertext (C) 4-byte boundaries Plaintext (P) Initialization vector (IV) Counter MSv42156V1 The structure of this message is: • A 16-byte initial counter block (ICB), composed of two distinct fields: –...
AES hardware accelerator (AES) RM0444 Suspend/resume operations in CTR mode Like for the CBC mode, it is possible to interrupt a message to send a higher priority message, and resume the message that was interrupted. Detailed CBC suspend/resume sequence is described in Section 20.4.8: AES basic chaining modes (ECB, CBC).
RM0444 AES hardware accelerator (AES) The message has the following structure: • 16-byte initial counter block (ICB), composed of two distinct fields: – Initialization vector (IV): a 96-bit value that must be unique for each encryption cycle with a given key. Note that the GCM standard supports IVs with less than 96 bits, but in this case strict rules apply.
AES hardware accelerator (AES) RM0444 GCM processing Figure 93 describes the GCM implementation in the AES peripheral. The GCM is selected by writing 011 to the CHMOD[2:0] bitfield of the AES_CR register. Figure 93. GCM authenticated encryption (3) Payload Block 1 Block n AES_IVRx ICB + (32-bit counter = 0x02)
Page 495
RM0444 AES hardware accelerator (AES) The authentication mechanism in GCM mode is based on a hash function called GF2mul that performs multiplication by a fixed parameter, called hash subkey (H), within a binary Galois field. A GCM message is processed through the following phases, further described in next subsections: •...
Page 496
AES hardware accelerator (AES) RM0444 GCM payload phase This phase, identical for encryption and decryption, is executed after the GCM header phase. During this phase, the encrypted/decrypted payload is stored in the AES_DOUTR register. The sequence to execute is: Indicate the payload phase, by setting to 10 the GCMPH[1:0] bitfield of the AES_CR register.
RM0444 AES hardware accelerator (AES) Suspend/resume operations in GCM mode To suspend the processing of a message, proceed as follows: If DMA is used, stop the AES DMA transfers to the IN FIFO by clearing the DMAINEN bit of the AES_CR register. If DMA is not used, make sure that the current computation is completed, which is indicated by the CCF flag of the AES_SR register set to 1.
AES hardware accelerator (AES) RM0444 A typical message construction for GMAC is given in Figure Figure 94. Message construction in GMAC mode [Len(A)] Len(A) 16-byte boundaries Last Authenticated data block 4-byte boundaries Authentication tag (T) Initialization vector (IV) Counter Zero padding MSv42158V2 AES GMAC processing Figure 95...
RM0444 AES hardware accelerator (AES) 20.4.12 AES counter with CBC-MAC (CCM) Overview The AES counter with cipher block chaining-message authentication code (CCM) algorithm allows encryption and authentication of plaintext, generating the corresponding ciphertext and tag (also known as message authentication code). To ensure confidentiality, the CCM algorithm is based on AES in counter mode.
Page 500
AES hardware accelerator (AES) RM0444 standard also states that, on MSB bits of the first message block (B1), the associated data length expressed in bytes (a) must be encoded as follows: – If 0 < a < 2 , then it is encoded as [a] , that is, on two bytes.
RM0444 AES hardware accelerator (AES) CCM processing Figure 97 describes the CCM implementation within the AES peripheral (encryption example). This mode is selected by writing 100 into the CHMOD[2:0] bitfield of the AES_CR register. Figure 97. CCM mode authenticated encryption Block 1 Block m (3) Payload...
Page 502
AES hardware accelerator (AES) RM0444 Note: In this mode, the settings 01 and 11 of the MODE[1:0] bitfield are forbidden. A CCM message is processed through the following phases, further described in next subsections: • Init phase: AES processes the first block and prepares the first counter block. •...
Page 503
RM0444 AES hardware accelerator (AES) CCM payload phase (encryption or decryption) This phase, identical for encryption and decryption, is executed after the CCM header phase. During this phase, the encrypted/decrypted payload is stored in the AES_DOUTR register. The sequence to execute is: Indicate the payload phase, by setting to 10 the GCMPH[1:0] bitfield of the AES_CR register.
Page 504
AES hardware accelerator (AES) RM0444 Suspend/resume operations in CCM mode To suspend the processing of a message in header or payload phase, proceed as follows: If DMA is used, stop the AES DMA transfers to the IN FIFO by clearing the DMAINEN bit of the AES_CR register.
RM0444 AES hardware accelerator (AES) 20.4.13 AES data registers and data swapping Data input and output A 128-bit data block is entered into the AES peripheral with four successive 32-bit word writes into the AES_DINR register (bitfield DIN[31:0]), the most significant word (bits [127:96]) first, the least significant word (bits [31:0]) last.
AES hardware accelerator (AES) RM0444 Figure 98. 128-bit block construction with respect to data swap increasing memory address byte 3 byte 2 byte 1 byte 0 DATATYPE[1:0] = 00: no swapping Word 3 Word 2 Word 1 Word 0 D127 D127 DATATYPE[1:0] = 01: 16-bit (half-word) swapping Word 3...
RM0444 AES hardware accelerator (AES) 20.4.14 AES key registers The AES_KEYRx write-only registers store the encryption or decryption key bitfield KEY[127:0] or KEY[255:0]. The data to write to each register is organized in the memory in little-endian order, that is, with most significant byte on the highest address (reads are not allowed for security reason).
AES hardware accelerator (AES) RM0444 DMA transfer must not include the last block. For details, refer to Section 20.4.4: AES procedure to perform a cipher operation. Figure 99. DMA transfer of a 128-bit data block during input phase Chronological order Increasing address Memory accessed through DMA Word3...
RM0444 AES hardware accelerator (AES) When the data transferring between AES and memory is managed by DMA, the CCF flag is not relevant and can be ignored (left set) by software. It must only be cleared when transiting back to data transferring managed by software. See Suspend/resume operations in ECB/CBC modes Section 20.4.8: AES basic chaining modes (ECB, CBC)
AES hardware accelerator (AES) RM0444 Table 108. AES interrupt requests Interrupt Interrupt clear AES interrupt event Event flag Enable bit acronym method computation completed flag CCFIE set CCFC read error flag RDERR ERRIE set ERRC write error flag WRERR 1. Bit of the AES_CR register. 20.6 AES processing latency The tables below summarize the latency to process a 128-bit block for each mode of...
Page 512
AES hardware accelerator (AES) RM0444 Bit 12 DMAOUTEN: DMA output enable This bit enables/disables data transferring with DMA, in the output phase: 0: Disable 1: Enable When the bit is set, DMA requests are automatically generated by AES during the output data phase.
RM0444 AES hardware accelerator (AES) Bits 4:3 MODE[1:0]: AES operating mode This bitfield selects the AES operating mode: 00: Mode 1: encryption 01: Mode 2: key derivation (or key preparation for ECB/CBC decryption) 10: Mode 3: decryption 11: Mode 4: key derivation then single decryption Attempts to write the bitfield are ignored when the EN bit of the AES_CR register is set before the write access and it is not cleared by that write access.
AES hardware accelerator (AES) RM0444 Bit 2 WRERR: Write error This flag indicates the detection of an unexpected write operation to the AES_DINR register (during computation or data output phase): 0: Not detected 1: Detected The flag is set by hardware. It is cleared by software upon setting the ERRC bit of the AES_CR register.
RM0444 AES hardware accelerator (AES) Bits 31:0 DIN[31:0]: Input data word A four-fold sequential write to this bitfield during the input phase results in writing a complete 128-bit block of input data to the AES peripheral. From the first to the fourth write, the corresponding data weights are [127:96], [95:64], [63:32], and [31:0].
AES hardware accelerator (AES) RM0444 20.7.5 AES key register 0 (AES_KEYR0) Address offset: 0x10 Reset value: 0x0000 0000 KEY[31:16] KEY[15:0] Bits 31:0 KEY[31:0]: Cryptographic key, bits [31:0] This write-only bitfield contains the bits [31:0] of the AES encryption or decryption key, depending on the operating mode: - In Mode 1 (encryption), Mode 2 (key derivation) and Mode 4 (key derivation then single decryption): the value to write into the bitfield is the encryption key.
AES hardware accelerator (AES) RM0444 Bits 31:0 IVI[31:0]: Initialization vector input, bits [31:0] Refer to Section 20.4.15: AES initialization vector registers on page 507 for description of the IVI[127:0] bitfield. The initialization vector is only used in chaining modes other than ECB. The AES_IVRx registers may be written only when the AES peripheral is disabled 20.7.10 AES initialization vector register 1 (AES_IVR1)
AES hardware accelerator (AES) RM0444 20.7.16 AES key register 7 (AES_KEYR7) Address offset: 0x3C Reset value: 0x0000 0000 KEY[255:240] KEY[239:224] Bits 31:0 KEY[255:224]: Cryptographic key, bits [255:224] Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield. Note: The key registers from 4 to 7 are used only when the key length of 256 bits is selected. They have no effect when the key length of 128 bits is selected (only key registers 0 to 3 are used in that case).
RM0444 Advanced-control timer (TIM1) Advanced-control timer (TIM1) In this section, “TIMx” should be understood as “TIM1” since there is only one instance of this type of timer for the products to which this reference manual applies. 21.1 TIM1 introduction The advanced-control timer (TIM1) consists of a 16-bit auto-reload counter driven by a programmable prescaler.
Advanced-control timer (TIM1) RM0444 21.2 TIM1 main features TIM1 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. •...
Advanced-control timer (TIM1) RM0444 21.3 TIM1 functional description 21.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.
RM0444 Advanced-control timer (TIM1) Figure 102. 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 103.
Advanced-control timer (TIM1) RM0444 21.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 (TIMx_RCR) + 1.
RM0444 Advanced-control timer (TIM1) Figure 108. 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 109.
Page 532
Advanced-control timer (TIM1) RM0444 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 (TIMx_RCR) + 1.
RM0444 Advanced-control timer (TIM1) Figure 114. 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...
Advanced-control timer (TIM1) RM0444 DMA request is sent). This is to avoid generating both update and capture interrupts when clearing the counter on the capture event. When an update event occurs, all the registers are updated and the update flag (UIF bit in TIMx_SR register) is set (depending on the URS bit): •...
Advanced-control timer (TIM1) RM0444 In Center aligned mode, for odd values of RCR, the update event occurs either on the overflow or on the underflow depending on when the RCR register was written and when the counter was launched: if the RCR was written before launching the counter, the UEV occurs on the underflow.
RM0444 Advanced-control timer (TIM1) 21.3.4 External trigger input The timer features an external trigger input ETR. It can be used as: • external clock (external clock mode 2, see Section 21.3.5) • trigger for the slave mode (see Section 21.3.26) •...
Advanced-control timer (TIM1) RM0444 21.3.5 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 • Encoder mode Internal clock source (CK_INT) If the slave mode controller is disabled (SMS=000), then the CEN, DIR (in the TIMx_CR1 register) and UG bits (in the TIMx_EGR register) are actual control bits and can be changed...
Advanced-control timer (TIM1) RM0444 Figure 126. 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.
RM0444 Advanced-control timer (TIM1) 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.
Advanced-control timer (TIM1) RM0444 21.3.6 Capture/compare channels Each Capture/Compare channel is built around a capture/compare register (including a shadow register), an input stage for capture (with digital filter, multiplexing, and prescaler, except for channels 5 and 6) and an output stage (with comparator and output control). Figure 129 Figure 132 give an overview of one Capture/Compare channel.
RM0444 Advanced-control timer (TIM1) detected (sampled at f frequency). Then write IC1F bits to 0011 in the TIMx_CCMR1 register. Select the edge of the active transition on the TI1 channel by writing CC1P and CC1NP bits to 0 in the TIMx_CCER register (rising edge in this case). Program the input prescaler.
Advanced-control timer (TIM1) RM0444 Select the proper TI1x source (internal or external) with the TI1SEL[3:0] bits in the TIMx_TISEL register. Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1 register (TI1 selected). Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter clear): write the CC1P and CC1NP bits to ‘0’...
RM0444 Advanced-control timer (TIM1) 21.3.10 Output compare mode This function is used to control an output waveform or indicate when a period of time has elapsed. Channels 1 to 4 can be output, while Channel 5 and 6 are only available inside the device (for instance, for compound waveform generation or for ADC triggering).
Advanced-control timer (TIM1) RM0444 Figure 135. Output compare mode, toggle on OC1 Write B201h in the CC1R register 0039 003A 003B B200 B201 TIM1_CNT B201 003A TIM1_CCR1 OC1REF= OC1 Match detected on CCR1 Interrupt generated if enabled MS31092V1 21.3.11 PWM mode Pulse Width Modulation mode allows a signal to be generated with a frequency determined by the value of the TIMx_ARR register and a duty cycle determined by the value of the TIMx_CCRx register.
RM0444 Advanced-control timer (TIM1) PWM edge-aligned mode • Upcounting configuration Upcounting is active when the DIR bit in the TIMx_CR1 register is low. Refer to the Upcounting mode on page 528. In the following example, we consider PWM mode 1. The reference PWM signal OCxREF is high as long as TIMx_CNT <...
Advanced-control timer (TIM1) RM0444 TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to Center-aligned mode (up/down counting) on page 535. Figure 137 shows some center-aligned PWM waveforms in an example where: • TIMx_ARR=8, • PWM mode is the PWM mode 1, •...
RM0444 Advanced-control timer (TIM1) 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.
RM0444 Advanced-control timer (TIM1) Figure 139. Combined PWM mode on channel 1 and 3 OC2’ OC1’ OC1REF OC2REF OC1REF’ OC2REF’ OC1REFC OC1REFC’ OC1REFC = OC1REF AND OC2REF OC1REFC’ = OC1REF’ OR OC2REF’ MS31094V1 21.3.14 Combined 3-phase PWM mode Combined 3-phase PWM mode allows one to three center-aligned PWM signals to be generated with a single programmable signal ANDed in the middle of the pulses.
Advanced-control timer (TIM1) RM0444 Figure 140. 3-phase combined PWM signals with multiple trigger pulses per period Counter OC5ref OC1refC OC2refC OC3refC Preload Active OC4ref OC6ref TRGO2 MS33102V1 The TRGO2 waveform shows how the ADC can be synchronized on given 3-phase PWM signals.
RM0444 Advanced-control timer (TIM1) Dead-time insertion is enabled by setting both CCxE and CCxNE bits, and the MOE bit if the break circuit is present. There is one 10-bit dead-time generator for each channel. From a reference waveform OCxREF, it generates 2 outputs OCx and OCxN. If OCx and OCxN are active high: •...
Advanced-control timer (TIM1) RM0444 Figure 143. Dead-time waveforms with delay greater than the positive pulse OCxREF OCxN delay MS31097V1 The dead-time delay is the same for each of the channels and is programmable with the DTG bits in the TIMx_BDTR register. Refer to Section 21.4.20: TIM1 break and dead-time register (TIM1_BDTR) for delay calculation.
Page 561
RM0444 Advanced-control timer (TIM1) The output enable signal and output levels during break are depending on several control bits: – the MOE bit in TIMx_BDTR register allows the outputs to be enabled/disabled by software and is reset in case of break or break2 event. –...
Advanced-control timer (TIM1) RM0444 All sources are ORed before entering the timer BRK or BRK2 inputs, as per Figure 144 below. Figure 144. Break and Break2 circuitry overview Lockup LOCK Core Lockup PVD LOCK System break requests SBIF flag Parity LOCK RAM parity Error ECC LOCK Double ECC Error...
Page 563
RM0444 Advanced-control timer (TIM1) When one of the breaks occurs (selected level on one of the break inputs): • The MOE bit is cleared asynchronously, putting the outputs in inactive state, idle state or even releasing the control to the GPIO controller (selected by the OSSI bit). This feature is enabled even if the MCU oscillator is off.
RM0444 Advanced-control timer (TIM1) The two break inputs have different behaviors on timer outputs: – The BRK input can either disable (inactive state) or force the PWM outputs to a predefined safe state. – BRK2 can only disable (inactive state) the PWM outputs. The BRK has a higher priority than BRK2 input, as described in Table 112.
Advanced-control timer (TIM1) RM0444 Figure 147. PWM output state following BRK assertion (OSSI=0) I/O state defined by the GPIO controller (HI-Z) Deadtime I/O state I/O state defined by the GPIO controller (HI-Z) Active Inactive Disabled MS34107V1 21.3.17 Bidirectional break inputs The TIM1 are featuring bidirectional break I/Os, as represented on Figure 148.
Advanced-control timer (TIM1) RM0444 21.3.18 Clearing the OCxREF signal on an external event The OCxREF signal of a given channel can be cleared when a high level is applied on the ocref_clr_int input (OCxCE enable bit in the corresponding TIMx_CCMRx register set to 1). OCxREF remains low until the next update event (UEV) occurs.
RM0444 Advanced-control timer (TIM1) 21.3.19 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. Thus one can program in advance the configuration for the next step and change the configuration of all the channels at the same time.
Advanced-control timer (TIM1) RM0444 21.3.20 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. Starting the counter can be controlled through the slave mode controller.
RM0444 Advanced-control timer (TIM1) 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 • The t is defined by the difference between the auto-reload value and the compare PULSE value (TIMx_ARR - TIMx_CCR1).
Advanced-control timer (TIM1) RM0444 Figure 152. Retriggerable one pulse mode TRGI Counter Output MS33106V1 21.3.22 Encoder interface mode To select Encoder Interface mode write SMS=‘001’ in the TIMx_SMCR register if the counter is counting on TI2 edges only, SMS=’010’ if it is counting on TI1 edges only and SMS=’011’...
RM0444 Advanced-control timer (TIM1) Table 114. Counting direction versus encoder signals Level on TI1FP1 signal TI2FP2 signal opposite signal (TI1FP1 Active edge for TI2, Rising Falling Rising Falling TI2FP2 for TI1) High Down No Count No Count Counting on TI1 only Down No Count No Count...
Advanced-control timer (TIM1) RM0444 Figure 154 gives an example of counter behavior when TI1FP1 polarity is inverted (same configuration as above except CC1P=’1’). Figure 154. Example of encoder interface mode with TI1FP1 polarity inverted. forward jitter backward jitter forward Counter down down MS33108V1...
RM0444 Advanced-control timer (TIM1) 21.3.24 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 an XOR gate, combining the three input pins TIMx_CH1, TIMx_CH2 and TIMx_CH3.
Page 576
Advanced-control timer (TIM1) RM0444 Example: one wants to change the PWM configuration of the advanced-control timer TIM1 after a programmed delay each time a change occurs on the Hall inputs connected to one of the TIMx timers. • Configure 3 timer inputs ORed to the TI1 input channel by writing the TI1S bit in the TIMx_CR2 register to ‘1’, •...
Advanced-control timer (TIM1) RM0444 21.3.26 Timer synchronization The TIMx timers are linked together internally for timer synchronization or chaining. Refer to Section 22.3.19: Timer synchronization for details. They can be synchronized 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.
RM0444 Advanced-control timer (TIM1) 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 do not need any filter, so we keep IC1F=0000).
Advanced-control timer (TIM1) RM0444 register. Write CC2P=1 and CC2NP=0 in TIMx_CCER register to validate the polarity (and detect low level only). • Configure the timer in trigger mode by writing SMS=110 in TIMx_SMCR register. Select TI2 as the input source by writing TS=00110 in TIMx_SMCR register. When a rising edge occurs on TI2, the counter starts counting on the internal clock and the TIF flag is set.
RM0444 Advanced-control timer (TIM1) In the following example, the upcounter is incremented at each rising edge of the ETR signal as soon as a rising edge of TI1 occurs: Configure the external trigger input circuit by programming the TIMx_SMCR register as follows: –...
Advanced-control timer (TIM1) RM0444 21.3.27 ADC synchronization The timer can generate an ADC triggering event with various internal signals, such as reset, enable or compare events. It is also possible to generate a pulse issued by internal edge detectors, such as: –...
RM0444 Advanced-control timer (TIM1) This is done in the following steps: Configure the corresponding DMA channel as follows: – DMA channel peripheral address is the DMAR register address – DMA channel memory address is the address of the buffer in the RAM containing the data to be transferred by DMA into CCRx registers.
Advanced-control timer (TIM1) RM0444 21.4 TIM1 registers Refer to for a list of abbreviations used in register descriptions. The peripheral registers can be accessed by half-words (16-bit) or words (32-bit). 21.4.1 TIM1 control register 1 (TIM1_CR1) Address offset: 0x00 Reset value: 0x0000 UIFRE Res.
RM0444 Advanced-control timer (TIM1) Bit 4 DIR: Direction 0: Counter used as upcounter 1: Counter used as downcounter Note: This bit is read only when the timer is configured in Center-aligned mode or Encoder mode. Bit 3 OPM: One pulse mode 0: Counter is not stopped at update event 1: Counter stops counting at the next update event (clearing the bit CEN) Bit 2 URS: Update request source...
Page 586
Advanced-control timer (TIM1) RM0444 Bits 31:24 Reserved, must be kept at reset value. Bits 23:20 MMS2[3:0]: Master mode selection 2 These bits allow the information to be sent to ADC for synchronization (TRGO2) to be selected. The combination is as follows: 0000: Reset - the UG bit from the TIMx_EGR register is used as trigger output (TRGO2).
Page 587
RM0444 Advanced-control timer (TIM1) Bit 12 OIS3: Output Idle state 3 (OC3 output) Refer to OIS1 bit Bit 11 OIS2N: Output Idle state 2 (OC2N output) Refer to OIS1N bit Bit 10 OIS2: Output Idle state 2 (OC2 output) Refer to OIS1 bit 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...
Advanced-control timer (TIM1) RM0444 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 589
RM0444 Advanced-control timer (TIM1) Bits 13:12 ETPS[1:0]: External trigger prescaler External trigger signal ETRP frequency must be at most 1/4 of f frequency. A CK_INT prescaler can be enabled to reduce ETRP frequency. It is useful when inputting fast external clocks.
Advanced-control timer (TIM1) RM0444 Bit 3 OCCS: OCREF clear selection This bit is used to select the OCREF clear source. 0: OCREF_CLR_INT is connected to COMP1 or COMP2 output depending on TIM1_OR1.OCREF_CLR 1: OCREF_CLR_INT is connected to ETRF Bits 16, 2, 1, 0 SMS[3:0]: 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 591
RM0444 Advanced-control timer (TIM1) Bit 15 Reserved, must be kept at reset value. Bit 14 TDE: Trigger DMA request enable 0: Trigger DMA request disabled 1: Trigger DMA request enabled Bit 13 COMDE: COM DMA request enable 0: COM DMA request disabled 1: COM DMA request enabled Bit 12 CC4DE: Capture/Compare 4 DMA request enable 0: CC4 DMA request disabled...
Page 593
RM0444 Advanced-control timer (TIM1) Bit 9 CC1OF: Capture/Compare 1 overcapture flag This flag is set by hardware only when the corresponding channel is configured in input capture mode. It is cleared by software by writing it to ‘0’. 0: No overcapture has been detected. 1: The counter value has been captured in TIMx_CCR1 register while CC1IF flag was already set Bit 8 B2IF: Break 2 interrupt flag...
Advanced-control timer (TIM1) RM0444 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: –...
RM0444 Advanced-control timer (TIM1) Bit 2 CC2G: Capture/Compare 2 generation Refer to CC1G description Bit 1 CC1G: Capture/Compare 1 generation This bit is set by software in order to generate an event, it is automatically cleared by hardware. 0: No action 1: A capture/compare event is generated on channel 1: If channel CC1 is configured as output: CC1IF flag is set, Corresponding interrupt or DMA request is sent if enabled.
Advanced-control timer (TIM1) RM0444 Bits 9:8 CC2S[1:0]: 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 01: CC2 channel is configured as input, IC2 is mapped on TI2 10: CC2 channel is configured as input, IC2 is mapped on TI1 11: CC2 channel is configured as input, IC2 is mapped on TRC.
Page 597
RM0444 Advanced-control timer (TIM1) corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (e.g. channel 1 in input capture mode and channel 2 in output compare mode). Output compare mode: Res.
Page 598
Advanced-control timer (TIM1) RM0444 Bits 16, 6:4 OC1M[3:0]: 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.
RM0444 Advanced-control timer (TIM1) Bit 3 OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register.
Advanced-control timer (TIM1) RM0444 Bits 31:16 Reserved, must be kept at reset value. Bits 15:12 IC4F[3:0]: Input capture 4 filter Refer to IC1F[3:0] description. Bits 11:10 IC4PSC[1:0]: Input capture 4 prescaler Refer to IC1PSC[1:0] description. Bits 9:8 CC4S[1:0]: Capture/Compare 4 selection This bit-field defines the direction of the channel (input/output) as well as the used input.
Page 601
RM0444 Advanced-control timer (TIM1) Bits 31:25 Reserved, must be kept at reset value. Bits 23:17 Reserved, must be kept at reset value. Bit 15 OC4CE: Output compare 4 clear enable Refer to OC1CE description. Bits 24, 14:12 OC4M[3:0]: Output compare 4 mode Refer to OC3M[3:0] description.
Advanced-control timer (TIM1) RM0444 Bit 0 CC1E: Capture/Compare 1 output enable 0: Capture mode disabled / OC1 is not active (see below) 1: Capture mode enabled / OC1 signal is output on the corresponding output pin When CC1 channel is configured as output, the OC1 level depends on MOE, OSSI, OSSR, OIS1, OIS1N and CC1NE bits, regardless of the CC1E bits state.
RM0444 Advanced-control timer (TIM1) 21.4.12 TIM1 counter (TIM1_CNT) Address offset: 0x24 Reset value: 0x0000 0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CNT[15:0] Bit 31 UIFCPY: UIF copy This bit is a read-only copy of the UIF bit of the TIMx_ISR register. If the UIFREMAP bit in the TIMxCR1 is reset, bit 31 is reserved and read at 0.
Advanced-control timer (TIM1) RM0444 21.4.15 TIM1 repetition counter register (TIM1_RCR) Address offset: 0x30 Reset value: 0x0000 REP[15:0] Bits 15:0 REP[15: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.
RM0444 Advanced-control timer (TIM1) 21.4.17 TIM1 capture/compare register 2 (TIM1_CCR2) Address offset: 0x38 Reset value: 0x0000 CCR2[15:0] 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).
Advanced-control timer (TIM1) RM0444 21.4.19 TIM1 capture/compare register 4 (TIM1_CCR4) Address offset: 0x40 Reset value: 0x0000 CCR4[15:0] 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). It is loaded permanently if the preload feature is not selected in the TIMx_CCMR2 register (bit OC4PE).
Page 609
RM0444 Advanced-control timer (TIM1) Bit 28 BKBID: Break Bidirectional 0: Break input BRK in input mode 1: Break input BRK in bidirectional mode In the bidirectional mode (BKBID bit set to 1), the break input is configured both in input mode and in open drain output mode.
Page 610
Advanced-control timer (TIM1) RM0444 Bits 23:20 BK2F[3:0]: Break 2 filter This bit-field defines the frequency used to sample BRK2 input and the length of the digital filter applied to BRK2. 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, BRK2 acts asynchronously 0001: f...
Page 611
RM0444 Advanced-control timer (TIM1) Bit 15 MOE: Main output enable This bit is cleared asynchronously by hardware as soon as one of the break inputs is active (BRK or BRK2). It is set by software or automatically depending on the AOE bit. It is acting only on the channels which are configured in output.
Advanced-control timer (TIM1) RM0444 Bit 10 OSSI: Off-state selection for Idle mode This bit is used when MOE=0 due to a break event or by a software write, on channels configured as outputs. See OC/OCN enable description for more details (Section 21.4.11: TIM1 capture/compare enable register (TIM1_CCER)).
RM0444 Advanced-control timer (TIM1) Bits 12:8 DBL[4:0]: DMA burst length This 5-bit vector defines the length of DMA transfers (the timer recognizes a burst transfer when a read or a write access is done to the TIMx_DMAR address), i.e. the number of transfers.
Advanced-control timer (TIM1) RM0444 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 DMA transfer, and ranges from 0 to DBL (DBL configured in TIMx_DCR).
Advanced-control timer (TIM1) RM0444 Bit 31 GC5C3: Group Channel 5 and Channel 3 Distortion on Channel 3 output: 0: No effect of OC5REF on OC3REFC 1: OC3REFC is the logical AND of OC3REFC and OC5REF This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload feature is selected in TIMxCCMR2).
Page 618
Advanced-control timer (TIM1) RM0444 Bit 10 BKCMP1P: BRK COMP1 input polarity This bit selects the COMP1 input sensitivity. It must be programmed together with the BKP polarity bit. 0: COMP1 input polarity is not inverted (active low if BKP=0, active high if BKP=1) 1: COMP1 input polarity is inverted (active high if BKP=0, active low if BKP=1) Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).
Advanced-control timer (TIM1) RM0444 Bit 3 BK2CMP3E: BRK2 COMP3 enable This bit enables the COMP3 for the timer’s BRK2 input. COMP3 output is ‘ORed’ with the other BRK2 sources. 0: COMP3 input disabled 1: COMP3 input enabled Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).
Page 621
RM0444 Advanced-control timer (TIM1) Bits 23:20 Reserved, must be kept at reset value. Bits 19:16 TI3SEL[3:0]: selects TI3[0] to TI3[15] input 0000: TIM1_CH3 input 0001: COMP3 output (available on STM32G0B1xx and STM32G0C1xx salestypes only) Others: Reserved Bits 15:12 Reserved, must be kept at reset value. Bits 11:8 TI2SEL[3:0]: selects TI2[0] to TI2[15] input 0000: TIM1_CH2 input 0001: COMP2 output...
Advanced-control timer (TIM1) RM0444 21.4.30 TIM1 register map TIM1 registers are mapped as 16-bit addressable registers as described in the table below: Table 117. TIM1 register map and reset values Register Offset name TIM1_CR1 [1:0] [1:0] 0x00 Reset value TIM1_CR2 MMS2[3:0] [2:0] 0x04...
Page 623
RM0444 Advanced-control timer (TIM1) Table 117. TIM1 register map and reset values (continued) Register Offset name TIM1_CNT CNT[15:0] 0x24 Reset value TIM1_PSC PSC[15:0] 0x28 Reset value TIM1_ARR ARR[15:0] 0x2C Reset value TIM1_RCR REP[15:0] 0x30 Reset value TIM1_CCR1 CCR1[15:0] 0x34 Reset value TIM1_CCR2 CCR2[15:0] 0x38...
Page 624
Advanced-control timer (TIM1) RM0444 Table 117. TIM1 register map and reset values (continued) Register Offset name TIM1_CCR5 CCR5[15:0] 0x58 Reset value TIM1_CCR6 CCR6[15:0] 0x5C Reset value TIM1_AF1 ETRSEL 0x60 [3:0] Reset value TIM1_AF2 0x64 Reset value TIM1_TISEL TI4SEL[3:0] TI3SEL[3:0] TI2SEL[3:0] TI1SEL[3:0] 0x68 Reset value...
RM0444 General-purpose timers (TIM2/TIM3/TIM4) General-purpose timers (TIM2/TIM3/TIM4) 22.1 TIM2/TIM3/TIM4 introduction The general-purpose timers consist of a 16-bit/32-bit auto-reload counter driven by a programmable prescaler. They may be used for a variety of purposes, including measuring the pulse lengths of input signals (input capture) or generating output waveforms (output compare and PWM).
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 22.3 TIM2/TIM3/TIM4 functional description 22.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, down or both up and down but also down or both up and down.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Figure 162. 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 163.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 22.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. An Update event can be generated at each counter overflow or by setting the UG bit in the TIMx_EGR register (by software or by using the slave mode controller).
RM0444 General-purpose timers (TIM2/TIM3/TIM4) The following figures show some examples of the counter behavior for different clock frequencies when TIMx_ARR=0x36. Figure 170. 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)
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Figure 174. 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...
General-purpose timers (TIM2/TIM3/TIM4) RM0444 DMA request is sent). This is to avoid generating both update and capture interrupt when clearing the counter on the capture event. When an update event occurs, all the registers are updated and the update flag (UIF bit in TIMx_SR register) is set (depending on the URS bit): •...
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Note: The capture prescaler is not used for triggering, so it does not need to be configured. Select rising edge polarity by writing CC2P=0 and CC2NP=0 and CC2NP=0 in the TIMx_CCER register. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR register.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Figure 185. Control circuit in external clock mode 2 f CK_INT CNT_EN ETRP ETRF Counter clock = CK_CNT =CK_PSC Counter register MSv33111V3 22.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).
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 22.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.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 22.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. •...
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 22.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. To force an output compare signal (ocxref/OCx) to its active level, one just needs to write 101 in the OCxM bits in the corresponding TIMx_CCMRx register.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 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 190.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) cleared by an external event through the ETR signal until the next PWM period), the OCREF signal is asserted only: • When the result of the comparison or • When the output compare mode (OCxM bits in TIMx_CCMRx register) switches from the “frozen”...
Page 650
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Downcounting configuration Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Downcounting mode on page 632. In PWM mode 1, the reference signal ocxref is low as long as TIMx_CNT>TIMx_CCRx else it becomes high. If the compare value in TIMx_CCRx is greater than the auto-reload value in TIMx_ARR, then ocxref is held at 100%.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 22.3.10 Asymmetric PWM mode Asymmetric mode allows two center-aligned PWM signals to be generated with a programmable phase shift. While the frequency is determined by the value of the TIMx_ARR register, the duty cycle and the phase-shift are determined by a pair of TIMx_CCRx registers.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) When a given channel is used as combined PWM channel, its secondary channel must be configured in the opposite PWM mode (for instance, one in Combined PWM mode 1 and the other in Combined PWM mode 2). Note: The OCxM[3:0] bit field is split into two parts for compatibility reasons, the most significant bit is not contiguous with the 3 least significant ones.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 The OCxREF signal for a given channel can be reset by applying a high level on the ETRF input (OCxCE enable bit set to 1 in the corresponding TIMx_CCMRx register). OCxREF remains low until the next update event (UEV) occurs. This function can be used only in the output compare and PWM modes.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 22.3.13 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. Starting the counter can be controlled through the slave mode controller.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 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 • The t is defined by the difference between the auto-reload value and the compare PULSE value (TIMx_ARR - TIMx_CCR1).
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Figure 197. Retriggerable one-pulse mode. TRGI Counter Output MS33106V1 22.3.15 Encoder interface mode To select Encoder Interface mode write SMS=‘001 in the TIMx_SMCR register if the counter is counting on TI2 edges only, SMS=010 if it is counting on TI1 edges only and SMS=011 if it is counting on both TI1 and TI2 edges.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Table 118. Counting direction versus encoder signals Level on opposite TI1FP1 signal TI2FP2 signal Active edge signal (TI1FP1 for Rising Falling Rising Falling TI2, TI2FP2 for TI1) High Down No Count No Count Counting on TI1 only Down No Count No Count...
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Figure 199. Example of encoder interface mode with TI1FP1 polarity inverted forward jitter backward jitter forward Counter down down MS33108V1 The timer, when configured in Encoder Interface mode provides information on the sensor’s current position. Dynamic information can be obtained (speed, acceleration, deceleration) by measuring the period between two encoder events using a second timer configured in capture mode.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 22.3.18 Timers and external trigger synchronization The TIMx Timers 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.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Configure the channel 1 to detect low levels on TI1. Configure the input filter duration (in this example, we do not need any filter, so we keep IC1F=0000). The capture prescaler is not used for triggering, so it does not need to be configured. The CC1S bits select the input capture source only, CC1S=01 in TIMx_CCMR1 register.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 CC2P=1 and CC2NP=0 in TIMx_CCER register to validate the polarity (and detect low level only). Configure the timer in trigger mode by writing SMS=110 in TIMx_SMCR register. Select TI2 as the input source by writing TS=00110 in TIMx_SMCR register. When a rising edge occurs on TI2, the counter starts counting on the internal clock and the TIF flag is set.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) A rising edge on TI1 enables the counter and sets the TIF flag. The counter then counts on ETR rising edges. The delay between the rising edge of the ETR signal and the actual reset of the counter is due to the resynchronization circuit on ETRP input.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Figure 205. Master/slave connection example with 1 channel only timers TIM_mstr TIM_slv Clock Prescaler Counter Output Slave tim_oc1 tim_itr CK_PSC mode control control Compare 1 Prescaler Counter Input TIM_CH1 trigger selection MSv65225V1 Note: The timers with one channel only (see Figure 205) do not feature a master mode.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Configure TIM3 master mode to send its Output Compare 1 Reference (OC1REF) signal as trigger output (MMS=100 in the TIM3_CR2 register). Configure the TIM3 OC1REF waveform (TIM3_CCMR1 register). Configure TIM2 to get the input trigger from TIM3 (TS=00010 in the TIM2_SMCR register).
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Figure 207. Gating TIM2 with Enable of TIM3 CK_INT TIM3-CEN=CNT_EN TIM3-CNT_INIT TIM3-CNT TIM2-CNT TIM2-CNT_INIT TIM2-write CNT TIM2-TIF Write TIF = 0 MS33120V1 Using one timer to start another timer In this example, we set the enable of Timer 2 with the update event of Timer 3. Refer to Figure 204 for connections.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) As in the previous example, both counters can be initialized before starting counting. Figure 209 shows the behavior with the same configuration as in Figure 208 but in trigger mode instead of gated mode (SMS=110 in the TIM2_SMCR register). Figure 209.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Configure the corresponding DMA channel as follows: – DMA channel peripheral address is the DMAR register address – DMA channel memory address is the address of the buffer in the RAM containing the data to be transferred by DMA into CCRx registers. –...
General-purpose timers (TIM2/TIM3/TIM4) RM0444 22.4 TIM2/TIM3/TIM4 registers Refer to Section 1.2 for a list of abbreviations used in register descriptions. The peripheral registers can be accessed by half-words (16-bit) or words (32-bit). 22.4.1 TIMx control register 1 (TIMx_CR1)(x = 2 to 4) Address offset: 0x00 Reset value: 0x0000 UIFRE...
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Bit 3 OPM: One-pulse mode 0: Counter is not stopped at update event 1: Counter stops counting at the next update event (clearing the bit CEN) 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.
Page 672
General-purpose timers (TIM2/TIM3/TIM4) RM0444 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) Section 21.3.25: Interfacing with Hall sensors on page 575 See also Bits 6:4 MMS[2:0]: Master mode selection...
Page 674
General-purpose timers (TIM2/TIM3/TIM4) RM0444 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 675
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Bits 21, 20, 6, 5, 4 TS[4:0]: Trigger selection This bit-field selects the trigger input to be used to synchronize the counter. 00000: Internal Trigger 0 (ITR0) 00001: Internal Trigger 1 (ITR1) 00010: Internal Trigger 2 (ITR2) 00011: Internal Trigger 3 (ITR3) 00100: TI1 Edge Detector (TI1F_ED) 00101: Filtered Timer Input 1 (TI1FP1)
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Bits 16, 2, 1, 0 SMS[3:0]: 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 678
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Bits 15:13 Reserved, must be kept at reset value. Bit 12 CC4OF: Capture/Compare 4 overcapture flag refer to CC1OF description Bit 11 CC3OF: Capture/Compare 3 overcapture flag refer to CC1OF description 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...
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Bit 2 CC2IF: Capture/Compare 2 interrupt flag Refer to CC1IF description Bit 1 CC1IF: Capture/compare 1 interrupt flag This flag is set by hardware. It is cleared by software (input capture or output compare mode) or by reading the TIMx_CCR1 register (input capture mode only). 0: No compare match / No input capture occurred 1: A compare match or an input capture occurred If channel CC1 is configured as output: this flag is set when the content of the counter...
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Bit 2 CC2G: Capture/compare 2 generation Refer to CC1G description Bit 1 CC1G: Capture/compare 1 generation This bit is set by software in order to generate an event, it is automatically cleared by hardware. 0: No action 1: A capture/compare event is generated on channel 1: If channel CC1 is configured as output: CC1IF flag is set, Corresponding interrupt or DMA request is sent if enabled.
Page 681
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Bits 9:8 CC2S[1:0]: 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. 01: CC2 channel is configured as input, IC2 is mapped on TI2. 10: CC2 channel is configured as input, IC2 is mapped on TI1.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 22.4.8 TIMx capture/compare mode register 1 [alternate] (TIMx_CCMR1) (x = 2 to 4) Address offset: 0x18 Reset value: 0x0000 0000 The same register can be used for output compare mode (this section) or for input capture mode (previous section).
Page 683
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Bits 16, 6:4 OC1M[3:0]: 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.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Bit 3 OC1PE: Output compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Bits 9:8 CC4S[1:0]: 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 11: CC4 channel is configured as input, IC4 is mapped on TRC.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Bits 9:8 CC4S[1:0]: 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 11: CC4 channel is configured as input, IC4 is mapped on TRC.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 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. Refer to CC1E description Bit 3 CC1NP: Capture/Compare 1 output Polarity.
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Address offset: 0x24 Reset value: 0x0000 0000 CNT[31:16] CNT[15:0] Bits 31:16 CNT[31:16]: Most significant part counter value (TIM2) Bits 15:0 CNT[15:0]: Least significant part of counter value 22.4.13 TIMx counter [alternate] (TIMx_CNT)(x = 2 to 4) Bit 31 of this register has two possible definitions depending on the value of UIFREMAP in TIMx_CR1 register: •...
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 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”).
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Bits 31:16 CCR1[31:16]: High Capture/Compare 1 value (TIM2) Bits 15:0 CCR1[15:0]: Low Capture/Compare 1 value If channel CC1 is configured as output: CCR1 is the value to be loaded in the actual capture/compare 1 register (preload value). It is loaded permanently if the preload feature is not selected in the TIMx_CCMR1 register (bit OC1PE).
RM0444 General-purpose timers (TIM2/TIM3/TIM4) CCR3[31:16] CCR3[15:0] Bits 31:16 CCR3[31:16]: High Capture/Compare 3 value (TIM2) Bits 15:0 CCR3[15:0]: Low Capture/Compare value If channel CC3 is configured as output: CCR3 is the value to be loaded in the actual capture/compare 3 register (preload value). It is loaded permanently if the preload feature is not selected in the TIMx_CCMR2 register (bit OC3PE).
General-purpose timers (TIM2/TIM3/TIM4) RM0444 22.4.20 TIMx DMA control register (TIMx_DCR)(x = 2 to 4) Address offset: 0x48 Reset value: 0x0000 Res. Res. Res. DBL[4:0] Res. Res. Res. DBA[4:0] Bits 15:13 Reserved, must be kept at reset value. Bits 12:8 DBL[4:0]: DMA burst length This 5-bit vector defines the number of DMA transfers (the timer recognizes a burst transfer when a read or a write access is done to the TIMx_DMAR address).
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Bits 31:20 Reserved, must be kept at reset value. Bits 19:16 TI3SEL[3:0]: TI3[0] to TI3[15] input selection These bits select the TI3[0] to TI3[15] input source. 0000: TIM3_CH3 input 0001: COMP3 output Others: Reserved Note: Available on STM32G0B1xx and STM32G0C1xx salestypes only, otherwise reserved. Bits 15:12 Reserved, must be kept at reset value.
Page 698
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Bits 11:8 TI2SEL[3:0]: TI2[0] to TI2[15] input selection These bits select the TI2[0] to TI2[15] input source. 0000: TIM4_CH2 input 0001: COMP2 output Others: Reserved Bits 7:4 Reserved, must be kept at reset value. Bits 3:0 TI1SEL[3:0]: TI1[0] to TI1[15] input selection These bits select the TI1[0] to TI1[15] input source.
RM0444 General-purpose timers (TIM2/TIM3/TIM4) 22.4.31 TIMx register map TIMx registers are mapped as described in the table below: Table 121. TIM2/TIM3/TIM4 register map and reset values Register Offset name TIMx_CR1 [1:0] [1:0] 0x00 Reset value TIMx_CR2 MMS[2:0] 0x04 Reset value ETPS TIMx_SMCR ETF[3:0]...
Page 700
General-purpose timers (TIM2/TIM3/TIM4) RM0444 Table 121. TIM2/TIM3/TIM4 register map and reset values (continued) Register Offset name CNT[30:16] TIMx_CNT CNT[15:0] (TIM2 only, reserved on the other timers) 0x24 Reset value TIMx_PSC PSC[15:0] 0x28 Reset value ARR[31:16] TIMx_ARR ARR[15:0] (TIM2 only, reserved on the other timers) 0x2C Reset value 0x30...
Page 701
RM0444 General-purpose timers (TIM2/TIM3/TIM4) Table 121. TIM2/TIM3/TIM4 register map and reset values (continued) Register Offset name TIM3_OR1 0x50 Reset value TIM4_OR1 0x50 Reset value ETRSEL TIM2_AF1 [3:0] 0x60 Reset value ETRSEL TIM3_AF1 [3:0] 0x60 Reset value ETRSEL TIM4_AF1 [3:0] 0x60 Reset value TIM2_TISEL TI3SEL[3:0]...
Basic timers (TIM6/TIM7) RM0444 Basic timers (TIM6/TIM7) 23.1 TIM6/TIM7 introduction The basic timers TIM6 and TIM7 consist of a 16-bit auto-reload counter driven by a programmable prescaler. They may be used as generic timers for time base generation but they are also specifically used to drive the digital-to-analog converter (DAC).
RM0444 Basic timers (TIM6/TIM7) 23.3 TIM6/TIM7 functional description 23.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.
Basic timers (TIM6/TIM7) RM0444 Figure 212. 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 213.
RM0444 Basic timers (TIM6/TIM7) 23.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).
RM0444 Basic timers (TIM6/TIM7) Figure 220. 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 23.3.5 Debug mode ® When the microcontroller enters the debug mode (Cortex -M0+ core - halted), the TIMx counter either continues to work normally or stops, depending on the DBG_TIMx_STOP...
Page 710
Basic timers (TIM6/TIM7) RM0444 Bit 7 ARPE: Auto-reload preload enable 0: TIMx_ARR register is not buffered. 1: TIMx_ARR register is buffered. Bits 6:4 Reserved, must be kept at reset value. Bit 3 OPM: One-pulse mode 0: Counter is not stopped at update event 1: Counter stops counting at the next update event (clearing the CEN bit).
RM0444 Basic timers (TIM6/TIM7) 23.4.2 TIMx control register 2 (TIMx_CR2)(x = 6 to 7) Address offset: 0x04 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. MMS[2:0] Res. Res. Res. Res. 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).
Basic timers (TIM6/TIM7) RM0444 23.4.4 TIMx status register (TIMx_SR)(x = 6 to 7) Address offset: 0x10 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 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.
RM0444 Basic timers (TIM6/TIM7) Bit 31 UIFCPY: UIF Copy This bit is a read-only copy of the UIF bit of the TIMx_ISR register. If the UIFREMAP bit in TIMx_CR1 is reset, bit 31 is reserved and read as 0. Bits 30:16 Reserved, must be kept at reset value. Bits 15:0 CNT[15:0]: Counter value 23.4.7 TIMx prescaler (TIMx_PSC)(x = 6 to 7)
Basic timers (TIM6/TIM7) RM0444 23.4.9 TIMx register map TIMx registers are mapped as 16-bit addressable registers as described in the table below: Table 122. TIMx register map and reset values Register Offset name TIMx_CR1 0x00 Reset value TIMx_CR2 [2:0] 0x04 Reset value 0x08 Reserved...
RM0444 General-purpose timers (TIM14) General-purpose timers (TIM14) 24.1 TIM14 introduction The TIM14 general-purpose timer consists of a 16-bit auto-reload counter driven by a programmable prescaler. It may be used for a variety of purposes, including measuring the pulse lengths of input signals (input capture) or generating output waveforms (output compare, PWM).
RM0444 General-purpose timers (TIM14) 24.3 TIM14 functional description 24.3.1 Time-base unit The main block of the timer is a 16-bit up-counter 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.
General-purpose timers (TIM14) RM0444 Figure 222. 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 223.
RM0444 General-purpose timers (TIM14) 24.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) also generates an update event. The UEV event can be disabled by software by setting the UDIS bit in the TIMx_CR1 register.
RM0444 General-purpose timers (TIM14) Figure 230. Control circuit in normal mode, internal clock divided by 1 Internal clock CEN=CNT_EN CNT_INIT r clock = CK_CNT = CK_PSC Counter register 33 34 35 36 03 04 05 MS31085V2 24.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).
RM0444 General-purpose timers (TIM14) cleared by software by writing it to ‘0’ or by reading the captured data stored in the TIMx_CCRx register. CCxOF is cleared when it is written with 0. The following example shows how to capture the counter value in TIMx_CCR1 when TI1 input rises.
General-purpose timers (TIM14) RM0444 The OCxREF signal can be forced low by writing the OCxM bits to ‘0100’ in the TIMx_CCMRx register. Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still performed and allows the flag to be set. Interrupt requests can be sent accordingly. This is described in the output compare mode section below.
RM0444 General-purpose timers (TIM14) Figure 234. Output compare mode, toggle on OC1. Write B201h in the CC1R register B200 B201 TIM1_CNT 0039 003A 003B B201 003A TIM1_CCR1 OC1REF= OC1 Match detected on CCR1 Interrupt generated if enabled MS31092V1 24.3.8 PWM mode Pulse Width Modulation mode allows to generate a signal with a frequency determined by the value of the TIMx_ARR register and a duty cycle determined by the value of the TIMx_CCRx register.
General-purpose timers (TIM14) RM0444 Figure 235. Edge-aligned PWM waveforms (ARR=8) Counter register OCXREF CCRx=4 CCxIF OCXREF CCRx=8 CCxIF ‘1’ OCXREF CCRx>8 CCxIF ‘0’ OCXREF CCRx=0 CCxIF MS31093V1 24.3.9 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.
RM0444 General-purpose timers (TIM14) 24.3.11 Using timer output as trigger for other timers (TIM14) The timers with one channel only do not feature a master mode. However, the OC1 output signal can be used to trigger some other timers (including timers described in other sections of this document).
General-purpose timers (TIM14) RM0444 24.4 TIM14 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). 24.4.1 TIM14 control register 1 (TIM14_CR1) Address offset: 0x00 Reset value: 0x0000 UIFRE...
RM0444 General-purpose timers (TIM14) Bit 2 URS: Update request source This bit is set and cleared by software to select the update interrupt (UEV) sources. 0: Any of the following events generate an UEV if enabled: – Counter overflow – Setting the UG bit 1: Only counter overflow generates an UEV if enabled.
General-purpose timers (TIM14) RM0444 Bits 15:10 Reserved, must be kept at reset value. Bit 9 CC1OF: Capture/Compare 1 overcapture flag This flag is set by hardware only when the corresponding channel is configured in input capture mode. It is cleared by software by writing it to ‘0’. 0: No overcapture has been detected.
RM0444 General-purpose timers (TIM14) Bits 15:2 Reserved, must be kept at reset value. Bit 1 CC1G: Capture/compare 1 generation This bit is set by software in order to generate an event, it is automatically cleared by hardware. 0: No action 1: A capture/compare event is generated on channel 1: If channel CC1 is configured as output: CC1IF flag is set, Corresponding interrupt or is sent if enabled.
Page 734
General-purpose timers (TIM14) RM0444 Bits 7:4 IC1F[3:0]: 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. 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 735
RM0444 General-purpose timers (TIM14) corresponding CCxS bits. All the other bits of this register have a different function in input and in output mode. Output compare mode: OC1M Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
General-purpose timers (TIM14) RM0444 Bit 3 OC1PE: Output compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register.
RM0444 General-purpose timers (TIM14) Bit 2 Reserved, must be kept at reset value. Bit 1 CC1P: Capture/Compare 1 output Polarity. 0: OC1 active high (output mode) / Edge sensitivity selection (input mode, see below) 1: OC1 active low (output mode) / Edge sensitivity selection (input mode, see below) When CC1 channel is configured as input, both CC1NP/CC1P bits select the active polarity of TI1FP1 and TI2FP1 for trigger or capture operations.
General-purpose timers (TIM14) RM0444 24.4.9 TIM14 prescaler (TIM14_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”).
RM0444 General-purpose timers (TIM14) 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). It is loaded permanently if the preload feature is not selected in the TIMx_CCMR1 register (bit OC1PE).
Page 740
General-purpose timers (TIM14) RM0444 Table 124. TIM14 register map and reset values (continued) Register Offset name TIMx_SR 0x10 Reset value TIMx_EGR 0x14 Reset value TIMx_CCMR1 OC1M CC1S Output compare [2:0] [1:0] mode Reset value 0x18 TIMx_CCMR1 CC1S IC1F[3:0] Input capture [1:0] [1:0] mode...
RM0444 General-purpose timers (TIM15/TIM16/TIM17) General-purpose timers (TIM15/TIM16/TIM17) 25.1 TIM15/TIM16/TIM17 introduction The TIM15/TIM16/TIM17 timers consist of a 16-bit auto-reload counter driven by a programmable prescaler. They may be used for a variety of purposes, including measuring the pulse lengths of input signals (input capture) or generating output waveforms (output compare, PWM, complementary PWM with dead-time insertion).
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.3 TIM16/TIM17 main features The TIM16/TIM17 timers include the following features: • 16-bit auto-reload upcounter • 16-bit programmable prescaler used to divide (also “on the fly”) the counter clock frequency by any factor between 1 and 65535 •...
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.4 TIM15/TIM16/TIM17 functional description 25.4.1 Time-base unit The main block of the programmable advanced-control 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.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Figure 238. 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 239.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.4.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 (TIMx_RCR).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.4.3 Repetition counter Section 25.4.1: Time-base unit describes how the update event (UEV) is generated with respect to the counter overflows. It is actually generated only when the repetition counter has reached zero. This can be useful when generating PWM signals. This means that data are transferred from the preload registers to the shadow registers (TIMx_ARR auto-reload register, TIMx_PSC prescaler register, but also TIMx_CCRx capture/compare registers in compare mode) every N counter overflows, where N is the...
RM0444 General-purpose timers (TIM15/TIM16/TIM17) only by software (except UG which remains cleared automatically). As soon as the CEN bit is written to 1, the prescaler is clocked by the internal clock CK_INT. Figure 247 shows the behavior of the control circuit and the upcounter in normal mode, without prescaler.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Select the proper TI2[x] source (internal or external) with the TI2SEL[3:0] bits in the TIMx_TISEL register. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in the TIMx_CCMR1 register. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1 register (if no filter is needed, keep IC2F=0000).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) already high, then the over-capture flag CCxOF (TIMx_SR register) is set. CCxIF can be cleared by software by writing it to ‘0’ or by reading the captured data stored in the TIMx_CCRx register. CCxOF is cleared when it is written with 0. The following example shows how to capture the counter value in TIMx_CCR1 when TI1 input rises.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 For example, one can measure the period (in TIMx_CCR1 register) and the duty cycle (in TIMx_CCR2 register) of the PWM applied on TI1 using the following procedure (depending on CK_INT frequency and prescaler value): Select the proper TI1[x] source (internal or external) with the TI1SEL[3:0] bits in the TIMx_TISEL register.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still performed and allows the flag to be set. Interrupt and DMA requests can be sent accordingly. This is described in the output compare mode section below. 25.4.9 Output compare mode This function is used to control an output waveform or indicating when a period of time has...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Figure 255. Output compare mode, toggle on OC1 Write B201h in the CC1R register B200 B201 TIM1_CNT 0039 003A 003B B201 003A TIM1_CCR1 OC1REF= OC1 Match detected on CCR1 Interrupt generated if enabled MS31092V1 25.4.10 PWM mode Pulse Width Modulation mode allows a signal to be generated with a frequency determined by the value of the TIMx_ARR register and a duty cycle determined by the value of the TIMx_CCRx register.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) ‘1’. If the compare value is 0 then OCxRef is held at ‘0’. Figure 256 shows some edge- aligned PWM waveforms in an example where TIMx_ARR=8. Figure 256. Edge-aligned PWM waveforms (ARR=8) Counter register OCXREF CCRx=4 CCxIF OCXREF CCRx=8...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Figure 257. Combined PWM mode on channel 1 and 2 OC2’ OC1’ OC1REF OC2REF OC1REF’ OC2REF’ OC1REFC OC1REFC’ OC1REFC = OC1REF AND OC2REF OC1REFC’ = OC1REF’ OR OC2REF’ MS31094V1 25.4.12 Complementary outputs and dead-time insertion The TIM15/TIM16/TIM17 general-purpose timers can output one complementary signal and manage the switching-off and switching-on of the outputs.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) reference waveform OCxREF, it generates 2 outputs OCx and OCxN. If OCx and OCxN are active high: • The OCx output signal is the same as the reference signal except for the rising edge, which is delayed relative to the reference rising edge. •...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Figure 260. Dead-time waveforms with delay greater than the positive pulse. OCxREF OCxN delay MS31097V1 The dead-time delay is the same for each of the channels and is programmable with the DTG bits in the TIMx_BDTR register. Refer to Section 25.6.14: TIMx break and dead-time register (TIMx_BDTR)(x = 16 to 17) on page 820 for delay calculation.
Page 765
RM0444 General-purpose timers (TIM15/TIM16/TIM17) The output enable signal and output levels during break are depending on several control bits: • the MOE bit in TIMx_BDTR register allows to enable /disable the outputs by software and is reset in case of break or break2 event. •...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Figure 261. Break circuitry overview Lockup LOCK Core Lockup PVD LOCK System break requests SBIF flag Parity LOCK RAM parity Error ECC LOCK ECC Error BKINP BKIN inputs BKINE Software break from AF requests: BG controller BIF flag BKCMP1P BKCMP1E...
Page 767
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 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 (taken over by the AFIO controller which forces a Hi-Z state) else the enable outputs remain or become high as soon as one of the CCxE or CCxNE bits is high.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.4.14 Bidirectional break inputs The TIM15/TIM16/TIM17 are featuring bidirectional break I/Os, as represented on Figure 263. They allow the following: • A board-level global break signal available for signaling faults to external MCUs or gate drivers, with a unique pin being both an input and an output status pin •...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 The following procedure must be followed to re-arm the protection after a break event: • The BKDSRM bit must be set to release the output control • The software must wait until the system break condition disappears (if any) and clear the SBIF status flag (or clear it systematically before re-arming) •...
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.4.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. Starting the counter can be controlled through the slave mode controller.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Figure 264. Example of one pulse mode OC1REF TIM1_ARR TIM1_CCR1 DELAY PULSE MS31099V1 For example one may want to generate a positive pulse on OC1 with a length of t PULSE after a delay of t as soon as a positive edge is detected on the TI2 input pin.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Particular case: OCx fast enable In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the counter. Then the comparison between the counter and the compare value makes the output toggle. But several clock cycles are needed for these operations and it limits the minimum delay t min we can get.
Page 774
General-purpose timers (TIM15/TIM16/TIM17) RM0444 the counter value and a potential roll-over condition signaled by the UIFCPY flag, to be atomically read. In particular cases, it can ease the calculations by avoiding race conditions caused for instance by a processing shared between a background task (counter reading) and an interrupt (Update Interrupt).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.4.18 Timer input XOR function (TIM15 only) 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 two input pins TIMx_CH1 and TIMx_CH2. The XOR output can be used with all the timer input functions such as trigger or input capture.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.4.19 External trigger synchronization (TIM15 only) The TIM timers are linked together internally for timer synchronization or chaining. The TIM15 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.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 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 do not need any filter, so we keep IC1F=0000).
General-purpose timers (TIM15/TIM16/TIM17) RM0444 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. Configure the input filter duration (in this example, we do not need any filter, so we keep IC2F=0000).
Page 779
RM0444 General-purpose timers (TIM15/TIM16/TIM17) The DBL[4:0] bits in the TIMx_DCR register set the DMA burst length. The timer recognizes a burst transfer when a read or a write access is done to the TIMx_DMAR address), i.e. the number of transfers (either in half-words or in bytes). The DBA[4:0] bits in the TIMx_DCR registers define the DMA base address for DMA transfers (when read/write access are done through the TIMx_DMAR address).
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.4.22 Timer synchronization (TIM15) The TIMx timers are linked together internally for timer synchronization or chaining. Refer to Section 22.3.19: Timer synchronization for details. Note: The clock of the slave peripherals (timer, ADC, ...) receiving the TRGO or the TRGO2 signals must be enabled prior to receive events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.5 TIM15 registers Refer to Section 1.2 for a list of abbreviations used in register descriptions. The peripheral registers can be accessed by half-words (16-bit) or words (32-bit). 25.5.1 TIM15 control register 1 (TIM15_CR1) Address offset: 0x00 Reset value: 0x0000 UIFRE Res.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 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 if enabled. These events can be: –...
Page 783
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bit 7 TI1S: TI1 selection 0: The TIMx_CH1 pin is connected to TI1 input 1: The TIMx_CH1, CH2 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 synchronization (TRGO).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bits 16, 2, 1, 0 SMS[3:0]: 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 787
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 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 capture mode.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bit 2 CC2IF: Capture/Compare 2 interrupt flag refer to CC1IF description Bit 1 CC1IF: Capture/Compare 1 interrupt flag This flag is set by hardware. It is cleared by software (input capture or output compare mode) or by reading the TIMx_CCR1 register (input capture mode only). 0: No compare match / No input capture occurred 1: A compare match or an input capture occurred If channel CC1 is configured as output: this flag is set when the content of the counter...
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 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 the CCPC bit is set, it is possible to update the CCxE, CCxNE and OCxM bits Note: This bit acts only on channels that have a complementary output.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bits 9:8 CC2S[1:0]: 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 01: CC2 channel is configured as input, IC2 is mapped on TI2 10: CC2 channel is configured as input, IC2 is mapped on TI1 11: CC2 channel is configured as input, IC2 is mapped on TRC.
Page 791
RM0444 General-purpose timers (TIM15/TIM16/TIM17) corresponding CCxS bits. All the other bits of this register have a different function in input and in output mode. Output compare mode: OC2M OC1M Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
Page 792
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bits 16, 6:4 OC1M[3:0]: 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.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bit 3 OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register.
Page 794
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bit 3 CC1NP: Capture/Compare 1 complementary output polarity CC1 channel configured as output: 0: OC1N active high 1: OC1N active low CC1 channel configured as input: This bit is used in conjunction with CC1P to define the polarity of TI1FP1 and TI2FP1. Refer to CC1P description.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Table 127. Output control bits for complementary OCx and OCxN channels with break feature (TIM15) Control bits Output states MOE bit OSSI bit OSSR bit CCxE bit CCxNE bit OCx output state OCxN output state Output Disabled (not driven by the timer: Hi-Z) OCx=0 OCxN=0, OCxN_EN=0 Output Disabled (not driven...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.5.10 TIM15 counter (TIM15_CNT) Address offset: 0x24 Reset value: 0x0000 0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CNT[15:0] Bit 31 UIFCPY: UIF Copy This bit is a read-only copy of the UIF bit in the TIMx_ISR register. Bits 30:16 Reserved, must be kept at reset value.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.5.13 TIM15 repetition counter register (TIM15_RCR) Address offset: 0x30 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. REP[7:0] 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.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.5.15 TIM15 capture/compare register 2 (TIM15_CCR2) Address offset: 0x38 Reset value: 0x0000 CCR2[15:0] 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). It is loaded permanently if the preload feature is not selected in the TIMx_CCMR2 register (bit OC2PE).
Page 799
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bit 27 Reserved, must be kept at reset value. Bit 26 BKDSRM: Break Disarm 0: Break input BRK is armed 1: Break input BRK is disarmed This bit is cleared by hardware when no break source is active. The BKDSRM bit must be set by software to release the bidirectional output control (open- drain output in Hi-Z state) and then be polled it until it is reset by hardware, indicating that the fault condition has disappeared.
Page 800
General-purpose timers (TIM15/TIM16/TIM17) RM0444 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).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 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]) x t with t = 2 x t DTG[7:5] = 110 =>...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 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 DMA transfer, and ranges from 0 to DBL (DBL configured in TIMx_DCR).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bits 8:4 Reserved, must be kept at reset value. Bit 3 BKCMP3E: BRK COMP3 enable This bit enables the COMP3 for the timer’s BRK input. COMP3 output is ‘ORed’ with the other BRK sources. 0: COMP3 input disabled 1: COMP3 input enabled Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.6 TIM16/TIM17 registers Refer to Section 1.2 for a list of abbreviations used in register descriptions. The peripheral registers can be accessed by half-words (16-bit) or words (32-bit). 25.6.1 TIMx control register 1 (TIMx_CR1)(x = 16 to 17) Address offset: 0x00 Reset value: 0x0000 UIFRE...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bit 1 UDIS: Update disable This bit is set and cleared by software to enable/disable UEV event generation. 0: UEV enabled. The Update (UEV) event is generated by one of the following events: – Counter overflow/underflow –...
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bit 0 CCPC: Capture/compare preloaded control 0: CCxE, CCxNE and OCxM bits are not preloaded 1: CCxE, CCxNE and OCxM bits are preloaded, after having been written, they are updated only when COM bit is set. Note: This bit acts only on channels that have a complementary output.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.6.4 TIMx status register (TIMx_SR)(x = 16 to 17) Address offset: 0x10 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. CC1OF Res. Res. COMIF Res. Res. Res. CC1IF rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 Bits 15:10 Reserved, must be kept at reset value. Bit 9 CC1OF: Capture/Compare 1 overcapture flag This flag is set by hardware only when the corresponding channel is configured in input capture mode.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 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: –...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.6.6 TIMx capture/compare mode register 1 [alternate] (TIMx_CCMR1) (x = 16 to 17) Address offset: 0x18 Reset value: 0x0000 0000 The same register can be used for input capture mode (this section) or for output compare mode (next section).
Page 813
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bits 7:4 IC1F[3:0]: 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. 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 814
General-purpose timers (TIM15/TIM16/TIM17) RM0444 OC1M Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. OC1M[2:0] OC1PE OC1FE CC1S[1:0] Bits 31:17 Reserved, must be kept at reset value. Bits 15:7 Reserved, must be kept at reset value.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bit 2 OC1FE: Output Compare 1 fast enable This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIMx_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
Page 816
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bit 2 CC1NE: Capture/Compare 1 complementary output enable 0: Off - OC1N is not active. OC1N level is then function of MOE, OSSI, OSSR, OIS1, OIS1N and CC1E bits. 1: On - OC1N signal is output on the corresponding output pin depending on MOE, OSSI, OSSR, OIS1, OIS1N and CC1E bits.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Table 129. Output control bits for complementary OCx and OCxN channels with break feature (TIM16/17) Control bits Output states MOE bit OSSI bit OSSR bit CCxE bit CCxNE bit OCx output state OCxN output state Output Disabled (not driven by the timer: Hi-Z) OCx=0 OCxN=0, OCxN_EN=0 Output Disabled (not driven...
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bit 31 UIFCPY: UIF Copy This bit is a read-only copy of the UIF bit of the TIMx_ISR register. If the UIFREMAP bit in TIMx_CR1 is reset, bit 31 is reserved and read as 0. Bits 30:16 Reserved, must be kept at reset value. Bits 15:0 CNT[15:0]: Counter value 25.6.10 TIMx prescaler (TIMx_PSC)(x = 16 to 17)
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.6.12 TIMx repetition counter register (TIMx_RCR)(x = 16 to 17) Address offset: 0x30 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. REP[7:0] 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.
General-purpose timers (TIM15/TIM16/TIM17) RM0444 25.6.14 TIMx break and dead-time register (TIMx_BDTR)(x = 16 to 17) Address offset: 0x44 Reset value: 0x0000 0000 Res. Res. Res. BKBID Res. Res. Res. Res. Res. Res. Res. BKF[3:0] DSRM OSSR OSSI LOCK[1:0] DTG[7:0] Note: As the BKBID, BKDSRM, BKF[3:0], AOE, BKP, BKE, OSSI, OSSR and DTG[7:0] bits may be write-locked depending on the LOCK configuration, it may be necessary to configure all of them during the first write access to the TIMx_BDTR register.
Page 821
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bits 25:20 Reserved, must be kept at reset value. Bits 19:16 BKF[3:0]: Break filter This bit-field defines the frequency used to sample BRK input and the length of the digital filter applied to BRK. The digital filter is made of an event counter in which N events are needed to validate a transition on the output: 0000: No filter, BRK acts asynchronously 0001: f...
Page 822
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bit 11 OSSR: Off-state selection for Run mode This bit is used when MOE=1 on channels that have a complementary output which are configured as outputs. OSSR is not implemented if no complementary output is implemented in the timer.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.6.15 TIMx DMA control register (TIMx_DCR)(x = 16 to 17) Address offset: 0x48 Reset value: 0x0000 Res. Res. Res. DBL[4:0] Res. Res. Res. DBA[4:0] Bits 15:13 Reserved, must be kept at reset value. Bits 12:8 DBL[4:0]: DMA burst length This 5-bit field defines the length of DMA transfers (the timer recognizes a burst transfer when a read or a write access is done to the TIMx_DMAR address), i.e.
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bit 3 BKCMP3E: BRK COMP3 enable This bit enables the COMP3 for the timer’s BRK input. COMP3 output is ‘ORed’ with the other BRK sources. 0: COMP3 input disabled 1: COMP3 input enabled Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).
RM0444 General-purpose timers (TIM15/TIM16/TIM17) Bit 9 BKINP: BRK BKIN input polarity This bit selects the BKIN alternate function input sensitivity. It must be programmed together with the BKP polarity bit. 0: BKIN input is active low 1: BKIN input 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 828
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Bits 31:4 Reserved, must be kept at reset value. Bits 3:0 TI1SEL[3:0]: selects TI1[0] to TI1[15] input 0000: TIM17_CH1 input 0001: HSI48/256 0010: HSE/32 0011: MCO 0100: MCO2 Others: Reserved 1. Available on STM32G0B1xx and STM32G0C1xx salestypes only, reserved otherwise. 828/1390 RM0444 Rev 5...
RM0444 General-purpose timers (TIM15/TIM16/TIM17) 25.6.21 TIM16/TIM17 register map TIM16/TIM17 registers are mapped as 16-bit addressable registers as described in the table below: Table 130. TIM16/TIM17 register map and reset values Register Offset name TIMx_CR1 [1:0] 0x00 Reset value TIMx_CR2 0x04 Reset value TIMx_DIER 0x0C...
Page 830
General-purpose timers (TIM15/TIM16/TIM17) RM0444 Table 130. TIM16/TIM17 register map and reset values (continued) Register Offset name TIMx_RCR REP[7:0] 0x30 Reset value TIMx_CCR1 CCR1[15:0] 0x34 Reset value TIMx_BDTR BKF[3:0] DTG[7:0] 0x44 [1:0] Reset value TIMx_DCR DBL[4:0] DBA[4:0] 0x48 Reset value TIMx_DMAR DMAB[15:0] 0x4C Reset value...
RM0444 Low-power timer (LPTIM) Low-power timer (LPTIM) 26.1 Introduction The LPTIM is a 16-bit timer that benefits from the ultimate developments in power consumption reduction. Thanks to its diversity of clock sources, the LPTIM is able to keep running in all power modes except for Standby mode. Given its capability to run even with no internal clock source, the LPTIM can be used as a “Pulse Counter”...
Low-power timer (LPTIM) RM0444 26.3 LPTIM implementation Table 131 describes LPTIM implementation on STM32G0x1 devices: the full set of features is implemented in LPTIM1. LPTIM2 supports a smaller set of features, but is otherwise identical to LPTIM1. Table 131. STM32G0x1 LPTIM features LPTIM modes/features LPTIM1 LPTIM2...
RM0444 Low-power timer (LPTIM) 26.4.2 LPTIM pins and internal signals The following tables provide the list of LPTIM pins and internal signals, respectively. Table 132. LPTIM input/output pins Names Signal type Description LPTIM_IN1 Digital input LPTIM Input 1 from GPIO pin on mux input 0 LPTIM_IN2 Digital input LPTIM Input 2 from GPIO pin on mux input 0...
RM0444 Low-power timer (LPTIM) 26.4.4 LPTIM reset and clocks The LPTIM can be clocked using several clock sources. It can be clocked using an internal clock signal which can be PCLK (APB clock) or any other embedded oscillator selectable through the RCC (see RCC section for more details). Also, the LPTIM can be clocked using an external clock signal injected on its external Input1.
Low-power timer (LPTIM) RM0444 Figure 271. Glitch filter timing diagram CLKMUX Input Filter out 2 consecutive samples 2 consecutive samples Filtered MS32490V1 Note: In case no internal clock signal is provided, the digital filter must be deactivated by setting the CKFLT and TRGFLT bits to ‘0’. In that case, an external analog filter may be used to protect the LPTIM external inputs against glitches.
RM0444 Low-power timer (LPTIM) The external triggers are considered asynchronous signals for the LPTIM. So after a trigger detection, a two-counter-clock period latency is needed before the timer starts running due to the synchronization. If a new trigger event occurs when the timer is already started it will be ignored (unless timeout function is enabled).
Low-power timer (LPTIM) RM0444 Figure 273. LPTIM output waveform, Single counting mode configuration and Set-once mode activated (WAVE bit is set) LPTIM_ARR Compare Discarded trigger External trigger event MSv39231V2 In case of software start (TRIGEN[1:0] = ‘00’), the SNGSTRT setting will start the counter for one-shot counting.
RM0444 Low-power timer (LPTIM) 26.4.9 Timeout function The detection of an active edge on one selected trigger input can be used to reset the LPTIM counter. This feature is controlled through the TIMOUT bit. The first trigger event will start the timer, any successive trigger event will reset the counter and the timer will restart.
Low-power timer (LPTIM) RM0444 Figure 275. Waveform generation LPTIM_ARR Compare One shot Pol = 0 Set once One shot Pol = 1 Set once MS32467V2 26.4.11 Register update The LPTIM_ARR register and LPTIM_CMP register are updated immediately after the APB bus write operation, or at the end of the current period if the timer is already started.
RM0444 Low-power timer (LPTIM) 26.4.12 Counter mode The LPTIM counter can be used to count external events on the LPTIM Input1 or it can be used to count internal clock cycles. The CKSEL and COUNTMODE bits control which source will be used for updating the counter. In case the LPTIM is configured to count external events on Input1, the counter can be updated following a rising edge, falling edge or both edges depending on the value written to the CKPOL[1:0] bits.
Low-power timer (LPTIM) RM0444 26.4.14 Timer counter reset In order to reset the content of LPTIM_CNT register to zero, two reset mechanisms are implemented: • The synchronous reset mechanism: the synchronous reset is controlled by the COUNTRST bit in the LPTIM_CR register. After setting the COUNTRST bit-field to '1', the reset signal is propagated in the LPTIM kernel clock domain.
RM0444 Low-power timer (LPTIM) To activate the Encoder mode the ENC bit has to be set to ‘1’. The LPTIM must first be configured in Continuous mode. When Encoder mode is active, the LPTIM counter is modified automatically following the speed and the direction of the incremental encoder.
Low-power timer (LPTIM) RM0444 Figure 276. Encoder mode counting sequence Counter down MS32491V1 26.4.16 Debug mode When the microcontroller enters debug mode (core halted), the LPTIM counter either continues to work normally or stops, depending on the DBG_LPTIM_STOP configuration bit in the DBG module.
RM0444 Low-power timer (LPTIM) 26.6 LPTIM interrupts The following events generate an interrupt/wake-up event, if they are enabled through the LPTIM_IER register: • Compare match • Auto-reload match (whatever the direction if encoder mode) • External trigger event • Autoreload register write completed •...
Low-power timer (LPTIM) RM0444 Bits 31:7 Reserved, must be kept at reset value. Bit 6 DOWNIE: Direction change to down Interrupt Enable DOWN interrupt disabled DOWN interrupt enabled Note: If the LPTIM does not support encoder mode feature, this bit is reserved. Please refer to Section 26.3: LPTIM implementation.
Page 849
RM0444 Low-power timer (LPTIM) Bit 24 ENC: Encoder mode enable The ENC bit controls the Encoder mode 0: Encoder mode disabled 1: Encoder mode enabled Note: If the LPTIM does not support encoder mode feature, this bit is reserved. Please refer to Section 26.3: LPTIM implementation.
Page 850
Low-power timer (LPTIM) RM0444 Bits 15:13 TRIGSEL[2:0]: Trigger selector The TRIGSEL bits select the trigger source that will serve as a trigger event for the LPTIM among the below 8 available sources: 000: lptim_ext_trig0 001: lptim_ext_trig1 010: lptim_ext_trig2 011: lptim_ext_trig3 100: lptim_ext_trig4 101: lptim_ext_trig5 110: lptim_ext_trig6...
RM0444 Low-power timer (LPTIM) Bits 4:3 CKFLT[1:0]: Configurable digital filter for external clock The CKFLT value sets the number of consecutive equal samples that should be detected when a level change occurs on an external clock signal before it is considered as a valid level transition. An internal clock source must be present to use this feature 00: any external clock signal level change is considered as a valid transition 01: external clock signal level change must be stable for at least 2 clock periods before it is...
Low-power timer (LPTIM) RM0444 Bits 31:5 Reserved, must be kept at reset value. Bit 4 RSTARE: Reset after read enable This bit is set and cleared by software. When RSTARE is set to '1', any read access to LPTIM_CNT register will asynchronously reset LPTIM_CNT register content. Bit 3 COUNTRST: Counter reset This bit is set by software and cleared by hardware.
RM0444 Low-power timer (LPTIM) Bits 31:16 Reserved, must be kept at reset value. Bits 15:0 CMP[15:0]: Compare value CMP is the compare value used by the LPTIM. Caution: The LPTIM_CMP register must only be modified when the LPTIM is enabled (ENABLE bit set to ‘1’).
RM0444 Low-power timer (LPTIM) 26.7.10 LPTIM register map The following table summarizes the LPTIM registers. Table 143. LPTIM register map and reset values Offset Register name LPTIM_ISR 0x000 0 0 0 0 0 0 0 Reset value LPTIM_ICR 0x004 0 0 0 0 0 0 0 Reset value LPTIM_IER 0x008...
Page 856
Low-power timer (LPTIM) RM0444 If LPTIM does not support encoder mode feature, this bit is reserved. Please refer to Section 26.3: LPTIM implementation. Refer to Section 2.2 on page 58 for the register boundary addresses. 856/1390 RM0444 Rev 5...
RM0444 Infrared interface (IRTIM) Infrared interface (IRTIM) An infrared interface (IRTIM) for remote control is available on the device. It can be used with an infrared LED to perform remote control functions. It uses internal connections with USART1, USART4 (on STM32G071/81/B1/C1xx) or USART2 (STM32G031/41/51/61xx), TIM16 and TIM17 as shown in Figure 277.
Independent watchdog (IWDG) RM0444 Independent watchdog (IWDG) 28.1 Introduction The devices feature an embedded watchdog peripheral that offers a combination of high safety level, timing accuracy and flexibility of use. The Independent watchdog peripheral detects and solves malfunctions due to software failure, and triggers system reset when the counter reaches a given timeout value.
RM0444 Independent watchdog (IWDG) When the independent watchdog is started by writing the value 0x0000 CCCC in the IWDG key register (IWDG_KR), the counter starts counting down from the reset value of 0xFFF. When it reaches the end of count value (0x000) a reset signal is generated (IWDG reset). Whenever the key value 0x0000 AAAA is written in the IWDG key register (IWDG_KR), the...
Independent watchdog (IWDG) RM0444 28.3.3 Hardware watchdog If the “Hardware watchdog” feature is enabled through the device option bits, the watchdog is automatically enabled at power-on, and generates a reset unless the IWDG key register (IWDG_KR) is written by the software before the counter reaches end of count or if the downcounter is reloaded inside the window.
RM0444 Independent watchdog (IWDG) 28.4 IWDG registers Refer to Section 1.2 on page 53 for a list of abbreviations used in register descriptions. The peripheral registers can be accessed by half-words (16-bit) or words (32-bit). 28.4.1 IWDG key register (IWDG_KR) Address offset: 0x00 Reset value: 0x0000 0000 (reset by Standby mode) Res.
RM0444 System window watchdog (WWDG) System window watchdog (WWDG) 29.1 Introduction The system window watchdog (WWDG) 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. The watchdog circuit generates an MCU reset on expiry of a programmed time period, unless the program refreshes the contents of the down-counter before the T6 bit becomes cleared.
RM0444 System window watchdog (WWDG) Warning: When writing to the WWDG_CR register, always write 1 in the T6 bit to avoid generating an immediate reset. Figure 280. Window watchdog timing diagram CNT DownCounter Refresh not allowed Refresh allowed T[6:0] W[6:0] 0x3F Time WDGTB...
System window watchdog (WWDG) RM0444 As an example, lets assume APB frequency is equal to 48 MHz, WDGTB[1:0] is set to 3 and T[5:0] is set to 63: ⁄ × × × t WWDG 1 48000 4096 43.69ms Refer to the datasheet for the minimum and maximum values of the t WWDG 29.3.5 Debug mode...
RM0444 System window watchdog (WWDG) Bits 31:8 Reserved, must be kept at reset value. Bit 7 WDGA: Activation bit This bit is set by software and only cleared by hardware after a reset. When WDGA = 1, the watchdog can generate a reset. 0: Watchdog disabled 1: Watchdog enabled Bits 6:0 T[6:0]: 7-bit counter (MSB to LSB)
RM0444 Real-time clock (RTC) Real-time clock (RTC) 30.1 Introduction The RTC provides an automatic wakeup to manage all low-power modes. The real-time clock (RTC) is an independent BCD timer/counter. The RTC provides a time- of-day clock/calendar with programmable alarm interrupts. As long as the supply voltage remains in the operating range, the RTC never stops, regardless of the device status (Run mode, low-power mode or under reset).
Real-time clock (RTC) RM0444 Table 148. RTC interconnection Signal name Source/destination From power controller (PWR): main power loss/switch to V detection rtc_its output rtc_tamp_evt From TAMP peripheral: tamp_evt rtc_calovf To TAMP peripheral: tamp_itamp5 The triggers outputs can be used as triggers for other peripherals. 30.3.3 GPIOs controlled by the RTC and TAMP The GPIOs included in the Battery Backup Domain (V...
Page 877
RM0444 Real-time clock (RTC) Table 149. PC13 configuration (continued) PC13 Pin function 01 or 10 or Don’t Don’t Don’t Don’t No pull care care care care 01 or 10 or TAMPALRM output 01 or Open-Drain 10 or Internal Don’t Don’t Don’t Don’t pull-up...
Real-time clock (RTC) RM0444 Table 149. PC13 configuration (continued) PC13 Pin function Don’t care Wakeup pin or Standard Don’t Don’t GPIO care care Don’t Don’t care care 1. OD: open drain; PP: push-pull. 2. In this configuration the GPIO must be configured in input. In addition, it is possible to output RTC_OUT2 on PA4 pin thanks to OUT2EN bit.
RM0444 Real-time clock (RTC) A programmable prescaler stage generates a 1 Hz clock which is used to update the calendar. To minimize power consumption, the prescaler is split into 2 programmable prescalers (see Figure 281: RTC block diagram): • A 7-bit asynchronous prescaler configured through the PREDIV_A bits of the RTC_PRER register.
Real-time clock (RTC) RM0444 BYPSHAD control bit in the RTC_CR register. By default, this bit is cleared, and the user accesses the shadow registers. When reading the RTC_SSR, RTC_TR or RTC_DR registers in BYPSHAD = 0 mode, the frequency of the APB clock (f ) must be at least 7 times the frequency of the RTC clock RTCCLK The shadow registers are reset by system reset.
RM0444 Real-time clock (RTC) the RTC_SR register, and the wakeup counter is automatically reloaded with its reload value (RTC_WUTR register value). The WUTF flag must then be cleared by software. When the periodic wakeup interrupt is enabled by setting the WUTIE bit in the RTC_CR register, it can exit the device from low-power modes.
Page 882
Real-time clock (RTC) RM0444 Set INIT bit to 1 in the RTC_ICSR register to enter initialization mode. In this mode, the calendar counter is stopped and its value can be updated. Poll INITF bit of in the RTC_ICSR register. The initialization phase mode is entered when INITF is set to 1.
RM0444 Real-time clock (RTC) The wakeup timer restarts down-counting.The WUTWF bit is cleared up to 2 RTCCLK clocks cycles after WUTE is cleared, due to clock synchronization. 30.3.9 Reading the calendar When BYPSHAD control bit is cleared in the RTC_CR register To read the RTC calendar registers (RTC_SSR, RTC_TR and RTC_DR) properly, the APB1 clock frequency (f ) must be equal to or greater than seven times the RTC clock...
Real-time clock (RTC) RM0444 Note: While BYPSHAD = 1, instructions which read the calendar registers require one extra APB cycle to complete. 30.3.10 Resetting the RTC The calendar shadow registers (RTC_SSR, RTC_TR and RTC_DR) and some bits of the RTC status register (RTC_ICSR) are reset to their default values by all available system reset sources.
RM0444 Real-time clock (RTC) Caution: This synchronization feature is not compatible with the reference clock detection feature: firmware must not write to RTC_SHIFTR when REFCKON = 1. 30.3.12 RTC reference clock detection The update of the RTC calendar can be synchronized to a reference clock, RTC_REFIN, which is usually the mains frequency (50 or 60 Hz).
Page 886
Real-time clock (RTC) RM0444 The smooth calibration register (RTC_CALR) specifies the number of RTCCLK clock cycles to be masked during the 32-second cycle: • Setting the bit CALM[0] to 1 causes exactly one pulse to be masked during the 32- second cycle.
RM0444 Real-time clock (RTC) Verifying the RTC calibration RTC precision is ensured by measuring the precise frequency of RTCCLK and calculating the correct CALM value and CALP values. An optional 1 Hz output is provided to allow applications to measure and verify the RTC precision. Measuring the precise frequency of the RTC over a limited interval can result in a measurement error of up to 2 RTCCLK clock cycles over the measurement period, depending on how the digital calibration cycle is aligned with the measurement period.
Real-time clock (RTC) RM0444 The calendar is saved in the timestamp registers (RTC_TSSSR, RTC_TSTR, RTC_TSDR) when an internal timestamp event is detected. The internal timestamp event is generated by the switch to the V supply. When a timestamp event occurs, due to internal or external event, the timestamp flag bit (TSF) in RTC_SR register is set.
RM0444 Real-time clock (RTC) When the TAMPOE control bit is set is the RTC_CR, all external and internal tamper flags are ORed and routed to the TAMPALRM output. If OSEL = 00 the TAMPALRM output reflects only the tampers flags. If OSEL ≠ 00, the signal on TAMPALRM provides both tamper flags and alarm A, B, or wakeup flag.
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 30.6.2 RTC date register (RTC_DR) The RTC_DR is the calendar date shadow register.
Real-time clock (RTC) RM0444 Bits 7:6 Reserved, must be kept at reset value. Bits 5:4 DT[1:0]: Date tens in BCD format Bits 3:0 DU[3:0]: Date units in BCD format Note: The calendar is frozen when reaching the maximum value, and can’t roll over. 30.6.3 RTC sub second register (RTC_SSR) Address offset: 0x08...
Page 893
RM0444 Real-time clock (RTC) Bits 31:17 Reserved, must be kept at reset value. 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.
Real-time clock (RTC) RM0444 Bit 2 WUTWF: Wakeup timer write flag This bit is set by hardware when WUT value can be changed, after the WUTE bit has been set to 0 in RTC_CR. It is cleared by hardware in initialization mode. 0: Wakeup timer configuration update not allowed except in initialization mode 1: Wakeup timer configuration update allowed Bit 1 ALRBWF: Alarm B write flag...
RM0444 Real-time clock (RTC) 30.6.6 RTC wakeup timer register (RTC_WUTR) This register can be written only when WUTWF is set to 1 in RTC_ICSR. This register is write protected. The write access procedure is described in RTC register write protection on page 881.
Page 896
Real-time clock (RTC) RM0444 Bit 31 OUT2EN: RTC_OUT2 output enable Setting this bit allows to remap the RTC outputs on RTC_OUT2 as follows: OUT2EN = 0: RTC output 2 disable If OSEL ≠ 00 or TAMPOE = 1: TAMPALRM is output on RTC_OUT1 If OSEL = 00 and TAMPOE = 0 and COE = 1: CALIB is output on RTC_OUT1 OUT2EN = 1: RTC output 2 enable If (OSEL ≠...
Page 897
RM0444 Real-time clock (RTC) Bit 19 COSEL: Calibration output selection When COE = 1, this bit selects which signal is output on CALIB. 0: Calibration output is 512 Hz 1: Calibration output is 1 Hz These frequencies are valid for RTCCLK at 32.768 kHz and prescalers at their default values (PREDIV_A = 127 and PREDIV_S = 255).
Real-time clock (RTC) RM0444 Bit 6 FMT: Hour format 0: 24 hour/day format 1: AM/PM hour format Bit 5 BYPSHAD: Bypass the shadow registers 0: Calendar values (when reading from RTC_SSR, RTC_TR, and RTC_DR) are taken from the shadow registers, which are updated once every two RTCCLK cycles. 1: Calendar values (when reading from RTC_SSR, RTC_TR, and RTC_DR) are taken directly from the calendar counters.
RM0444 Real-time clock (RTC) Bits 31:8 Reserved, must be kept at reset value. Bits 7:0 KEY[7:0]: Write protection key This byte is written by software. Reading this byte always returns 0x00. Refer to RTC register write protection for a description of how to unlock RTC register write protection.
Real-time clock (RTC) RM0444 Bit 13 CALW16: Use a 16-second calibration cycle period When CALW16 is set to 1, the 16-second calibration cycle period is selected. This bit must not be set to 1 if CALW8 = 1. Note: CALM[0] is stuck at 0 when CALW16 = 1. Refer to Section 30.3.13: RTC smooth digital calibration.
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. 30.6.12 RTC timestamp date register (RTC_TSDR) The content of this register is valid only when TSF is set to 1 in RTC_SR.
Real-time clock (RTC) RM0444 Bits 31:16 Reserved, must be kept at reset value. Bits 15:13 WDU[2:0]: Week day units Bit 12 MT: Month tens in BCD format Bits 11:8 MU[3:0]: Month units in BCD format Bits 7:6 Reserved, must be kept at reset value. Bits 5:4 DT[1:0]: Date tens in BCD format Bits 3:0 DU[3:0]: Date units in BCD format 30.6.13...
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. RM0444 Rev 5...
Real-time clock (RTC) RM0444 30.6.15 RTC alarm A sub second register (RTC_ALRMASSR) This register can be written only when ALRAWF is set to 1 in RTC_ICSR, or in initialization mode. This register is write protected. The write access procedure is described in RTC register write protection on page 881.
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 RM0444 Rev 5...
Real-time clock (RTC) RM0444 30.6.17 RTC alarm B sub second register (RTC_ALRMBSSR) This register can be written only when ALRBE is reset in RTC_CR register, or in initialization mode. This register is write protected.The write access procedure is described in Section : RTC register write protection.
RM0444 Real-time clock (RTC) Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ITSF TSOVF WUTF ALRBF ALRAF Bits 31:6 Reserved, must be kept at reset value. Bit 5 ITSF: Internal timestamp flag This flag is set by hardware when a timestamp on the internal event occurs.
Real-time clock (RTC) RM0444 Bits 31:6 Reserved, must be kept at reset value. Bit 5 ITSMF: Internal timestamp masked flag This flag is set by hardware when a timestamp on the internal event occurs and timestampinterrupt is raised. Bit 4 TSOVMF: Timestamp overflow masked flag This flag is set by hardware when a timestamp interrupt occurs while TSMF is already set.
Page 909
RM0444 Real-time clock (RTC) Bit 2 CWUTF: Clear wakeup timer flag Writing 1 in this bit clears the WUTF bit in the RTC_SR register. Bit 1 CALRBF: Clear alarm B flag Writing 1 in this bit clears the ALRBF bit in the RTC_SR register. Bit 0 CALRAF: Clear alarm A flag Writing 1 in this bit clears the ALRBF bit in the RTC_SR register.
Tamper and backup registers (TAMP) RM0444 Tamper and backup registers (TAMP) 31.1 Introduction 5 32-bit backup registers are retained in all low-power modes and also in V mode. They can be used to store sensitive data as their content is protected by an tamper detection circuit.
HSE monitoring tamp_itamp5 RTC calendar overflow (rtc_calovf) tamp_itamp6 ST manufacturer readout 31.3.3 TAMP register write protection After system reset, the TAMP registers (including backup registers) are protected against parasitic write access by the DBP bit in the power control peripheral (refer to the PWR power control section).
RM0444 Tamper and backup registers (TAMP) 31.3.4 Tamper detection The tamper detection can be configured for the following purposes: • erase the backup registers (default configuration) • generate an interrupt, capable to wakeup from Stop and Standby mode • generate a hardware trigger for the low-power timers TAMP backup registers The backup registers (TAMP_BKPxR) are not reset by system reset or when the device wakes up from Standby mode.
Page 916
Tamper and backup registers (TAMP) RM0444 This feature is available only when the tamper is configured in the Level detection with filtering on tamper inputs (passive mode) mode (TAMPFLT ≠ 00 and active mode is not selected). Timestamp on tamper event With TAMPTS set to 1 in the RTC_CR, any tamper event causes a timestamp to occur.
RM0444 Tamper and backup registers (TAMP) 31.4 TAMP low-power modes Table 158. Effect of low-power modes on TAMP Mode Description No effect. Sleep TAMP interrupts cause the device to exit the Sleep mode. No effect on all features, except for level detection with filtering mode which remain active only when the clock source is LSE or LSI.
Bit 21 ITAMP6E: Internal tamper 6 enable: ST manufacturer readout 0: Internal tamper 6 disabled. 1: Internal tamper 6 enabled: a tamper is generated in case of ST manufacturer readout. Bit 20 ITAMP5E: Internal tamper 5 enable: RTC calendar overflow 0: Internal tamper 5 disabled.
RM0444 Tamper and backup registers (TAMP) Bit 2 TAMP3E: Tamper detection on TAMP_IN3 enable 0: Tamper detection on TAMP_IN3 is disabled. 1: Tamper detection on TAMP_IN3 is enabled. Bit 1 TAMP2E: Tamper detection on TAMP_IN2 enable 0: Tamper detection on TAMP_IN2 is disabled. 1: Tamper detection on TAMP_IN2 is enabled.
Tamper and backup registers (TAMP) RM0444 Bits 22:19 Reserved, must be kept at reset value. Bit 18 TAMP3MSK: Tamper 3 mask 0: Tamper 3 event generates a trigger event and TAMP3F must be cleared by software to allow next tamper event detection. 1: Tamper 3 event generates a trigger event.
RM0444 Tamper and backup registers (TAMP) Bits 31:8 Reserved, must be kept at reset value. Bit 7 TAMPPUDIS: TAMP_INx pull-up disable This bit determines if each of the TAMPx pins are precharged before each sample. 0: Precharge TAMP_INx pins before sampling (enable internal pull-up) 1: Disable precharge of TAMP_INx pins.
Bit 23 Reserved, must be kept at reset value. Bit 22 Reserved, must be kept at reset value. Bit 21 ITAMP6IE: Internal tamper 6 interrupt enable: ST manufacturer readout 0: Internal tamper 6 interrupt disabled. 1: Internal tamper 6 interrupt enabled.
Bit 23 Reserved, must be kept at reset value. Bit 22 Reserved, must be kept at reset value. Bit 21 ITAMP6F: ST manufacturer readout tamper detection flag This flag is set by hardware when a tamper detection event is detected on the internal tamper 6.
Tamper and backup registers (TAMP) RM0444 Bit 21 ITAMP6MF: ST manufacturer readout tamper interrupt masked flag This flag is set by hardware when the internal tamper 6 interrupt is raised. Bit 20 ITAMP5MF: RTC calendar overflow tamper interrupt masked flag This flag is set by hardware when the internal tamper 5 interrupt is raised.
RM0444 Tamper and backup registers (TAMP) Bit 17 Reserved, must be kept at reset value. Bit 16 Reserved, must be kept at reset value. Bits 15:3 Reserved, must be kept at reset value. Bit 2 CTAMP3F: Clear TAMP3 detection flag Writing 1 in this bit clears the TAMP3F bit in the TAMP_SR register.
RM0444 Inter-integrated circuit (I2C) interface Inter-integrated circuit (I2C) interface 32.1 Introduction The I C (inter-integrated circuit) bus interface handles communications between the microcontroller and the serial I C bus. It provides multimaster capability, and controls all I bus-specific sequencing, protocol, arbitration and timing. It supports Standard-mode (Sm), Fast-mode (Fm) and Fast-mode Plus (Fm+).
Inter-integrated circuit (I2C) interface RM0444 The following additional features are also available depending on the product implementation (see Section 32.3: I2C implementation): • SMBus specification rev 3.0 compatibility: – Hardware PEC (Packet Error Checking) generation and verification with ACK control –...
RM0444 Inter-integrated circuit (I2C) interface If SMBus feature is supported: the additional optional SMBus Alert pin (SMBA) is also available. 32.4.1 I2C1 block diagram The block diagram of the I2C1 interface is shown in Figure 283. Figure 283. I2C1 block diagram I2CCLK I2c_ker_ck Data control...
Inter-integrated circuit (I2C) interface RM0444 32.4.2 I2C2 block diagram The block diagram of the I2C2 interface is shown in Figure 284. Figure 284. I2C2 block diagram I2CCLK PCLK Data control Digital Analog Shift register noise noise GPIO I2C1_SDA filter filter logic SMBUS generation/...
RM0444 Inter-integrated circuit (I2C) interface 32.4.3 I2C pins and internal signals Table 162. I2C input/output pins Pin name Signal type Description I2C_SDA Bidirectional I2C data I2C_SCL Bidirectional I2C clock I2C_SMBA Bidirectional SMBus Alert Table 163. I2C internal input/output signals Internal signal name Signal type Description I2C kernel clock, also named I2CCLK in this...
Inter-integrated circuit (I2C) interface RM0444 By default, it operates in slave mode. The interface automatically switches from slave to master when it generates a START condition, and from master to slave if an arbitration loss or a STOP generation occurs, allowing multimaster capability. Communication flow In Master mode, the I2C interface initiates a data transfer and generates the clock signal.
RM0444 Inter-integrated circuit (I2C) interface suppression of spikes with a pulse width up to 50 ns in Fast-mode and Fast-mode Plus. The user can disable this analog filter by setting the ANFOFF bit, and/or select a digital filter by configuring the DNF[3:0] bit in the I2C_CR1 register. When the digital filter is enabled, the level of the SCL or the SDA line is internally changed only if it remains stable for more than DNF x I2CCLK periods.
Inter-integrated circuit (I2C) interface RM0444 I2C timings The timings must be configured in order to guarantee a correct data hold and setup time, used in master and slave modes. This is done by programming the PRESC[3:0], SCLDEL[3:0] and SDADEL[3:0] bits in the I2C_TIMINGR register. The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C configuration window Figure 286.
RM0444 Inter-integrated circuit (I2C) interface • When the SCL falling edge is internally detected, a delay is inserted before sending SDA output. This delay is where = SDADEL x t = (PRESC+1) SDADEL PRESC I2CCLK PRESC I2CCLK impacts the hold time SDADEL HD;DAT.
Page 936
Inter-integrated circuit (I2C) interface RM0444 Note: At every clock pulse, after SCL falling edge detection, the I2C master or slave stretches SCL low during at least [(SDADEL+SCLDEL+1) x (PRESC+1) + 1] x t , in both transmission I2CCLK and reception modes. In transmission mode, in case the data is not yet written in I2C_TXDR when SDADEL counter is finished, the I2C keeps on stretching SCL low until the next data is written.
RM0444 Inter-integrated circuit (I2C) interface Figure 287. I2C initialization flowchart Initial settings Clear PE bit in I2C_CR1 Configure ANFOFF and DNF[3:0] in I2C_CR1 Configure PRESC[3:0], SDADEL[3:0], SCLDEL[3:0], SCLH[7:0], SCLL[7:0] in I2C_TIMINGR Configure NOSTRETCH in I2C_CR1 Set PE bit in I2C_CR1 MS19847V2 32.4.7 Software reset...
Inter-integrated circuit (I2C) interface RM0444 32.4.8 Data transfer The data transfer is managed through transmit and receive data registers and a shift register. Reception The SDA input fills the shift register. After the 8th SCL pulse (when the complete data byte is received), the shift register is copied into I2C_RXDR register if it is empty (RXNE=0).
RM0444 Inter-integrated circuit (I2C) interface Transmission If the I2C_TXDR register is not empty (TXE=0), its content is copied into the shift register after the 9th SCL pulse (the Acknowledge pulse). Then the shift register content is shifted out on SDA line. If TXE=1, meaning that no data is written yet in I2C_TXDR, SCL line is stretched low until I2C_TXDR is written.
Inter-integrated circuit (I2C) interface RM0444 When RELOAD=0 in master mode, the counter can be used in 2 modes: • Automatic end mode (AUTOEND = ‘1’ in the I2C_CR2 register). In this mode, the master automatically sends a STOP condition once the number of bytes programmed in the NBYTES[7:0] bit field has been transferred.
Page 941
RM0444 Inter-integrated circuit (I2C) interface By default, the slave uses its clock stretching capability, which means that it stretches the SCL signal at low level when needed, in order to perform software actions. If the master does not support clock stretching, the I2C must be configured with NOSTRETCH=1 in the I2C_CR1 register.
Inter-integrated circuit (I2C) interface RM0444 Slave Byte Control mode In order to allow byte ACK control in slave reception mode, Slave Byte Control mode must be enabled by setting the SBC bit in the I2C_CR1 register. This is required to be compliant with SMBus standards.
Page 943
RM0444 Inter-integrated circuit (I2C) interface Slave transmitter A transmit interrupt status (TXIS) is generated when the I2C_TXDR register becomes empty. An interrupt is generated if the TXIE bit is set in the I2C_CR1 register. The TXIS bit is cleared when the I2C_TXDR register is written with the next data byte to be transmitted.
RM0444 Inter-integrated circuit (I2C) interface Slave receiver RXNE is set in I2C_ISR when the I2C_RXDR is full, and generates an interrupt if RXIE is set in I2C_CR1. RXNE is cleared when I2C_RXDR is read. When a STOP is received and STOPIE is set in I2C_CR1, STOPF is set in I2C_ISR and an interrupt is generated.
RM0444 Inter-integrated circuit (I2C) interface 32.4.10 I2C master mode I2C master initialization Before enabling the peripheral, the I2C master clock must be configured by setting the SCLH and SCLL bits in the I2C_TIMINGR register. The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C Configuration window.
RM0444 Inter-integrated circuit (I2C) interface Table 167. I C-SMBus specification clock timings Standard- Fast-mode Fast-mode SMBus mode (Sm) (Fm) Plus (Fm+) Symbol Parameter Unit SCL clock frequency 1000 Hold time (repeated) START condition 0.26 µs HD:STA Set-up time for a repeated START 0.26 µs SU:STA...
Inter-integrated circuit (I2C) interface RM0444 master re-launches automatically the slave address transmission until ACK is received. In this case ADDRCF must be set if a NACK is received from the slave, in order to stop sending the slave address. If the I2C is addressed as a slave (ADDR=1) while the START bit is set, the I2C switches to slave mode and the START bit is cleared, when the ADDRCF bit is set.
RM0444 Inter-integrated circuit (I2C) interface • If the master addresses a 10-bit address slave, transmits data to this slave and then reads data from the same slave, a master transmission flow must be done first. Then a repeated start is set with the 10 bit slave address configured with HEAD10R=1. In this case the master sends this sequence: ReStart + Slave address 10-bit header Read.
Inter-integrated circuit (I2C) interface RM0444 Figure 303. Transfer bus diagrams for I2C master transmitter Example I2C master transmitter 2 bytes, automatic end mode (STOP) legend: TXIS TXIS transmission reception Address data1 data2 SCL stretch INIT EV1 EV2 NBYTES INIT: program Slave address, program NBYTES = 2, AUTOEND=1, set START EV1: TXIS ISR: wr data1 EV2: TXIS ISR: wr data2 Example I2C master transmitter 2 bytes, software end mode (RESTART)
Page 957
RM0444 Inter-integrated circuit (I2C) interface Master receiver In the case of a read transfer, the RXNE flag is set after each byte reception, after the 8th SCL pulse. An RXNE event generates an interrupt if the RXIE bit is set in the I2C_CR1 register.
RM0444 Inter-integrated circuit (I2C) interface 32.4.11 I2C_TIMINGR register configuration examples The tables below provide examples of how to program the I2C_TIMINGR to obtain timings compliant with the I C specification. In order to get more accurate configuration values, the STM32CubeMX tool (I2C Configuration window) must be used. Table 168.
Inter-integrated circuit (I2C) interface RM0444 2. t minimum value is 4 x t = 250 ns. Example with t = 1000 ns. SYNC1 + SYNC2 I2CCLK SYNC1 + SYNC2 minimum value is 4 x t = 250 ns. Example with t = 750 ns.
Page 963
RM0444 Inter-integrated circuit (I2C) interface Bus protocols There are eleven possible command protocols for any given device. A device may use any or all of the eleven protocols to communicate. The protocols are Quick Command, Send Byte, Receive Byte, Write Byte, Write Word, Read Byte, Read Word, Process Call, Block Read, Block Write and Block Write-Block Read Process Call.
Inter-integrated circuit (I2C) interface RM0444 Packet error checking A packet error checking mechanism has been introduced in the SMBus specification to improve reliability and communication robustness. Packet Error Checking is implemented by appending a Packet Error Code (PEC) at the end of each message transfer. The PEC is calculated by using the C(x) = x + x + 1 CRC-8 polynomial on all the message bytes (including addresses and read/write bits).
RM0444 Inter-integrated circuit (I2C) interface Figure 307. Timeout intervals for t LOW:SEXT LOW:MEXT Start Stop LOW:SEXT LOW:MEXT LOW:MEXT LOW:MEXT SMBCLK SMBDAT MS19866V1 Bus idle detection A master can assume that the bus is free if it detects that the clock and data signals have been high for t greater than t .
Inter-integrated circuit (I2C) interface RM0444 Specific address (Slave mode) The specific SMBus addresses must be enabled if needed. Refer to Bus idle detection on page 965 for more details. • The SMBus Device Default Address (0b1100 001) is enabled by setting the SMBDEN bit in the I2C_CR1 register.
RM0444 Inter-integrated circuit (I2C) interface for a master. As the standard specifies only a maximum, the user can choose LOW:MEXT the same value for the both. Then the timer is enabled by setting the TEXTEN bit in the I2C_TIMEOUTR register. If the SMBus peripheral performs a cumulative SCL stretch for a time greater than (TIMEOUTB+1) x 2048 x t , and in the timeout interval described in...
Inter-integrated circuit (I2C) interface RM0444 • Configuring the maximum duration of t to 50 µs IDLE Table 175. Examples of TIMEOUTA settings for various I2CCLK frequencies (max t = 50 µs) IDLE TIMEOUTA[11:0] bits TIDLE bit TIMEOUTEN bit I2CCLK TIDLE 8 MHz 0x63 100 x 4 x 125 ns = 50 µs...
RM0444 Inter-integrated circuit (I2C) interface Figure 308. Transfer sequence flowchart for SMBus slave transmitter N bytes + PEC SMBus slave transmission Slave initialization I2C_ISR.ADDR = Read ADDCODE and DIR in I2C_ISR stretched I2C_CR2.NBYTES = N + 1 PECBYTE=1 Set I2C_ICR.ADDRCF I2C_ISR.TXIS Write I2C_TXDR.TXDATA MS19867V2...
Page 970
Inter-integrated circuit (I2C) interface RM0444 SMBus Slave receiver When the I2C is used in SMBus mode, SBC must be programmed to ‘1’ in order to allow the PEC checking at the end of the programmed number of data bytes. In order to allow the ACK control of each byte, the reload mode must be selected (RELOAD=1).
RM0444 Inter-integrated circuit (I2C) interface When the SMBus master wants to send a RESTART condition after the PEC, software mode must be selected (AUTOEND=0). In this case, once NBYTES-1 have been transmitted, the I2C_PECR register content is transmitted and the TC flag is set after the PEC transmission, stretching the SCL line low.
Page 974
Inter-integrated circuit (I2C) interface RM0444 SMBus Master receiver When the SMBus master wants to receive the PEC followed by a STOP at the end of the transfer, automatic end mode can be selected (AUTOEND=1). The PECBYTE bit must be set and the slave address must be programmed, before setting the START bit. In this case, after NBYTES-1 data have been received, the next received byte is automatically checked versus the I2C_PECR register content.
Inter-integrated circuit (I2C) interface RM0444 32.4.16 Wakeup from Stop mode on address match This section is relevant only when Wakeup from Stop mode feature is supported. Refer to Section 32.3: I2C implementation. The I2C is able to wakeup the MCU from Stop mode (APB clock is off), when it is addressed.
Page 977
RM0444 Inter-integrated circuit (I2C) interface Arbitration lost (ARLO) An arbitration loss is detected when a high level is sent on the SDA line, but a low level is sampled on the SCL rising edge. • In master mode, arbitration loss is detected during the address phase, data phase and data acknowledge phase.
Inter-integrated circuit (I2C) interface RM0444 When a timeout violation is detected in master mode, a STOP condition is automatically sent. When a timeout violation is detected in slave mode, SDA and SCL lines are automatically released. When a timeout error is detected, the TIMEOUT flag is set in the I2C_ISR register, and an interrupt is generated if the ERRIE bit is set in the I2C_CR1 register.
RM0444 Inter-integrated circuit (I2C) interface DMA must be initialized before setting the START bit. The end of transfer is managed with the NBYTES counter. • In slave mode with NOSTRETCH=0, when all data are transferred using DMA, the DMA must be initialized before the address match event, or in the ADDR interrupt subroutine, before clearing the ADDR flag.
Inter-integrated circuit (I2C) interface RM0444 32.6 I2C interrupts The table below gives the list of I2C interrupt requests. Table 177. I2C Interrupt requests Exit the Exit the Exit the Interrupt Interrupt Event Enable Interrupt clear Sleep Stop Standby acronym event flag control bit method...
RM0444 Inter-integrated circuit (I2C) interface 32.7 I2C registers Refer to Section 1.2 on page 53 for a list of abbreviations used in register descriptions. The peripheral registers are accessed by words (32-bit). 32.7.1 I2C control register 1 (I2C_CR1) Address offset: 0x00 Reset value: 0x0000 0000 Access: No wait states, except if a write access occurs while a write access to this register is ongoing.
Page 982
Inter-integrated circuit (I2C) interface RM0444 Bit 19 GCEN: General call enable 0: General call disabled. Address 0b00000000 is NACKed. 1: General call enabled. Address 0b00000000 is ACKed. Bit 18 WUPEN: Wakeup from Stop mode enable 0: Wakeup from Stop mode disable. 1: Wakeup from Stop mode enable.
Page 983
RM0444 Inter-integrated circuit (I2C) interface Bit 7 ERRIE: Error interrupts enable 0: Error detection interrupts disabled 1: Error detection interrupts enabled Note: Any of these errors generate an interrupt: Arbitration Loss (ARLO) Bus Error detection (BERR) Overrun/Underrun (OVR) Timeout detection (TIMEOUT) PEC error detection (PECERR) Alert pin event detection (ALERT) Bit 6 TCIE: Transfer Complete interrupt enable...
Inter-integrated circuit (I2C) interface RM0444 32.7.2 I2C control register 2 (I2C_CR2) Address offset: 0x04 Reset value: 0x0000 0000 Access: No wait states, except if a write access occurs while a write access to this register is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed.
Page 985
RM0444 Inter-integrated circuit (I2C) interface Bit 15 NACK: NACK generation (slave mode) The bit is set by software, cleared by hardware when the NACK is sent, or when a STOP condition or an Address matched is received, or when PE=0. 0: an ACK is sent after current received byte.
Page 986
Inter-integrated circuit (I2C) interface RM0444 Bit 11 ADD10: 10-bit addressing mode (master mode) 0: The master operates in 7-bit addressing mode, 1: The master operates in 10-bit addressing mode Note: Changing this bit when the START bit is set is not allowed. Bit 10 RD_WRN: Transfer direction (master mode) 0: Master requests a write transfer.
RM0444 Inter-integrated circuit (I2C) interface 32.7.3 I2C own address 1 register (I2C_OAR1) Address offset: 0x08 Reset value: 0x0000 0000 Access: No wait states, except if a write access occurs while a write access to this register is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed.
Inter-integrated circuit (I2C) interface RM0444 32.7.4 I2C own address 2 register (I2C_OAR2) Address offset: 0x0C Reset value: 0x0000 0000 Access: No wait states, except if a write access occurs while a write access to this register is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed.
RM0444 Inter-integrated circuit (I2C) interface 32.7.5 I2C timing register (I2C_TIMINGR) Address offset: 0x10 Reset value: 0x0000 0000 Access: No wait states PRESC[3:0] Res. Res. Res. Res. SCLDEL[3:0] SDADEL[3:0] SCLH[7:0] SCLL[7:0] Bits 31:28 PRESC[3:0]: Timing prescaler This field is used to prescale I2CCLK in order to generate the clock period t used for PRESC data setup and hold counters (refer to...
Inter-integrated circuit (I2C) interface RM0444 32.7.6 I2C timeout register (I2C_TIMEOUTR) Address offset: 0x14 Reset value: 0x0000 0000 Access: No wait states, except if a write access occurs while a write access to this register is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed.
RM0444 Inter-integrated circuit (I2C) interface 32.7.7 I2C interrupt and status register (I2C_ISR) Address offset: 0x18 Reset value: 0x0000 0001 Access: No wait states Res. Res. Res. Res. Res. Res. Res. Res. ADDCODE[6:0] TIME BUSY Res. ALERT ARLO BERR STOPF NACKF ADDR RXNE TXIS Bits 31:24 Reserved, must be kept at reset value.
Page 992
Inter-integrated circuit (I2C) interface RM0444 Bit 11 PECERR: PEC Error in reception This flag is set by hardware when the received PEC does not match with the PEC register content. A NACK is automatically sent after the wrong PEC reception. It is cleared by software by setting the PECCF bit.
RM0444 Inter-integrated circuit (I2C) interface Bit 2 RXNE: Receive data register not empty (receivers) This bit is set by hardware when the received data is copied into the I2C_RXDR register, and is ready to be read. It is cleared when I2C_RXDR is read. Note: This bit is cleared by hardware when PE=0.
Inter-integrated circuit (I2C) interface RM0444 Bit 10 OVRCF: Overrun/Underrun flag clear Writing 1 to this bit clears the OVR flag in the I2C_ISR register. Bit 9 ARLOCF: Arbitration lost flag clear Writing 1 to this bit clears the ARLO flag in the I2C_ISR register. Bit 8 BERRCF: Bus error flag clear Writing 1 to this bit clears the BERRF flag in the I2C_ISR register.
Universal synchonous receiver transmitter (USART) RM0444 Universal synchonous receiver transmitter (USART) This section describes the universal synchronous asynchronous receiver transmitter (USART). 33.1 USART introduction The USART offers a flexible means to perform Full-duplex data exchange with external equipments requiring an industry standard NRZ asynchronous serial data format. A very wide range of baud rates can be achieved through a fractional baud rate generator.
RM0444 Universal synchonous receiver transmitter (USART) 33.2 USART main features • Full-duplex asynchronous communication • NRZ standard format (mark/space) • Configurable oversampling method by 16 or 8 to achieve the best compromise between speed and clock tolerance • Baud rate generator systems •...
Universal synchonous receiver transmitter (USART) RM0444 33.3 USART extended features • LIN master synchronous break send capability and LIN slave break detection capability – 13-bit break generation and 10/11 bit break detection when USART is hardware configured for LIN • IrDA SIR encoder decoder supporting 3/16 bit duration for normal mode •...
Need help?
Do you have a question about the STM32G0 1 Series and is the answer not in the manual?
Questions and answers