Skip to content

Conversation

@aescolar
Copy link
Member

@aescolar aescolar commented Sep 25, 2018

Added a new UART driver for posix arch boards. The driver can be configured to either attach to a new
pseudo-terminal, or to connect to the process stdin-out (only meant for automatic testing, not for interactive use)


Fixes #10190
Fixes #10127 by working around #10191

@aescolar aescolar added area: UART Universal Asynchronous Receiver-Transmitter area: native port Host native arch port (native_sim) labels Sep 25, 2018
@aescolar aescolar requested a review from dbkinder as a code owner September 25, 2018 12:40
@aescolar aescolar changed the title UART for POSIX_ARCH [DNM] UART for POSIX_ARCH Sep 25, 2018
@aescolar aescolar requested a review from ulfalizer September 25, 2018 12:54
@aescolar aescolar changed the title [DNM] UART for POSIX_ARCH UART for POSIX_ARCH Sep 25, 2018
@codecov-io
Copy link

codecov-io commented Sep 25, 2018

Codecov Report

Merging #10212 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #10212   +/-   ##
=======================================
  Coverage   53.06%   53.06%           
=======================================
  Files         214      214           
  Lines       26198    26198           
  Branches     5645     5645           
=======================================
  Hits        13901    13901           
  Misses      10025    10025           
  Partials     2272     2272

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab8d0c4...705b5e7. Read the comment docs.

@aescolar
Copy link
Member Author

aescolar commented Sep 25, 2018

One clarification to a question you will probably have:
The default is, purposely, to attach the UART to its own pty.
The option to map it to STDIN/OUT is really not the intended use-case.

The reason for this is that the shell assumes it has access to a terminal thru a raw driver, without any of the standard terminal niceties.

That means that if we wanted to provide some reasonable setup thru stdin/out for interactive use, we would need to reconfigure the terminal into a non-sane mode (no echo, no line input, no Ctrl+X raising signals, etc..).
That can be done easily, but then we have 2 issues:

  • We need to be sure to leave the terminal as it was on SIGSTP (Ctrl+Z) and bring it back to funny mode in SIGCONT. Otherwise the terminal is not usable if/when people leaves the native_posix executable in the background. This is double with a bit of extra code.
  • We need to be sure to leave the terminal back how it was on exit. And here is the big problem. When things end gracefully enough, we can bring the terminal back. But given that native_posix is meant as a debugging/development aid, it is likely/normal that things will crash horribly (e.g. segfault). If we don't bring the terminal back, it would be left in an unusable and unrecoverable state for 99.9% of the users.

@aescolar
Copy link
Member Author

You can for example try the shell sample app as:

cmake ../samples/subsys/shell/shell_module/  -GNinja -DBOARD=native_posix  -DCONFIG_NO_OPTIMIZATIONS=y
ninja
zephyr/zephyr.exe --attach_uart #assuming you have xterm and screen installed

If you run any of the commands which require options without an option you will trigger #10195

@aescolar
Copy link
Member Author

recheck

Copy link
Contributor

@ulfalizer ulfalizer Sep 25, 2018

Choose a reason for hiding this comment

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

depends on might be better here. selecting symbols with prompts or dependencies often leads to two common issues:

  • select ignores dependencies. If someone adds (unsatisfied) dependencies to SERIAL, this will still force it on (but at least you get a warning).

  • With select, you can't immediately tell when looking at SERIAL that there's other ways for it to get enabled, or that CONFIG_SHELL=y also enables SERIAL. That can lead to twisty and hard-to-follow Kconfig files if there's a lot of selecting going on.

    People often overlook the selecting symbols when changing dependencies too, which is how you end up with the first issue.

Usually, it's best to limit select to simple invisible "helper" symbols (select CPU_SUPPORTS_FOO and the like). It's great for that.

I whitelisted the select-without-satisfied-dependencies warning when I was turning warnings into errors, because there was a lot of it going on, and a lot of it seemed to be from CONSOLE-related symbols. Should probably refactor a bunch of those to use depends on instead. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

This sentiment also appears in kconfig-language.txt btw:

select should be used with care. select will force a symbol to a value without
visiting the dependencies. By abusing select you are able to select a symbol
FOO even if FOO depends on BAR that is not set. In general use select only for
non-visible symbols (no prompts anywhere) and for symbols with no dependencies.
That will limit the usefulness but on the other hand avoid the illegal
configurations all over.

Common sense overrides it though, but in practice, select very often leads to those issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Some examples would be nice here:

This board provides a few peripherals such as an Ethernet driver and UART.  See ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Not the new shell, eh? Will the new and legacy shells work together or are they mutually exclusive?

Copy link
Member Author

@aescolar aescolar Sep 26, 2018

Choose a reason for hiding this comment

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

Not the new shell, eh?

Not with that console driver. The new shell is not using CONSOLE , but hooks directly into the UART driver. So the CONSOLE/old shell backends we had are of no use with the new shell.

Will the new and legacy shells work together or are they mutually exclusive?

I guess the question should be for the new shell developers. But my understanding is that, today:

  • The modules using the legacy shell are being ported to use the new shell. So the legacy shell will be purposeless quite soon (unless some old app uses it).
  • The new shell does not know or care about the old shell, and does not intend to avoid any conflict with it. If the old shell was driven thru UART they will certainly conflict if compiled together.
  • In case of native_posix, I think you may still be able to compile the old shell in parallel with the new one by using this native console driver for the old shell, and the new UART driver for the new shell.

Copy link
Contributor

@jakub-uC jakub-uC Sep 27, 2018

Choose a reason for hiding this comment

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

AFAIK legacy shell will be removed completely

Copy link
Contributor

Choose a reason for hiding this comment

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

:ref:`shell` will be a reference to the new shell documentation and not to the legacy shell subsystem. The shell documentation is changing with PR #10216, so your PR's references may break when 10216 is merged (or not work until it is). This should probably change to:

When the :ref:`legacy shell` subsystem is compiled ...

Copy link
Member Author

@aescolar aescolar Sep 26, 2018

Choose a reason for hiding this comment

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

Yep.. I saw that PR coming after I sent mine. So I guess my options are
a. to leave the old link which is correct today, and if that PR is merged before this, correct it. If this PR is merged before, the other PR author should correct the references to the old shell page around, OR, I can send a new PR after 10216 is merged.
b. remove all links to Shell all together, and add them back in a new PR after both are merged.
c. Point to the new shell doc and stall this PR.. => don't like this one.

@aescolar aescolar force-pushed the native_uart branch 3 times, most recently from 0b42286 to dd4364f Compare September 26, 2018 10:23
@aescolar
Copy link
Member Author

@jarz-nordic: are you ok with the fixes in the shell files?

@aescolar
Copy link
Member Author

@nashif , @jukkar , @jhedberg : Please take a quick look at the code, and tell if it there is something obviously horrible or not. This code is adding a new optional feature meant for testing, so I do not think we need an extremely thorough review. (I do not expect anybody to review the particular terminal driver flags combination...).

If any of you can think of a better reviewer for this, just add him.

Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

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

LGTM

@aescolar aescolar force-pushed the native_uart branch 2 times, most recently from 2ad14ce to 5714624 Compare September 26, 2018 11:38
@jakub-uC
Copy link
Contributor

@aescolar : sorry for late review, I had a busy day.

@pfalcon pfalcon self-requested a review September 26, 2018 16:08
@pfalcon
Copy link
Contributor

pfalcon commented Sep 26, 2018

Is this supposed to fix #5941 ? If no, why? If yes, doc clauses like:

:option:CONFIG_NATIVE_UART_0_ON_OWN_PTY or
:option:CONFIG_NATIVE_UART_0_ON_STDINOUT
Note that for interactive use, the first option should be chosen. The
second option is only intended for automated testing or feeding/piping other
processes output to the UART.

Seem strange/limiting. I wanted to check myself, but hit another obstacle: #10243

@pfalcon
Copy link
Contributor

pfalcon commented Sep 26, 2018

Is this supposed to fix #5941 ?

Well, it doesn't. There's no irq mode support, only busy-polling.

@aescolar
Copy link
Member Author

Seem strange/limiting

It just means that for interactive use, you have a dedicated TTY for the UART, instead of taking over the one from where you launch the zephyr app.

@pfalcon
Copy link
Contributor

pfalcon commented Sep 26, 2018

It just means that for interactive use, you have a dedicated TTY for the UART, instead of taking over the one from where you launch the zephyr app.

In a typical embedded situation, there's just one UART for user to connect to and do everything (provide input and get output, see logging, etc.). I'd expect the same functionality to be available on an emulated Zephyr port (at least available, if not default).

@aescolar
Copy link
Member Author

I think you missunderstood me. When you configure the native_poxis UART with CONFIG_NATIVE_UART_0_ON_OWN_PTY (default), you get a new linux /dev/pts mapped to the Zephyr UART. If you use the --atach_uart command, you even get a new window with a terminal emulator connected to it pop automagically.

@pfalcon
Copy link
Contributor

pfalcon commented Sep 26, 2018

Right, and if CONFIG_NATIVE_UART_0_ON_STDINOUT is defined, your docs say that it "is only intended for automated testing or feeding/piping other
processes output to the UART." I don't see why it would be intended only for that. Anyway, that can be handled later.

@aescolar
Copy link
Member Author

I don't see why it would be ...

If you try to use the shell interactively in that way, you will find yourself with a lot of annoyances, like both the Linux terminal driver and Zephyr shell echoing, the terminal capturing the Ctrl+x combinations (which the shell expects to get raw), the terminal replacing the \r with a \n, while the shell only reacts to \r as end of line, and so forth. That's why I warn people in advance that it is not going to be pleasant, and guide them to the other option which provides what I think most people will expect.

@pfalcon
Copy link
Contributor

pfalcon commented Sep 26, 2018

If you try to use the shell interactively in that way, you will find yourself with a lot of annoyances, like both the Linux terminal driver and Zephyr shell echoing

Ack, I see. As I hinted above, I quickly tried this patch with samples/subsys/console/echo/, but that failed as it required interrupt-driven UART, and I didn't look further so far. Now the situation is clear, thanks. I'd be keen to do something about it, but will look into it later.

Copy link
Contributor

@ulfalizer ulfalizer left a comment

Choose a reason for hiding this comment

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

select nit fixed.

@aescolar
Copy link
Member Author

@dbkinder : Is your review stale? or do you want to hold merging this one until the shell doc PR is fixed and merged, and this one would point to the new pages?

@jukkar
Copy link
Member

jukkar commented Sep 27, 2018

I would like to see this merged asap, the net-shell conversion at #9825 is currently blocked and needs this fix.

The posix arch does not compile either of Zephyr's libc,
so _prf() is not avaliable

Signed-off-by: Alberto Escolar Piedras <[email protected]>
The shell subsystem, as it is today, depends on having a UART,
therefore let's add the dependency explicitly in its Kconfig

Fixes zephyrproject-rtos#10190

Signed-off-by: Alberto Escolar Piedras <[email protected]>
Added a new UART driver for posix arch boards.
The driver can be configured to either attach to a new
pseudo-terminal, or to connect to the invoking shell
stdin-out.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
When running a UART test in CI, it is better to configure
the nativeposix UART to be mapped to the process STDIN/OUT.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
@aescolar
Copy link
Member Author

aescolar commented Sep 27, 2018

This last push is just a commit message fix to address the neither->either typo. No other change.

@Vudentz
Copy link
Contributor

Vudentz commented Sep 27, 2018

I hope we are getting this merging soon, it is also blocking #10239

Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

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

I'll get out of the way for this PR and we'll deal with the doc changes after the new shell code and docs are merged.

@aescolar
Copy link
Member Author

@nashif / @carlescufi : If either of you does not have anything against, feel free to press the button.

@carlescufi carlescufi merged commit bded528 into zephyrproject-rtos:master Sep 27, 2018
@aescolar aescolar deleted the native_uart branch September 27, 2018 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native port Host native arch port (native_sim) area: UART Universal Asynchronous Receiver-Transmitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants