usb device network on nrf52840 platform


cpmcparland@...
 

Has anyone had any luck adding usb device networking to a project outside of samples/net/echo_server ?
I have built the above project with -DCONF_FILE="prj.conf overlay-netusb.conf" and it appears to work correctly.
But, when I add the overlay-netusb.conf file to another project - in particular, samples/net/sntp_client, the file nrfx_usbd.c
fails to compile.

The compile problem shows up when compiling nrfx_usbd.c (which compiles fine in the echo_server project).  There are
a number of complaints; but I suspect they have the same root cause - undiscovered as yet!

In file included from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/nrfx.h:37:0,
                 from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:32:
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:161:5: error: expected declaration specifiers or ‘...’ before ‘(’ token
     ((NRF_USBD_EPIN_CHECK(ep) ? NRFX_USBD_EPIN_BITPOS_0 : NRFX_USBD_EPOUT_BITPOS_0) \
     ^
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/./nrfx_glue.h:65:23: note: in definition of macro ‘NRFX_STATIC_ASSERT’
         static_assert(expression, "assertion failed")
                       ^~~~~~~~~~
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:185:20: note: in expansion of macro ‘NRFX_USBD_EP_BITPOS’
 NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN1)  == USBD_EPDATASTATUS_EPIN1_Pos );
                    ^~~~~~~~~~~~~~~~~~~

From what I can see, macro processor can't find a symbol it needs for evaluation.  I think most of the include files are actually static and not created by cmake.
So, I don't expect any problems there. The .config files generated for both projects are the same viz. networking and the generated dts .h files for both projects are identical.

Has anyone integrated USB device networking into a non sample project.

Thanks,
Chuck McP


cpmcparland@...
 

Well, as is usually the case, as soon as I'm convinced I'm stuck and send off a note, I try something else and make a bit
of progress......sigh.  The new project I was trying to integrate with an ecm usb network device interface had the following in prj.conf:

CONFIG_NEWLIB_LIBC=y

As soon as I removed that line, nrfx_usbd.c compiled - as did everything else.  The requirement for newlib may have been historical
and possibly irrelevant now.  I was doing some testing with a 3rd party source code package.  But, I don't know if this constitutes an
issue with the newlib code in the present distribution (1_13_99).  Can't say that my code is now functional, but the bizarre compiler behavior has disappeared. 
So, I think an interaction with the current newlib code is the cause of my initial problem.

Any comments on this are appreciated.  I may need newlib for compatibility reasons later on....would like to understand what's going on
here.

Regards,
Chuck McP


Puzdrowski, Andrzej
 

Hi

 

I’m unable to reproduce this problem – I mean that I did not encounter problem compiling usbd along with newlibc.

Can you point prj.conf you used, or even the project?

 

From: devel@... [mailto:devel@...] On Behalf Of cpmcparland@...
Sent: Tuesday, November 06, 2018 12:41 AM
To: devel@...
Subject: Re: [Zephyr-devel] usb device network on nrf52840 platform

 

Well, as is usually the case, as soon as I'm convinced I'm stuck and send off a note, I try something else and make a bit
of progress......sigh.  The new project I was trying to integrate with an ecm usb network device interface had the following in prj.conf:

CONFIG_NEWLIB_LIBC=y

As soon as I removed that line, nrfx_usbd.c compiled - as did everything else.  The requirement for newlib may have been historical
and possibly irrelevant now.  I was doing some testing with a 3rd party source code package.  But, I don't know if this constitutes an
issue with the newlib code in the present distribution (1_13_99).  Can't say that my code is now functional, but the bizarre compiler behavior has disappeared. 
So, I think an interaction with the current newlib code is the cause of my initial problem.

Any comments on this are appreciated.  I may need newlib for compatibility reasons later on....would like to understand what's going on
here.

Regards,
Chuck McP


cpmcparland@...
 

Andrezej, thanks for looking at this.  To keep things simple, I went back to the sample project:

samples/net/echo_server

With the exception of adding the first line, I don't believe I have changed anything from the zephyr clone I
made a few weeks ago (1_13_99).  Here's the prj.conf.

************************************************
#CONFIG_NEWLIB_LIBC=y
# Generic networking options
CONFIG_NETWORKING=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
#CONFIG_NET_IPV6=y
CONFIG_NET_IPV4=y
#CONFIG_NET_DHCPV4=y

# Kernel options
#CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
#CONFIG_INIT_STACKS=y

# Logging
CONFIG_NET_LOG=y
CONFIG_LOG=y
CONFIG_NET_STATISTICS=y
CONFIG_PRINTK=y

# Network buffers
CONFIG_NET_PKT_RX_COUNT=14
CONFIG_NET_PKT_TX_COUNT=14
CONFIG_NET_BUF_RX_COUNT=36
CONFIG_NET_BUF_TX_COUNT=36
CONFIG_NET_CONTEXT_NET_PKT_POOL=y

# IP address options
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
#CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
CONFIG_NET_MAX_CONTEXTS=10

# Network shell
CONFIG_NET_SHELL=y

# Network application options and configuration
CONFIG_NET_APP_SERVER=y
CONFIG_NET_CONFIG_SETTINGS=y
#CONFIG_NET_CONFIG_NEED_IPV6=y
CONFIG_NET_CONFIG_NEED_IPV4=y
#CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
#CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"

***************************************************
When the first line is uncommented, I get compile-time errors like the following (simple variations not copied here-
but, I can send complete listing if needed).

$cmake -DCONF_FILE="prj.conf overlay-netusb.conf" -DBOARD=nrf52840_pca10056 ../../
.... cmake completes successfully ...
$make
Scanning dependencies of target kobj_types_h_target
[  0%] Generating include/generated/kobj-types-enum.h, include/generated/otype-to-str.h
[  0%] Built target kobj_types_h_target
Scanning dependencies of target syscall_list_h_target
[  1%] Generating misc/generated/syscalls.json
[  1%] Generating include/generated/syscall_dispatch.c, include/generated/syscall_list.h
[  2%] Built target syscall_list_h_target
Scanning dependencies of target syscall_macros_h_target
[  2%] Generating include/generated/syscall_macros.h
[  2%] Built target syscall_macros_h_target
Scanning dependencies of target driver_validation_h_target
[  2%] Generating include/generated/driver-validation.h
[  2%] Built target driver_validation_h_target
Scanning dependencies of target offsets
[  2%] Building C object zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.obj
[  3%] Linking C static library liboffsets.a
[  3%] Built target offsets
Scanning dependencies of target offsets_h
[  3%] Generating include/generated/offsets.h
[  3%] Built target offsets_h
Scanning dependencies of target app
[  3%] Building C object CMakeFiles/app.dir/src/echo-server.c.obj
[  4%] Building C object CMakeFiles/app.dir/src/udp.c.obj
[  4%] Building C object CMakeFiles/app.dir/src/tcp.c.obj
[  5%] Linking C static library libapp.a
[  5%] Built target app
Scanning dependencies of target zephyr
[  6%] Building C object zephyr/CMakeFiles/zephyr.dir/arch/common/isr_tables.c.obj
[  7%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/thread_entry.c.obj
[  7%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/crc/crc32_sw.c.obj
[  8%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/crc/crc16_sw.c.obj
[  8%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/crc/crc8_sw.c.obj
[  9%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/mempool/mempool.c.obj
[  9%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/rbtree/rb.c.obj
[ 10%] Building C object zephyr/CMakeFiles/zephyr.dir/misc/printk.c.obj
[ 11%] Building C object zephyr/CMakeFiles/zephyr.dir/misc/generated/configs.c.obj
[ 11%] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/nordic_nrf/nrf52/power.c.obj
[ 12%] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/nordic_nrf/nrf52/soc.c.obj
[ 12%] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/nordic_nrf/nrf52/mpu_regions.c.obj
[ 13%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/nordic/nrfx/mdk/system_nrf52840.c.obj
[ 13%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/nordic/nrfx_glue.c.obj
[ 14%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/nordic/nrfx/drivers/src/nrfx_systick.c.obj
[ 15%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c.obj

In file included from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/nrfx.h:37:0,
                 from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:32:
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:161:5: error: expected declaration specifiers or ‘...’ before ‘(’ token
     ((NRF_USBD_EPIN_CHECK(ep) ? NRFX_USBD_EPIN_BITPOS_0 : NRFX_USBD_EPOUT_BITPOS_0) \
     ^
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/./nrfx_glue.h:65:23: note: in definition of macro ‘NRFX_STATIC_ASSERT’
         static_assert(expression, "assertion failed")
                       ^~~~~~~~~~
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:185:20: note: in expansion of macro ‘NRFX_USBD_EP_BITPOS’
 NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN1)  == USBD_EPDATASTATUS_EPIN1_Pos );
                    ^~~~~~~~~~~~~~~~~~~

... more similar errors...

In file included from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/nrfx.h:37:0,
                 from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:32:
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c: In function ‘usbd_dmareq_process’:
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:1397:50: warning: passing argument 1 of ‘atomic_and’ from incompatible pointer type [-Wincompatible-pointer-types]
                     (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << pos)));
                                                  ^
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/./nrfx_glue.h:186:58: note: in definition of macro ‘NRFX_ATOMIC_FETCH_AND’
 #define NRFX_ATOMIC_FETCH_AND(p_data, value)  atomic_and(p_data, value)
                                                          ^~~~~~
In file included from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/include/kernel_includes.h:21:0,
                 from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/include/kernel.h:17,
                 from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/./nrfx_glue.h:139,
                 from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/nrfx.h:37,
                 from /home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c:32:
/home/mcp/ZephyrProjects/zephyr-1_13_99/zephyr/include/atomic.h:248:28: note: expected ‘atomic_t * {aka int *}’ but argument is of type ‘uint32_t * {aka long unsigned int *}’
 static inline atomic_val_t atomic_and(atomic_t *target, atomic_val_t value)
                            ^~~~~~~~~~
zephyr/CMakeFiles/zephyr.dir/build.make:257: recipe for target 'zephyr/CMakeFiles/zephyr.dir/ext/hal/nordic/nrfx/drivers/src/nrfx_usbd.c.obj' failed

... more similar errors...

I know echo_server does not require newlib; but my app may.  This is the same behavior I see in my project.
Thought focusing on a sample project would help keep things a bit clearer.

Cheers,
Chuck McP


Jukka Rissanen
 

On Tue, 2018-11-06 at 10:38 -0800, cpmcparland@... wrote:
When the first line is uncommented, I get compile-time errors like
the following (simple variations not copied here-
but, I can send complete listing if needed).

$cmake -DCONF_FILE="prj.conf overlay-netusb.conf"
-DBOARD=nrf52840_pca10056 ../../
BTW, you can also say

$ cmake -DOVERLAY_CONFIG=overlay-netusb.conf -DBOARD=nrf52840_pca10056
../..

as prj.conf is automatically included anyway.
Using -DCONF_FILE="prj.conf overlay-netusb.conf" works too of course.


Cheers,
Jukka


cpmcparland@...
 

Jukka,

Thanks...learn something new everyday!  This is also a reason for NOT renaming the .conf file for
your project to something unique....which, of course, I did on my first project!

Cheers,
Chuck McP