对于Nordic SDK的程序架构来说,引脚的NFC功能和Reset功能主要是在system_nrf52.c,跳转进main函数前执行SystemInit进行初始化的。代码如下
void SystemInit(void)
{....../* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined,two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available asnormal GPIOs. */#if defined (CONFIG_NFCT_PINS_AS_GPIOS)if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}NVIC_SystemReset();}#endif/* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is notdefined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then bereserved for PinReset and not available as normal GPIO. */#if defined (CONFIG_GPIO_AS_PINRESET)if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}NRF_UICR->PSELRESET[0] = 21;while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}NRF_UICR->PSELRESET[1] = 21;while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}NVIC_SystemReset();}#endifSystemCoreClockUpdate();
}
由代码可以看出,特色功能的IO配置通用的配置方法是需要在编译选项里的全局变量进行设置的,如下:
话外,有些朋友曾经遇到过调试APP部分是OK,IO正常运行,而烧录三合一程序的时候就失效了。这种情况需要核对一下BootLoader里是否做了同样的配置。否则一旦BootLoader配置了其他功能,跳转到APP就会配置失效,需要留意