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

Openthread with FreeRTOS

Hi!
I've successfully set op an OpenThread MQTT broker using a Rasperry Pi and nrf52 dongle and I am able to publish and subscribe to and from my computer by flashing the mqttsn_client_subscriber and mqttsn_client_publisher examples to my nrf52840 DK.

I want to incorporate thread communication into a larger project on the nrf52840 DK using FreeRTOS. My first step has been trying to modify the mqttsn_client_subscriber example to incorporate FreeRTOS. However I have not had much success.

Does the SDK provide examples of OpenThread with FreeRTOS or are there other sources I can consult?






Parents
  • Hello,

    There is one example that uses the openthread stack and FreeRTOS:

    SDK_for_Thread_and_Zigbee_4.1.0\examples\thread\freertos_coap_server

    Perhaps you can use this example for reference.

    Best regards,

    Edvin

  • Hi!
    I've tried this unsuccessfully.

    I modified the mqttsn_client_subscriber example some, making it connect to the broker and subscribe to topic automatically, not using the buttons.
    This solution works well. 



    However when i try to implement the same solution in FreeRTOS, using the freertos_coap_server as a reference, it doesn't work. The program does not connect to the gateway etc. 


    There seems to be an issue with running the mqttsn_evt_handler, perhaps this is related to using the app_scheduler in the program? I am not sure, but the events are not triggered. 

    Here is my code: https://github.com/hunshamar/freertos_openthread

    Do you have any suggestions for making this work? I am not too experienced with FreeRTOS or the nordic SDK, so any help would be appreciated. 

    -Asgeir


  • I saw that repo, but which of the projects is it? And what IDE did you use to set up the project? I tried the freertos_coap_server\pca10056\blank\ses and armgcc, but none of them compiled in an unmodified SDK2.0.0. Where should I place the project file, and what IDE do you use? Please make sure that it compiles in an unmodified SDK.

    SDK2.0.0 is a bit old, so you can consider to move to SDK4.1.0, but we can look into it in the SDK2.0.0 first.

    BR,

    Edvin

  • The projects are explained in the readme. The "freertos_coap_server" is the freertos openthread mqtt program. 

    I am able to compile it in an unmodified SDK2.0.0. I tried downloading a new SDK now and tested it. I copied the files from the github repo into SDK/examples-folder. I used VS code to modify the code, but to compile it i ran the makefile in pca/10056/blank/armgcc using a terminal. You can see where i placed the project files in the picture. Does this not work for you?

    Kind regards, Asgeir. 





  • Yes. It was probably what it said earlier as well, but I guess it wasn't an error:

    So, I am currently working from home, and can't monitor the LEDs, because the DK is connected in my work computer in the office, so I added the line:

    NRF_LOG_INFO("led task"); right before toggling the led in the while loop.

    I saw that it was only printed once, and I wanted to debug, so I had to port the segger project that you provided. However, running that, I see that it is printed regularly (LED1_BLINK_INTERVAL).

    Can you try the attached project (unzip in the same location as you had your project) and check if it behaves the same, or if the LED keeps blinking in your case?

    6281.freertos_coap_server.zip

  • It behaves the same. The LED only blinks once. When i remove the call to mqttsn_client_search_gateway(), the blinking tasks works as expected. 

  • Did you test the SES (segger embedded Studio) project that I attatched in the previous reply? Does it behave the same there?

Reply Children
  • I only tested the armgcc solution with make. Should i install SES and try the SES file?

  • Hello,

    I experimented a bit more. It seems like you receive a hardfault, but I am not yet sure why. Please check the attached project:

    5460.freertos_coap_server_2.zip

    Put it in the same location as your current project. 

    Also, open hardfault_implementation.c and modify the function HardFault_process() to look like this:

    /*lint -save -e14 */
    __WEAK void HardFault_process(HardFault_stack_t * p_stack)
    {
        // Restart the system by default
        //NVIC_SystemReset();
        while (true)
        {
            NRF_LOG_PROCESS();
        }
    }
    /*lint -restore */

    And monitor the RTT log.

    I have to ask a colleague of mine, but he is not in today. I'll check with him, hopefully in the beginning of next week.

    BR,

    Edvin

  • Ok! I see.
    Keep me posted if your college or you find a solution. Hopefully we can make it work. 

    -Asgeir. 

  • Hi!
    Any updates? 

    One thing i noticed, when trying to run the working project without FreeRTOS in the project directory of the FreeRTOS program (modified coap server), and with the FreeRTOS makefile, the program would not run with the FreeRTOS makefile, despite not using any FreeRTOS functionality.

    I did not get a hardfault error, but other than that the program responded as the FreeRTOS program, not receiving any MQTT-events. However when i tried removing the FreeRTOS-files from the makefile, just from the SRC_FILES as shown below the program works.


    The right file is the working makefile.



    The program flow. First running the makefile on the left, then running the makefile on the right. 



    It seems that just including the FreeRTOS source files, without including or using them in the main-file,in the project causes the MQTT-events to stop responding. 



  • Hello,

    We believe the issue is that your function calls are using a lot of timers, which are not supposed to be called until you have kickstarted the FreeRTOS itself using vTaskStartScheduler().

    Basically, you can't use any of this:

        thread_instance_init();
        mqttsn_init();
        
        /* Connect to gateway */ 
        uint32_t err_code = mqttsn_client_search_gateway(&m_client, SEARCH_GATEWAY_TIMEOUT);
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_INFO("SEARCH GATEWAY message could not be sent. Error: 0x%x\r\n", err_code);
        }else{
            NRF_LOG_INFO("Search gateway message sendt");
        }

    before you call vTaskStartScheduler(). Please note that the vTaskStartScheduler does not return, so you need to add these parts e.g. within your openthread task. 

    Without being able to pin point exactly what caused the Hardfault it was definitely a timing related issue. The reason it worked in SES was probably due to optimization. When I compiled the DEBUG variant of the project, it hardfaulted, just like your armgcc project. 

    I don't know exactly what it should look like, but look at the unmodified freertos_coap_server example, and do only one change at the time. If it stops working, then look into why it doesn't work.

    Are you sure you really need FreeRTOS anyway?

    BR,

    Edvin

Related