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.
The device used in this code example (CE) is:
The board used for testing is:
- TRAVEO™ T2G Cluster 6M Lite Kit (KIT_T2G_C-2D-6M_LITE)
This code example demonstrates the transmission of data by P-DMA with 2D-Transfer.
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.
Feature | P-DMA | M-DMA |
---|---|---|
Focus | Low latency | High memory bandwidth |
Used for | Transfer between peripheral and memory | Transfer between memories |
Transfer engine | Shared between all channels | Dedicated for each channel |
Transfer size | 8-bit/16-bit/32-bit | |
Channel priority | Four levels, Preemptable | Four levels |
Transfer mode | Single 1D/2D CRC transfer | Single 1D/2D Memory copy Scatter |
Descriptor | Source 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:
- TRAVEO™ T2G CYT4DN
This CE has been developed for:
- TRAVEO™ T2G Cluster 6M Lite Kit (KIT_T2G_C-2D-6M_LITE)
Figure 1. KIT_T2G_C-2D-6M_LITE (Top View)
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.
-
To initialize DMA Descriptor, Cy_DMA_Descriptor_Init() is called with using structure cy_stc_dma_descriptor_config_t and cy_stc_dma_descriptor_t which are auto-coded by Device Configurator as argument.
-
To initialize P-DMA channel, Cy_DMA_Channel_Init() is called with using structure cy_stc_dma_channel_config_t which are auto-coded by Device Configurator as argument.
-
Source and destination addresses are specified by Cy_DMA_Descriptor_SetSrcAddress() and Cy_DMA_Descriptor_SetDstAddress() respectively.
-
To sets a descriptor as current for the specified P-DMA channel, Cy_DMA_Channel_SetDescriptor() is called with using structure cy_stc_dma_descriptor_t which are auto-coded by Device Configurator as argument.
-
To make an interrupt when the data transfer is completed, Cy_DMA_Channel_SetInterruptMask() is called and the interrupt service routine is registered by Cy_SysInt_Init() and enabled by NVIC_EnableIRQ().
-
After that enable P-DMA by Cy_DMA_Channel_Enable() and Cy_DMA_Enable().
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.
- This handler firstly clears the interrupt by calling Cy_DMA_Channel_ClearInterrupt().
- To check the interrupt reason, Cy_DMA_Channel_GetStatus() is called.
- If the reason is CY_DMA_INTR_CAUSE_COMPLETION, display a message to the terminal.
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)
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:
-
Connect the board to your PC using the provided USB cable through the KitProg3 USB connector.
-
Open a terminal program and select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud.
-
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).
-
After programming, the CE starts automatically.
-
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.
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: