-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
greetings: regularly print a string to the console every second. #61141
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Could you please also update the README ("Overview" and "Sample Output")? Thanks!
samples/hello_world/src/main.c
Outdated
printk("Hello World! %s\n", CONFIG_BOARD); | ||
while(1) { | ||
printk("Hello World! %s\n", CONFIG_BOARD); | ||
k_msleep(SLEEPTIME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k_msleep(SLEEPTIME); | |
k_msleep(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for simplicity, also, I'd change printk
to printf
, and include <stdio.h>
samples/hello_world/src/main.c
Outdated
/* delay between greetings (in ms) */ | ||
#define SLEEPTIME 1000 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* delay between greetings (in ms) */ | |
#define SLEEPTIME 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use samples/synchronization
/ sample. Lets not change the behavior of a classic hello world sample.
I did that originally, but that does increase the noise surface significantly, since it's involving threading (attach debugger, where are you?) During bring up of a new board (particularly if, like me, you have no idea what you're doing and is the first time you try), being able to exclude as much of the higher level stack is useful. Already bringing up the serial console adds more moving parts, which is why at least for the local testing I preferred reducing the surface area. Would a trade-off of having this |
I also think it's a good idea to have it repeat, then you'd still get an output if you are fiddling with serial ports and end up missing the boot message for whatever reason. |
30c130d
to
4590d1c
Compare
again, we have the syncronization sample for this :) |
TBH it is a bit of a stretch to compare improving the Hello World sample by adding a simple sleep/while(1) to a full blown synchronization sample that demonstrates how to create threads, use semaphores, etc. Should we refrain from using k_sleep in every sample then, for this should be something reserved only for the synchronization sample? :) I think the point here is really about improving the usability/UX of the Hello World (in addition to also making it a quick proof point that clock is setup properly, to @Flameeyes' point earlier), and nothing more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with Ben on this, synchronization
is good for showing thread usage but that's few steps ahead and this PR made me realize how may times I've hacked a printk into blinky
while searching for the TX pin on whatever board I had just for this.
Though it is indeed sad to diverge from the classic version of it, we were already a bit off from the start, it should have been a printf
and all lowercase.
https://www.geeksforgeeks.org/hello-world-in-30-different-languages/ hello world is a defacto "standard", it has been the same code in Zephyr since we started, lets not change that just because of someone's debug needs, if you want to debug something, take hello world and modify it. |
Let me try to find a way forward:
So here's an alternative approach I'm happy to run with if that raise no complaints: introduce a new application that is, semantically "blinky but on a serial port", update the documentation to suggest the use of that instead of hello_world where blinky can't be uesd. Maybe something with a repeating pattern like the old C64 demos? Like "/" sent very one second? There's a bit more use in slightly longer patterns as they're easier to caught with the debugger though, so maybe a |
that works, instead of changing the existing hello_world, you can add a new one implementing similar functionality to blinky for development/debugging needs. |
so what about blinky printing every second as well? |
blinky has a minimum hardware requirement for the led0 alias, or it'll fail to build — which is where the recommendation for hello_world comes from. I mean, we could still have it print as well to combine that option, but complicating the sample to make led0 optional doesn't seem like a good idea. |
Introduce a new sample app to repeatedly and regularly print a string ("Zephyr says 'Hi!'") every second on the console. Recommend this sample instead of hello_world for boards that are not meeting the minimum requirements for blinky. Signed-off-by: Diego Elio Pettenò <flameeyes@meta.com>
4590d1c
to
ed44cbb
Compare
Not entirely sure on what's the best practice between re-using the same pull request or separating it, but I think keeping the discussion in one place is worthwhile — happy to submit as a separate pull request if you think it's better. |
More to the need of not relying on philosophers: as of today philosophers causes a hard fault on the EV11L78A because something is broken in the threading code. @nashif what's the blocker for having this new sample app? |
@kartben can you take another look? |
@kartben ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an actual mistake re: sample path + some requested changes to leverage the recently introduced Zephyr sample Sphinx extension. Thanks @Flameeyes!
.. _greetings: | ||
|
||
Greetings | ||
######### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. _greetings: | |
Greetings | |
######### | |
.. zephyr:code-sample:: greetings | |
:name: Greetings | |
:relevant-api: thread_apis | |
Print greetings to the console once per second. |
A simple sample that can be used with any :ref:`supported board <boards>` and | ||
prints "Zephyr says 'Hi!'" to the console, once per second. | ||
|
||
It's an alternative to :ref:`blinky <blinky-sample>` for boards with no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an alternative to :ref:`blinky <blinky-sample>` for boards with no | |
It's an alternative to :zephyr:code-sample:`blinky` for boards with no |
This application can be built and executed on QEMU as follows: | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/greetings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:zephyr-app: samples/greetings | |
:zephyr-app: samples/basic/greetings |
@@ -652,7 +652,7 @@ Build the Blinky Sample | |||
|
|||
Blinky is compatible with most, but not all, :ref:`boards`. If your board | |||
does not meet Blinky's :ref:`blinky-sample-requirements`, then | |||
:ref:`hello_world` is a good alternative. | |||
:ref:`greetings` is a good alternative. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:ref:`greetings` is a good alternative. | |
:zephyr:code-sample:`greetings` is a good alternative. |
@Flameeyes will you have cycles to address the opened comments? Thanks! |
Probably next week, let me see! |
@Flameeyes thanks! FWIW blinky is now also printing to the console, so this might actually not be all that necessary to add this code sample? (PR #63056) |
Given this started while trying to get blinky to print, if we settled on that I don't need that. |
Introduce a new sample app to repeatedly and regularly print a string
("Zephyr says 'Hi!'") every second on the console.
Recommend this sample instead of hello_world for boards that are not
meeting the minimum requirements for blinky.