#define TIM2_CLK_ENABLE() ( RCC->APB1ENR |= RCC_APB1ENR_TIM2EN )
#define TIM3_CLK_ENABLE() ( RCC->APB1ENR |= RCC_APB1ENR_TIM3EN )
#define TIMx_CHANNEL_GPIOA_PORT() ( RCC->IOPENR |= (RCC_IOPENR_GPIOAEN))
#define TIMx_CHANNEL_GPIOB_PORT() ( RCC->IOPENR |= (RCC_IOPENR_GPIOBEN))
arm_drv_tim_pwm_channel_config (TIM2_BASE, GPIO_A, GPIO_A_15, GPIO_AF5_TIM2, TIM_CHANNEL_1);
short drv_io_config_pin( unsigned long pin, unsigned char config )
{
unsigned short port, index, bits;
GPIO_TypeDef* GPIO_Init_PORT;
GPIO_InitTypeDef GPIO_InitStruct;
port = (unsigned short)(pin >> 16); // port index for PORT A-H (0-4)
if(port > (MAXIMUM_GPIO_PORT-1)) // only has 5 ports: PORT_[A~H]
return 1;
GPIO_Init_PORT = GPIO_PORT[port];
GPIO_InitStruct.Pin = 0;
bits = 0x8000; // start from bit 15.
// prepare configure register
for( index = 0; index < 16; index++ )
{
if( pin & bits )
{
// the bit is selected.
GPIO_InitStruct.Pin = bits;
// config format: 0011,0001.pupd[7:6]=00=no pull-up, pull-down; ospeed[5:4]=11=high speed; otype[2]=0=push-pull; mode[1:0]=01=output.
GPIO_InitStruct.Mode = (GPIOMode_TypeDef) (config & 0x03); // GPIO_Mode;
GPIO_InitStruct.OType = (GPIOO
定时器TIM2输出pwm波
最新推荐文章于 2023-09-05 13:59:51 发布