Skip to content

Infineon/mtb-t2g-example-pdma-2d-transfer

Repository files navigation

P-DMA 2D Transfer

This code example demonstrates the transmission of data by Peripheral Direct Memory Access (P-DMA) 2D Transfer, shows its operation, initial setting, and interrupt handling.

Device

The device used in this code example (CE) is:

Board

The board used for testing is:

Scope of work

This code example demonstrates the transmission of data by P-DMA with 2D-Transfer.

Introduction

P-DMA

The TRAVEO™ T2G device supports two kinds of DMA controllers: Peripheral DMA (P-DMA) and Memory DMA (M-DMA). The main difference between the M-DMA and P-DMA controllers is that the M-DMA controller has dedicated channel logic (with channel state) for each channel, whereas the P-DMA reuses the channel logic for all channels.

FeatureP-DMAM-DMA
FocusLow latencyHigh memory bandwidth
Used forTransfer between peripheral and memoryTransfer between memories
Transfer engineShared between all channelsDedicated for each channel
Transfer size8-bit/16-bit/32-bit
Channel priorityFour levels, PreemptableFour levels
Transfer modeSingle
1D/2D
CRC transfer
Single
1D/2D
Memory copy
Scatter
DescriptorSource and destination address
Transfer size
Channel action
Data transfer mode
Activation trigger type (4 types)
Output trigger type (4 types)
Interrupt type (4 types)
Descriptor chaining
Access-control attributes
The access attributes of the bus transfer that programmed the channel will be inherited
Privileged/Unprivileged
Secure/Non-secure
Protection contexts

The P-DMA controller is part of the CPUSS and controls data transfer between peripherals and memory. This controller can be configured/programmed to perform multiple independent data transfers. Each data transfer is managed by a channel. The Descriptor type are Single transfer, 1D/2D transfer and CRC transfer.

UART included in Serial Communication Block (SCB)

  • Supports UART protocol
    • Standard UART
    • Multi-processor mode
  • SmartCard (ISO7816) reader
  • IrDA
  • Supports LIN
    • Break detection
    • Baud rate detection
    • Collision detection (ability to detect that a driven bit value is not reflected on the bus, indicating that another component is driving the same bus)
  • Data frame size programmable from 4 to 16 bits
  • Programmable number of STOP bits, which can be set in terms of half bit periods between 1 and 4
  • Parity support (odd and even parity)
  • Median filter on RX input
  • Programmable oversampling
  • Start skipping
  • FIFO mode operation only
  • Local loop-back control

More details can be found in:

Hardware setup

This CE has been developed for:

Figure 1. KIT_T2G_C-2D-6M_LITE (Top View)


Implementation

This design consists of P-DMA, a User Button1. The P-DMA is set to initiate transfers by software triggers. Pressing the user button generates an interrupt. When interrupt occurs, P-DMA transfer is triggered by software. Then, P-DMA transfers data from a source address to a destination address.

The transmitted data are composed of 64 unique values on code flash memory, and transferred to UART TX FIFO using 2D transfer in single descriptor. The terminal software connected to KitProg3 COM port will print out the data transferred. The 2D transfer is configured as figure below:
This 2D transfer is configured as do X-loop four times by one trigger, and Y-loop is configured as perform four times as well. In X-loop, P-DMA fetches one-byte data from source table and expands it to 32bit data then transfers it to TX_FIFO_WR register of SCB.

P-DMA configuration

The P-DMA initialization is done in following steps.

UART control

The UART is initialized by the PDL function Cy_SCB_UART_Init().

  • The pin is specified to use KitProg3 COM port
  • The serial port parameters become to 8N1 and 115200 baud

Then call Cy_SCB_UART_Enable() to enable the UART channel.

To output some guidance of this CE to the terminal, Cy_SCB_UART_PutString() is called respectively.

GPIO port pin initialization

Initialization of the GPIO port pin is done in the Cy_GPIO_Pin_Init() function.

  • Initialize the pin specified by User Button1 as input
  • For the port of User Button1, configuration of the GPIO interrupt is done once in the Cy_SysInt_Init() function.

P-DMA Transfer

  • When pressing the user button is detected, the handle_GPIO_Interrupt_SW1() is called and set the g_isInterrupt_SW1.

  • Next, input a software trigger to P-DMA by calling Cy_TrigMux_SwTrigger(). P-DMA performs a transfer for each trigger input, as a result 4 bytes from the source table are output to the terminal.

  • handle_PDMA_Interrupt() is called when the transfer of each X-loop completion.

Compiling and programming

Before testing this code example:

  • Power the board through the dedicated power connector
  • Connect the board to the PC through the USB interface
  • Build the project using the dedicated Build button or by right-clicking the project name and selecting "Build Project"
  • To program the board, in the Quick Panel, scroll down, and click [Project Name] Program (KitProg3_MiniProg4)

Run and Test

For this CE, a terminal emulator is required for displaying outputs. Install a terminal emulator if you do not have one. Instructions in this document use Tera Term.

After code compilation, perform the following steps to flashing the device:

  1. Connect the board to your PC using the provided USB cable through the KitProg3 USB connector.

  2. Open a terminal program and select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud.

  3. Program the board using one of the following:

    • Select the CE project in the Project Explorer.
    • In the Quick Panel, scroll down, and click [Project Name] Program (KitProg3_MiniProg4).
  4. After programming, the CE starts automatically.

    • Confirm that the messages are displayed on the UART terminal.

      Figure 3. Terminal output on program startup

      Figure 4. Print out the result after press User Button1

  5. You can debug the example to step through the code. In the IDE, use the [Project Name] Debug (KitProg3_MiniProg4) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ software user guide.

Note: (Only while debugging) On the CM7 CPU, some code in main() may execute before the debugger halts at the beginning of main(). This means that some code executes twice: once before the debugger stops execution, and again after the debugger resets the program counter to the beginning of main(). See KBA231071 to learn about this and for the workaround.

References

Relevant Application notes are:

  • AN235305 - Getting started with TRAVEO™ T2G family MCUs in ModusToolbox™
  • AN220191 - How To Use Direct Memory Access (DMA) Controller In TRAVEO™ T2G FAMILY
  • AN225401 - How to Use Serial Communications Block (SCB) in Traveo II Family
  • AN219842 - How to use interrupt in TRAVEO™ II

ModusToolbox™ is available online:

Associated TRAVEO™ T2G MCUs can be found on:

More code examples can be found on the GIT repository:

For additional trainings, visit our webpage:

For questions and support, use the TRAVEO™ T2G Forum: