5.15 GPIO Guide
This chapter covers the files of the GPIO/AFIO driver in the N32H49x standard peripheral library, its 38 public functions, and the LedBlink and IORemap examples. Read it together with the “AFIO” chapter of the user manual for the electrical characteristics of GPIO ports and alternate functions, the alternate-function mapping, and the JTAG remap.
5.15.1 Related files
| Relative path | Purpose |
|---|---|
firmware/n32h49x_std_periph_driver/inc/n32h49x_gpio.h |
Defines the GPIO port enumeration, the GPIO_InitType structure, the pin/mode/pull/drive-strength/slew/alternate-function selection macros, and the AFIO configuration macros for SPI NSS, XSPI, ETH, and EMC;declares the 38 public functions in sections such as initialization, data access, lock and remap, and AFIO configuration |
firmware/n32h49x_std_periph_driver/src/n32h49x_gpio.c |
Implements those functions: port and pin reset, peripheral initialization, input/output data access, bit set/reset/write/toggle, pin lock, EXTI line selection, pin remap, and a set of AFIO alternate-function, filter, and EMC configurations |
projects/n32h49x_EVAL/examples/GPIO/ |
GPIO example root, containing the LedBlink and IORemap examples |
projects/n32h49x_EVAL/examples/GPIO/LedBlink/ |
Project layout of the LedBlink example: MDK-ARM/, EWARM/, inc/, src/, readme.txt |
projects/n32h49x_EVAL/bsp/ |
Board support files used by the example: log initialization, print UART remapping, and millisecond delay |
5.15.2 API reference
The 38 public functions below follow the declaration order of n32h49x_gpio.h and fall into 6 groups; each entry gives a summary and the original comment directly above the function in n32h49x_gpio.c.
Initialization and reset
GPIO_DeInit, GPIO_DeInitPin, GPIO_AFIOInitDefault, GPIO_InitPeripheral, GPIO_InitStruct
Input data reads
GPIO_ReadInputDataBit, GPIO_ReadInputData
Output data reads
GPIO_ReadOutputDataBit, GPIO_ReadOutputData
Output writes and toggle
GPIO_SetBits, GPIO_ResetBits, GPIO_WriteBits, GPIO_Write, GPIO_TogglePin
Pin lock, EXTI line selection, and remap
GPIO_ConfigPinLock, GPIO_ConfigEXTILine, GPIO_ConfigPinRemap
AFIO multiplexing, filter, and EMC configuration
AFIO_Config_SPI_NSS_Mode, AFIO_ConfigIOFilter, AFIO_Config_FEMC_NADV_Pin, AFIO_Config_EXTI_Filter, AFIO_Config_XSPI_XIP_BigEndian, AFIO_Config_XSPI_HalfDuplexMode, AFIO_Config_XSPI_DualQuadMode, AFIO_Config_ETH_Mode, AFIO_Config_XSPI_NSS_Input, AFIO_Config_XSPI_RXDS_SampleDelay, AFIO_Config_XSPI_BigEndian_Read, AFIO_Config_XSPI_BigEndian_Write, AFIO_Config_XSPI_TimeExtension, AFIO_Config_XSPI_NSS_HighTime, AFIO_ConfigPinAnalogSignalChannel, SDRAM_EnableClockInversion, AFIO_ConfigPinFilter, AFIO_Config_SHRTIM_EXEV_Pin, AFIO_Config_EMC_Funtion, AFIO_Set_EMC_Cnt, AFIO_Get_EMC_Cnt
void GPIO_DeInit(GPIO_Module* GPIOx)Reset the GPIOx peripheral registers to their default reset values.
name GPIO_DeInit.
fun Reset the GPIOx peripheral registers to their default reset values.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
return none
void GPIO_DeInitPin(GPIO_Module* GPIOx, uint32_t Pin)Deinitializes the GPIOx pin to the default reset state.
name GPIO_DeInitPin.
fun Deinitializes the GPIOx pin to the default reset state.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
- GPIO_PIN_ALL
return none
void GPIO_AFIOInitDefault(void)Reset the AFIO peripheral registers to their default reset values.
name GPIO_AFIOInitDefault.
fun Reset the AFIO peripheral registers to their default reset values.
param none
return none
void GPIO_InitPeripheral(GPIO_Module* GPIOx, GPIO_InitType * GPIO_InitStruct)Initialize the GPIOx peripheral with the value of the GPIO_InitStruct structure.
name GPIO_InitPeripheral.
fun Initialize the GPIOx peripheral with the value of the GPIO_InitStruct structure.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param GPIO_InitStructure :
- Pin
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
- GPIO_PIN_ALL
- GPIO_Mode
- GPIO_MODE_INPUT
- GPIO_MODE_OUTPUT_PP
- GPIO_MODE_OUTPUT_OD
- GPIO_MODE_AF_PP
- GPIO_MODE_AF_OD
- GPIO_MODE_ANALOG
- GPIO_Pull
- GPIO_NO_PULL
- GPIO_PULL_UP
- GPIO_PULL_DOWN
- GPIO_Slew_Rate
- GPIO_SLEW_RATE_FAST
- GPIO_SLEW_RATE_SLOW
- GPIO_Current
- GPIO_DC_2mA
- GPIO_DC_8mA
- GPIO_DC_4mA
- GPIO_DC_12mA
- GPIO_Alternate
- This parameter can be GPIO_AFx where x can be (0..31)
return none
note If PC13,PC14,PC15 used as GPIO or Alternate IO, the clock of GPIOF must be enabled:
Set IOPFEN(RCC_AHB1PCLKEN register bit[5]) bit to '1'.
void GPIO_InitStruct(GPIO_InitType* GPIO_InitStruct)Assign default values to each InitStruct member.
name GPIO_InitStruct.
fun Assign default values to each InitStruct member.
param InitStruct :
pointer to GPIO_InitType structure.
return none
uint8_t GPIO_ReadInputDataBit(GPIO_Module* GPIOx, uint16_t Pin)Get the pin status on the specified input pin.
name GPIO_ReadInputDataBit.
fun Get the pin status on the specified input pin.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
return the state on the input pin.
uint16_t GPIO_ReadInputData(GPIO_Module* GPIOx)Get the input data on the designated GPIO port.
name GPIO_ReadInputData.
fun Get the input data on the designated GPIO port.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
return the data value on the GPIO input port.
uint8_t GPIO_ReadOutputDataBit(GPIO_Module* GPIOx, uint16_t Pin)Get the pin status on the specified output pin.
name GPIO_ReadOutputDataBit.
fun Get the pin status on the specified output pin.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
return the state on the output pin.
uint16_t GPIO_ReadOutputData(GPIO_Module* GPIOx)Get the output data on the designated GPIO port.
name GPIO_ReadOutputData.
fun Get the output data on the designated GPIO port.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
return the data value on the GPIO output port.
void GPIO_SetBits(GPIO_Module* GPIOx, uint16_t Pin)Sets the selected data port bits.
name GPIO_SetBits.
fun Sets the selected data port bits.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
return none
void GPIO_ResetBits(GPIO_Module* GPIOx, uint16_t Pin)Reset the selected data port bits.
name GPIO_ResetBits.
fun Reset the selected data port bits.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
return none
void GPIO_WriteBits(GPIO_Module* GPIOx, uint16_t Pin, Bit_OperateType BitCmd)Reset the selected data port bits.
name GPIO_WriteBit.
fun Reset the selected data port bits.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
param BitCmd :
- Bit_RESET
- Bit_SET
return none
void GPIO_Write(GPIO_Module* GPIOx, uint16_t data_value)Write data on the designated GPIO data port.
name GPIO_Write.
fun Write data on the designated GPIO data port.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param data_value :
the value to be written to the port output data register.
- 0~0xFFFF
return none
void GPIO_TogglePin(GPIO_Module *GPIOx, uint16_t Pin)Toggle the specified port pin level.
name GPIO_Pin_Toggle.
fun Toggle the specified port pin level.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
return none
void GPIO_ConfigPinLock(GPIO_Module* GPIOx, uint16_t Pin)GPIO port lock register configuration.
name GPIO_ConfigPinLock.
fun GPIO port lock register configuration.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
return none
void GPIO_ConfigEXTILine(uint8_t LineSource, uint8_t PortSource, uint8_t PinSource)Selects the GPIO pin used as EXTI Line.
name GPIO_ConfigEXTILine.
fun Selects the GPIO pin used as EXTI Line.
param LineSource :
- EXTI_LINE_SOURCE0
- EXTI_LINE_SOURCE1
- EXTI_LINE_SOURCE2
- EXTI_LINE_SOURCE3
- EXTI_LINE_SOURCE4
- EXTI_LINE_SOURCE5
- EXTI_LINE_SOURCE6
- EXTI_LINE_SOURCE7
- EXTI_LINE_SOURCE8
- EXTI_LINE_SOURCE9
- EXTI_LINE_SOURCE10
- EXTI_LINE_SOURCE11
- EXTI_LINE_SOURCE12
- EXTI_LINE_SOURCE13
- EXTI_LINE_SOURCE14
- EXTI_LINE_SOURCE15
param PortSource :
- GPIOA_PORT_SOURCE
- GPIOB_PORT_SOURCE
- GPIOC_PORT_SOURCE
- GPIOD_PORT_SOURCE
- GPIOE_PORT_SOURCE
- GPIOF_PORT_SOURCE
- GPIOG_PORT_SOURCE
- GPIOH_PORT_SOURCE
param PinSource :
- GPIO_PIN_SOURCE0
- GPIO_PIN_SOURCE1
- GPIO_PIN_SOURCE2
- GPIO_PIN_SOURCE3
- GPIO_PIN_SOURCE4
- GPIO_PIN_SOURCE5
- GPIO_PIN_SOURCE6
- GPIO_PIN_SOURCE7
- GPIO_PIN_SOURCE8
- GPIO_PIN_SOURCE9
- GPIO_PIN_SOURCE10
- GPIO_PIN_SOURCE11
- GPIO_PIN_SOURCE12
- GPIO_PIN_SOURCE13
- GPIO_PIN_SOURCE14
- GPIO_PIN_SOURCE15
return none
void GPIO_ConfigPinRemap(uint8_t PortSource, uint8_t PinSource, uint32_t AlternateFunction)Pin remapping configuration.
name GPIO_ConfigPinRemap.
fun Pin remapping configuration.
param PortSource :
- GPIOA_PORT_SOURCE
- GPIOB_PORT_SOURCE
- GPIOC_PORT_SOURCE
- GPIOD_PORT_SOURCE
- GPIOE_PORT_SOURCE
- GPIOF_PORT_SOURCE
- GPIOG_PORT_SOURCE
- GPIOH_PORT_SOURCE
param PinSource :
- GPIO_PIN_SOURCE0
- GPIO_PIN_SOURCE1
- GPIO_PIN_SOURCE2
- GPIO_PIN_SOURCE3
- GPIO_PIN_SOURCE4
- GPIO_PIN_SOURCE5
- GPIO_PIN_SOURCE6
- GPIO_PIN_SOURCE7
- GPIO_PIN_SOURCE8
- GPIO_PIN_SOURCE9
- GPIO_PIN_SOURCE10
- GPIO_PIN_SOURCE11
- GPIO_PIN_SOURCE12
- GPIO_PIN_SOURCE13
- GPIO_PIN_SOURCE14
- GPIO_PIN_SOURCE15
param AlternateFunction :
- This parameter can be GPIO_AFx where x can be (0..31)
- This parameter can also be one of the following parameter(PortSource and PinSource is ignored):
- GPIO_RMP_SWJ_JTAG: Full SWJ Enabled (JTAG-DP + SW-DP)
- GPIO_RMP_SWJ_JTAG_NO_NJTRST: Full SWJ Enabled (JTAG-DP + SW-DP) but without NJTRST
- GPIO_RMP_SWJ_SWD: JTAG-DP Disabled and SW-DP Enabled
- GPIO_RMP_SWJ_DISABLE: Full SWJ Disabled (JTAG-DP + SW-DP)
return none
void AFIO_Config_SPI_NSS_Mode(uint32_t AFIO_SPIx_NSS, uint32_t NSS_Mode)Configure the SPIx NSS mode during idle.
name AFIO_Config_SPI_NSS_Mode.
fun Configure the SPIx NSS mode during idle.
param AFIO_SPIx_NSS :
choose which SPI configuration.
- AFIO_SPI1_NSS
- AFIO_SPI2_NSS
- AFIO_SPI3_NSS
- AFIO_SPI4_NSS
- AFIO_SPI5_NSS
- AFIO_SPI6_NSS
param NSS_Mode :
specifies the SPI_NSS mode to be configured.
- AFIO_SPI_NSS_HIGH_IMPEDANCE
- AFIO_SPI_NSS_HIGH_LEVEL
return none
void AFIO_ConfigIOFilter(uint32_t Filter_Cycle)Configure IO filter cycle which is counted in AHB clock.
name AFIO_ConfigIOFilter.
fun Configure IO filter cycle which is counted in AHB clock.
param Filter_Cycle :
- 1~64
return none
void AFIO_Config_FEMC_NADV_Pin(uint32_t NADV_Pin)Enable or disable the FEMC NADV pin.
name AFIO_Config_FEMC_NADV_Pin.
fun Enable or disable the FEMC NADV pin.
param NADV_Pin :
- AFIO_FEMC_NADV_PIN_USED
- AFIO_FEMC_NADV_PIN_NOT_USED
return none
void AFIO_Config_EXTI_Filter(uint32_t EXTI_Filter)Enable or disable EXTI analog filter.
name AFIO_Config_EXTI_Filter.
fun Enable or disable EXTI analog filter.
param EXTI_Filter :
- AFIO_EXTI_FILTER_ENABLE
- AFIO_EXTI_FILTER_DISABLE
return none
void AFIO_Config_XSPI_XIP_BigEndian(uint32_t Endian)Enable or disable the big endian for XSPI XIP mode.
name AFIO_Config_XSPI_XIP_BigEndian.
fun Enable or disable the big endian for XSPI XIP mode.
param Endian :
- AFIO_XSPI_XIP_LITTLE_ENDIAN
- AFIO_XSPI_XIP_BIG_ENDIAN
return none
void AFIO_Config_XSPI_HalfDuplexMode(uint32_t HalfDuplex)Enable or disable the XSPI Half-Duplex mode.
name AFIO_Config_XSPI_HalfDuplexMode.
fun Enable or disable the XSPI Half-Duplex mode.
param HalfDuplex :
- AFIO_XSPI_HALF_DUPLEX_DISABLE
- AFIO_XSPI_HALF_DUPLEX_ENABLE
return none
void AFIO_Config_XSPI_DualQuadMode(uint32_t DualQuad)Enable or disable the XSPI Dual-Quad mode.
name AFIO_Config_XSPI_DualQuadMode.
fun Enable or disable the XSPI Dual-Quad mode.
param DualQuad :
- AFIO_XSPI_DUAL_QUAD_DISABLE
- AFIO_XSPI_DUAL_QUAD_ENABLE
return none
void AFIO_Config_ETH_Mode(uint32_t ETH_Mode)Config the ETH interface mode
name AFIO_Config_ETH_Mode.
fun Config the ETH interface mode
param ETH_Mode :
- AFIO_ETH_MODE_MII
- AFIO_ETH_MODE_RMII
return none
void AFIO_Config_XSPI_NSS_Input(uint32_t InputEnable, uint32_t InputPin)Enable or disable XSPI NSS input function, and select which NSS pin is used
name AFIO_Config_XSPI_NSS_Input.
fun Enable or disable XSPI NSS input function, and select which NSS pin is used
param InputEnable :
- AFIO_XSPI_NSS_INPUT_DISABLE
- AFIO_XSPI_NSS_INPUT_ENABLE
param InputPin :
- AFIO_XSPI_NSS_INPUT_NSS0
- AFIO_XSPI_NSS_INPUT_NSS1
return none
void AFIO_Config_XSPI_RXDS_SampleDelay(uint32_t Delay)Config the delay time between RXDS sample point and RXDS rising/falling edge.
name AFIO_Config_XSPI_RXDS_SampleDelay.
fun Config the delay time between RXDS sample point and RXDS rising/falling edge.
param Delay :
- AFIO_XSPI_RXDS_DELAY_NONE
- AFIO_XSPI_RXDS_DELAY_1HCLK
- AFIO_XSPI_RXDS_DELAY_2HCLK
return none
void AFIO_Config_XSPI_BigEndian_Read(uint32_t Endian)Enable or disable XSPI Big Endian read in normal mode(not XIP)
name AFIO_Config_XSPI_BigEndian_Read.
fun Enable or disable XSPI Big Endian read in normal mode(not XIP)
param Endian :
- AFIO_XSPI_READ_LITTLE_ENDIAN
- AFIO_XSPI_READ_BIG_ENDIAN
return none
void AFIO_Config_XSPI_BigEndian_Write(uint32_t Endian)Enable or disable XSPI Big Endian write in normal mode(not XIP)
name AFIO_Config_XSPI_BigEndian_Write.
fun Enable or disable XSPI Big Endian write in normal mode(not XIP)
param Endian :
- AFIO_XSPI_WRITE_LITTLE_ENDIAN
- AFIO_XSPI_WRITE_BIG_ENDIAN
return none
void AFIO_Config_XSPI_TimeExtension(uint32_t Extension)Enable or disable XSPI time extension funtion for setup time or hold time.
name AFIO_Config_XSPI_TimeExtension.
fun Enable or disable XSPI time extension funtion for setup time or hold time.
param Extension :
- AFIO_XSPI_NO_TIME_EXTENSION
- AFIO_XSPI_SETUP_TIME_EXTENSION
- AFIO_XSPI_HOLD_TIME_EXTENSION
- AFIO_XSPI_SETUP_HOLD_TIME_EXTENSION
return none
void AFIO_Config_XSPI_NSS_HighTime(uint32_t clk)Config the high-level time of XSPI NSS pin when XSPI_CTRL0.SSTE bit is set.
name AFIO_Config_XSPI_NSS_HighTime.
fun Config the high-level time of XSPI NSS pin when XSPI_CTRL0.SSTE bit is set.
param clk :
- AFIO_XSPI_NSS_HIGH_1CLK
- AFIO_XSPI_NSS_HIGH_2CLK
- AFIO_XSPI_NSS_HIGH_3CLK
- AFIO_XSPI_NSS_HIGH_4CLK
- AFIO_XSPI_NSS_HIGH_5CLK
- AFIO_XSPI_NSS_HIGH_6CLK
- AFIO_XSPI_NSS_HIGH_7CLK
- AFIO_XSPI_NSS_HIGH_8CLK
- AFIO_XSPI_NSS_HIGH_9CLK
- AFIO_XSPI_NSS_HIGH_10CLK
- AFIO_XSPI_NSS_HIGH_11CLK
- AFIO_XSPI_NSS_HIGH_12CLK
- AFIO_XSPI_NSS_HIGH_13CLK
- AFIO_XSPI_NSS_HIGH_14CLK
- AFIO_XSPI_NSS_HIGH_15CLK
- AFIO_XSPI_NSS_HIGH_16CLK
return none
void AFIO_ConfigPinAnalogSignalChannel(GPIO_Module* GPIOx, uint32_t Pin,FunctionalState cmd)Enable or disable the analog signal channel for GPIOx pin.
name AFIO_ConfigPinAnalogSignalChannel.
fun Enable or disable the analog signal channel for GPIOx pin.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
- GPIO_PIN_ALL
param cmd :
- DISABLE
- ENABLE
return none
void SDRAM_EnableClockInversion(FunctionalState cmd)Enable or disable the clock inversion of SDRAM.
name SDRAM_EnableClockInversion.
fun Enable or disable the clock inversion of SDRAM.
param cmd :
- DISABLE
- ENABLE
return none
void AFIO_ConfigPinFilter(GPIO_Module* GPIOx, uint32_t Pin,FunctionalState cmd)Enable or disable the digital filter function for GPIOx pin.
name AFIO_ConfigPinFilter.
fun Enable or disable the digital filter function for GPIOx pin.
param GPIOx :
- GPIOA
- GPIOB
- GPIOC
- GPIOD
- GPIOE
- GPIOF
- GPIOG
- GPIOH
param Pin :
- GPIO_PIN_0
- GPIO_PIN_1
- GPIO_PIN_2
- GPIO_PIN_3
- GPIO_PIN_4
- GPIO_PIN_5
- GPIO_PIN_6
- GPIO_PIN_7
- GPIO_PIN_8
- GPIO_PIN_9
- GPIO_PIN_10
- GPIO_PIN_11
- GPIO_PIN_12
- GPIO_PIN_13
- GPIO_PIN_14
- GPIO_PIN_15
- GPIO_PIN_ALL
param cmd :
- DISABLE
- ENABLE
return none
void AFIO_Config_SHRTIM_EXEV_Pin(uint8_t EXEV_Line, uint8_t PortSource, uint8_t PinSource)This function is declared in the driver header and has no implementation in this SDK.
name AFIO_Config_SHRTIM_EXEV_Pin
fun (declared in the driver header; no implementation in this SDK)
void AFIO_Config_EMC_Funtion(uint32_t EMC_fun, FunctionalState cmd)Enable or disable some EMC function.
name AFIO_Config_EMC_Funtion.
fun Enable or disable some EMC function.
param EMC_fun :
- AFIO_EMC_CLAMP1_RST
- AFIO_EMC_CLAMP2_RST
- AFIO_EMC_CLAMP3_RST
- AFIO_EMC_CLAMP4_RST
- AFIO_EMC_GBN1_RST
- AFIO_EMC_GBN2_RST
- AFIO_EMC_GBN3_RST
- AFIO_EMC_GBN4_RST
- AFIO_EMC_GB1_RST
- AFIO_EMC_GB2_RST
- AFIO_EMC_GB3_RST
- AFIO_EMC_GB4_RST
- AFIO_EMC_CLAMP1_DET
- AFIO_EMC_CLAMP2_DET
- AFIO_EMC_CLAMP3_DET
- AFIO_EMC_CLAMP4_DET
- AFIO_EMC_GBN1_DET
- AFIO_EMC_GBN2_DET
- AFIO_EMC_GBN3_DET
- AFIO_EMC_GBN4_DET
- AFIO_EMC_GB1_DET
- AFIO_EMC_GB2_DET
- AFIO_EMC_GB3_DET
- AFIO_EMC_GB4_DET
param cmd :
- DISABLE
- ENABLE
return none
void AFIO_Set_EMC_Cnt(uint32_t cnt)Set the EMC counter value.
name AFIO_Set_EMC_Cnt.
fun Set the EMC counter value.
param cnt :
- 0~1023
return none
uint32_t AFIO_Get_EMC_Cnt(void)Get the EMC counter value.
name AFIO_Get_EMC_Cnt.
fun Get the EMC counter value.
param none
return Current counter value.
5.15.3 Demo descriptions
This section covers the two GPIO examples: LedBlink demonstrates GPIO push-pull output and releasing PA8 through the SWJ remap, and IORemap cycles a key through the four SWJ states and lets you observe the released debug pins.
5.15.3.1 LedBlink LED blink
Example directory: projects/n32h49x_EVAL/examples/GPIO/LedBlink/
Enable the GPIO clocks of three LEDs and configure PA3, PB3, and PA8 as push-pull outputs→LED1 and LED3 blink alternately four times→Release PA8 from JTAG to a plain IO through the SWJ remap→The three LEDs light up one by one and repeat in the main loop
| Item | Source analysis |
|---|---|
| Function | Demonstrates GPIO output control with three LEDs on PA3, PB3, and PA8; LED1 and LED3 blink first, then the SWJ remap releases PA8 (occupied by JTAG) as a plain IO, and finally the three LEDs light up one by one and repeat. |
| Source files | src/main.c: main plus LED_Init, LED_On, LED_Off, and LED_Blink;inc/main.h: the LED1/LED2/LED3 port, pin, and clock macros and the function declarations;readme.txt: function, environment, and usage;MDK-ARM/ and EWARM/: Keil and IAR projects. |
| Key configuration | LED1 is PA3, LED2 is PB3, and LED3 is PA8, all configured as GPIO_MODE_OUTPUT_PP, GPIO_AF0, GPIO_NO_PULL, and GPIO_DS_8mA;the system clock is HSI+PLL at 240 MHz. |
| Program and data path | main calls LED_Init three times to initialize the LEDs, then blinks LED1 and LED3 alternately eight times with LED_Blink at an interval of systick_delay_ms(500);it then enables the AFIO clock and calls GPIO_ConfigPinRemap(0,0,GPIO_RMP_SWJ_SWD) to release PA8, and finally lights LED1, LED2, and LED3 in turn in the main loop. |
| Main APIs | GPIO_InitPeripheral, GPIO_SetBits, GPIO_ResetBits, GPIO_TogglePin, GPIO_ConfigPinRemap |
| Verification | After reset LED1 and LED3 blink together four times; PA8 is then remapped to GPIO and the three LEDs light up in turn at 500 ms intervals, repeating. |
| Use note | PA8 is used by JTAG by default after reset, so the AFIO clock must be enabled and GPIO_ConfigPinRemap must switch SWJ to SWD before it can be used as a LED;the debugger must then connect through SWD. Toolchains are KEIL MDK-ARM V5.34 and IAR EWARM 8.50.1. |
Core-code walkthrough and porting
The example drives LEDs from three GPIO push-pull outputs and shows how the SWJ remap releases PA8 (occupied by JTAG) as a plain IO.
Data path: LED_Init enables the GPIO clock and configures PA3/PB3/PA8 as push-pull outputs → LED_Blink uses GPIO_TogglePin to blink LED1 and LED3 alternately → GPIO_ConfigPinRemap switches SWJ to SWD to release PA8 → the main loop lights the three LEDs in turn with LED_On and LED_Off
1. A single initializer for the LED pins. The port, pin, and clock are passed in as arguments and the init structure is fixed as push-pull output.
void LED_Init(GPIO_Module* GPIOx,uint16_t Pin, uint32_t clock)
{
GPIO_InitType InitStruct;
/* Enable GPIO clock */
RCC_EnableAHB1PeriphClk(clock,ENABLE);
/* Init GPIO as output push-pull mode */
InitStruct.Pin = Pin;
InitStruct.GPIO_Slew_Rate = GPIO_SLEW_RATE_FAST;
InitStruct.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
InitStruct.GPIO_Alternate = GPIO_AF0;
InitStruct.GPIO_Pull = GPIO_NO_PULL;
InitStruct.GPIO_Current = GPIO_DS_8mA;
GPIO_InitPeripheral(GPIOx, &InitStruct);
}
GPIO_Alternate = GPIO_AF0 means no alternate function is used, and GPIO_Current = GPIO_DS_8mA sets the output drive strength.
2. Set, reset, and toggle wrappers. The three functions map to setting, resetting, and toggling a pin, which keeps the main loop easy to read.
void LED_On(GPIO_Module* GPIOx,uint16_t Pin)
{
GPIO_SetBits(GPIOx,Pin);
}
void LED_Off(GPIO_Module* GPIOx,uint16_t Pin)
{
GPIO_ResetBits(GPIOx,Pin);
}
void LED_Blink(GPIO_Module* GPIOx,uint16_t Pin)
{
GPIO_TogglePin(GPIOx,Pin);
}
3. Release the pin occupied by JTAG through the SWJ remap. PA8 belongs to JTAG by default after reset, so SWJ must be set to SWD before it can be used.
/* LED3 port is default used for JTAG, must remap first */
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPHEN_AFIO,ENABLE);
GPIO_ConfigPinRemap(0,0,GPIO_RMP_SWJ_SWD);
GPIO_RMP_SWJ_SWD corresponds to “JTAG-DP disabled, SW-DP enabled” in SWJ_CFG; PA13/PA14 remain available for debugging and the other JTAG pins are released as plain IO.
4. Light the three LEDs in turn in the main loop. After reset the LEDs blink first and then enter the loop that lights them one by one.
while (1)
{
/* Turn on LED1 and turn off LED3*/
LED_Off(LED3_PORT, LED3_PIN);
LED_On(LED1_PORT, LED1_PIN);
systick_delay_ms(500);
/* Turn on LED2 and turn off LED1*/
LED_Off(LED1_PORT, LED1_PIN);
LED_On(LED2_PORT, LED2_PIN);
systick_delay_ms(500);
/* Turn on LED3 and turn off LED2 */
LED_Off(LED2_PORT, LED2_PIN);
LED_On(LED3_PORT, LED3_PIN);
systick_delay_ms(500);
}
Each step lights one LED and turns the previous one off, with the interval set by systick_delay_ms(500), cycling through the three LEDs.
Corresponding source files: src/main.c, inc/main.h
5.15.3.2 IORemap JTAG port remap
Example directory: projects/n32h49x_EVAL/examples/GPIO/IORemap/
Initialize the print UART and two LEDs, and configure the JTAG pins as outputs and the key as an input→The main loop toggles PA13/PA14/PA15 and PB3/PB4 at a fixed rate→A key press with debouncing switches the SWJ state→The state cycles through JTAG, JTAG without NJTRST, SWD, and Disabled→The UART prints the current state and the LEDs indicate it
| Item | Source analysis |
|---|---|
| Function | Demonstrates SWJ remapping of the JTAG port: after a debounced key press, SWJ_CFG cycles through full JTAG, JTAG without NJTRST, SWD only, and fully disabled; the released debug pins output a square wave, and the UART prints the current state with LED indication. |
| Source files | src/main.c: main, LED_Init/LED_On/LED_Off, Key_Init, JTAG_IO_Init, JTAG_switch, and Delay;inc/main.h: the LED1/LED3 and KEY port/pin/clock macros, the KEY_READ macro, and the function declarations;readme.txt: function, environment, and usage;MDK-ARM/ and EWARM/: Keil and IAR projects. |
| Key configuration | LED1 is PA3 and LED3 is PA8; KEY is PA0, configured as GPIO_MODE_INPUT with GPIO_PULL_DOWN;the JTAG pins PA13/PA14/PA15 and PB3/PB4 are configured as GPIO_MODE_OUTPUT_PP with GPIO_NO_AF and GPIO_DS_2mA;the print UART is USART, TX-PA9 and RX-PA10 at 115200; the system clock is 240 MHz. |
| Program and data path | main calls log_init to print IO remaping demo! and the initial JTAG state, then enables the AFIO clock, initializes the LEDs, and calls JTAG_IO_Init and Key_Init;the loop reads PA0 with KEY_READ() and, once the key is released and the debounce count exceeds KEY_DEBOUCING, increments sts_cnt and calls JTAG_switch, while toggling the debug pins every SystemCoreClock/100. |
| Main APIs | GPIO_InitPeripheral, GPIO_TogglePin, GPIO_SetBits, GPIO_ResetBits, GPIO_ConfigPinRemap |
| Verification | After reset the UART prints the initial state JTAG, and PB4/PA15/PA14/PA13 show no square wave;each key press then switches to JTAG without TRST (releases PB4), SWD (releases PB4/PA15), and Disabled (releases all), with the released pins outputting a square wave;LED1/LED3 light up according to the state. |
| Use note | Switching the SWJ state changes how the debugger connects, so test the fully disabled JTAG/SWD case with a power cycle or reset to recover;JTAG_switch turns the LEDs off before calling GPIO_ConfigPinRemap, and the state wraps through sts_cnt and MAX_JTAG_STS.Toolchains are KEIL MDK-ARM V5.34 and IAR EWARM 8.50.1. |
Core-code walkthrough and porting
The example cycles a key through the four SWJ states and releases the pins occupied by JTAG as toggleable plain outputs.
Data path: JTAG_IO_Init configures PA13/PA14/PA15 and PB3/PB4 as push-pull outputs → the main loop polls the key with KEY_READ() and debounces it → JTAG_switch calls GPIO_ConfigPinRemap to change SWJ_CFG → GPIO_TogglePin drives a square wave on the released debug pins while the UART prints the current state
1. Two arrays register the four SWJ states. The state values and display names correspond one to one, and sts_cnt cycles through them so the switch and the print stay in order.
#define MAX_JTAG_STS (4)
uint32_t jtag_sts[MAX_JTAG_STS]={GPIO_RMP_SWJ_JTAG,GPIO_RMP_SWJ_JTAG_NO_NJTRST,GPIO_RMP_SWJ_SWD,GPIO_RMP_SWJ_DISABLE};
char *sts[] = {"JTAG","JTAG without TRST","SWD","Disabled"};
jtag_sts[] maps in order to full JTAG, JTAG without NJTRST, SWD only, and fully disabled, and sts[] provides the names printed on the UART.
2. JTAG_switch changes the state and lights the indicator LEDs. The function turns both LEDs off first, calls the remap interface to change SWJ, and lights the LEDs according to the state.
LED_Off(LED1_PORT, LED1_PIN);
LED_Off(LED3_PORT, LED3_PIN);
GPIO_ConfigPinRemap(0,0,jtag_sts[sts_cnt]);
printf("JTAG status changed to %s\r\n",sts[sts_cnt]);
if(sts_cnt & 0x1)
{
LED_On(LED1_PORT, LED1_PIN);
}
if(sts_cnt > 1)
{
LED_On(LED3_PORT, LED3_PIN);
}
The conditions sts_cnt & 0x1 and sts_cnt > 1 drive LED1 and LED3 respectively, so the two LEDs indicate which of the four states is active.
3. The main loop debounces the key. While the key is pressed KeyDelay accumulates; the press counts only after it is released with a count above KEY_DEBOUCING, and then sts_cnt is incremented and wrapped with MAX_JTAG_STS.
if( KEY_READ() != 0) /* Key pressed */
{
KeyDelay++;
}
else if(KeyDelay > KEY_DEBOUCING) /* Key released */
{
if(sts_cnt >= (MAX_JTAG_STS-1))
{
sts_cnt = 0;
}
else
{
sts_cnt++;
}
JTAG_switch(sts_cnt); /* Change JTAG status by remapping */
KeyDelay = 0;
}
A state change needs a press that is released after being held long enough, which keeps contact bounce from skipping states.
4. Toggle the released debug pins. At an interval of SystemCoreClock/100, GPIO_TogglePin toggles the former JTAG pins on GPIOA and GPIOB together so the release can be observed on a scope.
/*Toggle JTAG IO port*/
if(IODelay < (SystemCoreClock/100))
{
IODelay++;
}
else
{
IODelay = 0;
GPIO_TogglePin(GPIOA,GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
GPIO_TogglePin(GPIOB,GPIO_PIN_3|GPIO_PIN_4);
}
Pins that are not released are still controlled by the debug port and do not respond to the toggle; only the pins released by the current SWJ state output a square wave.
Corresponding source files: src/main.c, inc/main.h
5.15.4 Notes and troubleshooting
| Scenario | Check & action | Source |
|---|---|---|
| IO register access width | GPIO and AFIO registers must be accessed as 32-bit words, never as half-words or bytes; otherwise unexpected values may be read or the write may have no effect. |
User manual |
| Default state after reset | After reset, most IOs are in analog mode except the JTAG debug pins; before using one as a digital input or output, configure the matching mode through GPIO_InitPeripheral. |
User manual |
| Clock of PC13/PC14/PC15 | To use PC13, PC14, or PC15 as GPIO or alternate IO, the GPIOF clock must be enabled (set the IOPFEN bit, bit[5], of RCC_AHB1PCLKEN to 1); the comment of GPIO_InitPeripheral already points this out. |
User manual |
| Priority of backup-domain pins | PC14 and PC15 are forced to analog mode when LSE is enabled; PC13 is controlled by the backup domain and can only be used as GPIO when LSE is off, VDD is present, and the device is not in STANDBY/STOP0. |
User manual |
| Configuration lock | The port configuration lock register bits of a locked pin can only be cleared by a system reset; once locked, the pin configuration can no longer be changed. |
User manual |
| Alternate output and the peripheral | When a pin is configured as alternate output (GPIO_MODE_AF_PP/GPIO_MODE_AF_OD), the matching peripheral must be enabled and active;the output level is undefined while the peripheral is inactive. |
User manual |
| Debug port remap | Configure SWJ_CFG with GPIO_ConfigPinRemap and GPIO_RMP_SWJ_* (000 full JTAG, 001 no NJTRST, 010 JTAG off with SWD on, 100 all off);this releases PB4/PA15/PA14/PA13 as plain IO, so for example using PA15 as I2C1_SCL requires 010 or 100. |
User manual |
| EXTI input line configuration | A pin used as an EXTI or wakeup source must be configured as an input and mapped to the matching EXTI line through AFIO_EXTI_CFGy;one EXTI line can be mapped to only one GPIO pin at a time. |
User manual |