|
|
|
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* |
|
|
|
|
* Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved. |
|
|
|
|
* Copyright (c) 2012-2015 PX4 Development Team. All rights reserved. |
|
|
|
|
* |
|
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
|
* modification, are permitted provided that the following conditions |
|
|
|
@ -35,10 +35,10 @@
@@ -35,10 +35,10 @@
|
|
|
|
|
* @file px4fmu_init.c |
|
|
|
|
* |
|
|
|
|
* PX4FMU-specific early startup code. This file implements the |
|
|
|
|
* nsh_archinitialize() function that is called early by nsh during startup. |
|
|
|
|
* board_app_initialize() function that is called early by nsh during startup. |
|
|
|
|
* |
|
|
|
|
* Code here is run before the rcS script is invoked; it should start required |
|
|
|
|
* subsystems and perform board-specific initialisation. |
|
|
|
|
* subsystems and perform board-specific initialization. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
@ -53,8 +53,9 @@
@@ -53,8 +53,9 @@
|
|
|
|
|
#include <errno.h> |
|
|
|
|
|
|
|
|
|
#include <nuttx/arch.h> |
|
|
|
|
#include <nuttx/spi.h> |
|
|
|
|
#include <nuttx/i2c.h> |
|
|
|
|
#include <nuttx/board.h> |
|
|
|
|
#include <nuttx/spi/spi.h> |
|
|
|
|
#include <nuttx/i2c/i2c_master.h> |
|
|
|
|
#include <nuttx/mmcsd.h> |
|
|
|
|
#include <nuttx/analog/adc.h> |
|
|
|
|
|
|
|
|
@ -79,13 +80,13 @@
@@ -79,13 +80,13 @@
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPP_HAVE_VARARGS |
|
|
|
|
# ifdef CONFIG_DEBUG |
|
|
|
|
# define message(...) lowsyslog(__VA_ARGS__) |
|
|
|
|
# define message(...) syslog(__VA_ARGS__) |
|
|
|
|
# else |
|
|
|
|
# define message(...) printf(__VA_ARGS__) |
|
|
|
|
# endif |
|
|
|
|
#else |
|
|
|
|
# ifdef CONFIG_DEBUG |
|
|
|
|
# define message lowsyslog |
|
|
|
|
# define message syslog |
|
|
|
|
# else |
|
|
|
|
# define message printf |
|
|
|
|
# endif |
|
|
|
@ -124,18 +125,39 @@ __END_DECLS
@@ -124,18 +125,39 @@ __END_DECLS
|
|
|
|
|
|
|
|
|
|
__EXPORT void stm32_boardinitialize(void) |
|
|
|
|
{ |
|
|
|
|
/* configure always-on ADC pins */ |
|
|
|
|
stm32_configgpio(GPIO_ADC1_IN10); |
|
|
|
|
stm32_configgpio(GPIO_ADC1_IN11); |
|
|
|
|
|
|
|
|
|
/* configure SPI interfaces */ |
|
|
|
|
stm32_spiinitialize(); |
|
|
|
|
|
|
|
|
|
/* configure LEDs (empty call to NuttX' ledinit) */ |
|
|
|
|
up_ledinit(); |
|
|
|
|
/* configure LEDs (empty call to NuttX' ) */ |
|
|
|
|
board_autoled_initialize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nsh_archinitialize |
|
|
|
|
* Name: board_app_initialize |
|
|
|
|
* |
|
|
|
|
* Description: |
|
|
|
|
* Perform architecture specific initialization |
|
|
|
|
* Perform application specific initialization. This function is never |
|
|
|
|
* called directly from application code, but only indirectly via the |
|
|
|
|
* (non-standard) boardctl() interface using the command BOARDIOC_INIT. |
|
|
|
|
* |
|
|
|
|
* Input Parameters: |
|
|
|
|
* arg - The boardctl() argument is passed to the board_app_initialize() |
|
|
|
|
* implementation without modification. The argument has no |
|
|
|
|
* meaning to NuttX; the meaning of the argument is a contract |
|
|
|
|
* between the board-specific initalization logic and the the |
|
|
|
|
* matching application logic. The value cold be such things as a |
|
|
|
|
* mode enumeration value, a set of DIP switch switch settings, a |
|
|
|
|
* pointer to configuration data read from a file or serial FLASH, |
|
|
|
|
* or whatever you would like to do with it. Every implementation |
|
|
|
|
* should accept zero/NULL as a default configuration. |
|
|
|
|
* |
|
|
|
|
* Returned Value: |
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on |
|
|
|
|
* any failure to indicate the nature of the failure. |
|
|
|
|
* |
|
|
|
|
****************************************************************************/ |
|
|
|
|
|
|
|
|
@ -143,17 +165,27 @@ static struct spi_dev_s *spi1;
@@ -143,17 +165,27 @@ static struct spi_dev_s *spi1;
|
|
|
|
|
static struct spi_dev_s *spi2; |
|
|
|
|
static struct spi_dev_s *spi3; |
|
|
|
|
|
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
__EXPORT int nsh_archinitialize(void) |
|
|
|
|
__EXPORT int board_app_initialize(uintptr_t arg) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
int result; |
|
|
|
|
|
|
|
|
|
/* configure always-on ADC pins */ |
|
|
|
|
px4_arch_configgpio(GPIO_ADC1_IN10); |
|
|
|
|
px4_arch_configgpio(GPIO_ADC1_IN11); |
|
|
|
|
/* IN12 and IN13 further below */ |
|
|
|
|
|
|
|
|
|
#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(); |
|
|
|
|
|
|
|
|
@ -187,11 +219,11 @@ __EXPORT int nsh_archinitialize(void)
@@ -187,11 +219,11 @@ __EXPORT int nsh_archinitialize(void)
|
|
|
|
|
|
|
|
|
|
/* Configure SPI-based devices */ |
|
|
|
|
|
|
|
|
|
spi1 = px4_spibus_initialize(1); |
|
|
|
|
spi1 = stm32_spibus_initialize(1); |
|
|
|
|
|
|
|
|
|
if (!spi1) { |
|
|
|
|
message("[boot] FAILED to initialize SPI port 1\r\n"); |
|
|
|
|
up_ledon(LED_AMBER); |
|
|
|
|
board_autoled_on(LED_AMBER); |
|
|
|
|
return -ENODEV; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -210,7 +242,7 @@ __EXPORT int nsh_archinitialize(void)
@@ -210,7 +242,7 @@ __EXPORT int nsh_archinitialize(void)
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_SPI2 |
|
|
|
|
spi2 = px4_spibus_initialize(2); |
|
|
|
|
spi2 = stm32_spibus_initialize(2); |
|
|
|
|
/* Default SPI2 to 1MHz and de-assert the known chip selects. */ |
|
|
|
|
SPI_SETFREQUENCY(spi2, 10000000); |
|
|
|
|
SPI_SETBITS(spi2, 8); |
|
|
|
@ -223,17 +255,17 @@ __EXPORT int nsh_archinitialize(void)
@@ -223,17 +255,17 @@ __EXPORT int nsh_archinitialize(void)
|
|
|
|
|
spi2 = NULL; |
|
|
|
|
message("[boot] Enabling IN12/13 instead of SPI2\n"); |
|
|
|
|
/* no SPI2, use pins for ADC */ |
|
|
|
|
px4_arch_configgpio(GPIO_ADC1_IN12); |
|
|
|
|
px4_arch_configgpio(GPIO_ADC1_IN13); // jumperable to MPU6000 DRDY on some boards
|
|
|
|
|
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 = px4_spibus_initialize(3); |
|
|
|
|
spi3 = stm32_spibus_initialize(3); |
|
|
|
|
|
|
|
|
|
if (!spi3) { |
|
|
|
|
message("[boot] FAILED to initialize SPI port 3\n"); |
|
|
|
|
up_ledon(LED_AMBER); |
|
|
|
|
board_autoled_on(LED_AMBER); |
|
|
|
|
return -ENODEV; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -242,7 +274,7 @@ __EXPORT int nsh_archinitialize(void)
@@ -242,7 +274,7 @@ __EXPORT int nsh_archinitialize(void)
|
|
|
|
|
|
|
|
|
|
if (result != OK) { |
|
|
|
|
message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n"); |
|
|
|
|
up_ledon(LED_AMBER); |
|
|
|
|
board_autoled_on(LED_AMBER); |
|
|
|
|
return -ENODEV; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|