You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Fotis Panagiotopoulos <f....@gmail.com> on 2021/11/03 10:36:48 UTC

Simulator - UART

Hello everyone!

I am working on a new NuttX-based firmware.
On this application a hardware board will be able to communicate through
UART with a Linux system.

There is still some testing and development to be done on this Linux
program, so I thought that this is a great use for the simulator. Instead
of passing actual hardware boards to every developer, they can start-off
with a simulator app for the first steps.

I am also thinking that later, appropriate tests may be included in our CI.
That's much more convenient than actually connecting hardware on the CI
server.

I tried to build the firmware for the simulator target.
It was quite straightforward, and everything works correctly (with mocked
board drivers of course).

Now I need to implement this UART communication with the host.
I am not sure if this is possible, is it?

I saw that there are simulated UARTs, but they are poorly documented, and I
am not sure whether this is their purpose.
I tried using them, but I didn't have any luck, NuttX seems that it cannot
open the device for writing.

Any ideas?

Re: Simulator - UART

Posted by Tomasz CEDRO <to...@cedro.info>.
On Thu, Nov 4, 2021 at 11:19 AM Fotis Panagiotopoulos wrote:
> > No, The emulated UART is designed to work with the real UART on host.
> Oh, now I understand how it works!
>
> In my case, however, I also wanted a "simulated" UART, not a physical one.
> So I run:
>
> socat PTY,link=/dev/ttySIM0 PTY,link=/dev/ttyNX
>
> and indeed our software was perfectly capable of communicating with the
> simulation.
> Both softwares now run unaltered, both "thinking" of talking to each other
> through a UART, as in a the real-world case.
> Perfect!

SOCAT ROX! Thanks! :-)


> Needless to say that this is a killer feature of NuttX.
> It opens up a huge array of possibilities for testing (especially automated
> / CI), and development without the strict need of hardware.

Yup :-) NuttX amazes me more and more too :-)


-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Re: Simulator - UART

Posted by Xiang Xiao <xi...@gmail.com>.
Yes, this case is also in the initial design but we never used this before.
Glad to see it work for you.

On Thu, Nov 4, 2021 at 6:19 PM Fotis Panagiotopoulos <f....@gmail.com>
wrote:

> > No, The emulated UART is designed to work with the real UART on host.
> Oh, now I understand how it works!
>
> In my case, however, I also wanted a "simulated" UART, not a physical one.
> So I run:
>
> socat PTY,link=/dev/ttySIM0 PTY,link=/dev/ttyNX
>
> and indeed our software was perfectly capable of communicating with the
> simulation.
> Both softwares now run unaltered, both "thinking" of talking to each other
> through a UART, as in a the real-world case.
> Perfect!
>
> Needless to say that this is a killer feature of NuttX.
> It opens up a huge array of possibilities for testing (especially automated
> / CI), and development without the strict need of hardware.
>
> Thank you all!
>
>
> Στις Τετ, 3 Νοε 2021 στις 3:36 μ.μ., ο/η Alan Carvalho de Assis <
> acassis@gmail.com> έγραψε:
>
> > On 11/3/21, Xiang Xiao <xi...@gmail.com> wrote:
> > > On Wed, Nov 3, 2021 at 8:06 PM Tomasz CEDRO <to...@cedro.info> wrote:
> > >
> > >> On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
> > >> > I am working on a new NuttX-based firmware.
> > >> > On this application a hardware board will be able to communicate
> > >> > through
> > >> > UART with a Linux system.
> > >> >
> > >> > There is still some testing and development to be done on this Linux
> > >> > program, so I thought that this is a great use for the simulator.
> > >> > Instead
> > >> > of passing actual hardware boards to every developer, they can
> > >> > start-off
> > >> > with a simulator app for the first steps.
> > >>
> > >> This sounds like a very useful feature! I have no experience yet in
> > >> this area but sounds like local or network socket could be useful here
> > >> to pipe UART from/to the simulator? :-)
> > >>
> > >
> > > You can get the network capability with:
> > > 1.Through tap device
> > >    incubator-nuttx/NETWORK-LINUX.txt at master · apache/incubator-nuttx
> > > (github.com)
> > > <
> >
> https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-LINUX.txt
> > >
> > > 2.Through VPN
> > >    incubator-nuttx/NETWORK-VPNKIT.txt at master ·
> apache/incubator-nuttx
> > > (github.com)
> > > <
> >
> https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-VPNKIT.txt
> > >
> > > 3.Through usrsock
> > > All possible option is documented here:
> > > incubator-nuttx/Kconfig at master · apache/incubator-nuttx (github.com
> )
> > > <
> >
> https://github.com/apache/incubator-nuttx/blob/master/arch/sim/Kconfig#L137-L177
> > >
> > >
> > > You can even simulate the functional audio/display/touchscreen and
> > SMP/AMP
> > > with sim.
> > >
> >
> > Also from any board running NuttX with network support you can use
> > FIFO e netcat to get data directly from your application output this
> > say:
> >
> > nsh> mkfifo /dev/fifo
> > nsh> myapp > /dev/fifo &
> > nsh> netcat 192.168.0.15 10123 /dev/fifo
> >
> >
> >
> https://acassis.wordpress.com/2021/03/04/using-fifo-on-nuttx-to-send-data-from-your-board-to-computer/
> >
> > Then in your computer (IP 192.168.0.15 in this example) you just run:
> >
> > $ nc -l 10123
> >
> > BR,
> >
> > Alan
> >
>

Re: Simulator - UART

Posted by Fotis Panagiotopoulos <f....@gmail.com>.
> No, The emulated UART is designed to work with the real UART on host.
Oh, now I understand how it works!

In my case, however, I also wanted a "simulated" UART, not a physical one.
So I run:

socat PTY,link=/dev/ttySIM0 PTY,link=/dev/ttyNX

and indeed our software was perfectly capable of communicating with the
simulation.
Both softwares now run unaltered, both "thinking" of talking to each other
through a UART, as in a the real-world case.
Perfect!

Needless to say that this is a killer feature of NuttX.
It opens up a huge array of possibilities for testing (especially automated
/ CI), and development without the strict need of hardware.

Thank you all!


Στις Τετ, 3 Νοε 2021 στις 3:36 μ.μ., ο/η Alan Carvalho de Assis <
acassis@gmail.com> έγραψε:

> On 11/3/21, Xiang Xiao <xi...@gmail.com> wrote:
> > On Wed, Nov 3, 2021 at 8:06 PM Tomasz CEDRO <to...@cedro.info> wrote:
> >
> >> On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
> >> > I am working on a new NuttX-based firmware.
> >> > On this application a hardware board will be able to communicate
> >> > through
> >> > UART with a Linux system.
> >> >
> >> > There is still some testing and development to be done on this Linux
> >> > program, so I thought that this is a great use for the simulator.
> >> > Instead
> >> > of passing actual hardware boards to every developer, they can
> >> > start-off
> >> > with a simulator app for the first steps.
> >>
> >> This sounds like a very useful feature! I have no experience yet in
> >> this area but sounds like local or network socket could be useful here
> >> to pipe UART from/to the simulator? :-)
> >>
> >
> > You can get the network capability with:
> > 1.Through tap device
> >    incubator-nuttx/NETWORK-LINUX.txt at master · apache/incubator-nuttx
> > (github.com)
> > <
> https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-LINUX.txt
> >
> > 2.Through VPN
> >    incubator-nuttx/NETWORK-VPNKIT.txt at master · apache/incubator-nuttx
> > (github.com)
> > <
> https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-VPNKIT.txt
> >
> > 3.Through usrsock
> > All possible option is documented here:
> > incubator-nuttx/Kconfig at master · apache/incubator-nuttx (github.com)
> > <
> https://github.com/apache/incubator-nuttx/blob/master/arch/sim/Kconfig#L137-L177
> >
> >
> > You can even simulate the functional audio/display/touchscreen and
> SMP/AMP
> > with sim.
> >
>
> Also from any board running NuttX with network support you can use
> FIFO e netcat to get data directly from your application output this
> say:
>
> nsh> mkfifo /dev/fifo
> nsh> myapp > /dev/fifo &
> nsh> netcat 192.168.0.15 10123 /dev/fifo
>
>
> https://acassis.wordpress.com/2021/03/04/using-fifo-on-nuttx-to-send-data-from-your-board-to-computer/
>
> Then in your computer (IP 192.168.0.15 in this example) you just run:
>
> $ nc -l 10123
>
> BR,
>
> Alan
>

Re: Simulator - UART

Posted by Alan Carvalho de Assis <ac...@gmail.com>.
On 11/3/21, Xiang Xiao <xi...@gmail.com> wrote:
> On Wed, Nov 3, 2021 at 8:06 PM Tomasz CEDRO <to...@cedro.info> wrote:
>
>> On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
>> > I am working on a new NuttX-based firmware.
>> > On this application a hardware board will be able to communicate
>> > through
>> > UART with a Linux system.
>> >
>> > There is still some testing and development to be done on this Linux
>> > program, so I thought that this is a great use for the simulator.
>> > Instead
>> > of passing actual hardware boards to every developer, they can
>> > start-off
>> > with a simulator app for the first steps.
>>
>> This sounds like a very useful feature! I have no experience yet in
>> this area but sounds like local or network socket could be useful here
>> to pipe UART from/to the simulator? :-)
>>
>
> You can get the network capability with:
> 1.Through tap device
>    incubator-nuttx/NETWORK-LINUX.txt at master · apache/incubator-nuttx
> (github.com)
> <https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-LINUX.txt>
> 2.Through VPN
>    incubator-nuttx/NETWORK-VPNKIT.txt at master · apache/incubator-nuttx
> (github.com)
> <https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-VPNKIT.txt>
> 3.Through usrsock
> All possible option is documented here:
> incubator-nuttx/Kconfig at master · apache/incubator-nuttx (github.com)
> <https://github.com/apache/incubator-nuttx/blob/master/arch/sim/Kconfig#L137-L177>
>
> You can even simulate the functional audio/display/touchscreen and SMP/AMP
> with sim.
>

Also from any board running NuttX with network support you can use
FIFO e netcat to get data directly from your application output this
say:

nsh> mkfifo /dev/fifo
nsh> myapp > /dev/fifo &
nsh> netcat 192.168.0.15 10123 /dev/fifo

https://acassis.wordpress.com/2021/03/04/using-fifo-on-nuttx-to-send-data-from-your-board-to-computer/

Then in your computer (IP 192.168.0.15 in this example) you just run:

$ nc -l 10123

BR,

Alan

Re: Simulator - UART

Posted by Xiang Xiao <xi...@gmail.com>.
On Wed, Nov 3, 2021 at 8:06 PM Tomasz CEDRO <to...@cedro.info> wrote:

> On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
> > I am working on a new NuttX-based firmware.
> > On this application a hardware board will be able to communicate through
> > UART with a Linux system.
> >
> > There is still some testing and development to be done on this Linux
> > program, so I thought that this is a great use for the simulator. Instead
> > of passing actual hardware boards to every developer, they can start-off
> > with a simulator app for the first steps.
>
> This sounds like a very useful feature! I have no experience yet in
> this area but sounds like local or network socket could be useful here
> to pipe UART from/to the simulator? :-)
>

You can get the network capability with:
1.Through tap device
   incubator-nuttx/NETWORK-LINUX.txt at master · apache/incubator-nuttx
(github.com)
<https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-LINUX.txt>
2.Through VPN
   incubator-nuttx/NETWORK-VPNKIT.txt at master · apache/incubator-nuttx
(github.com)
<https://github.com/apache/incubator-nuttx/blob/master/boards/sim/sim/sim/NETWORK-VPNKIT.txt>
3.Through usrsock
All possible option is documented here:
incubator-nuttx/Kconfig at master · apache/incubator-nuttx (github.com)
<https://github.com/apache/incubator-nuttx/blob/master/arch/sim/Kconfig#L137-L177>

You can even simulate the functional audio/display/touchscreen and SMP/AMP
with sim.


> --
> CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
>

Re: Simulator - UART

Posted by Alan Carvalho de Assis <ac...@gmail.com>.
s/look a look/took a look/

On 11/3/21, Alan Carvalho de Assis <ac...@gmail.com> wrote:
> Hi Fotis and Tomasz,
>
> On 11/3/21, Tomasz CEDRO <to...@cedro.info> wrote:
>> On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
>>> I am working on a new NuttX-based firmware.
>>> On this application a hardware board will be able to communicate through
>>> UART with a Linux system.
>>>
>>> There is still some testing and development to be done on this Linux
>>> program, so I thought that this is a great use for the simulator.
>>> Instead
>>> of passing actual hardware boards to every developer, they can start-off
>>> with a simulator app for the first steps.
>>
>> This sounds like a very useful feature! I have no experience yet in
>> this area but sounds like local or network socket could be useful here
>> to pipe UART from/to the simulator? :-)
>>
>
> I look a look at the simulated UART few week ago and I didn't find a
> way to use it with an external USB/Serial adapter. Seams like the
> emulated UART is used mostly to fake a UART to NuttX applications, not
> to real communication with external UART like we have to I2C and SPI.
>
> I think we need some glue just to let NuttX running on simulator get
> access to the real UART device of the host.
>
> Xiang, did you (or someone of your team) already use the real host
> UART with the simulator?
>
> BR,
>
> Alan
>

Re: Simulator - UART

Posted by Xiang Xiao <xi...@gmail.com>.
On Wed, Nov 3, 2021 at 8:14 PM Alan Carvalho de Assis <ac...@gmail.com>
wrote:

> Hi Fotis and Tomasz,
>
> On 11/3/21, Tomasz CEDRO <to...@cedro.info> wrote:
> > On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
> >> I am working on a new NuttX-based firmware.
> >> On this application a hardware board will be able to communicate through
> >> UART with a Linux system.
> >>
> >> There is still some testing and development to be done on this Linux
> >> program, so I thought that this is a great use for the simulator.
> Instead
> >> of passing actual hardware boards to every developer, they can start-off
> >> with a simulator app for the first steps.
> >
> > This sounds like a very useful feature! I have no experience yet in
> > this area but sounds like local or network socket could be useful here
> > to pipe UART from/to the simulator? :-)
> >
>
> I look a look at the simulated UART few week ago and I didn't find a
> way to use it with an external USB/Serial adapter. Seams like the
> emulated UART is used mostly to fake a UART to NuttX applications, not
> to real communication with external UART like we have to I2C and SPI.
>
>
No, The emulated UART is designed to work with the real UART on host.


> I think we need some glue just to let NuttX running on simulator get
> access to the real UART device of the host.
>
>
You can access the host UART through configuration without any code change.


> Xiang, did you (or someone of your team) already use the real host
> UART with the simulator?
>

Yes, we run a sensor/gps program in NuttX, and talk with the external
hardware module through host UART.
Here is the setup you need to change:

   1. set CONFIG_SIM_UART_NUMBER to 1
   2. set CONFIG_SIM_UART0_NAME to the host uart path(e.g. /dev/ttyUSB0)

If you want to access more host UART at the same time:

   1. Increase CONFIG_SIM_UART_NUMBER
   2. Set CONFIG_SIM_UART1_NAME,  CONFIG_SIM_UART2_NAME... according

You can access the host UART inside simulator with the same path(e.g.
/dev/ttyUSB0).


> BR,
>
> Alan
>

Re: Simulator - UART

Posted by Alan Carvalho de Assis <ac...@gmail.com>.
Hi Fotis and Tomasz,

On 11/3/21, Tomasz CEDRO <to...@cedro.info> wrote:
> On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
>> I am working on a new NuttX-based firmware.
>> On this application a hardware board will be able to communicate through
>> UART with a Linux system.
>>
>> There is still some testing and development to be done on this Linux
>> program, so I thought that this is a great use for the simulator. Instead
>> of passing actual hardware boards to every developer, they can start-off
>> with a simulator app for the first steps.
>
> This sounds like a very useful feature! I have no experience yet in
> this area but sounds like local or network socket could be useful here
> to pipe UART from/to the simulator? :-)
>

I look a look at the simulated UART few week ago and I didn't find a
way to use it with an external USB/Serial adapter. Seams like the
emulated UART is used mostly to fake a UART to NuttX applications, not
to real communication with external UART like we have to I2C and SPI.

I think we need some glue just to let NuttX running on simulator get
access to the real UART device of the host.

Xiang, did you (or someone of your team) already use the real host
UART with the simulator?

BR,

Alan

Re: Simulator - UART

Posted by Tomasz CEDRO <to...@cedro.info>.
On Wed, Nov 3, 2021 at 11:37 AM Fotis Panagiotopoulos wrote:
> I am working on a new NuttX-based firmware.
> On this application a hardware board will be able to communicate through
> UART with a Linux system.
>
> There is still some testing and development to be done on this Linux
> program, so I thought that this is a great use for the simulator. Instead
> of passing actual hardware boards to every developer, they can start-off
> with a simulator app for the first steps.

This sounds like a very useful feature! I have no experience yet in
this area but sounds like local or network socket could be useful here
to pipe UART from/to the simulator? :-)

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info