diff --git a/arch/arm/src/sama5/sam_ehci.c b/arch/arm/src/sama5/sam_ehci.c index 4d1ada715d1..b2b3050cca2 100644 --- a/arch/arm/src/sama5/sam_ehci.c +++ b/arch/arm/src/sama5/sam_ehci.c @@ -438,7 +438,7 @@ static int sam_reset(void); /**************************************************************************** * Private Data ****************************************************************************/ -/* In this driver implementation, support is provided for only a single a single +/* In this driver implementation, support is provided for only a single * USB device. All status information can be simply retained in a single global * instance. */ @@ -4924,18 +4924,18 @@ FAR struct usbhost_connection_s *sam_ehci_initialize(int controller) /* "In order to initialize the host controller, software should perform the * following steps: * - * • "Program the CTRLDSSEGMENT register with 4-Gigabyte segment where all + * - "Program the CTRLDSSEGMENT register with 4-Gigabyte segment where all * of the interface data structures are allocated. [64-bit mode] - * • "Write the appropriate value to the USBINTR register to enable the + * - "Write the appropriate value to the USBINTR register to enable the * appropriate interrupts. - * • "Write the base address of the Periodic Frame List to the PERIODICLIST + * - "Write the base address of the Periodic Frame List to the PERIODICLIST * BASE register. If there are no work items in the periodic schedule, * all elements of the Periodic Frame List should have their T-Bits set * to a one. - * • "Write the USBCMD register to set the desired interrupt threshold, + * - "Write the USBCMD register to set the desired interrupt threshold, * frame list size (if applicable) and turn the host controller ON via * setting the Run/Stop bit. - * • Write a 1 to CONFIGFLAG register to route all ports to the EHCI controller + * - Write a 1 to CONFIGFLAG register to route all ports to the EHCI controller * ... * * "At this point, the host controller is up and running and the port registers diff --git a/boards/Kconfig b/boards/Kconfig index aed15fd802d..fc2bf68c05d 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -1300,7 +1300,7 @@ config ARCH_BOARD_SAMA5D3_XPLAINED select ARCH_HAVE_LEDS select ARCH_HAVE_BUTTONS select ARCH_HAVE_IRQBUTTONS - select ARCH_PHY_INTERRUPT if NETDEVICES + select ARCH_PHY_INTERRUPT if NETDEVICES && (SAMA5_EMACA || SAMA5_EMAC0 || SAMA5_EMAC1 || SAMA5_GMAC) ---help--- The port of NuttX to the Atmel SAMA5D3 Xplained development board. diff --git a/boards/arm/sama5/sama5d3-xplained/README.txt b/boards/arm/sama5/sama5d3-xplained/README.txt index 24daaebbca9..1273b4aec84 100644 --- a/boards/arm/sama5/sama5d3-xplained/README.txt +++ b/boards/arm/sama5/sama5d3-xplained/README.txt @@ -90,7 +90,7 @@ Development Environment Several possible development environments may be used: - Linux or macOS native - - Cygwin unders Windows + - Cygwin under Windows - MinGW + MSYS under Windows - Windows native (with GNUMake from GNUWin32). @@ -278,7 +278,14 @@ Loading Code into SRAM with J-Link (gdb) target remote localhost:2331 (gdb) mon reset (gdb) load nuttx - (gdb) ... start debugging ... + (gdb) breakpoint nsh_main + (gdb) continue + Continuing. + + Breakpoint 1, nsh_main (argc=1, argv=0x2007757c) at nsh_main.c:218 + 218 sched_getparam(0, ¶m); + (gdb) continue + (gdb) ... debugging ... Loading code using J-Link Commander ---------------------------------- @@ -578,6 +585,28 @@ Load NuttX with U-Boot on AT91 boards NuttShell (NSH) NuttX-7.2 nsh> + It is possible to autoboot from the SD Card: + + 1. Format an SD Card as FAT. + 2. Copy the file nuttx/boards/arm/sama5/sama5d3-xplained/boot/uImage file to the SD Card. + 3. Copy the file nuttx.bin you just compiled to the SD Card. + 4. Attach a 3.3V USB-serial adapter to the DEBUG console port. + 5. Open a serial terminal to the debug console. In Linux, do this: + + picocom -b 115200 /dev/ttyUSB0 + + 6. Press the RESET button. You should see a U-Boot prompt. Press a key to stop the booting process. + 7. Issue the following commands to U-Boot: + + U-Boot> setenv load_nuttx 'fatload mmc 0 0x20008000 nuttx.bin' + U-Boot> setenv run_nuttx 'go 0x20008040' + U-Boot> setenv boot_nuttx 'run load_nuttx; run run_nuttx' + U-Boot> setenv bootcmd 'boot_nuttx' + U-Boot> saveenv + U-Boot> reset + + 8. The board should now always boot to NuttX if you have the SD Card inserted. + Loading through network On a development system, it is useful to get the kernel and root file @@ -1349,6 +1378,90 @@ USB High-Speed Device Application Configuration -> Examples: CONFIG_SYSTEM_CDCACM=y : Enable an CDC/ACM example + CDC/ECM Ethernet Over USB + ------------------------- + + This will select the CDC/ECM Ethernet over USB device. Defaults for the other + options should be okay. + + CONFIG_NET_CDCECM=y + CONFIG_CDCECM_EP0MAXPACKET=64 + CONFIG_CDCECM_EPINTIN=1 + CONFIG_CDCECM_EPINTIN_FSSIZE=16 + CONFIG_CDCECM_EPINTIN_HSSIZE=16 + CONFIG_CDCECM_EPBULKOUT=5 + CONFIG_CDCECM_EPBULKOUT_FSSIZE=64 + CONFIG_CDCECM_EPBULKOUT_HSSIZE=512 # needed for non-fragmentation IP and ICMP packets in HS mode + CONFIG_CDCECM_EPBULKIN=2 + CONFIG_CDCECM_EPBULKIN_FSSIZE=64 + CONFIG_CDCECM_EPBULKIN_HSSIZE=512 # needed for non-fragmentation IP and ICMP packets in HS mode + CONFIG_CDCECM_VENDORID=0x0525 + CONFIG_CDCECM_PRODUCTID=0xa4a2 + CONFIG_CDCECM_VENDORSTR="NuttX" + CONFIG_CDCECM_PRODUCTSTR="CDC/ECM Ethernet" + + There are two defconfig files that have been tested with these configurations: + + ethernet-over-usb/defconfig + ethernet-over-usb-telnetd/defconfig + + The latter has a telnetd enabled, so once the system boots, you can issue the telnetd command, + and then telnet into it from the host. + + To use them, copy them to .config, and run 'make menuconfig' (you don't have to change anything), + then save the file. Then run 'make' to make NuttX. + + On Linux, a helper script is provided called helpers/netusb-up.sh. This script can be used + to configure the Linux USB Ethernet Gadget network interface. Once you boot a NuttX system with the + CDC ECM Ethernet over USB device, the Linux network interface will be added to your system. You should + see something like the following messages in /var/log/kern.log: + + [302074.552879] usb 1-2: new high-speed USB device number 107 using ehci-pci + [302074.718264] usb 1-2: New USB device found, idVendor=0525, idProduct=a4a2, bcdDevice= 1.00 + [302074.718267] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 + [302074.718269] usb 1-2: Product: CDC/ECM Ethernet + [302074.718271] usb 1-2: Manufacturer: NuttX + [302074.718272] usb 1-2: SerialNumber: 0 + [302074.760638] cdc_ether 1-2:1.0 usb0: register 'cdc_ether' at usb-0000:02:03.0-2, CDC Ethernet Device, 02:00:00:11:22:33 + [302074.796215] cdc_ether 1-2:1.0 ens35u2: renamed from usb0 + + If you execute the command 'ifconfig -a' you should see a new interface: + + $ ifconfig -a + + ens35u2: flags=4098 mtu 576 + ether 02:00:00:11:22:33 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + + If you run the netusb-up.sh script, then do ifconfig, you should see the following: + + $ sudo ./netusb-up.sh + $ ifconfig -a + + ens35u2: flags=4163 mtu 576 + ether 02:00:00:11:22:33 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 15 bytes 2477 (2.4 KB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + + ens35u2:0: flags=4163 mtu 576 + inet 10.0.0.1 netmask 255.255.255.0 broadcast 10.0.0.255 + ether 02:00:00:11:22:33 txqueuelen 1000 (Ethernet) + + Now that the new interface has an IP address, you can ping the NuttX box at 10.0.0.2 + (or whatever IP address you configured it to have). If you used the telnet defconfig, + you should be able to telnet to the board using: + + $ telnet 10.0.0.2 + + The helper script also sets up Network Address Translation (NAT) so the NuttX system + can access the Internet. If that is not what you want, you can remove the iptables + NAT commands from the script. + Debugging USB Device -------------------- diff --git a/boards/arm/sama5/sama5d3-xplained/boot/uImage b/boards/arm/sama5/sama5d3-xplained/boot/uImage new file mode 100755 index 00000000000..910d93407d1 Binary files /dev/null and b/boards/arm/sama5/sama5d3-xplained/boot/uImage differ diff --git a/boards/arm/sama5/sama5d3-xplained/configs/ethernet-over-usb-telnetd/defconfig b/boards/arm/sama5/sama5d3-xplained/configs/ethernet-over-usb-telnetd/defconfig new file mode 100644 index 00000000000..b95a1495e2e --- /dev/null +++ b/boards/arm/sama5/sama5d3-xplained/configs/ethernet-over-usb-telnetd/defconfig @@ -0,0 +1,120 @@ +# +# 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_DISABLE_OS_API is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_CMDPARMS is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="sama5d3-xplained" +CONFIG_ARCH_BOARD_SAMA5D3_XPLAINED=y +CONFIG_ARCH_CHIP="sama5" +CONFIG_ARCH_CHIP_ATSAMA5D36=y +CONFIG_ARCH_CHIP_SAMA5=y +CONFIG_ARCH_CHIP_SAMA5D3=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_IRQPRIO=y +CONFIG_ARCH_LOWVECTORS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARM_SEMIHOSTING_SYSLOG=y +CONFIG_BOARDCTL_USBDEVCTRL=y +CONFIG_BOARD_LOOPSPERMSEC=65775 +CONFIG_BOOT_RUNFROMSDRAM=y +CONFIG_BUILTIN=y +CONFIG_CDCECM_EPINTIN_HSSIZE=16 +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEV_LOOP=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_WGET=y +CONFIG_EXAMPLES_WGET_URL="http://10.0.0.1/" +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_EXCLUDE_VERSION=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_INTELHEX_BINARY=y +CONFIG_INTERPRETERS_CHIBI_SCHEME=y +CONFIG_IOB_NBUFFERS=24 +CONFIG_IOB_THROTTLE=0 +CONFIG_MAX_TASKS=16 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_MMCSD=y +CONFIG_NETINIT_NETLOCAL=y +CONFIG_NETINIT_NOMAC=y +CONFIG_NETUTILS_NETLIB_GENERICURLPARSER=y +CONFIG_NETUTILS_TELNETC=y +CONFIG_NETUTILS_TELNETD=y +CONFIG_NETUTILS_WEBCLIENT=y +CONFIG_NET_ARP_IPIN=y +CONFIG_NET_ARP_SEND=y +CONFIG_NET_BROADCAST=y +CONFIG_NET_CDCECM=y +CONFIG_NET_ICMP=y +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_ROUTE=y +CONFIG_NET_STATISTICS=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_NOTIFIER=y +CONFIG_NET_TCP_WRITE_BUFFERS=y +CONFIG_NET_UDP=y +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_PROMPT_STRING="nsh> " +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PREALLOC_WDOGS=16 +CONFIG_RAMDISK=y +CONFIG_RAM_SIZE=268435456 +CONFIG_RAM_START=0x20000000 +CONFIG_RAM_VSTART=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=100 +CONFIG_READLINE_CMD_HISTORY_LINELEN=120 +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_RR_INTERVAL=200 +CONFIG_SAMA5D3XPLAINED_528MHZ=y +CONFIG_SAMA5_BOOT_SDRAM=y +CONFIG_SAMA5_DBGU=y +CONFIG_SAMA5_DBGU_CONSOLE=y +CONFIG_SAMA5_DBGU_NOCONFIG=y +CONFIG_SAMA5_HSMC=y +CONFIG_SAMA5_PIOA_IRQ=y +CONFIG_SAMA5_PIOB_IRQ=y +CONFIG_SAMA5_PIOC_IRQ=y +CONFIG_SAMA5_PIOD_IRQ=y +CONFIG_SAMA5_PIOE_IRQ=y +CONFIG_SAMA5_PIO_IRQ=y +CONFIG_SAMA5_UART1=y +CONFIG_SAMA5_UDPHS=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_START_DAY=31 +CONFIG_START_MONTH=7 +CONFIG_START_YEAR=2014 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSLOG_CHARDEV=y +CONFIG_SYSLOG_TIMESTAMP=y +CONFIG_SYSTEM_CLE_CMD_HISTORY=y +CONFIG_SYSTEM_CLE_CMD_HISTORY_LEN=20 +CONFIG_SYSTEM_CLE_CMD_HISTORY_LINELEN=120 +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_CXXINITIALIZE=y +CONFIG_SYSTEM_PING=y +CONFIG_SYSTEM_VI=y +CONFIG_USBDEV=y +CONFIG_USBDEV_DMA=y +CONFIG_USBDEV_DUALSPEED=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WDOG_INTRESERVE=2 diff --git a/boards/arm/sama5/sama5d3-xplained/configs/ethernet-over-usb/defconfig b/boards/arm/sama5/sama5d3-xplained/configs/ethernet-over-usb/defconfig new file mode 100644 index 00000000000..6853980f50b --- /dev/null +++ b/boards/arm/sama5/sama5d3-xplained/configs/ethernet-over-usb/defconfig @@ -0,0 +1,119 @@ +# +# 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_DISABLE_OS_API is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_CMDPARMS is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="sama5d3-xplained" +CONFIG_ARCH_BOARD_SAMA5D3_XPLAINED=y +CONFIG_ARCH_CHIP="sama5" +CONFIG_ARCH_CHIP_ATSAMA5D36=y +CONFIG_ARCH_CHIP_SAMA5=y +CONFIG_ARCH_CHIP_SAMA5D3=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_IRQPRIO=y +CONFIG_ARCH_LOWVECTORS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARM_SEMIHOSTING_SYSLOG=y +CONFIG_BOARDCTL_USBDEVCTRL=y +CONFIG_BOARD_LOOPSPERMSEC=65775 +CONFIG_BOOT_RUNFROMSDRAM=y +CONFIG_BUILTIN=y +CONFIG_CDCECM_EPINTIN_HSSIZE=16 +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEV_LOOP=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_WGET=y +CONFIG_EXAMPLES_WGET_URL="http://10.0.0.1/" +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_EXCLUDE_VERSION=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_INTELHEX_BINARY=y +CONFIG_INTERPRETERS_CHIBI_SCHEME=y +CONFIG_IOB_NBUFFERS=24 +CONFIG_IOB_THROTTLE=0 +CONFIG_MAX_TASKS=16 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_MMCSD=y +CONFIG_NETINIT_NETLOCAL=y +CONFIG_NETINIT_NOMAC=y +CONFIG_NETUTILS_NETLIB_GENERICURLPARSER=y +CONFIG_NETUTILS_TELNETC=y +CONFIG_NETUTILS_WEBCLIENT=y +CONFIG_NET_ARP_IPIN=y +CONFIG_NET_ARP_SEND=y +CONFIG_NET_BROADCAST=y +CONFIG_NET_CDCECM=y +CONFIG_NET_ICMP=y +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_ROUTE=y +CONFIG_NET_STATISTICS=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_NOTIFIER=y +CONFIG_NET_TCP_WRITE_BUFFERS=y +CONFIG_NET_UDP=y +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_PROMPT_STRING="nsh> " +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PREALLOC_WDOGS=16 +CONFIG_RAMDISK=y +CONFIG_RAM_SIZE=268435456 +CONFIG_RAM_START=0x20000000 +CONFIG_RAM_VSTART=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=100 +CONFIG_READLINE_CMD_HISTORY_LINELEN=120 +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_RR_INTERVAL=200 +CONFIG_SAMA5D3XPLAINED_528MHZ=y +CONFIG_SAMA5_BOOT_SDRAM=y +CONFIG_SAMA5_DBGU=y +CONFIG_SAMA5_DBGU_CONSOLE=y +CONFIG_SAMA5_DBGU_NOCONFIG=y +CONFIG_SAMA5_HSMC=y +CONFIG_SAMA5_PIOA_IRQ=y +CONFIG_SAMA5_PIOB_IRQ=y +CONFIG_SAMA5_PIOC_IRQ=y +CONFIG_SAMA5_PIOD_IRQ=y +CONFIG_SAMA5_PIOE_IRQ=y +CONFIG_SAMA5_PIO_IRQ=y +CONFIG_SAMA5_UART1=y +CONFIG_SAMA5_UDPHS=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_START_DAY=31 +CONFIG_START_MONTH=7 +CONFIG_START_YEAR=2014 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSLOG_CHARDEV=y +CONFIG_SYSLOG_TIMESTAMP=y +CONFIG_SYSTEM_CLE_CMD_HISTORY=y +CONFIG_SYSTEM_CLE_CMD_HISTORY_LEN=20 +CONFIG_SYSTEM_CLE_CMD_HISTORY_LINELEN=120 +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_CXXINITIALIZE=y +CONFIG_SYSTEM_PING=y +CONFIG_SYSTEM_VI=y +CONFIG_USBDEV=y +CONFIG_USBDEV_DMA=y +CONFIG_USBDEV_DUALSPEED=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WDOG_INTRESERVE=2 diff --git a/boards/arm/sama5/sama5d3-xplained/helpers/netusb-up.sh b/boards/arm/sama5/sama5d3-xplained/helpers/netusb-up.sh new file mode 100755 index 00000000000..ffbd98e8d9d --- /dev/null +++ b/boards/arm/sama5/sama5d3-xplained/helpers/netusb-up.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -x + +# This script can be used to set up the USB Ethernet Gadget interfaces +# on Linux. Tested on Ubuntu 19.10, kernel 5.3.0-24-generic + +# USB Ethernet Gadget interface +IF_USB=ens35u2 +# external interface +IF_HOST=ens33 + +IP_NET="10.0.0.0/24" +IP_NETMASK="255.255.255.0" +IP_BROADCAST="10.0.0.255" +IP_HOST="10.0.0.1" +IP_NUTTX="10.0.0.2" + +sudo ifconfig $IF_USB up +ifconfig -a +sudo ifconfig $IF_USB add $IP_HOST +sudo ifconfig $IF_USB:0 broadcast $IP_BROADCAST netmask $IP_NETMASK +sudo ip route delete $IP_NET +ip route add $IP_NET dev $IF_USB src $IP_HOST +sudo ip route add $IP_NET dev $IF_USB src $IP_HOST +sudo ip route add $IP_NUTTX/32 dev ens35u2 src $IP_HOST + +# nat to allow NuttX to access the internet +sudo iptables -t nat -A POSTROUTING -o $IF_HOST -j MASQUERADE +sudo iptables -A FORWARD -i $IF_HOST -o $IF_USB -m state --state RELATED,ESTABLISHED -j ACCEPT +sudo iptables -A FORWARD -i $IF_USB -o $IF_HOST -j ACCEPT + +ip route show + +# pinging the nuttx system should work now +#ping -c 1 $IP_NUTTX diff --git a/boards/arm/sama5/sama5d3-xplained/src/Makefile b/boards/arm/sama5/sama5d3-xplained/src/Makefile index df381ce1805..8910a0aec44 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/Makefile +++ b/boards/arm/sama5/sama5d3-xplained/src/Makefile @@ -86,6 +86,7 @@ endif ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += sam_appinit.c +CSRCS += sam_bringup.c endif ifeq ($(CONFIG_ADC),y) diff --git a/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c b/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c index fed9a6435ec..2b83062ca20 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c +++ b/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c @@ -87,139 +87,12 @@ int board_app_initialize(uintptr_t arg) { int ret; -#ifdef HAVE_NAND - /* Initialize the NAND driver */ - - ret = sam_nand_automount(NAND_MINOR); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: sam_nand_automount failed: %d\n", ret); - return ret; - } -#endif - -#ifdef HAVE_AT25 - /* Initialize the AT25 driver */ - - ret = sam_at25_automount(AT25_MINOR); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: sam_at25_automount failed: %d\n", ret); - return ret; - } -#endif - -#ifdef HAVE_HSMCI -#ifdef CONFIG_SAMA5_HSMCI0 - /* Initialize the HSMCI0 driver */ - - ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", - HSMCI0_SLOTNO, HSMCI0_MINOR, ret); - return ret; - } -#endif - -#ifdef CONFIG_SAMA5_HSMCI1 - /* Initialize the HSMCI1 driver */ - - ret = sam_hsmci_initialize(HSMCI1_SLOTNO, HSMCI1_MINOR); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", - HSMCI1_SLOTNO, HSMCI1_MINOR, ret); - return ret; - } -#endif -#endif - -#ifdef HAVE_USBHOST - /* Initialize USB host operation. sam_usbhost_initialize() starts a thread - * will monitor for USB connection and disconnection events. - */ - - ret = sam_usbhost_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", ret); - return ret; - } -#endif - -#ifdef HAVE_USBMONITOR - - /* Start the USB Monitor */ - - ret = usbmonitor_start(); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: Failed to start USB monitor: %d\n", ret); - } -#endif - -#ifdef CONFIG_ADC - - /* Initialize ADC and register the ADC driver. */ - - ret = sam_adc_setup(); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: sam_adc_setup failed: %d\n", ret); - } -#endif - -#ifdef CONFIG_AJOYSTICK - - /* Initialize and register the joystick driver */ - - ret = sam_ajoy_initialization(); - if (ret != OK) - { - syslog(LOG_ERR, - "ERROR: Failed to register the joystick driver: %d\n", - ret); - return ret; - } -#endif - -#ifdef CONFIG_PWM - - /* Initialize PWM and register the PWM device. */ - - ret = sam_pwm_setup(); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: sam_pwm_setup() failed: %d\n", ret); - return ret; - } -#endif - -#ifdef CONFIG_CAN - /* Initialize CAN and register the CAN driver. */ - - ret = sam_can_setup(); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: sam_can_setup failed: %d\n", ret); - } -#endif - -#ifdef CONFIG_FS_PROCFS - - /* Mount the procfs file system */ - - ret = mount(NULL, SAMA5_PROCFS_MOUNTPOINT, "procfs", 0, NULL); - if (ret < 0) - { - syslog(LOG_ERR, - "ERROR: Failed to mount procfs at %s: %d\n", - SAMA5_PROCFS_MOUNTPOINT, ret); - return ret; - } -#endif - UNUSED(ret); +#ifndef CONFIG_BOARD_LATE_INITIALIZE + /* Perform board initialization */ + + return sam_bringup(); +#else return OK; +#endif } diff --git a/boards/arm/sama5/sama5d3-xplained/src/sam_bringup.c b/boards/arm/sama5/sama5d3-xplained/src/sam_bringup.c new file mode 100755 index 00000000000..d4332aed348 --- /dev/null +++ b/boards/arm/sama5/sama5d3-xplained/src/sam_bringup.c @@ -0,0 +1,368 @@ +/**************************************************************************** + * boards/arm/sama5/sama5d4-ek/src/sam_bringup.c + * + * Copyright (C) 2014, 2016, 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include + +#ifdef CONFIG_USBMONITOR +# include +#endif + +#include +#include + +#include "sam_twi.h" +#include "sama5d3-xplained.h" + +#ifdef HAVE_ROMFS +# include +#endif + +#ifdef CONFIG_NET_CDCECM +# include +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NSECTORS(n) \ + (((n)+CONFIG_SAMA5D4EK_ROMFS_ROMDISK_SECTSIZE-1) / \ + CONFIG_SAMA5D4EK_ROMFS_ROMDISK_SECTSIZE) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = sam_i2cbus_initialize(bus); + if (i2c == NULL) + { + _err("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + _err("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + sam_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: sam_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2ctool(void) +{ +#ifdef CONFIG_SAMA5_TWI0 + sam_i2c_register(0); +#endif +#ifdef CONFIG_SAMA5_TWI1 + sam_i2c_register(1); +#endif +#ifdef CONFIG_SAMA5_TWI2 + sam_i2c_register(2); +#endif +#ifdef CONFIG_SAMA5_TWI3 + sam_i2c_register(3); +#endif +} +#else +# define sam_i2ctool() +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int sam_bringup(void) +{ + int ret; + + /* Register I2C drivers on behalf of the I2C tool */ + + sam_i2ctool(); + +#ifdef HAVE_HSMCI +#ifdef CONFIG_SAMA5_HSMCI0 + /* Initialize the HSMCI0 driver */ + + ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR); + if (ret < 0) + { + _err("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", + HSMCI0_SLOTNO, HSMCI0_MINOR, ret); + } + +#ifdef CONFIG_SAMA5D4EK_HSMCI0_MOUNT + else + { + /* REVISIT: + * A delay seems to be required here or the mount will fail. + */ + + /* Mount the volume on HSMCI0 */ + + ret = mount(CONFIG_SAMA5D4EK_HSMCI0_MOUNT_BLKDEV, + CONFIG_SAMA5D4EK_HSMCI0_MOUNT_MOUNTPOINT, + CONFIG_SAMA5D4EK_HSMCI0_MOUNT_FSTYPE, + 0, NULL); + + if (ret < 0) + { + _err("ERROR: Failed to mount %s: %d\n", + CONFIG_SAMA5D4EK_HSMCI0_MOUNT_MOUNTPOINT, errno); + } + } +#endif +#endif + +#ifdef CONFIG_SAMA5_HSMCI1 + /* Initialize the HSMCI1 driver */ + + ret = sam_hsmci_initialize(HSMCI1_SLOTNO, HSMCI1_MINOR); + if (ret < 0) + { + _err("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", + HSMCI1_SLOTNO, HSMCI1_MINOR, ret); + } + +#ifdef CONFIG_SAMA5D4EK_HSMCI1_MOUNT + else + { + /* REVISIT: A delay seems to be required here or the mount will fail. */ + + /* Mount the volume on HSMCI1 */ + + ret = mount(CONFIG_SAMA5D4EK_HSMCI1_MOUNT_BLKDEV, + CONFIG_SAMA5D4EK_HSMCI1_MOUNT_MOUNTPOINT, + CONFIG_SAMA5D4EK_HSMCI1_MOUNT_FSTYPE, + 0, NULL); + + if (ret < 0) + { + _err("ERROR: Failed to mount %s: %d\n", + CONFIG_SAMA5D4EK_HSMCI1_MOUNT_MOUNTPOINT, errno); + } + } +#endif +#endif +#endif + +#ifdef HAVE_AUTOMOUNTER + /* Initialize the auto-mounter */ + + sam_automount_initialize(); +#endif + +#ifdef HAVE_ROMFS + /* Create a ROM disk for the /etc filesystem */ + + ret = romdisk_register(CONFIG_SAMA5D4EK_ROMFS_ROMDISK_MINOR, romfs_img, + NSECTORS(romfs_img_len), + CONFIG_SAMA5D4EK_ROMFS_ROMDISK_SECTSIZE); + if (ret < 0) + { + _err("ERROR: romdisk_register failed: %d\n", -ret); + } + else + { + /* Mount the file system */ + + ret = mount(CONFIG_SAMA5D4EK_ROMFS_ROMDISK_DEVNAME, + CONFIG_SAMA5D4EK_ROMFS_MOUNT_MOUNTPOINT, + "romfs", MS_RDONLY, NULL); + if (ret < 0) + { + _err("ERROR: mount(%s,%s,romfs) failed: %d\n", + CONFIG_SAMA5D4EK_ROMFS_ROMDISK_DEVNAME, + CONFIG_SAMA5D4EK_ROMFS_MOUNT_MOUNTPOINT, errno); + } + } +#endif + +#ifdef HAVE_USBHOST + /* Initialize USB host operation. sam_usbhost_initialize() starts a thread + * will monitor for USB connection and disconnection events. + */ + + ret = sam_usbhost_initialize(); + if (ret != OK) + { + _err("ERROR: Failed to initialize USB host: %d\n", ret); + } +#endif + +#ifdef HAVE_USBMONITOR + /* Start the USB Monitor */ + + ret = usbmonitor_start(); + if (ret != OK) + { + _err("ERROR: Failed to start the USB monitor: %d\n", ret); + } +#endif + +#ifdef HAVE_MAXTOUCH + /* Initialize the touchscreen */ + + ret = sam_tsc_setup(0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: sam_tsc_setup failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_PWM + /* Initialize PWM and register the PWM device. */ + + ret = sam_pwm_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: sam_pwm_setup() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_ADC + /* Initialize ADC and register the ADC driver. */ + + ret = sam_adc_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: sam_adc_setup failed: %d\n", ret); + } +#endif + +#ifdef HAVE_WM8904 + /* Configure WM8904 audio */ + + ret = sam_wm8904_initialize(0); + if (ret != OK) + { + _err("ERROR: Failed to initialize WM8904 audio: %d\n", ret); + } +#endif + +#ifdef HAVE_AUDIO_NULL + /* Configure the NULL audio device */ + + ret = sam_audio_null_initialize(0); + if (ret != OK) + { + _err("ERROR: Failed to initialize the NULL audio device: %d\n", ret); + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = mount(NULL, SAMA5_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + _err("ERROR: Failed to mount procfs at %s: %d\n", + SAMA5_PROCFS_MOUNTPOINT, ret); + } +#endif + +#if defined(CONFIG_RNDIS) + /* Set up a MAC address for the RNDIS device. */ + + uint8_t mac[6]; + mac[0] = 0xa0; /* TODO */ + mac[1] = (CONFIG_NETINIT_MACADDR_2 >> (8 * 0)) & 0xff; + mac[2] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 3)) & 0xff; + mac[3] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 2)) & 0xff; + mac[4] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 1)) & 0xff; + mac[5] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 0)) & 0xff; + usbdev_rndis_initialize(mac); +#endif + +#ifdef CONFIG_NET_CDCECM + ret = cdcecm_initialize(0, NULL); + if (ret < 0) + { + _err("ERROR: cdcecm_initialize() failed: %d\n", ret); + } +#endif + + /* If we got here then perhaps not all initialization was successful, but + * at least enough succeeded to bring-up NSH with perhaps reduced + * capabilities. + */ + + UNUSED(ret); + return OK; +} diff --git a/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h b/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h index cf9cb49c1c4..b0cf5a612e5 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h +++ b/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h @@ -480,9 +480,9 @@ * KSZ9021/31) operating at 10/100/1000 Mbps. * The board supports RGMII interface mode. * The Ethernet interface consists of 4 pairs of low voltage differential - * pair signals designated from GRX± and GTx± plus control signals for link - * activity indicators. These signals can be used to connect to a - * 10/100/1000 BaseT RJ45 connector integrated on the main board. + * pair signals designated from TXRXP_A/TXRXM_A to TXRXP_D/TXRXM_D plus control + * signals for link activity indicators. These signals can be used to connect + * to a 10/100/1000 BaseT RJ45 connector integrated on the main board. * * The KSZ9021/31 interrupt is available on PB35 INT_GETH0. The sense of * the interrupt is configurable but is, by default, active low. @@ -803,5 +803,15 @@ int sam_can_setup(void); void weak_function sam_netinitialize(void); #endif +/**************************************************************************** + * Name: sam_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int sam_bringup(void); + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_SAMA5_SAMA5D3_XPLAINED_SRC_SAMA5D3_XPLAINED_H */ diff --git a/drivers/usbdev/cdcecm.c b/drivers/usbdev/cdcecm.c index 8c0d4f3f577..a19ab5f5c47 100644 --- a/drivers/usbdev/cdcecm.c +++ b/drivers/usbdev/cdcecm.c @@ -1299,7 +1299,8 @@ static int cdcecm_setconfig(FAR struct cdcecm_driver_s *self, uint8_t config) self->epint->priv = self; - cdcecm_mkepdesc(CDCECM_EP_BULKIN_IDX, &epdesc, &self->devinfo, false); + bool is_high_speed = (self->usbdev.speed == USB_SPEED_HIGH); + cdcecm_mkepdesc(CDCECM_EP_BULKIN_IDX, &epdesc, &self->devinfo, is_high_speed); ret = EP_CONFIGURE(self->epbulkin, &epdesc, false); if (ret < 0) @@ -1309,7 +1310,7 @@ static int cdcecm_setconfig(FAR struct cdcecm_driver_s *self, uint8_t config) self->epbulkin->priv = self; - cdcecm_mkepdesc(CDCECM_EP_BULKOUT_IDX, &epdesc, &self->devinfo, false); + cdcecm_mkepdesc(CDCECM_EP_BULKOUT_IDX, &epdesc, &self->devinfo, is_high_speed); ret = EP_CONFIGURE(self->epbulkout, &epdesc, true); if (ret < 0) @@ -1697,11 +1698,17 @@ static int16_t cdcecm_mkcfgdesc(FAR uint8_t *desc, len += USB_SIZEOF_IFDESC; + #ifdef CONFIG_USBDEV_DUALSPEED + bool is_high_speed = USB_SPEED_HIGH; + #else + bool is_high_speed = USB_SPEED_LOW; + #endif + if (desc) { FAR struct usb_epdesc_s *epdesc = (FAR struct usb_epdesc_s *)desc; - cdcecm_mkepdesc(CDCECM_EP_BULKIN_IDX, epdesc, devinfo, false); + cdcecm_mkepdesc(CDCECM_EP_BULKIN_IDX, epdesc, devinfo, is_high_speed); desc += USB_SIZEOF_EPDESC; } @@ -1711,7 +1718,7 @@ static int16_t cdcecm_mkcfgdesc(FAR uint8_t *desc, { FAR struct usb_epdesc_s *epdesc = (FAR struct usb_epdesc_s *)desc; - cdcecm_mkepdesc(CDCECM_EP_BULKOUT_IDX, epdesc, devinfo, false); + cdcecm_mkepdesc(CDCECM_EP_BULKOUT_IDX, epdesc, devinfo, is_high_speed); desc += USB_SIZEOF_EPDESC; }