This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/LAUNCHXL-CC26X2R1: Using Display_printf() in multiple tasks

Part Number: LAUNCHXL-CC26X2R1


Tool/software: TI-RTOS

I am working on the Simple Peripheral project for the CC26X2 launchpad. I have created my own task outside of the simple peripheral task. I would like to write to a serial display on PuTTy. However, although I am able to write to it from the simple peripheral task, when I try to call the Display_printf() function within my own task, the program hangs. I want to say this may be due to some improper initialization, but I'm not sure what to do to make this work. So far, I have tried to create my own separate display handle and tried to use the display handle from the simple peripheral task using an external variable, both of no avail. The display handle remains null.

So far, this is what I am doing within my task:

Display_init();

dispHandle = Display_open(Display_Type_ANY, NULL);

Display_printf(dispHandle, 0, 0, "Error Initializing I2C.\n");

What do I do to make this work? I would really appreciate some help debugging this issue.

EDIT: My task is a separate .c file

  • Hi Bharathi,

    You're code snippet doesn't tell me much. Are you calling Display_init() multiple times? Are you opening multiple display handles? Or are you using the same display handle in all of the tasks?
  • This is where I'm a little confused. I'm not entirely sure how all this works. Am I supposed to be calling Display_init() multiple times? I know the simple peripheral task already has a display handle set up and display initialized. From my task do I need to redo this or can I just use what simple peripheral has defined.

    I have tried both, opening new display handles and using the same one. Neither of which seem to be working. The program just hangs on Display_printf().

    My guess is that using the same display handle will not work since these are different tasks. So the display handle may not even be initialized while running one task or another since the other task hasn't happened yet.
  • You are not supposed to call Display_init() multiple times, only once. If you want multiple tasks to access the same Display peripheral then you need to open a single display handle with that Display peripheral, and then use that handle in the tasks you want to call Display_printf().
  • Seems like I am still having the same issue. When I call Display_printf() from my task, my program crashes. 

    I only open one display handle and use the same one from the simple peripheral task. In order to do so, I create an external variable in my task. Why would this be happening? Is there something else I need to do with regards to initializing the display handle?

    This is what my simple peripheral task does. Not sure what the two-button menu module is, maybe this is why it's not working?

    // The type of display is configured based on the BOARD_DISPLAY_USE...

      // preprocessor definitions
      if(dispHandle == NULL)
      {
          dispHandle = Display_open(Display_Type_ANY, NULL);
          
      }
    
    
      // Initialize Two-Button Menu module
      TBM_SET_TITLE(&spMenuMain, "Simple Peripheral");
      tbm_setItemStatus(&spMenuMain, TBM_ITEM_NONE, TBM_ITEM_ALL);
    
      tbm_initTwoBtnMenu(dispHandle, &spMenuMain, 2, SimplePeripheral_menuSwitchCb);
      Display_printf(dispHandle, SP_ROW_SEPARATOR_1, 0, "====================");


    Also, I noticed that my task runs first before the simple_peripheral task when starting, so dispHandle is NULL when my task runs. In order to accommodate for that, I do the following in the second code snippet.

     if (dispHandle == NULL) {
    
                 dispHandle = Display_open(Display_Type_UART, NULL);
           }
    
           Display_printf(dispHandle, 40, 0, "Starting the i2c.\n");

  • You should be opening the same Display handle on both opens, Display_Type_UART.
  • I tried that as well, but that didn't seem to work either. I came up with a temporarily solution but its not very clean and I would like to fix it. Since I am displaying something periodically, I used an external variable in the simple_peripheral task that references the variable I want to display from my task. And then use the Display_printf() command in the periodic tick function. I would like to find out the alternative correct way to do this however.

  • As long as both tasks are using the same handle, and that a task is not trying to use a handle that is not yet opened (i.e. handle is NULL), then it work fine.