2014-10-23 02:03 PM
I wrote a
that shows how to blink LEDs on a STM8L-Discovery using free tools only. It consists of a few lines of C code to set up a timer, implement clock(), and use it to blink the green LED exactly once per second and the blue LED exactly once every two seconds. The C code is compiled using sdcc 3.4.0 or newer and put onto the board using the free stm8flash utility. Please tell me if you find anything wrong or missing in the tutorial. Philipp2014-10-25 01:35 AM
Maybe slightly off topic but I wonder why not to use the standard header from ST.
I'm not sure about STM8L but I use stm8s.h with sdcc and it's quite easy to patch. The only problem here is the INTERRUPT_HANDLER_TRAP macro. I think current sdcc version doesn't support it but that's not very important.--- save/stm8s_orig.h 2011-11-18 11:15:000000000 +0100
+++ stm8s.h 2014-10-24 19:03:975477306 +0200
@@ -75,6 +75,7 @@
#define _RAISONANCE_
#elif defined(__ICCSTM8__)
#define _IAR_
+#elif defined(__SDCC)
#else
#error ''Unsupported Compiler!'' /* Compiler defines not found */
#endif
@@ -128,6 +129,12 @@
/*!<
Used
with memory Models for code less than 64K */
#define MEMCPY memcpy
#endif /* STM8S208 or STM8S207 or STM8S007 or STM8AF62Ax or STM8AF52Ax */
+#elif defined (__SDCC)
+ #undef FAR
+ #undef NEAR
+ #undef TINY
+ #undef EEPROM
+ #define CONST const
#else /*_IAR_*/
#define FAR __far
#define NEAR __near
@@ -159,6 +166,8 @@
#define IN_RAM(a) a
#elif defined (_RAISONANCE_) /* __RCST7__ */
#define IN_RAM(a) a inram
+ #elif defined (__SDCC)
+ #undef IN_RAM(a)
#else /*_IAR_*/
#define IN_RAM(a) __ramfunc a
#endif /* _COSMIC_ */
@@ -2615,6 +2624,15 @@
#define trap() {_asm(''trap
'');} /* Trap (soft IT) */
#define wfi() {_asm(''wfi
'');} /* Wait For Interrupt */
#define halt() {_asm(''halt
'');} /* Halt */
+#elif defined(__SDCC)
+ #define enableInterrupts() {__asm__(''rim
'');} /* enable interrupts */
+ #define disableInterrupts() {__asm__(''sim
'');} /* disable interrupts */
+ #define rim() {__asm__(''rim
'');} /* enable interrupts */
+ #define sim() {__asm__(''sim
'');} /* disable interrupts */
+ #define nop() {__asm__(''nop
'');} /* No Operation */
+ #define trap() {__asm__(''trap
'');} /* Trap (soft IT) */
+ #define wfi() {__asm__(''wfi
'');} /* Wait For Interrupt */
+ #define halt() {__asm__(''halt
'');} /* Halt */
#else /*_IAR_*/
#include <intrinsics.h>
#define enableInterrupts() __enable_interrupt() /* enable interrupts */
@@ -2650,6 +2668,11 @@
__interrupt void (a) (void)
#endif /* _IAR_ */
+#ifdef __SDCC
+ #define INTERRUPT_HANDLER(a,b) void a(void) __interrupt (b)
+ #undef INTERRUPT_HANDLER_TRAP
+#endif
+
/*============================== Interrupt Handler declaration ========================*/
#ifdef _COSMIC_
#define INTERRUPT @far @interrupt
2014-10-25 11:07 AM
Three reasons
1) I wanted small self-contained examples depending only on standard features, and not on third-party libraries (and not on IDEs, etc). 2) The license situation with the library seems unclear. 3) AFAIR the library is buggy, at least wrt. UARTs; UARTs are important in the other tutorials I'm writing. Philipp2014-10-26 02:43 AM
1) I wanted small self-contained examples depending only on standard features, and not on third-party libraries (and not on IDEs, etc).
2) The license situation with the library seems unclear.
Yes, unfortunately. It's not clear if you can redistribute these headers.3) AFAIR the library is buggy, at least wrt. UARTs; UARTs are important in the other tutorials I'm writing.
You probably mean the ''standard driver'' part.I only use the header with registers definitions.
2014-11-01 11:04 PM
Hello,
I am using SDCC for STM8S-Discovery board and using code blocks editor
The compiler worked fine until i decided to try out interrupts Now i see a file stm8_interrupt_vector.c in the examples but INTERRUPT & INTERRUPT_HANDLER both creating problems for compilation. I read in some discussions for STM8(SDCC) that the IVT is implemented already. Now i am unable to figure out how to use the interrupt part for SDCC. Also i tried to use rim instruction in my program, and surprisingly the execution gets stuck there I used it as __asm;rim
__endasm; If anyone of you have experience in making interrupt work using SDCC with STM8, please share
Thanks in advance
Rajiv2014-11-02 01:17 AM
You can define the macro like this:
#define INTERRUPT_HANDLER(a,b) void a(void) __interrupt (b)
Or you can use sdcc specific declaration directly like this:void tim4(void) __interrupt(23)
{
TIM4->SR1 = ~TIM4_SR1_UIF;
if (g_t4cnt)
g_t4cnt--;
}
2014-11-02 07:43 AM
Thanks knik for your prompt reply
i have now defined my ISR as void EXTI_PORTB_IRQHandler() __interrupt (4)Now the compilation goes through and in the .asm file in the interrupt_vect: i see an entry int _EXTI_PORTB_IRQHandler ;int4 When i check the .rst file i find an entry 008018 82 00 81 1A 66 int _EXTI_PORTB_IRQHandler ;int4 which looks like the function is placed at the correct address according to the datasheet
But the interrupt is not getting called. I am sure it's some mistake from my side but unfortunately i am unable to figure it out yet. I will try again and keep you posted. In the meanwhile do you have any suggestions that i can try
2014-11-03 01:12 AM
Also i tried to use rim instruction in my program, and surprisingly the execution gets stuck there
I used it as
__asm;
rim
__endasm;
Have you solved this problem, interrupts are disabled by default so you need to enable it with RIM or WFI.If it gets stuck it can be that irq source is not cleared in isr and it gets called repeatedly and no chance returning to main.
2014-11-03 02:37 AM
Hello knik,
Thank you for your inputs. It's working now !!!! It seems the culprit is uart2 initialization If the uart2 init functions are present in the code the interrupt does not get called Otherwise the interrupt code works fine I will try to find what is the reason for this weird behavior and will keep you posted if i find any interesting observation Regards, Rajiv2017-03-18 12:12 PM
i went to your colecovision website. however, i have no idea what is going on.
i have STM8L which i want to play with ...
anybody still around to help me get from zero to blinky?