代码如下:还有一些宏定义,请问该怎么解决?

************************************************

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;
}

梦里花落0921
浏览 91回答 1
1回答

饮歌长啸

这函数实际是完成AFIO->MAPR寄存器的配置,我就是嫌这代码写的太烦了,所以直接对寄存器进行操作。比如将串口2重映射时,就是:AFIO->MAPR|=GPIO_Remap_USART2;要取消重映射,就是:AFIO->MAPR&=~GPIO_Remap_USART2;GPIO_Remap_USART2在stm32f10x_GPIO.h中是有定义的,AFIO->MAPR寄存器各个位的定义在参考手册中有详细描述。
打开App,查看更多内容
随时随地看视频慕课网APP