Mbed-os: Callback.h@635,9: 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"

Created on 9 Oct 2020  Â·  5Comments  Â·  Source: ARMmbed/mbed-os

Description of defect

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 [ERROR] In file included from .\main.cpp:1:
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 static_assert(std::is_trivially_copyable::value, "F must be TriviallyCopyable. Turn on Mbed configuration option 'platform.callback-nontrivial' to use more complex function objects");
^ ~~~~~~~~
./mbed-os/platform/include/platform\Callback.h:382:9: note: in instantiation of function template specialization 'mbed::Callback' requested here
generate(std::move(f));
^
.\main.cpp:38:13: note: in instantiation of function template specialization 'mbed::Callback' requested here
sw.fall(queue.event(fall_handler));
^

Target(s) affected by this defect ?

NUCLEO-F103RB

Toolchain(s) (name and version) displaying this defect ?

What version of Mbed-os are you using (tag or sha) ?


mbed-os 6.3.0

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

Mbed Studio: 1.2.1

How is this defect reproduced ?

code:

include "mbed.h"

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) {

// }

}

Most helpful comment

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,

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings