This reference manual targets application developers. It provides complete information on
how to use the STM32F101xx and STM32F103xx microcontroller memory and peripherals.
The STM32F101xx and STM32F103xx will be referred to as STM32F10xxx throughout the
document.
The STM32F10xxx is a family of microcontro llers with diff erent memory sizes, pac kages and
peripherals.
For ordering info rmation, mechanical and electrical device char acteristics please ref er to the
STM32F101xx and STM32F103xx datasheets.
For information on programming, erasing and protection of the internal Flash memory
please refer to the STM32F10xxx Fla sh programming manual.
For information on the ARM Cortex™-M3 core, please refer to the Cortex™-M3 Technical Reference Manual.
The following abbreviations are used in register descriptions:
read/write (rw)Software can read and write to these bits.
read-only (r)Software can only read these bits.
write-only (w)Software can only write to this bit. Reading the bit returns the reset
value.
read-clear (rc)The software can only read or clear this bit.
read/clear (rc_w1) Software can read as well as clear this bit by writing 1. Writing ‘0’ has
no effect on the bit value.
read/clear (rc_w0) Software can read as well as clear this bit by writing 0. Writing ‘1’ has
no effect on the bit value.
read/set (rs)Software can read as well as set this bit. Writing ‘0’ has no effect on the
bit value.
toggle (t)The software can only toggle this bit by writing ‘1’. Writing ‘0’ has no
effect.
23/501
Page 24
Memory and bus architectureRM0008
2 Memory and bus architecture
2.1 System architecture
The main system consists of:
●Four masters:
–Cortex™-M3 core ICode bus (I-bus), DCode bus (D-bus), and System bus (S-bus)
–GP-DMA (General Purpose DMA)
●Three slaves:
–Internal SRAM
–Internal Flash memory
–AHB to APB bridges (AHB2APBx) which connect all the APB peripherals
These are interconnected using a multilayer AHB bus architecture as shown in Figure 1:
Figure 1.System architecture
Cortex-M3
DCode
System
ICode
FLITF
Flash
memory
SRAM
DMA
Ch.1
Ch.2
Ch.7
AHB system bus
DMA request
Bridge 1
Bridge 2
GPIOA
GPIOB
GPIOC
GPIOD
GPIOE
EXTI
APB2APB1
USART1
SPI1
ADC1
ADC2
TIM1
AFIO
USART2
USART3
SPI2
I2C1
I2C2
USB
IWDG
WWDG
CAN
BKP
PWR
TIM2
TIM3
TIM4
ICode bus
This bus connects the Instruction bus of the Cortex™-M3 core to the Flash memory
instruction interface. Prefetching is perfo rmed on this bus.
DCode bus
This bus connects the DCode bus (literal load and debug access) of the Cortex™-M3 core
to the Flash memory Data interface.
System bus
This bus connects the system b us of the Cortex™-M3 co re (peripherals bus) to a BusMatrix
which manages the arbitration between the core and the DMA.
24/501
Page 25
RM0008Memory and bus architecture
DMA bus
This bus connects the AHB master interface of the DMA to the BusMatrix which manages
the access of CPU DCode and DMA to SRAM, Flash memory and peripherals.
BusMatrix
The BusMatrix manages the access arbitration between the core system bus and the DMA
master bus. The arbitration uses a Round Robin algorithm. The BusMatrix is composed of
three masters (CPU DCode, System bus and DMA bus) and three slav es (FLITF, SRAM,
and AHB2APB bridges).
AHB peripherals are connected on system bus through a BusMatrix to allow DMA access.
AHB/APB bridges (APB)
The two AHB/APB bridges provide full synchronous connections between the AHB and the
2 APB buses. APB1 is limited to 36 MHz, APB2 operates at full speed (up to 72 MHz
depending on device).
Refer to Table 1 on page 27 for the address mapping of the peripherals connected to each
bridge.
2.2 Memory organization
Program memory, data memory, register s 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 low est numbered b yte in a word
is considered the word’s least significant byte and the highest numbered byte the most
significant.
Figure 2 on page 26 shows the STM32F10xxx Memory Map. For the detailed mapping of
peripheral registers, please refer to the related chapters.
The addressable memory space is divided into 8 main blocks, each of 512MB.
All the memory areas that are not allocated to on-chip memories and peripherals are
considered “Reserved” (gray shaded areas in the Figure 2 on page 26).
The STM32F10xxx features 20 Kbytes of static SRAM. It can be accessed as bytes, halfwords (16 bits) or full words (32 bits). The SRAM start address is 0x2000 0000.
2.3.3 Bit banding
The Cortex™-M3 memory map includes two bit-band regions. These regions map each
word in an alias region of memory to a bit in a bit-band region of memory. Writing to a word
in the alias region has the same eff ect as a read-modify-write oper ation on the t argeted bit in
the bit-band region.
In the STM32F10xxx both peripheral registers and SRAM are mapped in a bit-band region.
This allows single bit-band write and read operations to be performed.
28/501
Page 29
RM0008Memory and bus architecture
A mapping formula shows ho w to ref erence each word in th e alias region to a correspon ding
bit in the bit-band region. The mapping formula is:
bit_word_addr is the address of the word in the alias memory region that maps to the
targeted bit.
bit_band_base is the starting address of the alias region
byte_offset is the number of the by te in the b it-band reg ion that con tains the ta rgeted bit
bit_number is the bit position (0-31) of the targeted bit.
Example:
The following example shows how to map bit 2 of the byte located at SRAM address
0x20000300 in the alias region:
0x22006008 = 0x22000000 + (0x300*32) + (2*4).
Writing to address 0x22006008 has the same effect as a read-modify-write operation on bit
2 of the byte at SRAM address 0x20000300.
Reading address 0x22006008 returns the v alue (0x0 1 o r 0 x00) of bit 2 o f th e byte at SRAM
address 0x20000300 (0x01: bit set; 0x00: bit reset ).
For more information on Bit-Banding, please refer to the Cortex™-M3 Technical Reference Manual.
2.3.4 Embedded Flash memory
The high-performance Flash memory module has the following key features:
●Density of 128 Kbytes
●Memory organization: the Flash memory is organized as a main block and an
information block:
–Main memory block of size 16 Kb × 64 bits. The main block is divided into 128
pages of 1 Kbyte each (see Table 3).
–Information block of size 258 × 64 bits. The information block is divided into 2
pages of 2 Kbytes and 16 bytes, respectively (see Table 3).
The Flash memor y inte r face features:
●Read interface with prefetch buffer (2x64-bit words)
Note:For further information on the Flash memory registers, please refer to the STM32F10xxx
Flash programming manual.
30/501
Page 31
RM0008Memory and bus architecture
Reading Flash memory
Flash memory instructions and data access are performed through the AHB bus. The
prefetch block is used for instruction f etches thr ough the ICode bus. Arbitration is performed
in the Flash memory interface, and priority is given to data access on the DCode bus.
Read accesses can be performed with the f ollowing configuration options:
●Latency: number of wait states for a read operation programmed on-the-fly
●Prefetch buffer (2 x 64-bit blocks): it is enabled after reset; a whole block can be
replaced with a single read from the Flash memory as the size of the b lock mat ches the
bandwidth of the Flash memory. Thanks to the prefetch buffer, faster CPU execution is
possible as the CPU fetches one word at a time with the next word readily available in
the prefetch buffer
●HalfCycle: for power optimization
Note:1These options should be used in accordance with the Flash memory access time. The wait
states represent the ratio of the SYSCLK ( system cloc k) period to the Flash memory access
time:
zero wait state, if 0 < SYSCLK
one wait state, if 24 MHz < SYSCLK
two wait states, if 48 MHz < SYSCLK
2Half cycle configuration is not available in combination with a prescaler on the AHB. The
clock system should be equal to the HCLK clock. This feature can therefore be used only
with a direct clock from the internal, 8 MHz RC (HSI) oscillator or with the HSE oscillator.
3The prefetch buffer must be kept on when using a prescaler different from 1 on the AHB
clock
4Using DMA: DMA accesses Flash memory on the DCode bus and has priority over ICode
instructions. The DMA provides one free cycle after each tr ansf er. Some instructions can be
performed together with DMA transfer.
≤
24 MHz
≤
48 MHz
≤
72 MHz
Programming and erasing Flash memory
The Flash memory can be programmed 16 bits (half words) at a time.
The Flash memory erase operation can be performed at page level or on the whole Flash
area (mass-erase). The mass-erase does not affect the information blocks.
To ensure that there is no over-programming, the Flash Programming and Erase Controller
blocks are clocked by a fixed clock.
The End of write operation (programming or erasing) can trigger an interrupt. This interrupt
can be used to exit from WFI mode, only if the FLITF clock is enabled. Otherwise, the
interrupt is served only after an exit from WFI.
Note:F or further information on Flash memory operations and register configura tions, please ref er
to the STM32F10xxx Flash programming manual.
31/501
Page 32
Memory and bus architectureRM0008
2.4 Boot configuration
In the STM32F10xxx, 3 different boot modes can be selected through BOOT[1:0] pins as
shown in Table 3.
Table 3.Boot modes
Boot mode
selection pins
BOOT1BOOT0
x0User Flash memoryUser Flash memory is selected as boot space
01SystemMemorySystemMemory is selected as boot space
11Embedded SRAMEmbedded SRAM is selected as boot space
This aliases the physical memory associated with each boot mode to Block 000 (boot
memory). The values on the BOOT pins are latched on the 4th rising edge of SYSCLK after
a Reset. It is up to the user to set the BOOT1 and BOOT0 pins after Reset to select the
required boot mode.
The BOOT pins are also re-sampled when exiting from Standby mode. Consequently they
must be kept in the required Boot mo de configuration in Standby mode.
Boot modeAliasing
Even when aliased in the boot memory space, the related memory (Flash memory or
SRAM) is still accessible at its original memory space.
After this startup delay has elapsed, the CPU starts code ex ecution from the boot memory,
located at the bottom of the memory address space starting from 0x0000 0000.
Embedded boot loader
The embedded boot loader is used to reprogram the Flash memory using the USART1
serial interface. This program is located in the SystemMemory and is pro grammed by ST
during production.
32/501
Page 33
RM0008Power control (PWR)
3 Power control (PWR)
3.1 Power supplies
The device requires a 2.0-to-3.6 V operating voltage supply (VDD). An embedded regulator
is used to supply the internal 1.8 V digital power.
The real-time clock (R TC) and back up registers can be po wered from the V
the main V
3.1.1 Independent A/D converter supply and reference voltage
To improve conversion accuracy, the ADC has an independent power supply which can be
separately filtered and shielded from noise on the PCB.
●The ADC voltage supply input is available on a separate V
●An isolated supply ground connection is provided on pin V
When available (according to package), V
must be tied to V
REF-
33/501
DDA
SSA
SSA
pin.
.
.
Page 34
Power control (PWR)RM0008
On 100-pin packages
To ensure a better accuracy on low voltage inputs , the user can connect a separ ate e xternal
reference voltage ADC input on V
2.4 V to V
DDA
.
REF+
and V
. The voltage on V
REF-
can range from
REF+
On packages with 64 pins or less
The V
voltage supply (V
REF+
and V
pins are not available, they are internally connected to the ADC
REF-
) and ground (V
DDA
3.1.2 Battery backup domain
To retain the content of the Backup registers and supply the RTC function when V
turned off, V
by another source.
The V
BAT
the RTC to operate even when the main digital supply (V
V
supply is controlled by the Power Down Reset embedded in the Reset bloc k.
BAT
Warning:During the t
If no external battery is used in the application, V
When the backup domain is supplied by V
following functions are available:
●PC14 and PC15 can be used as either GPIO or LSE pins
●PC13 can be used as GPIO, TAMPER pin, RTC Calibration Clock, RTC Alarm or
second output (refer to Section 9: Backup registers (BKP) on page 132)
pin can be connected to an optional standby v oltage supplied b y a battery or
BAT
pin powers the RTC unit, the LSE oscillator and the PC13 to PC15 IOs, allowing
switch between V
V
rises fast and may become established during this time,
DD
a current may be injected into V
connected between V
VDD−0.6V. Refer to the datasheet for t h e value of t
SSA
RSTTEMPO
BAT
).
) is turned off. The switch to the
DD
temporization at VDD startup, the power
and VDD remains connected to V
through a diode
and V
DD
(analog switch connected to VDD), the
DD
BAT
when V
BAT
must be connected externally to VDD.
BAT
is lower than
BAT
RSTTEMPO.
BAT
. As
DD
is
Note:Due t o the f act that the switch o nly sinks a limited amount of current, the use of GPIOs PC13
to PC15 is restricted: only one I/O at a time can be used as an output, the speed has to be
limited to 2 MHz with a maximum load of 30 pF and these IOs must not be used as a current
source (e.g. to drive an LED).
When the backup domain is supplied by V
V
is not present), the following functions are available:
DD
●PC14 and PC15 can be used as LSE pins only
●PC13 can be used as TAMPER pin, RTC Alarm or Second output (refer to section
(analog switch connected to V
BAT
because
BAT
Section 9.5.2: RTC clock calibration register (BKP_RTCCR) on page 133).
34/501
Page 35
RM0008Power control (PWR)
3.1.3 Voltage regulator
The voltage regulator is always enabled after Reset. It works in three different modes
depending on the application modes.
●In Run mode, the regulator supplies full power to the 1.8 V domain (core, memories
and digital peripherals).
●In Stop mode the regulator supplies low-pow er to the 1.8 V domain, preserving
contents of registers and SRAM
●In Standby Mode, the regulator is pow ered off . The conten ts of the registe rs and SRAM
are lost except for the Standby circuitry and the Backup Domain.
3.2 Power supply supervisor
3.2.1 Power on reset (POR)/power down reset (PDR)
The device has an integrated POR/PDR circuitry that allows proper operation starting
from/down to 2 V.
The device remains in Reset mode when V
is below a specified threshold, V
DD
without the need for an external reset circuit. For more details concerning the power
on/power down reset threshold, refer to the electrical characteristics of the datasheet.
Figure 4.Power on reset/power down reset waveform
V
DD
POR
40 mV
hysteresis
Temporization
t
RSTTEMPO
Reset
3.2.2 Programmable voltage detector (PVD)
POR/PDR
PDR
,
You can use the PVD to monitor the VDD power supply by comparing it to a threshold
selected by the PLS[2:0] bits in the Power control register (PWR_CR).
The PVD is enabled by setting t he PVDE bit.
A PVDO flag is available , in the Power control/status register (PWR_CSR), to indicate if V
DD
is higher or lower than the PVD threshold. This event is internally connected to the EXTI
line16 and can generate an interrupt if ena bled through the EXTI registers. The PVD output
interrupt can be generated when V
drops below the PVD threshold and/or when VDD
DD
35/501
Page 36
Power control (PWR)RM0008
rises above the PVD threshold depending on EXTI line16 rising/falling edge configuration.
As an example the service routine could perform emergency shutdown tasks.
Figure 5.PVD thresholds
V
DD
PVD output
PVD threshold
100 mV
hysteresis
36/501
Page 37
RM0008Power control (PWR)
3.3 Low-power modes
By default, the microcont roller is in Run mode aft er a system or a po wer Reset. I n Run mode
the CPU is clocked by HCLK an d 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. It is up to the user to select the mo de that gi ves the best
compromise between low-po wer consumption, short startup time and available wakeup
sources.
The STM32F10xxx devices feature three low-power modes:
In Run mode the speed of the system clocks (SYSCLK, HCLK, PCLK1, PCLK2) can be
reduced by progra mming the prescaler reg isters. Th ese prescalers can also be u sed to slow
down peripherals before entering Sleep mode.
For more details refer to Section 4.3.2: Clock configuration register (RCC_CFGR).
3.3.2 Peripheral clock gating
no effect on other
clocks or analog
clock sources
All 1.8V domain
clocks OFF
NoneON
ON or in lowpower mode
(depends on
HSI and
HSE
oscillators
OFF
Power control
register
(PWR_CR))
OFF
In Run mode, the HCLK and PCLKx for individual peripherals and me mories can be stopped
at any time to reduce power consumption.
37/501
Page 38
Power control (PWR)RM0008
To further reduce power consumption in Sleep mode the peripheral clocks can be disabled
prior to executing th e WFI or WFE instructions.
Peripheral clock gating is controlled by the AHB Peripheral Clock enable register
The Sleep mode is entered by executing the WFI (Wait For Interrupt) or WFE (Wait for
Event) instructions. Two options are available to select the Sleep mode entry mechanism,
depending on the SLEEPONEXIT bit in the Cortex-M3 System Control register:
●Sleep-now: if the SLEEPONEXIT bit is cleared, the MCU enters Sleep mode as soon
as WFI or WFE instruction is executed.
●Sleep-on-exit: if the SLEEPONEXIT bit is set when the WFI instruction is executed, the
MCU enters Sleep mode as soon as it exits the lowest priority ISR.
Refer to Table 5 and Table 6 for details on how to enter Sleep mode.
Exiting Sleep mode
If the WFI instruction is used to enter Sleep mode, an y peripheral interrupt ac knowledg ed by
the nested vectored interrupt controller (NVI C) can wake up the device from Sleep mode.
If the WFE instruction is used to enter Sleep mode, the MCU exits Sleep mode as soon as
an event occurs. This event can be either an interrupt enabled in the peripheral control
register but not in the NVIC, or an EXTI line configured in event mode.
This mode offers the lowest wakeup time as no time is wasted in interrupt entry/exit.
Refer to Table 5 and Table 6 for more details on how to exit Sleep mode.
Table 5.Sleep-now
Sleep-now modeDescription
WFI (Wait for Interrupt) or WFE (Wait fo r Event) while:
Mode entry
Mode exit
Wakeup la tencyNone
– SLEEPDEEP = 0 and
– SLEEPONEXIT = 0
Refer to the Cortex™-M3 System Control register.
If WFI was used for entry:
Interrupt: Refer to Table 27: Vector table
If WFE was used for entry
Wakeup event: Refer to Section 6.2.3 : Wakeup event management
38/501
Page 39
RM0008Power control (PWR)
Table 6.Sleep-on-exit
Sleep-on-exitDescription
WFI (wait for interrupt) while:
Mode entry
Mode exitInterrupt: refer to Table 27: Vector table.
Wakeup la tencyNone
– SLEEPDEEP = 0 and
– SLEEPONEXIT = 1
Refer to the Cortex™-M3 System Control register.
3.3.4 Stop mode
The Stop mode is based on the Cortex-M3 deepsleep mode combined with peripheral cloc k
gating. The volta ge regulator can be configur ed either in normal or low- pow er mode . In Stop
mode, all clocks in the 1.8 V domain are stopped, the PLL, the HSI and the HSE RC
oscillators are disabled. SRAM and register contents are preserved.
Entering Stop mode
Refer to Table 7 for details on how to enter Stop mode.
To further reduce power consumption in Stop mode, the internal voltage regulator can be
put in low-power mode. This is configured by the LPDS bit of the Power control register
(PWR_CR).
If Flash memory programming is ongoing, the Stop entry is delayed until the memory
access is finished.
If an access to APB domain is ongoing, Stop mode entry is delayed until the APB access is
finished.
In Stop mode, the following features can be selected by programming individual control bits:
●Independent Watchdog (IWDG): t he IWDG is started by writing to its Key register or by
hardware option. Once started it cannot be stopped except by a Reset. See
Section 10.1 in Section 10: Independent watchdog (IWDG).
●real-time clock (RTC): this is configured by the R TCEN bit in the Back up domain control
register (RCC_BDCR)
●Internal RC oscillator (LSI RC): this is configured by the LSION bit in the Control/status
register (RCC_CSR).
●External 32.768 kHz oscillator (LSE OSC): this is configured by the LSEON bit in the
Backup domain control register (RCC_BDCR).
Exiting Stop mode
Refer to Table 7 for more details on how to exit Stop mode.
When exiting Stop mode by issuing an interrupt or a wakeup event, the HSI RC oscillator is
selected as system clock.
When the voltage regulator operates in low-power mode, an additional startup delay is
incurred when waking up from St op mode . By k eeping the in ternal regulator ON during Stop
mode, the consumption is higher although the startup time is reduced.
39/501
Page 40
Power control (PWR)RM0008
Table 7.Stop mode
Stop modeDescription
WFI (Wait for Interrupt) or WFE (Wait fo r Event) while:
– Set SLEEPDEEP bit in Cortex™-M3 System Control register
– Clear PDDS bit in Power Control register (PWR_CR)
Mode entry
Mode exit
Wakeup la tencyHSI RC wakeup time + regulator wakeup time from Low-power mode
– Select the voltage regulator mode by configuring LPDS bit in PWR_CR
Note: To enter Stop mode, all EXTI Line pending bits (in Pending register
(EXTI_PR)) and RTC Alarm flag must be reset. Otherwise, the Stop mode
entry procedure is ignored and program execution continues.
If WFI was used for entry:
Any EXTI Line configured in Interrupt mode (the corresponding EXTI
Interrupt vector must be enabled in the NVIC). Refer to Table 27: Vector
table on page 98
If WFE was used for entry:
Any EXTI Line configured in event mode . Refer to Section 6.2.3: Wakeup
event management on page 102
3.3.5 Standby mode
The Standby mode allows to achieve the lowest power consumption. It is based on the
Cortex-M3 deepsleep mode, with the voltage regulator disabled. The 1.8 V dom ain is
consequently powered off. The PLL, the HSI oscillator and the HSE oscillator are also
switched off . SRAM and register contents are lost e xcept f or r egisters in the Backup domain
and Standby circuitry (see Figure 3).
Entering Standby mode
Refer to Table 8 for more details on how to enter Standby mode.
In Standby mode, the following features can be selected by programming individual control
bits:
●Independent Watchdog (IWDG): t he IWDG is started by writing to its Key register or by
hardware option. Once started it cannot be stopped e xcept by a reset. See
Section 10.1 in Section 10: Independent watchdog (IWDG).
●real-time clock (RTC): this is configur ed by the R TCEN bit in the Bac kup domain control
register (RCC_BDCR)
●Internal RC oscillator (LSI RC): this is configured by the LSION bit in the Control/status
register (RCC_CSR).
●External 32.768 kHz oscillator (LSE OSC): this is configured by the LSEON bit in the
Backup domain control register (RCC_BDCR)
40/501
Page 41
RM0008Power control (PWR)
Exiting Standby mode
The microcontroller exits Standby mode when an external Reset (NRST pin), IWDG Reset,
a rising edge on WKUP pin or an RTC alarm occurs. All registers are reset after wakeup
from Standby e xcept for Power control/status register (PWR_CSR).
After waking up from Standby mode, program execution restarts in the same way as after a
Reset (boot pins sampling, vector reset is fetched, etc.). The SBF status flag in the Power
control/status register (PWR_CSR) indicates that the MCU was in Standby mode.
Refer to Table 8 for more details on how to exit Standby mode.
Table 8.Standby mode
Standby modeDescription
WFI (Wait for Interrupt) or WFE (Wait fo r Event) while:
Mode entry
– Set SLEEPDEEP in Cortex™-M3 System Control register
– Set PDDS bit in Power Control register (PWR_CR)
– Clear WUF bit in Power Control/Status register (PWR_CSR)
In Standby mode, all I/O pins are high impedance except:
●Reset pad (still available)
●TAMPER pin if configured for tamper or calibration out
●WKUP pin, if enabled
Debug mode
By default, the debug connection is lost if the application puts the MCU in Stop or Standby
mode while the debug f ea tures are used . This is due to the f act that the Cortex™-M3 core is
no longer clocked.
However, by setting some configuration bits in the DBGMCU_CR register, the software can
be debugged even when using the low-power modes extensively. For more details, refer to
Section 20.15.1: Debug support for low-power modes.
3.3.6 Auto Wakeup (AWU) from low-power mode
The RTC can be used to wakeup the MCU from low-power mode without depending on an
external interrupt (Auto Wakeup mode). The RTC provides a programmable time base for
waking-up from Stop or Standb y mode at regular interva ls. F or this purpose, two of the three
41/501
Page 42
Power control (PWR)RM0008
alternative RTC clock sources can be selected b y p rog r amming t he RTCSEL[1:0] bits in the
This clock source provides a precise time base with very low-power consumption (less
than 1µA added co nsu m pt ion in typic al co nd itio ns )
●Low-power internal RC Oscillator (LSI RC)
This clock source has the advantage of saving the cost of the 32.768 kHz crystal. This
internal RC Oscillator is designed to add minimum power consumption.
To wakeup from Stop mode with an RTC alarm event, it is necessary to:
●Configure the EXTI Line 17 to be sensitive to rising edge
●Configure the RTC to generate the RTC alarm
To wakeup from Standby mode, there is no need to configure the EXTI Line 17.
42/501
Page 43
RM0008Power control (PWR)
3.4 Power control registers
3.4.1 Power control register (PWR_CR)
Address offset: 0x00
Reset value: 0x0000 0000 (reset by wakeup from Standby mode)
31302928272625242322212019181716
Reserved
Res.
1514131211109876543210
ReservedDBPPLS[2:0]PVDE CSBF CWUF PDDSLPDS
Resrwrwrwrwrwrc_w1rc_w1rwrw
Bits 31:9 Reserved, always read as 0.
Bit 8 DBP: Disable Backup Domain write protection.
In reset state, the RTC and backup registers are protected against parasitic write access. This bit
must be set to enable write access to these registers.
0: Access to RTC and Backup registers disabled
1: Access to RTC and Backup registers enabled
Bits 7:5 PLS[2:0]: PVD Level Selection.
These bits are written by software to select the voltage threshold detected by the Power Voltage
Detector
Note: Refer to the electrical characteristics of the datasheet for more details.
Bit 4 PVDE: Power Voltage Detector Enable.
This bit is set and cleared by software.
0: PVD disabled
1: PVD enabled
Bit 3 CSBF: Clear Standby Flag.
This bit is always read as 0.
0: No effect
1: Clear the SBF Standby Flag (write).
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 cyc les. (write)
43/501
Page 44
Power control (PWR)RM0008
Bit 1 PDDS: Power Down Deepsleep.
This bit is set and cleared by software. It works together with the LPDS bit.
0: Enter Stop mode when the CPU enters Deepsleep. The regulator status depends on the LPDS bit.
1: Enter Standby mode when the CPU enters Deepsleep.
Bit 0 LPDS: Low-Power Deepsleep.
This bit is set and cleared by software. It works together with the PDDS bit. 0: Voltage regulator on
during Stop mode
1: Voltage regulator in low-power mode during Stop mode
44/501
Page 45
RM0008Power control (PWR)
3.4.2 Power control/status register (PWR_CSR)
Address offset: 0x04
Reset value: 0x0000 0000 (not reset by wakeup from Standby mode)
Additional APB cycles are needed to read this register versus a standard APB read.
31302928272625242322212019181716
Reserved
Res.
1514131211109876543210
Reserved
Res.rwRes.rrr
Bits 31:9 Reserved, always read as 0.
Bit 8 EWUP: Enable WKUP pin
This bit is set and cleared by software.
0: WKUP pin is used for general purpose I/O. An event on the WKUP pin does not wakeup the
device from Standby mode.
1: WKUP pin is used for wakeup from Standby mode and forced in input pull down configuration
(rising edge on WKUP pin wakes-up the system from Standby mode).
Note: This bit is reset by a system Reset.
Bits 7:3 Reserved, always read as 0.
Bit 2 PVDO: PVD Output
This bit is set and cleared by hardware. It is valid only if PVD is enabled by the PVDE bit.
0: V
is higher than the PVD threshold selected with the PLS[2:0] bits.
DD
1: V
is lower than the PVD threshold selected with the PLS[2:0] bits.
DD
Note: The PVD is stopped by Standby mode. For this reason, this bit is equal to 0 after Standby or
reset until the PVDE bit is set.
Bit 1 SBF: Standby Flag
This bit is set by hardware and cleared only by a POR/PDR (Power On Reset/Power Down Reset)
or by setting the CSBF bit in the Power control register (PWR_CR)
0: Device has not been in Standby mode
1: Device has been in Standby mode
Bit 0 WUF: Wakeup Flag
This bit is set by hardware and cleared only by a POR/PDR (Power On Reset/Power Down Reset)
or by setting the CWUF bit in the Power control register (PWR_CR)
0: No wakeup event occurred
1: A wakeup event was received from the WKUP pin or from the RTC alarm
Note: An additional wakeup ev ent is detected if the WKUP pin is enab led (b y setting the EWUP bit)
when the WKUP pin level is already high.
EWUP
Reserved
PVDOSBFWUF
45/501
Page 46
Power control (PWR)RM0008
3.5 PWR register map
The following table summarizes the PWR registers.
Table 9.PWR - register map and reset values
OffsetRegister
000h
004h
313029282726252423222120191817161514131211
PWR_CR
Reset value000000000
PWR_CSR
Reset value0000
Reserved
Reserved
987654321
10
PLS[2:0]
DBP
EWUP
PVDE
Reserved
CSBF
PDDS
CWUF
SBF
PVDO
Refer to Table 1 on page 27 for the register boundary addresses.
0
LPDS
WUF
46/501
Page 47
RM0008Reset and clock control (RCC)
4 Reset and clock control (RCC)
4.1 Reset
There are three types of reset, defined as system Reset, power Reset and backup domain
Reset.
4.1.1 System Reset
A system Reset sets all registers to their reset values except the reset flags in the clock
controller CSR register and the registers in the Backup domain (see Figure 3.).
A system Reset is generated when one of the following events occurs:
1.A low lev el on the NRST pin (External Reset)
2. Window Watchdog end of count condition (WWDG Reset)
3. Independent Watchdog end of count condition (IWDG Reset)
4. A software Reset (SW Reset) (see Section : Software Reset)
5. Low-power management Reset (see Section : Low-power management Reset)
The reset source can be identified by chec king the Rese t flags in the Control/Stat us register ,
RCC_CSR (see Section 4.3.10: Control/status register (RCC_CSR)).
Software Reset
The SYSRESETREQ bit in Cortex™-M3 Application Interrupt and Reset Control Register
must be set to force a software Reset on the device. Refer to the Cortex™-M3 technical
reference manual for more details.
Low-power management Reset
There are two ways to generate a low-power management Reset:
1.Reset generated when entering Stan d by mode:
This type of reset is enab led by re setting nRST_STDBY bit in User Option Bytes . In this
case, whenever a Standby mode entry sequence is successfully executed, the device
is reset instead of entering Standby mode.
2. Reset when entering Stop mode:
This type of reset is enab led by resetting NRST_STOP bit in User Option Bytes. In t his
case, whenever a Stop mode entry sequence is successfully executed, the device is
reset instead of entering Stop mode.
For further information on the User Option Bytes, refer to the STM32F10xxx Flash
programming manual.
47/501
Page 48
Reset and clock control (RCC)RM0008
4.1.2 Power reset
A power Reset is generated when one of the following events occurs:
1.Power On/Power down Reset (POR/PDR Reset)
2. When exiting Standby mode
A power Reset sets all registers to their reset values except the Backup domain (see
Figure 3)
These sources act on the RESET
RESET service routine vector is fixed at addresses
map.
Figure 6.Reset circuit
EXTERNAL
RESET
NRST
The Backup domain has two specific resets that affect only the Backup domain (see
Figure 3)
4.1.3 Backup domain Reset
A backup domain Reset is generated when one of the following events occurs:
1.Software Reset, triggered by setting the BDRST bit in the Backup domain control
register (RCC_BDCR).
2. V
DD
or V
power on, if both supplies have previously been powered off.
BAT
pin and it is always kept low during the delay phase. The
Three different clock sources can be used to drive the system clock (SYSCLK):
●HSI oscillator clock
●HSE oscillator clock
●PLL clock
The devices have the following two secondary clock sources:
●40 kHz low speed internal RC (LSI RC) which drives the independent watchdog and
optionally the RTC used for Auto Wakeup from Stop/Standby mode.
●32.768 kHz low speed external crystal (LSE crystal) which optionally drives the real-
time clock (RTCCLK)
48/501
Page 49
RM0008Reset and clock control (RCC)
Each clock source can be switched on or off independently when it is not used, to optimize
power consumption.
Figure 7.Clock tree
OSC_OUT
OSC_IN
OSC32_IN
OSC32_OUT
8 MHz
HSI RC
PLLSRC
4-16 MHz
HSE OSC
LSE OSC
32.768 kHz
HSI
PLLMUL
..., x16
x2, x3, x4
PLL
PLLXTPRE
/2
/128
LSE
RTCSEL[1:0]
USB
Prescaler
/2
SW
HSI
SYSCLK
HSE
CSS
72 MHz
max
to RTC
PLLCLK
RTCCLK
/1, 1.5
AHB
Prescaler
/1, 2..512
48 MHz
72 MHz max
Clock
Enable (3 bits)
/8
APB1
Prescaler
/1, 2, 4, 8, 16
TIM2, 3, 4
x1, 2 Multiplier
APB2
Prescaler
/1, 2, 4, 8, 16
TIM1 Timer
x1, 2 Multiplier
ADC
Prescaler
/2, 4, 6, 8
USBCLK
to USB interface
HCLK
to AHB bus, core,
memory and DMA
to Cortex System timer
FCLK Cortex
free running clock
36 MHz max
Peripheral Clock
Enable (13 bits)
Peripheral Clock
Enable (3 bits)
72 MHz max
Peripheral Clock
Enable (11 bits)
Peripheral Clock
Enable (1 bit)
ADCCLK
PCLK1
to APB1
peripherals
to TIM2, 3
and 4
TIMXCLK
PCLK2
to APB2
peripherals
to TIM1
TIM1CLK
to ADC
to Independent Watchdog (IWDG)
IWDGCLK
PLLCLK
HSI
HSE
SYSCLK
Legend:
HSE = High Speed External clock signal
HSI = High Speed Internal clock signal
LSI = Low Speed Internal clock signal
LSE = Low Speed External clock signal
MCO
LSI RC
40 kHz
Main
Clock Output
LSI
/2
MCO
1. When the HSI is used as a PLL clock input, the maximum system clock frequency that can be achieved is
64 MHz.
Several prescalers allow the configuration of the AHB frequency, the high speed APB
(APB2) and the low speed APB (APB1) domains. The AHB and the APB2 domains
maximum frequency is 72 MHz. The APB1 domains maximum allowed frequency is 36
MHz. The RCC feeds the Cortex System Timer (SysTick) external clock with the AHB clock
divided by 8. The SysTick can work either with this clock or with the Cortex clock (AHB),
configurable in the SysTick Control and Status Register. The ADCs are clocked by the cloc k
of the High Speed domain (APB2) divided by 2, 4, 6 or 8.
49/501
Page 50
Reset and clock control (RCC)RM0008
The timer clock frequencies are twice the frequency of the APB domain which they are
connected to. Nevertheless, if the APB prescaler is 1, the clock frequency of the timer is the
same as the frequency of the APB domain which it is connected to.
FCLK acts as Cortex™-M3 free running clock. For more details refer to the ARM Cortex™M3 Technical Reference Manual.
4.2.1 HSE clock
The high speed external clock signal (HSE) can be generated from two possibl e clock
sources:
●HSE external crystal/ceramic resonator
●HSE user external clock
The resonator and the load capacitors have to be placed as close as possible to the
oscillator pins in order to minimize output distortion and startup stabilization time. The
loading capacitance values must be adjusted according to the selected oscillator.
Figure 8.HSE/ LSE clock sources
Hardware configuration
OSC_OUT
(HiZ)
External ClockCrystal/Ceramic Resonators
EXTERNAL
SOURCE
OSC_IN OSC_OUT
C
L1
LOAD
CAPACITORS
C
L2
External source (HSE bypass)
In this mode, an exte rnal clock source must be pro vided . It can ha v e a frequency of up to 25
MHz. You select this mode by setting the HSEBYP and HSEON
register (RCC_CR). The external clock signal (square, sinus or triangle) with ~50% dut y
cycle has to drive the OSC_IN pin while the OSC_OUT pin should b e left hi-Z. See Figure 8.
bits in the Clock control
50/501
Page 51
RM0008Reset and clock control (RCC)
External crystal/ceramic resonator (HSE crystal)
The 4 to 16 MHz external oscillator has the advantage of producing a very accurate rate on
the main clock.
The associated hardware configuration is shown in Figure 8. Refer to the electrical
characteristics section of the datasheet for more details.
The HSERDY flag in the Clock control register (RCC_CR) indicates if the high-speed
external oscillator is stable or not. At startup, the clock is not released until this bit is set by
hardware. An interrupt can be generated if enabled in the Clock interrupt register
(RCC_CIR).
The HSE Crystal can be switched on and off using the HSEON bit in the Clock control
register (RCC_CR).
4.2.2 HSI clock
The HSI clock signal is generated from an internal 8 MHz RC Oscillator and can be used
directly as a system clock or divided by 2 to be used as PLL input.
The HSI RC oscillator has the advantage of providing a clock source at low cost (no e xternal
components). It also has a faster startup time than the HSE crystal oscillator however, even
with calibration the frequency is less accurate than an external crystal oscillator or ceramic
resonator.
Calibration
RC oscillator frequencies can vary from one chip to another due to manufacturing process
variations, this is why each device is factory calibrated by ST for 1% accuracy at T
After Reset, the factory calibration value is loaded in the HSICAL[7:0] bits in the Clock
control register (RCC_CR).
If the application is subject to voltage or temperature variations this ma y affect the RC
oscillator speed. You can trim the HSI frequency in the application using the HSITRIM[4:0]
bits in the Clock control register (RCC_CR).
The HSIRD Y flag in the Clock control register (RCC_CR) indicates if the HSI RC is stab le or
not. At startup, the HSI RC output clock is not released until this bit is set by hardware.
The HSI RC can be switched on and off using the HSION bit in the Clock control register
(RCC_CR).
The HSI signal can also be used as a backup source (Auxiliary clock) if the HSE crystal
oscillator fails. Refer to Section 4.2.7: Clock security system (CSS) on page 53.
4.2.3 PLL
The internal PLL can be used to multiply the HSI RC output or HSE crystal output clock
frequency. Refer to Figure 7 and Clock control register (RCC_CR).
The PLL configuration (selection of HSI oscillator divided by 2 or HSE oscillator for PLL
input clock, and multiplication factor) must be done before enabling the PLL. Once the PLL
enabled, these parameters cannot be changed.
=25°C.
A
An interrupt can be generated when the PLL is ready if enabled in the Clock interrupt
register (RCC_CIR).
51/501
Page 52
Reset and clock control (RCC)RM0008
If the USB interface is used in the a pplica tion, th e PL L m ust be pr og rammed to output 48 or
72 MHz. This is needed to provide a 48 MHz USBCLK.
4.2.4 LSE clock
The LSE crystal is a 32.768 kHz Low Speed External crystal or ceramic resonator. It has the
advantage providing a low-power but highly accurate clock source to the real-time clock
peripheral (RTC) for clock/calendar or other timing functions.
The LSE crystal is switched on and off using the LSEON bit in Backup domain control
register (RCC_BDCR).
The LSERDY flag in the Backup domain control register (RCC_BDCR) indicates if the LSE
crystal is stable or not. At startup, the LSE crystal output clock signal is not released until
this bit is set by hardware. An interrupt can be generated if enabled in the Clock interrupt
register (RCC_CIR).
External source (LSE bypass)
In this mode, an ext ernal clock source must be provided. It must have a frequency of
32.768 kHz. You select this mode by setting the LSEBYP and LSEON bits in the Backup
domain control register (RCC_BDCR). The external clock signal (square, sinus or triangle)
with ~50% duty cycle has to drive the OSC32_IN pin while the OSC32_OUT pin should be
left Hi-Z. See Figure 8.
4.2.5 LSI clock
The LSI RC acts as an low-power clock source that can be kept running in Stop and
Standby mode for the independent watchdog (IWDG) and Auto Wakeup unit (AWU). The
clock frequency is around 40 kHz (between 30 kHz and 60 kHz). For more details, refer to
the electrical characteristics section of the datasheets.
The LSI RC can be switched on and off using the LSION bit in the Contro l/st at us re gis te r
(RCC_CSR).
The LSIRDY flag in the Control/status registe r (RCC _C SR) indicates if the low-speed
internal oscillator is stable or not. At startup, the clock is not released until this bit is set by
hardware. An interrupt can be generated if enabled in the Clock interrupt register
(RCC_CIR).
4.2.6 System clock (SYSCLK) selection
After a system Reset, the HSI oscillator is selected as system clock. When a clock source is
used directly or through the PLL as system clock, it is not possible to stop it.
A switch from one clock source to another occurs only if the target clock source is ready
(clock stable after startup delay or PLL locked). If a clock source which is not yet ready is
selected, the switch will occur when the clock source will be ready. Status bits in the Clock
control register (RCC_CR) indicate which clock(s) is (are) ready and which clock is currently
used as system clock.
52/501
Page 53
RM0008Reset and clock control (RCC)
4.2.7 Clock security system (CSS)
Clock Security System can be activated by software. In this case, the clock detector is
enabled after the HSE oscillator startup delay, and disabled when this oscillator is stopped.
If a failure is detected on the HSE oscillator clock, this oscillator is automatically disabled, a
clock failure event is sent to the break input of the TIM1 Advanced control timer and an
interrupt is generated to inform the software about the failure (Clock Security System
Interrupt CSSI), allowing the MCU to perform rescue operations. The CSSI is link ed to the
Cortex™-M3 NMI (Non-Maskable Interrupt) exception vector.
Note:Once the CSS is enabled and if the HSE clock fails, the CSS interrupt occurs and an NMI is
automatically generated. The NMI will be executed indefinitely unless the CSS interrupt
pending bit is cleared. As a consequence, in the NMI ISR user must clear the CSS interrupt
by setting the CSSC bit in the Clock interrupt register (RCC_CIR).
If the HSE oscillator is used directly or indirectly as the system clock (indirectly 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 to the HSI oscillator and the disab ling of the external
HSE oscillator. If the HSE oscillator clock (divided or not) is the clock entry of the PLL used
as system clock when the failure occurs, the PLL is disabled too.
4.2.8 RTC clock
The RTCCLK clock source can be either the HSE/128, LSE or LSI clocks. This is selected
by programming the RTCSEL[1:0] bits in the Backup domain control register (RCC_BDCR).
This selection cannot be modified without resetting the Backup domain.
The LSE clock is in the Backup do main, whereas the HSE and LSI clocks are not.
Consequently:
●If LSE is selected as RTC clock:
–The RTC continues to work even if the V
V
supply is maintained.
BAT
●If LSI is selected as Auto Wakeup unit (AWU) clock:
–The AWU state is not guaranteed if the V
●If the HSE clock divided by 128 is used as RTC clock:
–The RTC state is not guaranteed if the V
voltage regulator is powered off (removing power from the 1.8 V domain).
4.2.9 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.
4.2.10 Clock-out capability
The microcontroller clock output (MCO) capability allows the clock to be output onto the
external MCO pin. The configuration registers of the corresponding GPIO port must be
supply is switched off, provided the
DD
supply is powered off.
DD
supply is powered off or if the internal
DD
53/501
Page 54
Reset and clock control (RCC)RM0008
programmed in alternate function mode. One of 4 cloc k signals can be select ed as the MCO
clock.
●SYSCLK
●HSI
●HSE
●PLL clock divided by 2
The selection is controlled by the MCO[2:0] bits of the Clock configuration register
(RCC_CFGR).
4.3 RCC register description
Refer to Section 1.1 on page 23 for a list of abbreviations used in register descriptions.
4.3.1 Clock control register (RCC_CR)
Address offset: 0x00
Reset value: 0x0000 XX83 where X is undef ined.
Access: no wait state, word , half-word and byte access
31302928272625242322212019181716
Reserved
Res.rrwRes.rwrwrrw
1514131211109 87654321 0
HSICAL[7:0]HSITRIM[4:0]Res.
rrrrrrr rrwrwrwrwrw rrw
PLL
PLLONReserved
RDY
Bits 31:26 Reserved, always read as 0.
CSS ONHSE
BYP
HSE
RDY
HSI
RDY
HSE
ON
HSION
Bit 25 PLLRDY PLL clock ready flag
Set by hardware to indicate that the PLL is locked.
0: PLL unlocked
1: PLL locked
Bit 24 PLLON PLL enable
Set and reset by software to enable PLL.
Reset by hardware when entering Stop and Standby mode. This bit can not be reset if the PLL clock
is used as system clock or is selected to become the system clock.
0: PLL OFF
1: PLL ON
Bits 23:20 Reserved, always read as 0.
Bit 19 CSSON Clock Security System enable
Set and reset by software to enable clock detector.
0: Clock detector OFF
1: Clock detector ON if external 1-25 MHz oscillator is ready.
54/501
Page 55
RM0008Reset and clock control (RCC)
Bit 18 HSEBYP External High Speed clock Bypass
Set and reset by software in debug for bypassing oscillator with external clock. This bit can be
written only if the external 1-25 MHz oscillator is disabled.
0: external 1-25 MHz oscillator not bypassed
1: external 1-25 MHz oscillator bypassed with external clock
Bit 17 HSERDY External High Speed clock ready flag
Set by hardware to indicate that external 1-25 MHz oscillator is stable. This bit needs 6 cycles of
external 1-25 MHz oscillator clock to fall down after HSEON reset.
Set and reset by software.
Reset by hardware to stop the external 1-25MHz oscillator when entering in Stop and Standby
mode. This bit can not be reset if the external 1-25 MHz oscillator is used directly or indirectly as
system clock or is selected to become the system clock.
0: HSE oscillator OFF
1: HSE oscillator ON
Bits 15:8 HSICAL[7:0] Internal High Speed clock Calibration
These bits are initialized automatically at startup.
Bits 7:3 HSITRIM[4:0] Internal High Speed clock trimming
These bits provide an additional user-programmable trimming value that is added to the
HSICAL[7:0] bits. It can be programmed to adjust to variations in voltage and temperature that
influence the frequency of the internal HSI RC.
The default v alue i s 16, wh ich, w hen adde d to th e HSICAL v alue , sh ould trim th e HSI t o 8 MHz a t T
= 25 °C. The HSI RC frequency increases when the HSICAL value increases and decreases when
the HSICAL value decreases. The trimming step is 40 kHz between two consecutive HSICAL steps.
A
Bit 2 Reserved, always read as 0.
Bit 1 HSIRDY Internal High Speed clock ready flag
Set by hardware to indicate that internal 8 MHz RC oscillator is stable. This bit needs 6 cycles of the
internal 8 MHz RC oscillator clock to fall down after HSION reset.
Set and reset by software.
Set by hardware to force the internal 8 MHz RC oscillator ON when leaving Stop and Standby mode
or in case of failure of the external 1-25 MHz oscillator used directly or indirectly as system clock.
This bit can not be reset if the internal 8 MHz RC is used directly or indirectly as system clock or is
selected to become the system clock.
0: internal 8 MHz RC oscillator OFF
1: internal 8 MHz RC oscillator ON
55/501
Page 56
Reset and clock control (RCC)RM0008
4.3.2 Clock configuration register (RCC_CFGR)
Address offset: 0x04
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.
Set and reset by software to enable/disable interrupt caused by the internal 8 MHz RC oscillator
stabilization.
0: HSI ready interrupt disabled
1: HSI ready interrupt enabled
Bit 9 LSERDYIE LSE Ready Interrupt Enable
Set and reset by software to enable/disable interrupt caused by the external 40 kHz oscillator
stabilization.
Reset by software by writing CSSC.
Set by hardware when a failure is detected in the external 1-25 MHz oscillator.
0: No clock security interrupt caused by HSE clock failure
1: Clock security interrupt caused by HSE clock failure
Bits 6:5 Reserved, always read as 0.
Bit 4 PLLRDYF PLL Ready Interrupt flag
Reset by software by writing PLLRDYC.
Set by hardware when the PLL locks and PLLRDYDIE is set.
0: No clock ready interrupt caused by PLL lock
1: Clock ready interrupt caused by PLL lock
Bit3 HSERDYF HSE Ready Interrupt flag
Reset by software by writing HSERDYC.
Set by hardware when External Low Speed clock becomes stable and HSERDYDIE is set.
0: No clock ready interrupt caused by the external 1-25 MHz oscillator
1: Clock ready interrupt caused by the external 1-25 MHz oscillator
60/501
Page 61
RM0008Reset and clock control (RCC)
Bit 2 HSIRDYF HSI Ready Interrupt flag
Reset by software by writing HSIRDYC.
Set by hardware when the Internal High Speed clock becomes stable and HSIRDYDIE is set.
0: No clock ready interrupt caused by the internal 8 MHz RC oscillator
1: Clock ready interrupt caused by the internal 8 MHz RC oscillator
Bit 1 LSERDYF LSE Ready Interrupt flag
Reset by software by writing LSERDYC.
Set by hardware when the External Low Speed clock becomes stable and LSERDYDIE is set.
0: No clock ready interrupt caused by the external 32 kHz oscillator
1: Clock ready interrupt caused by the external 32 kHz oscillator
Bit 0 LSIRDYF LSI Ready Interrupt flag
Reset by software by writing LSIRDYC.
Set by hardware when Internal Low Speed clock becomes stable and LSIRDYDIE is set.
0: No clock ready interrupt caused by the internal RC 40 kHz oscillator
1: Clock ready interrupt caused by the internal RC 40 kHz oscillator
Address: 0x18
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 APB2 domain
is on going. In this case, wait states are inserted until this access to APB2 peripheral is
finished.
31302928272625242322212019181716
Reserved
Res.
1514131211109 87654321 0
USAR
Res;
Res.rwRes.rwrwrwrwRes.rwrwrwrwrwRes.rw
T1
EN
SPI1ENTIM1ENADC2ENADC1
Res;
EN
Reserved
IOPEENIOPDENIOPCENIOPBENIOPA
EN
Res.
AFIO
EN
Bits 31:15 Reserved, always read as 0.
Bit 14 USART1EN USART1 clock enable
Set and reset by software.
0: USART1 clock disabled
1: USART1 clock enabled
Bit 13 Reserved, always read as 0.
Bit 12 SPI1EN SPI 1 clock enable
Address: 0x1C
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. In this case, wait states are inserted until this access to APB1 peripheral is
finished.
31302928272625242322212019181716
Reserved
Res.rwrwrwrwrwrwrwrw
1514131211109876543210
SPI2
Res.
Res.rwRes.rwRes.rwrwrw
EN
PWRENBKP
Reserved
EN
WWD
GEN
Bits 31:29 Reserved, always read as 0.
Bit 28 PWREN Power interface clock enable
Set and reset by software.
0: Power interface clock disabled
1: Power interface clock enable
Bit 27 BKPEN Backup interface clock enable
Set and reset by software.
0: Backup interface clock disabled
1: Backup interface clock enabled
Bit 26 Reserved, always read as 0.
Res.
CAN
EN
Res.
USBENI2C2ENI2C1
Reserved
EN
Reserved
USART3ENUSART2
TIM4ENTIM3ENTIM2
EN
Res.
EN
Bit 25 CANEN CAN clock enable
Set and reset by software.
0: CAN clock disabled
1: CAN clock enabled
Bit 24 Reserved, always read as 0.
Bit 23 USBEN USB clock enable
Set and reset by software.
0: USB clock disabled
1: USB clock enabled
Bit 22 I2C2EN I2C 2 clock enable
Set and reset by software.
0: I2C 2 clock disabled
1: I2C 2 clock enabled
Bit 21 I2C1EN I2C 1 clock enable
Set and reset by software.
0: I2C 1 clock disabled
1: I2C 1 clock enabled
69/501
Page 70
Reset and clock control (RCC)RM0008
Bits 20:19 Reserved, always read as 0.
Bit 18 USART3EN USART 3 clock enable
Set and reset by software.
0: USART 3 clock disabled
1: USART 3 clock enabled
Bit 17 USART2EN USART 2 clock enable
Set and reset by software.
0: USART 2 clock disabled
1: USART 2 clock enabled
Bits 16:15 Reserved, always read as 0.
Bit 14 SPI2EN SPI 2 clock enable
Set and reset by software.
0: SPI 2 clock disabled
1: SPI 2 clock enabled
Bits 13:12 Reserved, always read as 0.
Bit 11 WWDGEN Window Watchdog clock enable
Set and reset by software.
0: Window watchdog clock disabled
1: Window watchdog clock enabled
Bits 10:3 Reserved, always read as 0.
Bit 2 TIM4EN Timer 4 clock enable
Set and reset by software.
0: Timer 4 clock disabled
1: Timer 4 clock enabled
Bit 1 TIM3EN Timer 3 clock enable
Set and reset by software.
0: Timer 3 clock disabled
1: Timer 3 clock enabled
Bit 0 TIM2EN Timer 2 clock enable
Set and reset by software.
0: Timer 2 clock disabled
1: Timer 2 clock enabled
70/501
Page 71
RM0008Reset and clock control (RCC)
4.3.9 Backup domain control register (RCC_BDCR)
Address: 0x20
Reset value: 0x0000 0000, reset by Backup domain Reset.
Access: 0 ≤ wait state ≤ 3, word, half-word and byte access
Wait states are inserted in case of successive accesses to this register.
Note:LSEON, LSEBYP, RTCSEL and RTCEN bits of the Backup domain control register
(RCC_BDCR) are in the Backup domain. As a result, after Reset, these bits are write
protected and the DBP bit in the Power control register (PWR_CR)has to be set before
these can be modified. Refer to Section 9.1 on page 132 for further information. These bits
are only reset after a Backup domain Reset and V
Reset will not have any effect on these bits.
31302928272625242322212019181716
ReservedBDRST
Res.rw
1514131211109 87654321 0
RTC
EN
rwRes.rwrwRes.rwrrw
Bits 31:17 Reserved, always read as 0.
ReservedRTCSEL[1:0]Reserved
power on. Any inte rnal or external
BAT
LSE
BYP
LSE
RDY
LSEON
Bit 16 BDRST Backup domain software reset
Set and reset by software.
0: Reset not activated
1: Resets the entire Backup domain
Bit 15 RTCEN RTC clock enable
Set and reset by software.
0: RTC clock disabled
1: RTC clock enabled
Bits 14:10 Reserved, always read as 0.
Bits 9:8 RTCSEL[1:0] RTC clock source selection
Set by software to select the clock source for the RTC. Once the RTC clock source has been
selected, it cannot be changed anymore unless the Backup domain is reset. The BDRST bit can be
used to reset them.
00: No clock
01: LSE oscillator clock used as RTC clock
10: LSI oscillator clock used as RTC clock
11: HSE oscillator clock divided by 128 used as RTC clock
Bits 7:3 Reserved, always read as 0.
Bit 2 LSEBYP External Low Speed oscillator Bypass
Set and reset by software to bypass oscillator in debug mode. This bit can be written only when the
external 32 kHz oscillator is disabled.
0: LSE oscillator not bypassed
1: LSE oscillator bypassed
71/501
Page 72
Reset and clock control (RCC)RM0008
Bit 1 LSERDY External Low Speed oscillator Ready
Set and reset by hardware to indicate when the external 32 kHz oscillator is stable. This bit needs 6
cycles of external Low Speed oscillator clock to fall down after LSEON reset.
0: External 32 kHz oscillator not ready
1: External 32 kHz oscillator ready
Bit 0 LSEON External Low Speed oscillator enable
Set and reset by software.
0: External 32 kHz oscillator OFF
1: External 32 kHz oscillator ON
4.3.10 Control/status register (RCC_CSR)
Address: 0x24
Reset value: 0x0C00 0000, reset by system Reset, except reset flags by power Reset only.
Access: 0 ≤ wait state ≤ 3, word, half-word and byte access
Wait states are inserted in case of successive accesses to this register.
31302928272625242322212019181716
LPWR
WWDG
RSTF
rwrwrwrwrwrwRes.rwRes.
1514131211109 87654321 0
Bit 31 LPWRRSTF Low-Power reset flag
Bit 30 WWDGRSTF Window watchdog reset flag
Bit 29 IWDGRSTF Independent Watchdog reset flag
RSTF
IWDG
RSTF
SFT
RSTF
POR
RSTF
PIN
RSTF
Res.RMVFReserved
Reserved
Res.rrw
LSI
RDY
Reset by software by writing the RMVF bit.
Set by hardware when a Low-power management reset occurs.
0: No Low-power management reset occurred
1: Low-power management reset occurred
For further information on Low-power management reset, refer to Section : Low-power management
Reset.
Reset by software by writing the RMVF bit.
Set by hardware when a window watchdog reset occurs.
0: No window watchdog reset occurred
1: Window watchdog reset occurred
Reset by software by writing the RMVF bit.
Set by hardware when a watchdog reset from V
domain occurs.
DD
0: No watchdog reset occurred
1: Watchdog reset occurred
LSION
72/501
Page 73
RM0008Reset and clock control (RCC)
Bit 28 SFTRSTF Software Reset flag
Reset by software by writing the RMVF bit.
Set by hardware when a software reset occurs.
0: No software reset occurred
1: Software reset occurred
Bit 27 PORRSTF POR/PDR reset flag
Reset by software by writing the RMVF bit.
Set by hardware when a POR/PDR reset occurs.
0: No POR/PDR reset occurred
1: POR/PDR reset occurred
Bit 26 PINRSTF PIN reset flag
Reset by software by writing the RMVF bit.
Set by hardware when a reset from the NRST pin occurs.
0: No reset from NRST pin occurred
1: Reset from NRST pin occurred
Bit 25 Reserved, always read as 0.
Bit 24 RMVF Remove reset flag
Set and reset by software to reset the value of the reset flags.
0: Reset of the reset flags not activated
1: Reset the value of the reset flags
Bits 23:2 Reserved, always read as 0.
Bit 1 LSIRDY Internal Low Speed oscillator Ready
Set and reset by hardware to indicate when the internal RC 40 kHz oscillator is stable. This bit
needs 3 cycles of internal RC 40 kHz oscillator to fall down after LSION reset.
0: Internal RC 40 kHz oscillator not ready
1: Internal RC 40 kHz oscillator ready
Bit 0 LSION Internal Low Speed oscillator enable
Set and reset by software.
0: Internal RC 40 kHz oscillator OFF
1: Internal RC 40 kHz oscillator ON
73/501
Page 74
Reset and clock control (RCC)RM0008
4.4 RCC register map
Table 10.RCC - register map and reset values
OffsetRegister
000h
004h
008h
00Ch
010h
014h
313029282726252423222120191817161514131211
RCC_CR
Reset value000000000 00 000 10 00011
RCC_CFGR
Reset value0000000 0000000000000000000
RCC_CIR
Reset value00000000000000000
RCC_APB2RSTR
Reset value00000000000
RCC_APB1RSTR
Reset value0000000000000
RCC_AHBENR
Reset value110
Reserved
Reserved
Reserved
Reserved
PWRRST
MCO [2:0]
BKPRST
Reserved
PLL ON
PLL RDY
Reserved
CANRST
Reserved
Reserved
PLLMUL[3:0]
USBPRE
Reserved
CSSC
Reserved
USBRST
I2C2RST
I2C1RST
CSSON
PLLRDYC
HSERDYC
Reserved
Reserved
HSEBYP
HSIRDYC
USART3RST
HSERDY
PLLXTPRE
LSERDYC
USART2RST
HSEON
PLLSRC
LSIRDYC
987654321
10
HSICAL[7:0]HSITRIM[4:0]
ADC
Reserved
PRE
[1:0]
Reserved
USART1RST
SPI2RST
PPRE2
[2:0]
Reserved
Reserved
PLLRDYIE
SPI1RST
PPRE1
HSERDYIE
TIM1RST
WWDGRST
[2:0]
HSIRDYIE
LSERDYIE
ADC2RST
ADC1RST
HPRE[3:0]
CSSF
LSIRDYIE
Reserved
Reserved
Reserved
IOPERST
SWS
[1:0]
PLLRDYF
HSERDYF
IOPBRST
IOPDRST
IOPCRST
FLITFEN
Reserved
HSIRDY
Reserved
SW
[1:0]
HSIRDYF
LSERDYF
Reserved
IOPARST
TIM4RST
TIM3RST
SRAMEN
Reserved
0
HSION
LSIRDYF
AFIORST
TIM2RST
DMAEN
018h
01Ch
020h
024h
RCC_APB2ENR
Reset value00000000000
RCC_APB1ENR
Reset value0000000000000
RCC_BDCR
Reset value0000000
RCC_CSR
Reset value 000011000
Reserved
LPWRSTF
WWDGRSTF
BKPEN
PWREN
SFTRSTF
PORRSTF
IWDGRSTF
CANEN
Reserved
Reserved
PINRSTF
Reserved
Reserved
USBEN
Reserved
RMVF
SPI1EN
TIM1EN
ADC2EN
USART1EN
Reserved
I2C2EN
I2C1EN
USART3EN
USART2EN
Reserved
Reserved
BDRST
RTCEN
SPI2EN
Reserved
Reserved
Reserved
ADC1EN
WWDGEN
RTC
SEL
[1:0]
IOPEEN
Reserved
Reserved
Reserved
IOPDEN
IOPBEN
IOPCEN
IOPAEN
TIM4EN
LSEBYP
Refer to Table 1 on page 27 for the register boundary addresses.
Reserved
TIM3EN
LSERDY
LSIRDY
AFIOEN
TIM2EN
LSEON
LSION
74/501
Page 75
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
5 General-purpose and alternate-function I/Os (GPIOs
and AFIOs)
5.1 GPIO functional description
Each of the general-purpose I/O ports has two 32-bit configuration registers (G PIOx_CRL,
GPIOx_CRH), two 32-bit data reg isters (GPIOx_IDR, GPIOx_ODR), a 32-bit set/reset
register (GPIOx_BSRR), a 16-bit reset register (GPIOx_BRR) and a 32-bit locking register
(GPIOx_LCKR).
Subject to the specific hardware chara cteristics of each I/O port listed in the datasheet, each
port bit of the General Purpose IO (GPIO) Ports, can be individually configured by software
in several modes:
–Input floating
–Input pull-up
–Input-pull-down
–Analog Input
–Output open-drain
–Output push-pull
–Alternate function pu sh- p ull
–Alternate function open-drain
Each I/O port bit is freely programmable , how ev er the I /O port registers hav e to be accessed
as 32-bit words (half-word or byte accesses are not allowed). The purpose of the
GPIOx_BSRR and GPIOx_BRR registers is to allow atomic read/modify accesses to an y of
the GPIO registers. This way, there is no risk that an IRQ occurs between the read and the
modify access.
Figure 9 shows the basic structure of an I/O Port bit.
75/501
Page 76
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
Figure 9.Basic structure of a standard I/O port bit
V
V
V
on/off
on/off
DD
P-MOS
N-MOS
SS
DD
V
SS
Push-pull,
open-drain or
disabled
V
DD
V
SS
Protection
diode
Protection
diode
ai14781
I/O pin
To on-chip
peripheral
Read
Write
Read/write
From on-chip
peripheral
Analog Input
Alternate Function Input
Input data register
Bit set/reset registers
Output data register
Alternate Function Output
TTL Schmitt
trigger
Input driver
Output driver
on/off
Output
control
Figure 10. Basic structure of a five-volt tolerant I/O port bit
V
V
on/off
on/off
DD
P-MOS
N-MOS
SS
V
V
Push-pull,
open-drain or
disabled
1. V
To on-chip
peripheral
Analog Input
Alternate Function Input
on/off
Read
TTL Schmitt
Input data register
Write
trigger
Input driver
Output driver
Bit set/reset registers
Read/write
From on-chip
peripheral
is a potential specific to five-volt tolerant I/Os and different from VDD.
DD_FT
Output data register
Alternate Function Output
Output
control
DD
(1)
V
DD_FT
Protection
diode
ai14782
I/O pin
SS
V
SS
76/501
Page 77
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
Table 11.Port bit configuration table
Configuration modeCNF1CNF0MODE1MODE0
General purpose
output
Alternate Function
output
Push-pull
Open-drain10 or 1
Push-pull
Open-drain1don’t care
Analog input
Input floating1don’t care
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
5.1.1 General-purpose I/O (GPIO)
During and just after reset, the alternate functions are not active and the I/O ports are
configured in Input Floating mode (CNFx[1:0]=01b, MODEx[1:0]=00b).
The JTAG pins are in input PU/PD after reset:
PA15: JTDI in PU
PA14: JTCK in PD
PA13: JTMS in PU
PB4: JNTRST in PU
When configured as output, the value written to the Output Data register (GPIOx_ODR) is
output on the I/O pin. It is possible t o use the output driv er in Push-Pull mode o r Open-Drain
mode (only the N-MOS is activat ed when outputting 0).
The Input Data register (GPIOx_IDR) captures the data present on the I/O pin at every
APB2 clock cycle.
All GPIO pins have a internal weak pull-up and weak pull-down which can be activated or
not when configured as input.
5.1.2 Atomic bit set or bit reset
There is no need for the software to disable interrupts when programming the GPIOx_ODR
at bit level: it is possible to modify only one or several bits in a single atomic APB2 write
access.
This is achieved by programming to ‘1’ the Bit Set/Reset Register (GPIOx_BSRR, or for
reset only GPIOx_BRR) to select the bits you want to modify. The unselected bits will not be
modified.
5.1.3 External interrupt/wakeup lines
All ports have external interrupt capability. To use external interrupt lines, the port must be
configured in input mode. For more information on external interrupts, refer to:
●Section 6.2: External interrupt/event controller (EXTI) on page 101 and
●Section 6.2.3: Wakeup event management on page 102.
5.1.4 Alternate functions (AF)
It is necessary to program the Po rt Bit Configuration Register before using a default
alternate function.
●For alternate function inputs, the port can be configured either:
–in Input mode (floating, pull-up or pull-down)
–in Alternate Function Output mode. In this case the input driver is configured in
input floating mode
●For Alternate Function Outputs, the port must be configured in Alternate Function
Output mode (Push-Pull or Open-Drain).
●For bidirectional Alternate Functions, the port bit must be configured in Alternate
Function Output mode (Push-Pull or Open-Drain). In this case the input driver is
configured in input floating mode
78/501
Page 79
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
If you configure a port bit as Alternate Function Output, this disconnects the output register
and connects the pin to the output signal of an on-chip peripheral.
If software configures a GPIO pin as Alternate Function Output, but peripheral is not
activated, its output is not specified.
5.1.5 Software remapping of I/O alternate functions
To optimize the number of peripheral I/O functions for different device packages, it is
possible to remap some alternate functions to some other pins. This is achieved by
software, by progr ammin g the correspon ding registers ( ref e r to AFIO regi ster description on
page 92. In that case, the alternate functions are no longer mapped to their original
assignations.
5.1.6 GPIO locking mechanism
The locking mechanism allows the IO configur ation to be f rozen . When th e LOCK sequence
has been applied on a port bit, it is no longer possible to modify the value of the port bit until
the next reset.
5.1.7 Input configuration
When the I/O Port is programmed as Input:
●The Output Buffer is disabled
●The Schmitt Trigger Input is activated
●The weak pull-up and pull-down resistors are activated or not depending on input
configuration (pull-up, pull-down or floating):
●The data present on the I/O pin is sampled into the Input Data Register every APB2
clock cycle
●A read access to the Input Data Register obtains the I/O State.
The Figure 11 on page 79 shows the Input Configuration of the I/O Port bit.
Figure 11. Input floating/pull up/pull down configurations
V
DD
on/off
on
TTL Schmitt
trigger
on/off
V
SS
79/501
1. V
Read
Write
Bit set/reset registers
Read/write
is a potential specific to five-volt tolerant I/Os and different from VDD.
DD_FT
Input data register
input driver
output driver
Output data register
V
DD
V
SS
or V
DD_FT
protection
diode
protection
diode
(1)
I/O pin
ai14783
Page 80
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
5.1.8 Output configuration
When the I/O Port is programmed as Output:
●The Output Buffer is enabled:
–Open Drain Mode: A “0” in the Output register activates the N-MOS while a “1” in
the Output register leaves the port in Hi-Z. (the P-MOS is never activated)
–Push-Pull Mode: A “0” in the Output register a ctiva tes the N-MOS while a “ 1” in the
Output register activates the P-MOS.
●The Schmitt Trigger Input is activated.
●The weak pull-up and pull-down resistors are disabled.
●The data present on the I/O pin is sampled into the Input Data Register every APB2
clock cycle
●A read access to the Input Data Register gets the I/O state in open dra in mode
●A read access to the Output Data register gets the last written value in Push-Pull mode
The Figure 12 on page 80 shows the Output configuration of the I/O Port bit.
Figure 12. Output configuration
Read
TTL Schmitt
trigger
Write
Read/write
1. V
Input data register
Input driver
Output driver
Bit set/reset registers
Output data register
is a potential specific to five-volt tolerant I/Os and different from VDD.
DD_FT
5.1.9 Alternate function configuration
When the I/O Port is programmed as Alternate Function:
●The Output Buffer is turned on in Open Drain or Push-Pull configuration
●The Output Buffer is driven b y the sign al coming from t he periphera l (alternate function
out)
●The Schmitt Trigger Input is activated
●The weak pull-up and pull-down resistors are disabled.
●The data present on the I/O pin is sampled into the Input Data Register every APB2
clock cycle
●A read access to the Input Data Register gets the I/O state in open dra in mode
●A read access to the Output Data register gets the last written value in Push-Pull mode
Output
control
on
DD_FT
ai14784
(1)
I/O pin
V
V
DD
P-MOS
N-MOS
SS
Push-pull or
Open-drain
V
DD
V
SS
or V
Protection
diode
Protection
diode
80/501
Page 81
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
The Figure 13 on page 81 shows the Alternate Function Configuration of the I/O Port bit.
Also, refer to Section 5.4: AFIO register description on page 92 for further information.
A set of Alternate Function I/O registers allow you to remap some alternate functions to
different pins. Refer to
Figure 13. Alternate function configuration
To on-chip
peripheral
Read
Write
Read/write
From on-chip
peripheral
1. V
DD_FT
Alternate Function Input
Input data register
Bit set/reset registers
Output data register
Alternate Function Output
is a potential specific to five-volt tolerant I/Os and different from VDD.
5.1.10 Analog input configuration
When the I/O Port is programmed as Analog Input Configuration:
●The Output Buffer is disabled.
●The Schmitt Trigger Input is de-activated providing ze ro consumption for every analog
value of the I/O pin. The output of the Schmitt Trigger is forced to a constant value (0).
●The weak pull-up and pull-down resistors are disabled.
●Read access to the Input Data Register gets the value “0”.
TTL Schmitt
trigger
Input driver
Output driver
Output
control
on
DD_FT
I/O pin
ai14785
(1)
V
V
DD
SS
P-MOS
N-MOS
push-pull or
open-drain
V
DD
VSS
or V
Protection
diode
Protection
diode
The Figure 14 on page 82 shows the High impedance-Analog Input Configu r ation of the I/ O
Port bit.
81/501
Page 82
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
Figure 14. High impedance-analog input configuration
To on-chip
peripheral
Read
Write
Read/write
From on-chip
peripheral
Analog Input
Bit set/reset registers
off
0
Input data register
Input driver
Output data register
TTL Schmitt
trigger
V
DD
V
SS
or V
Protection
diode
DD_FT
Protection
diode
I/O pin
ai14786
(1)
82/501
Page 83
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
5.2 GPIO register description
Refer to Section 1.1 on page 23 for a list of abbreviations used in register descriptions.
5.2.1 Port configuration register low (GPIOx_CRL) (x=A..E)
These bits are written by software to configure the corresponding I/O port.
Refer to Table 11: Port bit configuration table on page 77.In input mode (MODE[1:0]=00):
00: Analog input mode
01: Floating input (reset state)
10: Input with pull-up / pull-down
11: Reserved
In output mode (MODE[1:0]
> 00):
00: General purpose output push-pull
01: General purpose output Open-drain
10: Alternate function output Push-pull
11: Alternate function output Open-drain
MODEy[1:0]:Port x mode bits (y= 0 .. 7)
These bits are written by software to configure the corresponding I/O port.
Refer to Table 11: Port bit configuration table on page 77.
00: Input mode (reset state)
01: Output mode, max speed 10 MHz.
10: Output mode, max speed 2 MHz.
11: Output mode, max speed 50 MHz.
83/501
Page 84
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
5.2.2 Port configuration register high (GPIOx_CRH) (x=A..E)
These bits are written by software to configure the corresponding I/O port.
Refer to Table 11: Port bit configuration table on page 77.In input mode (MODE[1:0]=00):
00: Analog input mode
01: Floating input (reset state)
10: Input with pull-up / pull-down
11: Reserved
In output mode (MODE[1:0]
> 00):
00: General purpose output push-pull
01: General purpose output Open-drain
10: Alternate function output Push-pull
11: Alternate function output Open-drain
Bits 29:28, 25:24, 21:20,
17:16, 13:12, 9:8, 5:4, 1:0
MODEy[1:0]:Port x mode bits (y= 8 .. 15)
These bits are written by software to configure the corresponding I/O port.
Refer to Table 11: Port bit configuration table on page 77.
00: Input mode (reset state)
01: Output mode, max speed 10 MHz.
10: Output mode, max speed 2 MHz.
11: Output mode, max speed 50 MHz.
84/501
Page 85
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
5.2.3 Port input data register (GPIOx_IDR) (x=A..E)
These bits are write-only and can be accessed in Word mode only.
0: No action on the corresponding ODRx bit
1: Reset the corresponding ODRx bit
86/501
Page 87
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
5.2.7 Port configuration lock register (GPIOx_LCKR) (x=A..E)
This register is used to lock the configuration of the port bits when a correct write sequence
is applied to bit 16 (LCKK). The value of bits [15:0] is used to lock the configuration of the
GPIO. During the write sequence, the value of LCKR[15:0] must not change. When the
LOCK sequence has been applied on a port bit it is no longer possible to modify the value of
the port bit until the next reset.
Each lock bit freezes the corresponding 4 bits of the control register (CRL, CRH).
Address offset: 0x18
Reset value: 0x0000 0000
This bit can be read anytime. It can only be modified using the Lock Key Writing
Sequence.
0: Port configuration lock key not active
1: Port configuration lock key active. GPIOx_LCKR register is locked until an
MCU reset occurs.
LOCK Key Writing Sequence:
Write 1
Write 0
Write 1
Read 0
Read 1 (this read is optional but confirms that the lock is active)
Notes:
During the LOCK Key Writing sequence, the value of LCK[15:0] must not change.
Any error in the lock sequence will abort the lock.
Bits 15:0 LCKy: Port x Lock bit y (y= 0 .. 15)
These bits are read write but can only be written when the LCKK bit is 0.
0: Port configuration not locked
1: Port configuration locked.
87/501
Page 88
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
5.3 Alternate function I/O and debug configuration (AFIO)
To optimize the number of peripherals available for the 64-pin or the 100-pin package, it is
possible to remap some alternate functions to some other pins. This is achieved by
software, by programming the AF remap and debug I/O configuration register
(AFIO_MAPR) on page 93. In this case, the alternate functions are no longer mapped to
their original assignations.
5.3.1 Using OSC32_IN/OSC32_OUT pins as GPIO ports PC14/PC15
The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general-purpose I/O
PC14 and PC15, respectively, when the LSE oscillator is off. The LSE has priority over the
GP IOs function.
Note:1The PC14/PC15 GPIO functionality is lost when the 1.8 V domain is powered off (by
entering standby mode) or when the backup domain is supplied by V
supplied). In this case the IOs are set in analog input mode.
2Refer to the note on IO usage restrictions in Section 3.1.2 on page 34.
5.3.2 Using OSC_IN/OSC_OUT pins as GPIO ports PD0/PD1
The HSE oscillator pins OSC_IN/OSC_OUT can be used as general-purpose I/O PD0/PD1
by programming the PD01 _REMAP bit in the AF remap and de bug I/O config uration register
(AFIO_MAPR).
(VDD no more
BAT
This remap is available only on 36-, 48- and 64-pin packag es (P D0 and PD1 are available
on 100-pin packages, no need for remapping).
Note:The use of PD0 and PD1 in output mode is limited since PD0 and PD1 can only be used in
output mode at 50 MHz.
5.3.3 BXCAN alternate function remapping
The BXCAN signal can be mapped on Port A, Port B or Port D as shown in Table 13.
Table 13.BXCAN alternate function remapping
Alternate function
CANRXPA11PB8PD0
CANTXPA12PB9PD1
1. Remap not available on 36-pin package
CAN_REMAP[1:0] =
“00”
CAN_REMAP[1:0] =
“10”
(1)
CAN_REMAP[1:0] =
“11”
5.3.4 JTAG/SWD alternate function remapping
The debug interface signals are mapped on the GPIO ports as shown in Table 14.
Table 14.Debug interface signals
Alternate functionGPIO port
JTMS / SWDIOPA13
JTCK / SWCLKPA14
88/501
Page 89
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
To optimize the number of free GPIOs during deb ug gin g, this m app ing ca n be conf ig ured in
different ways by programming the SWJ_CFG[1:0] bi ts in the AF remap and debug I/O
configuration register (AFIO_MAPR). Refer to Table 15
Table 15.Debug port mapping
SWJ I/O pin assigned
SWJ
_CFG
[2:0]
Available debug ports
PA.13 /
JTMS/
SWDIO
PA.14 /
JTCK/S
WCLK
PA.15 /
JTDI
PB.3 /
JTDO/
TRACE
SWO
PB.4/
JNTRST
Full SWJ (JTAG-DP + SW-DP)
000
(Reset state)
Full SWJ (JTAG-DP + SW-DP)
001
but without JNTRST
JTAG-DP Disabled and
010
SW-DP Enabled
JTAG-DP Disabled and
100
SW-DP Disabled
freefreefreefreefree
Other Forbidden
1. Released only if not using asynchronous trace.
5.3.5 Timer alternate function remapping
Timer 4 channels 1 to 4 can be remapped from Port B to Port D.
Other timer remapping possibilities are listed in Table 17 to Table 19.
Refer to AF remap and debug I/ O configuration register (AFIO_MAPR).
Table 16.Timer 4 alternate function remapping
Alternate functionTIM4_REMAP = 0TIM4_REMAP = 1
TIM4_CH1PB6PD12
XXX X X
XXX xfree
XXfreefree
(1)
free
(1)
TIM4_CH2PB7PD13
89/501
Page 90
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
Refer to AF remap and debug I/ O configuration register (AFIO_MAPR)
Table 23.I2C1 remapping
Alternate functionI2C1_REMAP = 0 I2C1_REMAP = 1
I2C1_SCLPB6PB8
I2C1_SDAPB7PB9
1. Remap not available on 36-pin package.
5.3.8 SPI 1 alternate function remapping
Refer to AF remap and debug I/ O configuration register (AFIO_MAPR)
91/501
(1)
Page 92
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
Table 24.SPI1 remapping
Alternate functionSPI1_REMAP = 0SPI1_REMAP = 1
SPI1_NSSPA4PA15
SPI1_SCKPA5PB3
SPI1_MISOPA6PB4
SPI1_MOSIPA7PB5
5.4 AFIO register description
Refer to Section 1.1 on page 23 for a list of abbreviations used in register descriptions .
5.4.1 Event control register (AFIO_EVCR)
Address offset: 0x00
Reset value: 0x0000 0000
31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedEVOEPORT[2:0]PIN[3:0]
rwrwrwrwrwrwrwrw
Bits 31:8 Reserved
Bit 7 EVOE Event Output Enable
Set and cleared by software. When set the EVENTOUT Cortex output is connected to the I/O
selected by the PORT[2:0] and PIN[3:0] bits.
Bits 6:4 PORT[2:0]: Port selection
Set and cleared by software. Select the port used to output the Cortex EVENTOUT signal.
000: PA selected
001: PB selected
010: PC selected
011: PD selected
100: PE selected
Bits 3:0 PIN[3:0] Pin selection (x = A .. E)
Set and cleared by software. Select the pin used to output the Cortex EVENTOUT signal.
0000: Px0 selected
0001: Px1 selected
0010: Px2 selected
0011: Px3 selected
...
1111: Px15 selected
92/501
Page 93
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
5.4.2 AF remap and debug I/O configuration register (AFIO_MAPR)
Address offset: 0x04
Reset value: 0x0000 0000
31302928272625242322212019181716
Reserved
1514131211109876543210
PD01_
REMAP
CAN_REMAP
[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
TIM4_
REMAP
TIM3_REMAP
[1:0]
SWJ_
CFG[2:0]
rwrwrw
TIM2_REMAP
[1:0]
TIM1_REMAP
[1:0]
REMAP[1:0]
Bits 31:27 Reserved
Bits 26:24 SWJ_CFG[2:0] Serial Wire JTAG configuration
These bits are set and cleared by software. They are used to configure the SWJ and trace alternate
function I/Os. The SWJ (Serial Wire JT A G) supports JT A G or SWD access to the Cortex deb ug port.
The default state after reset is SWJ ON without trace. This allows JTAG or SW mode to be enabled
by sending a specific sequence on the JTMS / JTCK pin.
000: Full SWJ (JTAG-DP + SW-DP): Reset State
001: Full SWJ (JTAG-DP + SW-DP) but without JNTRST
010: JTAG-DP Disabled and SW-DP Enabled
100: JTAG-DP Disabled and SW-DP Disabled
Other combinations: Forbidden
USART3_
Reserved
USART
REMAP
USART
2_
REMAP
I2C1_
1_
REMAP
SPI1_
REMAP
Bits 23:16 Reserved
Bit 15 PD01_REMAP: Port D0/Port D1 mapping on OSC_IN/OSC_OUT
This bit is set and cleared by software. It controls the mapping of PD0 and PD1 GPIO functionality.
When the HSE oscillator is not used (application running on internal 8 MHz RC) PD0 and PD1 can
be mapped on OSC_IN and OSC_OUT. This is available only on 36-, 48- and 64-pin packages
(PD0 and PD1 are available on 100-pinpackages, no need for remapping).
0: No remapping of PD0 and PD1
1: PD0 remapped on OSC_IN, PD1 remapped on OSC_OUT,
Bits 14:13 CAN_REMAP[1:0] CAN Alternate function remapping
These bits are set and cleared by software. They control the mapping of Alternate Functions
CANRX and CANTX.
00: CANRX mapped to PA11, CANTX mapped to PA12
01: Not used
10: CANRX mapped to PB8, CANTX mapped to PB9 (not available on 36-pin package)
11: CANRX mapped to PD0, CANTX mapped to PD1
Bit 12 TIM4_REMAP TIM4 remapping
This bit is set and cleared by software. It controls the mapping of TIM4 channels 1 to 4 on 100-pin
packages only.
0: No remap (TIM4_CH1/PB6, TIM4_CH2/PB7, TIM4_CH3/PB8, TIM4_CH4/PB9)
1: Full remap (TIM4_CH1/PD12, TIM4_CH2/PD13, TIM4_CH3/PD14, TIM4_CH4/PD15)
Note: TIM4_ETR on PE0 is not re-mapped.
93/501
Page 94
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
Bits 11:10 TIM3_REMAP[1:0] TIM3 remapping
These bits are set and cleared by software. They control the mapping of TIM3 channels 1 to 4 on
the GPIO ports.
00: No remap (CH1/PA6, CH2/PA7, CH3/PB0, CH4/PB1)
01: Not used
10: Partial remap (CH1/PB4, CH2/PB5, CH3/PB0, CH4/PB1)
11: Full remap (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9)
Note: TIM3_ETR on PE0 is not re-mapped.
Bits 9:8 TIM2_REMAP[1:0] TIM2 remapping
These bits are set and cleared by software. They control the mapping of TIM2 channels 1 to 4 and
external trigger (ETR) on the GPIO ports.
00: No remap (CH1/ETR/PA0, CH2/PA1, CH3/PA2, CH4/PA3)
01: Partial remap (CH1/ETR/PA15, CH2/PB3, CH3/PA2, CH4/PA3)
10: Partial remap (CH1/ETR/PA0, CH2/PA1, CH3/PB10, CH4/PB11)
11: Full remap (CH1/ETR/PA15, CH2/PB3, CH3/PB10, CH4/PB11)
Bits 7:6 TIM1_REMAP[1:0] TIM1 remapping
These bits are set and cleared by software. They control the mapping of TIM2 channels 1 to 4, 1N to
3N, external trigger (ETR) and Break input (BKIN) on the GPIO ports.
00: No remap (ETR/PA12, CH1/PA8, CH2/PA9, CH3/PA10, CH4/PA11, BKIN/PB12, CH1N/PB13,
CH2N/PB14, CH3N/PB15)
01: Partial remap (ETR/PA12, CH1/PA8, CH2/PA9, CH3/PA10, CH4/PA11, BKIN/PA6, CH1N/PA7,
CH2N/PB0, CH3N/PB1)
10: not used
11: Full remap (ETR/PE7, CH1/PE9, CH2/PE11, CH3/PE13, CH4/PE14, BKIN/PE15, CH1N/PE8,
CH2N/PE10, CH3N/PE12)
Bits 5:4 USART3_REMAP[1:0] USART3 remapping
These bits are set and cleared by software. They control the mapping of USART3 CTS, R TS ,CK,TX
and RX alternate functions on the GPIO ports.
00: No remap (TX/PB10, RX/PB11, CK/PB12, CTS/PB13, RTS/PB14)
01: Partial remap (TX/PC10, RX/PC11, CK/PC12, CTS/PB13, RTS/PB14)
10: not used
11: Full remap (TX/PD8, RX/PD9, CK/PD10, CTS/PD11, RTS/PD12)
Bit 3 USART2_REMAP USART2 remapping
This bit is set and cleared by software. It controls the mapping of USART2 CTS, RTS ,CK,TX and RX
alternate functions on the GPIO ports.
This bit is set and cleared by software. It controls the mapping of USART1 TX and RX alternate
functions on the GPIO ports.
0: No remap (TX/PA9, RX/PA10)
1: Remap (TX/PB6, RX/PB7)
Bit 1 I2C1_REMAP I2C1 remapping
This bit is set and cleared by software. It controls the mapping of I2C1 SCL and SDA alternate
functions on the GPIO ports.
0: No remap (SCL/PB6, SDA/PB7)
1: Remap (SCL/PB8, SDA/PB9)
94/501
Page 95
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
Bit 0 SPI1_REMAP SPI1 remapping
This bit is set and cleared by software. It controls the mapping of SPI1 NSS, SCK, MISO, MOSI
alternate functions on the GPIO ports.
0: No remap (NSS/PA4, SCK/PA5, MISO/PA6, MOSI/PA7)
1: Remap (NSS/PA15, SCK/PB3, MISO/PB4, MOSI/PB5)
Bits 15:0 EXTIx[3:0]: EXTI x configuration (x= 4 to 7)
These bits are written by software to select the source input for EXTIx external interrupt.
0000: PA[x] pin
0001: PB[x] pin
0010: PC[x] pin
0011: PD[x] pin
0100: PE[x] pin
95/501
Page 96
General-purpose and alternate-functi on I/Os (GPIOs and AFIOs)RM0008
Bits 15:0 EXTIx[3:0]: EXTI x configuration (x= 8 to 11)
These bits are written by software to select the source input for EXTIx external interrupt.
0000: PA[x] pin
0001: PB[x] pin
0010: PC[x] pin
0011: PD[x] pin
0100: PE[x] pin
Bits 15:0 EXTIx[3:0]: EXTI x configuration (x= 12 to 15)
These bits are written by software to select the source input for EXTIx external interrupt.
0000: PA[x] pin
0001: PB[x] pin
0010: PC[x] pin
0011: PD[x] pin
0100: PE[x] pin
96/501
Page 97
RM0008General-purpose and alternate-function I/Os (GPIOs and AFIOs)
5.5 GPIO and AFIO register maps
Refer to Table 1 on page 27 for the register boundary addresses.
5.5.1 GPIO register map
Table 25.GPIO register map and reset values
OffsetRegister
00h
04h
08h
0Ch
10h
14h
18h
313029282726252423222120191817161514131211
CNF
MODE
CNF
MODE
CNF
GPIOx_CRL
Reset value 01000100010001000100010001000100
GPIOx_CRH
Reset value 01000100010001000100010001000100
GPIOx_IDR
Reset value0000000000000000
GPIOx_ODR
Reset value0000000000000000
GPIOx_BSRRBR[15:0]BSR[15:0]
Reset value 00000000000000000000000000000000
GPIOx_BRR
Reset value0000000000000000
GPIOx_LCKR
Reset value00000000000000000
7
[1:0]
CNF
15
[1:0]
7
[1:0]
MODE
15
[1:0]
6
[1:0]
CNF
14
[1:0]
6
[1:0]
MODE
14
[1:0]
Reserved
Reserved
Reserved
Reserved
5
[1:0]
CNF
13
[1:0]
MODE
5
[1:0]
MODE
13
[1:0]
5.5.2 AFIO register map
CNF
4
[1:0]
CNF
12
[1:0]
MODE
4
[1:0]
MODE
12
[1:0]
CNF
[1:0]
CNF
[1:0]
LCKK
987654321
CNF
2
[1:0]
CNF
10
[1:0]
10
MODE
2
[1:0]
MODE
10
[1:0]
IDR[15:0]l
ODR[15:0]
BR[15:0]
LCK[15:0]
CNF
1
[1:0]
CNF
9
[1:0]
MODE
1
[1:0]
MODE
9
[1:0]
CNF
0
[1:0]
CNF
8
[1:0]
MODE
3
3
[1:0]
MODE
11
11
[1:0]
MODE
0
[1:0]
MODE
8
[1:0]
0
Table 26.AFIO register map and reset values
OffsetRegister
00h
04h
08h
0Ch
10h
14h
313029282726252423222120191817161514131211
AFIO_EVCR
Reset value0000000
AFIO_MAPR
Reset value000000 00 00000000000
AFIO_EXTICR1
Reset value0000000000000000
AFIO_EXTICR2
Reset value0000000000000000
AFIO_EXTICR3
Reset value0000000000000000
AFIO_EXTICR4
Reset value0000000000000000
Reserved
SWJ_CFG[2]
SWJ_CFG[1]
SWJ_CFG[0]
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
987654321
10
PORT[2:0] PIN[3:0]
EVOE
PD01_REMAP
EXTI3[3:0]EXTI2[3:0]EXTI1[3:0]EXTI0[3:0]
EXTI7[3:0]EXTI6[3:0]EXTI5[3:0]EXTI4[3:0]
EXTI11[3:0] EXTI10[3:0]EXTI9[3:0]EXTI8[3:0]
EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
TIM4_REMPA P
CAN_REMAP[1]
CAN_REMAP[0]
TIM3_REMPAP[1]
TIM3_REMPAP[0]
TIM2_REMPAP[1]
TIM2_REMPAP[0]
TIM1_REMPAP[1]
TIM1_REMPAP[0]
USART3_REMAP[1]
USART3_REMAP[0]
USART2_REMAP
USART1_REMAP
I2C1_REMAP
0
SPI1_REMAP
97/501
Page 98
Interrupts and eventsRM0008
6 Interrupts and events
6.1 Nested vectored interrupt controller (NVIC)
Features
●43 maskable interrupt channels (not including the 16 interrupt lines of Cortex™-M3)
●16 programmable priority levels (4 bits of interrupt priority are used)
●Low-latency exception and interrupt handling
●Power management control
●Implementation of System Control Registers
The NVIC and the processor core interface are closely coupled, which enables low latency
interrupt processing and efficient processing of late arriving interrupts.
All interrupts including the core exceptions are managed b y th e NVIC. For more information
on exceptions and NVIC programming see Chap 5 Exceptions & Chap 8 Nested Vectored
Interrupt Controller of the ARM Cortex™-M3 Technical Reference Manual.
6.1.1 SysTick calibration value register
The SysTick calibration value is fixed to 9000 which allows the generation of a time base of
1ms with the SysTick clock set to 9 MHz (max HCLK/8).
6.1.2 Interrupt and exception vectors
Table 27.Vector table
Type of
priority
Priority
Position
---Reserved0x0000_0000
-3fixedResetReset0x0000_0004
-2fixedNMI
-1fixedHardFaultAll class of fault0x0000_000C
0settableMemManageMemory management0x0000_0010
1settableBusFaultPre-fetch fault, memory access fault0x0000_0014
2settableUsageFaultUndefined instruction or illegal state0x0000_0018
---Reserved
AcronymDescriptionAddress
Non maskable interrupt. The RCC
Clock Security System (CSS) is linked
to the NMI vector.
0x0000_0008
0x0000_001C -
0x0000_002B
3settableSVCall
4settableDebug MonitorDebug Monitor0x0000_0030
---Reserved0x0000_0034
5settablePendSVPendable request for system service0x0000_0038
2734settableTIM1_CCTIM1 Capture Compare interrupt0x0000_00AC
2835settableTIM2TIM2 global interrupt0x0000_00B0
2936settableTIM3TIM3 global interrupt0x0000_00B4
USB_HP_CAN_TXUSB High Priority or CAN TX
interrupts
USB_LP_CAN_
RX0
USB Low Priority or CAN RX0
interrupts
TIM1 Trigger and Commutation
interrupts
0x0000_008C
0x0000_0090
0x0000_00A8
99/501
Page 100
Interrupts and eventsRM0008
Table 27.Vector table (continued)
Position
Type of
priority
Priority
AcronymDescriptionAddress
3037settableTIM4TIM4 global interrupt0x0000_00B8
3138settableI2C1_EVI
3239settableI2C1_ERI
3340settableI2C2_EVI
3441settableI2C2_ERI
2
C1 event interrupt0x0000_00BC
2
C1 error interrupt0x0000_00C0
2
C2 event interrupt0x0000_00C4
2
C2 error interrupt0x0000_00C8
3542settableSPI1SPI1 global interrupt0x0000_00CC
3643settableSPI2SPI2 global interrupt0x0000_00D0
3744settableUSART1USART1 global interrupt0x0000_00D4
3845settableUSART2USART2 global interrupt0x0000_00D8
3946settableUSART3USART3 global interrupt0x0000_00DC
4047settableEXTI15_10EXTI Line[15:10] interrupts0x0000_00E0
4148settableRTCAlarmRTC alarm through EXTI line interrupt0x0000_00E4
4249settableUSBWakeup
USB wakeup from suspend through
EXTI line interrupt
0x0000_00E8
100/501
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.