Page 1
This reference manual targets application developers. It provides complete information on how to use the STM32L0x3 microcontroller memory and peripherals. The STM32L0x3 is a line of microcontrollers with different memory sizes, packages and peripherals. For ordering information, mechanical and electrical device characteristics please refer to the corresponding datasheets.
Page 10
Contents RM0367 9.4.9 GPIO alternate function low register (GPIOx_AFRL) (x = A to E and H) ......... 251 9.4.10 GPIO alternate function high register (GPIOx_AFRH) (x = A to E and H) .
Page 13
RM0367 Contents 14.5.1 Data register and data alignment (ADC_DR, ALIGN) ... . . 321 14.5.2 ADC overrun (OVR, OVRMOD) ......321 14.5.3 Managing a sequence of data converted without using the DMA .
Documentation conventions RM0367 Documentation conventions General information ®(a) ® The STM32L0x3 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.
RM0367 Documentation conventions Glossary This section gives a brief definition of acronyms and abbreviations used in this document: • Sector: 32 pages write protection granularity in the Code area • Page: 32 words for Code and System Memory areas, 1 word for Data, Factory Option and User Option areas •...
SPI1/2 USB SRAM USB FS DMA request MS32790V2 1. Refer to Table 1: STM32L0x3 memory density, to Table 2: Overview of features per category and to the device datasheets for the GPIO ports and peripherals available on your device. 56/1043...
RM0367 System and memory overview ® 2.1.1 S0: Cortex -bus ® This bus connects the DCode/ICode bus of the Cortex -M0+ core to the BusMatrix. This bus is used by the core to fetch instructions, get data and access the AHB/APB resources. 2.1.2 S1: DMA-bus This bus connects the AHB master interface of the DMA to the BusMatrix which manages...
RM0367 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.
RM0367 The following table gives the boundary addresses of the peripherals available in the devices. Table 3. STM32L0x3 peripheral register boundary addresses Boundary address Size (bytes) Peripheral Peripheral register map Section 9.4.12: GPIO register 0X5000 1C00 - 0X5000 1FFF GPIOH...
(SYSCFG_CFGR1)). Boot configuration In the STM32L0x3, three different boot modes can be selected through the BOOT0 pin and boot configuration bits in the User option byte, as shown in the following table. Table 4. Boot modes Boot mode selection...
MEM_MODE bits in the SYSCFG memory remap register (SYSCFG_CFGR1). Embedded bootloader bootloader The embedded 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: •...
Flash program memory and data EEPROM (FLASH) RM0367 Flash program memory and data EEPROM (FLASH) Introduction The non-volatile memory (NVM) is composed of: • Up to 192 Kbytes of Flash program memory. This area is used to store the application code.
RM0367 Flash program memory and data EEPROM (FLASH) NVM functional description 3.3.1 NVM organization The NVM is organized as 32-bit memory cells that can be used to store code, data, boot code or Option bytes. The memory array is divided into pages. A page is composed of 32 words (or 128 bytes) in Flash program memory and System memory, and 1 single word (or 4 bytes) in data EEPROM and Option bytes areas (user and factory).
RM0367 Flash program memory and data EEPROM (FLASH) 3.3.2 Dual-bank boot capability Category 5 devices have two Flash memory banks: Bank 1 and Bank 2. They feature an additional boot mechanism which allows booting either from Bank 2 or from Bank 1 depending on BFB2 bit status (bit 23 in FLASH_OPTR register).
Flash program memory and data EEPROM (FLASH) RM0367 Table 11. Boot pin and BFB2 bit configuration (continued) Boot mode selection Protection BFB2 Boot mode Aliasing nBOOT1 level BOOT0 option User Flash memory User Flash memory Bank1 is selected as the User Flash memory boot area.
RM0367 Flash program memory and data EEPROM (FLASH) You can read the NVM by word (4 bytes), half-word (2 bytes) or byte. When the NVM features only one bank, it is not possible to read the NVM during a write/erase operation. If a write/erase operation is ongoing, the reading will be in a wait state until the write/erase operation completes, stalling the master that requested the read operation, except when the address is read-protected.
Page 74
Flash program memory and data EEPROM (FLASH) RM0367 Change the CPU Frequency After reset, the clock used is the MSI (2.1 MHz) and 0 wait state is configured in the FLASH_ACR register. The following software sequences have to be respected to tune the number of wait states needed to access the NVM with the CPU frequency.
RM0367 Flash program memory and data EEPROM (FLASH) Data buffering In the NVM, six buffers can impact the performance (and in some conditions help to reduce the power consumption) during read operations, both for fetch and data. The structure of one buffer is shown on Figure Figure 3.
Flash program memory and data EEPROM (FLASH) RM0367 Table 14. Internal buffer management Buffers for fetch Buffers for data DISAB_BUF PREFTEN PRE_READ Buffers for Buffers for Buffers for Buffers for Buffers for jumps prefetch last value pre-read last value If a value in a buffer is not empty, the history shows the time elapsed between the moment it has been read or written.
RM0367 Flash program memory and data EEPROM (FLASH) To manage the fetch, the memory interface uses 4 buffers: at reset (DISAB_BUF = 0, PRFTEN = 0, PRE_READ = 0). 3 buffers are used to manage the jumps and 1 buffer to store the last value fetched.
Page 78
Flash program memory and data EEPROM (FLASH) RM0367 Figure 5 shows the timing to fetch and execute instructions from the NVM with 0 wait states (a) and 1 wait state (b) when the prefetch is enabled. The read executed by the prefetch appears in green.
Flash program memory and data EEPROM (FLASH) RM0367 Dhrystone performances The Dhrystone test is used to evaluate the memory interface performances. The test has been executed in all memory interface configurations. Refer to Table 16 for a summary of the results. Common parameters are: •...
RM0367 Flash program memory and data EEPROM (FLASH) 3.3.4 Writing/erasing the NVM There are many ways to change the NVM content. The memory interface helps to reduce the possibility of unwanted changes and to implement by hardware all sequences necessary to erase or write in the different memory areas.
Flash program memory and data EEPROM (FLASH) RM0367 When the memory interface receives the first address, it stalls the master for some pulses of clock while it checks the protections and the previous value and it latches the new value inside the NVM (for more details, see Table 17).
Page 83
RM0367 Flash program memory and data EEPROM (FLASH) Any wrong key sequence will lock up FLASH_PECR until the next reset and generate a hard fault. Idem if the master tries to write another register between the two key sequences or if it uses the wrong key. A reading access does not generate an error and does not interrupt the sequence.
Page 84
Flash program memory and data EEPROM (FLASH) RM0367 To lock the Flash program memory again, the software only needs to set PRGLOCK bit in FLASH_PECR. When locked again, PRGLOCK bit needs a new sequence to return to 0. If PELOCK returns to 1 (locked), PRGLOCK is automatically locked, too. Unlocking the Option bytes area An additional write protection is implemented on the Option bytes area.
RM0367 Flash program memory and data EEPROM (FLASH) Detailed description of NVM write/erase operations This section details the different types of write and erase operations, showing the necessary bits for each one. Write to data EEPROM • Purpose Write one word in the data EEPROM with a specific value. •...
Page 86
Flash program memory and data EEPROM (FLASH) RM0367 Erase data EEPROM • Purpose Delete one row in data EEPROM. This operation performs the same function as Write a word which size is null to data EEPROM. It is available for compatibility purpose only. •...
Page 87
RM0367 Flash program memory and data EEPROM (FLASH) This operation aims at writing a word in the Option bytes area. The Option bytes area can only be written in Level 0 or Level 1. The user must consider that, in a word, the 16 higher bits (from 16 to 31) have to be the complement of the 16 lower bits (from 0 to 15): a mismatch between the higher and lower parts of data would generate an error during the Option bytes loading (see Section 3.8: Option...
Page 88
Flash program memory and data EEPROM (FLASH) RM0367 Erase Option bytes • Purpose Delete one row in the Option bytes area. This operation performs the same function as Write Option Byte with a zero value. It is available for compatibility purpose only. •...
Page 89
RM0367 Flash program memory and data EEPROM (FLASH) Program a single word to Flash program memory • Purpose Write one word in the Flash program memory with a specific value. • Size Write only by word. • Address Select an address in the Flash program memory. •...
Page 90
Flash program memory and data EEPROM (FLASH) RM0367 Program half-page in Flash program memory • Purpose Write one half page (16 words) in the Flash program memory. • Size Write only by word. • Address Select one address in the Flash program memory aligned to a half-page (for the first address) and inside the same half-page selected by the second address for the next 15 addresses.
RM0367 Flash program memory and data EEPROM (FLASH) – Other categories NOTZEROERR is set to 1. Writing a word to an address containing a non-null value is not performed. When a half-page operation starts, the memory interface waits for 16 addresses/data, aborting (with a hard fault) all read accesses that are not a fetch (refer to Fetch and prefetch).
Page 92
Flash program memory and data EEPROM (FLASH) RM0367 Erase a page in Flash program memory • Purpose Delete one page (32 words) in the Flash program memory. • Size Erase only by word (it deletes a page of the Flash program memory writing with a word size) •...
Page 93
RM0367 Flash program memory and data EEPROM (FLASH) Mass erase • Purpose Remove the read and write protection on the Flash program memory and data EEPROM. • Size Erase only by word. • Address To generate a mass erase, it is necessary to write 0x015500AA to the first Option bytes address (bits 31 to 25 and 15 to 9 are not complemented because they are not used, and not checked) with Level 1 as the actual level.
Flash program memory and data EEPROM (FLASH) RM0367 Timing tables Table 17. NVM write/erase timings Delay to latch the first Delay to latch the next Operation address/data address/data (in AHB clock pulses) (in AHB clock pulses) Write to data EEPROM Erase data EEPROM Write Option bytes Erase Option bytes...
RM0367 Flash program memory and data EEPROM (FLASH) Status register The FLASH_SR Status Register gives some information on the memory interface or the NVM status (operation(s) ongoing) and about errors that happened. This flags is set and reset by hardware. It is set to 1 every time the memory interface executes a write/erase operation, and it informs that no other operation can be executed.
Flash program memory and data EEPROM (FLASH) RM0367 To reset this flag, the software need to write it to 1. SIZERR This flag is set by hardware and reset by software. It informs when a size error happened. It is raised when: •...
RM0367 Flash program memory and data EEPROM (FLASH) Three types of protections are implemented. 3.4.1 RDP (Read Out Protection) This type of protection aims at protecting against unwanted read (hacking) of the NVM content. This protection is managed by RDPROT bitfield in the FLASH_OPTR register. The value is loaded from the Option bytes area during a boot and copied in the read-only register.
RM0367 Flash program memory and data EEPROM (FLASH) Any read access performed as data (see Read as data and pre-read) in a protected sector will trigger the RDERR flag in the FLASH_SR register. Any read-protected sector is also write-protected and any write access to one of these sectors will trigger the WRPERR flag in the FLASH_SR register.
Flash program memory and data EEPROM (FLASH) RM0367 The only way to remove a protection from a sector is to request a mass erase (which changes the protection level to 0 and disables PcROP): when PcROP is disabled, the protection on sectors can be changed freely. 3.4.3 Protections against unwanted write/erase operations The memory interface implements two ways to protect against unwanted write/erase...
RM0367 Flash program memory and data EEPROM (FLASH) Table 21. Memory access vs mode, protection and Flash program memory sectors (continued) Mode User (including In Application User Flash program memory Programming) in Debug, or sectors no Debug, or with Boot in RAM, or no Boot in RAM, or with Boot in System memory no Boot in System memory...
Flash program memory and data EEPROM (FLASH) RM0367 3.4.5 Protection errors Write protection error flag (WRPERR) If an erase/program operation to a write-protected page of the Flash program memory and data EEPROM is launched, the Write Protection Error flag (WRPERR) is set in the FLASH_SR register.
RM0367 Flash program memory and data EEPROM (FLASH) Table 22. Flash interrupt request Interrupt event Event flag Enable control bit End of operation EOPIE RDERR WRPERR PGAERR Error OPTVERR ERRIE SIZERR FWWERR NOTZEROERR 3.5.1 Hard fault A hard fault is generated on: •...
Flash program memory and data EEPROM (FLASH) RM0367 master are blocked, the memory interface continues the operation freeing the bus and the master. • If the address is protected, the write/erase is filtered (the write/erase requested is never sent to the memory) and an error is raised. •...
RM0367 Flash program memory and data EEPROM (FLASH) Write while another write operation is ongoing If the master requests a write operation while another one is ongoing, there are different cases: • If the previous write uses a Single programming operation or a Multiple programming operation (half page)
Flash program memory and data EEPROM (FLASH) RM0367 Flash register description Read registers To read all internal registers of the memory interface, the user must read at the register addresses. The content is available immediately (no wait state is necessary to read registers).
Flash program memory and data EEPROM (FLASH) RM0367 Bit 2 Reserved, must be kept at reset value Bit 1 PRFTEN This bit enables the prefetch. It is automatically reset every time the DISAB_BUF bit (in this register) is set to 1. To know how the prefetch works, see the Fetch and prefetch section.
Page 109
RM0367 Flash program memory and data EEPROM (FLASH) Bits 31:24 Reserved, must be kept at reset value Bit 23 NZDISABLE: Non-Zero check notification disable When this bit is set, the application software does not check if the previous NVM content is zero before programming a word or an half-page in the program or boot area.
Page 110
Flash program memory and data EEPROM (FLASH) RM0367 Bit 8 FIX 0: An erase phase is automatically performed, when necessary, before a program operation in the data EEPROM and the Option bytes areas. The programming time can be: Tprog (program operation) or 2 * Tprog (erase + program operations). 1: The program operation is always performed with a preliminary erase and the programming time is: 2 * Tprog.
Page 111
RM0367 Flash program memory and data EEPROM (FLASH) Bit 2 OPTLOCK: Option bytes lock This bit blocks the write/erase operations to the user Option bytes area and the OBL_LAUNCH bit (in this register). It can only be written to 1 to re-lock. To reset to 0, a correct sequence of unlock with OPTKEYR register is necessary (see Unlocking the Option bytes area), with PELOCK bit at 0.
Flash program memory and data EEPROM (FLASH) RM0367 3.7.3 Power-down key register (FLASH_PDKEYR) Address offset: 0x08 Reset value: 0x0000 0000 FLASH_PDKEYR[31:16] FLASH_PDKEYR15:0] Bits 31:0 This is a write-only register. With a sequence of two write operations (the first one with 0x04152637 and the second one with 0xFAFBFCFD), the write size being that of a word, it is possible to unlock the RUN_PD bit of the FLASH_ACR register.
RM0367 Flash program memory and data EEPROM (FLASH) 3.7.6 Option bytes unlock key register (FLASH_OPTKEYR) Address offset: 0x14 Reset value: 0x0000 0000 FLASH_OPTKEYR[31:16] FLASH_OPTKEYR[15:0] Bits 31:0 This is a write-only register. With a sequence of two write operations (the first one with 0xFBEAD9C8 and the second one with 0x24252627), the write size being that of a word, it is possible to unlock the Option bytes area and the OBL_LAUNCH bit.
Page 115
RM0367 Flash program memory and data EEPROM (FLASH) Bit 10 SIZERR: Size error This bit is set by hardware when the size of data to program is not correct. It is cleared by writing 1. 0: No size error happened. 1: One size error happened.
Flash program memory and data EEPROM (FLASH) RM0367 3.7.8 Option bytes register (FLASH_OPTR) Address offset 0x1C Reset value: 0xX0XX 0XXX. It depends on the value programmed in the option bytes. During production, it is set to 0x8070 00AA. Res. Res. Res.
Page 117
RM0367 Flash program memory and data EEPROM (FLASH) Bit 20 WDG_SW If there is a mismatch on this configuration during the Option bytes loading, it is loaded with 1. 0: Hardware watchdog. 1: Software watchdog. Bits 19:16 BOR_LEV: Brownout reset threshold level These bits reset the threshold level for a 1.45 V to 1.55 V voltage range (power-down only).
Flash program memory and data EEPROM (FLASH) RM0367 3.7.9 Write protection register 1 (FLASH_WRPROT1) Address offset: 0x20 Reset value: 0xXXXX XXXX. It depends on the value programmed in the option bytes. During production, it is set to 0x0000 0000. WRPROT1[31:16] WRPROT1[15:0] Bits 31:0 WRPROT1: Write protection –...
RM0367 Flash program memory and data EEPROM (FLASH) 3.7.10 Write protection register 2 (FLASH_WRPROT2) Address offset: 0x80 Reset value: 0x 0000 XXXX. It depends on the value programmed in the option bytes. During production, it is set to 0x0000 0000. Res.
RM0367 Flash program memory and data EEPROM (FLASH) Option bytes On the NVM, an area is reserved to store a set of Option bytes which are used to configure the product. Some option bytes are written in factory while others can be configured by the end user.
Flash program memory and data EEPROM (FLASH) RM0367 3.8.2 Mismatch when loading protection flags When there is a mismatch during an Option byte loading, the memory interface sets the default value in registers. In the Option byte area, there are three kinds of protection information: •...
RM0367 Cyclic redundancy check calculation unit (CRC) Cyclic redundancy check calculation unit (CRC) 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.
RM0367 Cyclic redundancy check calculation unit (CRC) 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: •...
Cyclic redundancy check calculation unit (CRC) RM0367 CRC registers 4.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.
Firewall (FW) RM0367 Firewall (FW) Introduction The Firewall is made to protect a specific part of code or data into the Non-Volatile Memory, and/or to protect the Volatile data into the SRAM from the rest of the code executed outside the protected area.
Firewall AMBA bus snoop The Firewall peripheral is snooping the AMBA buses on which the memories (volatile and non-volatile) are connected. A global architecture view is illustrated in Figure Figure 8. STM32L0x3 firewall connection schematics AHB Slave AHB Master 1 Flash program...
Firewall (FW) RM0367 Write protection In order to offer a maximum security level, the following points need to be respected: • It is mandatory to keep a write protection on the part of the code enabling the Firewall. This activation code should be located outside the segments protected by the Firewall. •...
RM0367 Firewall (FW) Volatile data segment Volatile data used by the protected code located into the code segment must be defined into the SRAM memory. The access to this segment is defined into the Section 5.3.4: Segment accesses and properties. Depending on the Volatile data segment configuration, the Firewall must be opened or not before accessing this segment area.
Firewall (FW) RM0367 The Volatile data segment is a bit different from the two others. The segment can be: • Shared (VDS bit in the register) It means that the area and the data located into this segment can be shared between the protected code and the user code executed in a non-protected area.
RM0367 Firewall (FW) Below is the initialization procedure to follow: Configure the RCC to enable the clock to the Firewall module Configure the RCC to enable the clock of the system configuration registers Set the base address and length of each segment (CSSA, CSL, NVDSSA, NVDSL, VDSSA, VDSL registers) Set the configuration register of the Firewall (FW_CR register) Enable the Firewall clearing the FWDIS bit in the system configuration register.
Firewall (FW) RM0367 Opening the Firewall As soon as the Firewall is enabled, it is closed. It means that most of the accesses to the protected segments are forbidden (refer to Section 5.3.4: Segment accesses and properties). In order to open the Firewall to interact with the protected segments, it is mandatory to apply the “call gate”...
Firewall (FW) RM0367 5.4.3 Non-volatile data segment start address (FW_NVDSSA) Address offset: 0x08 Reset value: 0x0000 0000 Res. Res. Res. Res. Res. Res. Res. Res. ADD[23:16] ADD[15:8] Res. Res. Res. Res. Res. Res. Res. Res. Bits 31:24 Reserved, must be kept at the reset value. Bits 23:8 ADD[23:8]: Non-volatile data segment start address The LSB bits of the start address (bit 7:0) are reserved and forced to 0 in order to allow a 256-byte granularity.
Power control (PWR) RM0367 Power control (PWR) Power supplies The device requires a 1.8-to-3.6 V V operating voltage supply (down to 1.65 V at power- down) when the BOR is available. The device requires a 1.65-to-3.6 V V operating voltage supply when the BOR is not available. An embedded linear voltage regulator is used to supply the internal digital power, ranging from 1.2 to 1.8 V.
Power control (PWR) RM0367 6.1.2 Independent LCD supply The V pin is provided to control the contrast of the glass LCD. This pin can be used in two ways: • It can receive from an external circuitry the desired maximum voltage that is provided on segment and common lines to the glass LCD by the microcontroller.
RM0367 Power control (PWR) 6.1.4 Voltage regulator An embedded linear voltage regulator supplies all the digital circuitries except for the Standby circuitry. The regulator output voltage (V ) can be programmed by software to CORE three different ranges within 1.2 - 1.8 V (typical) (see Section 6.1.5).
Power control (PWR) RM0367 Range 2 and 3 The regulator can also be programmed to output a regulated 1.5 V (typical, range 2) or a 1.2 V (typical, range 3) without any limitations on V (1.65 to 3.6 V). • At 1.5 V, the Flash memory is still functional but with medium read access time.
RM0367 Power control (PWR) 6.1.6 Dynamic voltage scaling configuration The following sequence is required to program the voltage regulator ranges: Check V to identify which ranges are allowed (see Figure 11: Performance versus VDD and VCORE range). Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0. Configure the voltage scaling range by setting the VOS[1:0] bits in the PWR_CR register.
Voltage range and limitations when V ranges from 1.71 V to 2.0 V The STM32L0x3 voltage regulator is based on an architecture designed for Ultra-low-power a. It does not use any external capacitor. Such regulator is sensitive to fast changes of load.
RM0367 Power control (PWR) Figure 12. Power supply supervisors DD A 100 mV hysteresis 100 mV BO R hysteresis IT enabled PVD output BOR reset (NRST) BOR/PDR reset (NRST) POR/PDR reset (NRST) BOR always active BOR disabled by option byte POR/PDR (BOR not available) ai17211b 1.
Power control (PWR) RM0367 6.2.1 Power-on reset (POR)/power-down reset (PDR) The device has an integrated POR/PDR circuitry that allows operation down to 1.5 V. During power-on, the device remains in Reset mode when V is below a specified threshold, V , without the need for an external reset circuit.
RM0367 Power control (PWR) And when the BOR option is disabled by option byte, the power-down reset is controlled by the PDR and a “gray zone” exists between the 1.65 V and V is configured through device option bytes. By default, the Level 4 threshold is activated.
Power control (PWR) RM0367 generated when V drops below the PVD threshold. As an example the service routine could perform emergency shutdown tasks. Figure 15. PVD thresholds VDD/VDDA 100mV PVD threshold hysteresis PVD output MSv32795V2 6.2.4 Internal voltage reference (V REFINT The internal reference (V ) provides stable voltage for analog peripherals.
RM0367 Power control (PWR) Low-power modes By default, the microcontroller is in Run mode after a system or a power-on reset. In Run mode the CPU is clocked by HCLK and the program code is executed. 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.
Power control (PWR) RM0367 Table 32. Summary of low-power modes (continued) Effect on V Effect on V CORE Mode name Entry Wakeup domain Voltage regulator domain clocks clocks PDDS, LPSDSR Any EXTI line bits + (configured in the EXTI In low-power Stop SLEEPDEEP bit + registers, internal and...
RM0367 Power control (PWR) 6.3.2 Slowing down system clocks In Run mode the speed of the system clocks (SYSCLK, HCLK, PCLK1, PCLK2) can be reduced by programming the prescaler registers. These prescalers can also be used to slow down peripherals before entering Sleep mode. For more details refer to Section 7.3.4: Clock configuration register (RCC_CFGR).
Power control (PWR) RM0367 Exiting Low-power run mode To exit Low-power run mode proceed as follows: The regulator is forced in Main regulator mode by software. The Flash memory is switched on, if needed. The frequency of the clock system can be increased. 6.3.5 Entering low-power mode Low-power modes (except for Low-power run mode) are entered by executing the WFI...
RM0367 Power control (PWR) 6.3.7 Sleep mode I/O states in Sleep mode In Sleep mode, all I/O pins keep the same state as in Run mode. Entering Sleep mode The Sleep mode is entered according to Section 6.3.5: Entering low-power mode.
Power control (PWR) RM0367 Table 34. Sleep-on-exit Sleep-on-exit Description WFI (wait for interrupt) while: – SLEEPDEEP = 0 and – No interrupt (for WFI) or event (for WFE) is pending ® Refer to the Cortex -M0+ System Control register (see PM0223 programming manual).
RM0367 Power control (PWR) Note: To be able to read the RTC calendar register when the APB1 clock frequency is less than seven times the RTC clock frequency (7*RTCLCK), the software must read the calendar time and date registers twice. If the second read of the RTC_TR gives the same result as the first read, this ensures that the data is correct.
Power control (PWR) RM0367 Table 36. Sleep-on-exit (Low-power sleep) Sleep-on-exit Description WFI (wait for interrupt) while: – SLEEPDEEP = 0 and – No interrupt (for WFI) or event (for WFE) is pending ® Refer to the Cortex -M0+ System Control register (see PM0223 programming manual).
RM0367 Power control (PWR) To further reduce power consumption in Stop mode, the internal voltage regulator can be put in low-power mode. This is configured by the LPSDSR bit in the PWR_CR register (see Section 6.4.1). The internal voltage regulator can also be kept in Main mode but the consumption will be much higher.
Power control (PWR) RM0367 Table 37. Stop mode Stop mode Description WFI (Wait for Interrupt) or WFE (Wait for Event) while: – No interrupt (for WFI) or event (for WFE) is pending. ® – SLEEPDEEP bit is set in Cortex -M0+ System Control register –...
RM0367 Power control (PWR) 6.3.10 Standby mode The Standby mode allows to achieve the lowest power consumption. It is based on the ® Cortex -M0+ Deepsleep mode, with the voltage regulator disabled. The V domain is CORE consequently powered off. The PLL, the MSI, the HSI16 oscillator and the HSE oscillator are also switched off.
Power control (PWR) RM0367 Table 38. Standby mode Standby mode Description WFI (Wait for Interrupt) or WFE (Wait for Event) while: ® – SLEEPDEEP = 1 in Cortex -M0+ System Control register – PDDS = 1 bit in Power Control register (PWR_CR) –...
RM0367 Power control (PWR) The RTC provides a programmable time base for waking up from Stop or Standby mode at regular intervals. For this purpose, two of the three alternative RTC clock sources can be selected by programming the RTCSEL[1:0] bits in the RCC_CSR register (see Section 7.3.21): •...
Power control (PWR) RM0367 Comparator auto-wakeup (AWU) from the Stop mode • To wake up from the Stop mode with a comparator 1 or comparator 2 wakeup event, it is necessary to: Configure the EXTI Line 21 for comparator 1 or EXTI Line 22 for comparator 2 (Interrupt or Event mode) to be sensitive to the selected edges (falling, rising or falling and rising) Configure the comparator to generate the event.
RM0367 Power control (PWR) Power control registers The peripheral registers have to be accessed by half-words (16-bit) or words (32-bit). 6.4.1 PWR power control register (PWR_CR) Address offset: 0x00 Reset value: 0x0000 1000 (reset by wakeup from Standby mode) Res. Res.
Page 168
Power control (PWR) RM0367 Bit 10 FWU: Fast wakeup This bit works in conjunction with ULP bit. If ULP = 0, FWU is ignored If ULP = 1 and FWU = 1: V startup time is ignored when exiting from low-power mode. REFINT The VREFINTRDYF flag in the PWR_CSR register indicates when the V is ready...
Page 169
RM0367 Power control (PWR) Bit 2 CWUF: Clear wakeup flag This bit is always read as 0. 0: No effect 1: Clear the WUF Wakeup flag after 2 system clock cycles Bit 1 PDDS: Power-down deepsleep This bit is set and cleared by software. 0: Enter Stop mode when the CPU enters Deepsleep.
Power control (PWR) RM0367 6.4.2 PWR power control/status register (PWR_CSR) Address offset: 0x04 Reset value: 0x0000 0008 (not reset by wakeup from Standby mode) Additional APB cycles are needed to read this register versus a standard APB read. Res. Res. Res.
Page 171
RM0367 Power control (PWR) Bit 4 VOSF: Voltage Scaling select flag A delay is required for the internal regulator to be ready after the voltage range is changed. The VOSF bit indicates that the regulator has reached the voltage level defined with bits VOS of PWR_CR register.
Power control (PWR) RM0367 6.4.3 PWR register map The following table summarizes the PWR registers. Table 39. PWR - register map and reset values Offset Register PWR_CR PLS[2:0] [1:0] 0x000 Reset value PWR_CSR 0x004 Reset value Refer to Section 2.2 on page 58 for the register boundary addresses.
RM0367 Reset and clock control (RCC) Reset and clock control (RCC) Reset There are three types of reset, defined as system reset, power reset and RTC domain reset. 7.1.1 System reset A system reset sets all registers to their reset values unless specified otherwise in the register description.
Reset and clock control (RCC) RM0367 7.1.2 Power reset A power reset is generated when one of the following events occurs: • Power-on/power-down reset (POR/PDR reset) • BOR reset A power reset sets all registers to their reset values including for the RTC domain (see Figure These sources act on the NRST pin and it is always kept low during the delay phase.
RM0367 Reset and clock control (RCC) Clocks Four different clock sources can be used to drive the system clock (SYSCLK): • HSI16 (high-speed internal) oscillator clock • HSE (high-speed external) oscillator clock • PLL clock • MSI (multispeed internal) oscillator clock The MSI at 2.1MHz is used as system clock source after startup from power reset, system or RTC domain reset, and after wake-up from Standby mode.
Page 176
Reset and clock control (RCC) RM0367 – LSI clock – APB clock (PCLK) • The RTC/LCD clock which is derived from the following clock sources: – LSE clock, – LSI clock, – 4 MHz HSE_RTC (HSE divided by a programmable prescaler). •...
Reset and clock control (RCC) RM0367 The timer clock frequencies are automatically fixed by hardware. There are two cases: If the APB prescaler is 1, the timer clock frequencies are set to the same frequency as that of the APB domain to which the timers are connected. Otherwise, they are set to twice (×2) the frequency of the APB domain to which the timers are connected.
Calibration RC oscillator frequencies can vary from one chip to another due to manufacturing process variations, this is why each device is factory calibrated by ST for 1% accuracy at an ambient temperature, T , of 25 °C.
Calibration The MSI RC oscillator frequency can vary from one chip to another due to manufacturing process variations, this is why each device is factory calibrated by ST for 1% accuracy at an ambient temperature, T , of 25 °C.
RM0367 Reset and clock control (RCC) ENREF_HSI48 in Section 10.2.3: Reference control and status register (SYSCFG_CFGR3)) The HSI48RDY flag in the Clock recovery RC register (RCC_CRRCR) indicates whether the HSI48 RC is stable or not. At startup, the HSI48 RC output clock is not released until this bit is set by hardware.
Reset and clock control (RCC) RM0367 7.2.6 LSE clock The LSE crystal is a 32.768 kHz low speed external crystal or ceramic resonator. It has the advantage of providing a low-power but highly accurate clock source to the real-time clock peripheral (RTC) for clock/calendar or other timing functions.
RM0367 Reset and clock control (RCC) 7.2.8 System clock (SYSCLK) selection Four different clock sources can be used to drive the system clock (SYSCLK): • The HSI16 oscillator • The HSE oscillator • The PLL • The MSI oscillator clock (default after reset) When a clock source is used directly or through the PLL as system clock, it is not possible to stop it.
Reset and clock control (RCC) RM0367 If the HSE oscillator is used directly or indirectly as the system clock (indirectly means: it is used as PLL input clock, and the PLL clock is used as system clock), a detected failure causes a switch of the system clock and the disabling of the HSE oscillator.
RM0367 Reset and clock control (RCC) 7.2.13 Watchdog clock If the Independent watchdog (IWDG) is started by either hardware option or software access, the LSI oscillator is forced ON and cannot be disabled. After the LSI oscillator temporization, the clock is provided to the IWDG. If the IWDG was enabled by software, the LSI clock is disabled after system reset.
Reset and clock control (RCC) RM0367 The primary purpose of connecting the LSE to the channel 1 input capture is to be able to accurately measure the HSI16 and MSI system clocks (for this, either the HSI16 or MSI should be used as the system clock source). The number of HSI16 (MSI, respectively) clock counts between consecutive edges of the LSE signal provides a measure of the internal clock period.
RM0367 Reset and clock control (RCC) RCC registers Refer to Section 1.2 for a list of abbreviations used in register descriptions. 7.3.1 Clock control register (RCC_CR) Address offset: 0x00 System Reset value: 0b0000 0000 00XX 0X00 0000 0011 0000 0000 where X is undefined Power-on reset value: 0x0000 0300 Access: no wait state, word, half-word and byte access CSSHS...
Page 188
Reset and clock control (RCC) RM0367 Bit 18 HSEBYP: HSE clock bypass bit This bit is set and cleared by software to bypass the oscillator with an external clock. The external clock must be enabled with the HSEON bit, to be used by the device. The HSEBYP bit can be written only if the HSE oscillator is disabled.
Page 189
RM0367 Reset and clock control (RCC) Bit 2 HSI16RDYF: Internal high-speed clock ready flag This bit is set by hardware to indicate that the HSI 16 MHz oscillator is stable. After the HSI16ON bit is cleared, HSI16RDY goes low after 6 HSI16 clock cycles. 0: HSI 16 MHz oscillator not ready 1: HSI 16 MHz oscillator ready Bit 1 HSI16KERON: High-speed internal clock enable bit for some IP kernels...
Reset and clock control (RCC) RM0367 7.3.2 Internal clock sources calibration register (RCC_ICSCR) Address offset: 0x04 Reset value: 0x00XX B0XX where X is undefined. Access: no wait state, word, half-word and byte access MSITRIM[7:0] MSICAL[7:0] MSIRANGE[2:0] HSI16TRIM[4:0] HSI16CAL[7:0] Bits 31:24 MSITRIM[7:0]: MSI clock trimming These bits are set by software to adjust MSI calibration.
Reset and clock control (RCC) RM0367 7.3.4 Clock configuration register (RCC_CFGR) Address offset: 0x0C Reset value: 0x0000 0000 ≤ ≤ Access: 0 wait state 2, word, half-word and byte access 1 or 2 wait states inserted only if the access occurs during clock source switch. Res.
Page 193
RM0367 Reset and clock control (RCC) Bits 21:18 PLLMUL[3:0]: PLL multiplication factor These bits are written by software to define the PLL multiplication factor to generate the PLL VCO clock. These bits can be written only when the PLL is disabled. 0000: PLLVCO = PLL clock entry x 3 0001: PLLVCO = PLL clock entry x 4 0010: PLLVCO = PLL clock entry x 6...
Reset and clock control (RCC) RM0367 Bits 7:4 HPRE[3:0]: AHB prescaler These bits are set and cleared by software to control the division factor of the AHB clock. Caution: Depending on the device voltage range, the software has to set correctly these bits to ensure that the system frequency does not exceed the maximum allowed frequency (for more details please refer to the Dynamic voltage scaling management section in the PWR chapter.) After a write operation to these bits and before...
Page 195
RM0367 Reset and clock control (RCC) Bits 31:8 Reserved, must be kept at reset value. Bit 7 CSSLSE: LSE CSS interrupt flag This bit is set and reset by software to enable/disable the interrupt caused by the Clock Security System on external 32 kHz oscillator. 0: LSE CSS interrupt disabled 1: LSE CSS interrupt enabled Bit 6 HSI48RDYIE: HSI48 ready interrupt flag...
RM0367 Reset and clock control (RCC) Bit 2 HSI16RDYF: HSI16 ready interrupt flag This bit is reset by software by writing the HSI16RDYC bit. It is set by hardware when the HSE clock becomes stable and the HSI16RDYIE is set. 0: No clock ready interrupt caused by HSI16 clock failure 1: Clock ready interrupt caused by HSI16 clock failure Bit 1 LSERDYF: LSE ready interrupt flag...
Reset and clock control (RCC) RM0367 Bit 5 MSIRDYC: MSI ready Interrupt clear This bit is set by software to clear the MSIRDYF flag. It is reset by hardware. 0: No effect 1: MSIRDYF flag cleared Bit 4 PLLRDYC: PLL ready Interrupt clear This bit is set by software to clear the PLLRDYF flag.
RM0367 Reset and clock control (RCC) Bits 6:5 Reserved, must be kept at reset value. Bit 4 IOPERST: I/O port E reset This bit is set and cleared by software. 0: no effect 1: resets I/O port E Bit 3 IOPDRST: I/O port D reset This bit is set and cleared by software.
Reset and clock control (RCC) RM0367 Bits 19:17 Reserved, must be kept at reset value. Bit 16 TSCRST: Touch Sensing reset This bit is set and reset by software. 0: no effect 1: resets Touch sensing module Bits 15: 13 Reserved, must be kept at reset value. Bit 12 CRCRST: Test integration module reset This bit is set and reset by software.
RM0367 Reset and clock control (RCC) Bit 14 USART1RST: USART1 reset This bit is set and cleared by software. 0: No effect 1: Reset USART1 Bit 13 Reserved, must be kept at reset value. Bit 12 SPI1RST: SPI 1 reset This bit is set and cleared by software.
Page 202
Reset and clock control (RCC) RM0367 Bit 31 LPTIM1RST: Low-power timer reset This bit is set and cleared by software. 0: No effect 1: Resets low-power timer Bit 30 I2C3RST: I2C3 reset This bit is set and cleared by software. 0: No effect 1: Resets I2C3 Bit 29 DACRST: DAC interface reset...
Page 203
RM0367 Reset and clock control (RCC) Bit 17 USART2RST: USART2 reset This bit is set and cleared by software. 0: No effect 1: Resets USART2 Bits 16:15 Reserved, must be kept at reset value. Bit 14 SPI2RST: SPI2 reset This bit is set and cleared by software. 0: No effect 1: Resets SPI2 Bits 13:12 Reserved, must be kept at reset value.
RM0367 Reset and clock control (RCC) 7.3.13 AHB peripheral clock enable register (RCC_AHBENR) Address offset: 0x30 Reset value: 0x0000 0100 Access: no wait state, word, half-word and byte access When the peripheral clock is not active, the peripheral register values may not be readable by software and the returned value is always 0x0.
Page 206
Reset and clock control (RCC) RM0367 Bit 8 MIFEN: NVM interface clock enable bit This bit is set and reset by software. This reset can be activated only when the NVM is in power-down mode. 0: NVM interface clock disabled 1: NVM interface clock enabled Bits 7:1 Reserved, must be kept at reset value.
RM0367 Reset and clock control (RCC) 7.3.14 APB2 peripheral clock enable register (RCC_APB2ENR) Address: 0x34 Reset value: 0x0000 0000 Access: word, half-word and byte access No wait states, except if the access occurs while an access to a peripheral in the APB2 domain is on going.
Page 208
Reset and clock control (RCC) RM0367 Bit 6 Reserved, must be kept at reset value. Bit 5 TIM22EN: TIM22 timer clock enable bit This bit is set and cleared by software. 0:TIM22 clock disabled 1: TIM22 clock enabled Bits 4:3 Reserved, must be kept at reset value. Bit 2 TIM21EN: TIM21 timer clock enable bit This bit is set and cleared by software.
RM0367 Reset and clock control (RCC) 7.3.15 APB1 peripheral clock enable register (RCC_APB1ENR) Address: 0x38 Reset value: 0x0000 0000 Access: word, half-word and byte access No wait state, except if the access occurs while an access to a peripheral on APB1 domain is on going.
Page 210
Reset and clock control (RCC) RM0367 Bit 22 I2C2EN: I2C2 clock enable bit This bit is set and cleared by software. 0: I2C2 clock disabled 1: I2C2 clock enabled Bit 21 I2C1EN: I2C1 clock enable bit This bit is set and cleared by software. 0: I2C1 clock disabled 1: I2C1 clock enabled Bit 20 USART5EN: USART5 clock enable bit...
Page 211
RM0367 Reset and clock control (RCC) Bit 4 TIM6EN: Timer 6 clock enable bit Set and cleared by software. 0: Timer 6 clock disabled 1: Timer 6 clock enabled Bits 3:2 Reserved, must be kept at reset value. Bit 1 TIM3EN: Timer3 clock enable bit Set and cleared by software.
Reset and clock control (RCC) RM0367 7.3.16 GPIO clock enable in Sleep mode register (RCC_IOPSMENR) Address: 0x3C Reset value: the bits corresponding to the available GPIO ports are set Access: no wait state, word, half-word and byte access Res. Res. Res.
RM0367 Reset and clock control (RCC) 7.3.17 AHB peripheral clock enable in Sleep mode register (RCC_AHBSMENR) Address: 0x40 Reset value: the bits corresponding to the available peripherals are set Access: no wait state, word, half-word and byte access CRYP RNGS TSCSM Res.
Reset and clock control (RCC) RM0367 Bit 8 MIFSMEN: NVM interface clock enable during Sleep mode bit This bit is set and reset by software. 0: NVM interface clock disabled in Sleep mode 1: NVM interface clock enabled in Sleep mode Bits 7:1 Reserved, must be kept at reset value.
RM0367 Reset and clock control (RCC) Bits 8:6 Reserved, must be kept at reset value. Bit 5 TIM22SMEN: TIM22 timer clock enable during Sleep mode bit This bit is set and cleared by software. 0:TIM22 clock disabled in Sleep mode 1: TIM22 clock enabled in Sleep mode (if enabled by TIM22EN) Bits 4:3 Reserved, must be kept at reset value.
Page 216
Reset and clock control (RCC) RM0367 Bit 28 PWRSMEN: Power interface clock enable during Sleep mode bit This bit is set and cleared by software. 0: Power interface clock disabled in Sleep mode 1: Power interface clock enabled in Sleep mode (if enabled by PWREN) Bit 27 CRSSMEN: Clock recovery system clock enable during Sleep mode bit This bit is set and cleared by software.
RM0367 Reset and clock control (RCC) Bit 11 WWDGSMEN: Window watchdog clock enable during Sleep mode bit This bit is set and cleared by software. 0: Window watchdog clock disabled in Sleep mode 1: Window watchdog clock enabled in Sleep mode (if enabled by WWDGEN) Bit 10 Reserved, must be kept at reset value.
Page 218
Reset and clock control (RCC) RM0367 Bits 31:27 Reserved, must be kept at reset value. Bit26 HSI48SEL: 48 MHz HSI48 clock source selection bit This bit is set and cleared by software to select the HSI48 clock source for USB and RNG. 0: PLL USB clock selected as HSI48 clock 1: RC48 clock selected as HSI48 clock Bits 25:20 Reserved, must be kept at reset value.
RM0367 Reset and clock control (RCC) 7.3.21 Control/status register (RCC_CSR) Address: 0x50 Power-on reset value: 0x0C00 0000 ≤ ≤ Access: 0 wait state 3, word, half-word and byte access Wait states are inserted in case of successive accesses to this register. Note: The LSEON, LSEBYP, RTCSEL,LSEDRV and RTCEN bits in the RCC control and status register (RCC_CSR) are in the RTC domain.
Page 220
Reset and clock control (RCC) RM0367 Bit 26 PINRSTF: PIN reset flag This bit is set by hardware when a reset from the NRST pin occurs. It is cleared by writing to the RMVF bit, or by a POR. 0: No reset from NRST pin occurred 1: Reset from NRST pin occurred Bit 25 OBLRSTF Options bytes loading reset flag This bit is set by hardware when an OBL reset occurs.
Page 221
RM0367 Reset and clock control (RCC) Bit 14 CSSLSED: CSS on LSE failure detection flag This bit is set by hardware to indicate when a failure has been detected by the clock security system on the external 32 kHz oscillator (LSE). It is cleared by a power-on reset or by an RTC software reset (RTCRST bit).
Page 222
Reset and clock control (RCC) RM0367 Bits 7:3 Reserved, must be kept at reset value. Bit 1 LSIRDY: Internal low-speed oscillator ready bit This bit is set and cleared by hardware to indicate when the LSI oscillator is stable. After the LSION bit is cleared, LSIRDY goes low after 3 LSI oscillator clock cycles.
RM0367 Reset and clock control (RCC) 7.3.22 RCC register map The following table gives the RCC register map and the reset values. Table 42. RCC register map and reset values Off- Register RCC_CR 0x00 [1:0] Reset value X X 0 X 0 0 0 0 0 0 0 0 MSIRAN HSI16TRIM[4:0...
Page 224
Reset and clock control (RCC) RM0367 Table 42. RCC register map and reset values (continued) Off- Register RCC_APB2RSTR 0x24 Reset value RCC_APB1RSTR 0x28 Reset value 0 0 0 0 0 0 0 0 0 0 0 0 RCC_IOPENR 0x2C Reset value 0 0 0 0 0 RCC_AHBENR 0x30...
Page 225
RM0367 Reset and clock control (RCC) Table 42. RCC register map and reset values (continued) Off- Register RCC_APB1SMENR 0x48 Reset value 1 1 1 1 1 1 1 1 1 1 1 1 RCC_CCIPR 0x4C Reset value 0 0 0 0 0 0 0 0 RCC_CSR 0x50...
Clock recovery system (CRS) RM0367 Clock recovery system (CRS) 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) RM0367 8.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. It starts counting down till it reaches the zero value, where the ESYNC (expected synchronization) event is generated.
RM0367 Clock recovery system (CRS) 8.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 –...
Clock recovery system (CRS) RM0367 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...
RM0367 Clock recovery system (CRS) CRS registers Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions. The peripheral registers can be accessed only by words (32-bit). 8.7.1 CRS control register (CRS_CR) Address offset: 0x00 Reset value: 0x0000 2000 Res.
RM0367 Clock recovery system (CRS) 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 234
Clock recovery system (CRS) RM0367 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.
RM0367 General-purpose I/Os (GPIO) 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).
General-purpose I/Os (GPIO) RM0367 Figure 21 Figure 22 show the basic structures of a standard and a 5-Volt tolerant I/O port bit, respectively. Table 47 gives the possible port bit configurations. Figure 21. Basic structure of an I/O port bit Analog To on-chip peripheral...
RM0367 General-purpose I/Os (GPIO) Table 47. Port bit configuration table MODE(i) OSPEED(i) PUPD(i) OTYPER(i) I/O configuration [1:0] [1:0] [1:0] GP output GP output PP + PU GP output PP + PD Reserved SPEED [1:0] GP output GP output OD + PU GP output OD + PD Reserved (GP output OD)
General-purpose I/Os (GPIO) RM0367 When the pin is configured as output, the value written to the output data register (GPIOx_ODR) is output on the I/O pin. It is possible to use the output driver in push-pull mode or open-drain mode (only the low level is driven, high level is HI-Z). The input data register (GPIOx_IDR) captures the data present on the I/O pin at every AHB clock cycle.
RM0367 General-purpose I/Os (GPIO) 9.3.3 I/O port control registers Each of the GPIO ports has four 32-bit memory-mapped control registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR) to configure up to 16 I/Os. The GPIOx_MODER register is used to select the I/O mode (input, output, AF, analog). The GPIOx_OTYPER and GPIOx_OSPEEDR registers are used to select the output type (push- pull or open-drain) and speed.
General-purpose I/Os (GPIO) RM0367 The LOCK sequence (refer to Section 9.4.8: GPIO port configuration lock register (GPIOx_LCKR) (x = A to E and H)) can only be performed using a word (32-bit long) access to the GPIOx_LCKR register due to the fact that GPIOx_LCKR bit 16 has to be set at the same time as the [15:0] bits.
General-purpose I/Os (GPIO) RM0367 9.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.
General-purpose I/Os (GPIO) RM0367 9.4.4 GPIO port pull-up/pull-down register (GPIOx_PUPDR) (x = A to E and H) Address offset: 0x0C Reset value: 0x2400 0000 (for port A) Reset value: 0x0000 0000 (for the other ports) PUPD15[1:0] PUPD14[1:0] PUPD13[1:0] PUPD12[1:0] PUPD11[1:0] PUPD10[1:0] PUPD9[1:0] PUPD8[1:0]...
RM0367 General-purpose I/Os (GPIO) 9.4.6 GPIO port output data register (GPIOx_ODR) (x = A to E and H) Address offset: 0x14 Reset value: 0x0000 0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
Page 250
General-purpose I/Os (GPIO) RM0367 LOCK sequence has been applied on a port bit, the value of this port bit can no longer be modified until the next MCU reset or peripheral reset. Note: A specific write sequence is used to write to the GPIOx_LCKR register. Only word access (32-bit long) is allowed during this locking sequence.
RM0367 General-purpose I/Os (GPIO) 9.4.9 GPIO alternate function low register (GPIOx_AFRL) (x = A to E and H) Address offset: 0x20 Reset value: 0x0000 0000 AFSEL7[3:0] AFSEL6[3:0] AFSEL5[3:0] AFSEL4[3:0] AFSEL3[3:0] AFSEL2[3:0] AFSEL1[3:0] AFSEL0[3:0] Bits 31:0 AFSEL[7:0][3:0]: Alternate function selection for port x I/O pin y (y = 7 to 0) These bits are written by software to configure alternate function I/Os.
General-purpose I/Os (GPIO) RM0367 Bits 31:0 AFSEL[15:8][3:0]: Alternate function selection for port x I/O pin y (y = 15 to 8) These bits are written by software to configure alternate function I/Os. 0000: AF0 0001: AF1 0010: AF2 0011: AF3 0100: AF4 0101: AF5 0110: AF6...
EVENTOUT, during SEV instruction execution. In STM32L0x3 devices, an event input can be generated by an external interrupt line or by an RTC alarm interrupt. It is also possible to select which output pin is connected to the ®...
System configuration controller (SYSCFG) RM0367 10.2 SYSCFG registers The peripheral registers have to be accessed by words (32-bit). 10.2.1 SYSCFG memory remap register (SYSCFG_CFGR1) This register is used for specific configurations related to memory remap: Note: This register is not reset through the SYSCFGRST bit in the RCC_APB2RSTR register. Address offset: 0x00 Reset value: 0x000x 000x (X is the memory mode selected by the boot configuration).
Page 257
RM0367 System configuration controller (SYSCFG) Bit 3 UFB: User bank swapping This bit is available only on category 5 devices and reserved on other categories. It is set and cleared by software. It controls the Bank 1/2 mapping (see Table 8: NVM organization for UFB = 0 (128 Kbyte category 5 devices) Table 10: NVM organization for UFB = 0 (64 Kbyte category 5...
RM0367 System configuration controller (SYSCFG) Bits 7:4 Reserved, must be kept at reset value Bits 5:1 LCD_CAPA[4:0]: Decoupling capacitance connection (refer to the datasheet for details on the device capability) These bits are set and cleared by software. They control the connection of the internal V rails supply voltage to a dedicated I/O (LCD_VLCD1, LCD_VLCD2, LCD_VLCD3) to perform an optional decoupling.
Page 260
System configuration controller (SYSCFG) RM0367 Bit 31 REF_LOCK: SYSCFG_CFGR3 lock bit This bit is set by software and cleared by a hardware system reset. It locks the whole content of the reference control/Status register, SYSCFG_CFGR3[31:0]. 0: SYSCFG_CFGR3[31:0] bits are read/write 1: SYSCFG_CFGR3[31:0] bits are read-only Bit 30 VREFINT_RDYF: VREFINT ready flag This bit is read-only.
RM0367 System configuration controller (SYSCFG) Bits 5:4 SEL_VREF_OUT: VREFINT_ADC connection bit These bits are set and cleared by software (only if REF_LOCK not set). These bits select which pad is connected to VREFINT_ADC when ENBUF_VREFINT_ADC is set. 00: no pad connected 01: PB0 connected 10: PB1 connected 11: PB0 and PB1 connected...
RM0367 Direct memory access controller (DMA) Direct memory access controller (DMA) 11.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) RM0367 11.3 DMA implementation 11.3.1 DMA is implemented with the hardware configuration parameters shown in the table below. Table 50. DMA implementation Feature Number of channels 11.3.2 DMA request mapping DMA controller The hardware requests from the peripherals (TIM2/6, ADC, DAC, SPI1/2, I2C1/2, AES (available only on category 3 and 5 devices, with AES), USART1/2 and LPUART1) are mapped to the DMA channels through the DMA_CSELR channel selection registers (see Figure...
RM0367 Direct memory access controller (DMA) The DMA block diagram is shown in the figure below. Figure 28. DMA block diagram FLITF Flash System Cortex- SRAM Reset & Ch.1 Clock control Ch.2 (RCC) up to Bridge Ch.7 Arbiter AHB Slave DMA request SPI1/SPI2 USART1/2/4/5...
Direct memory access controller (DMA) RM0367 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.
RM0367 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 – •...
Direct memory access controller (DMA) RM0367 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.
RM0367 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) RM0367 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).
RM0367 Direct memory access controller (DMA) Table 52. 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) RM0367 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: •...
RM0367 Direct memory access controller (DMA) 11.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 278
Direct memory access controller (DMA) RM0367 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...
RM0367 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) RM0367 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 281
RM0367 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 282
Direct memory access controller (DMA) RM0367 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.
RM0367 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) RM0367 11.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.
Page 285
RM0367 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.
Direct memory access controller (DMA) RM0367 11.6.7 DMA channel selection register (DMA_CSELR) Address offset: 0xA8 Reset value: 0x0000 0000 This register is used to manage the mapping of DMA channels as detailed in Section 11.3.2: DMA request mapping. Res. Res. Res.
Page 287
RM0367 Direct memory access controller (DMA) Table 54. DMA register map and reset values (continued) Offset Register DMA_CNDTR1 NDTR[15:0] 0x00C Reset value DMA_CPAR1 PA[31:0] 0x010 Reset value DMA_CMAR1 MA[31:0] 0x014 Reset value 0x018 Reserved Reserved. DMA_CCR2 0x01C Reset value DMA_CNDTR2 NDTR[15:0] 0x020 Reset value...
Page 288
Direct memory access controller (DMA) RM0367 Table 54. DMA register map and reset values (continued) Offset Register DMA_CMAR5 MA[31:0] 0x064 Reset value 0x068 Reserved Reserved. DMA_CCR6 0x06C Reset value DMA_CNDTR6 NDTR[15:0] 0x070 Reset value DMA_CPAR6 PA[31:0] 0x074 Reset value DMA_CMAR6 MA[31:0] 0x078 Reset value...
The SysTick calibration value is fixed to 4000, which gives a reference time base of 1 ms with the SysTick clock set to 4 MHz (max HCLK/8). 12.3 Interrupt and exception vectors Table 55 is the vector table for STM32L0x3 devices. (1)(2) Table 55. List of vectors Type of Position...
Page 290
Nested vectored interrupt controller (NVIC) RM0367 (1)(2) Table 55. List of vectors (continued) Type of Position Priority Acronym Description Address priority settable WWDG Window Watchdog interrupt 0x0000_0040 PVD through EXTI Line detection settable 0x0000_0044 interrupt RTC global interrupt through settable EXTI17/19/20 line and LSE CSS 0x0000_0048 interrupt through EXTI 19 line...
Page 291
® 1. The grayed cells correspond to the Cortex -M0+ interrupts. 2. Refer to Table 1: STM32L0x3 memory density, to Table 2: Overview of features per category and to the device datasheets for the GPIO ports and peripherals available on your device. The memory area corresponding to unavailable GPIO ports or peripherals are reserved.
Extended interrupt and event controller (EXTI) RM0367 Extended interrupt and event controller (EXTI) 13.1 Introduction The extended interrupts and events controller (EXTI) manages the external and internal asynchronous events/interrupts and generates the event request to the CPU/interrupt controller plus a wake-up request to the power controller. The EXTI allows the management of up to 30 event lines which can wake up the device from Stop mode.
MSv32798V1 13.3.2 Wakeup event management The STM32L0x3 microcontrollers are able to handle external or internal events in order to wake up the core (WFE). The wakeup event can be generated by either: • enabling an interrupt in the peripheral control register but not in the NVIC, and enabling ®...
Extended interrupt and event controller (EXTI) RM0367 13.3.3 Peripherals asynchronous interrupts Some peripherals can generate events when the system is in Run mode or in Stop mode, thus allowing to wake up the system from Stop mode. To accomplish this, the peripheral generates both a synchronized (to the system clock, e.g. APB clock) and an asynchronous version of the event.
RM0367 Extended interrupt and event controller (EXTI) 13.4 EXTI interrupt/event line mapping In the STM32L0x3, 30 interrupt/event lines are available.The GPIOs are connected to 16 configurable interrupt/event lines as shown in Figure Figure 30. Extended interrupt/event GPIO mapping EXTI0[3:0] bits in SYSCFG_EXTICR1 register...
Extended interrupt and event controller (EXTI) RM0367 The 30 lines are connected as shown in Table 56: EXTI lines connections: Table 56. EXTI lines connections EXTI line Line source Line type 0-15 GPIO configurable configurable RTC alarm configurable USB wakeup event direct RTC tamper or timestamp or configurable...
RM0367 Extended interrupt and event controller (EXTI) 13.5 EXTI registers Refer to Section 1.2 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by words (32-bit). 13.5.1 EXTI interrupt mask register (EXTI_IMR) Address offset: 0x00 Reset value: 0x3F84 0000 Res.
Extended interrupt and event controller (EXTI) RM0367 Bits 31:30 Reserved, must be kept at reset value. Bits 29:28 EMx: Event mask on line x (x = 29 to 28) 0: Event request from Line x is masked 1: Event request from Line x is not masked Bit 27 Reserved, must be kept at reset value.
Extended interrupt and event controller (EXTI) RM0367 Bits 31:23 Reserved, must be kept at reset value. Bits 22:19 SWIx: Software interrupt on line x (x = 22 to 19) Writing a 1 to this bit when it is at 0 sets the corresponding pending bit in EXTI_PR. If the interrupt is enabled on this line in EXTI_IMR and EXTI_EMR, an interrupt request is generated.
Analog-to-digital converter (ADC) RM0367 Analog-to-digital converter (ADC) 14.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.
RM0367 Analog-to-digital converter (ADC) 14.2 ADC main features • High performance – 12-bit, 10-bit, 8-bit or 6-bit configurable resolution – ADC conversion time: 0.87 µs for 12-bit resolution (1.14 MHz), 0.81 µs conversion time for 10-bit resolution, faster conversion times can be obtained by lowering resolution.
Analog-to-digital converter (ADC) RM0367 14.3 ADC functional description Figure 31 shows the ADC block diagram and Table 58 gives the ADC pin description. Figure 31. ADC block diagram ADC V REF+ 1.65 to 3.6 V Analog supply SCANDIR up/ 1.8 to 3.6 V AREADY down EOSMP...
RM0367 Analog-to-digital converter (ADC) Table 59. 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...
Analog-to-digital converter (ADC) RM0367 regulator is in low-power mode (with the device operating in LPRun, LPSleep or Stop mode), the voltage reference is disabled and the ADC cannot be used anymore. The software must follow the procedure described below to manage the ADC in low-power mode: Make sure that the ADC is disabled (ADEN = 0).
RM0367 Analog-to-digital converter (ADC) The calibration factor is maintained in the following low-power modes: LPRun, LPSleep and Stop. It is still possible to save and restore the calibration factor by software to save time when re-starting the ADC (as long as temperature and voltage are stable during the ADC power down).
Analog-to-digital converter (ADC) RM0367 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. Figure 33.
RM0367 Analog-to-digital converter (ADC) Follow this procedure to disable the ADC: Check that ADSTART = 0 in the ADC_CR register to ensure that no conversion is ongoing. If required, stop any ongoing conversion by writing 1 to the ADSTP bit in the ADC_CR register and waiting until this bit is read at 0.
Analog-to-digital converter (ADC) RM0367 The input clock of the analog ADC can be selected between two different clock sources (see Figure 35: ADC clock scheme to see how the PCLK clock and the ADC asynchronous clock are enabled): The ADC clock can be a specific clock source, named “ADC asynchronous clock“ which is independent and asynchronous with the APB clock.
RM0367 Analog-to-digital converter (ADC) 14.3.6 ADC connectivity ADC inputs are connected to the external channels as well as internal sources as described Figure Figure 36. ADC connectivity STM32L0x3 Channel selection Fast channel ADC_IN0 ADC_IN1 ADC_IN2 ADC_IN3 Fast channel ADC_IN4 Fast channel...
Analog-to-digital converter (ADC) RM0367 14.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).
RM0367 Analog-to-digital converter (ADC) 14.3.9 Programmable sampling time (SMP) Before starting a conversion, the ADC needs to establish a direct connection between the voltage source to be measured and the embedded sampling capacitor of the ADC. This sampling time must be enough for the input voltage source to charge the sample and hold capacitor to the input voltage level.
Analog-to-digital converter (ADC) RM0367 14.3.11 Continuous conversion mode (CONT In continuous conversion mode, when a software or hardware trigger event occurs, the ADC performs a sequence of conversions, converting all the channels once and then automatically re-starts and continuously performs the same sequence of conversions. This mode is selected when CONT = 1 in the ADC_CFGR1 register.
RM0367 Analog-to-digital converter (ADC) the need for software having to set the ADSTART bit again and ensures the next trigger event is not missed. 14.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...
Analog-to-digital converter (ADC) RM0367 14.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).
RM0367 Analog-to-digital converter (ADC) Refer to Table 60: External triggers Section 14.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.
RM0367 Analog-to-digital converter (ADC) 14.5 Data management 14.5.1 Data register and data alignment (ADC_DR, ALIGN) At the end of each conversion (when an EOC event occurs), the result of the converted data is stored in the ADC_DR data register which is 16-bit wide. The format of the ADC_DR depends on the configured data alignment and resolution.
Analog-to-digital converter (ADC) RM0367 Figure 45. Example of overrun (OVR) ADSTART ADSTP TRGx ADC state CH0 STOP ADC_DR read OVERRUN access ADC_DR (OVRMOD=0) ADC_DR (OVRMOD=1) by S/W by H/W triggered MSv30343V3 14.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.
RM0367 Analog-to-digital converter (ADC) converted data from the ADC_DR register to the destination location selected by the software. Note: The DMAEN bit in the ADC_CFGR1 register must be set after the ADC calibration phase. Despite this, if an overrun occurs (OVR = 1) because the DMA could not serve the DMA transfer request in time, the ADC stops generating DMA requests and the data corresponding to the new conversion is not transferred by the DMA.
Analog-to-digital converter (ADC) RM0367 14.6 Low-power features 14.6.1 Wait mode conversion Wait mode conversion can be used to simplify the software as well as optimizing the performance of applications clocked at low frequency where there might be a risk of ADC overrun occurring.
RM0367 Analog-to-digital converter (ADC) 14.6.2 Auto-off mode (AUTOFF) The ADC has an automatic power management feature which is called auto-off mode, and is enabled by setting AUTOFF = 1 in the ADC_CFGR1 register. When AUTOFF = 1, the ADC is always powered off when not converting and automatically wakes-up when a conversion is started (by software or hardware trigger).
RM0367 Analog-to-digital converter (ADC) Table 64. Analog watchdog comparison Analog Watchdog comparison between: Resolution bits Comments Raw converted Thresholds RES[1:0] data, left aligned 00: 12-bit DATA[11:0] LT[11:0] and HT[11:0] 01: 10-bit DATA[11:2],00 LT[11:0] and HT[11:0] The user must configure LT1[1:0] and HT1[1:0] to “00” The user must configure LT1[3:0] and HT1[3:0] to 10: 8-bit DATA[11:4],0000...
Analog-to-digital converter (ADC) RM0367 ADC_AWD1_OUT is activated when the analog watchdog is enabled: • ADC_AWD1_OUT is set when a guarded conversion is outside the programmed thresholds. • ADC_AWD1_OUT is reset after the end of the next guarded conversion which is inside the programmed thresholds.
Analog-to-digital converter (ADC) RM0367 Figure 53. Analog watchdog threshold update ADC state Conversion Conversion Conversion Conversion Threshould updated LT, HT XXXX XXXY XXXZ Masked Active Active Comparison MSv65329V1 14.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.
RM0367 Analog-to-digital converter (ADC) Figure 54. 20-bit to 16-bit result truncation Raw 20-bit data Shifting Truncation and rounding MS31928V2 Figure 55 gives a numerical example of the processing, from a raw 20-bit accumulated data to the final 16-bit result. Figure 55. Numerical example with 5-bits shift and rounding Raw 20-bit data: Final result after 5-bits shift and rounding to nearest...
Analog-to-digital converter (ADC) RM0367 sequence. New data are provided every N conversion, with an equivalent delay equal to N x = N x (t ). The flags features are raised as following: CONV SMPL • the end of the sampling phase (EOSMP) is set after each sampling phase •...
ADC V [17] 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. It is accessible in read-only mode. Figure 57 shows the block diagram of connections between the temperature sensor, the internal voltage reference and the ADC.
Analog-to-digital converter (ADC) RM0367 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 V SENSE Temperature ADC V [18] sensor converted...
RM0367 Analog-to-digital converter (ADC) Note: The sensor has a startup time after waking from power down mode before it can output at the correct level. The ADC also has a startup time after power-on, so to minimize SENSE the delay, the ADEN and TSEN bits should be set at the same time. Calculating the actual V voltage using the internal reference voltage The V...
Analog-to-digital converter (ADC) RM0367 14.10 voltage monitoring The VLCDEN bit in the ADC_CCR register allows to measure the LCD supply voltage on the VLCD pin. As the V voltage can be higher than V , to ensure the correct operation of the ADC, the VLCD pin is internally connected to a bridge divider.
RM0367 Analog-to-digital converter (ADC) 14.12 ADC registers Refer to Section 1.2 for a list of abbreviations used in register descriptions. 14.12.1 ADC interrupt and status register (ADC_ISR) Address offset: 0x00 Reset value: 0x0000 0000 Res. Res. Res. Res. Res. Res. Res.
Analog-to-digital converter (ADC) RM0367 Bit 2 EOC: End of conversion flag This bit is set by hardware at the end of each conversion of a channel when a new data result is available in the ADC_DR register. It is cleared by software writing 1 to it or by reading the ADC_DR register.
Page 339
RM0367 Analog-to-digital converter (ADC) Bit 7 AWDIE: Analog watchdog interrupt enable This bit is set and cleared by software to enable/disable the analog watchdog interrupt. 0: Analog watchdog interrupt disabled 1: Analog watchdog interrupt enabled 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 341
RM0367 Analog-to-digital converter (ADC) 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 343
RM0367 Analog-to-digital converter (ADC) Bit 16 DISCEN: Discontinuous mode This bit is set and cleared by software to enable/disable discontinuous mode. 0: Discontinuous mode disabled 1: Discontinuous mode enabled Note: It is not possible to have both discontinuous mode and continuous mode enabled: it is forbidden to set both bits DISCEN = 1 and CONT = 1.
Page 344
Analog-to-digital converter (ADC) RM0367 Bits 8:6 EXTSEL[2:0]: External trigger selection These bits select the external event used to trigger the start of conversion (refer to Table 60: External triggers for details): 000: TRG0 001: TRG1 010: TRG2 011: TRG3 100: TRG4 101: TRG5 110: TRG6 111: TRG7...
Page 345
RM0367 Analog-to-digital converter (ADC) 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. 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 ensures that no conversion is ongoing).
RM0367 Analog-to-digital converter (ADC) Bits 4:2 OVSR[2:0]: Oversampling ratio This bit filed defines the number of oversampling ratio. 000: 2x 001: 4x 010: 8x 011: 16x 100: 32x 101: 64x 110: 128x 111: 256x Note: The software is allowed to write this bit only when ADSTART = 0 (which ensures that no conversion is ongoing).
Analog-to-digital converter (ADC) RM0367 14.12.7 ADC watchdog threshold register (ADC_TR) Address offset: 0x20 Reset value: 0x0FFF 0000 Res. Res. Res. Res. HT[11:0] Res. Res. Res. Res. LT[11:0] Bits 31:28 Reserved, must be kept at reset value. Bits 27:16 HT[11:0]: Analog watchdog higher threshold These bits are written by software to define the higher threshold for the analog watchdog.
RM0367 Analog-to-digital converter (ADC) Bits 31:19 Reserved, must be kept at reset value. Bits 18:0 CHSELx: Channel-x selection These bits are written by software and define which channels are part of the sequence of channels to be converted. Refer to Figure 36: ADC connectivity for ADC inputs connected to external channels and internal sources.
Analog-to-digital converter (ADC) RM0367 Bits 31:7 Reserved, must be kept at reset value. Bits 6:0 CALFACT[6:0]: Calibration factor These bits are written by hardware or by software. – Once a single-ended inputs calibration is complete, they are updated by hardware with the calibration factors.
RM0367 Analog-to-digital converter (ADC) Bit 22 VREFEN: V enable REFINT This bit is set and cleared by software to enable/disable the V REFINT 0: V disabled REFINT 1: V enabled REFINT Note: Software is allowed to write this bit only when ADSTART = 0 (which ensures that no conversion is ongoing).
Page 352
Analog-to-digital converter (ADC) RM0367 Table 68. ADC register map and reset values (continued) Offset Register ADC_CFGR2 0x10 Reset value ADC_SMPR [2:0] 0x14 Reset value 0x18 Reserved Reserved 0x1C Reserved Reserved ADC_TR HT[11:0] LT[11:0] 0x20 Reset value 0x24 Reserved Reserved ADC_CHSELR 0x28 Reset value 0x2C...
RM0367 Digital-to-analog converter (DAC) Digital-to-analog converter (DAC) 15.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.
RM0367 Digital-to-analog converter (DAC) 15.3 DAC output buffer enable The DAC integrates two output buffers that can be used to reduce the output impedance and to drive external loads directly without having to add an external operational amplifier. The DAC channel output buffer can be enabled and disabled through the BOFF1 bit in the DAC_CR register.
Digital-to-analog converter (DAC) RM0367 register is reset). However, when a hardware trigger is selected (TENx bit in DAC_CR register is set) and a trigger occurs, the transfer is performed three PCLK1 clock cycles later. When DAC_DORx is loaded with the DAC_DHRx contents, the analog output voltage becomes available after a time t that depends on the power supply voltage and the SETTLING...
RM0367 Digital-to-analog converter (DAC) For code example, refer to A.9.2: Independent trigger with single triangle generation code example. 15.5.3 DAC output voltage Digital inputs are converted to output voltages on a linear conversion between 0 and V REF+ The analog output voltages on each DAC channel pin are determined by the following equation: ×...
Digital-to-analog converter (DAC) RM0367 15.6 Dual-mode functional description 15.6.1 DAC data format In Dual DAC channel mode, there are three possibilities: • 8-bit right alignment: data for DAC channel1 to be loaded in the DAC_DHR8RD [7:0] bits (stored in the DHR1[11:4] bits) and data for DAC channel2 to be loaded in the DAC_DHR8RD [15:8] bits (stored in the DHR2[11:4] bits) •...
RM0367 Digital-to-analog converter (DAC) Independent trigger without wave generation To configure the DAC in this conversion mode, the following sequence is required: Set the two DAC channel trigger enable bits TEN1 and TEN2 Configure different trigger sources by setting different values in the TSEL1[2:0] and TSEL2[2:0] bits Load the dual DAC channel data into the desired DHR register (DAC_DHR12RD, DAC_DHR12LD or DAC_DHR8RD)
Digital-to-analog converter (DAC) RM0367 Independent trigger with single triangle generation To configure the DAC in this conversion mode (refer to Section 15.8: Triangle-wave generation), the following sequence is required: Set the DAC channelx trigger enable TENx bits. Configure different trigger sources by setting different values in the TSELx[2:0] bits Configure the DAC channelx WAVEx[1:0] bits as “1x”...
RM0367 Digital-to-analog converter (DAC) Simultaneous trigger with single LFSR generation To configure the DAC in this conversion mode (refer to Section 15.7: Noise generation), the following sequence is required: Set the two DAC channel trigger enable bits TEN1 and TEN2 Configure the same trigger source for both DAC channels by setting the same value in the TSEL1[2:0] and TSEL2[2:0] bits Configure the two DAC channel WAVEx[1:0] bits as “01”...
Digital-to-analog converter (DAC) RM0367 Simultaneous trigger with different triangle generation To configure the DAC in this conversion mode ‘refer to Section 15.8: Triangle-wave generation), the following sequence is required: Set the DAC channelx trigger enable TENx bits. Configure the same trigger source for DAC channelx by setting the same value in the TSELx[2:0] bits Configure the DAC channelx WAVEx[1:0] bits as “1x”...
RM0367 Digital-to-analog converter (DAC) It is possible to reset LFSR wave generation by resetting the WAVEx[1:0] bits. Figure 63. DAC conversion (SW trigger enabled) with LFSR wave generation APB1_CLK 0x00 0xD55 0xAAA SWTRIG ai14714b Note: The DAC trigger must be enabled for noise generation by setting the TENx bit in the DAC_CR register.
Digital-to-analog converter (DAC) RM0367 Figure 65. DAC conversion (SW trigger enabled) with triangle wave generation APB1_CLK 0xABE 0xABE 0xABF 0xAC0 SWTRIG ai14716b Note: The DAC trigger must be enabled for triangle generation by setting the TENx bit in the DAC_CR register. The MAMPx[3:0] bits must be configured before enabling the DAC, otherwise they cannot be changed.
RM0367 Digital-to-analog converter (DAC) 15.10 DAC registers Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by words (32-bit). 15.10.1 DAC control register (DAC_CR) Address offset: 0x00 Reset value: 0x0000 0000 DMAU Res.
Page 366
Digital-to-analog converter (DAC) RM0367 Bits 23:22 WAVE2[1:0]: DAC channel2 noise/triangle wave generation enable These bits are set/reset by software. 00: wave generation disabled 01: Noise wave generation enabled 1x: Triangle wave generation enabled Note: Only used if bit TEN2 = 1 (DAC channel2 trigger enabled) These bits are available only in dual mode when wave generation is supported.
Page 367
RM0367 Digital-to-analog converter (DAC) Bit 12 DMAEN1: DAC channel1 DMA enable This bit is set and cleared by software. 0: DAC channel1 DMA mode disabled 1: DAC channel1 DMA mode enabled Bits 11:8 MAMP1[3:0]: DAC channel1 mask/amplitude selector These bits are written by software to select mask in wave generation mode or amplitude in triangle generation mode.
Page 368
Digital-to-analog converter (DAC) RM0367 Bit 2 TEN1: DAC channel1 trigger enable This bit is set and cleared by software to enable/disable DAC channel1 trigger. 0: DAC channel1 trigger disabled and data written into the DAC_DHRx register are transferred one APB1 clock cycle later to the DAC_DOR1 register 1: DAC channel1 trigger enabled and data from the DAC_DHRx register are transferred three APB1 clock cycles later to the DAC_DOR1 register Note: When software trigger is selected, the transfer from the DAC_DHRx register to the...
RM0367 Digital-to-analog converter (DAC) Bits 31:12 Reserved, must be kept at reset value. Bits 11:0 DACC2DHR[11:0]: DAC channel2 12-bit right-aligned data These bits are written by software which specifies 12-bit data for DAC channel2. 15.10.7 DAC channel2 12-bit left-aligned data holding register (DAC_DHR12L2) Address offset: 0x18 Reset value: 0x0000 0000...
Digital-to-analog converter (DAC) RM0367 15.10.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.
RM0367 Digital-to-analog converter (DAC) DACC2DHR[7:0] DACC1DHR[7:0] Bits 31:16 Reserved, must be kept at reset value. Bits 15:8 DACC2DHR[7:0]: DAC channel2 8-bit right-aligned data These bits are written by software which specifies 8-bit data for DAC channel2. Bits 7:0 DACC1DHR[7:0]: DAC channel1 8-bit right-aligned data These bits are written by software which specifies 8-bit data for DAC channel1.
Page 374
Digital-to-analog converter (DAC) RM0367 Res. Res. DMAUDR2 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. rc_w1 Res. Res. DMAUDR1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. rc_w1 Bits 31:30 Reserved, must be kept at reset value. Bit 29 DMAUDR2: DAC channel2 DMA underrun flag This bit is set by hardware and cleared by software (by writing it to 1).
Comparator (COMP) 16.1 Introduction STM32L0x3 devices embed two ultra-low-power comparators COMP1, and COMP2 that can be used either as standalone devices (all terminal are available on I/Os) or combined with the timers. The comparators can be used for a variety of functions including: •...
RM0367 Comparator (COMP) 16.3.3 COMP reset and clocks The COMP clock provided by the clock controller is synchronous with the PCLK (APB clock). There is no clock enable control bit provided in the RCC controller. Reset and clock enable bits are common for COMP and SYSCFG. Important: The polarity selection logic and the output redirection to the port works independently from the PCLK clock.
Page 380
Comparator (COMP) RM0367 COMP1 COMP1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. LOCK VALUE COMP1 COMP1 COMP1 COMP1INN COMP1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. POLARITY LPTIMIN1 Bit 31 COMP1LOCK: COMP1_CSR register lock bit This bit is set by software and cleared by a hardware system reset.
RM0367 Comparator (COMP) Bits 5:4 COMP1INNSEL: Comparator 1 Input Minus connection configuration bit These bits are set and cleared by software (only if COMP1LOCK not set). They select which input is connected with the Input Minus of comparator 1 00: VREFINT 01: PA0 10: DAC1/PA4 11: DAC2/PA5...
Page 382
Comparator (COMP) RM0367 Bit 13 COMP2LPTIMIN1: Comparator 2 LPTIM input 1 propagation bit This bit is set and cleared by software (assuming COMP2LOCK not set). It sends COMP2VALUE to LPTIM input 1. 0: Comparator 2 output gated 1: Comparator 2 output sent to LPTIM input 1 Note: COMP2LPTIMIN1 and COMP2LPTIMIN2 cannot both be set to ‘1’.
RM0367 Comparator (COMP) 16.5.3 COMP register map The following table summarizes the comparator registers. The comparator registers share SYSCFG peripheral register base addresses. Table 72. COMP register map and reset values Offset Register COMP1_CSR 0x18 Reset value COMP2_CSR 0x1C Reset value Refer to Section 2.2 on page 58 for the register boundary addresses.
Liquid crystal display controller (LCD) RM0367 Liquid crystal display controller (LCD) 17.1 Introduction The LCD controller is a digital controller/driver for monochrome passive liquid crystal display (LCD) with up to 8 common terminals and up to 52 segment terminals to drive 208 (4x52) or 384 (8x48) LCD picture elements (pixels).
RM0367 Liquid crystal display controller (LCD) 17.2 LCD main features • Highly flexible frame rate control. • Supports Static, 1/2, 1/3, 1/4 and 1/8 duty. • Supports Static, 1/2, 1/3 and 1/4 bias. • Double buffered memory allows data in LCD_RAM registers to be updated at any time by the application firmware without affecting the integrity of the data displayed.
RM0367 Liquid crystal display controller (LCD) The frequency generator allows you to achieve various LCD frame rates starting from an LCD input clock frequency (LCDCLK) which can vary from 32 kHz up to 1 MHz. 3 different clock sources can be used to provide the LCD clock (LCDCLK/RTCCLK): •...
Liquid crystal display controller (LCD) RM0367 Table 74. Example of frame rate calculation (continued) LCDCLK PS[3:0] DIV[3:0] Ratio Duty frame 1.00 MHz 2432 102.80 Hz 1.00 MHz 3328 100.16 Hz 1.00 MHz 4864 102.80 Hz 1.00 MHz 9728 static 102.80 Hz The frame frequency must be selected to be within a range of around ~30 Hz to ~100 Hz and is a compromise between power consumption and the acceptable refresh rate.
RM0367 Liquid crystal display controller (LCD) Figure 68. 1/3 bias, 1/4 duty Odd frame Even frame 2/3 V 1/3 V Com active Com inactive Com inactive Com inactive Com active Com inactive Com inactive Com inactive 2/3 V 1/3 V Com active Com active Com inactive Com inactive...
Liquid crystal display controller (LCD) RM0367 Figure 69. Static duty case 1 Odd frame Even frame Odd frame Even frame COM0 SEG0 SEG1 COM0 SEG0 COM0 SEG1 MS33439V1 In each frame there is only one phase, this is why f is equal to f .
RM0367 Liquid crystal display controller (LCD) In this mode, the segment terminals are multiplexed and each of them control four pixels. A pixel is activated only when both of its corresponding SEG and COM lines are active in the same phase. In case of 1/4 duty, to deactivate pixel 0 connected to COM[0] the SEG[0] needs to be inactive during the phase 0 when COM[0] is active.
Liquid crystal display controller (LCD) RM0367 The SEG[n] pin is driven to V in phase 0 of the even frame. If pixel n is inactive then the SEG[n] pin is driven to 2/3 (2/4) V in the odd frame or 1/3 (2/4) V in the even frame (current inversion in V pad) (see...
RM0367 Liquid crystal display controller (LCD) Figure 73. 1/4 duty, 1/3 bias 3/3 V 2/3 V COM0 1/3 V Liquid crystal display 0/3 V and terminal connection 3/3 V COM3 2/3 V COM1 1/3 V 0/3 V COM2 3/3 V 2/3 V COM2 COM1...
Liquid crystal display controller (LCD) RM0367 Figure 74. 1/8 duty, 1/4 bias Liquid crystal display 4/4 V and terminal connection 3/4 V COM0 2/4 V COM7 1/4 V 0/4 V COM5 COM6 4/4 V 3/4 V COM4 COM1 2/4 V COM3 COM1 1/4 V...
RM0367 Liquid crystal display controller (LCD) Blink The segment driver also implements a programmable blink feature to allow some pixels to continuously switch on at a specific frequency. The blink mode can be configured by the BLINK[1:0] bits in the LCD_FCR register, making possible to blink up to 1, 2, 4, 8 or all pixels (see Section 17.7.2: LCD frame control register (LCD_FCR)).
Liquid crystal display controller (LCD) RM0367 LCD intermediate voltages The LCD intermediate voltage levels are generated through an internal resistor divider network as shown in Figure The LCD voltage generator issues intermediate voltage levels between V and V • 1/3 V and 2/3 V in case of 1/3 bias •...
RM0367 Liquid crystal display controller (LCD) Figure 75. LCD voltage control 3/4 x V LCDRail3 2/3 x V LCDRail2 1/2 x V 1/3 x V LCDRail1 1/4 x V BIAS[1] STATIC MS33422V2 1. R and R are the low value resistance network and the high value resistance network, respectively. The R divider can be always switched on using the HD bit in the LCD_FCR configuration register (see...
Liquid crystal display controller (LCD) RM0367 External decoupling Devices with V rails decoupling capability (see device datasheets) allow adding decoupling capacitors on the VLCD intermediate voltage rails that available on LCD_VLCD1, LCD_VLCD2 and LCD_VLCD3 for stabilization purpose (see Figure 75). Spikes might be observed when the voltage applied to the pixel is alternating.
RM0367 Liquid crystal display controller (LCD) 17.4.6 Double buffer memory Using its double buffer memory the LCD controller ensures the coherency of the displayed information without having to use interrupts to control LCD_RAM modification. The application software can access the first buffer level (LCD_RAM) through the APB interface.
Liquid crystal display controller (LCD) RM0367 Summary of COM and SEG functions versus duty and remap All the possible ways of multiplexing the COM and SEG functions are described in Table Figure 77 gives examples showing the signal connections to the external pins. Table 77.
Page 401
RM0367 Liquid crystal display controller (LCD) Table 77. Remapping capability (continued) Configuration bits QFP64/ BGA100/ BGA64 Output pin Function LQFP100 DUTY MUX_SEG COM3 not used COM[2:0] COM[2:0] 52x3 SEG[51:48]/SEG[31:28]/COM[7:4] SEG[51:48] SEG[47:0] SEG[47:0] COM3 not used COM[2:0] COM[2:0] SEG[51:48]/SEG[31:28]/COM[7:4] SEG[31:28] 48x3 SEG[47:32] SEG[47:32] SEG[31:28]...
Page 402
Liquid crystal display controller (LCD) RM0367 Table 77. Remapping capability (continued) Configuration bits QFP64/ BGA100/ BGA64 Output pin Function LQFP100 DUTY MUX_SEG COM[3:2] not used COM[1:0] COM[1:0] 28x2 SEG[51:48]/SEG[31:28]/COM[7:4] not used SEG[27:0] SEG[27:0] COM[3:2] not used COM[1:0] COM[1:0] 32x2 SEG[51:48]/SEG[31:28]/COM[7:4] SEG[31:28] SEG[27:0] SEG[27:0]...
Liquid crystal display controller (LCD) RM0367 17.4.8 Flowchart Figure 78. Flowchart example START INIT - Enable the GPIO port clocks - Configure the LCD GPIO pins as alternate functions - Configure LCD controller according to the Display to be driven: - Load the initial data to be displayed into LCD_RAM and set the UDR bit in the LCD_SR register...
RM0367 Liquid crystal display controller (LCD) 17.5 LCD low-power modes the LCD controller can be displayed in Stop mode or can be fully disabled to reduce power consumption. Table 78. LCD behavior in low-power modes Mode Description Stop The LCD is still active Standby The LCD is not active 17.6...
RM0367 Liquid crystal display controller (LCD) Note: The VSEL, MUX_SEG,BIAS, and DUTY bits are write-protected when the LCD is enabled (ENS bit in LCD_SR to 1). 17.7.2 LCD frame control register (LCD_FCR) Address offset: 0x04 Reset value: 0x0000 0000 Res. Res.
Page 408
Liquid crystal display controller (LCD) RM0367 Bits 12:10 CC[2:0]: Contrast control These bits specify one of the V maximum voltages (independent of V ). It ranges from 2.60 V to 3.51V. 000: V LCD0 001: V LCD1 010: V LCD2 011: V LCD3 100: V...
RM0367 Liquid crystal display controller (LCD) Bit 2 Reserved, must be kept at reset value Bit 1 SOFIE: Start of frame interrupt enable This bit is set and cleared by software. 0: LCD Start of Frame interrupt disabled 1: LCD Start of Frame interrupt enabled Bit 0 HD: High drive enable This bit is written by software to enable a low resistance divider.
Liquid crystal display controller (LCD) RM0367 Bit 3 UDD: Update Display Done This bit is set by hardware. It is cleared by writing 1 to the UDDC bit in the LCD_CLR register. The bit set has priority over the clear. 0: No event 1: Update Display Request done.
RM0367 Liquid crystal display controller (LCD) Bits 31:4 Reserved, must be kept at reset value Bit 3 UDDC: Update display done clear This bit is written by software to clear the UDD flag in the LCD_SR register. 0: No effect 1: Clear UDD flag Bit 2 Reserved, must be kept at reset value Bit 1 SOFC: Start of frame flag clear...
Touch sensing controller (TSC) RM0367 Touch sensing controller (TSC) 18.1 Introduction The touch sensing controller provides a simple solution for adding capacitive sensing functionality to any application. Capacitive sensing technology is able to detect finger presence near an electrode that is protected from direct touch by a dielectric (for example glass, plastic).
Touch sensing controller (TSC) RM0367 Figure 80. Surface charge transfer analog I/O group structure Analog I/O group Electrode 1 Gx_IO1 Gx_IO2 Electrode 2 Gx_IO3 Electrode 3 Gx_IO4 MSv30930V2 Note: Gx_IOy where x is the analog I/O group number and y the GPIO number within the selected group.
RM0367 Touch sensing controller (TSC) Table 81. Acquisition sequence summary Gx_IO1 Gx_IO2 Gx_IO3 Gx_IO4 State State description (channel) (sampling) (channel) (channel) Output open- Input floating drain low with Input floating with analog switch Discharge all C with analog analog switch closed switch closed closed...
Touch sensing controller (TSC) RM0367 The Reset and Clock Controller (RCC) provides dedicated bits to enable the touch sensing controller clock and to reset this peripheral. For more information, refer to Section 7: Reset and clock control (RCC). 18.3.4 Charge transfer acquisition sequence An example of a charge transfer acquisition sequence is detailed in Figure Figure 82.
RM0367 Touch sensing controller (TSC) 18.3.5 Spread spectrum feature The spread spectrum feature allows to generate a variation of the charge transfer frequency. This is done to improve the robustness of the charge transfer acquisition in noisy environments and also to reduce the induced emission. The maximum frequency variation is in the range of 10% to 50% of the nominal charge transfer period.
Touch sensing controller (TSC) RM0367 18.3.7 Sampling capacitor I/O and channel I/O mode selection To allow the GPIOs to be controlled by the touch sensing controller, the corresponding alternate function must be enabled through the standard GPIO registers and the GPIOxAFR registers.
RM0367 Touch sensing controller (TSC) 18.3.8 Acquisition mode The touch sensing controller offers two acquisition modes: • Normal acquisition mode: the acquisition starts as soon as the START bit in the TSC_CR register is set. • Synchronized acquisition mode: the acquisition is enabled by setting the START bit in the TSC_CR register but only starts upon the detection of a falling edge or a rising edge and high level on the SYNC input pin.
Touch sensing controller (TSC) RM0367 18.4 TSC low-power modes Table 84. Effect of low-power modes on TSC Mode Description No effect Sleep TSC interrupts cause the device to exit Sleep mode. Stop TSC registers are frozen The TSC stops its operation until the Stop or Standby mode is exited. Standby 18.5 TSC interrupts...
RM0367 Touch sensing controller (TSC) 18.6 TSC registers Refer to Section 1.2 on page 52 of the reference manual for a list of abbreviations used in register descriptions. The peripheral registers can be accessed by words (32-bit). 18.6.1 TSC control register (TSC_CR) Address offset: 0x00 Reset value: 0x0000 0000 CTPH[3:0]...
Page 424
Touch sensing controller (TSC) RM0367 Bit 16 SSE: Spread spectrum enable This bit is set and cleared by software to enable/disable the spread spectrum feature. 0: Spread spectrum disabled 1: Spread spectrum enabled Note: This bit must not be modified when an acquisition is ongoing. Bit 15 SSPSC: Spread spectrum prescaler This bit is set and cleared by software.
RM0367 Touch sensing controller (TSC) Bit 2 AM: Acquisition mode This bit is set and cleared by software to select the acquisition mode. 0: Normal acquisition mode (acquisition starts as soon as START bit is set) 1: Synchronized acquisition mode (acquisition starts if START bit is set and when the selected signal is detected on the SYNC input pin) Note: This bit must not be modified when an acquisition is ongoing.
RM0367 AES hardware accelerator (AES) AES hardware accelerator (AES) 19.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. Multiple chaining modes are supported (ECB, CBC, CTR), for key size of 128 bits.
RM0367 AES hardware accelerator (AES) 19.4.3 AES cryptographic core Overview The AES cryptographic core consists of the following components: • AES algorithm (AEA) • key input • initialization vector (IV) input The AES core works on 128-bit data blocks (four words) with 128-bit key length. Depending on the chaining mode, the AES requires zero or one 96-bit initialization vector IV (and a 32- bit counter field).
AES hardware accelerator (AES) RM0367 Note: The chaining mode may be changed only when AES is disabled (bit EN of the AES_CR register set). Principle of each AES chaining mode is provided in the following subsections. Detailed information is in dedicated sections, starting from Section 19.4.8: AES basic chaining modes (ECB, CBC).
AES algorithm. AES accelerates the execution of the AES-128 cryptographic algorithm in ECB, CBC, and CTR operating modes. Note: For more details on the cryptographic library, refer to the UM1924 user manual “STM32 crypto library” available from www.st.com. 438/1043 RM0367 Rev 7...
RM0367 AES hardware accelerator (AES) Figure 88. STM32 cryptolib AES flowchart example Encryption Decryption Begin Begin AES_x encrypt init AES_x decrypt init Error status Error status success success AES_x encrypt AES_x decrypt append append Data to append Data to append Error status Error status success...
Page 440
AES hardware accelerator (AES) RM0367 For ECB or CBC mode, refer to Section 19.4.6: AES ciphertext stealing and data padding. The second-last and the last block management in these cases is more complex than in the sequence described in this section. Data append through polling This method uses flag polling to control the data append.
RM0367 AES hardware accelerator (AES) Prepare the last four-word data block (if the data to process does not fill it completely), by padding the remainder of the block with zeros. Configure the DMA controller so as to transfer the data to process from the memory to the AES peripheral input and the processed data from the AES peripheral output to the memory, as described in Section 19.4.13: AES DMA...
AES hardware accelerator (AES) RM0367 output data block Cx. The ECB encryption continues in this way until the last complete plaintext block is encrypted. Figure 92 illustrates the electronic codebook (ECB) decryption. Figure 92. ECB decryption Block 1 Block 2 AES_DINR (ciphertext C1) AES_DINR (ciphertext C2) Swap...
RM0367 AES hardware accelerator (AES) second-block plaintext data P2’ to produce the I2 input data for the AES core to produce the second block of ciphertext data. The chaining of data blocks continues in this way until the last plaintext block in the message is encrypted. If the message size is not a multiple of 128 bits, the final partial data block is encrypted in the way explained in Section 19.4.6: AES ciphertext stealing and data...
AES hardware accelerator (AES) RM0367 ECB/CBC encryption sequence The sequence of events to perform an ECB/CBC encryption (more detail in Section 19.4.4): Disable the AES peripheral by clearing the EN bit of the AES_CR register. Select the Mode 1 by to 00 the MODE[1:0] bitfield of the AES_CR register and select ECB or CBC chaining mode by setting the CHMOD[1:0] bitfield of the AES_CR register to 00 or 01, respectively.
RM0367 AES hardware accelerator (AES) Repeat steps 6,7,8 to process all the blocks encrypted with the same key. Figure 96. ECB/CBC decryption (Mode 3) Wait until flag CCF = 1 Input phase Computation phase Output phase 4 write operations into 4 read operations from AES_DINR[31:0] AES_DOUTR[31:0]...
AES hardware accelerator (AES) RM0367 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 the AES_CR and AES_KEYRx register setting, using the values of the saved configuration.
RM0367 AES hardware accelerator (AES) Figure 97. 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: –...
RM0367 AES hardware accelerator (AES) The sequence of events to perform an encryption or a decryption in CTR chaining mode: Ensure that AES is disabled (the EN bit of the AES_CR must be 0). Select CTR chaining mode by setting to 10 the CHMOD[1:0] bitfield of the AES_CR register.
AES hardware accelerator (AES) RM0367 The data swap type is selected through the DATATYPE[1:0] bitfield of the AES_CR register. The selection applies both to the input and the output of the AES core. For different data swap types, Figure 100 shows the construction of AES processing core input buffer data P127..0, from the input data entered through the AES_DINR register, or the construction of the output data available through the AES_DOUTR register, from the AES...
RM0367 AES hardware accelerator (AES) Data padding Figure 100 also gives an example of memory data block padding with zeros such that the zeroed bits after the data swap form a contiguous zone at the MSB end of the AES core input buffer.
AES hardware accelerator (AES) RM0367 Data input using DMA Setting the DMAINEN bit of the AES_CR register enables DMA writing into AES. The AES peripheral then initiates a DMA request during the input phase each time it requires a word to be written to the AES_DINR register.
RM0367 AES hardware accelerator (AES) word to be read from the AES_DOUTR register. It asserts four DMA requests to transfer one 128-bit (four-word) output data block to memory, as shown in Figure 102. Table 91 for recommended DMA configuration. Table 91. DMA channel configuration for AES-to-memory data transfer DMA channel control Recommended configuration register field...
AES hardware accelerator (AES) RM0367 DMA single requests are generated by AES until it is disabled. So, after the data output phase at the end of processing of a 128-bit data block, AES switches automatically to a new data input phase for the next data block, if any. 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.
RM0367 AES hardware accelerator (AES) Figure 103. AES interrupt signal generation CCFIE WRERR Flags in AES_SR register aes_it Bits of AES_CR register ERRIE (goes to NVIC) RDERR ERRIE MSv42162V1 Each AES interrupt source can individually be enabled/disabled, by setting/clearing the corresponding enable bit of the AES_CR register.
Page 459
RM0367 AES hardware accelerator (AES) Bit 8 ERRC: Error flag clear Upon written to 1, this bit clears the RDERR and WRERR error flags in the AES_SR register: 0: No effect 1: Clear RDERR and WRERR flags Reading the flag always returns zero. Bit 7 CCFC: Computation complete flag clear Upon written to 1, this bit clears the computation complete flag (CCF) in the AES_SR register: 0: No effect...
RM0367 AES hardware accelerator (AES) 19.7.3 AES data input register (AES_DINR) Address offset: 0x08 Reset value: 0x0000 0000 Only 32-bit access type is supported. DIN[x+31:x+16] DIN[x+15:x] Bits 31:0 This bitfield feeds a 32-bit input buffer. A 4-fold sequential write to this bitfield during the input phase DIN[x+31:x]: One of four 32-bit words of a 128-bit input data block being written into the peripheral virtually writes a complete 128-bit block of input data to the AES peripheral.
AES hardware accelerator (AES) RM0367 Bits 31:0 DOUT[x+31:x]: One of four 32-bit words of a 128-bit output data block being read from the peripheral This bitfield fetches a 32-bit output buffer. A 4-fold sequential read of this bitfield, upon the computation completion (CCF set), virtually reads a complete 128-bit block of output data from the AES peripheral.
RM0367 True random number generator (RNG) True random number generator (RNG) 20.1 Introduction The RNG is a true random number generator that continuously provides 32-bit entropy samples, based on an analog noise source. It can be used by the application as a live entropy source to build a NIST compliant Deterministic Random Bit Generator (DRBG).
RM0367 True random number generator (RNG) 20.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 105, and provides three main functions to the application: •...
True random number generator (RNG) RM0367 Noise source The noise source is the component that contains the non-deterministic, entropy-providing activity that is ultimately responsible for the uncertainty associated with the bitstring output by the entropy source. It is composed of: •...
RM0367 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) RM0367 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: –...
RM0367 True random number generator (RNG) Noise source error detection When a noise source (or seed) error occurs, the RNG stops generating random numbers and sets to “1” both SEIS and SECS bits to indicate that a seed error occurred. If a value is available in the RNG_DR register, it must not be used as it may not have enough entropy.
True random number generator (RNG) RM0367 20.6 RNG entropy source validation 20.6.1 Introduction In order to assess the amount of entropy available from the RNG, STMicroelectronics has tested the peripheral using NIST SP800-22 rev1a statistical tests. The results can be provided on demand or the customer can reproduce the tests.
RM0367 True random number generator (RNG) 20.7 RNG registers The RNG is associated with a control register, a data register and a status register. 20.7.1 RNG control register (RNG_CR) Address offset: 0x000 Reset value: 0x0000 0000 Res. Res. Res. Res. Res.
RM0367 True random number generator (RNG) 20.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 42 periods of RNG clock if the output FIFO is empty.
RM0367 General-purpose timers (TIM2/TIM3) General-purpose timers (TIM2/TIM3) 21.1 TIM2/TIM3 introduction The general-purpose 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 and PWM).
RM0367 General-purpose timers (TIM2/TIM3) 21.3 TIM2/TIM3 functional description 21.3.1 Time-base unit The main block of the programmable timer is a 16-bit 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. The counter clock can be divided by a prescaler.
General-purpose timers (TIM2/TIM3) RM0367 Figure 107. 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 108.
RM0367 General-purpose timers (TIM2/TIM3) 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. 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).
RM0367 General-purpose timers (TIM2/TIM3) The following figures show some examples of the counter behavior for different clock frequencies when TIMx_ARR=0x36. Figure 115. 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)
RM0367 General-purpose timers (TIM2/TIM3) Figure 119. 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) RM0367 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): •...
RM0367 General-purpose timers (TIM2/TIM3) For example, to configure the upcounter to count in response to a rising edge on the TI2 input, use the following procedure: Configure channel 2 to detect rising edges on the TI2 input by writing CC2S= ‘01 in the TIMx_CCMR1 register.
General-purpose timers (TIM2/TIM3) RM0367 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. Figure 129 gives an overview of the external trigger input block. Figure 129.
RM0367 General-purpose timers (TIM2/TIM3) Figure 130. Control circuit in external clock mode 2 CK_INT CNT_EN ETRP ETRF Counter clock = CK_INT =CK_PSC Counter register MS33111V2 21.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).
Page 500
General-purpose timers (TIM2/TIM3) RM0367 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 the CC1P and CC1NP bits to 00 in the TIMx_CCER register (rising edge in this case). Program the input prescaler.
RM0367 General-purpose timers (TIM2/TIM3) 21.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. •...
General-purpose timers (TIM2/TIM3) RM0367 21.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.
RM0367 General-purpose timers (TIM2/TIM3) 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 135.
General-purpose timers (TIM2/TIM3) RM0367 In PWM mode (1 or 2), TIMx_CNT and TIMx_CCRx are always compared to determine whether TIMx_CCRx ≤ TIMx_CNT or TIMx_CNT ≤ TIMx_CCRx (depending on the direction of the counter). However, to comply with the OCREF_CLR functionality (OCREF can be cleared by an external event through the ETR signal until the next PWM period), the OCREF signal is asserted only: •...
RM0367 General-purpose timers (TIM2/TIM3) Downcounting configuration Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Section : Downcounting mode on page 486. In PWM mode 1, the reference signal OCxREF is low as long as TIMx_CNT>TIMx_CCRx else it becomes high.
RM0367 General-purpose timers (TIM2/TIM3) 21.3.10 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) RM0367 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+1).
RM0367 General-purpose timers (TIM2/TIM3) Figure 139. Clearing TIMx OCxREF (CCRx) Counter (CNT) ETRF OCxREF (OCxCE = ‘0’) OCxREF (OCxCE = ‘1’) OCxREF_CLR OCxREF_CLR becomes high still high MS33105V1 1. In case of a PWM with a 100% duty cycle (if CCRx>ARR), OCxREF is enabled again at the next counter overflow.
General-purpose timers (TIM2/TIM3) RM0367 position. The count direction correspond to the rotation direction of the connected sensor. The table summarizes the possible combinations, assuming TI1 and TI2 do not switch at the same time. Table 98. Counting direction versus encoder signals Level on opposite TI1FP1 signal TI2FP2 signal...
RM0367 General-purpose timers (TIM2/TIM3) Figure 140. Example of counter operation in encoder interface mode forward jitter backward jitter forward Counter down MS33107V1 Figure 141 gives an example of counter behavior when TI1FP1 polarity is inverted (same configuration as above except CC1P=1). Figure 141.
General-purpose timers (TIM2/TIM3) RM0367 21.3.14 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.
RM0367 General-purpose timers (TIM2/TIM3) 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 (TIM2/TIM3) RM0367 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).
RM0367 General-purpose timers (TIM2/TIM3) Slave mode: External Clock mode 2 + trigger mode The external clock mode 2 can be used in addition to another slave mode (except external clock mode 1 and encoder mode). In this case, the ETR signal is used as external clock input, and another input can be selected as trigger input when operating in reset mode, gated mode or trigger mode.
General-purpose timers (TIM2/TIM3) RM0367 Figure 145. Control circuit in external clock mode 2 + trigger mode CEN/CNT_EN Counter clock = CK_CNT = CK_PSC Counter register MS33110V1 21.3.15 Timer synchronization The TIMx timers are linked together internally for timer synchronization or chaining. When one Timer is configured in Master Mode, it can reset, start, stop or clock the counter of another Timer configured in Slave Mode.
RM0367 General-purpose timers (TIM2/TIM3) For example, Timer x can be configured to act as a prescaler for Timer y. Refer to Figure 146. To do this, follow the sequence below: Configure Timer x in master mode so that it outputs a periodic trigger signal on each update event UEV.
General-purpose timers (TIM2/TIM3) RM0367 Figure 147. Gating timer y with OC1REF of timer x CK_INT TIMERx-OC1REF TIMERx-CNT TIMERy-CNT 3045 3046 3047 3048 TIMERy-TIF Write TIF = 0 MS33137V1 In the example in Figure 147, the Timer y counter and prescaler are not initialized before being started.
RM0367 General-purpose timers (TIM2/TIM3) Figure 148. Gating timer y with Enable of timer x CK_INT TIMERx-CEN=CNT_EN TIMERx-CNT_INIT TIMERx-CNT TIMERy-CNT TIMERy-CNT_INIT TIMERy-write CNT TIMERy-TIF Write TIF = 0 MS33138V1 Using one timer to start another timer In this example, we set the enable of Timer y with the update event of Timer x. Refer to Figure 146 for connections.
General-purpose timers (TIM2/TIM3) RM0367 Figure 149. Triggering timer y with update of timer x CK_INT TIMERx-UEV TIMERx-CNT TIMERy-CNT TIMERy-CEN=CNT_EN TIMERy-TIF Write TIF = 0 MS33139V1 As in the previous example, both counters can be initialized before starting counting. Figure 150 shows the behavior with the same configuration as in Figure 149 but in trigger...
RM0367 General-purpose timers (TIM2/TIM3) Starting 2 timers synchronously in response to an external trigger In this example, we set the enable of timer x when its TI1 input rises, and the enable of Timer y with the enable of Timer x. Refer to Figure 146 for connections.
General-purpose timers (TIM2/TIM3) RM0367 21.3.16 Debug mode ® When the microcontroller enters debug mode (Cortex -M0+ core - halted), the TIMx counter either continues to work normally or stops, depending on DBG_TIMx_STOP configuration bit in DBG module. For more details, refer to Section 33.9.2: Debug support for timers, watchdog and I 522/1043...
RM0367 General-purpose timers (TIM2/TIM3) 21.4 TIM2/TIM3 registers Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions. The 32-bit peripheral registers have to be written by words (32 bits). All other peripheral registers have to be written by half-words (16 bits) or words (32 bits). Read accesses can be done by bytes (8 bits), half-words (16 bits) or words (32 bits).
Page 524
General-purpose timers (TIM2/TIM3) RM0367 Bit 2 URS: Update request source This bit is set and cleared by software to select the UEV event sources. 0: Any of the following events generate an update interrupt or DMA request if enabled. These events can be: –...
General-purpose timers (TIM2/TIM3) RM0367 21.4.3 TIMx slave mode control register (TIMx_SMCR) Address offset: 0x08 Reset value: 0x0000 ETPS[1:0] ETF[3:0] TS[2:0] Res. SMS[2:0] Bit 15 ETP: External trigger polarity This bit selects whether ETR or ETR is used for trigger operations 0: ETR is noninverted, active at high level or rising edge 1: ETR is inverted, active at low level or falling edge Bit 14 ECE: External clock enable...
RM0367 General-purpose timers (TIM2/TIM3) Bit 7 MSM: Master/Slave mode 0: No action 1: The effect of an event on the trigger input (TRGI) is delayed to allow a perfect synchronization between the current timer and its slaves (through TRGO). It is useful if we want to synchronize several timers on a single external event.
Page 530
General-purpose timers (TIM2/TIM3) RM0367 Bit 2 CC2IF: Capture/Compare 2 interrupt flag refer to CC1IF description Bit 1 CC1IF: Capture/compare 1 interrupt flag If channel CC1 is configured as output: This flag is set by hardware when the counter matches the compare value, with some exception in center-aligned mode (refer to the CMS bits in the TIMx_CR1 register description).
RM0367 General-purpose timers (TIM2/TIM3) 21.4.6 TIMx event generation register (TIMx_EGR) Address offset: 0x14 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CC4G CC3G CC2G CC1G Bits 15:7 Reserved, must be kept at reset value. Bit 6 TG: Trigger generation This bit is set by software in order to generate an event, it is automatically cleared by hardware.
General-purpose timers (TIM2/TIM3) RM0367 21.4.7 TIMx capture/compare mode register 1 (TIMx_CCMR1) Address offset: 0x18 Reset value: 0x0000 The channels can be used in input (capture mode) or in output (compare mode). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function in input and in output mode.
RM0367 General-purpose timers (TIM2/TIM3) Bits 6:4 OC1M: Output compare 1 mode These bits define the behavior of the output reference signal OC1REF from which OC1 and OC1N are derived. OC1REF is active high whereas OC1 and OC1N active level depends on CC1P and CC1NP bits.
Page 534
General-purpose timers (TIM2/TIM3) RM0367 Bits 15:12 IC2F: Input capture 2 filter Bits 11:10 IC2PSC[1:0]: Input capture 2 prescaler Bits 9:8 CC2S: Capture/compare 2 selection This bit-field defines the direction of the channel (input/output) as well as the used input. 00: CC2 channel is configured as output. 01: CC2 channel is configured as input, IC2 is mapped on TI2.
General-purpose timers (TIM2/TIM3) RM0367 Input capture mode Bits 15:12 IC4F: Input capture 4 filter Bits 11:10 IC4PSC: Input capture 4 prescaler Bits 9:8 CC4S: Capture/Compare 4 selection This bit-field defines the direction of the channel (input/output) as well as the used input. 00: CC4 channel is configured as output 01: CC4 channel is configured as input, IC4 is mapped on TI4 10: CC4 channel is configured as input, IC4 is mapped on TI3...
RM0367 General-purpose timers (TIM2/TIM3) 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) RM0367 Note: The state of the external I/O pins connected to the standard OCx channels depends on the OCx channel state and the GPIO registers. 21.4.10 TIMx counter (TIMx_CNT) Address offset: 0x24 Reset value: 0x0000 CNT[15:0] Bits 15:0 CNT[15:0]: Low counter value 21.4.11 TIMx prescaler (TIMx_PSC) Address offset: 0x28...
RM0367 General-purpose timers (TIM2/TIM3) 21.4.17 TIMx DMA control register (TIMx_DCR) 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).
General-purpose timers (TIM2/TIM3) RM0367 Example of how to use the DMA burst feature In this example the timer DMA burst feature is used to update the contents of the CCRx registers (x = 2, 3, 4) with the DMA transferring half words into the CCRx registers. This is done in the following steps: Configure the corresponding DMA channel as follows: –...
General-purpose timers (TIM2/TIM3) RM0367 21.4.20 TIM3 option register (TIM3_OR) Address offset: 0x50 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TI_RMP ETR_RMP Bits 15:5 Reserved, must be kept at reset value. Bit 4 TI_RMP: Timer3 remapping on PC9 This bit is set and cleared by software.
RM0367 General-purpose timers (TIM21/22) General-purpose timers (TIM21/22) 22.1 Introduction The TIM21/22 general-purpose 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).
RM0367 General-purpose timers (TIM21/22) 22.3 TIM21/22 functional description 22.3.1 Timebase unit The main block of the timer is a 16-bit counter with its related auto-reload register. The counters counts up, down or both up and down but also down or both up and down. The counter clock can be divided by a prescaler.
RM0367 General-purpose timers (TIM21/22) Figure 154. Counter timing diagram with prescaler division change from 1 to 4 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 MS31077V2 22.3.2 Counter modes...
General-purpose timers (TIM21/22) RM0367 The following figures show some examples of the counter behavior for different clock frequencies when TIMx_ARR=0x36. Figure 155. Counter timing diagram, internal clock divided by 1 CK_PSC CNT_EN Timerclock = CK_CNT Counter register 34 35 36 Counter overflow Update event (UEV) Update interrupt flag...
General-purpose timers (TIM21/22) RM0367 The following figures show some examples of the counter behavior for different clock frequencies when TIMx_ARR=0x36. Figure 161. 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)
General-purpose timers (TIM21/22) RM0367 Center-aligned mode (up/down counting) In center-aligned mode, the counter counts from 0 to the auto-reload value (content of the TIMx_ARR register) – 1, generates a counter overflow event, then counts from the auto- reload value down to 1 and generates a counter underflow event. Then it restarts counting from 0.
RM0367 General-purpose timers (TIM21/22) External clock source mode 1 This mode is selected when SMS=’111’ in the TIMx_SMCR register. The counter can count at each rising or falling edge on a selected input. Figure 172. TI2 external clock connection example TIMx_SMCR TS[2:0] TI2F...
General-purpose timers (TIM21/22) RM0367 Figure 173. 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.
RM0367 General-purpose timers (TIM21/22) For example, to configure the upcounter to count each 2 rising edges on ETR, use the following procedure: As no filter is needed in this example, write ETF[3:0]=0000 in the TIMx_SMCR register. Set the prescaler by writing ETPS[1:0]=01 in the TIMx_SMCR register Select rising edge detection on the ETR pin by writing ETP=0 in the TIMx_SMCR register Enable external clock mode 2 by writing ECE=1 in the TIMx_SMCR register.
RM0367 General-purpose timers (TIM21/22) Figure 178. Output stage of capture/compare channel (channel 1 and 2) ETRF To the master mode controller CNT > CCR2 Output Output OCx_REF mode enable CNT = CCR2 controller circuit CCxP CCxE TIMx_CCER OCxM[2:0] TIMx_CCER TIMx_CCMR1 MSv33714V1 The capture/compare block is made of one preload register and one shadow register.
Page 568
General-purpose timers (TIM21/22) RM0367 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 programming CC1P and CC1NP bits to ‘00’ in the TIMx_CCER register (rising edge in this case). Program the input prescaler.
RM0367 General-purpose timers (TIM21/22) 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. •...
General-purpose timers (TIM21/22) RM0367 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’...
RM0367 General-purpose timers (TIM21/22) 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 180.
General-purpose timers (TIM21/22) RM0367 The timer is able to generate PWM in edge-aligned mode only since the counter is upcounting. • Upcounting configuration Upcounting is active when the DIR bit in the TIMx_CR1 register is low. Refer to the Upcounting mode on page 551.
RM0367 General-purpose timers (TIM21/22) PWM center-aligned mode Center-aligned mode is active when the CMS bits in TIMx_CR1 register are different from ‘00’ (all the remaining configurations having the same effect on the OCxRef/OCx signals). The compare flag is set when the counter counts up, when it counts down or both when it counts up and down depending on the CMS bits configuration.
General-purpose timers (TIM21/22) RM0367 Hints on using center-aligned mode • When starting in center-aligned mode, the current up-down configuration is used. It means that the counter counts up or down depending on the value written in the DIR bit in the TIMx_CR1 register. Moreover, the DIR and CMS bits must not be changed at the same time by the software.
RM0367 General-purpose timers (TIM21/22) Figure 183. Clearing TIMx OCxREF (CCRx) Counter (CNT) ETRF OCxREF (OCxCE = ‘0’) OCxREF (OCxCE = ‘1’) OCxREF_CLR OCxREF_CLR becomes high still high MS33105V1 Note: In case of a PWM with a 100% duty cycle (if CCRx>ARR), then OCxREF is enabled again at the next counter overflow.
General-purpose timers (TIM21/22) RM0367 Figure 184. 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.
RM0367 General-purpose timers (TIM21/22) Since only 1 pulse (Single mode) is needed, a 1 must be written in the OPM bit in the TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over from the auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0', so the Repetitive Mode is selected.
General-purpose timers (TIM21/22) RM0367 Table 102. 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...
RM0367 General-purpose timers (TIM21/22) Figure 186 gives an example of counter behavior when TI1FP1 polarity is inverted (same configuration as above except CC1P=1). Figure 186. Example of encoder interface mode with TI1FP1 polarity inverted forward jitter backward jitter forward Counter down down MS33108V1...
General-purpose timers (TIM21/22) RM0367 The counter starts counting on the internal clock, then behaves normally until TI1 rising edge. When TI1 rises, the counter is cleared and restarts from 0. In the meantime, the trigger flag is set (TIF bit in the TIMx_SR register) and an interrupt request can be sent if enabled (depending on the TIE bit in TIMx_DIER register).
RM0367 General-purpose timers (TIM21/22) Figure 188. Control circuit in gated mode cnt_en Counter clock = ck_cnt = ck_psc Counter register 32 33 35 36 Write TIF=0 MS31402V1 Slave mode: Trigger mode The counter can start in response to an event on a selected input. In the following example, the upcounter starts in response to a rising edge on TI2 input: Configure the external trigger input circuit by programming the TIMx_SMCR register as follows:...
General-purpose timers (TIM21/22) RM0367 Figure 189. Control circuit in trigger mode cnt_en Counter clock = ck_cnt = ck_psc Counter register MS31403V1 22.3.14 Timer synchronization (TIM21/22) The timers are linked together internally for timer synchronization or chaining. Refer to Section 21.3.15: Timer synchronization on page 516 for details.
RM0367 General-purpose timers (TIM21/22) 22.4 TIM21/22 registers Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions. The peripheral registers have to be written by half-words (16 bits) or words (32 bits). Read accesses can be done by bytes (8 bits), half-words (16 bits) or words (32 bits). 22.4.1 TIM21/22 control register 1 (TIMx_CR1) Address offset: 0x00...
Page 584
General-purpose timers (TIM21/22) RM0367 Bit 2 URS: Update request source This bit is set and cleared by software to select the UEV event sources. 0: Any of the following events generates an update interrupt if enabled: – Counter overflow – Setting the UG bit 1: Only counter overflow generates an update interrupt if enabled.
RM0367 General-purpose timers (TIM21/22) 22.4.2 TIM21/22 control register 2 (TIMx_CR2) 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: Master mode selection These bits allow to select the information to be sent in master mode to slave timers for synchronization (TRGO).
General-purpose timers (TIM21/22) RM0367 22.4.3 TIM21/22 slave mode control register (TIMx_SMCR) Address offset: 0x08 Reset value: 0x0000 ETPS[1:0] ETF[3:0] TS[2:0] Res. SMS[2:0] Bit 15 ETP: External trigger polarity This bit selects whether ETR or ETR is used for trigger operations 0: ETR is non-inverted, active at high level or rising edge.
Page 587
RM0367 General-purpose timers (TIM21/22) 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 590
General-purpose timers (TIM21/22) RM0367 Bit 6 TIF: Trigger interrupt flag This flag is set by hardware on trigger event (active edge detected on TRGI input when the slave mode controller is enabled in all modes but gated mode. It is set when the counter starts or stops when gated mode is selected.
RM0367 General-purpose timers (TIM21/22) 22.4.6 TIM21/22 event generation register (TIMx_EGR) Address offset: 0x14 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CC2G CC1G Bits 15:7 Reserved, must be kept at reset value. Bit 6 TG: Trigger generation This bit is set by software in order to generate an event, it is automatically cleared by hardware.
General-purpose timers (TIM21/22) RM0367 22.4.7 TIM21/22 capture/compare mode register 1 (TIMx_CCMR1) Address offset: 0x18 Reset value: 0x0000 The channels can be used in input (capture mode) or in output (compare mode). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits in this register have different functions in input and output modes.
Page 593
RM0367 General-purpose timers (TIM21/22) Bits 6:4 OC1M: Output compare 1 mode These bits define the behavior of the output reference signal OC1REF from which OC1 and OC1N are derived. OC1REF is active high whereas the active levels of OC1 and OC1N depend on the CC1P and CC1NP bits, respectively.
General-purpose timers (TIM21/22) RM0367 Input capture mode Bits 15:12 IC2F: Input capture 2 filter Bits 11:10 IC2PSC[1:0]: Input capture 2 prescaler Bits 9:8 CC2S: Capture/compare 2 selection This bitfield defines the direction of the channel (input/output) as well as the used input. 00: CC2 channel is configured as output 01: CC2 channel is configured as input, IC2 is mapped on TI2 10: CC2 channel is configured as input, IC2 is mapped on TI1...
General-purpose timers (TIM21/22) RM0367 Table 104. Output control bit for standard OCx channels CCxE bit OCx output state Output disabled (OCx=’0’, OCx_EN=’0’) OCx=OCxREF + Polarity, OCx_EN=’1’ Note: The states of the external I/O pins connected to the standard OCx channels depend on the state of the OCx channel and on the GPIO registers.
General-purpose timers (TIM21/22) RM0367 22.4.14 TIM21 option register (TIM21_OR) Address offset: 0x50 Reset value: 0x0000 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TI2_RMP TI1_RMP ETR_RMP Bits 15:6 Reserved, must be kept at reset value. Bit 5 TI2_RMP: Timer21 TI2 (connected to TIM21_CH1) remap This bit is set and cleared by software.
Basic timers (TIM6/7) RM0367 Basic timers (TIM6/7) 23.1 Introduction The basic timers TIM6, TIM7 consist of a 16-bit auto-reload counter driven by a programmable prescaler. They can be used as generic timers for timebase generation but they are also specifically used to drive the digital-to-analog converter (DAC).
RM0367 Basic timers (TIM6/7) 23.3 TIM6/7 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/7) RM0367 Figure 191. 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 192.
RM0367 Basic timers (TIM6/7) 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).
RM0367 Basic timers (TIM6/7) Figure 199. 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.4 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...
Basic timers (TIM6/7) RM0367 23.4 TIM6/7 registers Refer to Section 1.2: List of abbreviations for registers for a list of abbreviations used in register descriptions. The peripheral registers have to be written by half-words (16 bits) or words (32 bits). Read accesses can be done by bytes (8 bits), half-words (16 bits) or words (32 bits).
RM0367 Basic timers (TIM6/7) 23.4.2 TIM6/7 control register 2 (TIMx_CR2) 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: 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/7) RM0367 23.4.4 TIM6/7 status register (TIMx_SR) 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.
RM0367 Basic timers (TIM6/7) 23.4.7 TIM6/7 prescaler (TIMx_PSC) Address offset: 0x28 Reset value: 0x0000 PSC[15:0] Bits 15:0 PSC[15:0]: Prescaler value The counter clock frequency (CK_CNT) is equal to f / (PSC[15:0] + 1). CK_PSC PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).
Basic timers (TIM6/7) RM0367 23.4.9 TIM6/7 register map TIMx registers are mapped as 16-bit addressable registers as described in the table below: Table 106. TIM6/7 register map and reset values Offset Register TIMx_CR1 0x00 Reset value TIMx_CR2 MMS[2:0] 0x04 Reset value 0x08 Res.
RM0367 Low-power timer (LPTIM) Low-power timer (LPTIM) 24.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) RM0367 The digital filters are divided into two groups: • The first group of digital filters protects the LPTIM external inputs. The digital filters sensitivity is controlled by the CKFLT bits • The second group of digital filters protects the LPTIM internal trigger inputs. The digital filters sensitivity is controlled by the TRGFLT bits.
RM0367 Low-power timer (LPTIM) 24.4.6 Trigger multiplexer The LPTIM counter may be started either by software or after the detection of an active edge on one of the 8 trigger inputs. TRIGEN[1:0] is used to determine the LPTIM trigger source: •...
Low-power timer (LPTIM) RM0367 Figure 202. LPTIM output waveform, single counting mode configuration LPTIM_ARR Compare External trigger event MSv39230V2 - Set-once mode activated: It should be noted that when the WAVE bit-field in the LPTIM_CFGR register is set, the Set- once mode is activated.
RM0367 Low-power timer (LPTIM) Figure 204. LPTIM output waveform, Continuous counting mode configuration Discarded triggers LPTIM_ARR Compare External trigger event MSv39229V2 SNGSTRT and CNTSTRT bits can only be set when the timer is enabled (The ENABLE bit is set to ‘1’). It is possible to change “on the fly” from One-shot mode to Continuous mode. If the Continuous mode was previously selected, setting SNGSTRT will switch the LPTIM to the One-shot mode.
Low-power timer (LPTIM) RM0367 The LPTIM output waveform can be configured through the WAVE bit as follow: • Resetting the WAVE bit to ‘0’ forces the LPTIM to generate either a PWM waveform or a One pulse waveform depending on which bit is set: CNTSTRT or SNGSTRT. •...
RM0367 Low-power timer (LPTIM) counter comparator. Within this latency period, any additional write into these registers must be avoided. The ARROK flag and the CMPOK flag in the LPTIM_ISR register indicate when the write operation is completed to respectively the LPTIM_ARR register and the LPTIM_CMP register.
Low-power timer (LPTIM) RM0367 24.4.12 Timer enable The ENABLE bit located in the LPTIM_CR register is used to enable/disable the LPTIM kernel logic. After setting the ENABLE bit, a delay of two counter clock is needed before the LPTIM is actually enabled. The LPTIM_CFGR and LPTIM_IER registers must be modified only when the LPTIM is disabled.
RM0367 Low-power timer (LPTIM) The following figure shows a counting sequence for Encoder mode where both-edge sensitivity is configured. Caution: In this mode the LPTIM must be clocked by an internal clock source, so the CKSEL bit must be maintained to its reset value which is equal to ‘0’. Also, the prescaler division ratio must be equal to its reset value which is 1 (PRESC[2:0] bits must be ‘000’).
Low-power timer (LPTIM) RM0367 24.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 •...
RM0367 Low-power timer (LPTIM) 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 24.3: LPTIM implementation.
Page 630
Low-power timer (LPTIM) RM0367 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 24.3: LPTIM implementation.
Page 631
RM0367 Low-power timer (LPTIM) 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...
Low-power timer (LPTIM) RM0367 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...
RM0367 Low-power timer (LPTIM) Bits 31:3 Reserved, must be kept at reset value. Bit 2 CNTSTRT: Timer start in Continuous mode This bit is set by software and cleared by hardware. In case of software start (TRIGEN[1:0] = ‘00’), setting this bit starts the LPTIM in Continuous mode. If the software start is disabled (TRIGEN[1:0] different than ‘00’), setting this bit starts the timer in Continuous mode as soon as an external trigger is detected.
Independent watchdog (IWDG) RM0367 Independent watchdog (IWDG) 25.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.
RM0367 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) RM0367 25.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.
RM0367 Independent watchdog (IWDG) 25.4 IWDG registers Refer to Section 1.2 on page 52 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.4.1 IWDG key register (IWDG_KR) Address offset: 0x00 Reset value: 0x0000 0000 (reset by Standby mode) Res.
RM0367 System window watchdog (WWDG) System window watchdog (WWDG) 26.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.
RM0367 System window watchdog (WWDG) Figure 209. Window watchdog timing diagram CNT DownCounter Refresh not allowed Refresh allowed T[6:0] W[6:0] 0x3F Time WDGTB x 4096 x 2 pclk 0x41 0x40 0x3F wwdg_ewit EWIF = 0 wwdg_rst T6 bit MS47266V1 The formula to calculate the timeout value is given by: WDGTB[1:0] ×...
System window watchdog (WWDG) RM0367 26.3.5 Debug mode When the device enters debug mode (processor halted), the WWDG counter either continues to work normally or stops, depending on the configuration bit in DBG module. For more details refer to Section 33.9.2: Debug support for timers, watchdog and I 26.4 WWDG interrupts The early wakeup interrupt (EWI) can be used if specific safety operations or data logging...
RM0367 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)
System window watchdog (WWDG) RM0367 Bits 31:1 Reserved, must be kept at reset value. Bit 0 EWIF: Early wakeup interrupt flag This bit is set by hardware when the counter has reached the value 0x40. It must be cleared by software by writing ‘0’. Writing ‘1’ has no effect. This bit is also set if the interrupt is not enabled.
RM0367 Real-time clock (RTC) Real-time clock (RTC) 27.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. The RTC includes also a periodic programmable wakeup flag with interrupt capability.
Real-time clock (RTC) RM0367 27.2 RTC main features The RTC unit main features are the following (see Figure 210: RTC block diagram): • Calendar with subseconds, seconds, minutes, hours (12 or 24 format), day (day of week), date (day of month), month, and year. •...
Real-time clock (RTC) RM0367 The RTC includes: • Two alarms • Up to three tamper events from I/Os – Tamper detection erases the backup registers. • One timestamp event from I/O • Tamper event detection can generate a timestamp event •...
RM0367 Real-time clock (RTC) Table 117. RTC pin PC13 configuration (continued) OSEL[1:0] TSE bit COE bit TAMP1E bit bits RTC_OUT PC13 Pin RTC_ALARM (RTC_CALIB (RTC_TAMP1 (RTC_TS configuration _TYPE (RTC_ALARM _RMP output input input and function output enable) enable) enable) enable) Don’t care RTC_TS and RTC_TAMP1...
Page 656
Real-time clock (RTC) RM0367 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 210: RTC block diagram): • A 7-bit asynchronous prescaler configured through the PREDIV_A bits of the RTC_PRER register.
Page 657
RM0367 Real-time clock (RTC) 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.
Page 658
Real-time clock (RTC) RM0367 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. The periodic wakeup flag can be routed to the RTC_ALARM output provided it has been enabled through bits OSEL[1:0] of RTC_CR register.
Page 659
RM0367 Real-time clock (RTC) Note: After a system reset, the application can read the INITS flag in the RTC_ISR register to check if the calendar has been initialized or not. If this flag equals 0, the calendar has not been initialized since the year field is set at its RTC domain reset default value (0x00). To read the calendar after initialization, the software must first check that the RSF flag is set in the RTC_ISR register.
Page 660
Real-time clock (RTC) RM0367 If the APB1 clock frequency is less than seven times the RTC clock frequency, the software must read the calendar time and date registers twice. If the second read of the RTC_TR gives the same result as the first read, this ensures that the data is correct. Otherwise a third read access must be done.
Page 661
RM0367 Real-time clock (RTC) On the contrary, the following registers are reset to their default values by a RTC domain reset and are not affected by a system reset: the RTC current calendar registers, the RTC control register (RTC_CR), the prescaler register (RTC_PRER), the RTC calibration register (RTC_CALR), the RTC shift register (RTC_SHIFTR), the RTC timestamp registers (RTC_TSSSR, RTC_TSTR and RTC_TSDR), the RTC tamper configuration register (RTC_TAMPCR), the RTC backup registers (RTC_BKPxR), the wakeup timer register...
Page 662
Real-time clock (RTC) RM0367 detection is enabled (REFCKON bit of RTC_CR set to 1), the calendar is still clocked by the LSE, and RTC_REFIN is used to compensate for the imprecision of the calendar update frequency (1 Hz). Each 1 Hz clock edge is compared to the nearest RTC_REFIN clock edge (if one is found within a given time window).
Page 663
RM0367 Real-time clock (RTC) Note: CALM[8:0] (RTC_CALR) specifies the number of RTCCLK pulses to be masked during the 32-second cycle. Setting the bit CALM[0] to ‘1’ causes exactly one pulse to be masked during the 32-second cycle at the moment when cal_cnt[19:0] is 0x80000; CALM[1]=1 causes two other cycles to be masked (when cal_cnt is 0x40000 and 0xC0000);...
Page 664
Real-time clock (RTC) RM0367 However, this measurement error can be eliminated if the measurement period is the same length as the calibration cycle period. In this case, the only error observed is the error due to the resolution of the digital calibration. •...
Page 665
RM0367 Real-time clock (RTC) Note: TSF is set 2 ck_apre cycles after the time-stamp event occurs due to synchronization process. There is no delay in the setting of TSOVF. This means that if two time-stamp events are close together, TSOVF can be seen as '1' while TSF is still '0'. As a consequence, it is recommended to poll TSOVF only after TSF has been set.
Page 666
Real-time clock (RTC) RM0367 A new tamper occurring on the same pin cannot be detected during the latency described above and 2.5 ck_rtc additional cycles. By setting the TAMPIE bit in the RTC_TAMPCR register, an interrupt is generated when a tamper detection event occurs (when TAMPxF is set).
Page 667
RM0367 Real-time clock (RTC) The RTC_TAMPx inputs are precharged through the I/O internal pull-up resistance before its state is sampled, unless disabled by setting TAMPPUDIS to 1,The duration of the precharge is determined by the TAMPPRCH bits, allowing for larger capacitances on the RTC_TAMPx inputs.
Real-time clock (RTC) RM0367 27.5 RTC low-power modes Table 119. Effect of low-power modes on RTC Mode Description No effect Sleep RTC interrupts cause the device to exit the Sleep mode. The RTC remains active when the RTC clock source is LSE or LSI. RTC alarm, RTC Stop tamper event, RTC timestamp event, and RTC Wakeup cause the device to exit the Stop mode.
Page 669
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 RM0367 Rev 7...
Page 670
Real-time clock (RTC) RM0367 27.7.2 RTC date register (RTC_DR) The RTC_DR is the calendar date shadow register. This register must be written in initialization mode only. Refer to Calendar initialization and configuration on page 658 Reading the calendar on page 659.
Page 672
Real-time clock (RTC) RM0367 Bit 16 ADD1H: Add 1 hour (summer time change) When this bit is set, 1 hour is added to the calendar time. This bit is always read as 0. 0: No effect 1: Adds 1 hour to the current time. This can be used for summer time change outside initialization mode.
Page 673
RM0367 Real-time clock (RTC) Bit 4 REFCKON: RTC_REFIN reference clock detection enable (50 or 60 Hz) 0: RTC_REFIN detection disabled 1: RTC_REFIN detection enabled Note: PREDIV_S must be 0x00FF. Bit 3 TSEDGE: Time-stamp event active edge 0: RTC_TS input rising edge generates a time-stamp event 1: RTC_TS input falling edge generates a time-stamp event TSE must be reset when TSEDGE is changed to avoid unwanted TSF setting.
Real-time clock (RTC) RM0367 27.7.4 RTC initialization and status register (RTC_ISR) This register is write protected (except for RTC_ISR[13:8] bits). The write access procedure is described in RTC register write protection on page 658. Address offset: 0x0C RTC domain reset value: 0x0000 0007 System reset: not affected except INIT, INITF, and RSF bits which are cleared to ‘0’...
Page 675
RM0367 Real-time clock (RTC) Bit 9 ALRBF: Alarm B flag This flag is set by hardware when the time/date registers (RTC_TR and RTC_DR) match the Alarm B register (RTC_ALRMBR). This flag is cleared by software by writing 0. Bit 8 ALRAF: Alarm A flag This flag is set by hardware when the time/date registers (RTC_TR and RTC_DR) match the Alarm A register (RTC_ALRMAR).
Page 676
Real-time clock (RTC) RM0367 Bit 2 WUTWF: Wakeup timer write flag This bit is set by hardware up to 2 RTCCLK cycles after the WUTE bit has been set to 0 in RTC_CR, and is cleared up to 2 RTCCLK cycles after the WUTE bit has been set to 1. The wakeup timer values can be changed when WUTE bit is cleared and WUTWF is set.
RM0367 Real-time clock (RTC) 27.7.5 RTC prescaler register (RTC_PRER) This register must be written in initialization mode only. The initialization must be performed in two separate write accesses. Refer to Calendar initialization and configuration on page 658. This register is write protected. The write access procedure is described in RTC register write protection on page 658.
Real-time clock (RTC) RM0367 27.7.6 RTC wakeup timer register (RTC_WUTR) This register can be written only when WUTWF is set to 1 in RTC_ISR. This register is write protected. The write access procedure is described in RTC register write protection on page 658.
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. RM0367 Rev 7...
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 680/1043...
Real-time clock (RTC) RM0367 27.7.11 RTC shift control register (RTC_SHIFTR) This register is write protected. The write access procedure is described in RTC register write protection on page 658. Address offset: 0x2C RTC domain reset value: 0x0000 0000 System reset: not affected ADD1S Res.
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. RM0367 Rev 7...
Real-time clock (RTC) RM0367 27.7.13 RTC timestamp date register (RTC_TSDR) The content of this register is valid only when TSF is set to 1 in RTC_ISR. It is cleared when TSF bit is reset. Address offset: 0x34 RTC domain reset value: 0x0000 0000 System reset: not affected Res.
RM0367 Real-time clock (RTC) 27.7.14 RTC time-stamp sub second register (RTC_TSSSR) The content of this register is valid only when RTC_ISR/TSF is set. It is cleared when the RTC_ISR/TSF bit is reset. Address offset: 0x38 RTC domain reset value: 0x0000 0000 System reset: not affected Res.
Real-time clock (RTC) RM0367 27.7.15 RTC calibration register (RTC_CALR) This register is write protected. The write access procedure is described in RTC register write protection on page 658. Address offset: 0x3C RTC domain reset value: 0x0000 0000 System reset: not affected Res.
Real-time clock (RTC) RM0367 27.7.17 RTC alarm A sub second register (RTC_ALRMASSR) This register can be written only when ALRAE is reset in RTC_CR register, or in initialization mode. This register is write protected. The write access procedure is described in RTC register write protection on page 658 Address offset: 0x44...
RM0367 Real-time clock (RTC) 27.7.18 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.
RM0367 Inter-integrated circuit (I2C) interface Inter-integrated circuit (I2C) interface 28.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+).
I2C implementation This manual describes the full set of features implemented in I2C1, I2C3. I2C2 supports a smaller set of features, but is otherwise identical to I2C1/I2C3. The differences are listed below. Table 122. STM32L0x3 I2C features I2C features I2C1 I2C2...
RM0367 Inter-integrated circuit (I2C) interface If SMBus feature is supported: the additional optional SMBus Alert pin (SMBA) is also available. 28.4.1 I2C1/3 block diagram The block diagram of the I2C1 interface is shown in Figure 211. Figure 211. I2C1/3 block diagram I2CCLK i2c_ker_ck Data control...
Inter-integrated circuit (I2C) interface RM0367 28.4.2 I2C2 block diagram The block diagram of the I2C2 interface is shown in Figure 212. Figure 212. I2C2 block diagram I2CCLK PCLK Data control Digital Analog Shift register noise noise GPIO I2C1_SDA filter filter logic SMBUS generation/...
RM0367 Inter-integrated circuit (I2C) interface 28.4.3 I2C pins and internal signals Table 123. 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 124. I2C internal input/output signals Internal signal name Signal type Description I2C kernel clock, also named I2CCLK in this...
Inter-integrated circuit (I2C) interface RM0367 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.
RM0367 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 RM0367 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 214.
Page 703
RM0367 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 704
Inter-integrated circuit (I2C) interface RM0367 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.
RM0367 Inter-integrated circuit (I2C) interface Figure 215. 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 28.4.7 Software reset...
Inter-integrated circuit (I2C) interface RM0367 28.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).
RM0367 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 RM0367 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 is transferred.
Page 709
RM0367 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 RM0367 Slave byte control mode In order to allow byte ACK control in slave reception mode, The 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 711
RM0367 Inter-integrated circuit (I2C) interface For code example, refer to A.16.1: I2C configured in slave mode code example. 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.
RM0367 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.
Inter-integrated circuit (I2C) interface RM0367 Figure 223. Transfer sequence flowchart for slave receiver with NOSTRETCH=1 Slave reception Slave initialization I2C_ISR.STOPF I2C_ISR.RXNE Set I2C_ICR.STOPCF Read I2C_RXDR.RXDATA MS19856V2 Figure 224. Transfer bus diagrams for I2C slave receiver legend: Example I2C slave receiver 3 bytes, NOSTRETCH=0: transmission ADDR RXNE...
Page 717
RM0367 Inter-integrated circuit (I2C) interface 28.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.
RM0367 Inter-integrated circuit (I2C) interface Table 128. 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 RM0367 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.
RM0367 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 RM0367 Figure 231. 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 725
RM0367 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.
RM0367 Inter-integrated circuit (I2C) interface 28.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 129.
Page 730
Inter-integrated circuit (I2C) interface RM0367 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.
RM0367 Inter-integrated circuit (I2C) interface Received command and data acknowledge control A SMBus receiver must be able to NACK each received command or data. In order to allow the ACK control in slave mode, the Slave Byte Control mode must be enabled by setting SBC bit in I2C_CR1 register.
Inter-integrated circuit (I2C) interface RM0367 Table 131. SMBus timeout specifications (continued) Limits Symbol Parameter Unit Cumulative clock low extend time (slave device) LOW:SEXT Cumulative clock low extend time (master device) LOW:MEXT 1. t is the cumulative time a given slave device is allowed to extend the clock cycles in one message LOW:SEXT from the initial START to the STOP.
Page 733
RM0367 Inter-integrated circuit (I2C) interface 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 . (refer to Table 126: I2C-SMBus specification data IDLE HIGH setup and hold...
Inter-integrated circuit (I2C) interface RM0367 Table 132. SMBus with PEC configuration Mode SBC bit RELOAD bit AUTOEND bit PECBYTE bit Master Tx/Rx NBYTES + PEC+ STOP Master Tx/Rx NBYTES + PEC + ReSTART Slave Tx/Rx with PEC Timeout detection The timeout detection is enabled by setting the TIMOUTEN and TEXTEN bits in the I2C_TIMEOUTR register.
RM0367 Inter-integrated circuit (I2C) interface Caution: Changing the TIMEOUTA and TIDLE configuration is not allowed when the TIMEOUTEN is set. SMBus: 28.4.14 I2C_TIMEOUTR register configuration examples This section is relevant only when SMBus feature is supported. Refer to Section 28.3: I2C implementation.
Inter-integrated circuit (I2C) interface RM0367 that case the total number of TXIS interrupts is NBYTES-1 and the content of the I2C_PECR register is automatically transmitted if the master requests an extra byte after the NBYTES-1 data transfer. Caution: The PECBYTE bit has no effect when the RELOAD bit is set. Figure 236.
Inter-integrated circuit (I2C) interface RM0367 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 741
RM0367 Inter-integrated circuit (I2C) interface 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 RM0367 Figure 241. Bus transfer diagrams for SMBus master receiver Example SMBus master receiver 2 bytes + PEC, automatic end mode (STOP) RXNE RXNE RXNE legend: transmission data1 data2 Address reception INIT SCL stretch NBYTES INIT: program Slave address, program NBYTES = 3, AUTOEND=1, set PECBYTE, set START EV1: RXNE ISR: rd data1 EV2: RXNE ISR: rd data2 EV3: RXNE ISR: rd PEC...
Page 743
RM0367 Inter-integrated circuit (I2C) interface 28.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 28.3: I2C implementation. The I2C is able to wakeup the MCU from Stop mode (APB clock is off), when it is addressed.
Page 744
Inter-integrated circuit (I2C) interface RM0367 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.
Page 745
RM0367 Inter-integrated circuit (I2C) interface 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.
Inter-integrated circuit (I2C) interface RM0367 Reception using DMA DMA (direct memory access) can be enabled for reception by setting the RXDMAEN bit in the I2C_CR1 register. Data is loaded from the I2C_RXDR register to an SRAM area configured using the DMA peripheral (refer to Section 11: Direct memory access controller (DMA) on page 265) whenever the RXNE bit is set.
RM0367 Inter-integrated circuit (I2C) interface 28.6 I2C interrupts The table below gives the list of I2C interrupt requests. Table 137. I2C Interrupt requests Exit the Exit the Exit the Interrupt Interrupt Event Enable Interrupt clear Sleep Stop Standby acronym event flag control bit method...
Page 748
Inter-integrated circuit (I2C) interface RM0367 28.7 I2C registers Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions. The peripheral registers are accessed by words (32-bit). 28.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 749
RM0367 Inter-integrated circuit (I2C) interface 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 750
Inter-integrated circuit (I2C) interface RM0367 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...
Page 751
RM0367 Inter-integrated circuit (I2C) interface 28.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 752
Inter-integrated circuit (I2C) interface RM0367 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 753
RM0367 Inter-integrated circuit (I2C) interface Bits 9:0 SADD[9:0]: Slave address (master mode) In 7-bit addressing mode (ADD10 = 0): SADD[7:1] should be written with the 7-bit slave address to be sent. The bits SADD[9], SADD[8] and SADD[0] are don't care. In 10-bit addressing mode (ADD10 = 1): SADD[9:0] should be written with the 10-bit slave address to be sent.
Page 754
Inter-integrated circuit (I2C) interface RM0367 28.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.
Page 755
RM0367 Inter-integrated circuit (I2C) interface 28.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...
Page 756
Inter-integrated circuit (I2C) interface RM0367 28.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.
Page 757
RM0367 Inter-integrated circuit (I2C) interface 28.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 758
Inter-integrated circuit (I2C) interface RM0367 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.
Page 759
RM0367 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.
Page 760
Inter-integrated circuit (I2C) interface RM0367 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.
Inter-integrated circuit (I2C) interface RM0367 28.7.12 I2C register map The table below provides the I2C register map and reset values. Table 138. I2C register map and reset values Register Offset name I2C_CR1 DNF[3:0] Reset value I2C_CR2 NBYTES[7:0] SADD[9:0] Reset value I2C_OAR1 OA1[9:0] Reset value...
Page 763
RM0367 Inter-integrated circuit (I2C) interface Table 138. I2C register map and reset values (continued) Register Offset name I2C_TXDR TXDATA[7:0] 0x28 Reset value Refer to Section 2.2 on page 58 for the register boundary addresses. RM0367 Rev 7 763/1043...
Page 764
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) 29.1 Introduction The universal synchronous asynchronous receiver transmitter (USART) offers a flexible means of Full-duplex data exchange with external equipment requiring an industry standard NRZ asynchronous serial data format. The USART offers a very wide range of baud rates using a programmable baud rate generator.
Page 765
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) • Communication control/error detection flags • Parity control: – Transmits parity bit – Checks parity of received data byte • Fourteen interrupt sources with flags • Multiprocessor communications The USART enters Mute mode if the address does not match. •...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 29.4 USART implementation Table 139. STM32L0x3 USART/LPUART features USART modes/features USART1/2 USART4 USART5 LPUART1 Hardware flow control for modem Continuous communication using DMA Multiprocessor communication Synchronous mode Smartcard mode Single-wire Half-duplex communication Ir SIR ENDEC block...
Page 767
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Serial data are transmitted and received through these pins in normal USART mode. The frames are comprised of: • An Idle Line prior to transmission or reception • A start bit • A data word (7, 8 or 9 bits) least significant bit first •...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 242. USART block diagram PRDATA PWDATA Write Read DR (data register) (CPU or DMA) (CPU or DMA) Transmit shift register Receive shift register IrDA Transmit data register Receive data register ENDEC (TDR) (RDR) block USART_GTPR register CK control...
Page 769
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) 29.5.1 USART character description The word length can be selected as being either 7 or 8 or 9 bits by programming the M[1:0] bits in the USART_CR1 register (see Figure 243). • 7-bit character length: M[1:0] = 10 •...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 243. Word length programming 9-bit word length (M = 01 ), 1 Stop bit Possible Data frame Parity Next Start Stop Start Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Clock Start Idle frame Stop Stop...
Page 771
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) 29.5.2 USART transmitter The transmitter can send data words of either 7, 8 or 9 bits depending on the M bits status. The Transmit Enable bit (TE) must be set in order to activate the transmitter function. The data in the transmit shift register is output on the TX pin and the corresponding clock pulses are output on the CK pin.
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 244. Configurable stop bits 8-bit data, 1 Stop bit Possible Data frame Next Next data frame parity bit start Stop Start bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 CLOCK ** LBCL bit controls last data clock pulse 8-bit data, 1 1/2 Stop bits Possible Data frame...
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) When a transmission is taking place, a write instruction to the USART_TDR register stores the data in the TDR register; next, the data is copied in the shift register at the end of the currently ongoing transmission.
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 29.5.3 USART receiver The USART can receive data words of either 7, 8 or 9 bits depending on the M bits in the USART_CR1 register. Start bit detection The start bit detection sequence is the same when oversampling by 16 or by 8. In the USART, the start bit is detected when a specific sequence of samples is recognized.
Page 775
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) If neither conditions a. or b. are met, the start detection aborts and the receiver returns to the idle state (no flag is set). Character reception During an USART reception, data shifts in least significant bit first (default configuration) through the RX pin.
Page 776
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Overrun error An overrun error occurs when a character is received when RXNE has not been reset. Data can not be transferred from the shift register to the RDR register until the RXNE bit is cleared.
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Programming the ONEBIT bit in the USART_CR3 register selects the method used to evaluate the logic level. There are two options: • The majority vote of the three samples in the center of the received bit. In this case, when the 3 samples used for the majority vote are not equal, the NF bit is set •...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 248. Data sampling when oversampling by 8 RX line sampled values Sample clock (x8) One bit time MSv31153V1 Table 140. Noise detection from sampled data Sampled value NE status Received bit value Framing error A framing error is detected when the stop bit is not recognized on reception at the expected time, following either a de-synchronization or excessive noise.
Page 779
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Configurable stop bits during reception The number of stop bits to be received can be configured through the control bits of Control Register 2 - it can be either 1 or 2 in normal mode and 0.5 or 1.5 in Smartcard mode. •...
Page 780
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register. • When OVER8 = 0, BRR = USARTDIV. • When OVER8 = 1 – BRR[2:0] = USARTDIV[3:0] shifted 1 bit to the right. –...
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Table 141. Error calculation for programmed baud rates at f = 32 MHz in both cases of oversampling by 16 or by 8 Baud rate Oversampling by 16 (OVER8 = 0) Oversampling by 8 (OVER8 = 1) % Error = (Calculated - S.No...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 where DWU is the error due to sampling point deviation when the wakeup from Stop mode is used. when M[1:0] = 01: WUUSART -------------------------- - × Tbit when M[1:0] = 00: WUUSART -------------------------- - ×...
Page 783
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Note: The data specified in Table 142 Table 143 may slightly differ in the special case when the received frames contain some Idle frames of exactly 10-bit durations when M bits = 00 (11-bit durations when M bits =01 or 9- bit durations when M bits = 10). 29.5.6 USART auto baud rate detection The USART is able to detect and automatically set the USART_BRR register value based...
Page 784
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 detection range (bit duration not between 16 and 65536 clock periods (oversampling by 16) and not between 8 and 65536 clock periods (oversampling by 8)). The RXNE interrupt will signal the end of the operation. At any later time, the auto baud rate detection may be relaunched by resetting the ABRF flag (by writing a 0).
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Idle line detection (WAKE=0) The USART enters mute mode when the MMRQ bit is written to 1 and the RWU is automatically set. It wakes up when an Idle frame is detected. Then the RWU bit is cleared by hardware but the IDLE bit is not set in the USART_ISR register.
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 250. Mute mode using address mark detection In this example, the current address of the receiver is 1 (programmed in the USART_CR2 register) RXNE RXNE RXNE IDLE Addr=0 Data 1 Data 2 IDLE Addr=1 Data 3 Data 4 Addr=2 Data 5 Mute mode Normal mode...
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) 29.5.9 USART parity control Parity control (generation of parity bit in transmission and parity checking in reception) can be enabled by setting the PCE bit in the USART_CR1 register. Depending on the frame length defined by the M bits, the possible USART frame formats are as listed in Table 144.
Page 788
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 29.5.10 USART LIN (local interconnection network) mode This section is relevant only when LIN mode is supported. Please refer to Section 29.4: USART implementation on page 766. The LIN mode is selected by setting the LINEN bit in the USART_CR2 register. In LIN mode, the following bits must be kept cleared: •...
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Figure 251. Break detection in LIN mode (11-bit break length - LBDL bit is set) Case 1: break signal not long enough => break discarded, LBDF is not set Break frame RX line Capture strobe Break state Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 252. Break detection in LIN mode vs. Framing error detection Case 1: break occurring after an Idle RX line data 1 IDLE BREAK data 2 (0x55) data 3 (header) 1 data time 1 data time RXNE /FE LBDF Case 2: break occurring while data is being received...
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Note: The CK pin works in conjunction with the TX pin. Thus, the clock is provided only if the transmitter is enabled (TE=1) and data is being transmitted (the data register USART_TDR written). This means that it is not possible to receive synchronous data without transmitting data.
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 255. USART data clock timing diagram (M bits = 01) Idle or Idle or next preceding Start M bits =01 (9 data bits) Stop transmission transmission Clock (CPOL=0, CPHA=0) Clock (CPOL=0, CPHA=1) Clock (CPOL=1, CPHA=0) Clock (CPOL=1, CPHA=1)
Page 793
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) 29.5.12 USART Single-wire Half-duplex communication Single-wire Half-duplex mode is selected by setting the HDSEL bit in the USART_CR3 register. In this mode, the following bits must be kept cleared: • LINEN and CLKEN bits in the USART_CR2 register, •...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 257. ISO 7816-3 asynchronous protocol Without Parity error Guard time Start bit WithParity error Guard time Start bit Line pulled low by receiver during stop in case of parity error MSv31162V1 When connected to a smartcard, the TX output of the USART drives a bidirectional line that is also driven by the smartcard.
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) • In transmission, the USART inserts the Guard Time (as programmed in the Guard Time register) between two successive characters. As the Guard Time is measured after the stop bit of the previous character, the GT[7:0] register must be programmed to the desired CGT (Character Guard Time, as defined by the 7816-3 specification) minus 12 (the duration of one character).
Page 796
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Block mode (T=1) In T=1 (block) mode, the parity error transmission is deactivated, by clearing the NACK bit in the UART_CR3 register. When requesting a read from the smartcard, in block mode, the software must enable the receiver Timeout feature by setting the RTOEN bit in the USART_CR2 register and program the RTO bits field in the RTOR register to the BWT (block wait time) - 11 value.
Page 797
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Note: The error checking code (LRC/CRC) must be computed/verified by software. Direct and inverse convention The Smartcard protocol defines two conventions: direct and inverse. The direct convention is defined as: LSB first, logical bit value of 1 corresponds to a H state of the line and parity is even.
Page 798
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Method 2 The USART is programmed in 9-bit/no-parity mode, no bit inversion. In this mode it receives any of the two TS patterns as: (H) LHHL LLL LLH = 0x103 -> inverse convention to be chosen (H) LHHL HHH LLH = 0x13B ->...
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) • The IrDA specification requires the acceptance of pulses greater than 1.41 µs. The acceptable pulse width is programmable. Glitch detection logic on the receiver end filters out pulses of width less than 2 PSC periods (PSC is the prescaler value programmed in the USART_GTPR).
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 260. IrDA data modulation (3/16) -Normal Mode Stop Start IrDA_OUT Bit period 3/16 IrDA_IN MSv31165V1 29.5.15 USART continuous communication in DMA mode The USART is capable of performing continuous communication using the DMA. The DMA requests for Rx buffer and Tx buffer are generated independently.
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) In transmission mode, once the DMA has written all the data to be transmitted (the TCIF flag is set in the DMA_ISR register), the TC flag can be monitored to make sure that the USART communication is complete.
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) RS232 RTS and CTS flow control can be enabled independently by writing the RTSE and CTSE bits respectively to 1 (in the USART_CR3 register). RS232 RTS flow control If the RTS flow control is enabled (RTSE=1), then RTS is asserted (tied low) as long as the USART receiver is ready to receive a new data.
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Figure 265. RS232 CTS flow control Transmit data register Data 2 empty Data 3 empty Stop Start Stop Start Idle Data 1 Data 2 Data 3 Writing data 3 in TDR Transmission of Data 3 is delayed until CTS = 0 MSv31167V2 Note:...
Page 805
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Note: If the USART kernel clock is kept ON during Stop mode, there is no constraint on the maximum baud rate that allows waking up from Stop mode. It is the same as in Run mode. •...
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Let us take this example: OVER8 = 0, M bits = 10, ONEBIT = 1, BRR [3:0] = 0000. In these conditions, according to Table 142: Tolerance of the USART receiver when BRR [3:0] = 0000, the USART receiver tolerance is 4.86 %.
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Table 146. USART interrupt requests (continued) Enable Control Interrupt event Event flag Idle line detected IDLE IDLEIE Parity error PEIE LIN break LBDF LBDIE Noise Flag, Overrun error and Framing Error in multibuffer NF or ORE or FE communication.
Page 808
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 29.8 USART registers Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by words (32 bits). 29.8.1 USART control register 1 (USART_CR1) Address offset: 0x00 Reset value: 0x0000 0000 Res.
Page 809
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bits 20:16 DEDT[4:0]: Driver Enable de-assertion time This 5-bit value defines the time between the end of the last stop bit, in a transmitted message, and the de-activation of the DE (Driver Enable) signal. It is expressed in sample time units (1/8 or 1/16 bit duration, depending on the oversampling rate).
Page 810
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bit 8 PEIE: PE interrupt enable This bit is set and cleared by software. 0: Interrupt is inhibited 1: A USART interrupt is generated whenever PE=1 in the USART_ISR register Bit 7 TXEIE: interrupt enable This bit is set and cleared by software.
Page 811
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bit 2 RE: Receiver enable This bit enables the receiver. It is set and cleared by software. 0: Receiver is disabled 1: Receiver is enabled and begins searching for a start bit Bit 1 UESM: USART enable in Stop mode When this bit is cleared, the USART is not able to wake up the MCU from Stop mode.
Page 812
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bits 31:28 ADD[7:4]: Address of the USART node This bit-field gives the address of the USART node or a character code to be recognized. This is used in multiprocessor communication during Mute mode or Stop mode, for wakeup with 7- bit address mark detection.
Page 813
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bit 18 DATAINV: Binary data inversion This bit is set and cleared by software. 0: Logical data from the data register are send/received in positive/direct logic. (1=H, 0=L) 1: Logical data from the data register are send/received in negative/inverse logic. (1=L, 0=H). The parity bit is also inverted.
Page 814
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bit 11 CLKEN: Clock enable This bit allows the user to enable the CK pin. 0: CK pin disabled 1: CK pin enabled This bit can only be written when the USART is disabled (UE=0). Note: If neither synchronous mode nor Smartcard mode is supported, this bit is reserved and must be kept at reset value.
Page 815
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bit 5 LBDL: LIN break detection length This bit is for selection between 11 bit or 10 bit break detection. 0: 10-bit break detection 1: 11-bit break detection This bit can only be written when the USART is disabled (UE=0). Note: If LIN mode is not supported, this bit is reserved and must be kept at reset value.
Page 816
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bits 21:20 WUS[1:0]: Wakeup from Stop mode interrupt flag selection This bit-field specify the event which activates the WUF (wakeup from Stop mode flag). 00: WUF active on address match (as defined by ADD[7:0] and ADDM7) 01:Reserved.
Page 817
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bit 12 OVRDIS: Overrun Disable This bit is used to disable the receive overrun detection. 0: Overrun Error Flag, ORE, is set when received data is not read before receiving new data. 1: Overrun functionality is disabled. If new data is received while the RXNE flag is still set the ORE flag is not set and the new received data overwrites the previous content of the USART_RDR register.
Page 818
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bit 5 SCEN: Smartcard mode enable This bit is used for enabling Smartcard mode. 0: Smartcard Mode disabled 1: Smartcard Mode enabled This bit field can only be written when the USART is disabled (UE=0). Note: If the USART does not support Smartcard mode, this bit is reserved and must be kept at reset value.
Page 819
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) 29.8.4 USART baud rate register (USART_BRR) This register can only be written when the USART is disabled (UE=0). It may be automatically updated by hardware in auto baud rate detection mode. Address offset: 0x0C Reset value: 0x0000 0000 Res.
Page 820
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bits 31:16 Reserved, must be kept at reset value. Bits 15:8 GT[7:0]: Guard time value This bit-field is used to program the Guard time value in terms of number of baud clock periods. This is used in Smartcard mode. The Transmission Complete flag is set after this guard time value.
Page 821
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bits 31:24 BLEN[7:0]: Block Length This bit-field gives the Block length in Smartcard T=1 Reception. Its value equals the number of information characters + the length of the Epilogue Field (1-LEC/2-CRC) - 1. Examples: BLEN = 0 ->...
Page 822
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bits 31:5 Reserved, must be kept at reset value. Bit 4 TXFRQ: Transmit data flush request Writing 1 to this bit sets the TXE flag. This allows to discard the transmit data. This bit must be used only in Smartcard mode, when data has not been sent due to errors (NACK) and the FE flag is active in the USART_ISR register.
Page 823
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bit 22 REACK: Receive enable acknowledge flag This bit is set/reset by hardware, when the Receive Enable value is taken into account by the USART. When the wakeup from Stop mode is supported, the REACK flag can be used to verify that the USART is ready for reception before entering Stop mode.
Page 824
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bit 15 ABRF: Auto baud rate flag This bit is set by hardware when the automatic baud rate has been set (RXNE will also be set, generating an interrupt if RXNEIE = 1) or when the auto baud rate operation was completed without success (ABRE=1) (ABRE, RXNE and FE are also set in this case) It is cleared by software, in order to request a new auto baud rate detection, by writing 1 to the ABRRQ in the USART_RQR register.
Page 825
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bit 9 CTSIF: CTS interrupt flag This bit is set by hardware when the CTS input toggles, if the CTSE bit is set. It is cleared by software, by writing 1 to the CTSCF bit in the USART_ICR register. An interrupt is generated if CTSIE=1 in the USART_CR3 register.
Page 826
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bit 4 IDLE: Idle line detected This bit is set by hardware when an Idle Line is detected. An interrupt is generated if IDLEIE=1 in the USART_CR1 register. It is cleared by software, writing 1 to the IDLECF in the USART_ICR register.
Page 828
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Bit 3 ORECF: Overrun error clear flag Writing 1 to this bit clears the ORE flag in the USART_ISR register. Bit 2 NCF: Noise detected clear flag Writing 1 to this bit clears the NF flag in the USART_ISR register. Bit 1 FECF: Framing error clear flag Writing 1 to this bit clears the FE flag in the USART_ISR register.
RM0367 Universal synchronous/asynchronous receiver transmitter (USART/UART) Bits 31:9 Reserved, must be kept at reset value. Bits 8:0 TDR[8:0]: Transmit data value Contains the data character to be transmitted. The TDR register provides the parallel interface between the internal bus and the output shift register (see Figure 242).
Page 830
Universal synchronous/asynchronous receiver transmitter (USART/UART) RM0367 Table 147. USART register map and reset values (continued) Offset Register USART_ISR 0x1C Reset value USART_ICR 0x20 Reset value USART_RDR RDR[8:0] 0x24 Reset value X X X X X X X X X USART_TDR TDR[8:0] 0x28 Reset value...
Page 831
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Low-power universal asynchronous receiver transmitter (LPUART) 30.1 Introduction The low-power universal asynchronous receiver transmitted (LPUART) is an UART which allows Full-duplex UART communications with a limited power consumption. Only 32.768 kHz LSE clock is required to allow UART communications up to 9600 baud. Higher baud rates can be reached when the LPUART is clocked by clock sources different from the LSE clock.
Page 832
The LPUART enters mute mode if the address does not match. • Wakeup from mute mode (by idle line detection or address mark detection) 30.3 LPUART implementation The STM32L0x3 devices embed one LPUART. Refer to Section 29.4: USART implementation for LPUART supported features. 832/1043...
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Table 148. STM32L0x3 USART/LPUART features USART modes/features USART1/2 USART4 USART5 LPUART1 Hardware flow control for modem Continuous communication using DMA Multiprocessor communication Synchronous mode Smartcard mode Single-wire Half-duplex communication Ir SIR ENDEC block...
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 The following pins are required in RS232 Hardware flow control mode: • CTS: Clear To Send blocks the data transmission at the end of the current transfer when high • RTS: Request to send indicates that the LPUART is ready to receive data (when low). The following pin is required in RS485 Hardware control mode: •...
Page 835
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) 30.4.1 LPUART character description Word length may be selected as being either 7 or 8 or 9 bits by programming the M[1:0] bits in the LPUART_CR1 register (see Figure 268). • 7-bit character length: M[1:0] = 10 •...
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) 30.4.2 LPUART transmitter The transmitter can send data words of either 7 or 8 or 9 bits depending on the M bits status. The Transmit Enable bit (TE) must be set in order to activate the transmitter function. The data in the transmit shift register is output on the TX pin.
Page 838
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Character transmission procedure Program the M bits in LPUART_CR1 to define the word length. Select the desired baud rate using the LPUART_BRR register. Program the number of stop bits in LPUART_CR2. Enable the LPUART by writing the UE bit in LPUART_CR1 register to 1. Select DMA enable (DMAT) in LPUART_CR3 if multibuffer Communication is to take place.
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Figure 270. TC/TXE behavior when transmitting Idle preamble Frame 1 Frame 2 Frame 3 TX line Set by hardware Set by hardware cleared by software cleared by software TXE flag Set by hardware LPUART_DR Set by hardware TC flag...
Page 840
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Character reception During an LPUART reception, data shifts in least significant bit first (default configuration) through the RX pin. In this mode, the LPUART_RDR register consists of a buffer (RDR) between the internal bus and the received shift register. Character reception procedure Program the M bits in LPUART_CR1 to define the word length.
Page 841
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Overrun error An overrun error occurs when a character is received when RXNE has not been reset. Data can not be transferred from the shift register to the RDR register until the RXNE bit is cleared.
Page 842
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Framing error A framing error is detected when the stop bit is not recognized on reception at the expected time, following either a de-synchronization or excessive noise. When the framing error is detected: •...
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 30.4.5 Tolerance of the LPUART receiver to clock deviation The asynchronous receiver of the LPUART works correctly only if the total clock system deviation is less than the tolerance of the LPUART receiver. The causes which contribute to the total deviation are: •...
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Figure 271. Mute mode using Idle line detection RXNE RXNE Data 1 Data 2 Data 3 Data 4 IDLE Data 5 Data 6 Mute mode Normal mode MMRQ written to 1 Idle frame detected MSv31154V1 Note: If the MMRQ is set while the IDLE character has already elapsed, mute mode will not be...
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Figure 272. Mute mode using address mark detection In this example, the current address of the receiver is 1 (programmed in the LPUART_CR2 register) RXNE RXNE RXNE IDLE Addr=0 Data 1 Data 2 IDLE Addr=1 Data 3 Data 4 Addr=2 Data 5 Mute mode...
Page 848
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Parity checking in reception If the parity check fails, the PE flag is set in the LPUART_ISR register and an interrupt is generated if PEIE is set in the LPUART_CR1 register. The PE flag is cleared by software writing 1 to the PECF in the LPUART_ICR register.
Page 849
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Transmission using DMA DMA mode can be enabled for transmission by setting DMAT bit in the LPUART_CR3 register. Data is loaded from a SRAM area configured using the DMA peripheral (refer to Section Direct memory access controller (DMA)) to the LPUART_TDR register whenever the TXE bit is set.
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Figure 273. Transmission using DMA Idle preamble Frame 2 Frame 1 Frame 3 TX line Set by hardware cleared by Set by hardware cleared DMA read by DMA read TXE flag Set by hardware Ignored by the DMA because the transfer DMA request is complete...
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Figure 274. Reception using DMA Frame 2 Frame 1 Frame 3 TX line Set by hardware cleared by DMA read RXNE flag DMA request LPUART_RDR DMA reads LPUART_RDR Cleared by DMA TCIF flag Set by hardware software (transfer complete)
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 RS232 RTS flow control If the RTS flow control is enabled (RTSE=1), then RTS is asserted (tied low) as long as the LPUART receiver is ready to receive a new data. when the receive register is full, RTS is de- asserted, indicating that the transmission is expected to stop at the end of the current frame.
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Figure 277. RS232 CTS flow control Transmit data register Data 2 empty Data 3 empty Stop Start Stop Start Idle Data 1 Data 2 Data 3 Writing data 3 in TDR Transmission of Data 3 is delayed until CTS = 0 MSv31167V2 Note:...
Page 854
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 30.4.11 Wakeup from Stop mode using LPUART The LPUART is able to wake up the MCU from Stop modewhen the UESM bit is set and the LPUART clock is set to HSI or LSE (refer to the Reset and clock control (RCC) section. •...
Page 855
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Using Mute mode with Stop mode If the LPUART is put into Mute mode before entering Stop mode: • Wakeup from Mute mode on idle detection must not be used, because idle detection cannot work in Stop mode.
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 30.5 LPUART in low-power mode Table 153. Effect of low-power modes on the LPUART Mode Description Sleep No effect. USART interrupt causes the device to exit Sleep mode. Low-power run No effect. No effect. USART interrupt causes the device to exit Low-power sleep Low-power sleep mode.
Page 858
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 30.7 LPUART registers Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by words (32 bits). 30.7.1 Control register 1 (LPUART_CR1) Address offset: 0x00 Reset value: 0x0000 Res.
Page 859
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Bit 13 MME: Mute mode enable This bit activates the mute mode function of the LPUART. When set, the LPUART can switch between the active and mute modes, as defined by the WAKE bit. It is set and cleared by software.
Page 860
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Bit 4 IDLEIE: IDLE interrupt enable This bit is set and cleared by software. 0: Interrupt is inhibited 1: An LPUART interrupt is generated whenever IDLE=1 in the LPUART_ISR register Bit 3 TE: Transmitter enable This bit enables the transmitter.
Page 862
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Bit 16 RXINV: RX pin active level inversion This bit is set and cleared by software. 0: RX pin signal works using the standard logic levels (V =1/idle, Gnd=0/mark) 1: RX pin signal values are inverted. ((V =0/mark, Gnd=1/idle).
Page 864
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Bit 13 DDRE: DMA Disable on Reception Error 0: DMA is not disabled in case of reception error. The corresponding error flag is set but RXNE is kept 0 preventing from overrun. As a consequence, the DMA request is not asserted, so the erroneous data is not transferred (no DMA request), but next correct received data will be transferred.
Page 865
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Bit 3 HDSEL: Half-duplex selection Selection of Single-wire Half-duplex mode 0: Half duplex mode is not selected 1: Half duplex mode is selected This bit can only be written when the LPUART is disabled (UE=0). Bits 2:1 Reserved, must be kept at reset value.
Page 866
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Bits 31:4 Reserved, must be kept at reset value Bit 3 RXFRQ: Receive data flush request Writing 1 to this bit clears the RXNE flag. This allows to discard the received data without reading it, and avoid an overrun condition. Bit 2 MMRQ: Mute mode request Writing 1 to this bit puts the LPUART in mute mode and resets the RWU flag.
Page 867
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Bit 19 RWU: Receiver wakeup from Mute mode This bit indicates if the LPUART is in mute mode. It is cleared/set by hardware when a wakeup/mute sequence is recognized. The mute mode control sequence (address or IDLE) is selected by the WAKE bit in the LPUART_CR1 register.
Page 868
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Bit 7 TXE: Transmit data register empty This bit is set by hardware when the content of the LPUART_TDR register has been transferred into the shift register. It is cleared by a write to the LPUART_TDR register. An interrupt is generated if the TXEIE bit =1 in the LPUART_CR1 register.
Page 869
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Bit 2 NF: START bit Noise detection flag This bit is set by hardware when noise is detected on the START bit of a received frame. It is cleared by software, writing 1 to the NFCF bit in the LPUART_ICR register. 0: No noise is detected 1: Noise is detected Note: This bit does not generate an interrupt as it appears at the same time as the RXNE bit...
Page 870
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 Bit 6 TCCF: Transmission complete clear flag Writing 1 to this bit clears the TC flag in the LPUART_ISR register. Bit 5 Reserved, must be kept at reset value. Bit 4 IDLECF: Idle line detected clear flag Writing 1 to this bit clears the IDLE flag in the LPUART_ISR register.
Page 871
RM0367 Low-power universal asynchronous receiver transmitter (LPUART) Bits 31:9 Reserved, must be kept at reset value. Bits 8:0 TDR[8:0]: Transmit data value Contains the data character to be transmitted. The TDR register provides the parallel interface between the internal bus and the output shift register (see Figure 242).
Low-power universal asynchronous receiver transmitter (LPUART) RM0367 30.7.10 LPUART register map The table below gives the LPUART register map and reset values. Table 155. LPUART register map and reset values Offset Register LPUART_ 0x00 Reset value LPUART_ STOP ADD[7:4] ADD[3:0] [1:0] 0x04 Reset value...
Page 873
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Serial peripheral interface/ inter-IC sound (SPI/I2S) 31.1 Introduction The SPI/I²S interface can be used to communicate with external devices using the SPI protocol or the I S audio protocol. SPI or I S mode is selectable by software. SPI mode is selected by default after a device reset.
256 × F (where F is the audio sampling frequency) 31.2 SPI/I2S implementation This manual describes the full set of features implemented in SPI1 and SPI2. Table 156. STM32L0x3 SPI implementation Features SPI1 SPI2 Hardware CRC calculation I2S mode TI mode 1.
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) 31.3 SPI functional description 31.3.1 General description The SPI allows synchronous, serial communication between the MCU and external devices. Application software can manage the communication by polling the status flag or using dedicated SPI interrupt. The main elements of SPI and their interactions are shown in the following block diagram Figure 279.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 31.3.2 Communications between one master and one slave The SPI allows the MCU to communicate using different configurations, depending on the device targeted and the application requirements. These configurations use 2 or 3 wires (with software NSS management) or 3 or 4 wires (with hardware NSS management).
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Figure 281. Half-duplex single master/ single slave application MISO MISO Rx shift register Tx shift register 1kΩ MOSI MOSI Tx shift register Rx shift register SPI clock generator Master Slave MSv39624V1 1. The NSS pins can be used to provide a hardware control flow between master and slave. Optionally, the pins can be left unused by the peripheral.
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) 31.3.3 Standard multi-slave communication In a configuration with two or more independent slaves, the master uses GPIO pins to manage the chip select lines for each slave (see Figure 283.). The master must select one of the slaves individually by pulling low the GPIO connected to the slave NSS input.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 31.3.4 Multi-master communication Unless SPI bus is not designed for a multi-master capability primarily, the user can use build in feature which detects a potential conflict between two nodes trying to master the bus at the same time.
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) – NSS output enable (SSM=0,SSOE = 1): this configuration is only used when the MCU is set as master. The NSS pin is managed by the hardware. The NSS signal is driven low as soon as the SPI is enabled in master mode (SPE=1), and is kept low until the SPI is disabled (SPE =0).
Page 882
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 31.3.6 Communication formats During SPI communication, receive and transmit operations are performed simultaneously. The serial clock (SCK) synchronizes the shifting and sampling of the information on the data lines. The communication format depends on the clock phase, the clock polarity and the data frame format.
Page 884
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 31.3.7 SPI configuration The configuration procedure is almost the same for master and slave. For specific mode setups, follow the dedicated chapters. When a standard communication is to be initialized, perform these steps: Write proper GPIO registers: Configure GPIO for MOSI, MISO and SCK pins.
Page 885
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Refer to Section 31.3.11: Communication using DMA (direct memory addressing) for details on how to handle DMA. 31.3.9 Data transmission and reception procedures Rx and Tx buffers In reception, data are received and then stored into an internal Rx buffer while in transmission, data are first stored into an internal Tx buffer before being transmitted.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 While the master can provide all the transactions in continuous mode (SCK signal is continuous), it has to respect slave capability to handle data flow and its content at anytime. When necessary, the master must slow down the communication and provide either a slower clock or separate frames or data sessions with sufficient delays.
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Figure 288. TXE/RXNE/BSY behavior in slave / full-duplex mode (BIDIMODE=0, RXONLY=0) in the case of continuous transfers Example in Slave mode with CPOL=1, CPHA=1 DATA 1 = 0xF1 DATA 2 = 0xF2 DATA 3 = 0xF3 MISO/MOSI (out) b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7 set by hardware...
Page 888
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 Note: During discontinuous communications, there is a 2 APB clock period delay between the write operation to the SPI_DR register and BSY bit setting. As a consequence it is mandatory to wait first until TXE is set and then until BSY is cleared after writing the last data.
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) To close communication it is mandatory to follow these steps in order: Disable DMA streams for Tx and Rx in the DMA registers, if the streams are used. Disable the SPI by following the SPI disable procedure. Disable DMA Tx and Rx buffers by clearing the TXDMAEN and RXDMAEN bits in the SPI_CR2 register, if DMA Tx and/or DMA Rx are used.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 Figure 290. Reception using DMA Example with CPOL=1, CPHA=1 DATA 1 = 0xA1 DATA 2 = 0xA2 DATA 3 = 0xA3 MISO/MOSI (in) b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7 set by hardware clear by DMA read RXNE flag...
Page 891
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) The BSY flag is cleared under any one of the following conditions: • When the SPI is correctly disabled • When a fault is detected in Master mode (MODF bit set to 1) •...
Page 892
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 CRC error (CRCERR) This flag is used to verify the validity of the value received when the CRCEN bit in the SPIx_CR1 register is set. The CRCERR flag in the SPIx_SR register is set if the value received in the shift register does not match the receiver SPIx_RXCRC value.
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Note: To detect TI frame errors in slave transmitter only mode by using the Error interrupt (ERRIE=1), the SPI must be configured in 2-line unidirectional mode by setting BIDIMODE and BIDIOE to 1 in the SPI_CR1 register. When BIDIMODE is set to 0, OVR is set to 1 because the data register is never read and error interrupts are always generated, while when BIDIMODE is set to 1, data are not received and OVR is never set.
Page 894
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 The received CRC is stored in the Rx buffer like any other data frame. A CRC-format transaction takes one more data frame to communicate at the end of data sequence. When the last CRC data is received, an automatic check is performed comparing the received value and the value in the SPIx_RXCRC register.
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) 31.5 SPI interrupts During SPI communication an interrupts can be generated by the following events: • Transmit Tx buffer ready to be loaded • Data received in Rx buffer • Master mode fault •...
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 31.6 S functional description 31.6.1 S general description The block diagram of the I S is shown in Figure 292. Figure 292. I S block diagram Address and data bus Tx buffer BSY OVR MODF TxE RxNE 16-bit SIDE...
Page 897
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) The I S shares three common pins with the SPI: • SD: Serial Data (mapped on the MOSI pin) to transmit or receive the two time- multiplexed data channels (in half-duplex mode only). •...
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) The I S interface supports four audio standards, configurable using the I2SSTD[1:0] and PCMSYNC bits in the SPIx_I2SCFGR register. S Philips standard For this standard, the WS signal is used to indicate which channel is being transmitted. It is activated one CK clock cycle before the first bit (MSB) is available.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 • In transmission mode: If 0x8EAA33 has to be sent (24-bit): Figure 296. Transmitting 0x8EAA33 First write to Data register Second write to Data register 0x8EAA 0x33XX Only the 8 MSB are sent to compare the 24 bits 8 LSBs have no meaning and can be anything...
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Figure 299. Example of 16-bit data frame extended to 32-bit channel frame Only one access to SPIx_DR 0x76A3 MS19595V1 For transmission, each time an MSB is written to SPIx_DR, the TXE flag is set and its interrupt, if allowed, is generated to load the SPIx_DR register with the new value to send.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 Figure 302. MSB justified 16-bit extended to 32-bit packet frame with CPOL = 0 Transmission Reception 16-bit data 16-bit remaining 0 forced Channel left 32-bit Channel right MS30102V1 LSB justified standard This standard is similar to the MSB justified standard (no difference for the 16-bit and 32-bit full-accuracy frame formats).
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) • In transmission mode: If data 0x3478AE have to be transmitted, two write operations to the SPIx_DR register are required by software or by DMA. The operations are shown below. Figure 305. Operations required to transmit 0x3478AE First write to Data register Second write to Data register conditioned by TXE=1...
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 Figure 308. Example of 16-bit data frame extended to 32-bit channel frame Only one access to the SPIx-DR register 0x76A3 MS19598V1 In transmission mode, when a TXE event occurs, the application has to write the data to be transmitted (in this case 0x76A3).
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Note: For both modes (master and slave) and for both synchronizations (short and long), the number of bits between two consecutive pieces of data (and so two synchronization signals) needs to be specified (DATLEN and CHLEN bits in the SPIx_I2SCFGR register) even in slave mode.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 The audio sampling frequency may be 192 KHz, 96 kHz, 48 kHz, 44.1 kHz, 32 kHz, 22.05 kHz, 16 kHz, 11.025 kHz or 8 kHz (or any other value within this range). In order to reach the desired frequency, the linear divider needs to be programmed according to the formulas below: When the master clock is generated (MCKOE in the SPIx_I2SPR register is set):...
Page 907
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Table 158. Audio-frequency precision using standard 8 MHz HSE (continued) I2SxCLK Data I2SDIV I2SODD MCLK Target fs(Hz) Real f (kHz) Error (MHz) length 11025 11.363 3.0715% 8000 7.812 2.3428% 8000 7.812 2.3428% 31.6.5 S master mode The I S can be configured in master mode.
Page 908
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 set after each transfer from the Tx buffer to the shift register and an interrupt is generated if the TXEIE bit in the SPIx_CR2 register is set. For more details about the write operations depending on the I S Standard-mode selected, refer to Section 31.6.3: Supported audio...
Page 909
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) • For all other combinations of DATLEN and CHLEN, whatever the audio mode selected through the I2SSTD bits, carry out the following sequence to switch off the I Wait for the second to last RXNE = 1 (n – 1) Then wait one I S clock cycle (using a software loop) Disable the I...
Page 910
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 For more details about the write operations depending on the I S Standard-mode selected, refer to Section 31.6.3: Supported audio protocols. To secure a continuous audio data transmission, it is mandatory to write the SPIx_DR register with the next data to transmit before the end of the current transmission.
Page 911
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) The BSY flag is useful to detect the end of a transfer if the software needs to disable the I This avoids corrupting the last transfer. For this, the procedure described below must be strictly respected.
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 ERRIE bit in the SPIx_CR2 register is set. The UDR bit is cleared by a read operation on the SPIx_SR register. Overrun flag (OVR) This flag is set when data are received and the previous data have not yet been read from the SPIx_DR register.
Page 913
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) 31.7 SPI and I S registers The peripheral registers can be accessed by half-words (16-bit) or words (32-bit). In addition, SPI_DR can be accessed by 8-bit. Refer to Section 1.2 for a list of abbreviations used in register descriptions. 31.7.1 SPI control register 1 (SPI_CR1) (not used in I S mode)
Page 914
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 Bit 10 RXONLY: Receive only mode enable This bit enables simplex communication using a single unidirectional line to receive data exclusively. Keep BIDIMODE bit clear when receive only mode is active. This bit is also useful in a multislave system in which this particular slave is not accessed, the output from the accessed slave is not corrupted.
Page 915
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Bit 2 MSTR: Master selection 0: Slave configuration 1: Master configuration Note: This bit should not be changed when communication is ongoing. It is not used in I S mode. Bit1 CPOL: Clock polarity 0: CK to 0 when idle 1: CK to 1 when idle Note: This bit should not be changed when communication is ongoing.
Page 916
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 Bit 2 SSOE: SS output enable 0: SS output is disabled in master mode and the cell can work in multimaster configuration 1: SS output is enabled in master mode and when the cell is enabled. The cell cannot work in a multimaster environment.
Page 917
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Bit 5 MODF: Mode fault 0: No mode fault occurred 1: Mode fault occurred This flag is set by hardware and reset by a software sequence. Refer to Section 31.4 on page 892 for the software sequence.
Page 918
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 31.7.4 SPI data register (SPI_DR) Address offset: 0x0C Reset value: 0x0000 DR[15:0] Bits 15:0 DR[15:0]: Data register Data received or to be transmitted. The data register is split into 2 buffers - one for writing (Transmit Buffer) and another one for reading (Receive buffer).
Page 919
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) 31.7.6 SPI RX CRC register (SPI_RXCRCR) (not used in I S mode) Address offset: 0x14 Reset value: 0x0000 RXCRC[15:0] Bits 15:0 RXCRC[15:0]: Rx CRC register When CRC calculation is enabled, the RxCRC[15:0] bits contain the computed CRC value of the subsequently received bytes.
Page 920
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0367 31.7.8 SPI_I S configuration register (SPI_I2SCFGR) Address offset: 0x1C Reset value: 0x0000 PCMSY Res. Res. Res. Res. I2SMOD I2SE I2SCFG Res. I2SSTD CKPOL DATLEN CHLEN Bits 15:12 Reserved, must be kept at reset value. Bit 11 I2SMOD: I2S mode selection 0: SPI mode is selected 1: I2S mode is selected...
Page 921
RM0367 Serial peripheral interface/ inter-IC sound (SPI/I2S) Bit 3 CKPOL: Steady state clock polarity 0: I S clock steady state is low level 1: I S clock steady state is high level Note: For correct operation, this bit should be configured when the I S is disabled.
USB_DP line) 32.3 USB implementation Table 161 describes the USB implementation in the devices. Table 161. STM32L0x3 USB implementation USB features Number of endpoints Size of dedicated packet buffer memory SRAM 1024 bytes Dedicated packet buffer memory SRAM access scheme 2 x 16 bits / word USB 2.0 Link Power Management (LPM) support...
Universal serial bus full-speed device interface (USB) RM0367 32.4 USB functional description Figure 313 shows the block diagram of the USB peripheral. Figure 313. USB peripheral block diagram USB PHY USB clock (48 MHz) Embedded Analog pull-up PCLK transceiver Clock Control RX-TX registers and logic...
Page 925
RM0367 Universal serial bus full-speed device interface (USB) place. The data buffered by the USB peripheral is loaded in an internal 16-bit register and memory access to the dedicated buffer is performed. When all the data has been transferred, if needed, the proper handshake packet over the USB is generated or expected according to the direction of the transfer.
Page 926
Universal serial bus full-speed device interface (USB) RM0367 • Endpoint-Related Registers: Each endpoint has an associated register containing the endpoint type and its current status. For mono-directional/single-buffer endpoints, a single register can be used to implement two distinct endpoints. The number of registers is 8, allowing up to 16 mono-directional/single-buffer or up to 7 double-buffer endpoints in any combination.
Page 927
RM0367 Universal serial bus full-speed device interface (USB) 32.5.2 System and power-on reset Upon system and power-on reset, the first operation the application software should perform is to provide all required clock signals to the USB peripheral and subsequently de-assert its reset signal so to be able to access its registers.
Universal serial bus full-speed device interface (USB) RM0367 back accesses. The USB peripheral logic uses a dedicated clock. The frequency of this dedicated clock is fixed by the requirements of the USB standard at 48 MHz, and this can be different from the clock used for the interface to the APB bus.
Page 929
RM0367 Universal serial bus full-speed device interface (USB) Each packet buffer is used either during reception or transmission starting from the bottom. The USB peripheral will never change the contents of memory locations adjacent to the allocated memory buffers; if a packet bigger than the allocated buffer length is received (buffer overrun condition) the data will be copied to the memory only up to the last available location.
Page 930
Universal serial bus full-speed device interface (USB) RM0367 indicating a flow control condition: the USB host will retry the transaction until it succeeds. It is mandatory to execute the sequence of operations in the above mentioned order to avoid losing the notification of a second IN transaction addressed to the same endpoint immediately following the one which triggered the CTR interrupt.
Page 931
RM0367 Universal serial bus full-speed device interface (USB) processed. After the received data is processed, the application software should set the STAT_RX bits to ‘11 (Valid) in the USB_EPnR, enabling further transactions. While the STAT_RX bits are equal to ‘10 (NAK), any OUT request addressed to that endpoint is NAKed, indicating a flow control condition: the USB host will retry the transaction until it succeeds.
Page 932
Universal serial bus full-speed device interface (USB) RM0367 32.5.3 Double-buffered endpoints All different endpoint types defined by the USB standard represent different traffic models, and describe the typical requirements of different kind of data transfer operations. When large portions of data are to be transferred between the host PC and the USB function, the bulk endpoint type is the most suited model.
RM0367 Universal serial bus full-speed device interface (USB) Table 162. Double-buffering buffer flag definition Buffer flag ‘Transmission’ endpoint ‘Reception’ endpoint DTOG DTOG_TX (USB_EPnR bit 6) DTOG_RX (USB_EPnR bit 14) SW_BUF USB_EPnR bit 14 USB_EPnR bit 6 The memory buffer which is currently being used by the USB peripheral is defined by DTOG buffer flag, while the buffer currently in use by application software is identified by SW_BUF buffer flag.
Page 934
Universal serial bus full-speed device interface (USB) RM0367 DBL_BUF setting, STAT bit pair is not affected by the transaction termination and its value remains ‘11 (Valid). However, as the token packet of a new transaction is received, the actual endpoint status will be masked as ‘10 (NAK) when a buffer conflict between the USB peripheral and the application software is detected (this condition is identified by DTOG and SW_BUF having the same value, see Table 163 on page...
RM0367 Universal serial bus full-speed device interface (USB) Table 164. Isochronous memory buffers usage Endpoint DTOG bit Packet buffer used by the Packet buffer used by the Type value USB peripheral application software ADDRn_TX_0 / COUNTn_TX_0 ADDRn_TX_1 / COUNTn_TX_1 buffer description table buffer description table locations.
Universal serial bus full-speed device interface (USB) RM0367 The actual procedure used to suspend the USB peripheral is device dependent since according to the device composition, different actions may be required to reduce the total consumption. A brief description of a typical suspend procedure is provided below, focused on the USB- related aspects of the application software routine responding to the SUSP notification of the USB peripheral: Set the FSUSP bit in the USB_CNTR register to 1.
Page 937
RM0367 Universal serial bus full-speed device interface (USB) Table 165. Resume event detection (continued) [RXDP,RXDM] status Wakeup event Required resume software action “01” Root resume None “11” Not allowed (noise on bus) Go back in Suspend mode A device may require to exit from suspend mode as an answer to particular events not directly related to the USB protocol (e.g.
Page 938
Universal serial bus full-speed device interface (USB) RM0367 32.6 USB and USB SRAM registers The USB peripheral registers can be divided into the following groups: • Common Registers: Interrupt and Control registers • Endpoint Registers: Endpoint configuration and status The USB SRAM registers cover: •...
Page 939
RM0367 Universal serial bus full-speed device interface (USB) Bit 11 SUSPM: Suspend mode interrupt mask 0: Suspend Mode Request (SUSP) Interrupt disabled. 1: SUSP Interrupt enabled, an interrupt request is generated when the corresponding bit in the USB_ISTR register is set. Bit 10 RESETM: USB reset interrupt mask 0: RESET Interrupt disabled.
Page 940
Universal serial bus full-speed device interface (USB) RM0367 Bit 1 PDWN: Power down This bit is used to completely switch off all USB-related analog parts if it is required to completely disable the USB peripheral for any reason. When this bit is set, the USB peripheral is disconnected from the transceivers and it cannot be used.
Page 941
RM0367 Universal serial bus full-speed device interface (USB) could be set by the hardware and the next write will clear it before the microprocessor has the time to serve the event. The following describes each bit in detail: Bit 15 CTR: Correct transfer This bit is set by the hardware to indicate that an endpoint has successfully completed a transaction;...
Page 942
Universal serial bus full-speed device interface (USB) RM0367 Bit 10 RESET: USB reset request Set when the USB peripheral detects an active USB RESET signal at its inputs. The USB peripheral, in response to a RESET, just resets its internal protocol state machine, generating an interrupt if RESETM enable bit in the USB_CNTR register is set.
Page 943
RM0367 Universal serial bus full-speed device interface (USB) Bits 3:0 EP_ID[3:0]: Endpoint Identifier These bits are written by the hardware according to the endpoint number, which generated the interrupt request. If several endpoint transactions are pending, the hardware writes the endpoint identifier related to the endpoint having the highest priority defined in the following way: Two endpoint sets are defined, in order of priority: Isochronous and double-buffered bulk endpoints are considered first and then the other endpoints are examined.
Page 944
Universal serial bus full-speed device interface (USB) RM0367 Res. Res. Res. Res. Res. Res. Res. Res. ADD6 ADD5 ADD4 ADD3 ADD2 ADD1 ADD0 Bits 15:8 Reserved Bit 7 EF: Enable function This bit is set by the software to enable the USB device. The address of this device is contained in the following ADD[6:0] bits.
Page 945
RM0367 Universal serial bus full-speed device interface (USB) Bits 15:8 Reserved, must be kept at reset value. Bits 7:4 BESL[3:0]: BESL value These bits contain the BESL value received with last ACKed LPM Token Bit 3 REMWAKE: bRemoteWake value This bit contains the bRemoteWake value received with last ACKed LPM Token Bit 2 Reserved Bit 1 LPMACK: LPM Token acknowledge enable 0: the valid LPM Token will be NYET.
Page 946
Universal serial bus full-speed device interface (USB) RM0367 Bit 4 DCDET: Data contact detection (DCD) status This bit gives the result of DCD. 0: data lines contact not detected. 1: data lines contact detected. Bit 3 SDEN: Secondary detection (SD) mode enable This bit is set by the software to put the BCD into SD mode.
Page 947
RM0367 Universal serial bus full-speed device interface (USB) Bit 15 CTR_RX: Correct transfer for reception This bit is set by the hardware when an OUT/SETUP transaction is successfully completed on this endpoint; the software can only clear this bit. If the CTRM bit in USB_CNTR register is set accordingly, a generic interrupt condition is generated together with the endpoint related interrupt condition, which is always activated.
Page 948
Universal serial bus full-speed device interface (USB) RM0367 Bits 10:9 EP_TYPE[1:0]: Endpoint type These bits configure the behavior of this endpoint as described in Table 167: Endpoint type encoding on page 949. Endpoint 0 must always be a control endpoint and each USB function must have at least one control endpoint which has address 0, but there may be other control endpoints if required.
RM0367 Universal serial bus full-speed device interface (USB) Bits 5:4 STAT_TX [1:0]: Status bits, for transmission transfers These bits contain the information about the endpoint status, listed in Table 169. These bits can be toggled by the software to initialize their value. When the application software writes ‘0, the value remains unchanged, while writing ‘1 makes the bit value toggle.
Universal serial bus full-speed device interface (USB) RM0367 Table 169. Transmission status encoding STAT_TX[1:0] Meaning DISABLED: all transmission requests addressed to this endpoint are ignored. STALL: the endpoint is stalled and all transmission requests result in a STALL handshake. NAK: the endpoint is naked and all transmission requests result in a NAK handshake.
Page 951
RM0367 Universal serial bus full-speed device interface (USB) 32.6.2 Buffer descriptor table Note: The buffer descriptor table is located inside the packet buffer memory in the separate "USB SRAM" address space. Although the buffer descriptor table is located inside the packet buffer memory ("USB SRAM"...
Page 952
Universal serial bus full-speed device interface (USB) RM0367 Bits 15:10 These bits are not used since packet size is limited by USB specifications to 1023 bytes. Their value is not considered by the USB peripheral. Bits 9:0 COUNTn_TX[9:0]: Transmission byte count These bits contain the number of bytes to be transmitted by the endpoint associated with the USB_EPnR register at the next IN token addressed to it.
RM0367 Universal serial bus full-speed device interface (USB) enumeration process according to its maxPacketSize parameter value (See “Universal Serial Bus Specification”). Bit 15 BL_SIZE: Block size This bit selects the size of memory block used to define the allocated buffer area. –...
Universal serial bus full-speed device interface (USB) RM0367 32.6.3 USB register map The table below provides the USB register map and reset values. Table 171. USB register map and reset values Offset Register STAT_ STAT_ USB_EP0R TYPE EA[3:0] 0x00 [1:0] [1:0] [1:0] Reset value...
Page 955
RM0367 Universal serial bus full-speed device interface (USB) Table 171. USB register map and reset values (continued) Offset Register USB_BTABLE BTABLE[15:3] 0x50 Reset value USB_LPMCSR BESL[3:0] 0x54 Reset value USB_BCDR 0x58 Reset value Refer to Section 2.2 on page 58 for the register boundary addresses.
The debug features are used by the debugger host when connecting to and debugging the STM32L0x3 MCUs. One interface for debug is available: • Serial wire ® Figure 315. Block diagram of STM32L0x3 MCU and Cortex -M0+-level debug support STM32 MCU debug suppo rt Cortex-M0 debug support Bus matrix System...
• CoreSight Design Kit revision r1p1 Technical Reference Manual 33.3 Pinout and debug port pins The STM32L0x3 MCUs are available in various packages with different numbers of available pins. 33.3.1 SWD port pins Two pins are used as outputs for the SW-DP as alternate functions of general purpose I/Os.
Page 958
33.4.1 MCU device ID code The STM32L0x3 products integrate an MCU ID code. This ID identifies the ST MCU part number and the die revision. This code is accessible by the software debug port (two pins) or by the user software.
RM0367 Debug support (DBG) Table 173. REV-ID values REV_ID Cat. 3 devices Cat. 5 devices 0x1000 Rev A 0x1008 Rev Z 0x1018 Rev Y 0x1038 Rev X 0x2000 Rev B 0x2008 Rev Z 33.5 SWD port 33.5.1 SWD protocol introduction This synchronous serial protocol uses two pins: •...
Debug support (DBG) RM0367 Table 174. Packet request (8-bits) (continued) Name Description Parity Single bit parity of preceding bits Stop Not driven by the host. Must be read as “1” by the target Park because of the pull-up ® Refer to the Cortex -M0+ TRM for a detailed description of DPACC and APACC registers.
RM0367 Debug support (DBG) 33.5.4 DP and AP read/write accesses • Read accesses to the DP are not posted: the target response can be immediate (if ACK=OK) or can be delayed (if ACK=WAIT). • Read accesses to the AP are posted. This means that the result of the access is returned on the next transfer.
Debug support (DBG) RM0367 Table 177. SW-DP registers (continued) CTRLSEL bit A[3:2] of SELECT Register Notes register The purpose is to select the current access Write SELECT port and the active 4-words register window This read buffer is useful because AP accesses are posted (the result of a read AP request is available on the next AP transaction).
RM0367 Debug support (DBG) 33.6 Core debug Core debug is accessed through the core debug registers. Debug access to these registers is by means of the debug access port. It consists of four registers: Table 179. Core debug registers Register Description The 32-bit Debug Halting Control and Status Register DHCSR...
Page 964
Debug support (DBG) RM0367 33.8 DWT (Data Watchpoint) ® The Cortex -M0+ DWT implementation provides two watchpoint register sets. 33.8.1 DWT functionality The processor watchpoints implement both data address and PC based watchpoint functionality, a PC sampling register, and support comparator address masking, as ®...
Page 965
RM0367 Debug support (DBG) 33.9.2 Debug support for timers, watchdog and I During a breakpoint, it is necessary to choose how the counter of timers and watchdog should behave: • They can continue to count inside a breakpoint. This is usually required when a PWM is controlling a motor, for example.
Page 966
Debug support (DBG) RM0367 Bits 31:3 Reserved, must be kept at reset value. Bit 2 DBG_STANDBY: Debug Standby mode 0: (FCLK=Off, HCLK=Off) The whole digital part is unpowered. From software point of view, exiting from Standby is identical than fetching reset vector (except a few status bit indicated that the MCU is resuming from Standby) 1: (FCLK=On, HCLK=On) In this case, the digital part is not unpowered and FCLK and HCLK are provided by the internal RC oscillator which remains active.
Page 967
RM0367 Debug support (DBG) 33.9.4 Debug MCU APB1 freeze register (DBG_APB1_FZ) The DBG_APB1_FZ register is used to configure the following APB peripherals, when the MCU under debug: • Timer clock counter freeze • I2C SMBUS timeout freeze • System window watchdog and independent watchdog counter freeze support. This register is mapped at address 0x4001 5808.
Page 968
Debug support (DBG) RM0367 Bit 11 DBG_WWDG_STOP: Debug window watchdog stopped when core is halted 0: The window watchdog counter clock continues even if the core is halted 1: The window watchdog counter clock is stopped when the core is halted Bit 10 DBG_RTC_STOP: Debug RTC stopped when core is halted 0: The clock of the RTC counter is fed even if the core is halted 1: The clock of the RTC counter is stopped when the core is halted...
Page 969
RM0367 Debug support (DBG) 33.9.5 Debug MCU APB2 freeze register (DBG_APB2_FZ) The DBG_APB2_FZ register is used to configure some APB peripheral features when the MCU is under DEBUG: • Timer clock counter freeze. This register is mapped at address 0x4001580C. It is asynchronously reset by the POR (and not the system reset).
Debug support (DBG) RM0367 33.10 DBG register map The following table summarizes the Debug registers. Table 180. DBG register map and reset values Addr. Register DBG_ REV_ID DEV_ID IDCODE Reset value X X X X X X X X X X X X X X X X X X X X X X X X X X X X DBG_CR Reset value...
Page 971
Device electronic signature Device electronic signature This section applies to all STM32L0x3 devices, unless otherwise specified. The electronic signature is stored in the System memory area in the Flash memory module, and can be read using the JTAG/SWD or the CPU. It contains factory-programmed identification data that allow the user firmware or other external devices to automatically match its interface to the characteristics of the STM32L0x3 microcontroller.
Page 972
Device electronic signature RM0367 Base address: 0x1FF8 0050 Address offset: 0x00 Read only = 0xXXXX XXXX where X is factory-programmed U_ID(31:16) U_ID(15:0) (31:24): Bits 31:0 U_ID WAF_NUM[7:0] Wafer number (8-bit unsigned number) (23:0): U_ID LOT_NUM[55:32] Lot number (ASCII code) Address offset: 0x04 Read only = 0xXXXX XXXX where X is factory-programmed U_ID(63:48) U_ID(47:32)
Page 973
This appendix shows the code examples of the sequence described in this Reference Manual. These code examples are extracted from the STM32L0xx Snippet firmware package STM32SnippetsL0 available on www.st.com. These code examples used the peripheral bit and register description from the CMSIS header file (stm32l0xx.h).
Page 974
Code examples RM0367 A.2.3 Switch from PLL to HSI16 sequence code uint32_t tickstart; /* (1) Switch the clock on HSI16/4 */ /* (2) Wait for clock switched on HSI16/4 */ /* (3) Disable the PLL by resetting PLLON */ /* (4) Wait until PLLRDY is cleared */ RCC->CFGR (RCC->CFGR &...
Page 975
RM0367 Code examples tickstart = Tick; & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL) /* (4) */ while ((RCC->CFGR ((Tick tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE) error = ERROR_CLKSWITCH_TIMEOUT; /* Report an error */ return; Note: Tick is a global variable incremented in the SysTick ISR each millisecond. NVM Operation code example A.3.1 Unlocking the data EEPROM and FLASH_PECR register...
Page 976
Code examples RM0367 /* For robust implementation, add here time-out management */ ((FLASH->PECR & FLASH_PECR_PELOCK) == 0) /* (2) */ ((FLASH->PECR & FLASH_PECR_PRGLOCK) != 0) /* (3) */ FLASH->PRGKEYR = FLASH_PRGKEY1; /* (4) */ FLASH->PRGKEYR = FLASH_PRGKEY2; A.3.4 Unlocking the option bytes area code example /* (1) Wait till no operation is on going */ /* (2) Check that the PELOCK is unlocked */ /* (3) Check if the OPTLOCK is unlocked */...
Page 977
RM0367 Code examples /* (3) Enter in wait for interrupt. The EOP check is done in the Flash ISR /* (6) Reset the ERASE and DATA bits in the FLASH_PECR register to disable the page erase */ FLASH->PECR FLASH_PECR_ERASE | FLASH_PECR_DATA; /* (1) */ *(__IO uint32_t *)addr = (uint32_t)0;...
Page 978
Code examples RM0367 * Retval None __INLINE __RAM_FUNC void OptionByteErase(uint8_t index) /* (1) Set the ERASE bit in the FLASH_PECR register to enable option byte erasing */ /* (2) Write a 32-bit word value at the option byte address to be erased to start the erase sequence */ /* (3) Wait until the BSY bit is reset in the FLASH_SR register */ /* (4) Check the EOP flag in the FLASH_SR register */...
Page 979
RM0367 Code examples else /* Manage the error cases */ A.3.10 Program half-page to Flash program memory code example * This function programs a half page. It is executed from the RAM. * The Programming bit (PROG) and half-page programming bit (FPRG) * is set at the beginning and reset at the end of the function, * in case of successive programming, these two operations * could be performed outside the function.
Page 980
Code examples RM0367 /* Manage the error cases */ FLASH->PECR &= ~(FLASH_PECR_PROG | FLASH_PECR_FPRG); /* (6) */ Note: This function must be loaded in RAM. A.3.11 Erase a page in Flash program memory code example * This function erases a page of flash. * The Page Erase bit (PER) is set at the beginning and reset * at the end of the function, in case of successive erase, * these two operations could be performed outside the function.
Page 981
RM0367 Code examples A.3.12 Mass erase code example * This function performs a mass erase of the flash. * This function is loaded in RAM. * Param None * Retval while successful, the function never returns except if executed from RAM __RAM_FUNC void FlashMassErase(void)
Page 982
Code examples RM0367 Clock Controller A.4.1 HSE start sequence code example * This function enables the interrupton HSE ready, * and start the HSE as external clock. * Param None * Retval None __INLINE StartHSE(void) void /* Configure NVIC for RCC */ /* (1) Enable Interrupt on RCC */ /* (2) Set priority for RCC */ NVIC_EnableIRQ(RCC_CRS_IRQn);...
Page 983
RM0367 Code examples /* Manage error */ A.4.2 PLL configuration modification code example /* (1) Test if PLL is used as System clock */ /* (2) Select HSI as system clock */ /* (3) Wait for HSI switched */ /* (4) Disable the PLL */ /* (5) Wait until PLLRDY is cleared */ /* (6) Set latency to 1 wait state */ /* (7) Set the PLL multiplier to 24 and divider by 3 */...
Page 984
Code examples RM0367 A.4.3 MCO selection code example /* (1) Clear the MCO selection bits */ /* (2)Select system clock/4 to be output on the MCO without prescaler */ RCC->CFGR &= (uint32_t) RCC_CFGR_MCOSEL; /* (1) */ RCC->CFGR RCC_CFGR_MCO_SYSCLK | RCC_CFGR_MCO_PRE_4; /* (2) */ GPIOs A.5.1...
Page 985
RM0367 Code examples A.6.1 DMA Channel Configuration sequence code example /* (1) Enable the peripheral clock on DMA */ /* (2) Remap DMA channel1 on ADC (reset value) */ /* (3) Enable DMA transfer on ADC */ /* (4) Configure the peripheral data register address */ /* (5) Configure the memory address */ /* (6) Configure the number of DMA tranfer to be performs on channel 1 */ /* (7) Configure increment, size and interrupts */...
Page 986
Code examples RM0367 /* (5) Configure the Trigger Selection bits of the Interrupt line on rising edge */ /* (6) Configure the Trigger Selection bits of the Interrupt line on falling edge */ RCC->IOPENR |= RCC_IOPENR_GPIOAEN; /* (1) */ GPIOA->MODER (GPIOA->MODER &...
Page 987
RM0367 Code examples & ADC_ISR_ADRDY) == 0) /* (3) */ while ((ADC1->ISR /* For robust implementation, add here time-out management */ A.8.3 ADC disable sequence code example /* (1) Ensure that no conversion on going */ /* (2) Stop any ongoing conversion */ /* (3) Wait until ADSTP is reset by hardware i.e.
Page 988
Code examples RM0367 /* Performs the AD conversion */ ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversion */ while ((ADC1->ISR & ADC_ISR_EOC) == 0) /* wait end of conversion */ /* For robust implementation, add here time-out management */ A.8.6 Continuous conversion sequence code example Software trigger /* (1) Select HSI16 by writing 00 in CKMODE (reset value) */...
Page 989
RM0367 Code examples A.8.8 Continuous conversion sequence code example Hardware trigger /* (1) Select HSI16 by writing 00 in CKMODE (reset value) */ /* (2) Select the external trigger on TIM22_TRGO (TRG4 i.e. EXTSEL = 100 and rising edge, the continuous mode and scanning direction */ /* (3) Select CHSEL4, CHSEL9 and CHSEL17 */ /* (4) Select a sampling mode of 111 i.e.
Page 990
Code examples RM0367 A.8.10 DMA circular mode sequence code example /* (1) Enable the peripheral clock on DMA */ /* (2) Enable DMA transfer on ADC and circular mode */ /* (3) Configure the peripheral data register address */ /* (4) Configure the memory address */ /* (5) Configure the number of DMA tranfer to be performs on DMA channel 1 */ /* (6) Configure increment, size, interrupts and circular mode */...
Page 992
Code examples RM0367 /* (6) Enable interrupts on EOC, EOSEQ and Analog Watchdog */ /* (7) Wake-up the VREFINT (only for VBAT, Temp sensor and VRefInt) */ //ADC1->CFGR2 &= ~ADC_CFGR2_CKMODE; /* (1) */ ADC1->CFGR1 ADC_CFGR1_CONT \ | (17<<26) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL;...
Page 993
RM0367 Code examples - (int32_t) *TEMP30_CAL_ADDR temperature temperature - 30); (int32_t)(130 temperature temperature (int32_t)(*TEMP130_CAL_ADDR *TEMP30_CAL_ADDR); temperature temperature + 30; return(temperature); A.9.1 Independent trigger without wave generation code example /* (1) Enable the peripheral clock of the DAC */ /* (2) Configure WAVE1 at 01 and LFSR mask amplitude (MAMP1) at 1000 for a 511-bits amplitude, enable the DAC ch1, disable buffer on ch1,...
Page 994
Code examples RM0367 DAC->CR DAC_CR_DMAUDRIE1 DAC_CR_DMAEN1 DAC_CR_BOFF1 DAC_CR_TEN1 | DAC_CR_EN1; /* (2) */ /* (1) Enable the peripheral clock on DMA */ /* (2) Remap DAC on DMA channel 2 */ /* (3) Configure the peripheral data register address */ /* (4) Configure the memory address */ /* (5) Configure the number of DMA tranfer to be performs on DMA channel x */...
Page 996
Code examples RM0367 /* (2) Enable the counter by writing CEN=1 in the TIMx_CR1 register. */ TIMx->SMCR TIM_SMCR_ETPS_0 | TIM_SMCR_ECE; /* (1) */ TIMx->CR1 |= TIM_CR1_CEN; /* (2) */ A.11.3 Input capture configuration code example /* (1) Select the active input TI1 (CC1S = 01), program the input filter for 8 clock cycles (IC1F = 0011), select the rising edge on CC1 (CC1P = 0, reset value) and prescaler at each valid transition (IC1PS = 00, reset value) */...
Page 997
RM0367 Code examples Counter counter1 0xFFFF counter0 + 1; counter0 = counter1; else /* Manage error */ Note: This code manages only single counter overflows. To manage several counter overflows, the update interrupt must be enabled (UIE = 1) and properly managed.
Need help?
Do you have a question about the STM32L0x3 and is the answer not in the manual?
Questions and answers