STM32: Peripherals
Alberto Bosio bosio@lirmm.fr
Univeristé de Montpellier
November 29, 2017
System Architecture
System Architecture
S0: I-bus: This bus connects the Instruction bus of the Cortex-M4 core to the BusMatrix. This bus is used by the core to fetch instructions. The targets of this bus are the internal Flash memory, the SRAM and the CCM RAM.
S1: D-bus: This bus connects the DCode bus (literal load and debug access) of the Cortex-M4 core to the BusMatrix.
The targets of this bus are the internal Flash memory, the SRAM and the CCM RAM.
S2: S-bus: This bus connects the system bus of the
Cortex-M4 core to the BusMatrix. This bus is used to access data located in the peripheral or SRAM area. The targets of this bus are the SRAM, the AHB to APB1/APB2 bridges, the AHB IO port and the ADC.
S3, S4: DMA-bus: This bus connects the AHB master interface of the DMA to the BusMatrix which manages the
Memory map
Peripherals are memory mapped
Memory map
Memory map
Memory map
Memory map
Reset and clock control (RCC)
System clock (SYSCLK) selection:
I HSI clock: generated from an internal 8 MHz RC Oscillator RCC registers allow to enable the use of a particular peripheral
I When the peripheral clock is not active, the peripheral register values may not be readable by software and the returned value is always 0x0.
RCC_AHBENR, RCC_APB1RSTR, RCC_APB2RSTR
Example: Using on board LEDs
On which bus LEDs are connected?
Example: Using on board LEDs
On which bus LEDs are connected? Read DATA SHEET!
Example: Using on board LEDs
Example: Using on board LEDs
Example: Using on board LEDs
We have to use GPIOE connected to bus AHB
Let us configure the correct RCC register: RCC_AHBENR
I How to write? (address)
I Which value?
Example: Using on board LEDs
Example: Using on board LEDs
We have to write ‘1’ on the bit 21 Address: base + offset
I base = 0x40021000
I offset = 0x14
I address = 0x40021014
Example: Using on board LEDs
Can you write the assembler code?
Example: Using on board LEDs
Next steps are:
I Configure the GPIOE in output mode
I Write a value in order to switch on/off LEDs
Example: Using on board LEDs
Configure the GPIOE in output mode:
I GPIO port mode register (GPIOx_MODER)
Which value do you have to write? Which address?
Example: Using on board LEDs
Write a value in order to switch on/off LEDs:
Which value do you have to write? Which address?
Interrupts
Nested vectored interrupt controller (NVIC)
I 74 maskable interrupt channels
I 16 programmable priority levels (4 bits of interrupt priority are used)
I Low-latency exception and interrupt handling
I Power management control
I Implementation of System Control Registers
Configuring Interrupts
To configure a line as interrupt source, use the following procedure:
I Configure the corresponding mask bit in the EXTI_IMR register.
I Configure the Trigger Selection bits of the Interrupt line (EXTI_RTSR and EXTI_FTSR).
I Set the Interrupt Service Routine.
I Clear the pending request.
External and internal interrupt/event line mapping
36 interrupt/event lines are available: 8 lines are internal (including the reserved ones); the remaining 28 lines are external.
The GPIOs are connected to the 16 external interrupt/event lines in the following manner:
External and internal interrupt/event line mapping
External and internal interrupt/event line mapping
Configuring Interrupts
Configure the corresponding mask bit in the EXTI_IMR register:
Configuring Interrupts
Configure the Trigger Selection bits of the Interrupt line (EXTI_RTSR)
Configuring Interrupts
Configure the Trigger Selection bits of the Interrupt line (EXTI_FTSR)
Configuring Interrupts
Set the Interrupt Service Routine (Vector Table)
Configuring Interrupts
Configuring Interrupts
Configuring Interrupts
Clear the pending request.