AURIX TC397 ASCLIN UART
目录
- ASCLIN
- 硬件连接
- 新建工程
- Debug Printf
- ASCLIN_UART 发送
- Ifx_Console_print
- 接收中断
- TC397_UART工程下载
- ASCLIN_Shell_UART_1
- 参考
- 微信公众号
ASCLIN
TC397有12路ASCLIN
, 可以支持12路UART
.
ASCLIN
, Asynchronous Synchronous Interface
, 3合1模块, 可以用单个模块实现ASC(UART)
, LIN
和Master SPI
的功能, 配置每位4~16倍过采样, 实现更高的精度和更高的波特率.
作为ASC(UART)或Master SPI时, 支持高达25MBaud波特率.
过采样的设置:
来源 AURIX ASCLIN
硬件连接
先来看下硬件连接, KIT_A2G_TC397_5V_TFT
评估板上:
PIN | ASCLIN0_UART |
---|---|
P14.0 | TX |
P14.1 | RX |
这个串口直接连到了调试器上:
所以评估板USB插到电脑上, 电脑就可以和这个串口通信:
新建工程
- 打开AURIX Development Studio
- File -> New -> New AURIX Project
- 填入Project Name, 然后Next
- 选择板子和器件, Finish:
Debug Printf
这种方式在调试的时候可以用, 无需串口外设.
#include "Bsp.h"
#include <stdio.h>while(1){static uint8 count = 0; //Only for Debugprintf("Hello, world, %d\r\n", ++count); //Only for DebugwaitTime(5 * TimeConst_100ms);}
点击爬虫图标进入调试:
点击Resume按钮运行程序, 可以在右下方看到打印:
ASCLIN_UART 发送
直接上Cpu0_Main.c
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"#include "Bsp.h"
//#include <stdio.h> //Only for Debug
#include "IfxAsclin_Asc.h"
#include "IfxCpu_Irq.h"#define SERIAL_BAUDRATE0 115200
#define SERIAL_PIN_RX0 IfxAsclin0_RXA_P14_1_IN
#define SERIAL_PIN_TX0 IfxAsclin0_TX_P14_0_OUT
#define INTPRIO_ASCLIN0_TX 19 /* Priority of the ISR */#define ASC_TX_BUFFER_SIZE 64
/* The transfer buffers allocate memory for the data itself and for FIFO runtime variables.* 8 more bytes have to be added to ensure a proper circular buffer handling independent from* the address to which the buffers have been located.*/
uint8 g_ascTxBuffer[ASC_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;IfxAsclin_Asc g_asc0;IFX_INTERRUPT(asclin0TxISR, 0, INTPRIO_ASCLIN0_TX); /* Adding the Interrupt Service Routine */void asclin0TxISR(void)
{IfxAsclin_Asc_isrTransmit(&g_asc0);
}void core0_main(void)
{IfxCpu_enableInterrupts();/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!* Enable the watchdogs and service them periodically if it is required*/IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());/* Wait for CPU sync event */IfxCpu_emitEvent(&g_cpuSyncEvent);IfxCpu_waitEvent(&g_cpuSyncEvent, 1);initTime();/* Initialize an instance of IfxAsclin_Asc_Config with default values */IfxAsclin_Asc_Config ascConfig;IfxAsclin_Asc_initModuleConfig(&ascConfig, SERIAL_PIN_TX0.module);/* Set the desired baud rate */ascConfig.baudrate.baudrate = SERIAL_BAUDRATE0;/* ISR priorities and interrupt target */ascConfig.interrupt.txPriority = INTPRIO_ASCLIN0_TX;ascConfig.interrupt.typeOfService = IfxCpu_Irq_getTos(IfxCpu_getCoreIndex());/* FIFO configuration */ascConfig.txBuffer = &g_ascTxBuffer;ascConfig.txBufferSize = ASC_TX_BUFFER_SIZE;/* Port pins configuration */const IfxAsclin_Asc_Pins pins ={NULL_PTR, IfxPort_InputMode_pullUp, /* CTS pin not used */&SERIAL_PIN_RX0, IfxPort_InputMode_pullUp, /* RX pin not used */NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS pin not used */&SERIAL_PIN_TX0, IfxPort_OutputMode_pushPull, /* TX pin */IfxPort_PadDriver_cmosAutomotiveSpeed1};ascConfig.pins = &pins;/* Initialize module with above parameters */IfxAsclin_Asc_initModule(&g_asc0, &ascConfig);while(1){static uint8 count = 1; //Only for Debug//printf("Hello, world, %d\r\n", ++count); //Only for DebugIfxAsclin_Asc_blockingWrite(&g_asc0, ++count);IfxAsclin_Asc_blockingWrite(&g_asc0, '-');uint8 txData[] = "Hello World!\r\n"; /* Message to send */Ifx_SizeT count1 = 14; /* Size of the message */IfxAsclin_Asc_write(&g_asc0, txData, &count1, TIME_INFINITE);waitTime(5 * TimeConst_100ms);}
}
其中:
初始化了发送, 优先级, 中断, FIFO
发送的中断服务还不能少
波特率115200以下时, 用
AURIX Development Studio
自带的Terminal
即可接收串口消息:
只测试了2M及以下的波特率, 改用SSCOM或者友善串口助手, 是正常的, 这个兄弟用printf测到了6.18M, AURIX 学习笔记(6)标准库中串口控制台输出
Ifx_Console_print
这个就是类似于printf
的功能, 只不过函数名变了一下而已.
#include "Ifx_Console.h"IfxStdIf_DPipe g_ascStandardInterface; /* Standard interface object */void core0_main(void)
{//上面的初始化//.../* Initialize the Standard Interface */IfxAsclin_Asc_stdIfDPipeInit(&g_ascStandardInterface, &g_asc0);/* Initialize the Console */Ifx_Console_init(&g_ascStandardInterface);while(1){static uint8 count = 1;Ifx_Console_print("count: %d\r\n", ++count);waitTime(5 * TimeConst_100ms);}
}
编译运行:
接收中断
这里实现一下把接收到的数据原封不动发送出去, 直接上 Cpu0_Main.c
:
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"#include "Bsp.h"
//#include <stdio.h> //Only for Debug
#include "IfxAsclin_Asc.h"
#include "IfxCpu_Irq.h"
#include "Ifx_Console.h"#define SERIAL_BAUDRATE0 921600
#define SERIAL_PIN_RX0 IfxAsclin0_RXA_P14_1_IN
#define SERIAL_PIN_TX0 IfxAsclin0_TX_P14_0_OUT
#define INTPRIO_ASCLIN0_TX 19 /* Priority of the ISR */
#define INTPRIO_ASCLIN0_RX 15 /* Priority of the ISR */
#define INTPRIO_ASCLIN0_ER 23 /* Priority of the ISR */#define ASC_TX_BUFFER_SIZE 1024
#define ASC_RX_BUFFER_SIZE 1024
/* The transfer buffers allocate memory for the data itself and for FIFO runtime variables.* 8 more bytes have to be added to ensure a proper circular buffer handling independent from* the address to which the buffers have been located.*/
uint8 g_ascTxBuffer[ASC_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
uint8 g_ascRxBuffer[ASC_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;IfxAsclin_Asc g_asc0; /* ASCLIN module object */
IfxStdIf_DPipe g_ascStandardInterface; /* Standard interface object */IFX_INTERRUPT(asclin0TxISR, 0, INTPRIO_ASCLIN0_TX); /* Adding the Interrupt Service Routine */
void asclin0TxISR(void)
{IfxAsclin_Asc_isrTransmit(&g_asc0);
}IFX_INTERRUPT(asc0RxISR, 0, INTPRIO_ASCLIN0_RX);
void asc0RxISR(void)
{IfxStdIf_DPipe_onReceive(&g_ascStandardInterface);// //abcdefghijklmnopqrstuvwxyz0123456789~?!$%^&*()
// if(IfxAsclin_Asc_getReadCount(&g_asc0) > 0)
// {// uint8 a = IfxAsclin_Asc_blockingRead(&g_asc0);
// IfxAsclin_Asc_blockingWrite(&g_asc0, a);
if(a == '\n')
{ //IfxAsclin_Asc_blockingWrite(&g_asc0, 'R');
//IfxAsclin_Asc_blockingWrite(&g_asc0, ':');
//IfxAsclin_Asc_blockingWrite(&g_asc0, ' ');
Ifx_Console_print("R: ");
}
// }
}IFX_INTERRUPT(asc0ErrISR, 0, INTPRIO_ASCLIN0_ER);
void asc0ErrISR(void)
{IfxStdIf_DPipe_onError(&g_ascStandardInterface);
}void core0_main(void)
{IfxCpu_enableInterrupts();/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!* Enable the watchdogs and service them periodically if it is required*/IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());/* Wait for CPU sync event */IfxCpu_emitEvent(&g_cpuSyncEvent);IfxCpu_waitEvent(&g_cpuSyncEvent, 1);initTime();/* Initialize an instance of IfxAsclin_Asc_Config with default values */IfxAsclin_Asc_Config ascConfig;IfxAsclin_Asc_initModuleConfig(&ascConfig, SERIAL_PIN_TX0.module);/* Set the desired baud rate */ascConfig.baudrate.baudrate = SERIAL_BAUDRATE0;ascConfig.baudrate.oversampling = IfxAsclin_OversamplingFactor_16; /* Set the oversampling factor *//* Configure the sampling mode */ascConfig.bitTiming.medianFilter = IfxAsclin_SamplesPerBit_three; /* Set the number of samples per bit*/ascConfig.bitTiming.samplePointPosition = IfxAsclin_SamplePointPosition_8; /* Set the first sample position *//* ISR priorities and interrupt target */ascConfig.interrupt.txPriority = INTPRIO_ASCLIN0_TX;ascConfig.interrupt.rxPriority = INTPRIO_ASCLIN0_RX;ascConfig.interrupt.erPriority = INTPRIO_ASCLIN0_ER;ascConfig.interrupt.typeOfService = IfxCpu_Irq_getTos(IfxCpu_getCoreIndex());/* FIFO configuration */ascConfig.txBuffer = &g_ascTxBuffer;ascConfig.txBufferSize = ASC_TX_BUFFER_SIZE;ascConfig.rxBuffer = &g_ascRxBuffer;ascConfig.rxBufferSize = ASC_RX_BUFFER_SIZE;/* Port pins configuration */const IfxAsclin_Asc_Pins pins ={NULL_PTR, IfxPort_InputMode_pullUp, /* CTS pin not used */&SERIAL_PIN_RX0, IfxPort_InputMode_pullUp, /* RX pin */NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS pin not used */&SERIAL_PIN_TX0, IfxPort_OutputMode_pushPull, /* TX pin */IfxPort_PadDriver_cmosAutomotiveSpeed1};ascConfig.pins = &pins;/* Initialize module with above parameters */IfxAsclin_Asc_initModule(&g_asc0, &ascConfig);/* Initialize the Standard Interface */IfxAsclin_Asc_stdIfDPipeInit(&g_ascStandardInterface, &g_asc0);/* Initialize the Console */Ifx_Console_init(&g_ascStandardInterface);//Ifx_Console_print("ACK Test\r\nR: ");while(1){//static uint8 count = 1; //Only for Debug//printf("Hello, world, %d\r\n", ++count); //Only for Debug//IfxAsclin_Asc_blockingWrite(&g_asc0, ++count);//IfxAsclin_Asc_blockingWrite(&g_asc0, '-');//uint8 txData[] = "Hello World!\r\n"; /* Message to send *///Ifx_SizeT count1 = 14; /* Size of the message *///IfxAsclin_Asc_write(&g_asc0, txData, &count1, TIME_INFINITE);//Ifx_Console_print("count: %d\r\n", ++count);//waitTime(5 * TimeConst_100ms);//abcdefghijklmnopqrstuvwxyz0123456789~?!$%^&*()sint32 readCount = (Ifx_SizeT)IfxAsclin_Asc_getReadCount(&g_asc0);if(readCount > 0){uint8 a = IfxAsclin_Asc_blockingRead(&g_asc0);IfxAsclin_Asc_blockingWrite(&g_asc0, a);//IfxAsclin_Asc_read(&g_asc0, g_ascTxBuffer, &readCount, TIME_INFINITE);//IfxAsclin_Asc_write(&g_asc0, g_ascTxBuffer, &readCount, TIME_INFINITE);}}
}
注意结果:
- 波特率改为921600, 缓存改为1024字节(之前的64字节太小)
- SSCOM -> 显示 -> 显示缓冲上限设为5M, 勾选1ms定时发送
abcdefghijklmnopqrstuvwxyz0123456789~?!$%^&*()
加回车换行 - 测试百万字节, 没有丢字节, 大环形缓冲真香
TC397_UART工程下载
TC397_UART
ASCLIN_Shell_UART_1
打开AURIX Development Studio
File -> Import… -> Infineon, AURIX Development Studio Project -> ASCLIN_Shell_UART_1_KIT_TC397_TFT, 这个例程很有意思, 一种终端的感觉:
参考
- AURIX ASCLIN
- ASCLIN_Shell_UART_1 for KIT_AURIX_TC397_TFT
- ASCLIN_UART_1 for KIT_AURIX_TC397_TFT.
- UART_DMA_Transfer_1 for KIT_AURIX_TC397_TFT
- UART_VCOM_1 for KIT_AURIX_TC397_TFT
微信公众号
欢迎扫描关注我的微信公众号, 及时获取最新文章:
AURIX TC397 ASCLIN UART相关推荐
- AURIX TC397 SCU 之 Watchdog 看门狗
目录 看门狗基础 TC397 Watchdog 微信公众号 看门狗基础 文档参阅 TC3XX User Manual 的9.4节, 看门狗Watchdog Timers (WDT)是System Co ...
- TriCore AURIX TC397一览
目录 选型 命名规则 资源 框图 Datasheet & Usermanual 封装 IDE与例程 开发板 中文论坛 参考 微信公众号 选型 命名规则 资源 框图 Datasheet & ...
- AURIX TC397 ADC EVADC EDSADC
目录 EVADC EDSADC Example_ADC_Queued_Scan Example_ADC_Filtering 微信公众号 EVADC EVADC, Enhanced Versatile ...
- AURIX TC397 Timer PWM 基础知识
目录 Timer/PWM资源 STM GTM GPT12 CCU6 参考 微信公众号 Timer/PWM资源 TC397有下列Timer/PWM资源: 6x STM GTM 1x GPT12 1x C ...
- AURIX TC397 CAN MCMCAN
目录 TC397_CAN简介 CAN Loop-Back CAN Transceiver CAN00 标准帧和扩展帧 微信公众号 TC397_CAN简介 不同于TC297的MultiCAN+, TC3 ...
- AURIX TC397 SCU 之 ERU 外部中断
目录 ERU基础知识 ERU引脚 ERU Example 微信公众号 ERU基础知识 参考 AURIX™ TC3xx User Manual Part-1 ERU, Event Request Uni ...
- Infineon Aurix TC397启动过程学习
一.概览 TC397整个启动过程如下图所示: 首先由某个复位事件开始,必要情况下经历上电过程,然后执行芯片的引导固件进而跳转到用户启动代码,最后执行用户程序,因此整个过程可总结为"复位.上电 ...
- Aurix TC397多核开发建议
一.多核开发建议
- ST NXP Infineon 常用MCU的汇总说明
文章目录 ST NXP Infineon 主要是 ST, NXP, Infineon 的芯片: 基本都有免费的IDE 图形化的配置, 生成初始化代码 便宜的调试工具(RMB几十 ~几百) 都有移植好的 ...
- spring 演变_团队的演变
spring 演变 Editor's Note: Your team will change whether you like it or not. People will come and go. ...
最新文章
- 我为什么选择在北上广深打拼?
- 经典DL论文研读(part4)--ImageNet Classification with Deep Convolutional Neural Networks
- phpcms v9 在当前栏目下获取父栏目与当前栏目的名称与连接
- python中的类装饰器应用场景_python中的装饰器常用于哪些应用场景
- jsp内置对象之request
- python基础知识学完之后再如何学_已学完 Python 基础知识,应该如何继续提升算法能力,以及如何过渡到机器学习?...
- 程序员必备开发工具(IDE)推荐
- 更换浏览器标题栏图标
- 地理建模——模型概述
- warning: array subscript is above array bounds
- WPF界面工具Telerik UI for WPF入门级教程 - 设置一个主题(二)
- 为什么Flutter是跨平台开发的终极之选,这篇文章可以满足你80%日常工作
- 关于传递函数的离散化
- 终端安全解决方案如何帮助保护数字化工作空间中的设备
- 搞懂分布式技术15:缓存更新的套路
- 考试提交答案demo
- selenium实现zhilian招聘的爬取
- uniapp网上商城排坑专业户
- 习题4.10 设有一长为3000m的绳子,每天减去一半,问需几天时间,绳子的长度会短于5m。
- AToken小课堂----什么是私钥?什么是助记词?