STM32: Peripherals - LIRMM

Preview:

Citation preview

STM32: Peripherals

Alberto Bosiobosio@lirmm.fr

Univeristé de Montpellier

November 29, 2017

2

System Architecture

3

System Architecture

S0: I-bus: This bus connects the Instruction bus of theCortex-M4 core to the BusMatrix. This bus is used by the coreto fetch instructions. The targets of this bus are the internalFlash memory, the SRAM and the CCM RAM.S1: D-bus: This bus connects the DCode bus (literal loadand debug access) of the Cortex-M4 core to the BusMatrix.The targets of this bus are the internal Flash memory, theSRAM and the CCM RAM.S2: S-bus: This bus connects the system bus of theCortex-M4 core to the BusMatrix. This bus is used to accessdata located in the peripheral or SRAM area. The targets ofthis bus are the SRAM, the AHB to APB1/APB2 bridges, theAHB IO port and the ADC.S3, S4: DMA-bus: This bus connects the AHB masterinterface of the DMA to the BusMatrix which manages theaccess of different Masters to Flash, SRAM and peripherals.

4

Memory map

Peripherals are memory mapped

5

Memory map

6

Memory map

7

Memory map

8

Memory map

9

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 peripheralI When the peripheral clock is not active, the peripheral register

values may not be readable by software and the returned valueis always 0x0.

RCC_AHBENR, RCC_APB1RSTR, RCC_APB2RSTR

10

Example: Using on board LEDs

On which bus LEDs are connected?

11

Example: Using on board LEDs

On which bus LEDs are connected? Read DATA SHEET!

12

Example: Using on board LEDs

13

Example: Using on board LEDs

14

Example: Using on board LEDs

We have to use GPIOE connected to bus AHBLet us configure the correct RCC register: RCC_AHBENR

I How to write? (address)I Which value?

15

Example: Using on board LEDs

16

Example: Using on board LEDs

We have to write ‘1’ on the bit 21Address: base + offset

I base = 0x40021000I offset = 0x14I address = 0x40021014

17

Example: Using on board LEDs

Can you write the assembler code?

18

Example: Using on board LEDs

Next steps are:I Configure the GPIOE in output modeI Write a value in order to switch on/off LEDs

19

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?

20

Example: Using on board LEDs

Write a value in order to switch on/off LEDs:

Which value do you have to write? Which address?

21

Interrupts

Nested vectored interrupt controller (NVIC)I 74 maskable interrupt channelsI 16 programmable priority levels (4 bits of interrupt priority are

used)I Low-latency exception and interrupt handlingI Power management controlI Implementation of System Control Registers

22

Configuring Interrupts

To configure a line as interrupt source, use the followingprocedure:

I Configure the corresponding mask bit in the EXTI_IMRregister.

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.

23

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 areexternal.The GPIOs are connected to the 16 external interrupt/eventlines in the following manner:

24

External and internal interrupt/event line mapping

25

External and internal interrupt/event line mapping

26

Configuring Interrupts

Configure the corresponding mask bit in the EXTI_IMRregister:

27

Configuring Interrupts

Configure the Trigger Selection bits of the Interrupt line(EXTI_RTSR)

28

Configuring Interrupts

Configure the Trigger Selection bits of the Interrupt line(EXTI_FTSR)

29

Configuring Interrupts

Set the Interrupt Service Routine (Vector Table)

30

Configuring Interrupts

31

Configuring Interrupts

32

Configuring Interrupts

Clear the pending request.

Recommended