Exemple #1
0
int nsh_archinitialize(void)
{
#ifdef CONFIG_NSH_HAVEMMCSD
  FAR struct spi_dev_s *ssp;
  int ret;

  /* Get the SSP port */

  ssp = lpc17_spiinitialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!ssp)
    {
      message("nsh_archinitialize: Failed to initialize SSP port %d\n",
              CONFIG_NSH_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  message("Successfully initialized SSP port %d\n",
          CONFIG_NSH_MMCSDSPIPORTNO);

  /* Bind the SSP port to the slot */

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, ssp);
  if (ret < 0)
    {
      message("nsh_archinitialize: Failed to bind SSP port %d to MMC/SD slot %d: %d\n",
              CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO, ret);
      return ret;
    }

  message("Successfuly bound SSP port %d to MMC/SD slot %d\n",
          CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
#endif
  return OK;
}
Exemple #2
0
int usbmsc_archinitialize(void)
{
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI port */

  message("Initializing SPI port\n");

  spi = up_spiinitialize(AVR_MMCSDSPIPORTNO);
  if (!spi)
    {
      message("up_spiinitialize failed\n");
      return -ENODEV;
    }

  /* Bind the SPI port to the slot */

  message("Binding SPI port to MMC/SD slot\n");

  ret = mmcsd_spislotinitialize(CONFIG_EXAMPLES_USBMSC_DEVMINOR1, AVR_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      message("mmcsd_spislotinitialize failed: %d\n", ret);
      return ret;
    }

  return OK;
}
Exemple #3
0
int sam_sdinitialize(int port, int minor)
{
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI driver instance for the SD chip select */

  fvdbg("Initializing SERCOM SPI%d\n", port);

  spi = up_spiinitialize(port);
  if (!spi)
    {
      fdbg("Failed to initialize SPI%d\n", port);
      return -ENODEV;
    }

  fvdbg("Successfully initialized SPI%d\n", port);

  /* Bind the SPI device for the chip select to the slot */

  fvdbg("Binding SPI%d to MMC/SD slot %d\n", port, SAMDL_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(minor, SAMDL_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      fdbg("Failed to bind SPI%d to MMC/SD slot %d: %d\n",
            port, SAMDL_MMCSDSLOTNO, ret);
      return ret;
    }

  fvdbg("Successfuly bound SPI%d to MMC/SD slot %d\n",
        port, SAMDL_MMCSDSLOTNO);

  return OK;
}
Exemple #4
0
int board_app_initialize(void)
{
#ifdef NSH_HAVEMMCSD
  FAR struct spi_dev_s *ssp;
  int ret;

  /* Get the SSP port */

  ssp = lpc11_sspbus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!ssp)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SSP port %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SSP port %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO);

  /* Bind the SSP port to the slot */

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, ssp);
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: Failed to bind SSP port %d to MMC/SD slot %d: %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO, ret);
      return ret;
    }

  syslog(LOG_INFO, "Successfuly bound SSP port %d to MMC/SD slot %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
#endif
  return OK;
}
Exemple #5
0
int board_app_initialize(uintptr_t arg)
{
#ifdef NSH_HAVEMMCSD
  FAR struct spi_dev_s *ssp;
#endif
  int ret;

#ifdef NSH_HAVEMMCSD
  /* Get the SSP port */

  ssp = lpc17_sspbus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!ssp)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SSP port %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SSP port %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO);

  /* Bind the SSP port to the slot */

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, ssp);
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: Failed to bind SSP port %d to MMC/SD slot %d: %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO, ret);
      return ret;
    }

  syslog(LOG_INFO, "Successfuly bound SSP port %d to MMC/SD slot %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
#endif

#ifdef CONFIG_PWM
  /* Initialize PWM and register the PWM device. */

  ret = lpcexpresso_pwm_setup();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: lpcexpresso_pwm_setup() failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_ADC
  /* Initialize ADC and register the ADC driver. */

  ret = lpcxpresso_adc_setup();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: lpcxpresso_adc_setup failed: %d\n", ret);
    }
#endif

  UNUSED(ret);
  return OK;
}
Exemple #6
0
__EXPORT int nsh_archinitialize(void)
{
	int result;

	/* configure the high-resolution time/callout interface */
	hrt_init();

	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif

	/* set up the serial DMA polling */
	static struct hrt_call serial_dma_call;
	struct timespec ts;

	/*
	 * Poll at 1ms intervals for received bytes that have not triggered
	 * a DMA event.
	 */
	ts.tv_sec = 0;
	ts.tv_nsec = 1000000;

	hrt_call_every(&serial_dma_call,
		       ts_to_abstime(&ts),
		       ts_to_abstime(&ts),
		       (hrt_callout)stm32_serial_dma_poll,
		       NULL);

	/* initial LED state */
	drv_led_start();
	led_off(LED_AMBER);
	led_off(LED_BLUE);

	/* Get the SPI port for the microSD slot */

	spi = up_spiinitialize(CONFIG_NSH_MMCSDSPIPORTNO);

	if (!spi) {
		message("[boot] FAILED to initialize SPI port %d\n", CONFIG_NSH_MMCSDSPIPORTNO);
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 2 to the MMCSD driver\n");
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	return OK;
}
Exemple #7
0
int composite_archinitialize(void)
{
  /* If system/composite is built as an NSH command, then SD slot should
   * already have been initized in nsh_archinitialize() (see up_nsh.c).  In
   * this case, there is nothing further to be done here.
   *
   * NOTE: CONFIG_NSH_BUILTIN_APPS is not a fool-proof indication that NSH
   * was built.
   */

#ifndef CONFIG_NSH_BUILTIN_APPS
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI port */

  syslog(LOG_INFO, "Initializing SPI port %d\n", LPC214X_MMCSDSPIPORTNO);

  spi = up_spiinitialize(LPC214X_MMCSDSPIPORTNO);
  if (!spi)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
             LPC214X_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SPI port %d\n",
         LPC214X_MMCSDSPIPORTNO);

  /* Bind the SPI port to the slot */

  syslog(LOG_INFO, "Binding SPI port %d to MMC/SD slot %d\n",
         LPC214X_MMCSDSPIPORTNO, LPC214X_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(CONFIG_SYSTEM_COMPOSITE_DEVMINOR1,
                                LPC214X_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
             LPC214X_MMCSDSPIPORTNO, LPC214X_MMCSDSLOTNO, ret);
      return ret;
    }

  syslog(LOG_INFO, "Successfully bound SPI port %d to MMC/SD slot %d\n",
         LPC214X_MMCSDSPIPORTNO, LPC214X_MMCSDSLOTNO);

#endif /* CONFIG_NSH_BUILTIN_APPS */

  return OK;
}
Exemple #8
0
static int nsh_sdinitialize(void)
{
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI port */

  spi = pic32mx_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!spi)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO);
      ret = -ENODEV;
      goto errout;
    }

  syslog(LOG_INFO, "Successfully initialized SPI port %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO);

  /* The SPI should be in 8-bit (default) and mode2: CKP=1, CKE=0.
   * The MMC/SD driver will control the SPI frequency.  WARNING:
   * this is not the right way to do this... this should be done
   * the MMC/SD driver:  Other device on SPI1 may need other mode
   * settings.
   */

  SPI_SETMODE(spi, SPIDEV_MODE2);

  /* Bind the SPI port to the slot */

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR,
                               CONFIG_NSH_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO,
             CONFIG_NSH_MMCSDSLOTNO, ret);
      goto errout;
    }

  syslog(LOG_INFO,
         "Successfully bound SPI port %d to MMC/SD slot %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO,
         CONFIG_NSH_MMCSDSLOTNO);

  return OK;

errout:
  return ret;
}
Exemple #9
0
int board_app_initialize(uintptr_t arg)
{
  int ret;

#ifdef CONFIG_FS_PROCFS
  /* mount the proc filesystem */

  syslog(LOG_INFO, "Mounting procfs to /proc\n");

  ret = mount(NULL, "/proc", "procfs", 0, NULL);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to mount the PROC filesystem: %d (%d)\n",
             ret, errno);
      return ret;
    }
#endif

#ifdef NSH_HAVEMMCSD
  FAR struct spi_dev_s *ssp;

  /* Get the SSP port */

  ssp = lpc17_sspbus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!ssp)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SSP port %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SSP port %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO);

  /* Bind the SSP port to the slot */

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, ssp);
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: Failed to bind SSP port %d to MMC/SD slot %d: %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO, ret);
      return ret;
    }

  syslog(LOG_INFO, "Successfuly bound SSP port %d to MMC/SD slot %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
#endif
  return OK;
}
Exemple #10
0
int usbmsc_archinitialize(void)
{
  FAR struct spi_dev_s *spi;
  int ret;

  /* Enable power to the SD/MMC via a GPIO. LOW enables SD/MMC. */

  lpc17_gpiowrite(LPC1766STK_MMC_PWR, false);

  /* Get the SPI port */

  message("usbmsc_archinitialize: Initializing SPI port %d\n",
          LPC17XX_MMCSDSPIPORTNO);

  spi = up_spiinitialize(LPC17XX_MMCSDSPIPORTNO);
  if (!spi)
    {
      message("usbmsc_archinitialize: Failed to initialize SPI port %d\n",
              LPC17XX_MMCSDSPIPORTNO);
      ret = -ENODEV;
      goto errout;
    }

  message("usbmsc_archinitialize: Successfully initialized SPI port %d\n",
          LPC17XX_MMCSDSPIPORTNO);

  /* Bind the SPI port to the slot */

  message("usbmsc_archinitialize: Binding SPI port %d to MMC/SD slot %d\n",
          LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(CONFIG_EXAMPLES_USBMSC_DEVMINOR1, LPC17XX_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      message("usbmsc_archinitialize: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
              LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO, ret);
      goto errout;
    }

  message("usbmsc_archinitialize: Successfuly bound SPI port %d to MMC/SD slot %d\n",
          LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO);
  return OK;

  /* Disable power to the SD/MMC via a GPIO. HIGH disables SD/MMC. */

errout:
  lpc17_gpiowrite(LPC1766STK_MMC_PWR, true);
  return ret;}
Exemple #11
0
int usbmsc_archinitialize(void)
{
  /* If system/usbmsc is built as an NSH command, then SD slot should
   * already have been initialized in board_app_initialize() (see stm32_appinit.c).
   * In this case, there is nothing further to be done here.
   */

  FAR struct spi_dev_s *spi;
  int ret;

  /* First, get an instance of the SPI interface */

  syslog(LOG_INFO, "Initializing SPI port %d\n",
      OLIMEXINO_STM32_MMCSDSPIPORTNO);

  spi = up_spiinitialize(OLIMEXINO_STM32_MMCSDSPIPORTNO);
  if (!spi)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
          OLIMEXINO_STM32_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SPI port %d\n",
      OLIMEXINO_STM32_MMCSDSPIPORTNO);

  /* Now bind the SPI interface to the MMC/SD driver */

  syslog(LOG_INFO, "Bind SPI to the MMC/SD driver, minor=%d slot=%d\n",
      CONFIG_SYSTEM_USBMSC_DEVMINOR1, OLIMEXINO_STM32_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(CONFIG_SYSTEM_USBMSC_DEVMINOR1,
                                OLIMEXINO_STM32_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SPI port %d to MMC/SD minor=%d slot=%d %d\n",
             OLIMEXINO_STM32_MMCSDSPIPORTNO, CONFIG_SYSTEM_USBMSC_DEVMINOR1,
             OLIMEXINO_STM32_MMCSDSLOTNO, ret);
      return ret;
    }

  syslog(LOG_INFO, "Successfully bound SPI to the MMC/SD driver\n");

  return OK;

}
static int nsh_sdinitialize(void)
{
  FAR struct spi_dev_s *ssp;
  int ret;

  /* Enable power to the SD/MMC via a GPIO. LOW enables SD/MMC. */

  lpc17_gpiowrite(LPC1766STK_MMC_PWR, false);

  /* Get the SSP port */

  ssp = lpc17_sspinitialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!ssp)
    {
      message("nsh_archinitialize: Failed to initialize SSP port %d\n",
              CONFIG_NSH_MMCSDSPIPORTNO);
      ret = -ENODEV;
      goto errout;
    }

  message("Successfully initialized SSP port %d\n",
          CONFIG_NSH_MMCSDSPIPORTNO);

  /* Bind the SSP port to the slot */

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR,
                               CONFIG_NSH_MMCSDSLOTNO, ssp);
  if (ret < 0)
    {
      message("nsh_sdinitialize: "
              "Failed to bind SSP port %d to MMC/SD slot %d: %d\n",
              CONFIG_NSH_MMCSDSPIPORTNO,
              CONFIG_NSH_MMCSDSLOTNO, ret);
      goto errout;
    }

  message("Successfuly bound SSP port %d to MMC/SD slot %d\n",
          CONFIG_NSH_MMCSDSPIPORTNO,
          CONFIG_NSH_MMCSDSLOTNO);
  return OK;

  /* Disable power to the SD/MMC via a GPIO. HIGH disables SD/MMC. */

errout:
  lpc17_gpiowrite(LPC1766STK_MMC_PWR, true);
  return ret;
}
Exemple #13
0
int nsh_archinitialize(void)
{
#ifdef NSH_HAVEMMCSD
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI port */

  syslog(LOG_INFO, "Initializing SPI port %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO);

  spi = up_spiinitialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!spi)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SPI port %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO);

  /* Bind the SPI port to the slot */

  syslog(LOG_INFO, "Binding SPI port %d to MMC/SD slot %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO, ret);
      return ret;
    }

  syslog(LOG_INFO, "Successfully bound SPI port %d to MMC/SD slot %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
#endif

  return OK;
}
Exemple #14
0
int usbmsc_archinitialize(void)
{
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI port */

  syslog(LOG_INFO, "Initializing SPI port %d\n",
         LPC17XX_MMCSDSPIPORTNO);

  zkit_spiinitialize();
  spi = lpc17_spiinitialize(LPC17XX_MMCSDSPIPORTNO);
  if (!spi)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
             LPC17XX_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SPI port %d\n",
         LPC17XX_MMCSDSPIPORTNO);

  /* Bind the SPI port to the slot */

  syslog(LOG_INFO, "Binding SPI port %d to MMC/SD slot %d\n",
         LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(CONFIG_SYSTEM_USBMSC_DEVMINOR1,
                                LPC17XX_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
             LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO, ret);
      return ret;
    }

  syslog(LOG_INFO, "Successfully bound SPI port %d to MMC/SD slot %d\n",
         LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO);
  return OK;
}
Exemple #15
0
static int nsh_sdinitialize(void)
{
  FAR struct spi_dev_s *ssp;
  int ret;

  /* Get the SPI port */

  ssp = up_spiinitialize(CONFIG_NSH_MMCSDSPIPORTNO);
  if (!ssp)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO);
      ret = -ENODEV;
      goto errout;
    }

  syslog(LOG_INFO, "Successfully initialized SPI port %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO);

  /* Bind the SPI port to the slot */

  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR,
                                CONFIG_NSH_MMCSDSLOTNO, ssp);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
             CONFIG_NSH_MMCSDSPIPORTNO,
             CONFIG_NSH_MMCSDSLOTNO, ret);
      goto errout;
    }

  syslog(LOG_INFO, "Successfuly bound SPI port %d to MMC/SD slot %d\n",
         CONFIG_NSH_MMCSDSPIPORTNO,
         CONFIG_NSH_MMCSDSLOTNO);
  return OK;

errout:
  return ret;
}
Exemple #16
0
int usbmsc_archinitialize(void)
{
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI port */

  message("usbmsc_archinitialize: Initializing SPI port %d\n",
          LPC17XX_MMCSDSPIPORTNO);

  spi = up_spiinitialize(LPC17XX_MMCSDSPIPORTNO);
  if (!spi)
    {
      message("usbmsc_archinitialize: Failed to initialize SPI port %d\n",
              LPC17XX_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  message("usbmsc_archinitialize: Successfully initialized SPI port %d\n",
          LPC17XX_MMCSDSPIPORTNO);

  /* Bind the SPI port to the slot */

  message("usbmsc_archinitialize: Binding SPI port %d to MMC/SD slot %d\n",
          LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(CONFIG_EXAMPLES_USBMSC_DEVMINOR1, LPC17XX_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      message("usbmsc_archinitialize: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
              LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO, ret);
      return ret;
    }

  message("usbmsc_archinitialize: Successfuly bound SPI port %d to MMC/SD slot %d\n",
          LPC17XX_MMCSDSPIPORTNO, LPC17XX_MMCSDSLOTNO);
  return OK;
}
Exemple #17
0
int stm32_sdinitialize(int minor)
{
#ifdef HAVE_MMCSD
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI port */

  finfo("Initializing SPI port %d\n", STM32_MMCSDSPIPORTNO);

  spi = stm32_spibus_initialize(STM32_MMCSDSPIPORTNO);
  if (!spi)
    {
      ferr("ERROR: Failed to initialize SPI port %d\n", STM32_MMCSDSPIPORTNO);
      return -ENODEV;
    }

  finfo("Successfully initialized SPI port %d\n", STM32_MMCSDSPIPORTNO);

  /* Bind the SPI port to the slot */

  finfo("Binding SPI port %d to MMC/SD slot %d\n",
          STM32_MMCSDSPIPORTNO, STM32_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(minor, STM32_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      ferr("ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n",
            STM32_MMCSDSPIPORTNO, STM32_MMCSDSLOTNO, ret);
      return ret;
    }

  finfo("Successfuly bound SPI port %d to MMC/SD slot %d\n",
        STM32_MMCSDSPIPORTNO, STM32_MMCSDSLOTNO);
#endif
  return OK;
}
Exemple #18
0
int sam_sdinitialize(int minor)
{
  FAR struct spi_dev_s *spi;
  int ret;

  /* Get the SPI driver instance for the SD chip select */

  finfo("Initializing bit bang SPI for the MMC/SD slot\n");

  spi = sam_mmcsd_spiinitialize();
  if (!spi)
    {
      ferr("ERROR: Failed to bit bang SPI for the MMC/SD slot\n");
      return -ENODEV;
    }

  finfo("Successfully initialized bit bang SPI for the MMC/SD slot\n");

  /* Bind the SPI device for the chip select to the slot */

  finfo("Binding bit bang SPI device to MMC/SD slot %d\n",
        SAM34_MMCSDSLOTNO);

  ret = mmcsd_spislotinitialize(minor, SAM34_MMCSDSLOTNO, spi);
  if (ret < 0)
    {
      ferr("ERROR: Failed to bind  bit bang SPI device to MMC/SD slot %d: %d\n",
            SAM34_MMCSDSLOTNO, ret);
      return ret;
    }

  finfo("Successfuly bound  bit bang SPI device to MMC/SD slot %d\n",
        SAM34_MMCSDSLOTNO);

  return OK;
}
__EXPORT int nsh_archinitialize(void)
{
	int result;

	message("\n");

	/* configure always-on ADC pins */
	stm32_configgpio(GPIO_ADC1_IN0);
	stm32_configgpio(GPIO_ADC1_IN10);
	stm32_configgpio(GPIO_ADC1_IN11);

	stm32_configgpio(GPIO_UART_SBUS_INVERTER);
#ifdef CONFIG_RC_INPUTS_TYPE(RC_INPUT_SBUS)
	stm32_gpiowrite(GPIO_UART_SBUS_INVERTER, 1);
#else
	stm32_gpiowrite(GPIO_UART_SBUS_INVERTER, 0);
#endif

	/* configure the high-resolution time/callout interface */
	hrt_init();

	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif


















	/* initial BUZZER state */
	drv_buzzer_start();
	buzzer_off(BUZZER_EXT);

	/* initial LED state */
	drv_led_start();
	led_off(LED_AMBER);
	led_off(LED_BLUE);
	led_off(LED_GREEN);
	led_off(LED_EXT1);
	led_off(LED_EXT2);



	/* Configure SPI-based devices */

	message("[boot] Initializing SPI port 1\n");
	spi1 = up_spiinitialize(1);

	if (!spi1) {
		message("[boot] FAILED to initialize SPI port 1\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI1 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi1, 10000000);
	SPI_SETBITS(spi1, 8);
	SPI_SETMODE(spi1, SPIDEV_MODE3);
	SPI_SELECT(spi1, GPIO_SPI_CS_MS5611, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_EXP_MS5611, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_EXP_MPU6000, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_EXP_HMC5983, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_EXP_WIFI_EEPROM, false);
	up_udelay(20);

	message("[boot] Successfully initialized SPI port 1\r\n");

//	message("[boot] Initializing Wireless Module\n");
//	wireless_archinitialize();

	message("[boot] Initializing SPI port 2\n");
	spi2 = up_spiinitialize(2);

	if (!spi2) {
		message("[boot] FAILED to initialize SPI port 2\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI2 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi2, 10000000);
	SPI_SETBITS(spi2, 8);
	SPI_SETMODE(spi2, SPIDEV_MODE3);
	SPI_SELECT(spi2, GPIO_SPI_CS_MPU6000, false);
	SPI_SELECT(spi2, GPIO_SPI_CS_IMU_MS5611, false);
	SPI_SELECT(spi2, GPIO_SPI_CS_IMU_MPU6000, false);
	SPI_SELECT(spi2, GPIO_SPI_CS_IMU_HMC5983, false);
	SPI_SELECT(spi2, GPIO_SPI_CS_IMU_EEPROM, false);

	message("[boot] Successfully initialized SPI port 2\n");

	/* Get the SPI port for the microSD slot */

	message("[boot] Initializing SPI port 3\n");
	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI3 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi3, 10000000);
	SPI_SETBITS(spi3, 8);
	SPI_SETMODE(spi3, SPIDEV_MODE3);
	SPI_SELECT(spi3, GPIO_SPI_CS_DATAFLASH, false);
	SPI_SELECT(spi3, GPIO_SPI_CS_EEPROM, false);
	SPI_SELECT(spi3, GPIO_SPI_CS_SDCARD, false);

	message("[boot] Successfully initialized SPI port 3\n");

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully bound SPI port 3 to the MMCSD driver\n");

	return OK;
}
Exemple #20
0
__EXPORT int nsh_archinitialize(void)
{
	int result;

	message("\n");

	/* configure always-on ADC pins */
	stm32_configgpio(GPIO_ADC1_IN1);
	stm32_configgpio(GPIO_ADC1_IN2);
	stm32_configgpio(GPIO_ADC1_IN3);
	stm32_configgpio(GPIO_ADC1_IN10);


	/* configure the high-resolution time/callout interface */
	hrt_init();

	/* configure the DMA allocator */
	dma_alloc_init();

	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif

	/* set up the serial DMA polling */
	static struct hrt_call serial_dma_call;
	struct timespec ts;

	/*
	 * Poll at 1ms intervals for received bytes that have not triggered
	 * a DMA event.
	 */
	ts.tv_sec = 0;
	ts.tv_nsec = 1000000;

	hrt_call_every(&serial_dma_call,
		       ts_to_abstime(&ts),
		       ts_to_abstime(&ts),
		       (hrt_callout)stm32_serial_dma_poll,
		       NULL);

	/* initial BUZZER state */
	drv_buzzer_start();
	buzzer_off(BUZZER_EXT);

	/* initial LED state */
	drv_led_start();
	led_off(LED_AMBER);
	led_off(LED_BLUE);
	led_off(LED_GREEN);
	led_off(LED_EXT1);
	led_off(LED_EXT2);



	/* Configure SPI-based devices */

	message("[boot] Initializing SPI port 1\n");
	spi1 = up_spiinitialize(1);

	if (!spi1) {
		message("[boot] FAILED to initialize SPI port 1\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI1 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi1, 10000000);
	SPI_SETBITS(spi1, 8);
	SPI_SETMODE(spi1, SPIDEV_MODE3);
	SPI_SELECT(spi1, SPIDEV_WIRELESS, false);
	SPI_SELECT(spi1, SPIDEV_MS5611, false);
	up_udelay(20);

	message("[boot] Successfully initialized SPI port 1\r\n");

	message("[boot] Initializing SPI port 2\n");
	spi2 = up_spiinitialize(2);

	if (!spi2) {
		message("[boot] FAILED to initialize SPI port 2\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI2 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi2, 10000000);
	SPI_SETBITS(spi2, 8);
	SPI_SETMODE(spi2, SPIDEV_MODE3);
	SPI_SELECT(spi2, SPIDEV_MPU6000, false);

	message("[boot] Successfully initialized SPI port 2\n");

	/* Get the SPI port for the microSD slot */

	message("[boot] Initializing SPI port 3\n");
	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI3 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi3, 10000000);
	SPI_SETBITS(spi3, 8);
	SPI_SETMODE(spi3, SPIDEV_MODE3);
	SPI_SELECT(spi3, SPIDEV_MMCSD, false);
	SPI_SELECT(spi3, SPIDEV_FLASH, false);

	message("[boot] Successfully initialized SPI port 3\n");

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully bound SPI port 3 to the MMCSD driver\n");

	return OK;
}
int nsh_archinitialize(void)
{
#if defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR)
    int ret;
#endif
#ifdef CONFIG_STM32_SPI3
    FAR struct spi_dev_s *spi;
    FAR struct mtd_dev_s *mtd;
#endif
    int ret;

    /* Configure SPI-based devices */

#ifdef CONFIG_STM32_SPI3
    /* Get the SPI port */

    message("nsh_archinitialize: Initializing SPI port 3\n");
    spi = up_spiinitialize(3);
    if (!spi)
    {
        message("nsh_archinitialize: Failed to initialize SPI port 3\n");
        return -ENODEV;
    }

    message("nsh_archinitialize: Successfully initialized SPI port 3\n");

    /* Now bind the SPI interface to the M25P8 SPI FLASH driver */

#if defined(CONFIG_MTD) && defined(CONFIG_MIKROE_FLASH)
    message("nsh_archinitialize: Bind SPI to the SPI flash driver\n");
    mtd = m25p_initialize(spi);
    if (!mtd)
    {
        message("nsh_archinitialize: Failed to bind SPI port 3 to the SPI FLASH driver\n");
    }
    else
    {
        message("nsh_archinitialize: Successfully bound SPI port 3 to the SPI FLASH driver\n");

#ifdef CONFIG_MIKROE_FLASH_PART
        {
            int partno;
            int partsize;
            int partoffset;
            const char *partstring = CONFIG_MIKROE_FLASH_PART_LIST;
            const char *ptr;
            FAR struct mtd_dev_s *mtd_part;
            char  partname[4];

            /* Now create a partition on the FLASH device */

            partno = 0;
            ptr = partstring;
            partoffset = 0;

            while (*ptr != '\0')
            {
                /* Get the partition size */

                partsize = atoi(ptr);
                mtd_part = mtd_partition(mtd, partoffset, (partsize>>2)*16);
                partoffset += (partsize >> 2) * 16;

#ifdef CONFIG_MIKROE_FLASH_CONFIG_PART
                /* Test if this is the config partition */

                if (CONFIG_MIKROE_FLASH_CONFIG_PART_NUMBER == partno)
                {
                    /* Register the partition as the config device */

                    mtdconfig_register(mtd_part);
                }
                else
#endif
                {
                    /* Now initialize a SMART Flash block device and bind it
                     * to the MTD device.
                     */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
                    sprintf(partname, "p%d", partno);
                    smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd_part, partname);
#endif
                }

                /* Update the pointer to point to the next size in the list */

                while ((*ptr >= '0') && (*ptr <= '9'))
                {
                    ptr++;
                }

                if (*ptr == ',')
                {
                    ptr++;
                }

                /* Increment the part number */

                partno++;
            }
#else /* CONFIG_MIKROE_FLASH_PART */

        /* Configure the device with no partition support */

        smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd, NULL);

#endif /* CONFIG_MIKROE_FLASH_PART */
        }
    }

    /* Create a RAM MTD device if configured */

#if defined(CONFIG_RAMMTD) && defined(CONFIG_MIKROE_RAMMTD)
    {
        uint8_t *start = (uint8_t *) kmalloc(CONFIG_MIKROE_RAMMTD_SIZE * 1024);
        mtd = rammtd_initialize(start, CONFIG_MIKROE_RAMMTD_SIZE * 1024);
        mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);

        /* Now initialize a SMART Flash block device and bind it to the MTD device */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
        smart_initialize(CONFIG_MIKROE_RAMMTD_MINOR, mtd, NULL);
#endif
    }

#endif /* CONFIG_RAMMTD && CONFIG_MIKROE_RAMMTD */

#endif /* CONFIG_MTD */
#endif /* CONFIG_STM32_SPI3 */

    /* Create the SPI FLASH MTD instance */
    /* The M25Pxx is not a good media to implement a file system..
     * its block sizes are too large
     */

    /* Mount the SDIO-based MMC/SD block driver */

#ifdef NSH_HAVEMMCSD
    /* Bind the spi interface to the MMC/SD driver */

    message("nsh_archinitialize: Bind SDIO to the MMC/SD driver, minor=%d\n",
            CONFIG_NSH_MMCSDMINOR);
    ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi);
    if (ret != OK)
    {
        message("nsh_archinitialize: Failed to bind SPI to the MMC/SD driver: %d\n", ret);
    }
    else
    {
        message("nsh_archinitialize: Successfully bound SPI to the MMC/SD driver\n");
    }
#endif

#ifdef HAVE_USBHOST
    /* Initialize USB host operation.  stm32_usbhost_initialize() starts a thread
     * will monitor for USB connection and disconnection events.
     */

    ret = stm32_usbhost_initialize();
    if (ret != OK)
    {
        message("nsh_archinitialize: Failed to initialize USB host: %d\n", ret);
        return ret;
    }
#endif

#ifdef HAVE_USBMONITOR
    /* Start the USB Monitor */

    ret = usbmonitor_start(0, NULL);
    if (ret != OK)
    {
        message("nsh_archinitialize: Start USB monitor: %d\n", ret);
    }
#endif

#ifdef CONFIG_LCD_MIO283QT2
    /* Configure the TFT LCD module */

    message("nsh_archinitialize: Initializing TFT LCD module\n");

    ret = up_lcdinitialize();
    if (ret != OK)
    {
        message("nsh_archinitialize: Failed to initialize TFT LCD module\n");
    }

#endif

    /* Configure the Audio sub-system if enabled and bind it to SPI 3 */

#ifdef CONFIG_AUDIO

    up_vs1053initialize(spi);

#endif

    return OK;
}
Exemple #22
0
__EXPORT int nsh_archinitialize(void)
{
	int result;

	/* configure the high-resolution time/callout interface */
#ifdef CONFIG_HRT_TIMER
	hrt_init();
#endif

	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif

	/* set up the serial DMA polling */
#ifdef SERIAL_HAVE_DMA
	{
		static struct hrt_call serial_dma_call;
		struct timespec ts;

		/*
		 * Poll at 1ms intervals for received bytes that have not triggered
		 * a DMA event.
		 */
		ts.tv_sec = 0;
		ts.tv_nsec = 1000000;

		hrt_call_every(&serial_dma_call,
			       ts_to_abstime(&ts),
			       ts_to_abstime(&ts),
			       (hrt_callout)stm32_serial_dma_poll,
			       NULL);
	}
#endif

	message("\r\n");

	// initial LED state
	drv_led_start();
	up_ledoff(LED_BLUE);
	up_ledoff(LED_AMBER);
	up_ledon(LED_BLUE);

	/* Configure SPI-based devices */

	spi1 = up_spiinitialize(1);

	if (!spi1) {
		message("[boot] FAILED to initialize SPI port 1\r\n");
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	// Default SPI1 to 1MHz and de-assert the known chip selects.
	SPI_SETFREQUENCY(spi1, 10000000);
	SPI_SETBITS(spi1, 8);
	SPI_SETMODE(spi1, SPIDEV_MODE3);
	SPI_SELECT(spi1, PX4_SPIDEV_GYRO, false);
	SPI_SELECT(spi1, PX4_SPIDEV_ACCEL, false);
	SPI_SELECT(spi1, PX4_SPIDEV_MPU, false);
	up_udelay(20);

	message("[boot] Successfully initialized SPI port 1\r\n");

	/* Get the SPI port for the microSD slot */

	message("[boot] Initializing SPI port 3\n");
	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\n");
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully initialized SPI port 3\n");

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n");
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully bound SPI port 3 to the MMCSD driver\n");

	stm32_configgpio(GPIO_ADC1_IN10);
	stm32_configgpio(GPIO_ADC1_IN11);
	//stm32_configgpio(GPIO_ADC1_IN12);	// XXX is this available?
	//stm32_configgpio(GPIO_ADC1_IN13);	// jumperable to MPU6000 DRDY on some boards

	return OK;
}
Exemple #23
0
int nsh_archinitialize(void)
{
  int result;

  /* INIT 1 Lowest level NuttX initialization has been done at this point, LEDs and UARTs are configured */

  /* INIT 2 Configuring PX4 low-level peripherals, these will be always needed */

  /* configure the high-resolution time/callout interface */
#ifdef CONFIG_HRT_TIMER
  hrt_init();
#endif

  /* configure CPU load estimation */
  #ifdef CONFIG_SCHED_INSTRUMENTATION
  cpuload_initialize_once();
  #endif

  /* set up the serial DMA polling */
#ifdef SERIAL_HAVE_DMA
  {
    static struct hrt_call serial_dma_call;
    struct timespec ts;

    /* 
     * Poll at 1ms intervals for received bytes that have not triggered
     * a DMA event.
     */
    ts.tv_sec = 0;
    ts.tv_nsec = 1000000;

    hrt_call_every(&serial_dma_call, 
                   ts_to_abstime(&ts),
                   ts_to_abstime(&ts),
                   (hrt_callout)stm32_serial_dma_poll,
                   NULL);
  }
#endif

  message("\r\n");

  up_ledoff(LED_BLUE);
  up_ledoff(LED_AMBER);

  up_ledon(LED_BLUE);

  /* Configure user-space led driver */
  px4fmu_led_init();

  /* Configure SPI-based devices */

  spi1 = up_spiinitialize(1);
  if (!spi1)
  {
	  message("[boot] FAILED to initialize SPI port 1\r\n");
	  up_ledon(LED_AMBER);
	  return -ENODEV;
  }

  // Setup 10 MHz clock (maximum rate the BMA180 can sustain)
  SPI_SETFREQUENCY(spi1, 10000000);
  SPI_SETBITS(spi1, 8);
  SPI_SETMODE(spi1, SPIDEV_MODE3);
  SPI_SELECT(spi1, PX4_SPIDEV_GYRO, false);
  SPI_SELECT(spi1, PX4_SPIDEV_ACCEL, false);
  SPI_SELECT(spi1, PX4_SPIDEV_MPU, false);
  up_udelay(20);

  message("[boot] Successfully initialized SPI port 1\r\n");

  /* initialize SPI peripherals redundantly */
  int gyro_attempts = 0;
  int gyro_fail = 0;

  while (gyro_attempts < 5)
  {
	  gyro_fail = l3gd20_attach(spi1, PX4_SPIDEV_GYRO);
	  gyro_attempts++;
	  if (gyro_fail == 0) break;
	  up_udelay(1000);
  }

  if (gyro_fail) message("[boot] FAILED to attach L3GD20 gyro\r\n");

  int acc_attempts = 0;
  int acc_fail = 0;

  while (acc_attempts < 5)
  {
	  acc_fail = bma180_attach(spi1, PX4_SPIDEV_ACCEL);
	  acc_attempts++;
	  if (acc_fail == 0) break;
	  up_udelay(1000);
  }

  if (acc_fail) message("[boot] FAILED to attach BMA180 accelerometer\r\n");

  int mpu_attempts = 0;
  int mpu_fail = 0;

  while (mpu_attempts < 1)
  {
	  mpu_fail = mpu6000_attach(spi1, PX4_SPIDEV_MPU);
	  mpu_attempts++;
	  if (mpu_fail == 0) break;
	  up_udelay(200);
  }

  if (mpu_fail) message("[boot] FAILED to attach MPU 6000 gyro/acc\r\n");

  /* initialize I2C2 bus */

  i2c2 = up_i2cinitialize(2);
  if (!i2c2) {
	  message("[boot] FAILED to initialize I2C bus 2\r\n");
	  up_ledon(LED_AMBER);
	  return -ENODEV;
  }

  /* set I2C2 speed */
  I2C_SETFREQUENCY(i2c2, 400000);


  i2c3 = up_i2cinitialize(3);
  if (!i2c3) {
	  message("[boot] FAILED to initialize I2C bus 3\r\n");
	  up_ledon(LED_AMBER);
	  return -ENODEV;
  }

  /* set I2C3 speed */
  I2C_SETFREQUENCY(i2c3, 400000);

  int mag_attempts = 0;
  int mag_fail = 0;

  while (mag_attempts < 5)
  {
	  mag_fail = hmc5883l_attach(i2c2);
	  mag_attempts++;
	  if (mag_fail == 0) break;
	  up_udelay(1000);
  }

  if (mag_fail) message("[boot] FAILED to attach HMC5883L magnetometer\r\n");

  int baro_attempts = 0;
  int baro_fail = 0;
  while (baro_attempts < 5)
  {
	  baro_fail = ms5611_attach(i2c2);
	  baro_attempts++;
	  if (baro_fail == 0) break;
	  up_udelay(1000);
  }

  if (baro_fail) message("[boot] FAILED to attach MS5611 baro at addr #1 or #2 (0x76 or 0x77)\r\n");

  /* try to attach, don't fail if device is not responding */
  (void)eeprom_attach(i2c3, FMU_BASEBOARD_EEPROM_ADDRESS,
		  FMU_BASEBOARD_EEPROM_TOTAL_SIZE_BYTES,
		  FMU_BASEBOARD_EEPROM_PAGE_SIZE_BYTES,
		  FMU_BASEBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/baseboard_eeprom", 1);

  int eeprom_attempts = 0;
  int eeprom_fail;
  while (eeprom_attempts < 5)
  {
	  /* try to attach, fail if device does not respond */
	  eeprom_fail = eeprom_attach(i2c2, FMU_ONBOARD_EEPROM_ADDRESS,
			  FMU_ONBOARD_EEPROM_TOTAL_SIZE_BYTES,
			  FMU_ONBOARD_EEPROM_PAGE_SIZE_BYTES,
			  FMU_ONBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/eeprom", 1);
	  eeprom_attempts++;
	  if (eeprom_fail == OK) break;
	  up_udelay(1000);
  }

  if (eeprom_fail) message("[boot] FAILED to attach FMU EEPROM\r\n");

  /* Report back sensor status */
  if (acc_fail || gyro_fail || mag_fail || baro_fail || eeprom_fail)
  {
	  up_ledon(LED_AMBER);
  }

#if defined(CONFIG_STM32_SPI3)
  /* Get the SPI port */

  message("[boot] Initializing SPI port 3\r\n");
  spi3 = up_spiinitialize(3);
  if (!spi3)
    {
      message("[boot] FAILED to initialize SPI port 3\r\n");
      up_ledon(LED_AMBER);
      return -ENODEV;
    }
  message("[boot] Successfully initialized SPI port 3\r\n");

  /* Now bind the SPI interface to the MMCSD driver */
  result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);
  if (result != OK)
  {
	  message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\r\n");
	  up_ledon(LED_AMBER);
	  return -ENODEV;
  }
  message("[boot] Successfully bound SPI port 3 to the MMCSD driver\r\n");
#endif /* SPI3 */

  /* initialize I2C1 bus */

  i2c1 = up_i2cinitialize(1);
  if (!i2c1) {
    message("[boot] FAILED to initialize I2C bus 1\r\n");
    up_ledon(LED_AMBER);
    return -ENODEV;
  }

  /* set I2C1 speed */
  I2C_SETFREQUENCY(i2c1, 400000);

  /* INIT 3: MULTIPORT-DEPENDENT INITIALIZATION */

  /* Get board information if available */

    /* Initialize the user GPIOs */
  px4fmu_gpio_init();

#ifdef CONFIG_ADC
  int adc_state = adc_devinit();
  if (adc_state != OK)
  {
    /* Try again */
    adc_state = adc_devinit();
    if (adc_state != OK)
    {
      /* Give up */
      message("[boot] FAILED adc_devinit: %d\r\n", adc_state);
      return -ENODEV;
    }
  }
#endif

    /* configure the tone generator */
#ifdef CONFIG_TONE_ALARM
  tone_alarm_init();
#endif

  return OK;
}
Exemple #24
0
int nsh_archinitialize(void)
{
  int result;

  /* INIT 1 Lowest level NuttX initialization has been done at this point, LEDs and UARTs are configured */

  /* INIT 2 Configuring PX4 low-level peripherals, these will be always needed */

  /* configure the high-resolution time/callout interface */
#ifdef CONFIG_HRT_TIMER
  hrt_init();
#endif

  /* configure CPU load estimation */
  #ifdef CONFIG_SCHED_INSTRUMENTATION
  cpuload_initialize_once();
  #endif

  /* set up the serial DMA polling */
#ifdef SERIAL_HAVE_DMA
  {
    static struct hrt_call serial_dma_call;
    struct timespec ts;

    /* 
     * Poll at 1ms intervals for received bytes that have not triggered
     * a DMA event.
     */
    ts.tv_sec = 0;
    ts.tv_nsec = 1000000;

    hrt_call_every(&serial_dma_call, 
                   ts_to_abstime(&ts),
                   ts_to_abstime(&ts),
                   (hrt_callout)stm32_serial_dma_poll,
                   NULL);
  }
#endif

  message("\r\n");

  up_ledoff(LED_BLUE);
  up_ledoff(LED_AMBER);

  up_ledon(LED_BLUE);

  /* Configure user-space led driver */
  px4fmu_led_init();


  i2c2 = up_i2cinitialize(2);
  if (!i2c2) {
	  message("[boot] FAILED to initialize I2C bus 3\r\n");
	  up_ledon(LED_AMBER);
	  return -ENODEV;
  }

  /* set I2C3 speed */
  I2C_SETFREQUENCY(i2c2, 400000);

  /* try to attach, don't fail if device is not responding */
  (void)eeprom_attach(i2c2, FMU_BASEBOARD_EEPROM_ADDRESS,
		  FMU_BASEBOARD_EEPROM_TOTAL_SIZE_BYTES,
		  FMU_BASEBOARD_EEPROM_PAGE_SIZE_BYTES,
		  FMU_BASEBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/baseboard_eeprom", 1);

  int eeprom_attempts = 0;
  int eeprom_fail;
  while (eeprom_attempts < 5)
  {
	  /* try to attach, fail if device does not respond */
	  eeprom_fail = eeprom_attach(i2c2, FMU_ONBOARD_EEPROM_ADDRESS,
			  FMU_ONBOARD_EEPROM_TOTAL_SIZE_BYTES,
			  FMU_ONBOARD_EEPROM_PAGE_SIZE_BYTES,
			  FMU_ONBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/eeprom", 1);
	  eeprom_attempts++;
	  if (eeprom_fail == OK) break;
	  up_udelay(1000);
  }

  if (eeprom_fail) message("[boot] FAILED to attach FMU EEPROM\r\n");

  /* Report back sensor status */
  if (eeprom_fail)
  {
	  up_ledon(LED_AMBER);
  }

#if defined(CONFIG_STM32_SPI3)
  /* Get the SPI port */

  message("[boot] Initializing SPI port 3\r\n");
  spi3 = up_spiinitialize(3);
  if (!spi3)
    {
      message("[boot] FAILED to initialize SPI port 3\r\n");
      up_ledon(LED_AMBER);
      return -ENODEV;
    }
  message("[boot] Successfully initialized SPI port 3\r\n");

  /* Now bind the SPI interface to the MMCSD driver */
  result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);
  if (result != OK)
  {
	  message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\r\n");
	  up_ledon(LED_AMBER);
	  return -ENODEV;
  }
  message("[boot] Successfully bound SPI port 3 to the MMCSD driver\r\n");
#endif /* SPI3 */

  /* INIT 3: MULTIPORT-DEPENDENT INITIALIZATION */

  /* Get board information if available */

    /* Initialize the user GPIOs */
  px4fmu_gpio_init();

#ifdef CONFIG_ADC
  int adc_state = adc_devinit();
  if (adc_state != OK)
  {
    /* Try again */
    adc_state = adc_devinit();
    if (adc_state != OK)
    {
      /* Give up */
      message("[boot] FAILED adc_devinit: %d\r\n", adc_state);
      return -ENODEV;
    }
  }
#endif

    /* configure the tone generator */
#ifdef CONFIG_TONE_ALARM
  tone_alarm_init();
#endif

  return OK;
}
Exemple #25
0
__EXPORT int nsh_archinitialize(void)
{
	int result;

	message("\r\n");

	/* configure ADC pins */
	stm32_configgpio(GPIO_ADC1_IN10);	/* BATT_VOLTAGE_SENS */
	stm32_configgpio(GPIO_ADC1_IN11);	/* BATT_CURRENT_SENS */
	stm32_configgpio(GPIO_ADC1_IN14);	/* SONAR */

	/* configure power supply control/sense pins */



	stm32_configgpio(GPIO_SBUS_INV);






#ifdef GPIO_RC_OUT
	stm32_configgpio(GPIO_RC_OUT);      /* Serial RC output pin */
	stm32_gpiowrite(GPIO_RC_OUT, 1);    /* set it high to pull RC input up */
#endif

	/* configure the GPIO pins to outputs and keep them low */
	stm32_configgpio(GPIO_GPIO0_OUTPUT);
	stm32_configgpio(GPIO_GPIO1_OUTPUT);
	stm32_configgpio(GPIO_GPIO2_OUTPUT);
	stm32_configgpio(GPIO_GPIO3_OUTPUT);
	stm32_configgpio(GPIO_GPIO4_OUTPUT);
	stm32_configgpio(GPIO_GPIO5_OUTPUT);
	stm32_configgpio(GPIO_GPIO6_OUTPUT);
	stm32_configgpio(GPIO_GPIO7_OUTPUT);
	stm32_configgpio(GPIO_GPIO8_OUTPUT);
	stm32_configgpio(GPIO_GPIO9_OUTPUT);
	stm32_configgpio(GPIO_GPI10_OUTPUT);
	stm32_configgpio(GPIO_GPI11_OUTPUT);
    stm32_configgpio(GPIO_GPI12_OUTPUT);
    stm32_configgpio(GPIO_GPI13_OUTPUT);
    stm32_configgpio(GPIO_GPI14_OUTPUT);

	/* configure the high-resolution time/callout interface */
	hrt_init();

	/* configure the DMA allocator */
	dma_alloc_init();

	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif

	/* set up the serial DMA polling */
	static struct hrt_call serial_dma_call;
	struct timespec ts;

	/*
	 * Poll at 1ms intervals for received bytes that have not triggered
	 * a DMA event.
	 */
	ts.tv_sec = 0;
	ts.tv_nsec = 1000000;

	hrt_call_every(&serial_dma_call,
		       ts_to_abstime(&ts),
		       ts_to_abstime(&ts),
		       (hrt_callout)stm32_serial_dma_poll,
		       NULL);

	/* initial LED state */
	drv_led_start();
	led_off(LED_RED);
	led_off(LED_GREEN);
	led_off(LED_BLUE);

	/* Configure SPI-based devices */

	message("[boot] Initializing SPI port 1\r\n");
	spi1 = up_spiinitialize(1);

	if (!spi1) {
		message("[boot] FAILED to initialize SPI port 1\r\n");
		up_ledon(LED_RED);
		return -ENODEV;
	}

	/* Default SPI1 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi1, 10000000);
	SPI_SETBITS(spi1, 8);
	SPI_SETMODE(spi1, SPIDEV_MODE3);
	SPI_SELECT(spi1, SPIDEV_MS5611, false);
	SPI_SELECT(spi1, SPIDEV_EXP_MS5611, false);
	SPI_SELECT(spi1, SPIDEV_EXP_MPU6000, false);
	SPI_SELECT(spi1, SPIDEV_EXP_HMC5983, false);
	up_udelay(20);

	message("[boot] Successfully initialized SPI port 1\r\n");

	message("[boot] Initializing SPI port 2\r\n");
	spi2 = up_spiinitialize(2);

	if (!spi2) {
		message("[boot] FAILED to initialize SPI port 2\r\n");
		up_ledon(LED_RED);
		return -ENODEV;
	}

	/* Default SPI2 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi2, 10000000);
	SPI_SETBITS(spi2, 8);
	SPI_SETMODE(spi2, SPIDEV_MODE3);
	SPI_SELECT(spi2, SPIDEV_MPU9250, false);
	SPI_SELECT(spi2, SPIDEV_IMU_MS5611, false);
	SPI_SELECT(spi2, SPIDEV_IMU_MPU6000, false);
	SPI_SELECT(spi2, SPIDEV_IMU_HMC5983, false);

	message("[boot] Successfully initialized SPI port 2\r\n");

	/* Get the SPI port for the microSD slot */

#ifdef CONFIG_MMCSD
	message("[boot] Initializing SPI port 3\r\n");
	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\r\n");
		up_ledon(LED_RED);
		return -ENODEV;
	}

	/* Default SPI3 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi3, 10000000);
	SPI_SETBITS(spi3, 8);
	SPI_SETMODE(spi3, SPIDEV_MODE3);
	SPI_SELECT(spi3, SPIDEV_MMCSD, false);
	SPI_SELECT(spi3, SPIDEV_FLASH, false);

	message("[boot] Successfully initialized SPI port 3\r\n");

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully bound SPI port 3 to the MMCSD driver\r\n");
#endif

	return OK;
}
Exemple #26
0
__EXPORT int nsh_archinitialize(void)
{
	int result;

	/* configure always-on ADC pins */
	stm32_configgpio(GPIO_ADC1_IN10);
	stm32_configgpio(GPIO_ADC1_IN11);
	/* IN12 and IN13 further below */

	/* configure the high-resolution time/callout interface */
	hrt_init();

	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif

	/* set up the serial DMA polling */
	static struct hrt_call serial_dma_call;
	struct timespec ts;

	/*
	 * Poll at 1ms intervals for received bytes that have not triggered
	 * a DMA event.
	 */
	ts.tv_sec = 0;
	ts.tv_nsec = 1000000;

	hrt_call_every(&serial_dma_call,
		       ts_to_abstime(&ts),
		       ts_to_abstime(&ts),
		       (hrt_callout)stm32_serial_dma_poll,
		       NULL);

	/* initial LED state */
	drv_led_start();
	led_off(LED_AMBER);
	led_off(LED_BLUE);


	/* Configure SPI-based devices */

	spi1 = up_spiinitialize(1);

	if (!spi1) {
		message("[boot] FAILED to initialize SPI port 1\r\n");
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI1 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi1, 10000000);
	SPI_SETBITS(spi1, 8);
	SPI_SETMODE(spi1, SPIDEV_MODE3);
	SPI_SELECT(spi1, PX4_SPIDEV_GYRO, false);
	SPI_SELECT(spi1, PX4_SPIDEV_ACCEL, false);
	SPI_SELECT(spi1, PX4_SPIDEV_MPU, false);
	up_udelay(20);

	/*
	 * If SPI2 is enabled in the defconfig, we loose some ADC pins as chip selects.
	 * Keep the SPI2 init optional and conditionally initialize the ADC pins
	 */

	#ifdef CONFIG_STM32_SPI2
		spi2 = up_spiinitialize(2);
		/* Default SPI2 to 1MHz and de-assert the known chip selects. */
		SPI_SETFREQUENCY(spi2, 10000000);
		SPI_SETBITS(spi2, 8);
		SPI_SETMODE(spi2, SPIDEV_MODE3);
		SPI_SELECT(spi2, PX4_SPIDEV_GYRO, false);
		SPI_SELECT(spi2, PX4_SPIDEV_ACCEL_MAG, false);

		message("[boot] Initialized SPI port2 (ADC IN12/13 blocked)\n");
	#else
		spi2 = NULL;
		message("[boot] Enabling IN12/13 instead of SPI2\n");
		/* no SPI2, use pins for ADC */
		stm32_configgpio(GPIO_ADC1_IN12);
		stm32_configgpio(GPIO_ADC1_IN13);	// jumperable to MPU6000 DRDY on some boards
	#endif

	/* Get the SPI port for the microSD slot */

	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\n");
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n");
		up_ledon(LED_AMBER);
		return -ENODEV;
	}

	return OK;
}
Exemple #27
0
__EXPORT int nsh_archinitialize(void)
{
	int result;

	message("\n");

	/* configure always-on ADC pins */
	stm32_configgpio(GPIO_ADC1_IN10);  //VBAT
	stm32_configgpio(GPIO_ADC1_IN11);  //IBAT
	stm32_configgpio(GPIO_ADC1_IN14); //SONAR_IN_1
	stm32_configgpio(GPIO_ADC1_IN15); //SONAR_IN_2

	stm32_configgpio(GPIO_USB_PRESENT);

	stm32_configgpio(GPIO_SHUTDOWN);
	stm32_configgpio(GPIO_SHUTDOWN_INT);

//	stm32_configgpio(GPIO_AUX_OUT1);
//	stm32_configgpio(GPIO_AUX_OUT2);
//	stm32_configgpio(GPIO_AUX_OUT3);
//	stm32_configgpio(GPIO_AUX_IN1);
//	stm32_configgpio(GPIO_AUX_IN2);


	stm32_configgpio(GPIO_AUX_IO1);
	stm32_configgpio(GPIO_AUX_IO2);
	stm32_configgpio(GPIO_AUX_IO3);
	stm32_configgpio(GPIO_AUX_IO4);
	stm32_configgpio(GPIO_AUX_IO5);
	stm32_configgpio(GPIO_AUX_IO6);

	/* configure the high-resolution time/callout interface */
	hrt_init();

	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif






















	/* initial LED state */
	drv_led_start();
	led_off(LED_AMBER);
	led_off(LED_BLUE);
	led_off(LED_GREEN);




	message("[boot] Initializing USB detect\n");
	stm32_usbinitialize();

	/* Configure SPI-based devices */

	message("[boot] Initializing SPI port 1\n");
	spi1 = up_spiinitialize(1);

	if (!spi1) {
		message("[boot] FAILED to initialize SPI port 1\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI1 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi1, 10000000);
	SPI_SETBITS(spi1, 8);
	SPI_SETMODE(spi1, SPIDEV_MODE3);
	SPI_SELECT(spi1, GPIO_SPI_CS_DATAFLASH, false);

	SPI_SELECT(spi1, GPIO_SPI_CS_EEPROM, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_DF_EXT1, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_DF_EXT2, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_DF_EXT3, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_DF_EXT4, false);
	SPI_SELECT(spi1, GPIO_SPI_CS_DF_EXT5, false);

	SPI_SELECT(spi1, GPIO_SPI_CS_MS5611, false);
	up_udelay(20);

	message("[boot] Successfully initialized SPI port 1\r\n");

	message("[boot] Initializing SPI port 2\n");
	spi2 = up_spiinitialize(2);

	if (!spi2) {
		message("[boot] FAILED to initialize SPI port 2\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI2 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi2, 10000000);
	SPI_SETBITS(spi2, 8);
	SPI_SETMODE(spi2, SPIDEV_MODE3);
	SPI_SELECT(spi2, GPIO_SPI_CS_MPU6000, false);

	message("[boot] Successfully initialized SPI port 2\n");

	/* Get the SPI port for the microSD slot */

	message("[boot] Initializing SPI port 3\n");
	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully initialized SPI port 3\n");

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully bound SPI port 3 to the MMCSD driver\n");

	return OK;
}
Exemple #28
0
__EXPORT int nsh_archinitialize(void)
{
	int result;

	message("\n");

	/* configure always-on ADC pins */
#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)
	stm32_configgpio(GPIO_GPIO0_INPUT);
	stm32_configgpio(GPIO_ADC1_IN0);
#endif
	stm32_configgpio(GPIO_ADC1_IN10);
	stm32_configgpio(GPIO_ADC1_IN11);

	/* configure the high-resolution time/callout interface */
	hrt_init();




	/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
	cpuload_initialize_once();
#endif


















	/* initial BUZZER state */
	drv_buzzer_start();
	buzzer_off(BUZZER_EXT);

	/* initial LED state */
	drv_led_start();
	led_off(LED_AMBER);
	led_off(LED_BLUE);
	led_off(LED_GREEN);
	led_off(LED_EXT1);
	led_off(LED_EXT2);
	led_off(LED_EXT3);

	message("[boot] Initializing USB detect\n");
	stm32_usbinitialize();

	/* Configure SPI-based devices */

	message("[boot] Initializing SPI port 1\n");
	spi1 = up_spiinitialize(1);

	if (!spi1) {
		message("[boot] FAILED to initialize SPI port 1\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI1 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi1, 10000000);
	SPI_SETBITS(spi1, 8);
	SPI_SETMODE(spi1, SPIDEV_MODE3);
	SPI_SELECT(spi1, SPIDEV_FLASH, false);
	SPI_SELECT(spi1, SPIDEV_MS5611, false);
	up_udelay(20);

	message("[boot] Successfully initialized SPI port 1\r\n");

	message("[boot] Initializing SPI port 2\n");
	spi2 = up_spiinitialize(2);

	if (!spi2) {
		message("[boot] FAILED to initialize SPI port 2\r\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI2 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi2, 10000000);
	SPI_SETBITS(spi2, 8);
	SPI_SETMODE(spi2, SPIDEV_MODE3);
	SPI_SELECT(spi2, SPIDEV_MPU6000, false);

	message("[boot] Successfully initialized SPI port 2\n");

#ifndef MPU6000_EXTERNAL
	/* Get the SPI port for the microSD slot */

	message("[boot] Initializing SPI port 3\n");
	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully initialized SPI port 3\n");

	/* Now bind the SPI interface to the MMCSD driver */
	result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);

	if (result != OK) {
		message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	message("[boot] Successfully bound SPI port 3 to the MMCSD driver\n");
#else
	message("[boot] Initializing SPI port 3\n");
	spi3 = up_spiinitialize(3);

	if (!spi3) {
		message("[boot] FAILED to initialize SPI port 3\n");
		led_on(LED_AMBER);
		return -ENODEV;
	}

	/* Default SPI3 to 1MHz and de-assert the known chip selects. */
	SPI_SETFREQUENCY(spi3, 10000000);
	SPI_SETBITS(spi3, 8);
	SPI_SETMODE(spi3, SPIDEV_MODE3);
	SPI_SELECT(spi3, SPIDEV_EXP_MPU6000, false);

	message("[boot] Successfully initialized SPI port 3\n");

#endif

	return OK;
}