mirror of
https://github.com/apache/nuttx.git
synced 2026-06-08 01:42:58 +08:00
usb/ssp initialization corrected
This commit is contained in:
@@ -133,10 +133,10 @@ CHIP_CSRCS += lpc43_spifi.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LPC43_SSP0),y)
|
||||
CHIP_CSRCS += lpc43_ssp.c
|
||||
CHIP_CSRCS += lpc43_ssp.c lpc43_spi.c
|
||||
else
|
||||
ifeq ($(CONFIG_LPC43_SSP1),y)
|
||||
CHIP_CSRCS += lpc43_ssp.c
|
||||
CHIP_CSRCS += lpc43_ssp.c lpc43_spi.c
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include "chip.h"
|
||||
#include "lpc43_pinconfig.h"
|
||||
#include "lpc43_spi.h"
|
||||
#include "lpc43_ssp.h"
|
||||
|
||||
#ifdef CONFIG_LPC43_SPI
|
||||
|
||||
@@ -583,3 +584,39 @@ FAR struct spi_dev_s *lpc43_spiinitialize(int port)
|
||||
|
||||
#endif /* CONFIG_LPC43_SPI */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_spiinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the selected SPI port
|
||||
* 0 - SPI
|
||||
* 1 - SSP0
|
||||
* 2 - SSP1
|
||||
*
|
||||
* Input Parameter:
|
||||
* Port number (for hardware that has multiple SPI interfaces)
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid SPI device structure reference on success; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct spi_dev_s *up_spiinitialize(int port)
|
||||
{
|
||||
if (port) {
|
||||
#if ( defined(CONFIG_LPC43_SSP0) || defined(CONFIG_LPC43_SSP1) )
|
||||
return lpc43_sspinitialize(port-1);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
} else {
|
||||
#if defined(CONFIG_LPC43_SPI)
|
||||
return lpc43_spiinitialize(port);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2583,12 +2583,9 @@ void up_usbinitialize(void)
|
||||
struct lpc43_usbdev_s *priv = &g_usbdev;
|
||||
int i;
|
||||
uint32_t regval;
|
||||
irqstate_t flags;
|
||||
|
||||
usbtrace(TRACE_DEVINIT, 0);
|
||||
|
||||
/* Disable USB interrupts */
|
||||
|
||||
lpc43_putreg(0, LPC43_USBDEV_USBINTR);
|
||||
flags = irqsave();
|
||||
|
||||
/* Initialize the device state structure */
|
||||
|
||||
@@ -2646,10 +2643,15 @@ void up_usbinitialize(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable PLL0 clock */
|
||||
|
||||
lpc43_pll0usbconfig();
|
||||
lpc43_pll0usbenable();
|
||||
|
||||
/* Clock */
|
||||
|
||||
regval = getreg32(LPC43_BASE_USB0_CLK);
|
||||
regval &= ~BASE_USB0_CLK_CLKSEL_MASK;
|
||||
regval &= ~(BASE_USB0_CLK_CLKSEL_MASK | BASE_USB0_CLK_PD) ;
|
||||
regval |= (BASE_USB0_CLKSEL_PLL0USB | BASE_USB0_CLK_AUTOBLOCK);
|
||||
putreg32(regval, LPC43_BASE_USB0_CLK);
|
||||
|
||||
@@ -2659,18 +2661,11 @@ void up_usbinitialize(void)
|
||||
regval |= CCU_CLK_CFG_RUN;
|
||||
putreg32(regval, LPC43_CCU1_M4_USB0_CFG);
|
||||
|
||||
/* Enable PLL0 clock */
|
||||
//lpc43_putreg(RGU_CTRL0_USB0_RST, LPC43_RGU_CTRL0); /* Reset USB block */
|
||||
|
||||
lpc43_pll0usbconfig();
|
||||
lpc43_pll0usbenable();
|
||||
lpc43_pullup(&priv->usbdev, false); /* disconnect device */
|
||||
|
||||
/* Reset USB block */
|
||||
|
||||
lpc43_putreg(RGU_CTRL0_USB0_RST, LPC43_RGU_CTRL0);
|
||||
|
||||
/* Reset the controller */
|
||||
|
||||
lpc43_putreg (USBDEV_USBCMD_RST, LPC43_USBDEV_USBCMD);
|
||||
lpc43_setbits (USBDEV_USBCMD_RST, LPC43_USBDEV_USBCMD); /* Reset the controller */
|
||||
while (lpc43_getreg (LPC43_USBDEV_USBCMD) & USBDEV_USBCMD_RST)
|
||||
;
|
||||
|
||||
@@ -2680,33 +2675,25 @@ void up_usbinitialize(void)
|
||||
regval &= ~CREG0_USB0PHY;
|
||||
putreg32(regval, LPC43_CREG0);
|
||||
|
||||
/* Attach USB controller interrupt handler */
|
||||
|
||||
if (irq_attach(LPC43M4_IRQ_USB0, lpc43_usbinterrupt) != 0)
|
||||
{
|
||||
usbtrace(TRACE_DEVERROR(LPC43_TRACEERR_IRQREGISTRATION),
|
||||
(uint16_t)LPC43M4_IRQ_USB0);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
lpc43_putreg(0, LPC43_USBDEV_USBINTR); /* Disable USB interrupts */
|
||||
|
||||
/* Program the controller to be the USB device controller */
|
||||
|
||||
lpc43_putreg (USBDEV_USBMODE_SDIS | USBDEV_USBMODE_SLOM | USBDEV_USBMODE_CM_DEVICE,
|
||||
LPC43_USBDEV_USBMODE);
|
||||
|
||||
/* Disconnect device */
|
||||
/* Attach USB controller interrupt handler */
|
||||
|
||||
lpc43_pullup(&priv->usbdev, false);
|
||||
irq_attach(LPC43M4_IRQ_USB0, lpc43_usbinterrupt);
|
||||
up_enable_irq(LPC43M4_IRQ_USB0);
|
||||
|
||||
irqrestore(flags);
|
||||
|
||||
/* Reset/Re-initialize the USB hardware */
|
||||
|
||||
lpc43_usbreset(priv);
|
||||
|
||||
return;
|
||||
|
||||
errout:
|
||||
up_usbuninitialize();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -2739,7 +2726,7 @@ void up_usbuninitialize(void)
|
||||
|
||||
/* Reset the controller */
|
||||
|
||||
lpc43_putreg (USBDEV_USBCMD_RST, LPC43_USBDEV_USBCMD);
|
||||
lpc43_setbits (USBDEV_USBCMD_RST, LPC43_USBDEV_USBCMD);
|
||||
while (lpc43_getreg (LPC43_USBDEV_USBCMD) & USBDEV_USBCMD_RST)
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user