S32K 实现printf打印

双击管脚配置组件

这里我使用串口0的TX功能,使用PTC3为发送管脚

双击串口组件

设置串口波特率

生成代码


 

定义printf串口重定向函数

#include <string.h>
#include <stdint.h>
#include <stdbool.h>

#include <stdio.h>
#include "ewl_misra_types.h"
#include "file_struc.h"


int_t __write_console(__file_handle handle, uchar_t * buffer, size_t * count)
{
	(void)(handle);

    uint32_t bytesRemain;
    size_t bytes=*count;

    LPUART_DRV_SendData(INST_LPUART1, buffer, bytes);
    while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);

    return 0;
}

  调用管脚和串口初始化函数

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);

  

  点击工程,右键点击Properties,安装下面方式箭头选择对应的项

重新编译完成之后即可使用printf

下面实现了支持Error、Warning、info、debug等打印,支持颜色打印,数组字符打印等

接口如下

		USER_LOG_ERROR("USER_LOG_ERROR\r\n");
		USER_LOG_WARNING("USER_LOG_WARNING\r\n");
		USER_LOG_INFO("USER_LOG_INFO\r\n");
		USER_LOG_DEBUG("USER_LOG_DEBUG\r\n");
		USER_LOG_NAME("USER_LOG_NAME\r\n");

		uint8_t data[30];
		USER_LOG_HEXDUMP(data,sizeof(data));

串口显示效果如下

 代码链接如下

https://download.csdn.net/download/dear_Wally/85720462icon-default.png?t=M5H6https://download.csdn.net/download/dear_Wally/85720462

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dear_Wally

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值