Skip to content

About

This example demonstrates the UART transmit and receive operation in PSoC 4 using DMA. The application uses a serial terminal to read data and echoes what is received. UART is configured to do both transmit and receive operations.

Topics

Resources

Contributing

Stars

0 stars

Watchers

16 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSOC™ 4: SCB UART transmit and receive with DMA

This code example demonstrates the UART transmit and receive operation in PSOC™ 4 using DMA. The application uses a serial terminal to read data and echoes what is received. The UART is configured to do both transmit and receive operations.

View this README on GitHub.

Provide feedback on this code example.

Requirements

Supported toolchains (make variable 'TOOLCHAIN')

  • GNU Arm® Embedded Compiler v14.2.1 (GCC_ARM) – Default value of TOOLCHAIN
  • Arm® Compiler v6.22 (ARM)
  • IAR C/C++ Compiler v9.50.2 (IAR)

Supported kits (make variable 'TARGET')

Hardware setup

This example uses the board's default configuration. See the kit user guide to ensure that the board is configured correctly.

Note: Some PSOC™ 4 kits ship with KitProg2 installed. ModusToolbox™ requires KitProg3. Before using this code example, make sure that the board is upgraded to KitProg3. The tool and instructions are available in the Firmware Loader GitHub repository. If you do not upgrade, you will see an error like "unable to find CMSIS-DAP device" or "KitProg firmware is out of date".

Software setup

See the ModusToolbox™ tools package installation guide for information about installing and configuring the tools package.

This example requires no additional software or tools.

Using the code example

Create the project

The ModusToolbox™ tools package provides the Project Creator as both a GUI tool and a command line tool.

Use Project Creator GUI
  1. Open the Project Creator GUI tool

    There are several ways to do this, including launching it from the dashboard or from inside the Eclipse IDE. For more details, see the Project Creator user guide (locally available at {ModusToolbox™ install directory}/tools_{version}/project-creator/docs/project-creator.pdf)

  2. On the Choose Board Support Package (BSP) page, select a kit supported by this code example. See Supported kits

    Note: To use this code example for a kit not listed here, you may need to update the source files. If the kit does not have the required resources, the application may not work

  3. On the Select Application page:

    a. Select the Applications(s) Root Path and the Target IDE

    Note: Depending on how you open the Project Creator tool, these fields may be pre-selected for you

    b. Select this code example from the list by enabling its check box

    Note: You can narrow the list of displayed examples by typing in the filter box

    c. (Optional) Change the suggested New Application Name and New BSP Name

    d. Click Create to complete the application creation process

Use Project Creator CLI

The 'project-creator-cli' tool can be used to create applications from a CLI terminal or from within batch files or shell scripts. This tool is available in the {ModusToolbox™ install directory}/tools_{version}/project-creator/ directory.

Use a CLI terminal to invoke the 'project-creator-cli' tool. On Windows, use the command-line 'modus-shell' program provided in the ModusToolbox™ installation instead of a standard Windows command-line application. This shell provides access to all ModusToolbox™ tools. You can access it by typing "modus-shell" in the search box in the Windows menu. In Linux and macOS, you can use any terminal application.

The following example clones the "Psoc4UartTxRxDma" application with the desired name "Psoc4UartTxRxDma" configured for the CY8CKIT-149 BSP into the specified working directory, C:/mtb_projects:

project-creator-cli --board-id CY8CKIT-149 --app-id mtb-example-psoc4-uart-transmit-receive-dma --user-app-name Psoc4UartTxRxDma --target-dir "C:/mtb_projects"

The 'project-creator-cli' tool has the following arguments:

Argument Description Required/optional
--board-id Defined in the field of the BSP manifest Required
--app-id Defined in the field of the CE manifest Required
--target-dir Specify the directory in which the application is to be created if you prefer not to use the default current working directory Optional
--user-app-name Specify the name of the application if you prefer to have a name other than the example's default name Optional

Note: The project-creator-cli tool uses the git clone and make getlibs commands to fetch the repository and import the required libraries. For details, see the "Project creator tools" section of the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).

Open the project

After the project has been created, you can open it in your preferred development environment.

Eclipse IDE

If you opened the Project Creator tool from the included Eclipse IDE, the project will open in Eclipse automatically.

For more details, see the Eclipse IDE for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_ide_user_guide.pdf).

Visual Studio (VS) Code

Launch VS Code manually, and then open the generated {project-name}.code-workspace file located in the project directory.

For more details, see the Visual Studio Code for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_vscode_user_guide.pdf).

Arm® Keil® µVision®

Double-click the generated {project-name}.cprj file to launch the Keil® µVision® IDE.

For more details, see the Arm® Keil® µVision® for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_uvision_user_guide.pdf).

IAR Embedded Workbench

Open IAR Embedded Workbench manually, and create a new project. Then select the generated {project-name}.ipcf file located in the project directory.

For more details, see the IAR Embedded Workbench for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_iar_user_guide.pdf).

Command line

If you prefer to use the CLI, open the appropriate terminal, and navigate to the project directory. On Windows, use the command-line 'modus-shell' program; on Linux and macOS, you can use any terminal application. From there, you can run various make commands.

For more details, see the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).

Operation

  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:

    Using Eclipse IDE
    1. Select the application project in the Project Explorer

    2. In the Quick Panel, scroll down, and click <Application Name> Program (KitProg3_MiniProg4)

    In other IDEs

    Follow the instructions in your preferred IDE

    Using CLI

    From the terminal, execute the make program command to build and program the application using the default toolchain to the default target. The default toolchain is specified in the application's Makefile but you can override this value manually:

    make program TOOLCHAIN=<toolchain>
    

    Example:

    make program TOOLCHAIN=GCC_ARM
    
  4. After programming, the application starts automatically. Confirm that "<CE Title>" is displayed on the UART terminal

  5. Start typing to see the echo on the terminal:

    Figure 1. Sample output

Debugging

You can debug the example to step through the code.

In Eclipse IDE

Use the <Application Name> Debug (KitProg3_MiniProg4) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ user guide.

In other IDEs

Follow the instructions in your preferred IDE.

Design and implementation

An UART block is configured to receive and send data to a terminal emulator. The application uses DMA to handle the data received in the UART Rx FIFO. Two DMA channels are used to handle the data in transmit and receive directions. Two SRAM buffers are alternately used on the receive side to hold the data received from the UART terminal. These buffers are called "ping-pong buffers" and are mainly used to provide the time for pulling the data out of either buffer.

The RxDma resource handles the data transfer in the receiving direction. RxDma has two descriptors in the chain; these two descriptors are configured such that the source alternates between the ping-pong buffers in the receive direction.

The TxDma resource is used to handle data in the transmit direction. TxDma has only one descriptor configured to transfer a single element alternately from the ping-pong buffers. The data received from the serial terminal is echoed back to the serial terminal.

Figure 2. Buffering

Resources and settings

Table 1. Application resources

Resource Alias/object Purpose
SCB (UART) (PDL) CYBSP_UART Serial communication
DMA (PDL) RxDma Data transfer
DMA (PDL) TxDma Data transfer

Related resources

Resources Links
Application notes AN79953 – Getting started with PSOC™ 4
AN0034 - Getting started with PSOC™ 4 HV MS and PSOC™ 4 HV PA MCUs in ModusToolbox™
Code examples Using ModusToolbox™ on GitHub
Device documentation PSOC™ 4 datasheets
PSOC™ 4 technical reference manuals
PSOC™ 4 HV MS 64k datasheets
PSOC™ 4 HV MS 64k reference manuals
PSOC™ 4 HV MS 128k datasheets
PSOC™ 4 HV MS 128k reference manuals
PSOC™ 4 HV PA datasheets
PSOC™ 4 HV PA reference manuals
Development kits Select your kits from the Evaluation board finder.
Libraries on GitHub mtb-pdl-cat2 – PSOC™ 4 Peripheral Driver Library (PDL)
mtb-hal-cat2 – Hardware Abstraction Layer (HAL) library
Tools ModusToolbox™ – ModusToolbox™ software is a collection of easy-to-use libraries and tools enabling rapid development with Infineon MCUs for applications ranging from wireless and cloud-connected systems, edge AI/ML, embedded sense and control, to wired USB connectivity using PSOC™ Industrial/IoT MCUs, AIROC™ Wi-Fi and Bluetooth® connectivity devices, XMC™ Industrial MCUs, and EZ-USB™/EZ-PD™ wired connectivity controllers. ModusToolbox™ incorporates a comprehensive set of BSPs, HAL, libraries, configuration tools, and provides support for industry-standard IDEs to fast-track your embedded application development.

Other resources

Infineon provides a wealth of data at www.infineon.com to help you select the right device, and quickly and effectively integrate it into your design.

Document history

Document title: CE231429 - PSOC™ 4: SCB UART transmit and receive with DMA

Version Description of change
1.0.0 New code example
This version is not backward compatible with ModusToolbox™ v2.1
1.1.0 Added support for new kits
2.0.0 Major update to support ModusToolbox™ v3.0.
This version is not backward compatible with previous versions of ModusToolbox™ software
2.1.0 Added support for KIT_PSOC4-HVMS-128K_LITE and KIT_PSOC4-HVMS-64K_LITE and updated to support ModusToolbox™ v3.2
2.2.0 Added support for CY8CPROTO-041TP and updated to support ModusToolbox™ v3.5
Changed HVMS kit name PSoC4 to PSOC4.
2.3.0 Added support for KIT_PSOC4-HVMS-128K_LITE-02 and KIT_PSOC4-HVMS-64K_LITE-02
2.4.0 Added support for KIT_PSOC4-HVPA-144K_LITE
2.5.0 Added support for KIT_PSOC-HVPA-SPM1_LITE and updated to support ModusToolbox™ v3.7.

All referenced product or service names and trademarks are the property of their respective owners.

The Bluetooth® word mark and logos are registered trademarks owned by Bluetooth SIG, Inc., and any use of such marks by Infineon is under license.

PSOC™, formerly known as PSoC™, is a trademark of Infineon Technologies. Any references to PSoC™ in this document or others shall be deemed to refer to PSOC™.


(c) 2020-2026, Infineon Technologies AG, or an affiliate of Infineon Technologies AG. All rights reserved. This software, associated documentation and materials ("Software") is owned by Infineon Technologies AG or one of its affiliates ("Infineon") and is protected by and subject to worldwide patent protection, worldwide copyright laws, and international treaty provisions. Therefore, you may use this Software only as provided in the license agreement accompanying the software package from which you obtained this Software. If no license agreement applies, then any use, reproduction, modification, translation, or compilation of this Software is prohibited without the express written permission of Infineon.
Disclaimer: UNLESS OTHERWISE EXPRESSLY AGREED WITH INFINEON, THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, ALL WARRANTIES OF NON-INFRINGEMENT OF THIRD-PARTY RIGHTS AND IMPLIED WARRANTIES SUCH AS WARRANTIES OF FITNESS FOR A SPECIFIC USE/PURPOSE OR MERCHANTABILITY. Infineon reserves the right to make changes to the Software without notice. You are responsible for properly designing, programming, and testing the functionality and safety of your intended application of the Software, as well as complying with any legal requirements related to its use. Infineon does not guarantee that the Software will be free from intrusion, data theft or loss, or other breaches (“Security Breaches”), and Infineon shall have no liability arising out of any Security Breaches. Unless otherwise explicitly approved by Infineon, the Software may not be used in any application where a failure of the Product or any consequences of the use thereof can reasonably be expected to result in personal injury.

About

This example demonstrates the UART transmit and receive operation in PSoC 4 using DMA. The application uses a serial terminal to read data and echoes what is received. UART is configured to do both transmit and receive operations.

Topics

Resources

Contributing

Stars

0 stars

Watchers

16 watching

Forks

Releases

Packages

Contributors

Languages