5.5 EXTI Guide

This chapter describes the file layout and the 8 public functions of the EXTI driver in the N32G033 standard peripheral library, together with the single example (KeyInterrupt). Read the “EXTI” chapter of the user manual for the trigger edge, event mode, and pin mapping, the AFIO chapter for the alternate-function numbers, and the errata sheet for known chip issues.

5.5.1 Related files

Relative path Purpose
firmware/n32g033_std_periph_driver/inc/n32g033_exti.h Defines the EXTI_InitType structure and the macros for trigger edge and interrupt and event modes, and declares 8 public functions in one contiguous block
firmware/n32g033_std_periph_driver/src/n32g033_exti.c Implements those 8 functions: EXTI reset and initialization, software interrupt, and reading and clearing the status flag and interrupt pending bit
projects/n32g033_EVAL/examples/EXTI/ EXTI example root directory, with 1 example: KeyInterrupt
projects/n32g033_EVAL/examples/EXTI/KeyInterrupt/ Project layout of this example: MDK-ARM/, EWARM/, inc/, src/, and readme.txt
projects/n32g033_EVAL/bsp/ Board support files shared by the examples: the serial log interface in log.h

5.5.2 API reference

Search API8 functions

The following 8 public functions are listed in the declaration order of n32g033_exti.h in 1 group; each entry gives a summary and the original comment above the function in n32g033_exti.c.

Initialization, triggering, and flag handling

EXTI_DeInit, EXTI_InitPeripheral, EXTI_InitStruct, EXTI_TriggerSWInt, EXTI_GetStatusFlag, EXTI_ClrStatusFlag, EXTI_GetITStatus, EXTI_ClrITPendBit

void EXTI_DeInit(void)Reset the EXTI registers.
Source comment
name    EXTI_DeInit.
fun     Reset the EXTI registers.
return  none
void EXTI_InitPeripheral(const EXTI_InitType* EXTI_InitStruct)Initializes the EXTI according to EXTI_InitStruct.
Source comment
name    EXTI_InitPeripheral.
fun     Initializes the EXTI according to EXTI_InitStruct.
param   EXTI_InitStruct(The input parameters must be the following values) :
          - EXTI_Line
            - EXTI_LINENONE
            - EXTI_LINE0
            - EXTI_LINE1
            - EXTI_LINE2
            - EXTI_LINE3
            - EXTI_LINE4
            - EXTI_LINE5
            - EXTI_LINE6
            - EXTI_LINE7
            - EXTI_LINE8
            - EXTI_LINE9
            - EXTI_LINE10
          - EXTI_Mode
            - EXTI_Mode_Interrupt
            - EXTI_Mode_Event
          - EXTI_Trigger
            - EXTI_Trigger_Rising
            - EXTI_Trigger_Falling
            - EXTI_Trigger_Rising_Falling
          - EXTI_LineCmd:
            - ENABLE
            - DISABLE
return  none
void EXTI_InitStruct(EXTI_InitType* EXTI_InitStruct)Fills each EXTI_InitStruct member with its default value.
Source comment
name    EXTI_InitStruct.
fun     Fills each EXTI_InitStruct member with its default value.
param   EXTI_StructInit :
            - - Pointer to the EXTI_InitType structure which will be initialized.
return  none
void EXTI_TriggerSWInt(uint32_t EXTI_Line)Generates a Software interrupt.
Source comment
name    EXTI_TriggerSWInt.
fun     Generates a Software interrupt.
param   EXTI_Line(The input parameters must be the following values) :
            - EXTI_LINE0
            - EXTI_LINE1
            - EXTI_LINE2
            - EXTI_LINE3
            - EXTI_LINE4
            - EXTI_LINE5
            - EXTI_LINE6
            - EXTI_LINE7
            - EXTI_LINE8
            - EXTI_LINE9
            - EXTI_LINE10
return  none
FlagStatus EXTI_GetStatusFlag(uint32_t EXTI_Line)Get EXTI line flag status.
Source comment
name    EXTI_GetStatusFlag.
fun     Get EXTI line flag status.
param   EXTI_Line(The input parameters must be the following values) :
            - EXTI_LINE0
            - EXTI_LINE1
            - EXTI_LINE2
            - EXTI_LINE3
            - EXTI_LINE4
            - EXTI_LINE5
            - EXTI_LINE6
            - EXTI_LINE7
            - EXTI_LINE8
            - EXTI_LINE9
            - EXTI_LINE10
return  SET or RESET
void EXTI_ClrStatusFlag(uint32_t EXTI_Line)Clear EXTI line flag status.
Source comment
name    EXTI_ClrStatusFlag.
fun     Clear EXTI line flag status.
param   EXTI_Line :
            - EXTI_LINE0
            - EXTI_LINE1
            - EXTI_LINE2
            - EXTI_LINE3
            - EXTI_LINE4
            - EXTI_LINE5
            - EXTI_LINE6
            - EXTI_LINE7
            - EXTI_LINE8
            - EXTI_LINE9
            - EXTI_LINE10
return  none
INTStatus EXTI_GetITStatus(uint32_t EXTI_Line)GET EXTI line interrupt status.
Source comment
name    EXTI_GetITStatus.
fun     GET EXTI line interrupt status.
param   exti_line :
            - EXTI_LINE0
            - EXTI_LINE1
            - EXTI_LINE2
            - EXTI_LINE3
            - EXTI_LINE4
            - EXTI_LINE5
            - EXTI_LINE6
            - EXTI_LINE7
            - EXTI_LINE8
            - EXTI_LINE9
            - EXTI_LINE10
return  SET or RESET
void EXTI_ClrITPendBit(uint32_t EXTI_Line)Clear EXTI line interrupt pend bit.
Source comment
name    EXTI_ClrITPendBit.
fun     Clear EXTI line interrupt pend bit.
param   exti_line :
            - EXTI_LINE0
            - EXTI_LINE1
            - EXTI_LINE2
            - EXTI_LINE3
            - EXTI_LINE4
            - EXTI_LINE5
            - EXTI_LINE6
            - EXTI_LINE7
            - EXTI_LINE8
            - EXTI_LINE9
            - EXTI_LINE10
return  none

5.5.3 Demo descriptions

This section describes the single EXTI example: KeyInterrupt uses an external interrupt on a key pin to blink an LED.

5.5.3.1 KeyInterrupt Key external interrupt

Example directory: projects/n32g033_EVAL/examples/EXTI/KeyInterrupt/

Enable the GPIO clock and configure the key pin as a pull-up input→Map the key pin onto the matching EXTI line→Set the EXTI line as a falling-edge interrupt and enable it→Pressing the key drives a falling edge on the pin→The interrupt service toggles the LED

Item Source analysis
Function Uses an external interrupt to blink an LED: pressing and releasing KEY2 makes the level on PA4 trigger the interrupt, and the handler toggles the LED on PA7.
Source files src/main.c holds main, KeyInputExtiInit, and the LED helpers LedInit, LedOn, LedOff, and LedBlink;
EXTI0_6_IRQHandler in src/n32g033_it.c handles the interrupt;
inc/main.h and inc/n32g033_it.h give the declarations and pin macros;
readme.txt gives the test steps;
the project files are in MDK-ARM/ and EWARM/.
Key configuration PA4 is a pull-up input that acts as the external interrupt entry, and PA7 is a push-pull output driving the LED;
the EXTI line is a falling-edge interrupt in interrupt mode;
the interrupt channel is EXTI0_6_IRQn at priority NVIC_PRIORITY_1.
Program and data path main -> LedInit configures PA6 and PA7 -> KeyInputExtiInit configures the GPIO and EXTI of PA4 and enables the interrupt -> LedOn lights LED1 -> the main loop is empty -> pressing and releasing KEY2 makes a falling edge on PA4 -> EXTI0_6_IRQHandler toggles PA7 and clears the pending bit.
Main APIs EXTI_InitPeripheral, GPIO_ConfigEXTILine, EXTI_GetStatusFlag, EXTI_ClrITPendBit, NVIC_Init
Verification The hardware is the N32G033K8Q7-1_STB V1.0 evaluation board, with UART TX on PA9 and RX on PA10 at 115200 baud;
after downloading, resetting, and running, pressing and releasing KEY2 toggles the LED on PA7 once.
Use note The system clock is 64 MHz;
the pin macros are defined centrally in inc/main.h, so change the port source and pin source together when you move a pin.
Core-code walkthrough and porting

The example configures a key pin as an external interrupt entry and toggles an LED in the service routine when the interrupt arrives.

Data path: LedInit configures the LED pins → KeyInputExtiInit enables the GPIO clock and maps PA4 onto the EXTI line → EXTI_InitPeripheral sets a falling-edge interrupt → pressing and releasing KEY2 makes a falling edge → EXTI0_6_IRQHandler toggles PA7 and clears the pending bit

1. The main flow only initializes and lights up. main initializes the two LEDs and the key external interrupt, lights LED1, and then spins in an empty loop, leaving all further action to the interrupt.

src/main.csrc/main.c · main
int main(void)
{
    /*SystemInit() function has been called by startup file startup_n32g033.s*/

    /*Initialize Led1 and Led2 as output pushpull mode*/
    LedInit(LED1_PORT, LED1_PIN);
    LedInit(LED2_PORT, LED2_PIN);

    /*Initialize key as external line interrupt*/
    KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN);

    /*Turn on Led1*/
    LedOn(LED1_PORT, LED1_PIN);

    while (1)
    {
    }
}

The ports and pins of the LEDs and the key are defined as macros in inc/main.h, so a port change needs only a macro edit, not a change to the main flow.

2. A key pin needs both GPIO and EXTI configuration. KeyInputExtiInit enables the GPIO clock, configures the pin as a pull-up input, maps it onto the EXTI line with GPIO_ConfigEXTILine, and then has EXTI_InitPeripheral set the trigger edge.

src/main.csrc/main.c · KeyInputExtiInit
    /* Enable the GPIO Clock */
    RCC_EnableAPBPeriphClk(RCC_APB_PERIPH_GPIO,ENABLE);

    /*Configure the GPIO pin as input floating*/
    if (Pin <= GPIO_PIN_ALL)
    {
        GPIO_InitStruct(&GPIO_InitStructure);
        GPIO_InitStructure.Pin          = Pin;
        GPIO_InitStructure.GPIO_Pull    = GPIO_PULL_UP;
        GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
    }

    /*Configure key EXTI Line to key input Pin*/
    GPIO_ConfigEXTILine(KEY_INPUT_PORT_SOURCE, KEY_INPUT_PIN_SOURCE);

    /*Configure key EXTI line*/
    EXTI_InitStructure.EXTI_Line    = KEY_INPUT_EXTI_LINE;
    EXTI_InitStructure.EXTI_Mode    = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_InitPeripheral(&EXTI_InitStructure);

    /*Set key input interrupt priority*/
    NVIC_InitStructure.NVIC_IRQChannel                   = KEY_INPUT_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPriority           = NVIC_PRIORITY_1;
    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

The example maps PA4 onto the EXTI line but uses the line macro EXTI_LINE1, so the two do not fully correspond; when porting, check the line number, port source, and pin source against the actual pin.

3. The handler tests the flag, toggles the LED, and clears the pending bit. EXTI0_6_IRQHandler checks the status flag of the EXTI line, toggles LED2, and then clears the interrupt pending bit so the interrupt does not re-enter.

src/n32g033_it.csrc/n32g033_it.c · EXTI0_6_IRQHandler
void EXTI0_6_IRQHandler(void)
{
    if (RESET != EXTI_GetStatusFlag(KEY_INPUT_EXTI_LINE))
    {
        LedBlink(LED2_PORT, LED2_PIN);
        EXTI_ClrITPendBit(KEY_INPUT_EXTI_LINE);
    }
}

The handler only toggles the LED once; if you add more work inside the interrupt, keep the execution time as short as you can.

Corresponding source files: src/main.c, src/n32g033_it.c, firmware/n32g033_std_periph_driver/inc/n32g033_exti.h

5.5.4 Notes and troubleshooting

Scenario Check & action Source
Trigger edge selection The EXTI chapter of the user manual states that each EXTI line can independently select rising, falling, or both edges;
confirm the trigger edge matches the actual level change on the pin.
User manual
EXTI line and pin mapping The EXTI chapter of the user manual states that an external interrupt line is associated with a GPIO pin through the alternate function;
change the port source and pin source together when you move a pin.
User manual
Software interrupt The EXTI chapter of the user manual states that a software interrupt can trigger one interrupt;
use it during debugging to check that the interrupt service routine is entered.
User manual
Interrupt and event modes The EXTI chapter of the user manual states that an EXTI line can work in interrupt mode or event mode;
choose the mode according to the wake-up need before entering low power.
User manual

Errata sheet V1.0.0 (2025.9.25) covers revision A silicon and lists no EXTI entries.

Nations Technologies DevKit Docs

Datasheets, SDK, driver APIs and demo guides for Nations Technologies MCU development kits, organized by chip series.

© 2026 Nations Technologies Inc. All rights reserved.粤ICP备11069485号This site uses cookie-free anonymous analytics.