Re: Using C++ STL in Nuttx

2021-03-17 Thread Flavio Castro Alves Filho
Hello Xiang,

I could finally build an C++ project using CMake and exported NuttX.
  - Before that, I made a test creating the same project inside the
NuttX apps structure, and it worked fine.

My sample project is here:
https://github.com/Phi-Innovations/nuttx-apps/tree/main/hellocpp

I compiled JsonCpp (https://github.com/nlohmann/json) together and it
worked fine.

Thank you for all your support.

Best regards,

Flavio


Em ter., 16 de mar. de 2021 às 21:04, Flavio Castro Alves Filho
 escreveu:
>
> Xiang,
>
> I believe the problem was related to something on my branch.
>
> I was using a quite old version, based on release 10 branch.
>
> Now using master as branch, the testlibcxx compiled correctly.
> Tomorrow I will try my experiments and report here.
>
> Best regards,
>
> Flavio
>
> Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
>  escreveu:
> >
> > Try to remove CONFIG_ARCH_FLOAT_H
> >
> > On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> > flavio.al...@gmail.com> wrote:
> >
> > > Hello Xiang,
> > >
> > > It is still not working. The error persists.
> > >
> > > Here is my defconfig file:
> > >
> > > #
> > > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > > #
> > > # You can use "make menuconfig" to make any modifications to the
> > > installed .config file.
> > > # You can then do "make savedefconfig" to generate a new defconfig
> > > file that includes your
> > > # modifications.
> > > #
> > > # CONFIG_ARCH_FPU is not set
> > > CONFIG_ARCH="arm"
> > > CONFIG_ARCH_BOARD="stm32f4discovery"
> > > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > > CONFIG_ARCH_CHIP="stm32"
> > > CONFIG_ARCH_CHIP_STM32=y
> > > CONFIG_ARCH_CHIP_STM32F407VG=y
> > > CONFIG_ARCH_FLOAT_H=y
> > > CONFIG_ARCH_STACKDUMP=y
> > > CONFIG_BOARD_LOOPSPERMSEC=16717
> > > CONFIG_BUILTIN=y
> > > CONFIG_C99_BOOL8=y
> > > CONFIG_DISABLE_MOUNTPOINT=y
> > > CONFIG_EXAMPLES_HELLOXX=y
> > > CONFIG_HAVE_CXX=y
> > > CONFIG_INTELHEX_BINARY=y
> > > CONFIG_LIBCXX=y
> > > CONFIG_LIBC_FLOATINGPOINT=y
> > > CONFIG_LIBC_LOCALTIME=y
> > > CONFIG_MAX_TASKS=16
> > > CONFIG_MM_REGIONS=2
> > > CONFIG_NFILE_DESCRIPTORS=8
> > > CONFIG_NSH_BUILTIN_APPS=y
> > > CONFIG_NSH_FILEIOSIZE=512
> > > CONFIG_PREALLOC_TIMERS=4
> > > CONFIG_RAM_SIZE=114688
> > > CONFIG_RAM_START=0x2000
> > > CONFIG_RAW_BINARY=y
> > > CONFIG_RR_INTERVAL=200
> > > CONFIG_SCHED_ONEXIT=y
> > > CONFIG_SCHED_ONEXIT_MAX=4
> > > CONFIG_SCHED_WAITPID=y
> > > CONFIG_SDCLONE_DISABLE=y
> > > CONFIG_START_DAY=2
> > > CONFIG_START_MONTH=11
> > > CONFIG_START_YEAR=2012
> > > CONFIG_STM32_JTAG_SW_ENABLE=y
> > > CONFIG_STM32_USART2=y
> > > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > > CONFIG_SYSTEM_NSH=y
> > > CONFIG_USART2_RXBUFSIZE=128
> > > CONFIG_USART2_SERIAL_CONSOLE=y
> > > CONFIG_USART2_TXBUFSIZE=128
> > > CONFIG_USER_ENTRYPOINT="nsh_main"
> > >
> > > Any idea of what is missing?
> > >
> > > Best regards,
> > >
> > > Flavio
> > >
> > > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > >  escreveu:
> > > >
> > > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > > flavio.al...@gmail.com> wrote:
> > > >
> > > > > Hello Xiang,
> > > > >
> > > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > >  escreveu:
> > > > > >
> > > > > > On Tu
> > > > > > >
> > > > > > This project use the modern C++ feature, so you must enable llvm
> > > > > > ibc++(CONFIG_LIBCXX=y)
> > > > >
> > > > > I tried a new build, executing:
> > > > >
> > > > > $ make distclean
> > > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > > $ make
> > > > >
> > > > > I can see the library being downloaded from git, but it is not
> > > compiling.
> > > > >
> > > > > In file included from
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > > >  from libcxx/src/random.cpp:16:
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global scope:
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > > '::signbit' has not been declared
> > > > >   321 | using ::signbit;
> > > > >   | ^~~
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > > '::fpclassify' has not been declared
> > > > >   322 | using ::fpclassify;
> > > > >   | ^~
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > > '::isnormal' has not been declared
> > > > >   326 | using ::isnormal;
> > > > >   | ^~~~
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > > > '::isgreater' has not been declared
> > > > >   327 | using ::isgreater;
> > > > >
> > > > > How should I solve this issue?
> > > > >
> > > >
> > > > CONFIG_LIBM has to be disabled, since NuttX match library implementation
> > > > lacks many standard defined functions which is required by the new 
> > > > libc++
> > > > library.
> > > >
> > > >
> > > > >
> > > > > > >
> > > > > > You need tell compiler stop to search the toolchain provided c++
> > > library
> > > 

Re: Using C++ STL in Nuttx

2021-03-17 Thread Xiang Xiao
Good news. It will be great if you can document your experience in the
Documentation folder when you find some free time.

On Wed, Mar 17, 2021 at 9:54 PM Flavio Castro Alves Filho <
flavio.al...@gmail.com> wrote:

> Hello Xiang,
>
> I could finally build an C++ project using CMake and exported NuttX.
>   - Before that, I made a test creating the same project inside the
> NuttX apps structure, and it worked fine.
>
> My sample project is here:
> https://github.com/Phi-Innovations/nuttx-apps/tree/main/hellocpp
>
> I compiled JsonCpp (https://github.com/nlohmann/json) together and it
> worked fine.
>
> Thank you for all your support.
>
> Best regards,
>
> Flavio
>
>
> Em ter., 16 de mar. de 2021 às 21:04, Flavio Castro Alves Filho
>  escreveu:
> >
> > Xiang,
> >
> > I believe the problem was related to something on my branch.
> >
> > I was using a quite old version, based on release 10 branch.
> >
> > Now using master as branch, the testlibcxx compiled correctly.
> > Tomorrow I will try my experiments and report here.
> >
> > Best regards,
> >
> > Flavio
> >
> > Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
> >  escreveu:
> > >
> > > Try to remove CONFIG_ARCH_FLOAT_H
> > >
> > > On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> > > flavio.al...@gmail.com> wrote:
> > >
> > > > Hello Xiang,
> > > >
> > > > It is still not working. The error persists.
> > > >
> > > > Here is my defconfig file:
> > > >
> > > > #
> > > > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > > > #
> > > > # You can use "make menuconfig" to make any modifications to the
> > > > installed .config file.
> > > > # You can then do "make savedefconfig" to generate a new defconfig
> > > > file that includes your
> > > > # modifications.
> > > > #
> > > > # CONFIG_ARCH_FPU is not set
> > > > CONFIG_ARCH="arm"
> > > > CONFIG_ARCH_BOARD="stm32f4discovery"
> > > > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > > > CONFIG_ARCH_CHIP="stm32"
> > > > CONFIG_ARCH_CHIP_STM32=y
> > > > CONFIG_ARCH_CHIP_STM32F407VG=y
> > > > CONFIG_ARCH_FLOAT_H=y
> > > > CONFIG_ARCH_STACKDUMP=y
> > > > CONFIG_BOARD_LOOPSPERMSEC=16717
> > > > CONFIG_BUILTIN=y
> > > > CONFIG_C99_BOOL8=y
> > > > CONFIG_DISABLE_MOUNTPOINT=y
> > > > CONFIG_EXAMPLES_HELLOXX=y
> > > > CONFIG_HAVE_CXX=y
> > > > CONFIG_INTELHEX_BINARY=y
> > > > CONFIG_LIBCXX=y
> > > > CONFIG_LIBC_FLOATINGPOINT=y
> > > > CONFIG_LIBC_LOCALTIME=y
> > > > CONFIG_MAX_TASKS=16
> > > > CONFIG_MM_REGIONS=2
> > > > CONFIG_NFILE_DESCRIPTORS=8
> > > > CONFIG_NSH_BUILTIN_APPS=y
> > > > CONFIG_NSH_FILEIOSIZE=512
> > > > CONFIG_PREALLOC_TIMERS=4
> > > > CONFIG_RAM_SIZE=114688
> > > > CONFIG_RAM_START=0x2000
> > > > CONFIG_RAW_BINARY=y
> > > > CONFIG_RR_INTERVAL=200
> > > > CONFIG_SCHED_ONEXIT=y
> > > > CONFIG_SCHED_ONEXIT_MAX=4
> > > > CONFIG_SCHED_WAITPID=y
> > > > CONFIG_SDCLONE_DISABLE=y
> > > > CONFIG_START_DAY=2
> > > > CONFIG_START_MONTH=11
> > > > CONFIG_START_YEAR=2012
> > > > CONFIG_STM32_JTAG_SW_ENABLE=y
> > > > CONFIG_STM32_USART2=y
> > > > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > > > CONFIG_SYSTEM_NSH=y
> > > > CONFIG_USART2_RXBUFSIZE=128
> > > > CONFIG_USART2_SERIAL_CONSOLE=y
> > > > CONFIG_USART2_TXBUFSIZE=128
> > > > CONFIG_USER_ENTRYPOINT="nsh_main"
> > > >
> > > > Any idea of what is missing?
> > > >
> > > > Best regards,
> > > >
> > > > Flavio
> > > >
> > > > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > > >  escreveu:
> > > > >
> > > > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > > > flavio.al...@gmail.com> wrote:
> > > > >
> > > > > > Hello Xiang,
> > > > > >
> > > > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > > >  escreveu:
> > > > > > >
> > > > > > > On Tu
> > > > > > > >
> > > > > > > This project use the modern C++ feature, so you must enable
> llvm
> > > > > > > ibc++(CONFIG_LIBCXX=y)
> > > > > >
> > > > > > I tried a new build, executing:
> > > > > >
> > > > > > $ make distclean
> > > > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > > > $ make
> > > > > >
> > > > > > I can see the library being downloaded from git, but it is not
> > > > compiling.
> > > > > >
> > > > > > In file included from
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > > > >  from libcxx/src/random.cpp:16:
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global
> scope:
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > > > '::signbit' has not been declared
> > > > > >   321 | using ::signbit;
> > > > > >   | ^~~
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > > > '::fpclassify' has not been declared
> > > > > >   322 | using ::fpclassify;
> > > > > >   | ^~
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > > > '::isnormal' has not been declared
> > > > > >   326 | using ::isnormal;
> > > > > >   | ^~~~
> > > > > > /home/ubuntu/nuttx_ws/nuttx/

Re: Tasks software watchdog timer

2021-03-17 Thread Fotis Panagiotopoulos
These are all good ideas, thank you!

I am considering the posix timer approach.

I would like to ask, are there cases where the timer may not fire?
Is it guaranteed to fire, for example, if the thread is in a dead lock, or
if a higher priority thread has caused CPU starvation, or similar cases?

Στις Δευ, 15 Μαρ 2021 στις 10:24 μ.μ., ο/η Sara da Cunha Monteiro de Souza <
saramonteirosouz...@gmail.com> έγραψε:

> Please,
> take a look at the watcher/watched examples:
>
> https://github.com/apache/incubator-nuttx-apps/tree/master/examples#watcher-watcher--watched
> .
> The watcher uses a Hardware WDT to monitor the subscribed watched tasks.
> In this case, the "watched" example  have 4 subscribed tasks.
> Note: these examples are going to be changed these days. I'll submit a PR
> to fix a issue in the print task.
>
> Em seg., 15 de mar. de 2021 às 06:36, Pelle Windestam <
> pelle.windes...@tagmaster.com> escreveu:
>
> > > > If you want to catch some task/thread in an infinite loop, the
> hardware
> > > > watchdog monitor in nuttx can do it for you.
> > >
> > > If the hardware watchdog is fed from multiple sources, all of them need
> > to
> > > fail. Not just one of them.
> > > Do you have anything else in mind?
> > >
> > > > You don't need a special timer here, the posix timer can work very
> > well:
> > > >
> > > >1. Create a watchdog timer by timer_create
> > > >2. Feed the timer periodically through timer_settime
> > > >3. Register a timeout signal handler
> > > >4. Call exit/abort in signal handler
> > >
> > > This is a nice idea, thank you.
> > > I didn't think of it before.
> >
> > We have a similar watchdog functionality built into a driver. Via an
> > ioctl()-call it is possible to register new individual "watchdogs" that
> are
> > fed via another ioctl()-call. This way each thread that we want to
> monitor
> > will register its own watchdog via the ioctl() interface, and the driver
> > will keep track of which thread failed to feed feed it.
> >
> > //Pelle
> >
>


Re: Tasks software watchdog timer

2021-03-17 Thread Gregory Nutt




I would like to ask, are there cases where the timer may not fire?
Is it guaranteed to fire, for example, if the thread is in a dead lock,


The signal will be delivered to some thread in the task group, so in 
that sense it will "fire".  However, it may be the case that the the 
dead locked thread cannot respond to the signal.  There are many 
possible scenarios.


If you setup a signal handler to run and the task is deadlocked waiting 
on a semaphore that receives the signal, the semaphore wait will return 
EINTR and the signal handler will run.  But, I can imagine other cases 
where the task might not respond to the signal.


In a multi-threaded task group, it may may not be the waiting thread 
that receives the signal, however.  Multi-threaded signal delivery is 
complex and non-obvious.



or if a higher priority thread has caused CPU starvation, or similar cases?


Certainly the signal handling will typically pend and be delayed.  POSIX 
requires that signal events be queued only at least one deep; NuttX 
queues signal action events but not other signal events (as I recall).  
The behavior will depend on the sigprocmask and might not pend at all!


Signal handling is complex and this was written from my recollection 
which may be flawed.