This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to write interrupts function for STM32f103 in Keil

Hi. I want use uC like STM32f103C8.. and Keil MDKARM and i want to write SysTick Hendler.

Should i use some __irq  specifier in hendler function? or maybe this hendler can be write like common c function for example void SysTick_Handler(void)  {}?

I think (hardly remember) that this specifier was needed, or not?

Parents
  • It can be written as a common C function.  There is no special qualifier is needed for cortex-M processors. (like the STM32f103C8)

    A function called "void SysTick_Handler(void);" should do the trick. This is the "standard" name for the function.  

    your startup file you are using needs to needs to reference this function in the startup vector table.  This is normally done for you.

    Vector_Table[15] should have the address of the SysTick_Handler function.

    Normally the startup file will define a handler to be called for SysTick_Handler IF the linker does not find a global one in your application code.

    void SysTick_Handler ( void ) __attribute__ ((weak, alias("Default_Handler")));

    this says if you do not find a definition for SysTick_Handler somewhere else, use Default_Handler function in its place.

    // Maybe in main.c as an example
    
    uint64_t SysTickCount = 0;
    
    void SysTick_handler(void)
    {
        SysTickCount++;
        // Do something else if you like
    }
    
    main()
    {
        // configure the System Tick to fire every millisecond
        // SystemClockFrequency is the speed your MPU is running
        // This will enabled the SysTick AND set the priority to
        // the lowest level base on the number of PRIO bits
        
        SysTick_Config( SystemClockFrequency / 1000);
        
        // At this point your SysTick_Handler should be called every 1 ms
        
        while (1);
    }
    
    
    

Reply
  • It can be written as a common C function.  There is no special qualifier is needed for cortex-M processors. (like the STM32f103C8)

    A function called "void SysTick_Handler(void);" should do the trick. This is the "standard" name for the function.  

    your startup file you are using needs to needs to reference this function in the startup vector table.  This is normally done for you.

    Vector_Table[15] should have the address of the SysTick_Handler function.

    Normally the startup file will define a handler to be called for SysTick_Handler IF the linker does not find a global one in your application code.

    void SysTick_Handler ( void ) __attribute__ ((weak, alias("Default_Handler")));

    this says if you do not find a definition for SysTick_Handler somewhere else, use Default_Handler function in its place.

    // Maybe in main.c as an example
    
    uint64_t SysTickCount = 0;
    
    void SysTick_handler(void)
    {
        SysTickCount++;
        // Do something else if you like
    }
    
    main()
    {
        // configure the System Tick to fire every millisecond
        // SystemClockFrequency is the speed your MPU is running
        // This will enabled the SysTick AND set the priority to
        // the lowest level base on the number of PRIO bits
        
        SysTick_Config( SystemClockFrequency / 1000);
        
        // At this point your SysTick_Handler should be called every 1 ms
        
        while (1);
    }
    
    
    

Children
No data