ch32v307的tim1设置pwm和rtthread的kprint用的usart输出冲突?

最近在用赤兔板子调试lcd,st7789,里面有这么一段代码:


void LCD_GPIOInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB| RCC_APB2Periph_TIM1, ENABLE );
  
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init( GPIOB, &GPIO_InitStructure );
    rt_kprintf("LCD manufacturer ID41\n\r  ");

    TIM_OCInitTypeDef TIM_OCInitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;

    TIM_TimeBaseInitStructure.TIM_Period = 100;
    TIM_TimeBaseInitStructure.TIM_Prescaler = 288-1;
    TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
    TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit( TIM1, &TIM_TimeBaseInitStructure );
    rt_kprintf("LCD manufacturer ID42\n\r  ");
#if (PWM_MODE == PWM_MODE1)
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

#elif (PWM_MODE == PWM_MODE2)
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
#endif

    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
    TIM_OCInitStructure.TIM_Pulse = 50;
    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
    TIM_OC2Init( TIM1, &TIM_OCInitStructure );
    rt_kprintf("LCD manufacturer ID43\n\r  ");
    TIM_CtrlPWMOutputs( TIM1, ENABLE );
    TIM_OC2PreloadConfig( TIM1, TIM_OCPreload_Disable );
    TIM_ARRPreloadConfig( TIM1, ENABLE );
    rt_kprintf("LCD manufacturer ID44\n\r  ");
    TIM_Cmd( TIM1, ENABLE );
   // printf("LCD manufacturer ID45\n\r  ");
}

上面代码是使用gpiob的pin14作为亮度调节输出。当不用rtthread时,使用debug.c里的printf打印,输出数据一切正常;当我用rtthread后,使用rt_kprint打印,就输出乱码,在

TIM_Cmd( TIM1, ENABLE );

之前的所有打印都正常,在其之后的所有打印都输出乱码

 \ | /

- RT -     Thread Operating System

 / | \     4.0.4 build May 24 2023

 2006 - 2021 Copyright by rt-thread team

MCU: CH32V307

SysClk: 144000000Hz

www.wch.cn-guolin

LCD manufacturer ID1

  LCD manufacturer ID2

  LCD manufacturer ID41

  LCD manufacturer ID42

  LCD manufacturer ID43

  LCD manufacturer ID44

 L??[[??I3????Y?s3cue??礃??mn?l7?洊?x5?慆6窙??? x5?萵??#膻05胊?n

[11:47:15.654]收←◆欬??!!


rt_kprintf("LCD manufacturer ID44\n\r  ");

这种是我用来定位哪里出问题的标志


您好,建议你按照下图在初始化的时候将对应结构体清零,打印应该就正常了,这边测试过没有问题,你可以试一下

image.png


只有登录才能回复,可以选择微信账号登录