这是本文档旧的修订版!


背景:ST的PLC参考设计板对应的设备树源码位于:https://github.com/peyoot/ccmp25_dt/blob/scarthgap/ccmp25-plc.dts ,编码器设备树的部分只是按早期官方文档的一个示例修改,需要进一步修改并验证其可用性。 官方文档可能有更新,LPTIM见:https://wiki.st.com/stm32mpu/wiki/LPTIM_device_tree_configuration#On_STM32MP2_series ,而 TIM DEVICE见https://wiki.st.com/stm32mpu/wiki/TIM_device_tree_configuration#On_STM32MP2_series

当前的设计,以counter_DI_1_2为例

&timers1 {
	status = "okay";

	/* USER CODE BEGIN timers1 */
	/delete-property/dmas;
	/delete-property/dma-names;
	/* USER CODE END timers1 */

	
	counter_DI_1_2  {                                          /* remove pwm10,pwm11 and add this */
		pinctrl-names = "default", "sleep";
		pinctrl-0 = <&ccmp25_timers1_ch3_4_pins>;
		pinctrl-1 = <&ccmp25_timers1_ch3_4_sleep_pins>;
		status = "okay";
    };
    
  
  和
  
 <code>
 ccmp25_timers1_ch3_4_pins: ccmp25-timers1-ch3_4 {
	pins {
		pinmux = <STM32_PINMUX('D',  9,  AF8)>, /* TIM1_CH3_PWM */
		 <STM32_PINMUX('D',  8,  AF8)>; /* TIM1_CH4_PWM */
		bias-disable;
	};
};
ccmp25_timers1_ch3_4_sleep_pins: ccmp25-timers1-ch3_4_sleep {
	pins {
		pinmux = <STM32_PINMUX('D',  9, ANALOG)>, /* TIM1_CH3_PWM */
		 <STM32_PINMUX('D',  8, ANALOG)>; /* TIM1_CH4_PWM */
	};
};
 </code>

注意,上面这个配置并未验证,在AI的协助下,需要的知识点包括:

timers1: timer@address {
    compatible = "st,stm32mp25-timers";
    /* ...其他公共资源... */
    
    pwm { compatible = "st,stm32mp25-pwm"; };   // PWM功能
    timer@0 { compatible = "st,stm32mp25-timer-trigger"; }; // 触发功能
    counter { compatible = "st,stm32mp25-timer-counter"; }; // 编码器/计数器功能
};
// counter子节点专门用于编码器/计数器功能,stm32mp25-timer-counter是STM32MP25系列的新绑定方式,而非以前的stm32-timer-encoder

下面,以这个编码器节点为例,可能需要的改变包括: 1、增加在counter内的compatible说明; 2、counter内增加一些描述

        // 编码器模式参数
        st,counter-mode = "encoder";    // 设置为编码器模式
        st,encoder-mode = <3>;          // 模式3:双通道边沿计数(四倍频)
        st,prescaler = <0>;             // 无预分频
        st,filter = <0>;                // 输入滤波器关闭

        // 通道映射(CH3和CH4)
        st,channel-config {
            ch3-mode = "input";  // CH3作为编码器输入A
            ch4-mode = "input";  // CH4作为编码器输入B
        st,counter-mode = "encoder";
        st,encoder-mode = <3>;
        st,prescaler = <0>;
        st,channel-config {
            ch3-mode = "input";
            ch4-mode = "input";