论坛元老
- 积分
- 3293
- 金钱
- 3293
- 注册时间
- 2016-1-7
- 在线时间
- 541 小时
|
10金钱
本帖最后由 challenger 于 2024-2-20 14:40 编辑
STM32F0换成STM32G0芯片后,配制PB3外部中断线,发现EXTI2_3_IRQHandler不工作,这是什么鬼?
void init_PB3_pin(void)
{
#if 0 //STM32F0
/* 1 - Enable the peripheral clock of GPIOB */
//RCC->AHBENR |= (1 << 18);
/* 2 - Select input mode (00) on PB3, reset is input mode */
/* 3 - Pull-up/Pull-down resistor configuration */
//GPIOB->PUPDR |= (1 << 6);
#else ////STM32g0
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOB_CLK_ENABLE();
#if 0
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = 0;//0
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI2_3_IRQn, 3, 1);
HAL_NVIC_EnableIRQ(EXTI2_3_IRQn);
#else
/*Configure GPIO pin : PB3 */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif
#endif
}
//下面这个STM32G0外部中断线配制不工作,程序如下:
void config_exti_line3_to_zerox(unsigned char enable_disable)
{
init_PB3_pin();
///////////////////////////////////////////////////
/* Enable SYSCFG clock */
#if 0 //STM32F0 配制
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
#else //STM32G0配制
// RCC->APBENR2 |= RCC_APBENR2_SYSCFGEN;
__HAL_RCC_SYSCFG_CLK_ENABLE();
#endif
/* Connect EXTI3 Line to PB3 pin */
uint32_t tmp = 0x00;
#if 0 //STM32F0 配制
tmp = ((uint32_t)0x0F) << (0x04 * (((uint8_t)0x03) & (uint8_t)0x03));
SYSCFG->EXTICR[((uint8_t)0x03) >> 0x02] &= ~tmp;
SYSCFG->EXTICR[((uint8_t)0x03) >> 0x02] |= (((uint32_t)((uint8_t)0x01)) << (0x04 * (((uint8_t)0x03) & (uint8_t)0x03)));
#else //STM32G0配制
tmp = ((uint32_t)0x0F) << (0x08 * (((uint8_t)0x03) & (uint8_t)0x03));
EXTI->EXTICR[((uint8_t)0x03) >> 0x02] &= ~tmp;
EXTI->EXTICR[((uint8_t)0x03) >> 0x02] |= (((uint32_t)((uint8_t)0x01)) << (0x08 * (((uint8_t)0x03) & (uint8_t)0x03)));
#endif
/* Configure EXTI3 line */
tmp = (uint32_t)EXTI_BASE;
if(enable_disable == ENABLE)
{
/* Clear EXTI line configuration */
#if 0 //STM32F0 配制
EXTI->IMR &= ~((uint32_t)0x00000008);
EXTI->EMR &= ~((uint32_t)0x00000008);
#else //STM32G0 配制
EXTI->IMR1 &= ~((uint32_t)0x00000008);
EXTI->EMR1 &= ~((uint32_t)0x00000008);
#endif
tmp += 0x00;
*(__IO uint32_t *) tmp |= ((uint32_t)0x00000008);
/* Clear Rising Falling edge configuration */
#if 0 //STM32F0 配制
EXTI->RTSR &= ~((uint32_t)0x00000008);
EXTI->FTSR &= ~((uint32_t)0x00000008);
#else //STM32g0 配制
EXTI->RTSR1 &= ~((uint32_t)0x00000008);
EXTI->FTSR1 &= ~((uint32_t)0x00000008);
#endif
/* Select the trigger for the selected interrupts */
tmp = (uint32_t)EXTI_BASE;
/* falling edge set */
tmp += 0x0C;
*(__IO uint32_t *) tmp |= ((uint32_t)0x00000008);
}
else
{
tmp += 0x00;
/* Disable the selected external lines */
*(__IO uint32_t *) tmp &= ~((uint32_t)0x00000008);
}
/* Configure NVIC for External Interrupt */
/* Enable Interrupt on EXTI2_3 */
NVIC_EnableIRQ(EXTI2_3_IRQn);
/* Set priority for EXTI2_3 */
NVIC_SetPriority(EXTI2_3_IRQn,0);
}
void EXTI2_3_IRQHandler(void)
{
#if 0 //STM32F0
if((EXTI->pR & ((uint32_t)0x00000008)) != 0) /* Check line 3 has triggered the IT */
{
printf("EXTI2_3_IRQHandler:pR=%d\r\n",(EXTI->pR & ((uint32_t)0x00000008)));
......................
/* Clear the EXTI line 3 pending bit */
EXTI->pR = ((uint32_t)0x00000008);
}
#else //stm32g0
if((EXTI->FPR1 & ((uint32_t)0x00000008)) != 0) /* Check line 3 has triggered the IT */
{
printf("EXTI2_3_IRQHandler:FPR1=%d\r\n",(EXTI->FPR1 & ((uint32_t)0x00000008)));
......................
EXTI->FPR1 = ((uint32_t)0x00000008);
}
}
以上程序在STM32F0基础上,改为STM32G0后,发现EXTI2_3_IRQHandler不工作,找了半天,没找出问题。有哪位大虾,玩过STM32G0系列的,程序哪里配制有问题?
|
|