External interrupt / event controllerEXTI Chapter

EXTI Datasheet

Interrupt mask, edge trigger selection, pending flag and line-to-pin routing

Document ID
EXTI-DS001
Revision
Rev 1.0
Base address
0x40010400
Scope
Line 6 centered EXTI subset
EXTI does not replace the GPIO input path. It observes the selected GPIO line, detects configured signal edges and generates an interrupt or event request. GPIO input configuration and EXTI edge configuration are therefore programmed separately.

Contents

  1. General description
  2. Main features
  3. EXTI architecture
  4. Register map and reset values
  5. Register descriptions
  6. Student register guide and code examples

1 General description

The external interrupt / event controller generates interrupt requests from selected GPIO input transitions. Each EXTI line may be masked or unmasked, and rising edge or falling edge detection can be enabled independently. When a configured edge is detected, the corresponding pending bit is set until cleared by software.

In the implemented subset used by the site, line 6 is the primary line of interest. On the real STM32F103, EXTI line 6 can be sourced from PA6, PB6, PC6, and the matching line-6 pad on other ports through AFIO_EXTICR2. The current trainer keeps only the fixed PA6 -> EXTI6 -> HALL_IN route.

EXTI6 source selection and trainer route

Figure 1. Official EXTI6 source-selection concept and the current fixed PA6 trainer route

Source reconstruction from RM0008 Rev 21 Figure 21, External interrupt/event GPIO mapping, and AFIO_EXTICR2 register description, with DS5319 Rev 20 pin-table context. Reconstructed trainer-scope drawing; no vendor PDF image was pasted.

2 Main features

3 EXTI architecture

EXTI line signal flow

Figure 2. EXTI6 internal block flow reconstructed from the STM32F103 reference-manual model

Source reconstruction from RM0008 Rev 21 Figure 20, External interrupt/event controller block diagram, and EXTI register descriptions for IMR, EMR, RTSR, FTSR, SWIER, and PR. Trainer scope is PA6/HALL_IN rising-edge handling.

The trainer-relevant path is Hall sensor to PA6 to EXTI6 to pending flag to ISR. Falling-edge configuration remains exposed for reference-manual shape, but the current lab flow uses rising Hall pulses only. Event mode and software interrupt injection are official RM0008 reference paths; the current trainer header/MMIO map does not expose EXTI_EMR or EXTI_SWIER as executable registers.

EXTI line GPIO source Common use Implemented note
Line 6 PA6 / PB6 / PC6 / ... (official), PA6 only (trainer) Hall pulse interrupt input in the trainer The current runtime hardwires line 6 to the Hall path on PA6.

4 Register map and reset values

OffsetRegisterReset valueDescriptionCurrent trainer support
0x00EXTI_IMR0x00000000Interrupt mask registerExposed; MR6 gates Hall interrupt handling.
0x04EXTI_EMR0x00000000Event mask registerRM0008 reference only for this trainer; not exposed by the current header/MMIO contract.
0x08EXTI_RTSR0x00000000Rising trigger selection registerExposed; TR6 enables Hall rising-edge counting.
0x0CEXTI_FTSR0x00000000Falling trigger selection registerExposed for reference shape; current Hall counting path is rising-edge only.
0x10EXTI_SWIER0x00000000Software interrupt event registerRM0008 reference only for this trainer; not exposed by the current header/MMIO contract.
0x14EXTI_PR0x00000000Pending registerExposed; PR6 is cleared by writing 1.

The offsets in this table are the official RM0008 EXTI offsets. The trainer's C pointer struct is compacted to the exposed subset, while the symbolic constants EXTI_IMR, EXTI_RTSR, EXTI_FTSR, and EXTI_PR preserve the official addresses for read_reg() / write_reg() examples.

5 Register descriptions

5.1 Interrupt mask register (EXTI_IMR)

Address offset: 0x00
Reset value: 0x00000000

If IMR6 = 0, the line is masked and no interrupt request reaches the CPU even if edge detection occurs.

5.2 Rising trigger selection register (EXTI_RTSR)

Address offset: 0x08
Reset value: 0x00000000

Set RTSR6 to enable rising edge detection on line 6.

5.3 Falling trigger selection register (EXTI_FTSR)

Address offset: 0x0C
Reset value: 0x00000000

Set FTSR6 to define falling-edge detection in the official register model. The current training workflow does not use falling Hall edges, and the runtime-visible Hall counting path is rising-edge only.

5.4 Pending register (EXTI_PR)

Address offset: 0x14
Reset value: 0x00000000

Pending bits are sticky. Software clears the pending condition by writing 1 to the corresponding bit position. Writing 0 has no effect.

5.5 Related AFIO source-selection register (AFIO_EXTICR2)

AFIO_EXTICR2.EXTI6[3:0] selects which GPIO line-6 pad feeds EXTI line 6 in the full STM32F103 source-selection model. The value 0000 selects PA6, 0001 selects PB6, and 0010 selects PC6. The current trainer fixes the source to the PA6 / HALL_IN route. AFIO_EXTICR2 is RM0008 reference material here, not a runnable trainer symbol.

6 Student register guide and code examples

RegisterCurrent useMain roleRead it together with
RCC_APB2ENRUse nowTurns on the AFIO helper path and the GPIOA register block before EXTI setup starts.Figure 1 source-selection path, GPIOA_CRL.
GPIOA_CRLUse nowPlaces PA6 in digital input mode so the Hall signal can reach EXTI.Figure 1 PA6 route, Figure 2 selected input.
EXTI_IMRUse nowUnmasks line 6 so the pending edge can become an interrupt request.Figure 2 interrupt gate.
EXTI_RTSRUse nowSelects the rising Hall edge used in the current trainer route.Figure 2 rising trigger path.
EXTI_FTSRVisible nearbyShows how falling-edge detection would be added in the full EXTI model.Figure 2 falling trigger path.
EXTI_PRUse nowClears the sticky pending bit after the interrupt is serviced.Figure 2 pending latch.
AFIO_EXTICR2RM0008 reference onlySelects whether line 6 comes from PA6, PB6, PC6, or another line-6 pad on a real STM32F103.Figure 1 source-selection box; not exposed by the trainer header/MMIO map.
EXTI_EMR / EXTI_SWIERRM0008 reference onlyShow the event and software-trigger branches in the official EXTI model.Figure 2 event/software branches; not exposed by the trainer header/MMIO map.

6.1 Current trainer code example

// Current trainer: PA6 -> EXTI6 -> HALL_IN route is fixed
RCC->APB2ENR |= (1u << 0);   // AFIOEN
RCC->APB2ENR |= (1u << 2);   // IOPAEN

GPIOA->CRL &= ~(0xFu << (6 * 4));
GPIOA->CRL |=  (0x4u << (6 * 4));  // PA6 input for Hall signal

EXTI->IMR  |= (1u << 6);
EXTI->RTSR |= (1u << 6);
EXTI->FTSR &= ~(1u << 6);

void EXTI6_IRQHandler(void)
{
    if ((EXTI->PR & (1u << 6)) != 0) {
        EXTI->PR = (1u << 6);  // clear pending
    }
}

Watch this code in Register View RCC_APB2ENR, GPIOA_CRL, EXTI_IMR, EXTI_RTSR, and EXTI_PR, then confirm the same Hall signal in Pin View and Graph View.

6.2 Full STM32F103 reference notes

On the real STM32F103, line 6 source selection is programmed through AFIO_EXTICR2.EXTI6[3:0]; value 0000 selects PA6. Official firmware services line 6 through the shared EXTI9_5_IRQHandler vector.

Those official names are intentionally kept as reference text, not trainer code. The current trainer exposes the fixed PA6 -> EXTI6 -> HALL_IN route and the dedicated EXTI6_IRQHandler hook because only the Hall route is modeled.

External interrupt / event controller descriptionEXTI-DS001 Rev 1.0