how to raise a keyboard exception

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
cyrille07
Posts: 3
Joined: Fri Jan 17, 2020 6:58 am

how to raise a keyboard exception

Post by cyrille07 » Wed Apr 21, 2021 7:38 am

Hello,

I am porting micropython to some HW...

How do I raise a kbd exception when the use presses on the "stop" key?

I know that I need to enable MICROPY_KBD_EXCEPTION, but I am missing the last part of the link to actually generate the exception.

Thanks,
Cyrille

User avatar
Roberthh
Posts: 2643
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: how to raise a keyboard exception

Post by Roberthh » Wed Apr 21, 2021 8:39 am

In you C code, call:

mp_keyboard_interrupt();

cyrille07
Posts: 3
Joined: Fri Jan 17, 2020 6:58 am

Re: how to raise a keyboard exception

Post by cyrille07 » Wed Apr 21, 2021 9:29 am

Hello,

I tried it, but unfortunately, it seems that mp_keyboard_interrupt is not defined anywhere...

enabeling
#define MICROPY_KBD_EXCEPTION (1)

and adding a call to mp_keyboard_interrupt

Generates 2 link errors:

3>skin.obj : error LNK2001: unresolved external symbol _mp_keyboard_interrupt
3>modmicropython.obj : error LNK2019: unresolved external symbol _mp_hal_set_interrupt_char referenced in function _mp_pystack_usage
3>P:\trv\fir_trunk\FIR\_qt5\Debug\Win32\\HPPrime.exe : fatal error LNK1120: 2 unresolved externals

Any clue as to what might be wrong?


EDIT:
looking on the net, I found an implementation for mp_keyboard_interrupt:
void mp_keyboard_interrupt()
{
MP_STATE_VM(mp_pending_exception) = (MP_STATE_PORT(mp_kbd_exception));
}

Unfortunately, that did not compile...
Hard casting like this did...
void mp_keyboard_interrupt()
{
MP_STATE_VM(mp_pending_exception) = (mp_obj_t*)&(MP_STATE_PORT(mp_kbd_exception));
}

So that is what I ended up doing.

Thanks,
Cyrille

Post Reply