This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

MPU fault when compiling .cpp file

Hello,

When I try to run a project containing a .cpp file, I get the following console output:

I am compiling the openthread client example with a slight modification. So far the only difference between the ncs openthread example and my project is that I have created a main.cpp file which calls main() instead of calling main() in coap_client.c. If I change the file extensions to .c it runs normally. Why is this? CONFIG_CPLUSPLUS is enabled in the prj.conf file. The same behaviour happens with the coap_server.c example.

Also, the two following errors always occur, even when running the example without any changes:

E: Timeout while waiting network interface
E: Network initialization failed (-115)

What does this mean?

  • Hi.

    I am not able to reproduce your problem when using C++.

    Here is a diff showing my modifications:

    diff --git a/samples/openthread/coap_client/CMakeLists.txt b/samples/openthread/coap_client/CMakeLists.txt
    index 1d22a08d..5deb620c 100644
    --- a/samples/openthread/coap_client/CMakeLists.txt
    +++ b/samples/openthread/coap_client/CMakeLists.txt
    @@ -15,6 +15,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
     project(openthread_coap_client)
     
     target_sources(app PRIVATE src/coap_client.c
    -			   src/coap_client_utils.c)
    +				 src/coap_client_utils.c
    +				 src/main.cpp)
     
     target_include_directories(app PUBLIC ../coap_server/interface)
    diff --git a/samples/openthread/coap_client/prj.conf b/samples/openthread/coap_client/prj.conf
    index 0e37907a..05f97b20 100644
    --- a/samples/openthread/coap_client/prj.conf
    +++ b/samples/openthread/coap_client/prj.conf
    @@ -83,3 +83,5 @@ CONFIG_COAP_UTILS=y
     CONFIG_COAP_CLIENT_LOG_LEVEL_DBG=y
     CONFIG_COAP_CLIENT_UTILS_LOG_LEVEL_DBG=y
     CONFIG_COAP_UTILS_LOG_LEVEL_DBG=y
    +
    +CONFIG_CPLUSPLUS=y
    \ No newline at end of file
    diff --git a/samples/openthread/coap_client/src/coap_client.c b/samples/openthread/coap_client/src/coap_client.c
    index 3c3a55fa..971785c7 100644
    --- a/samples/openthread/coap_client/src/coap_client.c
    +++ b/samples/openthread/coap_client/src/coap_client.c
    @@ -54,7 +54,7 @@ static void on_button_changed(u32_t button_state, u32_t has_changed)
     	}
     }
     
    -void main(void)
    +void c_main(void)
     {
     	int ret;
     
    

     

    Also, the two following errors always occur, even when running the example without any changes:

    E: Timeout while waiting network interface
    E: Network initialization failed (-115)

     Do you have two DKs, where the other one is running the coap_server sample?

    Best regards,

    Didrik

  • Hello Didrik,

    After updating the SDK to the latest revision, the MPU fault problem no longer occurs.
    The timeout and initialization errors are still present. However, they do not seem to cause any particular trouble for the application. And yes, I am running the server example on a different evalkit., but I do not think this is relevant for this error log since it occurs under initialization - whether or not another evalkit is running the server/client example.

Related