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
- Plug the CY8CKIT-062-BLE kit board into your computer's USB port.
- 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.
- 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.
- 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
Component | Instance Name | Purpose | Non-default Parameter Settings |
---|---|---|---|
UART (SCB_UART_PDL) | Uart_Printf | To handle UART serial communication | See Figure 3. |
Global Signal Reference (GSRef) | GlobalSignal | To generate Interrupt | Tab Basic - Global Signal Name: Port Interrupt 0 (PICU[0]). |
System Interrupt (SysInt) | SysInt_SW | To process Interrupt | Tab Basic - Check Box: Deep Sleep Capable. |
General Purpose Input / Output (GPIO) | Pin_Switch | To Connect to switch | See 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 Name | Location |
---|---|
Uart_Printf:tx | P5[1] |
Pin_Switch | P0[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
Revision | ECN | Orig. of Change | Submission Date | Description of Change |
---|---|---|---|---|
** | 6104587 | VJYA | 03/23/2018 | New 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
Products
- Arm® Cortex® Microcontrollers: cypress.com/arm
- Automotive: cypress.com/automotive
- Clocks & Buffers: cypress.com/clocks
- Interface: cypress.com/interface
- Internet of Things: cypress.com/iot
- Memory: cypress.com/memory
- Microcontrollers: cypress.com/mcu
- PSoC: cypress.com/psoc
- Power Management ICs: cypress.com/pmic
- Touch Sensing: cypress.com/touch
- USB Controllers: cypress.com/usb
- Wireless Connectivity: cypress.com/wireless
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.