stm32: peripherals - lirmm

32
STM32: Peripherals Alberto Bosio [email protected] Univeristé de Montpellier November 29, 2017

Upload: others

Post on 11-Jun-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: STM32: Peripherals - LIRMM

STM32: Peripherals

Alberto [email protected]

Univeristé de Montpellier

November 29, 2017

Page 2: STM32: Peripherals - LIRMM

2

System Architecture

Page 3: STM32: Peripherals - LIRMM

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.

Page 4: STM32: Peripherals - LIRMM

4

Memory map

Peripherals are memory mapped

Page 5: STM32: Peripherals - LIRMM

5

Memory map

Page 6: STM32: Peripherals - LIRMM

6

Memory map

Page 7: STM32: Peripherals - LIRMM

7

Memory map

Page 8: STM32: Peripherals - LIRMM

8

Memory map

Page 9: STM32: Peripherals - LIRMM

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

Page 10: STM32: Peripherals - LIRMM

10

Example: Using on board LEDs

On which bus LEDs are connected?

Page 11: STM32: Peripherals - LIRMM

11

Example: Using on board LEDs

On which bus LEDs are connected? Read DATA SHEET!

Page 12: STM32: Peripherals - LIRMM

12

Example: Using on board LEDs

Page 13: STM32: Peripherals - LIRMM

13

Example: Using on board LEDs

Page 14: STM32: Peripherals - LIRMM

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?

Page 15: STM32: Peripherals - LIRMM

15

Example: Using on board LEDs

Page 16: STM32: Peripherals - LIRMM

16

Example: Using on board LEDs

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

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

Page 17: STM32: Peripherals - LIRMM

17

Example: Using on board LEDs

Can you write the assembler code?

Page 18: STM32: Peripherals - LIRMM

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

Page 19: STM32: Peripherals - LIRMM

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?

Page 20: STM32: Peripherals - LIRMM

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?

Page 21: STM32: Peripherals - LIRMM

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

Page 22: STM32: Peripherals - LIRMM

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.

Page 23: STM32: Peripherals - LIRMM

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:

Page 24: STM32: Peripherals - LIRMM

24

External and internal interrupt/event line mapping

Page 25: STM32: Peripherals - LIRMM

25

External and internal interrupt/event line mapping

Page 26: STM32: Peripherals - LIRMM

26

Configuring Interrupts

Configure the corresponding mask bit in the EXTI_IMRregister:

Page 27: STM32: Peripherals - LIRMM

27

Configuring Interrupts

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

Page 28: STM32: Peripherals - LIRMM

28

Configuring Interrupts

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

Page 29: STM32: Peripherals - LIRMM

29

Configuring Interrupts

Set the Interrupt Service Routine (Vector Table)

Page 30: STM32: Peripherals - LIRMM

30

Configuring Interrupts

Page 31: STM32: Peripherals - LIRMM

31

Configuring Interrupts

Page 32: STM32: Peripherals - LIRMM

32

Configuring Interrupts

Clear the pending request.