PSoC 6 MCU UART printf Code Example

Document Number: 002-23001 Rev.**

Brand Note: This document was originally published by Cypress and is now part of the Infineon Technologies portfolio.

Objective

This example demonstrates how to use the printf function with a Serial Communication Block (SCB) based UART in PSoC® 6 MCU.

Overview

This example is designed to redirect the printf function to use the UART API. The project is designed to print the number of times the kit button SW2 is pressed, on the terminal.

Requirements

  • Tool: PSoC Creator™ 4.2; Peripheral Driver Library (PDL) 3.0.1
  • Programming Language: C (Arm® GCC 5.4.1 and Arm MDK 5.22)
  • Associated Parts: All PSoC 6 MCU parts
  • Related Hardware: CY8CKIT-062-BLE PSoC 6 BLE Pioneer Kit

Hardware Setup

This example uses the kit's default configuration. Refer to the kit guide to ensure correct configuration. If settings differ from defaults, consult the 'Selection Switches' table in the kit guide for reset procedures. Table 2 lists the PSoC Creator pin connection settings required on the CY8CKIT-062-BLE Kit.

Software Setup

Set up a terminal emulator such as Tera Term or PuTTY on your personal computer with the baud rate and other settings shown in Figure 2.

Operation

  1. Plug the CY8CKIT-062-BLE kit board into your computer's USB port.
  2. Build the UART_printf project and program it into the PSoC 6 MCU device using Debug > Program. Refer to PSoC Creator Help for device programming details. Flash for both CPUs is programmed in a single operation.
  3. Open a serial port communication program (e.g., Tera Term) and select the corresponding COM port. Configure the terminal with a baud rate of 115200, 8 data bits, 1 stop bit, and no parity or flow control.
  4. Press the SW2 switch on the kit. The terminal will display the number of times the SW2 switch has been pressed, as shown in Figure 1.

Terminal Prints (Figure 1)

Figure 1 displays a sample terminal output showing the count of button presses. The output format is "Number of times switch SW2 has been pressed = [count]". The count increments with each press and resets when it reaches 65535.

Design and Implementation

The design utilizes a UART (Uart_Printf) Component, a Global Signal Reference (GlobalSignal) Component, a System Interrupt Component (SysInt_Sw), and a GPIO (pin_switch) Component. The UART is configured in TX mode to transmit data at a baud rate of 115200. The GlobalSignal component connects the GPIO (pin_switch) interrupt signal to SysInt_Sw. SysInt_Sw increments a counter when the pin_switch (SW2 on the kit) is pressed. The total count is printed to the terminal using the printf function.

Figure 2: UART printf Example Schematic Description: The schematic illustrates the interconnections. A Global Signal Reference component generates an interrupt signal corresponding to a switch press, enabling Deep Sleep wake-up. This signal is connected to a System Interrupt component (SysInt_SW), which processes the interrupt. A GPIO component (Pin_Switch) is connected to the SW2 button. The UART (Uart_Printf) component handles serial communication. The terminal configuration is shown with Baud rate: 115200 bps, Data bits: 8, Parity: None, Stop bits: 1, Flow control: None.

Components and Settings

Table 1 lists the PSoC Creator Components used in this example, their purpose, and hardware resources. Non-default settings are detailed.

Table 1. PSoC Creator Components

ComponentInstance NamePurposeNon-default Parameter Settings
UART (SCB_UART_PDL)Uart_PrintfTo handle UART serial communicationSee Figure 3.
Global Signal Reference (GSRef)GlobalSignalTo generate InterruptTab Basic - Global Signal Name: Port Interrupt 0 (PICU[0]).
System Interrupt (SysInt)SysInt_SWTo process InterruptTab Basic - Check Box: Deep Sleep Capable.
General Purpose Input / Output (GPIO)Pin_SwitchTo Connect to switchSee Figure 4.

Figure 3. UART Parameter Settings Description:

The UART component is configured with the following key parameters:

  • Com Mode: Standard
  • TX/RX Mode: TX only
  • Baud Rate (bps): 115200
  • Oversample: 12
  • Bit Order: LSB First
  • Data Width: 8 bits
  • Parity: None
  • Stop Bits: 1

Pin Configuration (Figure 4)

Figure 4: Pin_Switch GPIO Parameter Settings Description: The Pin_Switch GPIO component is configured as a digital input. Key settings include: Drive mode: Resistive Pull Up, Initial drive state: High (1), Digital input enabled, External terminal enabled, and Interrupt set to Falling edge. The component is assigned to the Pin_Switch_0 pin.

Table 2. Pin Names and Location

Pin NameLocation
Uart_Printf:txP5[1]
Pin_SwitchP0[4]

Reusing This Example

This example is designed for the CY8CKIT-062-BLE pioneer kit. To port the design to a different PSoC 6 MCU device or kit, change the target device using the Device Selector and update the pin assignments in the Design Wide Resources Pins settings as needed. For single-core PSoC 6 MCU devices, port the code from main_cm4.c to main.c. If a resource used by this code example (e.g., an IP block) is not supported on another device, the example may not work, and build errors may occur. Consult the device datasheet for information on supported devices.

Related Documents

Application Notes

  • AN210781: Getting Started with PSoC 6 MCU with Bluetooth Low Energy (BLE) Connectivity - Describes PSoC 63 with BLE Connectivity and how to build your first PSoC Creator project.

PSoC Creator Component Datasheets

  • Global Signal Reference: Connections to device global signals
  • System Interrupt: Interrupt vectoring and control
  • General Purpose Input / Output: Supports Analog, Digital I/O and Bidirectional signal types
  • UART: Supports UART communication

Device Documentation

  • PSoC 6 MCU: PSoC 63 with BLE Datasheet
  • PSoC 6 MCU: PSoC 63 with BLE Architecture Technical Reference Manual

Development Kit (DVK) Documentation

  • CY8CKIT-062-BLE PSoC 6 BLE Pioneer Kit

Document History

Document Title: CE223001 – PSoC 6 MCU UART printf

Document Number: 002-23001

RevisionECNOrig. of ChangeSubmission DateDescription of Change
**6104587VJYA03/23/2018New Code Example

Worldwide Sales and Design Support

Infineon maintains a worldwide network of offices, solution centers, manufacturer's representatives, and distributors. To find the office closest to you, visit Cypress Locations.

PSoC® Solutions

PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP | PSoC 6 MCU

Cypress Developer Community

Forums | WICED IOT Forums | Projects | Videos | Blogs | Training | Components

Technical Support

cypress.com/support

Products

All other trademarks or registered trademarks referenced herein are the property of their respective owners.

Infineon Semiconductor
198 Champion Court
San Jose, CA 95134-1709

Copyright © Cypress Semiconductor Corporation, 2018. This document is the property of Cypress Semiconductor Corporation and its subsidiaries. Cypress reserves all rights under intellectual property laws. Use of the Software is governed by license agreements. Cypress makes no warranties regarding this document or any software/hardware. Cypress products are not intended for critical components in systems where failure could cause personal injury, death, or property damage (Unintended Uses). Users must indemnify Cypress against claims arising from Unintended Uses.

Trademarks: Cypress, the Cypress logo, Spansion, the Spansion logo, WICED, PSoC, CapSense, EZ-USB, F-RAM, and Traveo are trademarks or registered trademarks of Cypress. Visit cypress.com for a complete list.

PDF preview unavailable. Download the PDF instead.

PSoC 6 MCU UART printf Adobe PDF Library 15.0 Adobe InDesign 15.0 (Macintosh)

Related Documents

PreviewPSoC 6 MCU 双CPU 系统设计指南
本应用笔记详细介绍了 Infineon (原 Cypress) PSoC 6 MCU 系列的强大双CPU架构。该文档旨在为嵌入式系统开发者提供关于如何利用 PSoC 6 MCU 的 Arm® Cortex®-M4 和 Cortex®-M0+ 双核心优势的全面指南,涵盖开发工具、IPC、功耗管理和调试等关键方面。
PreviewInfineon SCB_UART_PDL Component Datasheet for PSoC Creator
Detailed datasheet for the Infineon SCB_UART_PDL Component, a UART module for PSoC Creator. Covers features, configuration, API, I/O, interrupts, DMA, and low-power modes for asynchronous serial communication (RS232, RS485, SmartCard, IrDA).
PreviewPSoC 6 MCU: CY8C63x6, CY8C63x7 Registers Technical Reference Manual (TRM)
This technical reference manual details the registers for Infineon's PSoC 6 MCU, covering CY8C63x6 and CY8C63x7 models with Bluetooth LE. It provides essential information on register mapping, peripheral groups, and system specifications for embedded development.
PreviewInfineon CY8CKIT-062S2-AI PSoC™ 6 AI Evaluation Kit Guide
Discover the Infineon CY8CKIT-062S2-AI PSoC™ 6 AI Evaluation Kit. This guide provides essential information for developing machine learning and IoT applications, detailing hardware features, sensors, and development tools like ModusToolbox™ and Imagimob Studio.
PreviewCY8CKIT-062-WiFi-BT PSoC 6 Wi-Fi Bluetooth Pioneer Kit Guide
Explore the CY8CKIT-062-WiFi-BT PSoC 6 Wi-Fi Bluetooth Pioneer Kit. This guide details its features, including the PSoC 6 MCU, Wi-Fi/Bluetooth connectivity, Arduino shield compatibility, and development tools, for IoT and embedded applications.
PreviewInfineon PSoC™ 4100S Max Pioneer Kit Quick Start Guide
A quick start guide for the Infineon PSoC™ 4100S Max Pioneer Kit (CY8CKIT-041S-MAX), detailing setup, basic operation, and board components.
PreviewInfineon PSoC™ 6 Wi-Fi Bluetooth® Pioneer Kit Guide
Explore the Infineon PSoC™ 6 Wi-Fi Bluetooth® Pioneer Kit (CY8CKIT-062-WIFI-BT) with this comprehensive guide. Learn about its features, hardware, operation, and development capabilities for IoT and embedded systems.
PreviewIAR Embedded Workbench for ModusToolbox™ User Guide - Infineon
Comprehensive user guide for Infineon's ModusToolbox™ software, detailing the integration and usage of IAR Embedded Workbench for embedded system development, including installation, configuration, building, and debugging.