目录
- 引脚有哪些功能
- 如何选择功能
- 代码
引脚有哪些功能
数据手册中,每一个引脚功能有至多64个,对应列Func0~Func63
其中,Func0 ~Func31在《表 2-1 引脚功能表》中列出
Func32~Func63在《表 2-2 Func32~63 表》中列出。
Func32~Func63中的功能分为两组Func_Grp1,Func_Grp2
引脚可以任意选择组内的任意一个功能
如何选择功能
- PFSRxy->FSEL[5:0]:功能选择
- PFSRxy->BFE[5:0]:副功能许可
- PCCR->BFSEL[3:0]:副功能选择
如果需要将一个端口同时设成两种功能,才要使能副功能。一般不使用设置为Disable即可。
副功能选择只有4个位域,只能选择到Func0~Func31
代码
/*********************************************************************************** \brief Set Port Pin function**** \param [in] enPort GPIO port index, This parameter can be** any value of @ref en_port_t** \param [in] u16Pin GPIO pin index, This parameter can be** any value of @ref en_pin_t** \param [in] enFuncSel Function selection, This parameter can be** any value of @ref en_port_func_t**** \param [in] enSubFunc The new state of the gpio sub-function.** \arg Enable Enable.** \arg Disable Disable.**** \retval Ok Set successful to corresponding pins********************************************************************************/
en_result_t PORT_SetFunc(en_port_t enPort, uint16_t u16Pin, en_port_func_t enFuncSel, \en_functional_state_t enSubFunc)
{stc_port_pfsr_field_t *PFSRx;uint8_t u8PinPos = 0u;/* parameter check */DDL_ASSERT(IS_VALID_PORT(enPort));DDL_ASSERT(IS_VALID_FUNC(enFuncSel));DDL_ASSERT(IS_FUNCTIONAL_STATE(enSubFunc));PORT_Unlock();for (u8PinPos = 0u; u8PinPos < 16u; u8PinPos ++){if (u16Pin & (uint16_t)(1ul<<u8PinPos)){PFSRx = (stc_port_pfsr_field_t *)((uint32_t)(&M4_PORT->PFSRA0) \+ 0x40ul * enPort + 0x4ul * u8PinPos);/* main function setting */PFSRx->FSEL = enFuncSel;/* sub function enable setting */PFSRx->BFE = (Enable == enSubFunc ? Enable : Disable);}}PORT_Lock();return Ok;
}