int SPI::init() { int ret = OK; /* attach to the spi bus */ if (_dev == nullptr) { _dev = up_spiinitialize(_bus); } if (_dev == nullptr) { DEVICE_DEBUG("failed to init SPI"); ret = -ENOENT; goto out; } // tell other SPI users that we may be doing transfers in // interrupt context up_spi_set_need_irq_save(_dev); /* deselect device to ensure high to low transition of pin select */ SPI_SELECT(_dev, _device, false); /* call the probe function to check whether the device is present */ ret = probe(); if (ret != OK) { DEVICE_DEBUG("probe failed"); goto out; } /* do base class init, which will create the device node, etc. */ ret = CDev::init(); if (ret != OK) { DEVICE_DEBUG("cdev init failed"); goto out; } /* tell the workd where we are */ DEVICE_LOG("on SPI bus %d at %d (%u KHz)", _bus, _device, _frequency / 1000); out: return ret; }
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno) { FAR struct spi_dev_s *spi; FAR struct lcd_dev_s *dev; /* Configure the OLED GPIOs. This initial configuration is RESET low, * putting the OLED into reset state. */ (void)sam_configgpio(GPIO_OLED_RST); /* Wait a bit then release the OLED from the reset state */ up_mdelay(20); sam_gpiowrite(GPIO_OLED_RST, true); /* Get the SPI1 port interface */ spi = up_spiinitialize(OLED_CSNO); if (!spi) { lcddbg("Failed to initialize SPI port 1\n"); } else { /* Bind the SPI port to the OLED */ dev = ssd1306_initialize(spi, devno); if (!dev) { lcddbg("Failed to bind SPI port 1 to OLED %d: %d\n", devno); } else { lcdvdbg("Bound SPI port 1 to OLED %d\n", devno); /* And turn the OLED on */ (void)dev->setpower(dev, CONFIG_LCD_MAXPOWER); return dev; } } return NULL; }
void lis3lv02qd_main(int argc, char *argv[]) { int port = 2; int freq = 1000000; int bits = 8; int conf = 0; spi_dev = up_spiinitialize(port); if (spi_read(port, LIS3LV02DQ_WHO_AM_I, freq, bits, conf) != 0x3A) { printf("It is not LIS3LV02DQ \n"); return; } uint16_t x_low; uint16_t x_high; uint16_t y_low; uint16_t y_high; uint16_t z_low; uint16_t z_high; uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; int i; for (i = 0; i < 30; i++) { spi_write(port, LIS3LV02DQ_CONF_REG_1, freq, bits, conf, 0x87); x_low = spi_read(port, LIS3LV02DQ_OUTX_L, freq, bits, conf); x_high = spi_read(port, LIS3LV02DQ_OUTX_H, freq, bits, conf); y_low = spi_read(port, LIS3LV02DQ_OUTY_L, freq, bits, conf); y_high = spi_read(port, LIS3LV02DQ_OUTY_H, freq, bits, conf); z_low = spi_read(port, LIS3LV02DQ_OUTZ_L, freq, bits, conf); z_high = spi_read(port, LIS3LV02DQ_OUTZ_H, freq, bits, conf); x = (x_low | (x_high << 8)); y = (y_low | (y_high << 8)); z = (z_low | (z_high << 8)); printf("x(0x%04x), y(0x%04x), z(0x%04x)\n", x, y, z); up_mdelay(500); } }
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno) { FAR struct spi_dev_s *spi; FAR struct lcd_dev_s *dev; /* Configure the OLED GPIOs */ oledcs_dumpgpio("board_graphics_setup: After OLEDCS setup"); oleddc_dumpgpio("board_graphics_setup: On entry"); tiva_configgpio(OLEDDC_GPIO); /* PC7: OLED display data/control select (D/Cn) */ tiva_configgpio(OLEDEN_GPIO); /* PC6: Enable +15V needed by OLED (EN+15V) */ oleddc_dumpgpio("board_graphics_setup: After OLEDDC/EN setup"); /* Get the SSI port (configure as a Freescale SPI port) */ spi = up_spiinitialize(0); if (!spi) { glldbg("Failed to initialize SSI port 0\n"); } else { /* Bind the SSI port to the OLED */ dev = rit_initialize(spi, devno); if (!dev) { glldbg("Failed to bind SSI port 0 to OLED %d: %d\n", devno); } else { gllvdbg("Bound SSI port 0 to OLED %d\n", devno); /* And turn the OLED on (CONFIG_LCD_MAXPOWER should be 1) */ (void)dev->setpower(dev, CONFIG_LCD_MAXPOWER); return dev; } } return NULL; }
unsigned int SPIPump(uint8_t data) { uint8_t rx; printf("SPIPump tx = 0x%X ", data); if (!spi) { spi = up_spiinitialize(1); SPI_SETBITS(spi, 8); SPI_SETMODE(spi, SPIDEV_MODE1); } SPI_EXCHANGE(spi, &data, &rx, 1); printf(" rx = 0x%X\n", rx); return rx; }
void up_netinitialize(void) { FAR struct spi_dev_s *spi; uint16_t reg16; int ret; /* Get the SPI port */ spi = up_spiinitialize(ENC28J60_SPI_PORTNO); if (!spi) { nlldbg("Failed to initialize SPI port %d\n", ENC28J60_SPI_PORTNO); return; } /* Configure the XTI for the ENC28J60 interrupt. */ ret = str71x_xticonfig(ENC28J60_IRQ, false); if (ret < 0) { nlldbg("Failed configure interrupt for IRQ %d: %d\n", ENC28J60_IRQ, ret); return; } /* Take ENC28J60 out of reset (active low)*/ reg16 = getreg16(STR71X_GPIO0_PD); reg16 &= ~ENC_GPIO0_NETRST; putreg16(reg16, STR71X_GPIO0_PD); /* Bind the SPI port to the ENC28J60 driver */ ret = enc_initialize(spi, ENC28J60_DEVNO, ENC28J60_IRQ); if (ret < 0) { nlldbg("Failed to bind SPI port %d ENC28J60 device %d: %d\n", ENC28J60_SPI_PORTNO, ENC28J60_DEVNO, ret); return; } nllvdbg("Bound SPI port %d to ENC28J60 device %d\n", ENC28J60_SPI_PORTNO, ENC28J60_DEVNO); }
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; }
int usbmsc_archinitialize(void) { 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_USBMSC_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); return OK; }
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; }
static void spansion_attach(void) { /* find the right spi */ struct spi_dev_s *spi = up_spiinitialize(1); /* this resets the spi bus, set correct bus speed again */ SPI_SETFREQUENCY(spi, 10 * 1000 * 1000); SPI_SETBITS(spi, 8); SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SELECT(spi, SPIDEV_FLASH, false); /* set 0 dummy cycles */ //SPI_SEND(spi, if (spi == NULL) errx(1, "failed to locate spi bus"); /* start the RAMTRON driver, attempt 5 times */ for (int i = 0; i < 10; i++) { mtd_dev = m25p_initialize(spi); if (mtd_dev) { /* abort on first valid result */ if (i > 0) { warnx("warning: mtd needed %d attempts to attach", i + 1); } break; } } /* if last attempt is still unsuccessful, abort */ if (mtd_dev == NULL) errx(1, "failed to initialize mtd driver"); int ret = mtd_dev->ioctl(mtd_dev, MTDIOC_SETSPEED, (unsigned long)10*1000*1000); if (ret != OK) warnx(1, "failed to set bus speed"); attached = true; }
int SPI::init() { int ret = OK; /* attach to the spi bus */ if (_dev == nullptr) _dev = up_spiinitialize(_bus); if (_dev == nullptr) { debug("failed to init SPI"); ret = -ENOENT; goto out; } /* deselect device to ensure high to low transition of pin select */ SPI_SELECT(_dev, _device, false); /* call the probe function to check whether the device is present */ ret = probe(); if (ret != OK) { debug("probe failed"); goto out; } /* do base class init, which will create the device node, etc. */ ret = CDev::init(); if (ret != OK) { debug("cdev init failed"); goto out; } /* tell the workd where we are */ log("on SPI bus %d at %d (%u KHz)", _bus, _device, _frequency / 1000); out: return ret; }
int stm32_max31855initialize(FAR const char *devpath) { FAR struct spi_dev_s *spi; int ret; spi = up_spiinitialize(MAX31855_SPI_PORTNO); if (!spi) { return -ENODEV; } /* Then register the barometer sensor */ ret = max31855_register(devpath, spi); if (ret < 0) { sndbg("Error registering MAX31855\n"); } return ret; }
int arch_tcinitialize(int minor) { FAR struct spi_dev_s *dev; int ret; idbg("minor %d\n", minor); DEBUGASSERT(minor == 0); /* Configure and enable the ADS7843E interrupt pin as an input */ (void)sam_configgpio(GPIO_TCS_BUSY); (void)sam_configgpio(GPIO_TCS_IRQ); /* Configure the PIO interrupt */ sam_gpioirq(GPIO_TCS_IRQ); /* Get an instance of the SPI interface for the touchscreen chip select */ dev = up_spiinitialize(TSC_CSNUM); if (!dev) { idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); return -ENODEV; } /* Initialize and register the SPI touschscreen device */ ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR); if (ret < 0) { idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); /* up_spiuninitialize(dev); */ return -ENODEV; } return OK; }
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; }
int SPI::init() { int ret = OK; // attach to the spi bus if (_dev == nullptr) _dev = up_spiinitialize(_bus); if (_dev == nullptr) { debug("failed to init SPI"); ret = -ENOENT; goto out; } // call the probe function to check whether the device is present ret = probe(); if (ret != OK) { debug("probe failed"); goto out; } // do base class init, which will create the device node, etc. ret = CDev::init(); if (ret != OK) { debug("cdev init failed"); goto out; } // tell the workd where we are log("on SPI bus %d at %d", _bus, _device); out: return ret; }
int stm32_sdinitialize(int minor) { #ifdef HAVE_MMCSD FAR struct spi_dev_s *spi; int ret; /* Get the SPI port */ fvdbg("Initializing SPI port %d\n", STM32_MMCSDSPIPORTNO); spi = up_spiinitialize(STM32_MMCSDSPIPORTNO); if (!spi) { fdbg("Failed to initialize SPI port %d\n", STM32_MMCSDSPIPORTNO); return -ENODEV; } fvdbg("Successfully initialized SPI port %d\n", STM32_MMCSDSPIPORTNO); /* Bind the SPI port to the slot */ fvdbg("Binding SPI port %d to MMC/SD slot %d\n", STM32_MMCSDSPIPORTNO, STM32_MMCSDSLOTNO); ret = mmcsd_spislotinitialize(minor, STM32_MMCSDSLOTNO, spi); if (ret < 0) { fdbg("Failed to bind SPI port %d to MMC/SD slot %d: %d\n", STM32_MMCSDSPIPORTNO, STM32_MMCSDSLOTNO, ret); return ret; } fvdbg("Successfuly bound SPI port %d to MMC/SD slot %d\n", STM32_MMCSDSPIPORTNO, STM32_MMCSDSLOTNO); #endif return OK; }
__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; }
__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; }
__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; }
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; }
__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; }
__EXPORT int nsh_archinitialize(void) { /* configure ADC pins */ stm32_configgpio(GPIO_ADC1_IN2); /* BATT_VOLTAGE_SENS */ stm32_configgpio(GPIO_ADC1_IN3); /* BATT_CURRENT_SENS */ stm32_configgpio(GPIO_ADC1_IN4); /* VDD_5V_SENS */ stm32_configgpio(GPIO_ADC1_IN11); /* BATT2_VOLTAGE_SENS */ stm32_configgpio(GPIO_ADC1_IN13); /* BATT2_CURRENT_SENS */ /* configure power supply control/sense pins */ stm32_configgpio(GPIO_VDD_3V3_PERIPH_EN); stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN); stm32_configgpio(GPIO_VDD_5V_PERIPH_EN); stm32_configgpio(GPIO_VDD_5V_HIPOWER_EN); stm32_configgpio(GPIO_VDD_BRICK_VALID); stm32_configgpio(GPIO_VDD_BRICK2_VALID); stm32_configgpio(GPIO_VDD_5V_PERIPH_OC); stm32_configgpio(GPIO_VDD_5V_HIPOWER_OC); stm32_configgpio(GPIO_VBUS_VALID); // stm32_configgpio(GPIO_SBUS_INV); // stm32_configgpio(GPIO_8266_GPIO0); // stm32_configgpio(GPIO_SPEKTRUM_PWR_EN); // stm32_configgpio(GPIO_8266_PD); // stm32_configgpio(GPIO_8266_RST); // stm32_configgpio(GPIO_BTN_SAFETY_FMU); /* 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); /* 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_AMBER); /* Configure SPI-based devices */ spi1 = up_spiinitialize(1); if (!spi1) { message("[boot] FAILED to initialize SPI port 1\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_ICM, false); SPI_SELECT(spi1, PX4_SPIDEV_BARO, false); SPI_SELECT(spi1, PX4_SPIDEV_LIS, false); SPI_SELECT(spi1, PX4_SPIDEV_MPU, false); SPI_SELECT(spi1, PX4_SPIDEV_EEPROM, false); up_udelay(20); /* Get the SPI port for the FRAM */ spi2 = up_spiinitialize(2); if (!spi2) { message("[boot] FAILED to initialize SPI port 2\n"); up_ledon(LED_AMBER); return -ENODEV; } /* Default SPI2 to 37.5 MHz (40 MHz rounded to nearest valid divider, F4 max) * and de-assert the known chip selects. */ // XXX start with 10.4 MHz in FRAM usage and go up to 37.5 once validated SPI_SETFREQUENCY(spi2, 12 * 1000 * 1000); SPI_SETBITS(spi2, 8); SPI_SETMODE(spi2, SPIDEV_MODE3); SPI_SELECT(spi2, SPIDEV_FLASH, false); /* Configure SPI 5-based devices */ spi5 = up_spiinitialize(PX4_SPI_EXT0); if (!spi5) { message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_EXT0); up_ledon(LED_RED); return -ENODEV; } /* Default SPI5 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi5, 10000000); SPI_SETBITS(spi5, 8); SPI_SETMODE(spi5, SPIDEV_MODE3); SPI_SELECT(spi5, PX4_SPIDEV_EXT0, false); /* Configure SPI 6-based devices */ spi6 = up_spiinitialize(PX4_SPI_EXT1); if (!spi6) { message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_EXT1); up_ledon(LED_RED); return -ENODEV; } /* Default SPI6 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi6, 10000000); SPI_SETBITS(spi6, 8); SPI_SETMODE(spi6, SPIDEV_MODE3); SPI_SELECT(spi6, PX4_SPIDEV_EXT1, false); #ifdef CONFIG_MMCSD /* First, get an instance of the SDIO interface */ sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO); if (!sdio) { message("[boot] Failed to initialize SDIO slot %d\n", CONFIG_NSH_MMCSDSLOTNO); return -ENODEV; } /* Now bind the SDIO interface to the MMC/SD driver */ int ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio); if (ret != OK) { message("[boot] Failed to bind SDIO to the MMC/SD driver: %d\n", ret); return ret; } /* Then let's guess and say that there is a card in the slot. There is no card detect GPIO. */ sdio_mediachange(sdio, true); #endif return OK; }
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; }
int board_app_initialize(void) { #if defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR) int ret; #endif #if defined(CONFIG_STM32_SPI4) FAR struct spi_dev_s *spi; FAR struct mtd_dev_s *mtd; #endif #if defined(CONFIG_MTD_PARTITION_NAMES) FAR const char *partname = CONFIG_STM32F429I_DISCO_FLASH_PART_NAMES; #endif /* Configure SPI-based devices */ #ifdef CONFIG_STM32_SPI4 /* Get the SPI port */ syslog(LOG_INFO, "Initializing SPI port 4\n"); spi = up_spiinitialize(4); if (!spi) { syslog(LOG_ERR, "ERROR: Failed to initialize SPI port 4\n"); return -ENODEV; } syslog(LOG_INFO, "Successfully initialized SPI port 4\n"); /* Now bind the SPI interface to the SST25F064 SPI FLASH driver. This * is a FLASH device that has been added external to the board (i.e. * the board does not ship from STM with any on-board FLASH. */ #if defined(CONFIG_MTD) && defined(CONFIG_MTD_SST25XX) syslog(LOG_INFO, "Bind SPI to the SPI flash driver\n"); mtd = sst25xx_initialize(spi); if (!mtd) { syslog(LOG_ERR, "ERROR: Failed to bind SPI port 4 to the SPI FLASH driver\n"); } else { syslog(LOG_INFO, "Successfully bound SPI port 4 to the SPI FLASH driver\n"); #ifdef CONFIG_STM32F429I_DISCO_FLASH_PART { int partno; int partsize; int partoffset; const char *partstring = CONFIG_STM32F429I_DISCO_FLASH_PART_LIST; const char *ptr; FAR struct mtd_dev_s *mtd_part; char partref[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_STM32F429I_DISCO_FLASH_CONFIG_PART /* Test if this is the config partition */ if (CONFIG_STM32F429I_DISCO_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(partref, "p%d", partno); smart_initialize(CONFIG_STM32F429I_DISCO_FLASH_MINOR, mtd_part, partref); #endif } /* Set the partition name */ #if defined(CONFIG_MTD_PARTITION_NAMES) mtd_setpartitionname(mtd_part, partname); /* Now skip to next name. We don't need to split the string here * because the MTD partition logic will only display names up to * the comma, thus allowing us to use a single static name * in the code. */ while (*partname != ',' && *partname != '\0') { /* Skip to next ',' */ partname++; } if (*partname == ',') { 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_STM32F429I_DISCO_FLASH_PART */ /* Configure the device with no partition support */ smart_initialize(CONFIG_STM32F429I_DISCO_FLASH_MINOR, mtd, NULL); #endif /* CONFIG_STM32F429I_DISCO_FLASH_PART */ } #endif /* CONFIG_MTD */ #endif /* CONFIG_STM32_SPI4 */ /* Create a RAM MTD device if configured */ #if defined(CONFIG_RAMMTD) && defined(CONFIG_STM32F429I_DISCO_RAMMTD) { uint8_t *start = (uint8_t *) kmm_malloc(CONFIG_STM32F429I_DISCO_RAMMTD_SIZE * 1024); mtd = rammtd_initialize(start, CONFIG_STM32F429I_DISCO_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_STM32F429I_DISCO_RAMMTD_MINOR, mtd, NULL); #endif } #endif /* CONFIG_RAMMTD && CONFIG_STM32F429I_DISCO_RAMMTD */ #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) { syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", ret); return ret; } #endif #ifdef HAVE_USBMONITOR /* Start the USB Monitor */ ret = usbmonitor_start(0, NULL); if (ret != OK) { syslog(LOG_ERR, "ERROR: Failed to start USB monitor: %d\n", ret); } #endif return OK; }
__EXPORT int nsh_archinitialize(void) { /* configure ADC pins */ stm32_configgpio(GPIO_ADC1_IN2); /* BATT_VOLTAGE_SENS */ stm32_configgpio(GPIO_ADC1_IN3); /* BATT_CURRENT_SENS */ stm32_configgpio(GPIO_ADC1_IN4); /* VDD_5V_SENS */ stm32_configgpio(GPIO_ADC1_IN13); /* FMU_AUX_ADC_1 */ stm32_configgpio(GPIO_ADC1_IN14); /* FMU_AUX_ADC_2 */ stm32_configgpio(GPIO_ADC1_IN15); /* PRESSURE_SENS */ /* configure power supply control/sense pins */ stm32_configgpio(GPIO_VDD_5V_PERIPH_EN); stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN); stm32_configgpio(GPIO_VDD_BRICK_VALID); stm32_configgpio(GPIO_VDD_SERVO_VALID); stm32_configgpio(GPIO_VDD_5V_HIPOWER_OC); stm32_configgpio(GPIO_VDD_5V_PERIPH_OC); #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) /* run C++ ctors before we go any further */ up_cxxinitialize(); # if defined(CONFIG_EXAMPLES_NSH_CXXINITIALIZE) # error CONFIG_EXAMPLES_NSH_CXXINITIALIZE Must not be defined! Use CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE. # endif #else # error platform is dependent on c++ both CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE must be defined. #endif /* 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_AMBER); /* Configure SPI-based devices */ spi1 = up_spiinitialize(1); if (!spi1) { syslog(LOG_ERR, "[boot] FAILED to initialize SPI port 1\n"); board_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, PX4_SPIDEV_GYRO, false); SPI_SELECT(spi1, PX4_SPIDEV_ACCEL_MAG, false); SPI_SELECT(spi1, PX4_SPIDEV_BARO, false); SPI_SELECT(spi1, PX4_SPIDEV_MPU, false); up_udelay(20); syslog(LOG_INFO, "[boot] Initialized SPI port 1 (SENSORS)\n"); /* Get the SPI port for the FRAM */ spi2 = up_spiinitialize(2); if (!spi2) { syslog(LOG_ERR, "[boot] FAILED to initialize SPI port 2\n"); board_led_on(LED_AMBER); return -ENODEV; } /* Default SPI2 to 37.5 MHz (40 MHz rounded to nearest valid divider, F4 max) * and de-assert the known chip selects. */ // XXX start with 10.4 MHz in FRAM usage and go up to 37.5 once validated SPI_SETFREQUENCY(spi2, 12 * 1000 * 1000); SPI_SETBITS(spi2, 8); SPI_SETMODE(spi2, SPIDEV_MODE3); SPI_SELECT(spi2, SPIDEV_FLASH, false); syslog(LOG_INFO, "[boot] Initialized SPI port 2 (RAMTRON FRAM)\n"); spi4 = up_spiinitialize(4); /* Default SPI4 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi4, 10000000); SPI_SETBITS(spi4, 8); SPI_SETMODE(spi4, SPIDEV_MODE3); SPI_SELECT(spi4, PX4_SPIDEV_EXT0, false); SPI_SELECT(spi4, PX4_SPIDEV_EXT1, false); syslog(LOG_INFO, "[boot] Initialized SPI port 4\n"); #ifdef CONFIG_MMCSD /* First, get an instance of the SDIO interface */ sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO); if (!sdio) { syslog(LOG_ERR, "[boot] Failed to initialize SDIO slot %d\n", CONFIG_NSH_MMCSDSLOTNO); return -ENODEV; } /* Now bind the SDIO interface to the MMC/SD driver */ int ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio); if (ret != OK) { syslog(LOG_ERR, "[boot] Failed to bind SDIO to the MMC/SD driver: %d\n", ret); return ret; } /* Then let's guess and say that there is a card in the slot. There is no card detect GPIO. */ sdio_mediachange(sdio, true); syslog(LOG_INFO, "[boot] Initialized SDIO\n"); #endif return OK; }
__EXPORT int nsh_archinitialize(void) { /* configure ADC pins */ stm32_configgpio(GPIO_ADC1_IN2); /* BATT_VOLTAGE_SENS */ stm32_configgpio(GPIO_ADC1_IN3); /* BATT_CURRENT_SENS */ stm32_configgpio(GPIO_ADC1_IN4); /* VDD_5V_SENS */ // stm32_configgpio(GPIO_ADC1_IN10); /* used by VBUS valid */ // stm32_configgpio(GPIO_ADC1_IN11); /* unused */ // stm32_configgpio(GPIO_ADC1_IN12); /* used by MPU6000 CS */ stm32_configgpio(GPIO_ADC1_IN13); /* FMU_AUX_ADC_1 */ stm32_configgpio(GPIO_ADC1_IN14); /* FMU_AUX_ADC_2 */ stm32_configgpio(GPIO_ADC1_IN15); /* PRESSURE_SENS */ /* configure power supply control/sense pins */ stm32_configgpio(GPIO_VDD_5V_PERIPH_EN); stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN); stm32_configgpio(GPIO_VDD_BRICK_VALID); stm32_configgpio(GPIO_VDD_SERVO_VALID); stm32_configgpio(GPIO_VDD_5V_HIPOWER_OC); stm32_configgpio(GPIO_VDD_5V_PERIPH_OC); /* 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); /* Configure SPI-based devices */ spi1 = up_spiinitialize(1); if (!spi1) { message("[boot] FAILED to initialize SPI port 1\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_MAG, false); SPI_SELECT(spi1, PX4_SPIDEV_BARO, false); SPI_SELECT(spi1, PX4_SPIDEV_MPU, false); up_udelay(20); message("[boot] Successfully initialized SPI port 1\n"); /* Get the SPI port for the FRAM */ spi2 = up_spiinitialize(2); if (!spi2) { message("[boot] FAILED to initialize SPI port 2\n"); up_ledon(LED_AMBER); return -ENODEV; } /* Default SPI2 to 37.5 MHz (F4 max) and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi2, 375000000); SPI_SETBITS(spi2, 8); SPI_SETMODE(spi2, SPIDEV_MODE3); SPI_SELECT(spi2, SPIDEV_FLASH, false); message("[boot] Successfully initialized SPI port 2\n"); #ifdef CONFIG_MMCSD /* First, get an instance of the SDIO interface */ sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO); if (!sdio) { message("nsh_archinitialize: Failed to initialize SDIO slot %d\n", CONFIG_NSH_MMCSDSLOTNO); return -ENODEV; } /* Now bind the SDIO interface to the MMC/SD driver */ int ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio); if (ret != OK) { message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); return ret; } /* Then let's guess and say that there is a card in the slot. There is no card detect GPIO. */ sdio_mediachange(sdio, true); message("[boot] Initialized SDIO\n"); #endif return OK; }
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; }
static int do_composite_archinitialize(void) { #ifdef HAVE_SST25 FAR struct spi_dev_s *spi; FAR struct mtd_dev_s *mtd; int ret; /* Configure SPI-based devices */ /* Get the SPI port */ fvdbg("Initializing SPI port %d\n", CONFIG_SPARK_FLASH_SPI); spi = up_spiinitialize(CONFIG_SPARK_FLASH_SPI); if (!spi) { fdbg("ERROR: Failed to initialize SPI port %d\n", CONFIG_SPARK_FLASH_SPI); return -ENODEV; } fvdbg("Successfully initialized SPI port %d\n", CONFIG_SPARK_FLASH_SPI); /* Now bind the SPI interface to the SST25 SPI FLASH driver */ fvdbg("Bind SPI to the SPI flash driver\n"); mtd = sst25_initialize(spi); if (!mtd) { fdbg("ERROR: Failed to bind SPI port %d to the SPI FLASH driver\n", CONFIG_SPARK_FLASH_SPI); } else { fvdbg("Successfully bound SPI port %d to the SPI FLASH driver\n", CONFIG_SPARK_FLASH_SPI); } #ifndef CONFIG_SPARK_FLASH_PART /* Use the FTL layer to wrap the MTD driver as a block driver */ ret = ftl_initialize(CONFIG_SPARK_FLASH_MINOR, mtd); if (ret < 0) { fdbg("ERROR: Initialize the FTL layer\n"); return ret; } #ifdef CONFIG_SPARK_MOUNT_FLASH char partname[16]; char mntpoint[16]; /* mount -t vfat /dev/mtdblock0 /mnt/p0 */ snprintf(partname, sizeof(partname), "/dev/mtdblock%d", CONFIG_SPARK_FLASH_MINOR); snprintf(mntpoint, sizeof(mntpoint)-1, CONFIG_SPARK_FLASH_MOUNT_POINT, CONFIG_SPARK_FLASH_MINOR); /* Mount the file system at /mnt/pn */ ret = mount(partname, mntpoint, "vfat", 0, NULL); if (ret < 0) { fdbg("ERROR: Failed to mount the FAT volume: %d\n", errno); return ret; } #endif #else { int partno; int partsize; int partoffset; const char *partstring = CONFIG_SPARK_FLASH_PART_LIST; const char *ptr; FAR struct mtd_dev_s *mtd_part; char partname[16]; char mntpoint[16]; /* Now create a partition on the FLASH device */ partno = CONFIG_SPARK_FLASH_MINOR; 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; /* Use the FTL layer to wrap the MTD driver as a block driver */ ret = ftl_initialize(partno, mtd_part); if (ret < 0) { fdbg("ERROR: Initialize the FTL layer\n"); return ret; } snprintf(partname,sizeof(partname), "/dev/mtdblock%d", partno); snprintf(mntpoint,sizeof(mntpoint)-1, CONFIG_SPARK_FLASH_MOUNT_POINT, partno); /* Mount the file system at /mnt/pn */ ret = mount(partname, mntpoint, "vfat", 0, NULL); if (ret < 0) { fdbg("ERROR: Failed to mount the FAT volume: %d\n", errno); return ret; } /* 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++; } } #endif /* CONFIG_SPARK_FLASH_PART */ #endif /* HAVE_SST25 */ #ifdef HAVE_USBMONITOR /* Start the USB Monitor */ ret = usbmonitor_start(0, NULL); if (ret != OK) { fdbg("ERROR: Failed to start USB monitor: %d\n", ret); } #endif return OK; }
int nsh_archinitialize(void) { #ifdef CONFIG_STM32_SPI1 FAR struct spi_dev_s *spi; FAR struct mtd_dev_s *mtd; #endif #ifdef NSH_HAVEMMCSD FAR struct sdio_dev_s *sdio; #endif #if defined(NSH_HAVEMMCSD) || defined(CONFIG_DJOYSTICK) int ret; #endif /* Configure SPI-based devices */ #ifdef CONFIG_STM32_SPI1 /* Get the SPI port */ syslog(LOG_INFO, "Initializing SPI port 1\n"); spi = up_spiinitialize(1); if (!spi) { syslog(LOG_ERR, "ERROR: Failed to initialize SPI port 0\n"); return -ENODEV; } syslog(LOG_INFO, "Successfully initialized SPI port 0\n"); /* Now bind the SPI interface to the M25P64/128 SPI FLASH driver */ syslog(LOG_INFO, "Bind SPI to the SPI flash driver\n"); mtd = m25p_initialize(spi); if (!mtd) { syslog(LOG_ERR, "ERROR: Failed to bind SPI port 0 to the SPI FLASH driver\n"); return -ENODEV; } syslog(LOG_INFO, "Successfully bound SPI port 0 to the SPI FLASH driver\n"); #warning "Now what are we going to do with this SPI FLASH driver?" #endif /* Create the SPI FLASH MTD instance */ /* The M25Pxx is not a give media to implement a file system.. * its block sizes are too large */ /* Mount the SDIO-based MMC/SD block driver */ #ifdef NSH_HAVEMMCSD /* First, get an instance of the SDIO interface */ syslog(LOG_INFO, "Initializing SDIO slot %d\n", CONFIG_NSH_MMCSDSLOTNO); sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO); if (!sdio) { syslog(LOG_ERR, "ERROR: Failed to initialize SDIO slot %d\n", CONFIG_NSH_MMCSDSLOTNO); return -ENODEV; } /* Now bind the SDIO interface to the MMC/SD driver */ syslog(LOG_INFO, "Bind SDIO to the MMC/SD driver, minor=%d\n", CONFIG_NSH_MMCSDMINOR); ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio); if (ret != OK) { syslog(LOG_ERR, "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); return ret; } syslog(LOG_INFO, "Successfully bound SDIO to the MMC/SD driver\n"); /* Then let's guess and say that there is a card in the slot. I need to check to * see if the STM3210E-EVAL board supports a GPIO to detect if there is a card in * the slot. */ sdio_mediachange(sdio, true); #endif #ifdef CONFIG_DJOYSTICK /* Initialize and register the joystick driver */ ret = stm32_djoy_initialization(); if (ret != OK) { syslog(LOG_ERR, "ERROR: Failed to register the joystick driver: %d\n", ret); return ret; } syslog(LOG_INFO, "Successfully registered the joystick driver\n"); #endif return OK; }
int sam_at25_automount(int minor) { FAR struct spi_dev_s *spi; FAR struct mtd_dev_s *mtd; static bool initialized = false; int ret; /* Have we already initialized? */ if (!initialized) { /* No.. Get the SPI port driver */ spi = up_spiinitialize(FLASH_CSNUM); if (!spi) { fdbg("ERROR: Failed to initialize SPI port %d\n", FLASH_CSNUM); return -ENODEV; } /* Now bind the SPI interface to the AT25 SPI FLASH driver */ mtd = at25_initialize(spi); if (!mtd) { fdbg("ERROR: Failed to bind SPI port %d to the AT25 FLASH driver\n"); return -ENODEV; } #if defined(CONFIG_SAM4EEK_AT25_FTL) /* And finally, use the FTL layer to wrap the MTD driver as a block * driver at /dev/mtdblockN, where N=minor device number. */ ret = ftl_initialize(minor, mtd); if (ret < 0) { fdbg("ERROR: Failed to initialize the FTL layer: %d\n", ret); return ret; } #elif defined(CONFIG_SAM4EEK_AT25_NXFFS) /* Initialize to provide NXFFS on the MTD interface */ ret = nxffs_initialize(mtd); if (ret < 0) { fdbg("ERROR: NXFFS initialization failed: %d\n", ret); return ret; } /* Mount the file system at /mnt/at25 */ ret = mount(NULL, "/mnt/at25", "nxffs", 0, NULL); if (ret < 0) { fdbg("ERROR: Failed to mount the NXFFS volume: %d\n", errno); return ret; } #endif /* Now we are initialized */ initialized = true; } return OK; }