一、华大的库 hc32l13x_ddl_Rev1.9.2 Lite 1.打开 hc32l13x_ddl_Rev1.9.2 Lite\driver\src\ddl.c 约208行
#if defined (__CC_ARM)
#pragma import(__use_no_semihosting)
void _sys_exit(int x)
{
x = x;
}
struct __FILE
{
int handle;
};
FILE __stdout;
#endif
#ifdef __DEBUG
int fputc(int ch, FILE *f)
{
if (((uint8_t)ch) == '\n')
{
Debug_Output('\r');
}
Debug_Output(ch);
return ch;
}
#endif
修改fputc函数
int fputc(int ch, FILE *f)
{
Uart_SendDataPoll(M0P_UART0,ch);
return ch;
}
二、初始化串口
只是要串口0就行,和上面的fputc要对应.由于hc32l136k8有多pin都可以配置为串口0,所以用宏来定义,决定用哪个pin。 新建usart.h
#define DEBUG_UART0_B8B9
三个pin随便用一个
usart.c
void UART0_PortInit(void)
{
stc_gpio_cfg_t stcGpioCfg;
DDL_ZERO_STRUCT(stcGpioCfg);
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE);
stcGpioCfg.enDir = GpioDirOut;
#if defined(DEBUG_UART0_B6B7)
Gpio_Init(GpioPortB, GpioPin6, &stcGpioCfg);
Gpio_SetAfMode(GpioPortB, GpioPin6, GpioAf2);
#elif defined(DEBUG_UART0_B8B9)
Gpio_Init(GpioPortB, GpioPin8, &stcGpioCfg);
Gpio_SetAfMode(GpioPortB, GpioPin8, GpioAf7);
#elif defined(DEBUG_UART0_A9A10)
Gpio_Init(GpioPortA, GpioPin9, &stcGpioCfg);
Gpio_SetAfMode(GpioPortA, GpioPin9, GpioAf1);
#endif
stcGpioCfg.enDir = GpioDirIn;
#if defined(DEBUG_UART0_B6B7)
Gpio_Init(GpioPortB, GpioPin7, &stcGpioCfg);
Gpio_SetAfMode(GpioPortB, GpioPin7, GpioAf2);
#elif defined(DEBUG_UART0_B8B9)
Gpio_Init(GpioPortB, GpioPin9, &stcGpioCfg);
Gpio_SetAfMode(GpioPortB, GpioPin9, GpioAf7);
#elif defined(DEBUG_UART0_A9A10)
Gpio_Init(GpioPortA, GpioPin10, &stcGpioCfg);
Gpio_SetAfMode(GpioPortA, GpioPin10, GpioAf1);
#endif
}
三、测试
int32_t main(void)
{
UART0_PortInit();
Uart0Cfg(38400);
printf("HC32L136K8TA-MINI \r\n");
while(1)
{
printf("+++......\r\n");
delay1ms(1000);
}
}
https://shop170824944.taobao.com/ https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-23044783907.23.56114554bzW4t2&id=650977624658
|