IR GDMA Transmit
This sample uses the IR peripheral to send data by utilizing GDMA, achieving the data transmission function.
The GDMA will transfer predefined IR data from memory to the IR TX FIFO, and upon completion, it will trigger a GDMA interrupt.
A logic analyzer can be used to observe whether the IR transmitted data meets expectations.
Requirements
For requirements, please refer to the Requirements.
Wiring
Connect the IR transmit pin P2_5 to the logic analyzer.
Configurations
-
The following macro can be configured to modify the pin definitions.
#define IR_TX_PIN P2_5
-
The following macros can be configured to modify the GDMA channel settings.
#define IO_TEST_GDMA_CHANNEL_MUM 1 /*< Set this macro to select the GDMA Channel num. */ // Set the following macros to modify the GDMA Channel configurations. #if (IO_TEST_GDMA_CHANNEL_MUM == 0) #define IO_TEST_GDMA_Channel GDMA_Channel0 #define IO_TEST_GDMA_Channel_IRQn GDMA0_Channel0_IRQn #define IO_TEST_GDMA_Channel_Handler GDMA0_Channel0_Handler #elif IO_TEST_GDMA_CHANNEL_MUM == 1 #define IO_TEST_GDMA_Channel GDMA_Channel1 #define IO_TEST_GDMA_Channel_IRQn GDMA0_Channel1_IRQn #define IO_TEST_GDMA_Channel_Handler GDMA0_Channel1_Handler #elif IO_TEST_GDMA_CHANNEL_MUM == 2 #define IO_TEST_GDMA_Channel GDMA_Channel2 #define IO_TEST_GDMA_Channel_IRQn GDMA0_Channel2_IRQn #define IO_TEST_GDMA_Channel_Handler GDMA0_Channel2_Handler #elif IO_TEST_GDMA_CHANNEL_MUM == 3 #define IO_TEST_GDMA_Channel GDMA_Channel3 #define IO_TEST_GDMA_Channel_IRQn GDMA0_Channel3_IRQn #define IO_TEST_GDMA_Channel_Handler GDMA0_Channel3_Handler #endif
-
The following macros can be configured to modify the GDMA data transfer length.
#define IO_TEST_GDMA_TRANSFER_SIZE IR_DATA_SIZE_MAX /*< Set this macro to modify the transfer size. */ #define IR_DATA_SIZE_MAX 68
Building and Downloading
For building and downloading, please refer to the Building and Downloading.
Experimental Verification
Observe the IR transmit waveform with a logic analyzer.

IR Transmit Waveform
Code Overview
This section introduces the code and process description for initialization and corresponding function implementation in the sample.
Source Code Directory
The directory for project file and source code are as follows:
Project directory:
sdk\samples\peripheral\ir\tx+gdma\proj
Source code directory:
sdk\samples\peripheral\ir\tx+gdma\src
Initialization
The initialization flow for peripherals can refer to Initialization Flow in General Introduction.
-
Call
Pad_Config()
andPinmux_Config()
to configure the PAD and PINMUX of the corresponding pins.void board_ir_init(void) { Pad_Config(IR_TX_PIN, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_LOW); Pinmux_Config(IR_TX_PIN, IRDA_TX); }
Call
RCC_PeriphClockCmd()
to enable the IR clock.-
Initialize the IR peripheral:
Define the
IR_InitTypeDef
typeIR_InitStruct
, and callIR_StructInit()
to pre-fillIR_InitStruct
with default values.Modify the
IR_InitStruct
parameters as needed. The IR initialization parameter configuration is shown in the table below.Call
IR_Init()
to initialize the IR peripheral.
IR Hardware Parameters |
Setting in the |
IR |
---|---|---|
Sample Clock |
38000 |
|
IR Duty Cycle |
3 |
|
IR Mode |
||
IR Tx GDMA Enable |
||
IR Tx Waterlevel |
15 |
Call
RCC_PeriphClockCmd()
to enable the IR clock.-
Initialize the GDMA peripheral:
Define a
GDMA_InitTypeDef
typeGDMA_InitStruct
, and callGDMA_StructInit()
to pre-fillGDMA_InitStruct
with default values.Modify the
GDMA_InitStruct
parameters as needed. The initialization parameters for the GDMA channel are configured as shown in the table below. CallGDMA_Init()
to initialize the GDMA peripheral.Configure the GDMA total transfer complete interrupt
GDMA_INT_Transfer
and NVIC. For NVIC configurations, refer to Interrupt Configuration.
GDMA Hardware Parameters |
Setting in the |
GDMA Channel |
---|---|---|
Channel Num |
1 |
|
Transfer Direction |
||
Buffer Size |
|
|
Source Address Increment or Decrement |
||
Destination Address Increment or Decrement |
||
Source Data Size |
||
Destination Data Size |
||
Source Burst Transaction Length |
||
Destination Burst Transaction Length |
||
Source Address |
|
|
Destination Address |
|
|
Destination Handshake |
Functional Implementation
Define IR send data array: carrier data is represented by the number of carriers or 0x80000000, no carrier data is represented by the number of carriers or 0x00000000.
-
Call
GDMA_Cmd()
to enable the corresponding GDMA channel transmission. CallIR_Cmd()
to enable the IR peripheral transmission function. GDMA transfers data fromGDMA_Send_Buf
to(&IR->IR_TX_FIFO)
.IR_Send_Data.CarrierFreq = 38000; IR_Send_Data.DataLen = IO_TEST_GDMA_TRANSFER_SIZE; IR_Send_Data.DataBuf[0] = 0x80000000 | 0x200; IR_Send_Data.DataBuf[1] = 0x00000000 | 0x100; ... IR_Send_Data.DataBuf[IR_Send_Data.DataLen - 1] = 0x80000000 | 0x800; /* Test data buffer */ for (uint32_t i = 0; i < IO_TEST_GDMA_TRANSFER_SIZE; i++) { GDMA_Send_Buf[i] = IR_Send_Data.DataBuf[i]; } ... IR_Cmd(IR_MODE_TX, ENABLE);
-
When the GDMA completes data transfer, trigger the
GDMA_INT_Transfer
interrupt. Within the interrupt function, print the relevant information, disable the GDMA transfer, and clear the interrupt flag.void IO_TEST_GDMA_Channel_Handler(void) { GDMA_INTConfig(IO_TEST_GDMA_CHANNEL_MUM, GDMA_INT_Transfer, DISABLE); GDMA_Cmd(IO_TEST_GDMA_CHANNEL_MUM, DISABLE); DBG_DIRECT("IO_TEST_GDMA_Channel_Handler\r\n"); GDMA_ClearINTPendingBit(IO_TEST_GDMA_CHANNEL_MUM, GDMA_INT_Transfer); }
See Also
Please refer to the relevant API Reference: