Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWU_IRQHandler not working for STM8S #164

Open
wmarkow opened this issue Jul 8, 2024 · 2 comments
Open

AWU_IRQHandler not working for STM8S #164

wmarkow opened this issue Jul 8, 2024 · 2 comments

Comments

@wmarkow
Copy link

wmarkow commented Jul 8, 2024

I wanted to use the active halt power save mode together with AWU unit to wake up.
Basically the concept of AWU works but the processor gets restarted every time the AWU interrupt occur. Expected behavior is that the procesdor should continue its execution from the place where HALT instruction has been called.

Root cause: it is not possible to correctly set the AWU_IRQHandler to some specific method. This code doesn't work:

INTERRUPT_HANDLER(AWU_IRQHandler, 1)
{
    AWU->CSR &= (uint8_t)(~AWU_CSR_AWUF);
}

because the AWU_IRQHandler is commented out in the stm8s_it.h file:

// SDCC patch: __interrupt keyword required after function name --> requires new block
#elif defined (_SDCC_)

// INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler);                 /* TRAP */
// INTERRUPT_HANDLER(TLI_IRQHandler, 0);                    /* TLI */
// INTERRUPT_HANDLER(AWU_IRQHandler, 1);                    /* AWU */
// INTERRUPT_HANDLER(CLK_IRQHandler, 2);                    /* CLOCK */
 INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3);             /* EXTI PORTA */
 INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4);             /* EXTI PORTB */
 INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5);             /* EXTI PORTC */
 INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6);             /* EXTI PORTD */
 INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7);             /* EXTI PORTE */

In this way the AWU_IRQHandler is set to zero and the processor gets restarted on this interrupt.

When I modify the file and uncomment the line

INTERRUPT_HANDLER(AWU_IRQHandler, 1);                    /* AWU */

then everything works fine. Is there any particular reason why the interrupt handler is commented out?

wmarkow added a commit to wmarkow/arduino-sandbox that referenced this issue Jul 10, 2024
…duino STM8 Framework.

tenbaht/sduino#164  AWU_IRQHandler not working for STM8S

We will use Platformio scripting to apply patched cores/arduino/stm8s_it.h file.
wmarkow added a commit to wmarkow/arduino-sandbox that referenced this issue Jul 10, 2024
@g1ra
Copy link

g1ra commented Dec 19, 2024

Hi @wmarkow I'm working on same to use STM8S103F3P6 halt for ultra low power consumption . Can you please share your working code how did you implement attaching interrupt to pin , etc ?

@wmarkow
Copy link
Author

wmarkow commented Dec 19, 2024

Hi @g1ra , my code is available here:
https://github.com/wmarkow/arduino-sandbox/blob/master/fox-hunting-stm8/examples/FoxTransmitter/FoxTransmitter.c
just look at the end of the file where AWU interrupt routine is implemented (together with sleep method),
but I'm using there a time wake up, so the uC goes to sleep and is woken up (after amount of time) automatically by AWU.

To make it happen I needed to patch the STM8 Arduino core, see this file:
https://github.com/wmarkow/arduino-sandbox/blob/master/fox-hunting-stm8/patches-fw/cores/sduino/stm8s_it.h
and look for the patch between phrases // PATCH wmarkow 'AWU_IRQHandler not working'. It is possible that it (the patch) could be done nicer as now all my example sketches need to define the AWU interrupt routine, even if it is not needed.
I'm using PlatformIO and the patch is copied automatically to the STM8 core distribution at every build.

wmarkow added a commit to SP3WAM/hc12-fox that referenced this issue Dec 31, 2024
…duino STM8 Framework.

tenbaht/sduino#164  AWU_IRQHandler not working for STM8S

We will use Platformio scripting to apply patched cores/arduino/stm8s_it.h file.
wmarkow added a commit to SP3WAM/hc12-fox that referenced this issue Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants