Initial PIC32 driver -- now is just a badly hacked STM32 USB driver

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4234 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-12-28 00:49:48 +00:00
parent 4c5d18d561
commit 14c215c980
4 changed files with 4031 additions and 15 deletions

View File

@ -438,7 +438,7 @@ EXTERN int pic32mx_spi3cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
EXTERN void pic32mx_dmainitilaize(void);
#endif
@ -456,7 +456,7 @@ EXTERN void pic32mx_dmainitilaize(void);
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
EXTERN DMA_HANDLE pic32mx_dmachannel(void);
#endif
@ -473,7 +473,7 @@ EXTERN DMA_HANDLE pic32mx_dmachannel(void);
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
EXTERN void pic32mx_dmafree(DMA_HANDLE handle);
#endif
@ -485,7 +485,7 @@ EXTERN void pic32mx_dmafree(DMA_HANDLE handle);
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
EXTERN int pic32mx_dmarxsetup(DMA_HANDLE handle,
uint32_t control, uint32_t config,
uint32_t srcaddr, uint32_t destaddr,
@ -500,7 +500,7 @@ EXTERN int pic32mx_dmarxsetup(DMA_HANDLE handle,
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
EXTERN int pic32mx_dmastart(DMA_HANDLE handle, dma_callback_t callback, void *arg);
#endif
@ -514,7 +514,7 @@ EXTERN int pic32mx_dmastart(DMA_HANDLE handle, dma_callback_t callback, void *ar
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
EXTERN void pic32mx_dmastop(DMA_HANDLE handle);
#endif
@ -526,7 +526,7 @@ EXTERN void pic32mx_dmastop(DMA_HANDLE handle);
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
#ifdef CONFIG_DEBUG_DMA
EXTERN void pic32mx_dmasample(DMA_HANDLE handle, struct pic32mx_dmaregs_s *regs);
#else
@ -542,7 +542,7 @@ EXTERN void pic32mx_dmasample(DMA_HANDLE handle, struct pic32mx_dmaregs_s *regs)
*
****************************************************************************/
#ifdef CONFIG_pic32mx_GPDMA
#ifdef CONFIG_PIC32MX_DMA
#ifdef CONFIG_DEBUG_DMA
EXTERN void pic32mx_dmadump(DMA_HANDLE handle, const struct pic32mx_dmaregs_s *regs,
const char *msg);
@ -551,6 +551,51 @@ EXTERN void pic32mx_dmadump(DMA_HANDLE handle, const struct pic32mx_dmaregs_s *r
#endif
#endif
/************************************************************************************
* Name: pic32mx_usbpullup
*
* Description:
* If USB is supported and the board supports a pullup via GPIO (for USB software
* connect and disconnect), then the board software must provide stm32_pullup.
* See include/nuttx/usb/usbdev.h for additional description of this method.
* Alternatively, if no pull-up GPIO the following EXTERN can be redefined to be
* NULL.
*
************************************************************************************/
#ifdef CONFIG_PIC32MX_USBDEV
EXTERN int pic32mx_usbpullup(FAR struct usbdev_s *dev, bool enable);
#endif
/************************************************************************************
* Name: pic32mx_usbsuspend
*
* Description:
* Board logic must provide the stm32_usbsuspend logic if the USBDEV driver is
* used. This function is called whenever the USB enters or leaves suspend mode.
* This is an opportunity for the board logic to shutdown clocks, power, etc.
* while the USB is suspended.
*
************************************************************************************/
#ifdef CONFIG_PIC32MX_USBDEV
EXTERN void pic32mx_usbsuspend(FAR struct usbdev_s *dev, bool resume);
#endif
/****************************************************************************
* Name: pic32mx_usbattach and pic32mx_usbdetach
*
* Description:
* The USB stack must be notified when the device is attached or detached
* by calling one of these functions.
*
****************************************************************************/
#ifdef CONFIG_PIC32MX_USBDEV
EXTERN void pic32mx_usbattach(void);
EXTERN void pic32mx_usbdetach(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}

File diff suppressed because it is too large Load Diff

View File

@ -179,7 +179,7 @@
#define USB_INT_UERR (1 << 1) /* Bit 1: USB Error Condition Interrupt */
#define USB_INT_SOF (1 << 2) /* Bit 2: SOF Token Interrupt */
#define USB_INT_TRN (1 << 3) /* Bit 3: Token Processing Complete Interrupt */
#define USB_INT_IDLE (1 << 4) /* Bit 4 : Idle Detect Interrupt */
#define USB_INT_IDLE (1 << 4) /* Bit 4: Idle Detect Interrupt */
#define USB_INT_RESUME (1 << 5) /* Bit 5: Resume Interrupt */
#define USB_INT_ATTACH (1 << 6) /* Bit 6: Peripheral Attach Interrupt */
#define USB_INT_STALL (1 << 7) /* Bit 7: STALL Handshake Interrupt */
@ -290,12 +290,13 @@
/* Buffer Descriptor Table (BDT) ****************************************************/
/* Offset 0: On write (software->hardware) */
#define USB_BDT_BSTALL (1 << 2) /* Bit 2: Buffer Stall Enable bit */
#define USB_BDT_DTS (1 << 3) /* Bit 3: Data Toggle Synchronization Enable bit */
#define USB_BDT_NINC (1 << 4) /* Bit 4: DMA Address Increment Disable bit */
#define USB_BDT_KEEP (1 << 5) /* Bit 5: BD Keep Enable bit */
#define USB_BDT_DATA01 (1 << 6) /* Bit 6: Data Toggle Packet bit */
#define USB_BDT_UOWN (1 << 7) /* Bit 7: USB Own bit */
#define USB_BDT_STATUS_MASK 0xfc /* Bits 2-7: Status bits */
#define USB_BDT_BSTALL (1 << 2) /* Bit 2: Buffer Stall Enable bit */
#define USB_BDT_DTS (1 << 3) /* Bit 3: Data Toggle Synchronization Enable bit */
#define USB_BDT_NINC (1 << 4) /* Bit 4: DMA Address Increment Disable bit */
#define USB_BDT_KEEP (1 << 5) /* Bit 5: BD Keep Enable bit */
#define USB_BDT_DATA01 (1 << 6) /* Bit 6: Data Toggle Packet bit */
#define USB_BDT_UOWN (1 << 7) /* Bit 7: USB Own bit */
#define USB_BDT_BYTECOUNT_SHIFT (16) /* Bits 16-25: Byte Count bits */
#define USB_BDT_BYTECOUNT_MASK (0x3ff << USB_BDT_BYTECOUNT_SHIFT)

View File

@ -0,0 +1,136 @@
/************************************************************************************
* configs/sure-pic32mx/src/up_usbdev.c
* arch/arm/src/board/up_usbdev.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References:
* - Sample code and schematics provided with the Sure Electronics PIC32 board.
*
* 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 <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/spi.h>
#include <arch/board/board.h>
#include "up_arch.h"
#include "chip.h"
#include "pic32mx-internal.h"
#include "sure-internal.h"
#if defined(CONFIG_PIC32MX_USBDEV)
/************************************************************************************
* Definitions
************************************************************************************/
/*
* PIN NAME SIGNAL NOTES
* ---- ------------------------------- -------------- ------------------------------
* 11 AN5/C1IN+/Vbuson/CN7/RB5 Vbuson/AN5/RB5 To USB VBUS circuitry
* 43 U1CTS/SDA1/IC2/INT2/RD9 USB_OPTEN USB PHY
* 44 SCL1/IC3/PMCS2/PMA15/INT3/RD10 USB_OPT USB PHY
*/
#define GPIO_USB_VBUSON (GPIO_INPUT|GPIO_PORTB|GPIO_PIN5)
#define GPIO_USB_OPTEN (GPIO_OUTPUT|GPIO_VALUE_ZERO|GPIO_PORTD|GPIO_PIN9)
#define GPIO_USB_OPT (GPIO_OUTPUT|GPIO_VALUE_ONE|GPIO_PORTD|GPIO_PIN10)
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: pic32mx_usbdevinitialize
*
* Description:
* Called to configure the mini-B PHY on the Sure PIC32MX board for the USB device
*
************************************************************************************/
void weak_function pic32mx_usbdevinitialize(void)
{
/* Connect the PHY to the USB mini-B port. Order and timing matter! */
pic32mx_configgpio(GPIO_USB_OPTEN);
pic32mx_configgpio(GPIO_USB_OPT);
/* Notes from the Sure Electronics sample code:
*
* "The USB specifications require that USB peripheral devices must never source
* current onto the Vbus pin. Additionally, USB peripherals should not source
* current on D+ or D- when the host/hub is not actively powering the Vbus line.
* When designing a self powered (as opposed to bus powered) USB peripheral
* device, the firmware should make sure not to turn on the USB module and D+
* or D- pull up resistor unless Vbus is actively powered. Therefore, the
* firmware needs some means to detect when Vbus is being powered by the host.
* A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and
* can be used to detect when Vbus is high (host actively powering), or low
* (host is shut down or otherwise not supplying power). The USB firmware
* can then periodically poll this I/O pin to know when it is okay to turn on
* the USB module/D+/D- pull up resistor. When designing a purely bus powered
* peripheral device, it is not possible to source current on D+ or D- when the
* host is not actively providing power on Vbus. Therefore, implementing this
* bus sense feature is optional. ..."
*/
#ifdef CONFIG_USBHOST
// pic32mx_configgpio(GPIO_USB_VBUSON);
#endif
/* "If the host PC sends a GetStatus (device) request, the firmware must respond
* and let the host know if the USB peripheral device is currently bus powered
* or self powered. See chapter 9 in the official USB specifications for details
* regarding this request. If the peripheral device is capable of being both
* self and bus powered, it should not return a hard coded value for this request.
* Instead, firmware should check if it is currently self or bus powered, and
* respond accordingly. If the hardware has been configured like demonstrated
* on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the
* currently selected power source. ..."
*/
#ifdef CONFIG_USB_PWRSENSE
// pic32mx_configgpio(GPIO_USB_PWRSENSE);
#endif
}
#endif /* CONFIG_PIC32MX_USBDEV */