TIM外设是一个多通道定时器单元,根据使用的需要,可以在各种配置中使用。有三种分类:高级控制计时器、通用计时器和基本计时器。
特性:

  • TIM1和TIM8是高级控制定时器,具有6个独立通道。

  • TIM2,TIM3,TIM4和TIM5是具有4个独立通道的通用定时器。

  • TIM12,TIM13和TIM14是通用定时器,具有2个(TIM12)或1个(TIM13和TIM14)独立通道。

  • TIM15,TIM16和TIM17也是通用定时器,具有2个(TIM15)或1个(TIM16和TIM17)独立通道。 与TIM12,TIM13和TIM14相比,此配置带来了一些对电机控制非常有用的功能(例如中断功能,DMA突发模式控制,具有死区时间插入的互补输出等)

  • TIM6和TIM7是基本计时器

 

TIM12和/或TIM15可分配给:

  • 可以在secure monitor(TF-A或OP-TEE)中控制Arm Cortex-A7安全核心,以在RCC中执行HSI和CSI校准。

可以将所有TIM控制器分配给:

  • 可以通过PWM或IIO框架在Linux中

或者

  • TIM HAL驱动程序可在STM32Cube MPU封装中控制Arm®Cortex®-M4

 

外设分配

 

DomainPeripheralRuntime allocationComment   
InstanceCortex-A7
secure
(OP-TEE)
Cortex-A7
non-secure
(Linux)
Cortex-M4
(STM32Cube)
   
Core/TimersTIMTIM1 (APB2 group)Assignment (single choice)
TIM2 (APB1 group)Assignment (single choice)  
TIM3 (APB1 group)Assignment (single choice)  
TIM4 (APB1 group)Assignment (single choice)  
TIM5 (APB1 group)Assignment (single choice)  
TIM6 (APB1 group)Assignment (single choice)  
TIM7 (APB1 group)Assignment (single choice)  
TIM8 (APB2 group)Assignment (single choice)  
TIM12 (APB1 group)Assignment (single choice)  
TIM13 (APB1 group)Assignment (single choice)  
TIM14 (APB1 group)Assignment (single choice)  
TIM15 (APB2 group)Assignment (single choice)  
TIM16 (APB2 group)Assignment (single choice)  
TIM17 (APB2 group)Assignment (single choice)  

 

FunctionPin NameAlternative Function
TIM3_CH2PB5AF2
TIM1_CH1NPB13AF2
TIM8_CH1NPH13AF3
TIM8_BKIN2PI1AF3
TIM8_ETRPI3AF3
TIM5_CH4PI0AF2
TIM8_CH4PI2AF3
TIM17_BKINPB5AF1
LPTIM2_OUTPB13AF4

 

CA7配置Capture功能

/* select TIM1_CH1 alternate function 1 on 'PE9' */
pwm1_in_pins_a: pwm1-in-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, AF1)>;
		bias-disable;
	};
};

/* configure 'PE9' as analog input in low-power mode */
pwm1_in_sleep_pins_a: pwm1-in-sleep-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, ANALOG)>;
	};
};

&timers1 {
	status = "okay";
	/* Enable DMA "ch1" for PWM input on TIM1_CH1 */
	dmas = <&dmamux1 11 0x400 0x5>;
	dma-names = "ch1";
	pwm {
		/* configure PWM input pins, e.g. TIM1_CH1 */
		pinctrl-0 = <&pwm1_in_pins_a>;
		pinctrl-1 = <&pwm1_in_sleep_pins_a>;
		pinctrl-names = "default", "sleep";
		/* enable PWM on TIM1 */
		status = "okay";
	};
};

CM4使用TIM功能

&timers1 {
		status = "disabled";
};

&m4_timers1 {
		pinctrl-names = "rproc_default";
		pinctrl-0 = <&timer1_pins>;
		status = "okay";
};

PWM输出功能

&pinctrl {	

	pwm5_pins_b: pwm5-0 {
		pins {
			pinmux = <STM32_PINMUX('I', 0, AF2)>; /* TIM5_CH4 */
			bias-pull-down;
			drive-push-pull;
			slew-rate = <0>;
		};
	};

	pwm5_sleep_pins_b: pwm5-sleep-0 {
		pins {
			pinmux = <STM32_PINMUX('I', 0, ANALOG)>; /* TIM5_CH4 */
		};
	};
};
&timers5 {
	status = "okay";
	/* spare all DMA channels since they are not needed for PWM output */
	/delete-property/dmas;
	/delete-property/dma-names;
	/* define pwm1 label */
	pwm {
		/* configure PWM pins on TIM1_CH1 */
		pinctrl-0 = <&pwm5_pins_b>;
		pinctrl-1 = <&pwm5_sleep_pins_b>;
		pinctrl-names = "default", "sleep";
		/* enable PWM on TIM1 */
		status = "okay";
	};
};
作者:SteveChen  创建时间:2024-09-18 14:45
最后编辑:SteveChen  更新时间:2024-09-18 14:46
上一篇:
下一篇: