Search This Blog

Monday, July 30, 2018

STM8 - Alternative IRQ Vectors declaration

 Projects / Misc 8-bit uC projects  Original post date: 02/11/2017

Using IRQ handlers in Cosmic C under STVD (ST Visual Develop) requires modifying ST's copyrighted source code which has its share of maintenance and licensing issues.

"stm8_interrupt_vector.c" is under "STMicroelectronics\st_toolset\stvd\builder" which is copied into a new STVP project. I have decided to replace it with my own "stm8_interrupt_vector.c" as follows. No additional editing is needed as all the changes are contained in the "irq.h" file.


#include "irq.h"
#include "stm8_interrupt_vector.h"

typedef struct
{
  unsigned char irq;
  void @far (*irq_handler)(void);
} irq_vectors;

extern void _stext();
@far @interrupt void Default_IRQ_Handler(void)
{
}

const irq_vectors _vectab[] =
{
  {0x82,(void @far (*)(void))_stext}, /* reset */
  {0x82,TRAP},   // trap
  {0x82,IRQ0},   // irq0
//: IRQ1-IRQ28 omitted in the code snippet
  {0x82,IRQ29},  // irq29
};

File: "irq.h" is where the vectors are customized with individual "#define" statements. This makes it easier keep track of the user IRQ handlers.


#define IRQ12 TIM1_Capture
@far @interrupt void TIM1_Capture(void);

The IRQ handler is declared some where else in the source code.


INTERRUPT void TIM1_Capture(void)
{
 // IRQ handler code ...
}

File "stm8_interrupt_vector.h" would then point the remaining undefined IRQs to Default_IRQ_Handler() thanks to the conditional statements. Alternatively, this file can be incorporated into "stm8_interrupt_vector.c"


#ifndef TRAP
#define TRAP Default_IRQ_Handler
#endif

#ifndef IRQ0
#define IRQ0 Default_IRQ_Handler
#endif

//: IRQ1-IRQ28 omitted in the code snippet

#ifndef IRQ29
#define IRQ29 Default_IRQ_Handler
#endif

Here is how it looks at the assembly level:


FYI: The code is generated from Excel and copy/pasted into an editor.


Files are on my github.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.