cancel
Showing results for 
Search instead for 
Did you mean: 

I want to understand that how Interrupt works in stm32f103c8t6(Blue pill).

Vivek yadav1
Associate III

I Did few things.

1: I used CubeMx to generate code with keil IDE

2: I made PC13 as Output to Toggle LED.

3: I made PA1 as Interrupt Pin(Button).

4: I called interrupt handler in main file under MX_GPIO_Init() function.

  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI1_IRQn);
  HAL_GPIO_EXTI_IRQHandler(Button_Pin); // by me

5: when i went to the defination of HAL_GPIO_EXIT_IRQHandler() function.

i found call back function there and in that function i set my flag to ONE.

and I am using this flag into my while loop for LED blinking.

extern uint8_t Interrupt_Flag;
extern void LED(void);
extern uint8_t Interrupt_Flag;
 
/**
  * @brief  This function handles EXTI interrupt request.
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
  /* EXTI line interrupt detected */
  if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
  {
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
  }
}
 
/**
  * @brief  EXTI line detection callbacks.
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
 
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  /* Prevent unused argument(s) compilation warning */
 
  UNUSED(GPIO_Pin);
 
  /* NOTE: This function Should not be modified, when the callback is needed,
           the HAL_GPIO_EXTI_Callback could be implemented in the user file
   */	
	Interrupt_Flag = 1;
}

After Doing all this I am expecting that when i give PA1 high my LED should be ON and at LOW it should be OFF.

But i am not getting output as i mention. I don't know where am i wrong.

So need your help. I tried on google but couldn't find any good example. which suits my need.

3 REPLIES 3

You did not tell us which STM32 are you using, but generally there are EXTI examples for probably all platforms in their respective Cube, e.g. [STM32Cube_FW_F4_V1.21.0]\Projects\STM32F4-Discovery\Examples\GPIO\GPIO_EXTI\

JW

STM32F013C8T6 Blue pill

Danish1
Lead II

When you use things like HAL, Cube (and, truth be told, high-level languages like C and C++ but let's not go there) you are adding layers that hide the underlying steps and mechanisms. This is great to get some (easy) things up and running, as well as porting from one processor to another. But another thing it does is separates the programmer from definitive documentation. All you get are examples that (largely) work but without the explanation as to why things are done in that specific way.

stm32 are complex devices, consisting of an Arm-designed Cortex processor core, some Arm-designed core peripherals and other ST-designed peripherals.

If you actually want to understand how things work so you can use them to best effect, then you could look at the official documentation. But there is a huge amount of information - too much to take in easily. There are books that try to make things easier e.g. "The Designer's Guide to the Cortex-M Processor Family"

The "definitive" documentation is spread over several documents:

  1. Data sheet - what is on your chip, and how it should perform (e.g. allowable speeds, current consumption) e.g. https://my.st.com/resource/en/datasheet/stm32f103c8.pdf
  2. Reference Manual - describes the ST-designed peripheral and how things go together e.g. https://my.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/CD00171190.pdf/jcr:content/translations/en.CD00171190.pdf
  3. Programming Manual - describes the Arm core and Arm-designed peripherals e.g. https://my.st.com/content/ccc/resource/technical/document/programming_manual/5b/ca/8d/83/56/7f/40/08/CD00228163.pdf/files/CD00228163.pdf/jcr:content/translations/en.CD00228163.pdf

When I was learning, I only knew about the Data Sheet and Reference Manual. And it was only some time later that I discovered the Programming Manual - where the Nested Vectored Interrupt Controller was described. Until I had seen that I did not know how interrupts worked.

Hope this helps,

Danish