Skip to content
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

Closed

Conversation

Flameeyes
Copy link
Contributor

@Flameeyes Flameeyes commented Aug 3, 2023

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.

@Flameeyes Flameeyes requested a review from nashif as a code owner August 3, 2023 23:22
Copy link
Collaborator

@kartben kartben left a 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!

printk("Hello World! %s\n", CONFIG_BOARD);
while(1) {
printk("Hello World! %s\n", CONFIG_BOARD);
k_msleep(SLEEPTIME);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
k_msleep(SLEEPTIME);
k_msleep(1000);

Copy link
Member

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>

Comment on lines 9 to 8
/* delay between greetings (in ms) */
#define SLEEPTIME 1000

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* delay between greetings (in ms) */
#define SLEEPTIME 1000

nashif
nashif previously requested changes Aug 4, 2023
Copy link
Member

@nashif nashif left a 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.

@Flameeyes
Copy link
Contributor Author

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 #define controllable be worth exploring?

@fabiobaltieri
Copy link
Member

fabiobaltieri commented Aug 4, 2023

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. samples/subsys/usb/console does that already, probably for this very same reason.

@Flameeyes Flameeyes force-pushed the hello-world-timing branch 5 times, most recently from 30c130d to 4590d1c Compare August 4, 2023 18:48
@nashif
Copy link
Member

nashif commented Aug 4, 2023

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.

again, we have the syncronization sample for this :)

@Flameeyes Flameeyes requested review from kartben and gmarull August 4, 2023 19:27
@kartben
Copy link
Collaborator

kartben commented Aug 4, 2023

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.

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.

kartben
kartben previously approved these changes Aug 4, 2023
fabiobaltieri
fabiobaltieri previously approved these changes Aug 4, 2023
Copy link
Member

@fabiobaltieri fabiobaltieri left a 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.

x

@nashif
Copy link
Member

nashif commented Aug 5, 2023

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.

@Flameeyes
Copy link
Contributor Author

Let me try to find a way forward:

  • there seem to be a want, besides from me, for a simple, regular output on the UART for various debugging purposes;
  • what made sense to me, is the equivalent of blinky, that is to output something every second or so — I have done that on hello_world because that's what the documentation suggests using it instead of blinky if the latter can't be used;
  • I personally believe that synchronization is not an equivalent simple app to blinky due to the aforementioned additional surface area
  • there's precedent for hello_world to simply terminate and not do anything more

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 "Zephyr says 'Hi!'" line every second?

@nashif
Copy link
Member

nashif commented Aug 5, 2023

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.

that works, instead of changing the existing hello_world, you can add a new one implementing similar functionality to blinky for development/debugging needs.

@gmarull
Copy link
Member

gmarull commented Aug 6, 2023

so what about blinky printing every second as well?

@Flameeyes
Copy link
Contributor Author

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>
@Flameeyes Flameeyes dismissed stale reviews from fabiobaltieri and kartben via ed44cbb August 6, 2023 10:49
@Flameeyes Flameeyes force-pushed the hello-world-timing branch from 4590d1c to ed44cbb Compare August 6, 2023 10:49
@Flameeyes Flameeyes changed the title hello_world: keep printing "Hello World!" every second. greetings: regularly print a string to the console every second. Aug 6, 2023
@zephyrbot zephyrbot requested a review from carlescufi August 6, 2023 10:49
@Flameeyes
Copy link
Contributor Author

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.

@Flameeyes
Copy link
Contributor Author

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?

@carlescufi
Copy link
Member

@kartben can you take another look?

@fabiobaltieri
Copy link
Member

@kartben ping

Copy link
Collaborator

@kartben kartben left a 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!

Comment on lines +1 to +4
.. _greetings:

Greetings
#########
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. _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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:ref:`greetings` is a good alternative.
:zephyr:code-sample:`greetings` is a good alternative.

@kartben
Copy link
Collaborator

kartben commented Dec 20, 2023

@Flameeyes will you have cycles to address the opened comments? Thanks!

@Flameeyes
Copy link
Contributor Author

Probably next week, let me see!

@kartben
Copy link
Collaborator

kartben commented Dec 20, 2023

@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)

@Flameeyes
Copy link
Contributor Author

Given this started while trying to get blinky to print, if we settled on that I don't need that.

@Flameeyes Flameeyes closed this Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants