1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

On revolution attach the flash chip to the accel bus now. Also extended the

flash chip driver to take in the slave number during initialization so this is
no longer a hardcoded option.
This commit is contained in:
James Cotton 2012-01-20 07:37:47 -06:00
parent 1b5e776dc5
commit 1e8811362e
5 changed files with 247 additions and 83 deletions

View File

@ -209,14 +209,6 @@ extern uint32_t pios_com_telem_usb_id;
// None. // None.
//------------------------- //-------------------------
//--------------------------
// Flash chip
//--------------------------
#define PIOS_FLASH_ENABLE PIOS_SPI_RC_PinSet(PIOS_SPI_FLASH,0,0)
#define PIOS_FLASH_DISABLE PIOS_SPI_RC_PinSet(PIOS_SPI_FLASH,0,1);
#endif /* STM3210E_INS_H_ */ #endif /* STM3210E_INS_H_ */
/** /**

View File

@ -1,12 +1,32 @@
/**
******************************************************************************
*
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_FLASH Flash device handler
* @{
*
* @file pios_flash_w25x.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Driver for talking to W25X flash chip (and most JEDEC chips)
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/* /*
* pios_flash_w25x.c * This program is free software; you can redistribute it and/or modify
* OpenPilotOSX * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* *
* Created by James Cotton on 1/23/11. * This program is distributed in the hope that it will be useful, but
* Copyright 2011 OpenPilot. All rights reserved. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* *
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "pios.h" #include "pios.h"
#include "pios_flash_w25x.h" #include "pios_flash_w25x.h"
#include "pios_adxl345.h" #include "pios_adxl345.h"
@ -33,52 +53,106 @@
static uint8_t device_type; static uint8_t device_type;
//! Private functions enum pios_w25x_dev_magic {
static int8_t PIOS_Flash_W25X_ClaimBus(); PIOS_W25X_DEV_MAGIC = 0xcb55aa55,
static void PIOS_Flash_W25X_ReleaseBus(); };
static uint8_t PIOS_Flash_W25X_WriteEnable();
static uint8_t PIOS_Flash_W25X_Busy() ;
static uint32_t PIOS_SPI_FLASH; //! Device handle structure
struct w25x_flash_dev {
uint32_t spi_id;
uint32_t slave_num;
enum pios_w25x_dev_magic magic;
};
//! Global structure for this flash device
struct w25x_flash_dev * flash_dev;
//! Private functions
static int32_t PIOS_Flash_W25X_Validate(struct w25x_flash_dev * dev);
static struct w25x_flash_dev * PIOS_Flash_W25X_alloc(void);
static int32_t PIOS_Flash_W25X_ClaimBus();
static int32_t PIOS_Flash_W25X_ReleaseBus();
static int32_t PIOS_Flash_W25X_WriteEnable();
static int32_t PIOS_Flash_W25X_Busy() ;
/**
* @brief Allocate a new device
*/
static struct w25x_flash_dev * PIOS_Flash_W25X_alloc(void)
{
struct w25x_flash_dev * w25x_dev;
w25x_dev = (struct w25x_flash_dev *)pvPortMalloc(sizeof(*w25x_dev));
if (!w25x_dev) return (NULL);
w25x_dev->magic = PIOS_W25X_DEV_MAGIC;
return(w25x_dev);
}
/**
* @brief Validate the handle to the spi device
*/
static int32_t PIOS_Flash_W25X_Validate(struct w25x_flash_dev * dev) {
if (dev == NULL)
return -1;
if (dev->magic != PIOS_W25X_DEV_MAGIC)
return -2;
if (dev->spi_id == 0)
return -3;
return 0;
}
/** /**
* @brief Claim the SPI bus for flash use and assert CS pin * @brief Claim the SPI bus for flash use and assert CS pin
* @return 0 for sucess, -1 for failure to get semaphore * @return 0 for sucess, -1 for failure to get semaphore
*/ */
static int8_t PIOS_Flash_W25X_ClaimBus() static int32_t PIOS_Flash_W25X_ClaimBus()
{ {
int8_t ret = PIOS_SPI_ClaimBus(PIOS_SPI_FLASH); if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
PIOS_FLASH_ENABLE; return -1;
int8_t ret = PIOS_SPI_ClaimBus(flash_dev->spi_id);
PIOS_SPI_RC_PinSet(flash_dev->spi_id, flash_dev->slave_num, 0);
return (ret == 0) ? 0 : -1; return (ret == 0) ? 0 : -1;
} }
/** /**
* @brief Release the SPI bus sempahore and ensure flash chip not using bus * @brief Release the SPI bus sempahore and ensure flash chip not using bus
*/ */
static void PIOS_Flash_W25X_ReleaseBus() static int32_t PIOS_Flash_W25X_ReleaseBus()
{ {
PIOS_FLASH_DISABLE; if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
PIOS_SPI_ReleaseBus(PIOS_SPI_FLASH); return -1;
PIOS_SPI_RC_PinSet(flash_dev->spi_id, flash_dev->slave_num, 1);
PIOS_SPI_ReleaseBus(flash_dev->spi_id);
} }
/** /**
* @brief Returns if the flash chip is busy * @brief Returns if the flash chip is busy
* @returns -1 for failure, 0 for not busy, 1 for busy
*/ */
static uint8_t PIOS_Flash_W25X_Busy() static int32_t PIOS_Flash_W25X_Busy()
{ {
return PIOS_Flash_W25X_ReadStatus() & W25X_STATUS_BUSY; int32_t status = PIOS_Flash_W25X_ReadStatus();
if (status < 0)
return -1;
return status & W25X_STATUS_BUSY;
} }
/** /**
* @brief Execute the write enable instruction and returns the status * @brief Execute the write enable instruction and returns the status
* @returns 0 if successful, -1 if unable to claim bus * @returns 0 if successful, -1 if unable to claim bus
*/ */
static uint8_t PIOS_Flash_W25X_WriteEnable() static int32_t PIOS_Flash_W25X_WriteEnable()
{ {
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1;
uint8_t out[] = {W25X_WRITE_ENABLE}; uint8_t out[] = {W25X_WRITE_ENABLE};
if(PIOS_Flash_W25X_ClaimBus() != 0) if(PIOS_Flash_W25X_ClaimBus() != 0)
return -1; return -1;
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,NULL,sizeof(out),NULL); PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL);
PIOS_Flash_W25X_ReleaseBus(); PIOS_Flash_W25X_ReleaseBus();
return 0; return 0;
} }
@ -86,13 +160,15 @@ static uint8_t PIOS_Flash_W25X_WriteEnable()
/** /**
* @brief Initialize the flash device and enable write access * @brief Initialize the flash device and enable write access
*/ */
int8_t PIOS_Flash_W25X_Init(uint32_t spi_id) int32_t PIOS_Flash_W25X_Init(uint32_t spi_id, uint32_t slave_num)
{ {
PIOS_SPI_FLASH = spi_id; flash_dev = PIOS_Flash_W25X_alloc();
if(flash_dev == NULL)
return -1;
flash_dev->spi_id = spi_id;
flash_dev->slave_num = slave_num;
#if defined(PIOS_FLASH_CS_PIN)
PIOS_GPIO_Enable(PIOS_FLASH_CS_PIN);
#endif
device_type = PIOS_Flash_W25X_ReadID(); device_type = PIOS_Flash_W25X_ReadID();
return 0; return 0;
} }
@ -101,12 +177,21 @@ int8_t PIOS_Flash_W25X_Init(uint32_t spi_id)
/** /**
* @brief Read the status register from flash chip and return it * @brief Read the status register from flash chip and return it
*/ */
uint8_t PIOS_Flash_W25X_ReadStatus() int32_t PIOS_Flash_W25X_ReadStatus()
{ {
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1;
uint8_t out[2] = {W25X_READ_STATUS, 0}; uint8_t out[2] = {W25X_READ_STATUS, 0};
uint8_t in[2] = {0,0}; uint8_t in[2] = {0,0};
PIOS_Flash_W25X_ClaimBus(); if(PIOS_Flash_W25X_ClaimBus() < 0)
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,in,sizeof(out),NULL); return -1;
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,in,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus(); PIOS_Flash_W25X_ReleaseBus();
return in[1]; return in[1];
} }
@ -114,12 +199,20 @@ uint8_t PIOS_Flash_W25X_ReadStatus()
/** /**
* @brief Read the status register from flash chip and return it * @brief Read the status register from flash chip and return it
*/ */
uint8_t PIOS_Flash_W25X_ReadID() int32_t PIOS_Flash_W25X_ReadID()
{ {
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1;
uint8_t out[] = {W25X_DEVICE_ID, 0, 0, 0, 0, 0}; uint8_t out[] = {W25X_DEVICE_ID, 0, 0, 0, 0, 0};
uint8_t in[6]; uint8_t in[6];
PIOS_Flash_W25X_ClaimBus(); if (PIOS_Flash_W25X_ClaimBus() < 0)
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,in,sizeof(out),NULL); return -1;
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,in,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus(); PIOS_Flash_W25X_ReleaseBus();
return in[5]; return in[5];
} }
@ -131,8 +224,11 @@ uint8_t PIOS_Flash_W25X_ReadID()
* @retval -1 if unable to claim bus * @retval -1 if unable to claim bus
* @retval * @retval
*/ */
int8_t PIOS_Flash_W25X_EraseSector(uint32_t addr) int32_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
{ {
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1;
uint8_t ret; uint8_t ret;
uint8_t out[] = {W25X_SECTOR_ERASE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff}; uint8_t out[] = {W25X_SECTOR_ERASE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
@ -141,10 +237,16 @@ int8_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
if(PIOS_Flash_W25X_ClaimBus() != 0) if(PIOS_Flash_W25X_ClaimBus() != 0)
return -1; return -1;
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,NULL,sizeof(out),NULL);
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus(); PIOS_Flash_W25X_ReleaseBus();
while(PIOS_Flash_W25X_Busy()) { // Keep polling when bus is busy too
while(PIOS_Flash_W25X_Busy() != 0) {
} }
return 0; return 0;
@ -154,8 +256,11 @@ int8_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
* @brief Execute the whole chip * @brief Execute the whole chip
* @returns 0 if successful, -1 if unable to claim bus * @returns 0 if successful, -1 if unable to claim bus
*/ */
int8_t PIOS_Flash_W25X_EraseChip() int32_t PIOS_Flash_W25X_EraseChip()
{ {
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1;
uint8_t ret; uint8_t ret;
uint8_t out[] = {W25X_CHIP_ERASE}; uint8_t out[] = {W25X_CHIP_ERASE};
@ -164,10 +269,16 @@ int8_t PIOS_Flash_W25X_EraseChip()
if(PIOS_Flash_W25X_ClaimBus() != 0) if(PIOS_Flash_W25X_ClaimBus() != 0)
return -1; return -1;
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,NULL,sizeof(out),NULL);
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus(); PIOS_Flash_W25X_ReleaseBus();
while(PIOS_Flash_W25X_Busy()) { // Keep polling when bus is busy too
while(PIOS_Flash_W25X_Busy() != 0) {
} }
return 0; return 0;
@ -184,8 +295,11 @@ int8_t PIOS_Flash_W25X_EraseChip()
* @retval -2 Size exceeds 256 bytes * @retval -2 Size exceeds 256 bytes
* @retval -3 Length to write would wrap around page boundary * @retval -3 Length to write would wrap around page boundary
*/ */
int8_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len) int32_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
{ {
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1;
uint8_t ret; uint8_t ret;
uint8_t out[4] = {W25X_PAGE_WRITE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff}; uint8_t out[4] = {W25X_PAGE_WRITE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
@ -203,14 +317,22 @@ int8_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
/* Execute write page command and clock in address. Keep CS asserted */ /* Execute write page command and clock in address. Keep CS asserted */
if(PIOS_Flash_W25X_ClaimBus() != 0) if(PIOS_Flash_W25X_ClaimBus() != 0)
return -1; return -1;
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,NULL,sizeof(out),NULL);
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -1;
}
/* Clock out data to flash */ /* Clock out data to flash */
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,data,NULL,len,NULL); if(PIOS_SPI_TransferBlock(flash_dev->spi_id,data,NULL,len,NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -1;
}
PIOS_Flash_W25X_ReleaseBus(); PIOS_Flash_W25X_ReleaseBus();
while(PIOS_Flash_W25X_Busy()) { // Keep polling while bus is busy too
while(PIOS_Flash_W25X_Busy() != 0) {
} }
return 0; return 0;
@ -224,17 +346,27 @@ int8_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
* @return Zero if success or error code * @return Zero if success or error code
* @retval -1 Unable to claim SPI bus * @retval -1 Unable to claim SPI bus
*/ */
int8_t PIOS_Flash_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len) int32_t PIOS_Flash_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len)
{ {
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1;
if(PIOS_Flash_W25X_ClaimBus() == -1) if(PIOS_Flash_W25X_ClaimBus() == -1)
return -1; return -1;
/* Execute read command and clock in address. Keep CS asserted */ /* Execute read command and clock in address. Keep CS asserted */
uint8_t out[] = {W25X_READ_DATA, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff}; uint8_t out[] = {W25X_READ_DATA, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,NULL,sizeof(out),NULL);
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -2;
}
/* Copy the transfer data to the buffer */ /* Copy the transfer data to the buffer */
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,NULL,data,len,NULL); if(PIOS_SPI_TransferBlock(flash_dev->spi_id,NULL,data,len,NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
return -3;
}
PIOS_Flash_W25X_ReleaseBus(); PIOS_Flash_W25X_ReleaseBus();

View File

@ -390,7 +390,9 @@ const static uint8_t pios_bma180_req_buf[7] = {BMA_X_LSB_ADDR | 0x80,0,0,0,0,0};
static void PIOS_BMA180_IRQHandler(void) static void PIOS_BMA180_IRQHandler(void)
{ {
// If we can't get the bus then just move on for efficiency // If we can't get the bus then just move on for efficiency
if(PIOS_BMA180_ClaimBus() == 0) if(PIOS_BMA180_ClaimBus() != 0)
return; // Something else is using bus, miss this data
PIOS_SPI_TransferBlock(PIOS_SPI_ACCEL,pios_bma180_req_buf,(uint8_t *) pios_bma180_dmabuf, PIOS_SPI_TransferBlock(PIOS_SPI_ACCEL,pios_bma180_req_buf,(uint8_t *) pios_bma180_dmabuf,
sizeof(pios_bma180_dmabuf), NULL); sizeof(pios_bma180_dmabuf), NULL);
PIOS_BMA180_SPI_Callback(); PIOS_BMA180_SPI_Callback();

View File

@ -1,16 +1,37 @@
/**
******************************************************************************
*
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_FLASH Flash device handler
* @{
*
* @file pios_flash_w25x.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Driver for talking to W25X flash chip (and most JEDEC chips)
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/* /*
* pios_flash_w25x.h * This program is free software; you can redistribute it and/or modify
* OpenPilotOSX * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* *
* Created by James Cotton on 1/23/11. * This program is distributed in the hope that it will be useful, but
* Copyright 2011 OpenPilot. All rights reserved. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* *
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
int8_t PIOS_Flash_W25X_Init(); int32_t PIOS_Flash_W25X_Init(uint32_t spi_id, uint32_t slave_num);
uint8_t PIOS_Flash_W25X_ReadStatus(); int32_t PIOS_Flash_W25X_ReadStatus();
uint8_t PIOS_Flash_W25X_ReadID(); int32_t PIOS_Flash_W25X_ReadID();
int8_t PIOS_Flash_W25X_EraseChip(); int32_t PIOS_Flash_W25X_EraseChip();
int8_t PIOS_Flash_W25X_EraseSector(uint32_t add); int32_t PIOS_Flash_W25X_EraseSector(uint32_t add);
int8_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len); int32_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len);
int8_t PIOS_Flash_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len); int32_t PIOS_Flash_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len);

View File

@ -29,14 +29,16 @@
#include <pios.h> #include <pios.h>
#if defined(PIOS_INCLUDE_SPI)
#include <openpilot.h> #include <openpilot.h>
#include <pios_spi_priv.h> #include <pios_spi_priv.h>
#include <uavobjectsinit.h> #include <uavobjectsinit.h>
#include <hwsettings.h> #include <hwsettings.h>
#include "manualcontrolsettings.h" #include "manualcontrolsettings.h"
#if defined(PIOS_INCLUDE_SPI)
#define PIOS_FLASH_ON_ACCEL
/* SPI1 Interface /* SPI1 Interface
* - Used for BMA180 accelerometer * - Used for BMA180 accelerometer
*/ */
@ -136,7 +138,7 @@ static const struct pios_spi_cfg pios_spi_accel_cfg = {
.GPIO_PuPd = GPIO_PuPd_UP .GPIO_PuPd = GPIO_PuPd_UP
}, },
}, },
.slave_count = 1, .slave_count = 2,
.ssel = { { .ssel = { {
.gpio = GPIOA, .gpio = GPIOA,
.init = { .init = {
@ -145,8 +147,17 @@ static const struct pios_spi_cfg pios_spi_accel_cfg = {
.GPIO_Mode = GPIO_Mode_OUT, .GPIO_Mode = GPIO_Mode_OUT,
.GPIO_OType = GPIO_OType_PP, .GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_UP .GPIO_PuPd = GPIO_PuPd_UP
},
} }, } },
{
.gpio = GPIOC,
.init = {
.GPIO_Pin = GPIO_Pin_5,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_Mode = GPIO_Mode_OUT,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_UP
} },
}
}; };
static uint32_t pios_spi_accel_id; static uint32_t pios_spi_accel_id;
@ -279,6 +290,7 @@ void PIOS_SPI_gyro_irq_handler(void)
} }
#if !defined(PIOS_FLASH_ON_ACCEL)
/* SPI3 Interface /* SPI3 Interface
* - Used for flash communications * - Used for flash communications
*/ */
@ -399,6 +411,7 @@ void PIOS_SPI_flash_irq_handler(void)
/* Call into the generic code to handle the IRQ for this specific device */ /* Call into the generic code to handle the IRQ for this specific device */
PIOS_SPI_IRQ_Handler(pios_spi_flash_id); PIOS_SPI_IRQ_Handler(pios_spi_flash_id);
} }
#endif /* PIOS_FLASH_ON_ACCEL */
#endif /* PIOS_INCLUDE_SPI */ #endif /* PIOS_INCLUDE_SPI */
@ -1544,11 +1557,24 @@ void PIOS_Board_Init(void) {
#endif /* PIOS_DEBUG_ENABLE_DEBUG_PINS */ #endif /* PIOS_DEBUG_ENABLE_DEBUG_PINS */
/* Set up the SPI interface to the accelerometer*/
if (PIOS_SPI_Init(&pios_spi_accel_id, &pios_spi_accel_cfg)) {
PIOS_DEBUG_Assert(0);
}
/* Set up the SPI interface to the gyro */
if (PIOS_SPI_Init(&pios_spi_gyro_id, &pios_spi_gyro_cfg)) {
PIOS_DEBUG_Assert(0);
}
#if !defined(PIOS_FLASH_ON_ACCEL)
/* Set up the SPI interface to the flash */ /* Set up the SPI interface to the flash */
if (PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) { if (PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) {
PIOS_DEBUG_Assert(0); PIOS_DEBUG_Assert(0);
} }
PIOS_Flash_W25X_Init(pios_spi_flash_id); PIOS_Flash_W25X_Init(pios_spi_flash_id, 0);
#else
PIOS_Flash_W25X_Init(pios_spi_accel_id, 1);
#endif
PIOS_FLASHFS_Init(); PIOS_FLASHFS_Init();
/* Initialize UAVObject libraries */ /* Initialize UAVObject libraries */
@ -1691,15 +1717,6 @@ void PIOS_Board_Init(void) {
if (PIOS_I2C_Init(&pios_i2c_pressure_adapter_id, &pios_i2c_pressure_adapter_cfg)) { if (PIOS_I2C_Init(&pios_i2c_pressure_adapter_id, &pios_i2c_pressure_adapter_cfg)) {
PIOS_DEBUG_Assert(0); PIOS_DEBUG_Assert(0);
} }
/* Set up the SPI interface to the accelerometer*/
if (PIOS_SPI_Init(&pios_spi_accel_id, &pios_spi_accel_cfg)) {
PIOS_DEBUG_Assert(0);
}
/* Set up the SPI interface to the gyro */
if (PIOS_SPI_Init(&pios_spi_gyro_id, &pios_spi_gyro_cfg)) {
PIOS_DEBUG_Assert(0);
}
PIOS_DELAY_WaitmS(500); PIOS_DELAY_WaitmS(500);