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. 测试结果

相关推荐
少司府4 天前
嵌入式外设篇(三)GPIO·三:MCU系统结构、总线与统一编制
linux·python·stm32·单片机·嵌入式硬件·mcu·嵌入式软件
国科安芯5 天前
卫星控制板偶发复位:MCU供电、时钟、ECC与总线的联合定位——AS32S601ZIT2在星载控制单元中的FAE排查方法
单片机·嵌入式硬件·mcu·risc-v·抗辐射·通信芯片
少司府6 天前
嵌入式外设篇(二)GPIO·二:GPIO输出与LED控制
linux·stm32·单片机·嵌入式硬件·mcu·51单片机·系统
少司府7 天前
嵌入式外设篇(一)GPIO·一:认识GPIO
linux·单片机·嵌入式硬件·mcu·系统·rtos·嵌入式软件
jianqiang.xue7 天前
1颗NPU分时复用:鸿蒙把轻AI塞进了MCU
人工智能·单片机·mcu·嵌入式·harmonyos·鸿蒙·端侧ai
国科安芯7 天前
星载姿轨控单元RISC-V MCU的存储、时基与辐射韧性——AS32S601ZIT2在商业卫星控制与配电单元中的应用
单片机·嵌入式硬件·mcu·risc-v·低轨卫星·抗辐射
少司府11 天前
嵌入式入门篇(二):初识STM32F103ZET6
linux·python·stm32·单片机·嵌入式硬件·mcu·嵌入式软件
蜀黍@猿13 天前
ARM 汇编入门(十二):MMU、页表与虚拟内存全解析
汇编·arm开发·stm32·mcu
wuyk55513 天前
嵌入式故障诊断-Bug002-局部大数组压栈高温必死机
stm32·单片机·嵌入式硬件·mcu·物联网·51单片机·嵌入式实时数据库
蜀黍@猿14 天前
ARM 汇编入门(十):标量浮点与 VFP 指令全解析
汇编·arm开发·stm32·mcu