************************************************void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState){uint32_t tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;/* Check the parameters */assert_param(IS_GPIO_REMAP(GPIO_Remap));assert_param(IS_FUNCTIONAL_STATE(NewState)); tmpreg = AFIO->MAPR;tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;tmp = GPIO_Remap & LSB_MASK;if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)){tmpreg &= DBGAFR_SWJCFG_MASK;AFIO->MAPR &= DBGAFR_SWJCFG_MASK; }else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK){tmp1 = ((uint32_t)0x03) << tmpmask;tmpreg &= ~tmp1;tmpreg |= ~DBGAFR_SWJCFG_MASK;}else{tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10));tmpreg |= ~DBGAFR_SWJCFG_MASK;}if (NewState != DISABLE){tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10));}AFIO->MAPR = tmpreg;}
1 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
这函数实际是完成AFIO->MAPR寄存器的配置,我就是嫌这代码写的太烦了,所以直接对寄存器进行操作。比如将串口2重映射时,就是:
AFIO->MAPR|=GPIO_Remap_USART2;
要取消重映射,就是:
AFIO->MAPR&=~GPIO_Remap_USART2;
GPIO_Remap_USART2在stm32f10x_GPIO.h中是有定义的,AFIO->MAPR寄存器各个位的定义在参考手册中有详细描述。
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报
0/150
提交
取消