[技术问答] HK32F030MF4P6 SWCLK配置为EXTI问题

[复制链接]
3533|4
 楼主| 明翰的帅爸爸 发表于 2021-8-24 15:37 | 显示全部楼层 |阅读模式
TI, pi, IO, ni, GPIO, gp
配置成GPIO输入是可以的,可以正常检测高低电平输入
但是配置EXTI,不能进入中断
求各位老哥帮忙看看

  1. void Hw_Key_Init(void)
  2. {
  3.     GPIO_InitTypeDef GPIO_InitStructure;
  4.     EXTI_InitTypeDef EXTI_InitStructure;
  5.     NVIC_InitTypeDef NVIC_InitStructure;
  6.    
  7.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX, ENABLE);
  8.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);  //使能GPIOB时钟
  9.    
  10.     //SWCLK PB5 as GPIO
  11.     //GPIO_IOMUX_ChangePin(IOMUX_PIN11, IOMUX_PB5_SEL_PB5); //TSSOP20PIN11(PD5)PB5 IO
  12.    
  13.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  14.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
  15.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
  16.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
  17.     GPIO_Init(GPIOB, &GPIO_InitStructure);
  18.    
  19.     /* 配置EXTI */
  20.    
  21.     EXTI_InitStructure.EXTI_Line = EXTI_Line5;
  22.     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  23.     EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  24.     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  25.     EXTI_Init(&EXTI_InitStructure);
  26.    
  27.     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);
  28.         EXTI_ClearITPendingBit(EXTI_Line5);
  29.    
  30.     NVIC_InitStructure.NVIC_IRQChannel = EXTI5_IRQn;
  31.     NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  32.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  33.     NVIC_Init(&NVIC_InitStructure);
  34.    
  35. }

  36. void EXTI5_IRQHandler(void)
  37. {
  38.    
  39.    
  40.     if(EXTI_GetFlagStatus(EXTI_Line5) != RESET)
  41.     {
  42.         //开机
  43.         if(0 == g_key_power_flag)
  44.         {
  45.             Hw_Pwm_Ch3_Enable();
  46.             Hw_Pwm_Ch4_Enable();
  47.             g_key_power_flag = 1;
  48.             
  49.             Hw_Led4_On();
  50.         }
  51.         else
  52.         {
  53.             Hw_Pwm_Ch3_Disable();
  54.             Hw_Pwm_Ch4_Disable();
  55.             g_key_power_flag = 0;
  56.             
  57.             Hw_Led4_Off();
  58.         }

  59.         
  60.         EXTI_ClearITPendingBit(EXTI_Line5);
  61.     }
  62. }
 楼主| 明翰的帅爸爸 发表于 2021-8-24 15:39 | 显示全部楼层
补上一段代码
  1.     GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
  2.     GPIOMUX->PKG_PIN_SEL &= (uint32_t)(0xFFFFFF00);  //NRSTPA0_PIN_SEL = 0
  3.     GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
  4.     GPIOMUX->NRST_PA0_SEL |= (uint32_t)(0x00000007); //bit0:NRST 1 PA0  bit1-2:SWCLK 11 PB5  bit5-6:SWDIO 00 PD5
 楼主| 明翰的帅爸爸 发表于 2021-8-26 16:48 | 显示全部楼层
已经破案了
仔细对照其他的EXTI官方例程,发现加上这个就OK了
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
HK32和STM32还是有一些细节不一样的
楼下贴出代码,希望能帮助其他人
 楼主| 明翰的帅爸爸 发表于 2021-8-26 16:49 | 显示全部楼层
  1. void Hw_Input_Chage_Init(void)
  2. {
  3.     GPIO_InitTypeDef GPIO_InitStructure;
  4.    
  5.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  6.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX, ENABLE);
  7.    
  8.     GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
  9.     GPIOMUX->PKG_PIN_SEL &= (uint32_t)(0xFFFFFF00);  //NRSTPA0_PIN_SEL = 0
  10.     GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
  11.     GPIOMUX->NRST_PA0_SEL |= (uint32_t)(0x00000007); //bit0:NRST 1 PA0  bit1-2:SWCLK 11 PB5  bit5-6:SWDIO 00 PD5
  12.    
  13.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  14.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
  15.    
  16.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
  17.     GPIO_InitStructure.GPIO_Schmit = GPIO_Schmit_Disable;
  18.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
  19.    
  20.     //NRST --> PA0
  21.     //GPIO_IOMUX_ChangePin(IOMUX_PIN2, IOMUX_NRST_SEL_NRST);// TSSOP16 PIN2(NRST)PA0 IO  IOMUX_NRST_SEL_NRST   IOMUX_NRST_SEL_PA0
  22.    
  23.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  24. }

  25. void Hw_Key_Init(void)
  26. {
  27.     GPIO_InitTypeDef GPIO_InitStructure;
  28.     EXTI_InitTypeDef EXTI_InitStructure;
  29.     NVIC_InitTypeDef NVIC_InitStructure;
  30.    
  31.    
  32.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  33.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  34.    
  35.     //SWCLK PB5 as GPIO
  36.     //GPIO_IOMUX_ChangePin(IOMUX_PIN11, IOMUX_PB5_SEL_PB5); //TSSOP20PIN11(PD5)PB5 IO
  37.    
  38.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  39.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
  40.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
  41.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
  42.     GPIO_Init(GPIOB, &GPIO_InitStructure);
  43.    
  44.     /* 配置EXTI */
  45.    
  46.     EXTI_InitStructure.EXTI_Line = EXTI_Line5;
  47.     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  48.     EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  49.     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  50.     EXTI_Init(&EXTI_InitStructure);
  51.    
  52.     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);
  53.         EXTI_ClearITPendingBit(EXTI_Line5);
  54.    
  55.     NVIC_InitStructure.NVIC_IRQChannel = EXTI5_IRQn;
  56.     NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  57.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  58.     NVIC_Init(&NVIC_InitStructure);
  59.    
  60. }

  61. //SWCLK
  62. unsigned char Hw_Key_Get_Power_Key_Value(void)
  63. {
  64.     return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5);
  65. }


  66. unsigned char g_temp = 0;

  67. void EXTI5_IRQHandler(void)
  68. {
  69.     if(EXTI_GetFlagStatus(EXTI_Line5) != RESET)
  70.     {
  71.         g_temp = !g_temp;
  72.         
  73.         if(g_temp)
  74.             Hw_Led_Green_Enable();
  75.         else   
  76.             Hw_Led_Green_Disable();
  77.         
  78.         EXTI_ClearITPendingBit(EXTI_Line5);
  79.     }
  80. }
单片小菜 发表于 2021-8-27 11:13 | 显示全部楼层
这个确实已经**了,很棒的代码。不错的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

7

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部