Eclipse IDE for ModusToolbox™ 3.4环境CYT4BB7串口配置发送

前言

CYT4BB7芯片,在开发过程中,通过Eclipse IDE for ModusToolbox™ 3.4的开发环境可以配置很多功能,其中就包括串口。配置起来很省事,配置完成后保存代码自动生成,在main方法中给串口初始化一下就可以实现发送的功能了。以下就是配置串口的前置条件和方法。

1.准备环境

安装Eclipse IDE for ModusToolbox™ 3.4开发环境,以及gcc编译相关软件。具体参考英飞凌官方文档。

2.创建Application

2.1 在quick panel中点击New Application按钮

2.2 Create from MPN

2.3 选择对应芯片型号

2.4 点击Close

2.5 Next

2.6 Create

3. 创建Application后首次编译

3.1 注掉报错代码

打开main.c文件,并注释掉#include "mtb_hal.h",否则编译会报错

3.2 首次编译

点击Quick Panel中的Build Project

4. 配置串口

4.1 打开配置工具

4.2 选择配置串口

4.3 串口配置

此时还没有配置后,如果按CTRL+S后会报错,因为时钟和引脚都还没配置。

4.4 时钟配置

4.4.1 System配置

在配置时钟之前,需要先配置System,以便时钟可以正确选择。

UART打算采用Periheral group1组的时钟,因此需要使能CLK_HF2,通路选择CLK_PATH3

Periheral group1组的时钟频率为100MHz。

4.4.2 时钟设置和关联

4.4.3 再次配置串口

OverSample需要设置成12后,实际波特率才能接近115200,但是会存在一些误差。

引脚选择15.0是接收,15.1是发送。

4.5 保存并生成代码

5. 编码实现串口发送

5.1 配置后生成的代码

5.2 时钟等的初始化

main函数中的cybsp_init方法,会调用cycfg_config_init()方法。这个初始化方法已经把系统、时钟、引脚等都初始化好了。

cpp 复制代码
void cycfg_config_init(void)
{
    init_cycfg_system();
    init_cycfg_clocks();
    init_cycfg_routing();
    init_cycfg_peripherals();
    init_cycfg_pins();
}

5.3 串口初始化

参考网页中的初始化方法(网页是在配置中点击打开网页的)

给出main.c的代码示例

cpp 复制代码
/*******************************************************************************
* File Name:   main.c
*
* Description: This is the source code for the Empty Application Example
*              for ModusToolbox.
*
* Related Document: See README.md
*
*******************************************************************************
* Copyright 2024, Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation.  All rights reserved.
*
* This software, including source code, documentation and related
* materials ("Software") is owned by Cypress Semiconductor Corporation
* or one of its affiliates ("Cypress") and is protected by and subject to
* worldwide patent protection (United States and foreign),
* United States 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 ("EULA").
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software
* source code solely for use in connection with Cypress's
* integrated circuit products.  Any reproduction, modification, translation,
* compilation, or representation of this Software except as specified
* above is prohibited without the express written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, 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 the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer
* of such system or application assumes all risk of such use and in doing
* so agrees to indemnify Cypress against all liability.
*******************************************************************************/


/*******************************************************************************
* Header Files
*******************************************************************************/
//#include "mtb_hal.h"
#include "cybsp.h"

/*******************************************************************************
* Macros
*******************************************************************************/


/*******************************************************************************
* Global Variables
*******************************************************************************/


/*******************************************************************************
* Function Prototypes
*******************************************************************************/


/*******************************************************************************
* Function Definitions
*******************************************************************************/

/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
* This is the main function for CPU. It...
*    1.
*    2.
*
* Parameters:
*  void
*
* Return:
*  int
*
*******************************************************************************/
uint8_t txBuffer[1024] =  "Hello World!\r\n";
cy_stc_scb_uart_context_t uartContext;

void uart_send_datas(uint8_t *buf, uint32_t len)
{
	Cy_SCB_UART_PutArrayBlocking(SCB9, buf, len);
	/* Blocking wait for transfer completion */
	while (!Cy_SCB_UART_IsTxComplete(SCB9))
	{
	}
}

void delay_ms(uint32_t ms)
{
	uint32_t tmp = 0, outj = 0;
	for(outj = 0; outj < ms; outj++)
	{
		for(tmp = 0; tmp < 3200; tmp++)
		{
			__ASM ("NOP");
		}
	}
}

int main(void)
{
    cy_rslt_t result;

    /* Initialize the device and board peripherals */
    result = cybsp_init();

    /* Board init failed. Stop program execution */
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

    Cy_SCB_UART_Init(SCB9, &scb_9_config, &uartContext);
    Cy_SCB_UART_Enable(SCB9);

    /* Enable global interrupts */
    __enable_irq();

    for (;;)
    {
    	uart_send_datas(txBuffer, 14);
    	delay_ms(1000);
    }
}

/* [] END OF FILE */

6. 编译烧录

编译完成后,烧录固件。

7. 测试结果

相关推荐
深色風信子1 天前
Eclipse 插件开发 5 编辑器
java·eclipse·编辑器
完美主义zx1 天前
Eclipse通过Tomcat启动web项目报错
eclipse·tomcat
冬天的雪20082 天前
eclipse中tomcat启动日志乱码
java·eclipse·tomcat
Bob99982 天前
基于晶晨S905L3B单网线盒子的Armbian 或openwrt应用
java·javascript·网络·数据结构·c++·python·eclipse
时光の尘4 天前
FreeRTOS菜鸟入门(十)·消息队列
c语言·stm32·单片机·嵌入式硬件·mcu·物联网·嵌入式实时数据库
ZeroOne电平浪客4 天前
AUTOSAR_BSW_从入门到精通学习笔记系列_EcuM
笔记·mcu·学习·汽车·autosar·普华小满
mftang5 天前
Zephyr RTOS架构下的固件升级
mcu·zephyr架构蓝牙应用笔记
Mr zhua6 天前
(七)ASCLIN_UART模块串口+DMA+环形缓存区
单片机·mcu·英飞凌·tc334
攻城狮-鹏哥7 天前
DRV8301 三相电机驱动芯片的硬件参数与应用设计
驱动开发·单片机·嵌入式硬件·mcu·硬件架构·dsp开发·pcb工艺
spencer_tseng8 天前
gradle eclipse [.project .classpath .settings]
java·ide·eclipse·gradle