27,374
社区成员
发帖
与我相关
我的任务
分享
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOE, &GPIO_InitStructure);
typedef struct
{
uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
This parameter can be any value of @ref GPIO_pins_define */
GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
This parameter can be a value of @ref GPIOSpeed_TypeDef */
GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
This parameter can be a value of @ref GPIOMode_TypeDef */
}GPIO_InitTypeDef;
GPIO_Pin这个变量是为了批量配置GPIO用的,比如说P1和P2有相同的速度和模式,就可以把GPIO_Pin的bit1和bit2置1,P1和P2就会在一次配置中完成。
可以说要配置一次GPIO口,就会定义一个GPIO_InitStructure变量,我再配置一次GPIO口变量就会再定义一个GPIO_InitStructure变量。
楼主说的这个保护是很难通过GPIO_Mode实现的。必须建立和STM32的GPIO口一一对应的数据结构才行。
楼主可以试试在主程序循环里调用这个,理论上不改变GPIO口配置情况只会打印一次。
void GPIO_protect(void)
{
static int preCRL = 0;
static int preCRH = 0;
GPIO_TypeDef* pGPIOx = GPIOC;
if(pGPIOx->CRL != preCRL)
{
preCRL = pGPIOx->CRL;
printf("GPIOx_CRL changed, %x -> %x\r\n", preCRL, pGPIOx->CRL);
}
if(pGPIOx->CRH != preCRH)
{
preCRH = pGPIOx->CRH;
printf("GPIOx_CRH changed, %x -> %x\r\n", preCRH, pGPIOx->CRH);
}
}