RX65N USB Host Driver

This commit is contained in:
anjana 2020-12-03 15:39:19 +05:30 committed by Xiang Xiao
parent a5e00ac3f0
commit 4629d5a722
12 changed files with 9394 additions and 42 deletions

View File

@ -424,6 +424,11 @@ config RX65N_TEST_INTEP
endif #RX65N_USBDEV
config RX65N_USBHOST
bool "USB host"
select USBHOST
select USBHOST_HAVE_ASYNCH
config RX65N_DTC
bool "DTC"
default n
@ -803,6 +808,11 @@ config RX65N_TEST_INTEP
endif #RX65N_USBDEV
config RX65N_USBHOST
bool "USB host"
select USBHOST
select USBHOST_HAVE_ASYNCH
config RX65N_DTC
bool "DTC"
default n

View File

@ -1,37 +1,22 @@
##############################################################################
############################################################################
# arch/renesas/src/rx65n/Make.defs
#
# Copyright (C) 2008-2019 Gregory Nutt. All rights reserved.
# Author: Anjana <anjana@tataelxsi.co.in>
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# 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.
#
##############################################################################
############################################################################
HEAD_ASRC = rx65n_head.S
@ -67,6 +52,10 @@ ifeq ($(CONFIG_RX65N_RSPI),y)
CHIP_CSRCS += rx65n_rspi.c
endif
ifeq ($(CONFIG_USBHOST),y)
CHIP_CSRCS += rx65n_usbhost.c
endif
ifeq ($(CONFIG_I2C),y)
CHIP_CSRCS += rx65n_riic.c
endif

View File

@ -847,17 +847,17 @@
* generic
*/
#define USB_PIPE1 (1)
#define USB_PIPE2 (2)
#define USB_PIPE3 (3)
#define USB_PIPE4 (4)
#define USB_PIPE5 (5)
#define USB_PIPE6 (6)
#define USB_PIPE7 (7)
#define USB_PIPE8 (8)
#define USB_PIPE9 (9)
#define USB_MIN_PIPE_NO (1u)
#define USB_MAX_PIPE_NO (9)
#define USB_PIPE1 (1)
#define USB_PIPE2 (2)
#define USB_PIPE3 (3)
#define USB_PIPE4 (4)
#define USB_PIPE5 (5)
#define USB_PIPE6 (6)
#define USB_PIPE7 (7)
#define USB_PIPE8 (8)
#define USB_PIPE9 (9)
#define USB_MIN_PIPE_NO (1u)
#define USB_MAX_PIPE_NO (9)
/* Details of pipe number for obtaining the pipe */
@ -1171,6 +1171,7 @@
#define USB_DEVICE_A (0xa000u) /* Device address A */
#define USB_NODEVICE (0xf000u) /* No device */
#define USB_DEVADDRBIT (12u)
#define USB_DEFPACKET (0x0040)
/* Device Address bit fields */
@ -1448,6 +1449,14 @@
#define USB_INT_BRDY (0x0001u)
#define USB_BMREQUESTTYPERECIP (0x001Fu) /* b4-0: Recipient */
#define HUB_PORT1 (1)
#define HUB_PORT2 (2)
#define HUB_PORT3 (3)
#define HUB_PORT4 (4)
/* StandBy RAM Address */
#define RX65N_SBRAM_BASE 0x000a4000
/* Start of RSPI interface related definitions */

View File

@ -42,6 +42,7 @@
void r_ether_port_configuration(void);
void r_ether_pheriperal_enable(void);
void r_usb_port_enable(void);
/****************************************************************************
* Name: r_system_init
@ -73,6 +74,10 @@ void r_system_init(void)
r_ether_pheriperal_enable();
#endif
#if defined(CONFIG_USBHOST)
r_usb_port_enable();
#endif
/* Disable writing to MPC pin function control registers */
MPC.PWPR.BIT.PFSWE = 0;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,248 @@
/****************************************************************************
* arch/renesas/src/rx65n/rx65n/rx65n_usbhost.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_RENESAS_SRC_RX65N_USBHOST_H
#define __ARCH_RENESAS_SRC_RX65N_USBHOST_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <nuttx/config.h>
#include "rx65n_definitions.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Default, no-OHCI Case ****************************************************/
#define RX65N_USBHOST_HAVE_BANK 0x20004000
#define RX65N_USBHOST_MEMORYBASE 0x20004000
#define RX65N_USBHOST_MEMORYSIZE 0x4000
#undef RX65N_USBHOST_HEAPBASE
#undef RX65N_USBHOST_HEAPSIZE
#ifdef RX65N_USBHOST_HAVE_BANK
# define RX65N_USBHOST_HEAPBASE RX65N_USBHOST_MEMORYBASE
# define RX65N_USBHOST_HEAPSIZE RX65N_USBHOST_MEMORYSIZE
#endif
#if defined(CONFIG_USBHOST) && defined(RX65N_NUSBHOST) > 0
/* OHCI RAM Configuration ***************************************************/
#ifndef RX65N_USBHOST_HAVE_BANK
# error "Phani needs to look into this AHB SRAM Bank1 is not available for OHCI RAM"
#endif
/* OHCI/Heap Memory Allocation **********************************************/
/* Configured Size of the region at the end of AHB SRAM BANK1 set set aside
* for the OHCI. This size must fit within AHB SRAM Bank 1 and also be a
* multiple of 256 bytes.
*/
#ifndef CONFIG_RX65N_USBHOST_RAM_SIZE
# define CONFIG_RX65N_USBHOST_RAM_SIZE RX65N_USBHOST_MEMORYSIZE
#endif
#if CONFIG_RX65N_USBHOST_RAM_SIZE > RX65N_USBHOST_HEAPBASE
# error "USB Host RAM size cannot exceed the size of AHB SRAM Bank 1"
#endif
#if (CONFIG_RX65N_USBHOST_RAM_SIZE & 0xff) != 0
# error "RX65N RAM size must be in multiples of 256 bytes"
#endif
#define RX65N_USBHOST_RAM_END (RX65N_USBHOST_HAVE_BANK + RX65N_USBHOST_MEMORYBASE)
/* Numbers and Sizes of Things **********************************************/
/* Fixed size of the OHCI control area */
#define RX65N_USBHOST_HCCA_SIZE 256
/* Fixed endpoint descriptor size. The actual size required by the hardware
* is only 16 bytes, however, we set aside an additional 16 bytes for for
* internal use by the OHCI host driver. 16-bytes is set aside because the
* EDs must still be aligned to 16-byte boundaries.
*/
#define RX65N_USBHOST_ED_SIZE 32
/* Configurable number of user endpoint descriptors (EDs). This number
* excludes the control endpoint that is always allocated.
*/
#ifndef CONFIG_RX65N_USBHOST_NEDS
# define CONFIG_RX65N_USBHOST_NEDS 9
#endif
/* Derived size of user endpoint descriptor (ED) memory. */
#define RX65N_USBHOST_EDFREE_SIZE (CONFIG_RX65N_USBHOST_NEDS * RX65N_USBHOST_ED_SIZE)
/* Fixed transfer descriptor size. The actual size required by the hardware
* is only 16 bytes, however, we set aside an additional 16 bytes for for
* internal use by the OHCI host driver. 16-bytes is set aside because the
* TDs must still be aligned to 16-byte boundaries.
*/
#define RX65N_USBHOST_TD_SIZE 32
/* Configurable number of user transfer descriptors (TDs). */
#ifndef CONFIG_RX65N_USBHOST_NTDS
# define CONFIG_RX65N_USBHOST_NTDS 10
#endif
#if CONFIG_RX65N_USBHOST_NTDS < 2
# error "Insufficent TDs"
#endif
/* Derived size of user transfer descriptor (TD) memory. */
#define RX65N_USBHOST_TDFREE_SIZE (CONFIG_RX65N_USBHOST_NTDS * RX65N_USBHOST_TD_SIZE)
/* Configurable number of request/descriptor buffers (TDBUFFER) */
#ifndef CONFIG_RX65N_USBHOST_TDBUFFERS
# define CONFIG_RX65N_USBHOST_TDBUFFERS 10
#endif
#if CONFIG_RX65N_USBHOST_TDBUFFERS < 2
# error "At least two TD buffers are required"
#endif
/* Configurable size of a TD buffer */
#if CONFIG_RX65N_USBHOST_TDBUFFERS > 0 && !defined(CONFIG_RX65N_USBHOST_TDBUFSIZE)
# define CONFIG_RX65N_USBHOST_TDBUFSIZE 128
#endif
#if (CONFIG_RX65N_USBHOST_TDBUFSIZE & 3) != 0
# error "TD buffer size must be an even number of 32-bit words"
#endif
#define RX65N_USBHOST_TBFREE_SIZE (CONFIG_RX65N_USBHOST_TDBUFFERS * CONFIG_RX65N_USBHOST_TDBUFSIZE)
/* Configurable size of an IO buffer. The number of IO buffers will be
* determined by what is left at the end of the BANK1 memory setup aside
* of OHCI RAM.
*/
#ifndef CONFIG_RX65N_USBHOST_IOBUFSIZE
# define CONFIG_RX65N_USBHOST_IOBUFSIZE 512
#endif
#if (CONFIG_RX65N_USBHOST_IOBUFSIZE & 3) != 0
# error "IO buffer size must be an even number of 32-bit words"
#endif
#define RX65N_USBHOST_HCCA_BASE 1
#define RX65N_USBHOST_TDTAIL_ADDR 2
#define RX65N_USBHOST_EDCTRL_ADDR 3
#define RX65N_USBHOST_EDFREE_BASE 4
#define RX65N_USBHOST_TDFREE_BASE 5
#define RX65N_USBHOST_TBFREE_BASE 6
#define RX65N_USBHOST_IOFREE_BASE 7
/* Finally, use the remainder of the allocated OHCI for IO buffers */
#if CONFIG_RX65N_USBHOST_IOBUFSIZE > 0
# define RX65N_USBHOST_IOBUFFERS 0
#else
# define RX65N_USBHOST_IOBUFFERS 0
#endif
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: rx65n_usbhost_initialize
*
* Description:
* Initialize USB host device controller hardware.
*
* Input Parameters:
* controller -- If the device supports more than USB host controller, then
* this identifies which controller is being initialized. Normally, this
* is just zero.
*
* Returned Value:
* And instance of the USB host interface. The controlling task should
* use this interface to (1) call the wait() method to wait for a device
* to be connected, and (2) call the enumerate() method to bind the device
* to a class driver.
*
* Assumptions:
* - This function should called in the initialization sequence in order
* to initialize the USB device functionality.
* - Class drivers should be initialized prior to calling this function.
* Otherwise, there is a race condition if the device is already connected.
*
****************************************************************************/
#ifdef CONFIG_USBHOST
struct usbhost_connection_s;
FAR struct usbhost_connection_s *rx65n_usbhost_initialize(int controller);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* #if defined(CONFIG_USBHOST) && defined(RX65N_NUSBHOST) > 0 */
#endif /* __ARCH_RENESAS_SRC_RX65N_USBHOST_H */

View File

@ -17,7 +17,8 @@ Contents
- RSPI
- RIIC
- DTC
- Debugging
- USB Host
- USB Host Hub
- Debugging
Board Features
@ -225,6 +226,20 @@ RSPI
For GRROSE board only channel 1 can be tested since RSPI channel1 pinout is only brought out as
Pin number 2 and 3 in CN4 is used for MOSIB and MISOB respectively.
USB Host
=============
For the RX65N RSK2MB board, to be used as USB Device, the following Jumper settings need to be done
J7 Short Pin 1 & Pin 2
J16 Short Pin 2 & Pin 3
USB Device
=============
For the RX65N RSK2MB board, to be used as USB Device, the following Jumper settings need to be done
J7 Short Pin 2 & Pin 3
J16 Short Pin 1 & Pin 2
RTC
==========
@ -299,6 +314,76 @@ DTC Testing
DTC has been tested using RSPI driver.
USB Host Configurations
--------------------------
The following configurations need to be enabled for USB Host Mode driver to
support USB HID Keyboard class and MSC Class.
CONFIG_USBHOST=y
CONFIG_USBHOST_HIDKBD=y
CONFIG_FS_FAT=y
CONFIG_EXAMPLES_HIDKBD=y
USB Host Driver Testing
------------------------
The Following Class Drivers were tested as mentioned below :
- USB HID Keyboard Class
On the NuttX Console "hidkbd" application was executed
nsh> hidkbd
The characters typed from the keyboard were executed correctly.
- USB MSC Class
The MSC device is enumerated as sda in /dev directory.
The block device is mounted using the command as mentioned below :
mount -t vfat /dev/sda /mnt
The MSC device is mounted in /dev directory
The copy command is executed to test the Read/Write functionality
cp /mnt/<file.txt> /mnt/file_copy.txt
USB Host Hub Configurations
--------------------------
The following configurations need to be enabled for USB Host Mode driver to
support USB HID Keyboard class and MSC Class.
CONFIG_RX65N_USBHOST=y
CONFIG_USBHOST_HUB=y
CONFIG_USBHOST_ASYNCH=y
CONFIG_USBHOST=y
CONFIG_USBHOST_HIDKBD=y
CONFIG_FS_FAT=y
CONFIG_EXAMPLES_HIDKBD=y
USB Host Hub Driver Testing
------------------------
The Following Class Drivers were tested as mentioned below :
- USB HID Keyboard Class
On the NuttX Console "hidkbd" application was executed
nsh> hidkbd
The characters typed from the keyboard were executed correctly.
- USB MSC Class
The MSC device is enumerated as sda in /dev directory.
The block device is mounted using the command as mentioned below :
mount -t vfat /dev/sda /mnt
The MSC device is mounted in /dev directory
The copy command is executed to test the Read/Write functionality
cp /mnt/<file.txt> /mnt/file_copy.txt
Debugging
==========

View File

@ -32,8 +32,12 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/kthread.h>
#include <nuttx/board.h>
#include <nuttx/usb/usbhost.h>
#include "rx65n_usbhost.h"
#include "rx65n_grrose.h"
#include <rx65n_definitions.h>
#ifdef CONFIG_LIB_BOARDCTL
@ -60,6 +64,165 @@
# include <nuttx/i2c/i2c_master.h>
# include "rx65n_riic.h"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#define NSH_HAVE_USBHOST 1
/* USB Host */
#ifndef CONFIG_USBHOST
# undef NSH_HAVE_USBHOST
#endif
#ifdef NSH_HAVE_USBHOST
# ifndef CONFIG_USBHOST_DEFPRIO
# define CONFIG_USBHOST_DEFPRIO 100
# endif
# ifndef CONFIG_USBHOST_STACKSIZE
# ifdef CONFIG_USBHOST_HUB
# define CONFIG_USBHOST_STACKSIZE 1536
# else
# define CONFIG_USBHOST_STACKSIZE 1024
# endif
# endif
#endif
#ifdef NSH_HAVE_USBHOST
static struct usbhost_connection_s *g_usbconn;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_waiter
*
* Description:
* Wait for USB devices to be connected.
*
****************************************************************************/
#ifdef NSH_HAVE_USBHOST
static int nsh_waiter(int argc, char *argv[])
{
struct usbhost_hubport_s *hport;
syslog(LOG_INFO, "nsh_waiter: Running\n\r");
for (; ; )
{
/* Wait for the device to change state */
DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport));
syslog(LOG_INFO, "nsh_waiter: %s\n\r",
hport->connected ? "Host:connected" : "Host:disconnected");
/* Did we just become connected? */
if (hport->connected && hport->port == 0)
{
/* Yes.. enumerate the newly connected device */
(void)CONN_ENUMERATE(g_usbconn, hport);
}
}
/* Keep the compiler from complaining */
return 0;
}
#endif
/****************************************************************************
* Name: nsh_usbhostinitialize
*
* Description:
* Initialize SPI-based microSD.
*
****************************************************************************/
#ifdef NSH_HAVE_USBHOST
static int nsh_usbhostinitialize(void)
{
int pid;
int ret;
/* First, register all of the class drivers needed to support the drivers
* that we care about:
*/
syslog(LOG_INFO, "Register class drivers\n\r");
#ifdef CONFIG_USBHOST_HUB
/* Initialize USB hub class support */
ret = usbhost_hub_initialize();
if (ret < 0)
{
uerr("ERROR: usbhost_hub_initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_USBHOST_MSC
/* Register the USB host Mass Storage Class */
ret = usbhost_msc_initialize();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the mass storage class: %d\n", ret);
}
#endif
#ifdef CONFIG_USBHOST_CDCACM
/* Register the CDC/ACM serial class */
ret = usbhost_kbdinit();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the KBD class: %d\n", ret);
}
#endif
#ifdef CONFIG_USBHOST_HIDKBD
/* Register the HID KBD class */
ret = usbhost_kbdinit();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the CDC/ACM serial class: %d\n", ret);
}
#endif
/* Then get an instance of the USB host interface */
g_usbconn = rx65n_usbhost_initialize(0);
if (g_usbconn)
{
/* Start a thread to handle device connection. */
syslog(LOG_INFO, "Start nsh_waiter\n\r");
pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO,
CONFIG_USBHOST_STACKSIZE,
(main_t)nsh_waiter, (FAR char * const *)NULL);
syslog(LOG_INFO, "USBHost: Created pid = %d\n\r", pid);
return pid < 0 ? -ENOEXEC : OK;
}
return -ENODEV;
}
#else
# define nsh_usbhostinitialize() (OK)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -230,6 +393,10 @@ int rx65n_bringup(void)
(void)rx65n_dtc_initialize();
#endif
#if defined(CONFIG_USBHOST)
ret = nsh_usbhostinitialize();
#endif
#ifdef CONFIG_RX65N_RSPI
(void)rx65n_rspi_initialize();
#endif

View File

@ -178,6 +178,26 @@ void r_usbdev_port_enable(void)
}
#endif
/****************************************************************************
* Name: r_usb_port_enable
*
* Description:
* USB Enabling for RX65N RSK2MB
****************************************************************************/
#if defined(CONFIG_USBHOST)
void r_usb_port_enable(void)
{
/* Set VBUS pin for USB */
MPC.P16PFS.BYTE = 0x11u;
/* PORT1.PMR.BYTE |= 0x40; */
PORT1.PMR.BIT.B6 = 1u;
}
#endif
/****************************************************************************
* Name: sci0_init_port
*

View File

@ -16,6 +16,8 @@ Contents
- RSPI
- RIIC
- DTC
- USB Host
- USB Host Hub
- Debugging
Board Features
@ -193,6 +195,20 @@ Channel1: Pin number 35 and 36 in JA3 is used for MOSIB and MISOB respectively
Channel2: Pin number 18 and 19 in JA3 is used for MOSIC and MISOC respectively
and for enabling these pin need to select DSW-SEL0 by making off SW4-4
USB Host
=============
For the RX65N RSK2MB board, to be used as USB Device, the following Jumper settings need to be done
J7 Short Pin 1 & Pin 2
J16 Short Pin 2 & Pin 3
USB Device
=============
For the RX65N RSK2MB board, to be used as USB Device, the following Jumper settings need to be done
J7 Short Pin 2 & Pin 3
J16 Short Pin 1 & Pin 2
RTC
==========
@ -272,6 +288,76 @@ DTC Testing
DTC has been tested using RSPI driver.
USB Host Configurations
--------------------------
The following configurations need to be enabled for USB Host Mode driver to
support USB HID Keyboard class and MSC Class.
CONFIG_USBHOST=y
CONFIG_USBHOST_HIDKBD=y
CONFIG_FS_FAT=y
CONFIG_EXAMPLES_HIDKBD=y
USB Host Driver Testing
------------------------
The Following Class Drivers were tested as mentioned below :
- USB HID Keyboard Class
On the NuttX Console "hidkbd" application was executed
nsh> hidkbd
The characters typed from the keyboard were executed correctly.
- USB MSC Class
The MSC device is enumerated as sda in /dev directory.
The block device is mounted using the command as mentioned below :
mount -t vfat /dev/sda /mnt
The MSC device is mounted in /dev directory
The copy command is executed to test the Read/Write functionality
cp /mnt/<file.txt> /mnt/file_copy.txt
USB Host Hub Configurations
--------------------------
The following configurations need to be enabled for USB Host Mode driver to
support USB HID Keyboard class and MSC Class.
CONFIG_RX65N_USBHOST=y
CONFIG_USBHOST_HUB=y
CONFIG_USBHOST_ASYNCH=y
CONFIG_USBHOST=y
CONFIG_USBHOST_HIDKBD=y
CONFIG_FS_FAT=y
CONFIG_EXAMPLES_HIDKBD=y
USB Host Hub Driver Testing
------------------------
The Following Class Drivers were tested as mentioned below :
- USB HID Keyboard Class
On the NuttX Console "hidkbd" application was executed
nsh> hidkbd
The characters typed from the keyboard were executed correctly.
- USB MSC Class
The MSC device is enumerated as sda in /dev directory.
The block device is mounted using the command as mentioned below :
mount -t vfat /dev/sda /mnt
The MSC device is mounted in /dev directory
The copy command is executed to test the Read/Write functionality
cp /mnt/<file.txt> /mnt/file_copy.txt
Debugging
==========
1. NuttX needs to be compiled in Cygwin environment on Windows.

View File

@ -32,8 +32,11 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/kthread.h>
#include <nuttx/board.h>
#include <nuttx/usb/usbhost.h>
#include "rx65n_usbhost.h"
#include "rx65n_rsk2mb.h"
#include <rx65n_definitions.h>
#ifdef CONFIG_LIB_BOARDCTL
@ -60,10 +63,165 @@
# include <nuttx/i2c/i2c_master.h>
# include "rx65n_riic.h"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#define NSH_HAVE_USBHOST 1
/* USB Host */
#ifndef CONFIG_USBHOST
# undef NSH_HAVE_USBHOST
#endif
#ifdef NSH_HAVE_USBHOST
# ifndef CONFIG_USBHOST_DEFPRIO
# define CONFIG_USBHOST_DEFPRIO 100
# endif
# ifndef CONFIG_USBHOST_STACKSIZE
# ifdef CONFIG_USBHOST_HUB
# define CONFIG_USBHOST_STACKSIZE 1536
# else
# define CONFIG_USBHOST_STACKSIZE 1024
# endif
# endif
#endif
#ifdef NSH_HAVE_USBHOST
static struct usbhost_connection_s *g_usbconn;
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_waiter
*
* Description:
* Wait for USB devices to be connected.
*
****************************************************************************/
#ifdef NSH_HAVE_USBHOST
static int nsh_waiter(int argc, char *argv[])
{
struct usbhost_hubport_s *hport;
syslog(LOG_INFO, "nsh_waiter: Running\n\r");
for (; ; )
{
/* Wait for the device to change state */
DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport));
/* Did we just become connected? */
if (hport->connected && hport->port == 0)
{
/* Yes.. enumerate the newly connected device */
(void)CONN_ENUMERATE(g_usbconn, hport);
}
}
/* Keep the compiler from complaining */
return 0;
}
#endif
/****************************************************************************
* Name: nsh_usbhostinitialize
*
* Description:
* Initialize SPI-based microSD.
*
****************************************************************************/
#ifdef NSH_HAVE_USBHOST
static int nsh_usbhostinitialize(void)
{
int pid;
int ret;
/* First, register all of the class drivers needed to support the drivers
* that we care about:
*/
syslog(LOG_INFO, "Register class drivers\n\r");
#ifdef CONFIG_USBHOST_MSC
/* Register the USB host Mass Storage Class */
printf ("USB Host MSC\n\r");
ret = usbhost_msc_initialize();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the mass storage class: %d\n", ret);
}
#endif
#ifdef CONFIG_USBHOST_CDCACM
/* Register the CDC/ACM serial class */
printf ("USB Host CDCACM \n\r");
ret = usbhost_kbdinit();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the KBD class: %d\n", ret);
}
#endif
#ifdef CONFIG_USBHOST_HIDKBD
/* Register the HID KBD class */
ret = usbhost_kbdinit();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the CDC/ACM serial class: %d\n", ret);
}
#endif
#ifdef CONFIG_USBHOST_HUB
/* Initialize USB hub class support */
ret = usbhost_hub_initialize();
if (ret < 0)
{
uerr("ERROR: usbhost_hub_initialize failed: %d\n", ret);
}
#endif
/* Then get an instance of the USB host interface */
g_usbconn = rx65n_usbhost_initialize(0);
if (g_usbconn)
{
/* Start a thread to handle device connection. */
syslog(LOG_INFO, "Start nsh_waiter\n\r");
pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO,
CONFIG_USBHOST_STACKSIZE,
(main_t)nsh_waiter, (FAR char * const *)NULL);
syslog(LOG_INFO, "USBHost: Created pid = %d\n\r", pid);
return pid < 0 ? -ENOEXEC : OK;
}
return -ENODEV;
}
#else
# define nsh_usbhostinitialize() (OK)
#endif
/****************************************************************************
* Name: rx65n_rspi_initialize
*
@ -234,6 +392,11 @@ int rx65n_bringup(void)
(void)rx65n_rspi_initialize();
#endif
#if defined(CONFIG_USBHOST)
ret = nsh_usbhostinitialize();
printf ("USB Initialization done!!! with return value = %d\n\r", ret);
#endif
#if defined(CONFIG_CDCACM) && !defined(CONFIG_CDCACM_CONSOLE)
/* Initialize CDCACM */

View File

@ -216,6 +216,33 @@ void r_usbdev_port_enable(void)
}
#endif
/****************************************************************************
* Name: r_usb_port_enable
*
* Description:
* USB Enabling for RX65N RSK2MB
****************************************************************************/
#if defined(CONFIG_ARCH_BOARD_RX65N_RSK2MB)
#if defined(CONFIG_USBHOST)
void r_usb_port_enable(void)
{
/* Set VBUS pin for USB */
MPC.P16PFS.BYTE = 0x12u;
/* PORT1.PMR.BYTE |= 0x40; */
PORT1.PMR.BIT.B6 = 1u;
/* set USB0_OVRCURA pin */
MPC.P14PFS.BYTE = 0x12u;
PORT1.PMR.BIT.B4 = 1u;
}
#endif
#endif
/****************************************************************************
* Name: sci1_init_port
*