1.7k views
in Getting started by

Hello.

I just started using Embedded Wizard and I have been having some trouble getting a few things to work.

I am developing some code for STN32F769-DISCO and I followed the tutorial at: Getting Started with STM32F769 Discovery.

Then I created my own EmWi and used the Generated Code with the Template to upload it to the board. So far so good.

Now I tried to create a second thread to run a simple code. Unfortunately I didn't get this part to work. Here are a few steps I followed.

1- I have set the EW_USE_FREE_RTOS to 1.

2- Created the function for my secondary thread. (Just print something with Putty).

static void myMainLoop ( const void* arg )
{
  while(1)
  {
    EwPrint( "[myMainLoop - Task]\n" );
  }
}

3- Created the new task right after the UI Thread (and before osKernelStart).

  EwPrint( "Create my thread...                          " );
  osThreadDef( MyThreadHandle, myMainLoop, osPriorityNormal, 0, semtstSTACK_SIZE );
  osThreadCreate( osThread( MyThreadHandle ), (void*)0 );
  EwPrint( "[OK]\n" );

4- I compiled and download this to the board.

 

The behavior was not what I expected. My secondary Thread doesn't run ever. Actually, only the first thread I defined and created runs. If I switch the order of the creation of the EmWiThreadHandle thread and mine (MyThreadHandle), the code will just execute my thread.

 

Is the template configured in a way that this won't work? Am I doing something wrong with the RTOS?

 

PS: I know the GUI application has to be in only one thread. That is why I didn't change the EmWiMainLoop function.

 

by
Ok. I discovered something:

There might be a problem with the function EwPrint. As soon as I removed it from my code, the multi-threading started working perfectly.

2 Answers

0 votes
by
 
Best answer
Hi Christian,

Thanks for your further investigation. As far as I know, EwPrint is not thread safe - so removing such calls is from my point of view the best solution. Did you integrate your further tasks successfully?

Best regards,
Manuel
by
I did. I noticed that I am a little restricted. All EW functions (no exceptions) have to be used in only on thread.

I was wontering. Is it possible to use EW functions in other threads if I am very careful with Semaphore, Mutex or Signals?

For example:

Task A = EW loop

Task B = It doesn't matter what it does, but it uses an EW function if a condition is met.

 

Events:

Task A runs EW functionality as usual.

Task B runs as usual until needs an EW function.

Task B requests to use an EW function.

Task A finishes whatever it was doing. Gives Task B permition and waits for it to finish.

Task B finishes using it quickly. Alerts Task A.

Task A goes back to normal.
by

Embedded Wizard GUIs are not thread-safe. To do a proper synchronization, please have a look here. Please have a look at this and this question, too. Does that help?

0 votes
by
Hello

The exact same problem occured with my code. But i do not use any EmWi Functions in my own thread. Besides that, i create the threads as mentioned above.

Are there any other aspects i have to consider? Are there any possibilities that you can provide me with your examle code for multithreading with FreeRROS and EmWi?

 

Best regards

 

migu

 

Edit: I was able to solve the problem. I had to create the threads as "Thread objects" .  Now both threads are running.

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...