https://os.mbed.com/docs/mbed-os/v6.3/apis/eventqueue.html
use :EventQueue example: deferring from interrupt context
but get error:
[Error] Callback.h@635,9: static_assert failed due to requirement 'std::is_trivially_copyable
In file included from ./mbed-os\mbed.h:22:
In file included from ./mbed-os/rtos/include\rtos/rtos.h:29:
In file included from ./mbed-os/rtos/include\rtos/Thread.h:30:
./mbed-os/platform/include/platform\Callback.h:635:9: error: static_assert failed due to requirement 'std::is_trivially_copyable
^ ~~~~~~~~
./mbed-os/platform/include/platform\Callback.h:382:9: note: in instantiation of function template specialization 'mbed::Callback
generate(std::move(f));
^
.\main.cpp:38:13: note: in instantiation of function template specialization 'mbed::Callback
sw.fall(queue.event(fall_handler));
^
NUCLEO-F103RB
mbed-os 6.3.0
Mbed Studio: 1.2.1
code:
DigitalOut led1(LED1);
InterruptIn sw(USER_BUTTON);
EventQueue queue(32 * EVENTS_EVENT_SIZE);
Thread t;
// It's safe to use UnbufferedSerial in ISR context
//UnbufferedSerial console(USBTX, USBRX);
void rise_handler(void)
{
// char buf[64];
printf("rise_handler in context %p\n", ThisThread::get_id());
// console.write(buf, strlen(buf));
// Toggle LED
led1 = !led1;
}
void fall_handler(void)
{
printf("rise_handler in context %p\n", ThisThread::get_id());
// Toggle LED
led1 = !led1;
}
// main() runs in its own thread in the OS
int main()
{
// Start the event queue
t.start(callback(&queue, &EventQueue::dispatch_forever));
printf("Starting in context %p\r\n", ThisThread::get_id());
// The 'rise' handler will execute in IRQ context
sw.rise(rise_handler);
// The 'fall' handler will execute in the context of thread 't'
sw.fall(queue.event(fall_handler));
// while (true) {
// }
}
Hi @varichs,
~The ThisThread::get_id() function call is not expected to work when running inside of an interrupt handler. The application is not running thread mode and therefore there is no thread ID associated with the interrupt context.~
I guess I was mistaken!
Hi @varichs,
The
ThisThread::get_id()function call is not expected to work when running inside of an interrupt handler. The application is not running thread mode and therefore there is no thread ID associated with the interrupt context.
But this code is an official example. Is this example wrong?https://os.mbed.com/docs/mbed-os/v6.3/apis/eventqueue.html
Hi @varichs
The error message says...
./mbed-os/platform/include/platform\Callback.h:635:9: error: static_assert failed due to requirement 'std::is_trivially_copyable<events::Event<void ()> >::value' "F must be TriviallyCopyable. Turn on Mbed configuration option 'platform.callback-nontrivial' to use more complex function objects"
So, you can try to enable the platform.callback-nontrivial in your mbed_app.json.
"target_overrides": {
"*": {
"platform.callback-nontrivial" : true,
@varichs thank you for raising this issue.Please take a look at the following comments:
What toolchain(s) are you using?
NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'.This indicates to us that at least all the fields have been considered.
Please update the issue header with the missing information, the issue will not be mirroredto our internal defect tracking system or investigated until this has been fully resolved.
So, you can try to enable the platform.callback-nontrivial in your mbed_app.json.
I'll close this as resolved
Most helpful comment
Hi @varichs
The error message says...
So, you can try to enable the
platform.callback-nontrivialin your mbed_app.json.