[bsp/IFX]补充缺少的文件 (#8055)

This commit is contained in:
guo 2023-09-19 12:27:58 +08:00 committed by GitHub
parent 746f527fac
commit 8a7831ee4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1012 additions and 0 deletions

View File

@ -78,6 +78,7 @@ if GetDepend(['SOC_CY8C6244LQI_S4D92']):
src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c') src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c')
if GetDepend(['RT_USING_SERIAL']): if GetDepend(['RT_USING_SERIAL']):
src += ['retarget-io/cy_retarget_io.c']
src += ['mtb-hal-cat1/source/cyhal_uart.c'] src += ['mtb-hal-cat1/source/cyhal_uart.c']
src += ['mtb-pdl-cat1/drivers/source/cy_scb_uart.c'] src += ['mtb-pdl-cat1/drivers/source/cy_scb_uart.c']

View File

@ -0,0 +1 @@
docs

View File

@ -0,0 +1,55 @@
CYPRESS END USER LICENSE AGREEMENT
PLEASE READ THIS END USER LICENSE AGREEMENT ("Agreement") CAREFULLY BEFORE DOWNLOADING, INSTALLING, COPYING, OR USING THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION. BY DOWNLOADING, INSTALLING, COPYING OR USING THE SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THIS AGREEMENT. IF YOU DO NOT AGREE TO ALL OF THE TERMS OF THIS AGREEMENT, PROMPTLY RETURN AND DO NOT USE THE SOFTWARE. IF YOU HAVE PURCHASED THIS LICENSE TO THE SOFTWARE, YOUR RIGHT TO RETURN THE SOFTWARE EXPIRES 30 DAYS AFTER YOUR PURCHASE AND APPLIES ONLY TO THE ORIGINAL PURCHASER.
1. Definitions.
"Software" means this software and any accompanying documentation, including any upgrades, updates, bug fixes or modified versions provided to you by Cypress.
"Source Code" means software in human-readable form.
"Binary Code" means the software in binary code form such as object code or an executable.
"Development Tools" means software that is intended to be installed on a personal computer and used to create programming code for Firmware, Drivers, or Host Applications. Examples of Development Tools are Cypress's PSoC Creator software, Cypress's WICED SDKs, and Cypress's ModusToolbox software.
"Firmware" means software that executes on a Cypress hardware product.
"Driver" means software that enables the use of a Cypress hardware product on a particular host operating system such as GNU/Linux, Windows, MacOS, Android, and iOS.
"Host Application" means software that executes on a device other than a Cypress hardware product in order to program, control, or communicate with a Cypress hardware product.
"inf File" means a hardware setup information file (.inf file) created by the Software to allow a Microsoft Windows operating system to install the driver for a Cypress hardware product.
2. License. Subject to the terms and conditions of this Agreement, Cypress Semiconductor Corporation ("Cypress") and its suppliers grant to you a non-exclusive, non-transferable license under their copyright rights:
a. to use the Development Tools in object code form solely for the purpose of creating Firmware, Drivers, Host Applications, and inf Files for Cypress hardware products; and
b. (i) if provided in Source Code form, to copy, modify, and compile the Firmware Source Code to create Firmware for execution on a Cypress hardware product, and (ii) to distribute Firmware in binary code form only, only when installed onto a Cypress hardware product; and
c. (i) if provided in Source Code form, to copy, modify, and compile the Driver Source Code to create one or more Drivers to enable the use of a Cypress hardware product on a particular host operating system, and (ii) to distribute the Driver, in binary code form only, only when installed on a device that includes the Cypress hardware product that the Driver is intended to enable; and
d. (i) if provided in Source Code form, to copy, modify, and compile the Host Application Source Code to create one or more Host Applications to program, control, or communicate with a Cypress hardware product, and (ii) to distribute Host Applications, in binary code form only, only when installed on a device that includes a Cypress hardware product that the Host Application is intended to program, control, or communicate with; and
e. to freely distribute any inf File.
Any distribution of Software permitted under this Agreement must be made pursuant to your standard end user license agreement used for your proprietary (closed source) software products, such end user license agreement to include, at a minimum, provisions limiting your licensors' liability and prohibiting reverse engineering of the Software, consistent with such provisions in this Agreement.
3. Free and Open Source Software. Portions of the Software may be licensed under free and/or open source licenses such as the GNU General Public License or other licenses from third parties ("Third Party Software"). Third Party Software is subject to the applicable license agreement and not this Agreement. If you are entitled to receive the source code from Cypress for any Third Party Software included with the Software, either the source code will be included with the Software or you may obtain the source code at no charge from <http://www.cypress.com/go/opensource>. The applicable license terms will accompany each source code package. To review the license terms applicable to any Third Party Software for which Cypress is not required to provide you with source code, please see the Software's installation directory on your computer.
4. Proprietary Rights; Ownership. The Software, including all intellectual property rights therein, is and will remain the sole and exclusive property of Cypress or its suppliers. Cypress retains ownership of the Source Code and any compiled version thereof. Subject to Cypress' ownership of the underlying Software (including Source Code), you retain ownership of any modifications you make to the Source Code. You agree not to remove any Cypress copyright or other notices from the Source Code and any modifications thereof. You agree to keep the Source Code confidential. Any reproduction, modification, translation, compilation, or representation of the Source Code except as permitted in Section 2 ("License") is prohibited without the express written permission of Cypress. Except as otherwise expressly provided in this Agreement, you may not: (i) modify, adapt, or create derivative works based upon the Software; (ii) copy the Software; (iii) except and only to the extent explicitly permitted by applicable law despite this limitation, decompile, translate, reverse engineer, disassemble or otherwise reduce the Software to human-readable form; or (iv) use the Software or any sample code other than for the Purpose. You hereby covenant that you will not assert any claim that the Software, or derivative works thereof created by or for Cypress, infringe any intellectual property right owned or controlled by you
5. No Support. Cypress may, but is not required to, provide technical support for the Software.
6. Term and Termination. This Agreement is effective until terminated, and either party may terminate this Agreement at any time with or without cause. This Agreement and your license rights under this Agreement will terminate immediately without notice from Cypress if you fail to comply with any provision of this Agreement. Upon termination, you must destroy all copies of Software in your possession or control. The following paragraphs shall survive any termination of this Agreement: "Free and Open Source Software," "Proprietary Rights; Ownership," "Compliance With Law," "Disclaimer," "Limitation of Liability," and "General."
7. Compliance With Law. Each party agrees to comply with all applicable laws, rules and regulations in connection with its activities under this Agreement. Without limiting the foregoing, the Software may be subject to export control laws and regulations of the United States and other countries. You agree to comply strictly with all such laws and regulations and acknowledge that you have the responsibility to obtain licenses to export, re-export, or import the Software.
8. Disclaimer. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THE SOFTWARE, INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes to the Software without notice. Cypress does not assume any liability arising out of the application or use of Software or any product or circuit described in the Software. It is the responsibility of the user of the Software to properly design, program, and test the functionality and safety of any application made of the Software and any resulting product. Cypress does not authorize its Software or products for use in any products where a malfunction or failure of the Software or Cypress product may reasonably be expected to result in significant property damage, injury or death ("High Risk Product"). If you include any Software or Cypress product in a High Risk Product, you assume all risk of such use and agree to indemnify Cypress and its suppliers against all liability. No computing device can be absolutely secure. Therefore, despite security measures implemented in Cypress hardware or software products, Cypress does not assume any liability arising out of any security breach, such as unauthorized access to or use of a Cypress product.
9. Limitation of Liability. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL CYPRESS OR ITS SUPPLIERS, RESELLERS, OR DISTRIBUTORS BE LIABLE FOR ANY LOST REVENUE, PROFIT, OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF CYPRESS OR ITS SUPPLIERS, RESELLERS, OR DISTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT SHALL CYPRESS' OR ITS SUPPLIERS', RESELLERS', OR DISTRIBUTORS' TOTAL LIABILITY TO YOU, WHETHER IN CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE, EXCEED THE GREATER OF US$500 OR THE PRICE PAID BY YOU FOR THE SOFTWARE. THE FOREGOING LIMITATIONS SHALL APPLY EVEN IF THE ABOVE-STATED WARRANTY FAILS OF ITS ESSENTIAL PURPOSE. BECAUSE SOME STATES OR JURISDICTIONS DO NOT ALLOW LIMITATION OR EXCLUSION OF CONSEQUENTIAL OR INCIDENTAL DAMAGES, ALL OR PORTIONS OF THE ABOVE LIMITATION MAY NOT APPLY TO YOU.
10. Restricted Rights. The Software is commercial computer software as that term is described in 48 C.F.R. 252.227-7014(a)(1). If the Software is being acquired by or on behalf of the U.S. Government or by a U.S. Government prime contractor or subcontractor (at any tier), then the Government's rights in Software shall be only those set forth in this Agreement.
11. Personal Information. You agree that information you provide through your registration on Cypress IoT Community Forum or other Cypress websites, including contact information or other personal information, may be collected and used by Cypress consistent with its Data Privacy Policy (www.cypress.com/privacy-policy), as updated or revised from time to time, and may be provided to its third party sales representatives, distributors and other entities conducting sales activities for Cypress for sales-related and other business purposes.
12. General. This Agreement will bind and inure to the benefit of each party's successors and assigns, provided that you may not assign or transfer this Agreement, in whole or in part, without Cypress' written consent. This Agreement shall be governed by and construed in accordance with the laws of the State of California, United States of America, as if performed wholly within the state and without giving effect to the principles of conflict of law. The parties consent to personal and exclusive jurisdiction of and venue in, the state and federal courts within Santa Clara County, California; provided however, that nothing in this Agreement will limit Cypress' right to bring legal action in any venue in order to protect or enforce its intellectual property rights. No failure of either party to exercise or enforce any of its rights under this Agreement will act as a waiver of such rights. If any portion of this Agreement is found to be void or unenforceable, the remaining provisions of this Agreement shall remain in full force and effect. This Agreement is the complete and exclusive agreement between the parties with respect to the subject matter hereof, superseding and replacing any and all prior agreements, communications, and understandings (both written and oral) regarding such subject matter. Any notice to Cypress will be deemed effective when actually received and must be sent to Cypress Semiconductor Corporation, ATTN: Chief Legal Officer, 198 Champion Court, San Jose, CA 95134 USA.

View File

@ -0,0 +1,165 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright
owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities
that control, are controlled by, or are under common control with that entity.
For the purposes of this definition, "control" means (i) the power, direct or
indirect, to cause the direction or management of such entity, whether by
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising
permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including
but not limited to software source code, documentation source, and configuration
files.
"Object" form shall mean any form resulting from mechanical transformation or
translation of a Source form, including but not limited to compiled object code,
generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made
available under the License, as indicated by a copyright notice that is included
in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that
is based on (or derived from) the Work and for which the editorial revisions,
annotations, elaborations, or other modifications represent, as a whole, an
original work of authorship. For the purposes of this License, Derivative Works
shall not include works that remain separable from, or merely link (or bind by
name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version
of the Work and any modifications or additions to that Work or Derivative Works
thereof, that is intentionally submitted to Licensor for inclusion in the Work
by the copyright owner or by an individual or Legal Entity authorized to submit
on behalf of the copyright owner. For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently
incorporated within the Work.
2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the Work and such
Derivative Works in Source or Object form.
3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
such license applies only to those patent claims licensable by such Contributor
that are necessarily infringed by their Contribution(s) alone or by combination
of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or contributory
patent infringement, then any patent licenses granted to You under this License
for that Work shall terminate as of the date such litigation is filed.
4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works thereof
in any medium, with or without modifications, and in Source or Object form,
provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of
this License; and
You must cause any modified files to carry prominent notices stating that You
changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form
of the Work, excluding those notices that do not pertain to any part of the
Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the
attribution notices contained within such NOTICE file, excluding those notices
that do not pertain to any part of the Derivative Works, in at least one of the
following places: within a NOTICE text file distributed as part of the
Derivative Works; within the Source form or documentation, if provided along
with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents of
the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works that
You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as
modifying the License.
You may add Your own copyright statement to Your modifications and may provide
additional or different license terms and conditions for use, reproduction, or
distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.
5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally submitted
for inclusion in the Work by You to the Licensor shall be under the terms and
conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of
any separate license agreement you may have executed with Licensor regarding
such Contributions.
6. Trademarks.
This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.
7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor provides the
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
solely responsible for determining the appropriateness of using or
redistributing the Work and assume any risks associated with Your exercise of
permissions under this License.
8. Limitation of Liability.
In no event and under no legal theory, whether in tort (including negligence),
contract, or otherwise, unless required by applicable law (such as deliberate
and grossly negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License or
out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
any and all other commercial damages or losses), even if such Contributor has
been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose to
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
other liability obligations and/or rights consistent with this License. However,
in accepting such obligations, You may act only on Your own behalf and on Your
sole responsibility, not on behalf of any other Contributor, and only if You
agree to indemnify, defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.

View File

@ -0,0 +1,38 @@
# Retarget IO
### Overview
A utility library to retarget the standard input/output (STDIO) messages to a UART port. With this library, you can directly print messages on a UART terminal using `printf()`. You can specify the TX pin, RX pin, and the baud rate through the `cy_retarget_io_init()` function. The UART HAL object is externally accessible so that you can use it with other UART HAL functions.
**NOTE:** The standard library is not standard in how it treats an I/O stream. Some implement a data buffer by default. The buffer is not flushed until it is full. In that case it may appear that your I/O is not working. You should be aware of how the library buffers data, and you should identify a buffering strategy and buffer size for a specified stream. If you supply a buffer, it must exist until the stream is closed. The following line of code disables the buffer for the standard library that accompanies the GCC compiler:
setvbuf( stdin, NULL, _IONBF, 0 );
**NOTE:** If the application is built using newlib-nano, by default, floating point format strings (%f) are not supported. To enable this support, you must add `-u _printf_float` to the linker command line.
# RTOS Integration
To avoid concurrent access to the UART peripheral in a RTOS environment, the ARM and IAR libraries use mutexes to control access to stdio streams. For Newlib (GCC_ARM), the mutex must be implemented in _write() and can be enabled by adding `DEFINES+=CY_RTOS_AWARE` to the Makefile. For all libraries, the program must start the RTOS kernel before calling any stdio functions.
### Quick Start
1. Add `#include "cy_retarget_io.h"`
2. Call `cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);`
`CYBSP_DEBUG_UART_TX` and `CYBSP_DEBUG_UART_RX` pins are defined in the BSP and `CY_RETARGET_IO_BAUDRATE` is set to 115200. You can use a different baud rate if you prefer.
3. Start printing using `printf()`
### Enabling Conversion of '\\n' into "\r\n"
If you want to use only '\\n' instead of "\r\n" for printing a new line using printf(), define the macro `CY_RETARGET_IO_CONVERT_LF_TO_CRLF` using the *DEFINES* variable in the application Makefile. The library will then append '\\r' before '\\n' character on the output direction (STDOUT). No conversion occurs if "\r\n" is already present.
### More information
* [API Reference Guide](https://infineon.github.io/retarget-io/html/index.html)
* [Cypress Semiconductor, an Infineon Technologies Company](http://www.cypress.com)
* [Infineon GitHub](https://github.com/infineon)
* [ModusToolbox™](https://www.cypress.com/products/modustoolbox-software-environment)
* [PSoC™ 6 Code Examples using ModusToolbox™ IDE](https://github.com/infineon/Code-Examples-for-ModusToolbox-Software)
* [ModusToolbox™ Software](https://github.com/Infineon/modustoolbox-software)
* [PSoC™ 6 Resources - KBA223067](https://community.cypress.com/docs/DOC-14644)
---
© Cypress Semiconductor Corporation (an Infineon company) or an affiliate of Cypress Semiconductor Corporation, 2019-2021.

View File

@ -0,0 +1,49 @@
# Retarget IO
A utility library to retarget the standard input/output (STDIO) messages to a UART port. With this library, you can directly print messages on a UART terminal using `printf()`.
### What's Included?
* printf() support over a UART terminal
* Support for GCC, IAR, and ARM toolchains
* Thread safe write for NewLib
### What Changed?
#### v1.3.0
* Added support for checking whether data is being transmitted and waiting until done before finishing the deinit process
* Added support for using with HAL v1 or v2
#### v1.2.0
* Improve error handling
* Add de-initialization of the mutex to `cy_retarget_io_deinit`
* Update documentation for integration of the library in a RTOS environment.
#### v1.1.1
* Minor update for documentation & branding
#### v1.1.0
* Implemented system I/O retarget functions specific to ARM Compiler 6.
* Made _write implementation thread-safe for Newlib.
#### v1.0.0
* Initial release
### Supported Software and Tools
This version of the Retarget IO was validated for compatibility with the following Software and Tools:
| Software and Tools | Version |
| :--- | :----: |
| ModusToolbox™ Software Environment | 2.4.0 |
| GCC Compiler | 10.3.1 |
| IAR Compiler | 8.4 |
| ARM Compiler 6 | 6.11 |
Minimum required ModusToolbox™ Software Environment: v2.0
### More information
* [API Reference Guide](https://infineon.github.io/retarget-io/html/index.html)
* [Cypress Semiconductor, an Infineon Technologies Company](http://www.cypress.com)
* [Infineon GitHub](https://github.com/infineon)
* [ModusToolbox™](https://www.cypress.com/products/modustoolbox-software-environment)
* [PSoC™ 6 Code Examples using ModusToolbox™ IDE](https://github.com/infineon/Code-Examples-for-ModusToolbox-Software)
* [ModusToolbox™ Software](https://github.com/Infineon/modustoolbox-software)
* [PSoC™ 6 Resources - KBA223067](https://community.cypress.com/docs/DOC-14644)
---
© Cypress Semiconductor Corporation (an Infineon company) or an affiliate of Cypress Semiconductor Corporation, 2019-2021.

View File

@ -0,0 +1,603 @@
/***************************************************************************//**
* \file cy_retarget_io.c
*
* \brief
* Provides APIs for retargeting stdio to UART hardware contained on the Cypress
* kits.
*
********************************************************************************
* \copyright
* Copyright 2018-2021 Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#include "cy_retarget_io.h"
#include "cyhal_hw_types.h"
#include "cyhal_uart.h"
#include "cy_utils.h"
#include "cyhal_system.h"
#include <stdbool.h>
#include <stdlib.h>
#if (defined(CY_RTOS_AWARE) || defined(COMPONENT_RTOS_AWARE)) && defined(__GNUC__) && \
!defined(__ARMCC_VERSION) && !defined(__clang__)
// The cyhal_uart driver is not necessarily thread-safe. To avoid concurrent
// access, the ARM and IAR libraries use mutexes to control access to stdio
// streams. For Newlib, the mutex must be implemented in _write(). For all
// libraries, the program must start the RTOS kernel before calling any stdio
// functions.
#include "cyabs_rtos.h"
static cy_mutex_t cy_retarget_io_mutex;
static bool cy_retarget_io_mutex_initialized = false;
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_init
//--------------------------------------------------------------------------------------------------
static cy_rslt_t cy_retarget_io_mutex_init(void)
{
cy_rslt_t rslt;
if (cy_retarget_io_mutex_initialized)
{
rslt = CY_RSLT_SUCCESS;
}
else if (CY_RSLT_SUCCESS == (rslt = cy_rtos_init_mutex(&cy_retarget_io_mutex)))
{
cy_retarget_io_mutex_initialized = true;
}
return rslt;
}
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_acquire
//--------------------------------------------------------------------------------------------------
static void cy_retarget_io_mutex_acquire(void)
{
CY_ASSERT(cy_retarget_io_mutex_initialized);
cy_rslt_t rslt = cy_rtos_get_mutex(&cy_retarget_io_mutex, CY_RTOS_NEVER_TIMEOUT);
if (rslt != CY_RSLT_SUCCESS)
{
abort();
}
}
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_release
//--------------------------------------------------------------------------------------------------
static void cy_retarget_io_mutex_release(void)
{
CY_ASSERT(cy_retarget_io_mutex_initialized);
cy_rslt_t rslt = cy_rtos_set_mutex(&cy_retarget_io_mutex);
if (rslt != CY_RSLT_SUCCESS)
{
abort();
}
}
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_deinit
//--------------------------------------------------------------------------------------------------
static void cy_retarget_io_mutex_deinit(void)
{
CY_ASSERT(cy_retarget_io_mutex_initialized);
cy_rslt_t rslt = cy_rtos_deinit_mutex(&cy_retarget_io_mutex);
if (rslt != CY_RSLT_SUCCESS)
{
abort();
}
}
#else // if (defined(CY_RTOS_AWARE) || defined(COMPONENT_RTOS_AWARE)) && defined(__GNUC__) &&
// !defined(__ARMCC_VERSION) && !defined(__clang__)
#ifdef __ICCARM__
// Ignore unused functions
#pragma diag_suppress=Pe177
#endif
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_init
//--------------------------------------------------------------------------------------------------
static inline cy_rslt_t cy_retarget_io_mutex_init(void)
{
return CY_RSLT_SUCCESS;
}
#if defined(__ARMCC_VERSION) // ARM-MDK
__attribute__((unused))
#endif
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_acquire
//--------------------------------------------------------------------------------------------------
static inline void cy_retarget_io_mutex_acquire(void)
{
}
#if defined(__ARMCC_VERSION) // ARM-MDK
__attribute__((unused))
#endif
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_release
//--------------------------------------------------------------------------------------------------
static inline void cy_retarget_io_mutex_release(void)
{
}
#if defined(__ARMCC_VERSION) // ARM-MDK
__attribute__((unused))
#endif
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_mutex_deinit
//--------------------------------------------------------------------------------------------------
static inline void cy_retarget_io_mutex_deinit(void)
{
}
#endif // if (defined(CY_RTOS_AWARE) || defined(COMPONENT_RTOS_AWARE)) && defined(__GNUC__) &&
// !defined(__ARMCC_VERSION) && !defined(__clang__)
#if defined(__cplusplus)
extern "C" {
#endif
// UART HAL object used by BSP for Debug UART port
cyhal_uart_t cy_retarget_io_uart_obj;
// Tracks the previous character sent to output stream
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
static char cy_retarget_io_stdout_prev_char = 0;
#endif // CY_RETARGET_IO_CONVERT_LF_TO_CRLF
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_getchar
//--------------------------------------------------------------------------------------------------
static inline cy_rslt_t cy_retarget_io_getchar(char* c)
{
return cyhal_uart_getc(&cy_retarget_io_uart_obj, (uint8_t*)c, 0);
}
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_putchar
//--------------------------------------------------------------------------------------------------
static inline cy_rslt_t cy_retarget_io_putchar(char c)
{
return cyhal_uart_putc(&cy_retarget_io_uart_obj, (uint8_t)c);
}
#if defined(__ARMCC_VERSION) // ARM-MDK
//--------------------------------------------------------------------------------------------------
// fputc
//--------------------------------------------------------------------------------------------------
__attribute__((weak)) int fputc(int ch, FILE* f)
{
(void)f;
cy_rslt_t rslt = CY_RSLT_SUCCESS;
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
if (((char)ch == '\n') && (cy_retarget_io_stdout_prev_char != '\r'))
{
rslt = cy_retarget_io_putchar('\r');
}
#endif // CY_RETARGET_IO_CONVERT_LF_TO_CRLF
if (CY_RSLT_SUCCESS == rslt)
{
rslt = cy_retarget_io_putchar(ch);
}
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
if (CY_RSLT_SUCCESS == rslt)
{
cy_retarget_io_stdout_prev_char = (char)ch;
}
#endif // CY_RETARGET_IO_CONVERT_LF_TO_CRLF
return (CY_RSLT_SUCCESS == rslt) ? ch : EOF;
}
#elif defined (__ICCARM__) // IAR
#include <yfuns.h>
//--------------------------------------------------------------------------------------------------
// __write
//--------------------------------------------------------------------------------------------------
__weak size_t __write(int handle, const unsigned char* buffer, size_t size)
{
size_t nChars = 0;
// This template only writes to "standard out", for all other file handles it returns failure.
if (handle != _LLIO_STDOUT)
{
return (_LLIO_ERROR);
}
if (buffer != NULL)
{
cy_rslt_t rslt = CY_RSLT_SUCCESS;
for (; nChars < size; ++nChars)
{
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
if ((*buffer == '\n') && (cy_retarget_io_stdout_prev_char != '\r'))
{
rslt = cy_retarget_io_putchar('\r');
}
#endif // CY_RETARGET_IO_CONVERT_LF_TO_CRLF
if (rslt == CY_RSLT_SUCCESS)
{
rslt = cy_retarget_io_putchar(*buffer);
}
if (rslt != CY_RSLT_SUCCESS)
{
break;
}
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
cy_retarget_io_stdout_prev_char = *buffer;
#endif // CY_RETARGET_IO_CONVERT_LF_TO_CRLF
++buffer;
}
}
return (nChars);
}
#else // (__GNUC__) GCC
// Add an explicit reference to the floating point printf library to allow the usage of floating
// point conversion specifier.
__asm(".global _printf_float");
//--------------------------------------------------------------------------------------------------
// _write
//--------------------------------------------------------------------------------------------------
__attribute__((weak)) int _write(int fd, const char* ptr, int len)
{
int nChars = 0;
(void)fd;
if (ptr != NULL)
{
cy_rslt_t rslt = CY_RSLT_SUCCESS;
cy_retarget_io_mutex_acquire();
for (; nChars < len; ++nChars)
{
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
if ((*ptr == '\n') && (cy_retarget_io_stdout_prev_char != '\r'))
{
rslt = cy_retarget_io_putchar('\r');
}
#endif // CY_RETARGET_IO_CONVERT_LF_TO_CRLF
if (CY_RSLT_SUCCESS == rslt)
{
rslt = cy_retarget_io_putchar((uint32_t)*ptr);
}
if (CY_RSLT_SUCCESS != rslt)
{
break;
}
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
cy_retarget_io_stdout_prev_char = *ptr;
#endif // CY_RETARGET_IO_CONVERT_LF_TO_CRLF
++ptr;
}
cy_retarget_io_mutex_release();
}
return (nChars);
}
#endif // if defined(__ARMCC_VERSION)
#if defined(__ARMCC_VERSION) // ARM-MDK
//--------------------------------------------------------------------------------------------------
// fgetc
//--------------------------------------------------------------------------------------------------
__attribute__((weak)) int fgetc(FILE* f)
{
(void)f;
char c;
cy_rslt_t rslt = cy_retarget_io_getchar(&c);
return (CY_RSLT_SUCCESS == rslt) ? c : EOF;
}
#elif defined (__ICCARM__) // IAR
//--------------------------------------------------------------------------------------------------
// __read
//--------------------------------------------------------------------------------------------------
__weak size_t __read(int handle, unsigned char* buffer, size_t size)
{
// This template only reads from "standard in", for all other file handles it returns failure.
if ((handle != _LLIO_STDIN) || (buffer == NULL))
{
return (_LLIO_ERROR);
}
else
{
cy_rslt_t rslt = cy_retarget_io_getchar((char*)buffer);
return (CY_RSLT_SUCCESS == rslt) ? 1 : 0;
}
}
#else // (__GNUC__) GCC
// Add an explicit reference to the floating point scanf library to allow the usage of floating
// point conversion specifier.
__asm(".global _scanf_float");
//--------------------------------------------------------------------------------------------------
// _read
//--------------------------------------------------------------------------------------------------
__attribute__((weak)) int _read(int fd, char* ptr, int len)
{
(void)fd;
cy_rslt_t rslt;
int nChars = 0;
if (ptr != NULL)
{
for (; nChars < len; ++ptr)
{
rslt = cy_retarget_io_getchar(ptr);
if (rslt == CY_RSLT_SUCCESS)
{
++nChars;
if ((*ptr == '\n') || (*ptr == '\r'))
{
break;
}
}
else
{
break;
}
}
}
return (nChars);
}
#endif // if defined(__ARMCC_VERSION)
#if defined(__ARMCC_VERSION) // ARM-MDK
// Include _sys_* prototypes provided by ARM Compiler runtime library
#include <rt_sys.h>
// Prevent linkage of library functions that use semihosting calls
__asm(".global __use_no_semihosting\n\t");
// Enable the linker to select an optimized library that does not include code to handle input
// arguments to main()
__asm(".global __ARM_use_no_argv\n\t");
//--------------------------------------------------------------------------------------------------
// _sys_open
//
// Open a file: dummy implementation.
// Everything goes to the same output, no need to translate the file names
// (__stdin_name/__stdout_name/__stderr_name) to descriptor numbers
//--------------------------------------------------------------------------------------------------
FILEHANDLE __attribute__((weak)) _sys_open(const char* name, int openmode)
{
(void)name;
(void)openmode;
return 1;
}
//--------------------------------------------------------------------------------------------------
// _sys_close
//
// Close a file: dummy implementation.
//--------------------------------------------------------------------------------------------------
int __attribute__((weak)) _sys_close(FILEHANDLE fh)
{
(void)fh;
return 0;
}
//--------------------------------------------------------------------------------------------------
// _sys_write
//
// Write to a file: dummy implementation.
// The low-level function fputc retargets output to use UART TX
//--------------------------------------------------------------------------------------------------
int __attribute__((weak)) _sys_write(FILEHANDLE fh, const unsigned char* buf, unsigned len,
int mode)
{
(void)fh;
(void)buf;
(void)len;
(void)mode;
return 0;
}
//--------------------------------------------------------------------------------------------------
// _sys_read
//
// Read from a file: dummy implementation.
// The low-level function fputc retargets input to use UART RX
//--------------------------------------------------------------------------------------------------
int __attribute__((weak)) _sys_read(FILEHANDLE fh, unsigned char* buf, unsigned len, int mode)
{
(void)fh;
(void)buf;
(void)len;
(void)mode;
return -1;
}
//--------------------------------------------------------------------------------------------------
// _ttywrch
//
// Write a character to the output channel: dummy implementation.
//--------------------------------------------------------------------------------------------------
void __attribute__((weak)) _ttywrch(int ch)
{
(void)ch;
}
//--------------------------------------------------------------------------------------------------
// _sys_istty
//
// Check if the file is connected to a terminal: dummy implementation
//--------------------------------------------------------------------------------------------------
int __attribute__((weak)) _sys_istty(FILEHANDLE fh)
{
(void)fh;
return 0;
}
//--------------------------------------------------------------------------------------------------
// _sys_seek
//
// Move the file position to a given offset: dummy implementation
//--------------------------------------------------------------------------------------------------
int __attribute__((weak)) _sys_seek(FILEHANDLE fh, long pos)
{
(void)fh;
(void)pos;
return -1;
}
//--------------------------------------------------------------------------------------------------
// _sys_flen
// Return the current length of a file: dummy implementation
//--------------------------------------------------------------------------------------------------
long __attribute__((weak)) _sys_flen(FILEHANDLE fh)
{
(void)fh;
return 0;
}
//--------------------------------------------------------------------------------------------------
// _sys_exit
//
// Terminate the program: dummy implementation
//--------------------------------------------------------------------------------------------------
void __attribute__((weak)) _sys_exit(int returncode)
{
(void)returncode;
for (;;)
{
// Halt here forever
}
}
//--------------------------------------------------------------------------------------------------
// _sys_command_string
//
// Return a pointer to the command line: dummy implementation
//--------------------------------------------------------------------------------------------------
char __attribute__((weak)) *_sys_command_string(char* cmd, int len)
{
(void)cmd;
(void)len;
return NULL;
}
#endif // ARM-MDK
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_init
//--------------------------------------------------------------------------------------------------
cy_rslt_t cy_retarget_io_init(cyhal_gpio_t tx, cyhal_gpio_t rx, uint32_t baudrate)
{
const cyhal_uart_cfg_t uart_config =
{
.data_bits = 8,
.stop_bits = 1,
.parity = CYHAL_UART_PARITY_NONE,
.rx_buffer = NULL,
.rx_buffer_size = 0
};
#if (CYHAL_API_VERSION >= 2)
cy_rslt_t result =
cyhal_uart_init(&cy_retarget_io_uart_obj, tx, rx, NC, NC, NULL, &uart_config);
#else // HAL API version 1
cy_rslt_t result = cyhal_uart_init(&cy_retarget_io_uart_obj, tx, rx, NULL, &uart_config);
#endif
if (result == CY_RSLT_SUCCESS)
{
result = cyhal_uart_set_baud(&cy_retarget_io_uart_obj, baudrate, NULL);
}
if (result == CY_RSLT_SUCCESS)
{
result = cy_retarget_io_mutex_init();
}
return result;
}
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_is_tx_active
//--------------------------------------------------------------------------------------------------
bool cy_retarget_io_is_tx_active()
{
return cyhal_uart_is_tx_active(&cy_retarget_io_uart_obj);
}
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_deinit
//--------------------------------------------------------------------------------------------------
void cy_retarget_io_deinit(void)
{
// Since the largest hardware buffer would be 256 bytes
// it takes about 500 ms to transmit the 256 bytes at 9600 baud.
// Thus 1000 ms gives roughly 50% padding to this time.
int timeout_remaining_ms = 1000;
while (timeout_remaining_ms > 0)
{
if (!cy_retarget_io_is_tx_active())
{
break;
}
cyhal_system_delay_ms(1);
timeout_remaining_ms--;
}
CY_ASSERT(timeout_remaining_ms != 0);
cyhal_uart_free(&cy_retarget_io_uart_obj);
cy_retarget_io_mutex_deinit();
}
#if defined(__cplusplus)
}
#endif

View File

@ -0,0 +1,99 @@
/***********************************************************************************************//**
* \file cy_retarget_io.h
*
* \brief
* Provides APIs for transmitting messages to or from the board via standard
* printf/scanf functions. Messages are transmitted over a UART connection which
* is generally connected to a host machine. Transmission is done at 115200 baud
* using the tx and rx pins provided by the user of this library. The UART
* instance is made available via cy_retarget_io_uart_obj in case any changes
* to the default configuration are desired.
* NOTE: If the application is built using newlib-nano, by default, floating
* point format strings (%f) are not supported. To enable this support you must
* add '-u _printf_float' to the linker command line.
*
***************************************************************************************************
* \copyright
* Copyright 2018-2021 Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**************************************************************************************************/
/**
* \addtogroup group_board_libs Retarget IO
* \{
*/
#pragma once
#include <stdio.h>
#include "cy_result.h"
#include "cyhal_hw_types.h"
#if defined(__cplusplus)
extern "C" {
#endif
/** UART HAL object used by this library */
extern cyhal_uart_t cy_retarget_io_uart_obj;
/** UART baud rate */
#define CY_RETARGET_IO_BAUDRATE (115200)
#ifdef DOXYGEN
/** Defining this macro enables conversion of line feed (LF) into carriage
* return followed by line feed (CR & LF) on the output direction (STDOUT). You
* can define this macro through the DEFINES variable in the application
* Makefile.
*/
#define CY_RETARGET_IO_CONVERT_LF_TO_CRLF
#endif // DOXYGEN
/**
* \brief Initialization function for redirecting low level IO commands to allow
* sending messages over a UART interface. This will setup the communication
* interface to allow using printf and related functions.
*
* In an RTOS environment, this function must be called after the RTOS has been
* initialized.
*
* \param tx UART TX pin
* \param rx UART RX pin
* \param baudrate UART baudrate
* \returns CY_RSLT_SUCCESS if successfully initialized, else an error about
* what went wrong
*/
cy_rslt_t cy_retarget_io_init(cyhal_gpio_t tx, cyhal_gpio_t rx, uint32_t baudrate);
/**
* \brief Checks whether there is data waiting to be written to the serial console.
* \returns true if there are pending TX transactions, otherwise false
*/
bool cy_retarget_io_is_tx_active();
/**
* \brief Releases the UART interface allowing it to be used for other purposes.
* After calling this, printf and related functions will no longer work.
*/
void cy_retarget_io_deinit(void);
#if defined(__cplusplus)
}
#endif
/** \} group_board_libs */

View File

@ -0,0 +1 @@
<version>1.3.0.25183</version>