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.
Interrupt mask, edge trigger selection, pending flag and line-to-pin routing
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.
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.
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. |
| Offset | Register | Reset value | Description | Current trainer support |
|---|---|---|---|---|
| 0x00 | EXTI_IMR | 0x00000000 | Interrupt mask register | Exposed; MR6 gates Hall interrupt handling. |
| 0x04 | EXTI_EMR | 0x00000000 | Event mask register | RM0008 reference only for this trainer; not exposed by the current header/MMIO contract. |
| 0x08 | EXTI_RTSR | 0x00000000 | Rising trigger selection register | Exposed; TR6 enables Hall rising-edge counting. |
| 0x0C | EXTI_FTSR | 0x00000000 | Falling trigger selection register | Exposed for reference shape; current Hall counting path is rising-edge only. |
| 0x10 | EXTI_SWIER | 0x00000000 | Software interrupt event register | RM0008 reference only for this trainer; not exposed by the current header/MMIO contract. |
| 0x14 | EXTI_PR | 0x00000000 | Pending register | Exposed; 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.
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.
Address offset: 0x08
Reset value: 0x00000000
Set RTSR6 to enable rising edge detection on line 6.
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.
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.
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.
| Register | Current use | Main role | Read it together with |
|---|---|---|---|
| RCC_APB2ENR | Use now | Turns on the AFIO helper path and the GPIOA register block before EXTI setup starts. | Figure 1 source-selection path, GPIOA_CRL. |
| GPIOA_CRL | Use now | Places PA6 in digital input mode so the Hall signal can reach EXTI. | Figure 1 PA6 route, Figure 2 selected input. |
| EXTI_IMR | Use now | Unmasks line 6 so the pending edge can become an interrupt request. | Figure 2 interrupt gate. |
| EXTI_RTSR | Use now | Selects the rising Hall edge used in the current trainer route. | Figure 2 rising trigger path. |
| EXTI_FTSR | Visible nearby | Shows how falling-edge detection would be added in the full EXTI model. | Figure 2 falling trigger path. |
| EXTI_PR | Use now | Clears the sticky pending bit after the interrupt is serviced. | Figure 2 pending latch. |
| AFIO_EXTICR2 | RM0008 reference only | Selects 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_SWIER | RM0008 reference only | Show the event and software-trigger branches in the official EXTI model. | Figure 2 event/software branches; not exposed by the trainer header/MMIO map. |
// 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.
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.