This code example shows how to transfer data from source memory to destination memory using 1D transfer of the Direct Memory Access (DMA) function to implement.
The device used in this code example (CE) is:
The board used for testing is:
- PSoC™ 4 HVMS Lite Kit (KIT_PSoC4-HVMS-128K_LITE)
- PSoC™ 4 HVMS Lite Kit (KIT_PSoC4-HVMS-64K_LITE)
This example configures function to tarnsfer data from source memory to destination memory using 1D transfer function of the Direct Memory Access (DMA) function. Transfer result shows window for terminal software.
The DMA controller provides DataWire (DW) and direct memory access (DMA) functionality. The DMA controller has the following features:
- Supports up to four counter groups (device specific)
- Supports eight DMA channels
- Four levels of priority for each channel
- Byte (8 bits), half-word (16 bits), and word (32 bits) transfers
- Three modes of operation supported for each channel
- Configurable interrupt generation
- Output trigger on completion of transfer
- Transfer sizes up to 65,536 data elements
The DMA controller supports three operation modes. These operational modes are different in how the DMA controller operates on a single trigger signal. These operating modes allow the user to implement different operation scenarios for the DMA. The operation modes are
- Mode 0: Single data element per trigger
- Mode 1: All data elements per trigger
- Mode 2: All data elements per trigger and automatically trigger chained descriptor
The data transfer specifics, such as source and destination address locations and the size of the transfer, are specified by a descriptor structure. Each channel has an independent descriptor structure. The DMA controller provides active/sleep functionality and is not available in the DeepSleep power mode.
More details can be found in:
- PSoC™ 4 HVMS Series
This Code Example has been developed for:
Figure 1. KIT_PSoC4-HVMS-128K_LITE (Top View)
The firmware is implemented in main.c and performs the following functions:
- Located transfer data (Source/Destination) in SRAM
- Initialize and enable GPIO interrupt
- Enable DMA Controller (DMAC) and initialize DMAC channel and descriptor configurations
- Enable using DMAC channel
- Set Trigger to initialize transfer
- Confirm results on the display of terminal software
ModusToolbox™ Device configurator
This code example project can be created or imported using ModusToolbox™ IDE. To configure the project in the Quick Panel, click on Device Configurator
Figure 2. Select Device Configurator
Figure 3. Select DMAC Channel 0
Figure 4. Parameter Settings for DMAC Channel 0
Figure 6. System Clock Settings
Figure 7. Peripheral Clock Settings
The basic idea is to display the results of a DMA transfer from source memory to destination memory in a Terminal window and visually compare the data on the source and destination sides.
- Cy_GPIO_Pin_Init() reflects the DMA configuration to the device.
- Using DMA Controller hardware and channel are initialized by Cy_DMAC_Channel_Init().
- Using DMA Controller descriptor is initialized by Cy_DMAC_Descriptor_Init().
- The source address is configured by Cy_DMAC_Descriptor_SetSrcAddress().
- The destination address is configured by Cy_DMAC_Descriptor_SetDstAddress().
- Using DMA Controller channel is enabled by Cy_DMAC_Channel_Enable().
- Using DMA Controller is enabled by Cy_DMAC_Enable().
- Transfer trigger is configured by Cy_TrigMux_SwTrigger().
- Getting the transfer response code by Cy_DMAC_Descriptor_GetResponse().
- SCB UART Initialization is configured by Cy_SCB_UART_Init().
- SCB UART Enable is configured by Cy_SCB_UART_Enable().
- SCB UART Put String data is configured by Cy_SCB_UART_PutString().
- Using by Cy_SCB_UART_IsTxComplete() execute empty check on the TX FIFO and shifter to see if there is any more data to send.
- SCB UART Put data elements are configured by Cy_SCB_UART_Put().
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
Figure 8. Build Project
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)
- Open the terminal program (example download and install Tera term select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud.
In this example, the DMA 1D transfer was successful.
- After programming, the code example will start automatically and display the transfer result.
Figure 10. Communication Results
- 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:
- AN0034 - Getting started with PSOC™ 4 HV MS MCUs in ModusToolbox™
ModusToolbox™ is available online:
Associated PSoC™ 4 HVMS 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 PSoC™ 4 HVMS Forum: