-
-
Notifications
You must be signed in to change notification settings - Fork 16
Zephyr User Threads (define/start) don't seem to be working. (Multithreading) #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As a quick update I added to the m7_conf file but still no luck:
|
Morning all:
And maybe important or not, added Serial.open() And a few prints at the start...
|
I thought I would try setting the priority of the main thread to a lower priority (higher value). So first thing I wanted to do is to retrieve the thread id. So I added:
And the sketch would not load:
So I tried adding: It still fails to load, but error message is now:
Not sure what the proper fix for this is: https://kb.segger.com/Thread-Local_Storage
UPDATE: - still should get the main way to work, but:
|
As we talked about it appears threads are not starting when using k_thread_define. Might be something with when the thread is created - timing. |
I wonder what code is responsible to create those threads: Still need to investigate more, but I am wondering if it creates the structures within some known location, that some boot code is upposed to iterate: The reason I ask this, is I see that the k_thread_define indirectly goes through:
So wondering if there are structures created in some known linker section, that the code can maybe know how big that section is, and how big each item is and iterate over them.. Does this work with this setup? So far maybe beyond my pay grade ;) (free), but will dig some more. |
@KurtE In setup () i did try to manually start it with EDIT: Did see this in comments for k_thread_start
|
@mjs513 @facchinm - Not sure how this is supposed to work, or simply not supported? Currently it looks like, the linker is throwing away the iterable sections:
Whereas if it is in the main build, the linker is setup to generate the data, like:
I don't see anything in the linker_script.ld file that does anything with these for the build of the sketch. However the build.sh code I believe uses the linker.cmd in the build\zephyr directory, which has sections like:
And my guess is that you could not just duplicate this, as might end up with duplicate symbols like: __static_thread_data_list_start And if it did, is there some code in place when the llext is loaded to do the iteration and then spawn the threads? |
Making some progress on this: @mjs513 - I updated your example 2 sketch, I put it up in my giga stuff github... I added:
In the sketch I linked to above, I added:
Assuming this is the right tract, this probably should be added to functions called by the llext when code is loaded. And, I am getting:
|
Gave you changes a try with a different test sketch I had using leds in the threads and it worked. Until Arduino figures out best way to handle it i modifed main.cpp - which seems to work also:
avoids having to add all that to each sketch |
Some background information on the enumeration of the static threads data and starting up the threads. I found similar code
My guess is this function nor z_setup_new_thread (in thread.c) that it calls are exported. Wondering if some of the things it does, we should mimic? like copy in the init data into the new_thread... Also if we should hold off starting the thread until we have initialized all of them? And try to do that holding lock as to |
@mjs513 @facchinm - Made similar changes to main.cpp, but did as I mentioned and updated it slightly.
As I suspected this needed me to add those two kernel functions into: llexp_exports.c
I only added the last two here... I removed it from the test2 mentioned and it still worked! I made a quick and dirty version of the ArduinoCore-zephyr/samples/threads_arduino sketch:
Hacked for the three LEDS RED/GREEN/BLUE - Should really have defines for these... Also wondering what the third created thread does versus the main thread. As both want to call loop? Maybe ignored?
as I don't see a blink_id2... Thinking we should probably do a PR for this. Thoughts? |
I modified that sketch a bit to use rgb led on pins 13, 11 and 10 since I wanted to play with a little rgb breakout that i have.
note that I changed the delays to k_msleep. Seems to run for me and blinks all leds. |
Not sure you want to use lock threads:
From what I was reading in the docs threads area started in the suspended state - forgot where I read that so don't hold me to it. Is interesting about
|
@facchinm - @KurtE Wish Discussions were turned on.
and it seems to work:
there are some things you have to know that the time slice is applied to same priority thread. Haven't figured out how to set it up to do it programmatically yet. Right now just testing functions and our changes. Next post semaphores |
Ok the semaphore example I am working with:
give me error in the debug window:
note may be issue with K_SEM_DEFINE. Have to look and play. To honest not sure about region 1 elf error. |
@KurtE @facchinm
Seeing the same error message:
going back to the linker.cmd file I am seeing a bunch of data areas being established, for example
not sure if it means anything. Still investigating |
@KurtE moved the __static_thread_data_list_start into the .text section which cleared up the region issues with mutexes and semaphores. Ran throught several sketches and they seem to be working. Will be issuing a PR to incorporate the changes |
retested with the test sketches posted in the PR (https://github.com/user-attachments/files/18519157/[thread_test_sketches.zip](https://github.com/user-attachments/files/18519157/thread_test_sketches.zip)) and they all ran with the changes. So going to close this out. However, am seeing this upload error occuring:
with the thread sketches. Going to be testing more. |
Describe the bug
Running thread examples from:
and
fail to out any data to serial monitor. Tried blink led as led as well but that didn't work.
Target board + cli verbose compilation output
Arduino Zephyr - GIGA...
Optional: attach the sketch
From item 1:
from item 2
The text was updated successfully, but these errors were encountered: