Zephyr: nrf52840 usb driver with openthread

Created on 12 Jun 2019  路  6Comments  路  Source: zephyrproject-rtos/zephyr

Describe the bug
When attempting to use both the nrf52 usb serial device driver and openthread, the usb serial output prints very slowly with many dropped/garbled characters.

To Reproduce

  • Start from the echo_client sample
  • Enable openthread in the configuration as per the overlay-ot.conf file
  • Enable USB in the configuration as per the usb/console sample .conf file
  • Build and flash for the nrf52840_pca10056 v1.0.0

Expected behavior
It should print to console almost immediately:

**** Booting Zephyr OS zephyr-v1.14.0 *****                                     
32m[00:00:00.000,000] <inf> ieee802154_nrf5: nRF5 802154 radio initialized      
[00:00:00.004,821] <inf> net_l2_openthread: OpenThread version: OPENTHREAD/20187
[00:00:00.005,096] <inf> net_l2_openthread: Network name:   ot_zephyr           
[00:00:00.006,134] <inf> net_l2_openthread: State changed! Flags: 0x047f1309 Cu0
[00:00:00.007,141] <inf> net_l2_openthread: State changed! Flags: 0x00000004 Cu1
[00:00:00.007,232] <inf> net_l2_openthread: State changed! Flags: 0x00000001 Cu1
[00:00:00.007,354] <inf> net_l2_openthread: State changed! Flags: 0x00001000 Cu1
[00:00:00.007,507] <inf> net_l2_openthread: State changed! Flags: 0x00001000 Cu1
[00:00:00.007,629] <inf> net_l2_openthread: State changed! Flags: 0x00000010 Cu1
[00:00:00.007,690] <inf> net_l2_openthread: State changed! Flags: 0x00000020 Cu1
[00:00:00.013,977] <inf> net_config: Initializing network                       
[00:00:00.014,129] <inf> net_l2_openthread: State changed! Flags: 0x00000001 Cu1
[00:00:01.996,124] <inf> net_l2_openthread: State changed! Flags: 0x00000040 Cu1
[00:00:03.013,763] <inf> net_echo_client_sample: Starting...                    
[00:00:03.013,763] <inf> net_echo_client_sample: Run echo client                
[00:00:03.014,953] <dbg> net_echo_client_sample.send_udp_data: IPv6 UDP: Sent 7s
[00:00:04.055,755] <inf> net_l2_openthread: State changed! Flags: 0x000012a5 Cu4

In reality it prints very slowly (over a couple minutes):

                                                                               0
000000.0,66]<if>ne_l_oenhrad Oenhradvesin:OPNTRED/01892-032-g9d571;NOE;Ju 1 219m
                                                                               m
                                                                               m
[0:0:0.00,70 m<nf nt_2_pethea: tae haned Fags 000000 Crrntroe:                 m
00000001,12]<nf nt_2_pethea: Sat caned Fag:0x00100 uren rle:1m                  
[0:0:0.01,47]<n> etl2opntred:Sttechngd!Flgs 0000000 uren rl: 1[0:0:0.10,14 <if> 
[0:0:0.02,08 min> etcofi: niiaiingnewokme! las:0x00000 uret ol:                 
                                        [0:0:0.03,01]<if>ne_l_opntred:Sttechngd0
00000200,37] [0<in> etl2opntred:Sttechngd!Flgs 0x00040Curen rle 1[0             
[0:0:0.03,73]if> eteco_lintsapl: uneco len                                      
00000301464] [0mdb> eteco_lintsapl.sndup_at: Pv UP:Sen 13byes[0                 
00000421,03]<nf ne_l_oenhrad Sat hage! las:0x00125 uren rle 4[0                 
00001300,90]er>ne_ehoclen_smpe:UD Iv6 Dtapaketno rceved[0                       
0000:3.0448]<bg>neteco_ciet_amlesed_dpdaa:IP6 DP Snt45btes[0                    
[0:0:2299,90]<bg nt_ch_ciet_ampe.en_up_ata Iv6UD: en 61byes[0                   
[0:0:2.91,45 ;1mer> eteco_lintsapl: DPIP6:Daa acetnotreeied[0                   
00003298,02]<bg nt_ehoclen_smpe.ed_up_dta Iv6UDP Snt 21byes[0                   
00004297,62]er> eteco_lintsapl: DPIP6:Daa acet otreeied[0                       
000042.71252 mdg>ne_ehoclen_smpe.endud_dta Iv6UD: en 26 yts[0m                  
 ...                                                           

Impact
Cannot use nrf software usb with openthread applications

Environment (please complete the following information):

  • OS: Ubuntu 18.04
  • Zephyr SDK
  • Zephyr v1.14.0
  • nrf52840_pca10056 v1.0.0

Additional context
Running the same sample without openthread, the usb console works fine
Running the sample with openthread, without usb, and instead using the j-link usb connection, console works fine.
It is only the combination of openthread and usb that has issues.

My resulting configuration file looks like this

# Generic networking options
CONFIG_NETWORKING=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
CONFIG_NET_IPV6=y
CONFIG_NET_IPV4=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_POLL_MAX=4

# Kernel options
CONFIG_MAIN_STACK_SIZE=2048
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=16
CONFIG_NET_PKT_TX_COUNT=16
CONFIG_NET_BUF_RX_COUNT=80
CONFIG_NET_BUF_TX_COUNT=80
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=n

# The addresses are selected so that qemu<->qemu connectivity works ok.
# For linux<->qemu connectivity, create a new conf file and swap the
# addresses (so that peer address is ending to 2).
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.2"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.1"

CONFIG_CPLUSPLUS=y

CONFIG_BT=n

# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
CONFIG_NET_TCP=n
CONFIG_NET_IPV4=n

CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_MLD=n
CONFIG_NET_CONFIG_NEED_IPV6=y
CONFIG_NET_CONFIG_NEED_IPV4=n
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_NET_TX_STACK_SIZE=2048
CONFIG_NET_RX_STACK_SIZE=5120
CONFIG_SHELL_STACK_SIZE=3072

CONFIG_NET_L2_OPENTHREAD=y

CONFIG_OPENTHREAD_DEBUG=y
CONFIG_OPENTHREAD_L2_DEBUG=y
CONFIG_OPENTHREAD_L2_LOG_LEVEL_INF=y

CONFIG_OPENTHREAD_CHANNEL=26

CONFIG_NET_CONFIG_MY_IPV6_ADDR="fdde:ad00:beef::1"
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="fdde:ad00:beef::2"

# Thread by default registers quite a lot addresses.
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=6
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=8

# Other OpenThread dependencies (flash for OT persistent storage)
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_REBOOT=y

CONFIG_GPIO=y

CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
CONFIG_USB_UART_CONSOLE=y

CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"
OpenThread USB bug nRF low

All 6 comments

Any thoughts on this? If it's too low of a priority for anyone to work on, then I might attempt to tackle it myself although I'm not sure where to start given the complexity of the openthread codebase. But not being able to get logging output with openthread apps is making development pretty challenging

Hi @jwknaup,

I've just tried to configure USB with OpenThread on current master. I've added the following configuration to the overlay-ot.conf in the echo_client sample:

CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_CDC_ACM=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr OpenThread device"

CONFIG_UART_SHELL_ON_DEV_NAME="CDC_ACM_0"

With this configuration shell and logger over USB CDC worked fine for me. Two caveats though:

  1. I've used nrf52840_pca10056 v1.1.0, could not find the v1.0.0,
  2. For whatever reason, I needed to send any input over the shell, before I started receiving output on my terminal. I don't think though that's an OpenThread issue.

Hi @jwknaup,

I was able to make Logging through USB work on a nrf52840_pca10059 (Dongle) but OpenThread's connection range was reduced from 20 meters to 1 meter.

I suppose it is somehow related to https://github.com/zephyrproject-rtos/zephyr/issues/11694, as it is necessary for me to disable UART interrupt for it to work properly:

CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_0_NRF_UARTE=n
CONFIG_UART_0_INTERRUPT_DRIVEN=n

Thanks @rlubos for the correct config. I guess I needed to use the usb uart shell instead of the console. I think we can close this

@jcorde I did not notice such a significant reduction in range, thank goodness!

@jwknaup You're correct, Zephyr's OpenThread port is integrated with shell/logger subsystem, not the console.

Issue resolved.

Was this page helpful?
0 / 5 - 0 ratings