1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

Flash: Because most of the commands are a JEDEC standard rename this file

pios_flash_jedec and abstract out the methods that can vary between chips.
This commit is contained in:
James Cotton 2012-01-25 00:23:24 -06:00
parent a02cad6f52
commit 0da20bb846
10 changed files with 154 additions and 137 deletions

View File

@ -224,7 +224,7 @@ SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_crc.c
SRC += $(PIOSCOMMON)/pios_flashfs_objlist.c
SRC += $(PIOSCOMMON)/pios_flash_w25x.c
SRC += $(PIOSCOMMON)/pios_flash_jedec.c
SRC += $(PIOSCOMMON)/pios_adxl345.c
SRC += $(PIOSCOMMON)/pios_l3gd20.c
SRC += $(PIOSCOMMON)/pios_bma180.c

View File

@ -71,7 +71,7 @@ int main()
PIOS_Board_Init();
#ifdef ERASE_FLASH
PIOS_Flash_W25X_EraseChip();
PIOS_Flash_Jedec_EraseChip();
#if defined(PIOS_LED_HEARTBEAT)
PIOS_LED_Off(PIOS_LED_HEARTBEAT);
#endif /* PIOS_LED_HEARTBEAT */

View File

@ -147,7 +147,7 @@ static const struct pios_l3gd20_cfg pios_l3gd20_cfg = {
};
#endif /* PIOS_INCLUDE_L3GD20 */
struct flashfs_cfg flashfs_w25x_cfg = {
static const struct flashfs_cfg flashfs_w25x_cfg = {
.table_magic = 0x85FB3C35,
.obj_magic = 0x3015AE71,
.obj_table_start = 0x00000010,
@ -155,6 +155,11 @@ struct flashfs_cfg flashfs_w25x_cfg = {
.sector_size = 0x00001000,
};
static const struct pios_flash_jedec_cfg flash_w25x_cfg = {
.sector_erase = 0x20,
.chip_erase = 0x60
};
#include <pios_board_info.h>
/**
* PIOS_Board_Init()
@ -201,7 +206,7 @@ void PIOS_Board_Init(void) {
}
#endif
PIOS_Flash_W25X_Init(pios_spi_flash_accel_id, 1);
PIOS_Flash_Jedec_Init(pios_spi_flash_accel_id, 1, &flash_w25x_cfg);
PIOS_FLASHFS_Init(&flashfs_w25x_cfg);

View File

@ -28,77 +28,74 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "pios.h"
#include "pios_flash_w25x.h"
#include "pios_adxl345.h"
#define W25X_WRITE_ENABLE 0x06
#define W25X_WRITE_DISABLE 0x04
#define W25X_READ_STATUS 0x05
#define W25X_WRITE_STATUS 0x01
#define W25X_READ_DATA 0x03
#define W25X_FAST_READ 0x0b
#define W25X_DEVICE_ID 0x90
#define W25X_SECTOR_ERASE 0x20
#define W25X_PAGE_WRITE 0x02
#define W25X_CHIP_ERASE 0x60
#define JEDEC_WRITE_ENABLE 0x06
#define JEDEC_WRITE_DISABLE 0x04
#define JEDEC_READ_STATUS 0x05
#define JEDEC_WRITE_STATUS 0x01
#define JEDEC_READ_DATA 0x03
#define JEDEC_FAST_READ 0x0b
#define JEDEC_DEVICE_ID 0x90
#define JEDEC_PAGE_WRITE 0x02
#define W25X_STATUS_BUSY 0x01
#define W25X_STATUS_WRITEPROTECT 0x02
#define W25X_STATUS_BP0 0x04
#define W25X_STATUS_BP1 0x08
#define W25X_STATUS_BP2 0x10
#define W25X_STATUS_TP 0x20
#define W25X_STATUS_SEC 0x40
#define W25X_STATUS_SRP0 0x80
#define JEDEC_STATUS_BUSY 0x01
#define JEDEC_STATUS_WRITEPROTECT 0x02
#define JEDEC_STATUS_BP0 0x04
#define JEDEC_STATUS_BP1 0x08
#define JEDEC_STATUS_BP2 0x10
#define JEDEC_STATUS_TP 0x20
#define JEDEC_STATUS_SEC 0x40
#define JEDEC_STATUS_SRP0 0x80
static uint8_t device_type;
enum pios_w25x_dev_magic {
PIOS_W25X_DEV_MAGIC = 0xcb55aa55,
enum pios_jedec_dev_magic {
PIOS_JEDEC_DEV_MAGIC = 0xcb55aa55,
};
//! Device handle structure
struct w25x_flash_dev {
struct jedec_flash_dev {
uint32_t spi_id;
uint32_t slave_num;
bool claimed;
enum pios_w25x_dev_magic magic;
const struct pios_flash_jedec_cfg * cfg;
enum pios_jedec_dev_magic magic;
};
//! Global structure for this flash device
struct w25x_flash_dev * flash_dev;
struct jedec_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() ;
static int32_t PIOS_Flash_Jedec_Validate(struct jedec_flash_dev * dev);
static struct jedec_flash_dev * PIOS_Flash_Jedec_alloc(void);
static int32_t PIOS_Flash_Jedec_ClaimBus();
static int32_t PIOS_Flash_Jedec_ReleaseBus();
static int32_t PIOS_Flash_Jedec_WriteEnable();
static int32_t PIOS_Flash_Jedec_Busy() ;
/**
* @brief Allocate a new device
*/
static struct w25x_flash_dev * PIOS_Flash_W25X_alloc(void)
static struct jedec_flash_dev * PIOS_Flash_Jedec_alloc(void)
{
struct w25x_flash_dev * w25x_dev;
struct jedec_flash_dev * jedec_dev;
w25x_dev = (struct w25x_flash_dev *)pvPortMalloc(sizeof(*w25x_dev));
if (!w25x_dev) return (NULL);
jedec_dev = (struct jedec_flash_dev *)pvPortMalloc(sizeof(*jedec_dev));
if (!jedec_dev) return (NULL);
w25x_dev->claimed = false;
w25x_dev->magic = PIOS_W25X_DEV_MAGIC;
return(w25x_dev);
jedec_dev->claimed = false;
jedec_dev->magic = PIOS_JEDEC_DEV_MAGIC;
return(jedec_dev);
}
/**
* @brief Validate the handle to the spi device
*/
static int32_t PIOS_Flash_W25X_Validate(struct w25x_flash_dev * dev) {
static int32_t PIOS_Flash_Jedec_Validate(struct jedec_flash_dev * dev) {
if (dev == NULL)
return -1;
if (dev->magic != PIOS_W25X_DEV_MAGIC)
if (dev->magic != PIOS_JEDEC_DEV_MAGIC)
return -2;
if (dev->spi_id == 0)
return -3;
@ -109,9 +106,9 @@ static int32_t PIOS_Flash_W25X_Validate(struct w25x_flash_dev * dev) {
* @brief Claim the SPI bus for flash use and assert CS pin
* @return 0 for sucess, -1 for failure to get semaphore
*/
static int32_t PIOS_Flash_W25X_ClaimBus()
static int32_t PIOS_Flash_Jedec_ClaimBus()
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
if(PIOS_SPI_ClaimBus(flash_dev->spi_id) < 0)
@ -126,9 +123,9 @@ static int32_t PIOS_Flash_W25X_ClaimBus()
/**
* @brief Release the SPI bus sempahore and ensure flash chip not using bus
*/
static int32_t PIOS_Flash_W25X_ReleaseBus()
static int32_t PIOS_Flash_Jedec_ReleaseBus()
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
PIOS_SPI_RC_PinSet(flash_dev->spi_id, flash_dev->slave_num, 1);
PIOS_SPI_ReleaseBus(flash_dev->spi_id);
@ -140,44 +137,48 @@ static int32_t PIOS_Flash_W25X_ReleaseBus()
* @brief Returns if the flash chip is busy
* @returns -1 for failure, 0 for not busy, 1 for busy
*/
static int32_t PIOS_Flash_W25X_Busy()
static int32_t PIOS_Flash_Jedec_Busy()
{
int32_t status = PIOS_Flash_W25X_ReadStatus();
int32_t status = PIOS_Flash_Jedec_ReadStatus();
if (status < 0)
return -1;
return status & W25X_STATUS_BUSY;
return status & JEDEC_STATUS_BUSY;
}
/**
* @brief Execute the write enable instruction and returns the status
* @returns 0 if successful, -1 if unable to claim bus
*/
static int32_t PIOS_Flash_W25X_WriteEnable()
static int32_t PIOS_Flash_Jedec_WriteEnable()
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
uint8_t out[] = {W25X_WRITE_ENABLE};
if(PIOS_Flash_W25X_ClaimBus() != 0)
uint8_t out[] = {JEDEC_WRITE_ENABLE};
if(PIOS_Flash_Jedec_ClaimBus() != 0)
return -1;
PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL);
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return 0;
}
/**
* @brief Initialize the flash device and enable write access
*/
int32_t PIOS_Flash_W25X_Init(uint32_t spi_id, uint32_t slave_num)
int32_t PIOS_Flash_Jedec_Init(uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg)
{
flash_dev = PIOS_Flash_W25X_alloc();
flash_dev = PIOS_Flash_Jedec_alloc();
if(flash_dev == NULL)
return -1;
flash_dev->spi_id = spi_id;
flash_dev->slave_num = slave_num;
flash_dev->cfg = cfg;
device_type = PIOS_Flash_Jedec_ReadID();
if(device_type == 0)
return -1;
device_type = PIOS_Flash_W25X_ReadID();
return 0;
}
@ -185,43 +186,43 @@ int32_t PIOS_Flash_W25X_Init(uint32_t spi_id, uint32_t slave_num)
/**
* @brief Read the status register from flash chip and return it
*/
int32_t PIOS_Flash_W25X_ReadStatus()
int32_t PIOS_Flash_Jedec_ReadStatus()
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
uint8_t out[2] = {W25X_READ_STATUS, 0};
uint8_t out[2] = {JEDEC_WRITE_STATUS, 0};
uint8_t in[2] = {0,0};
if(PIOS_Flash_W25X_ClaimBus() < 0)
if(PIOS_Flash_Jedec_ClaimBus() < 0)
return -1;
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,in,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return in[1];
}
/**
* @brief Read the status register from flash chip and return it
*/
int32_t PIOS_Flash_W25X_ReadID()
int32_t PIOS_Flash_Jedec_ReadID()
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
uint8_t out[] = {W25X_DEVICE_ID, 0, 0, 0, 0, 0};
uint8_t out[] = {JEDEC_DEVICE_ID, 0, 0, 0, 0, 0};
uint8_t in[6];
if (PIOS_Flash_W25X_ClaimBus() < 0)
if (PIOS_Flash_Jedec_ClaimBus() < 0)
return -1;
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,in,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return in[5];
}
@ -232,29 +233,29 @@ int32_t PIOS_Flash_W25X_ReadID()
* @retval -1 if unable to claim bus
* @retval
*/
int32_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
int32_t PIOS_Flash_Jedec_EraseSector(uint32_t addr)
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
uint8_t ret;
uint8_t out[] = {W25X_SECTOR_ERASE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
uint8_t out[] = {flash_dev->cfg->sector_erase, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
if((ret = PIOS_Flash_W25X_WriteEnable()) != 0)
if((ret = PIOS_Flash_Jedec_WriteEnable()) != 0)
return ret;
if(PIOS_Flash_W25X_ClaimBus() != 0)
if(PIOS_Flash_Jedec_ClaimBus() != 0)
return -1;
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
// Keep polling when bus is busy too
while(PIOS_Flash_W25X_Busy() != 0);
while(PIOS_Flash_Jedec_Busy() != 0);
return 0;
}
@ -263,29 +264,29 @@ int32_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
* @brief Execute the whole chip
* @returns 0 if successful, -1 if unable to claim bus
*/
int32_t PIOS_Flash_W25X_EraseChip()
int32_t PIOS_Flash_Jedec_EraseChip()
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
uint8_t ret;
uint8_t out[] = {W25X_CHIP_ERASE};
uint8_t out[] = {flash_dev->cfg->chip_erase};
if((ret = PIOS_Flash_W25X_WriteEnable()) != 0)
if((ret = PIOS_Flash_Jedec_WriteEnable()) != 0)
return ret;
if(PIOS_Flash_W25X_ClaimBus() != 0)
if(PIOS_Flash_Jedec_ClaimBus() != 0)
return -1;
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -2;
}
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
// Keep polling when bus is busy too
while(PIOS_Flash_W25X_Busy() != 0);
while(PIOS_Flash_Jedec_Busy() != 0);
return 0;
}
@ -301,13 +302,13 @@ int32_t PIOS_Flash_W25X_EraseChip()
* @retval -2 Size exceeds 256 bytes
* @retval -3 Length to write would wrap around page boundary
*/
int32_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
int32_t PIOS_Flash_Jedec_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
uint8_t ret;
uint8_t out[4] = {W25X_PAGE_WRITE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
uint8_t out[4] = {JEDEC_PAGE_WRITE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
/* Can only write one page at a time */
if(len > 0x100)
@ -317,28 +318,28 @@ int32_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
if(((addr & 0xff) + len) > 0x100)
return -3;
if((ret = PIOS_Flash_W25X_WriteEnable()) != 0)
if((ret = PIOS_Flash_Jedec_WriteEnable()) != 0)
return ret;
/* Execute write page command and clock in address. Keep CS asserted */
if(PIOS_Flash_W25X_ClaimBus() != 0)
if(PIOS_Flash_Jedec_ClaimBus() != 0)
return -1;
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -1;
}
/* Clock out data to flash */
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,data,NULL,len,NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -1;
}
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
// Keep polling while bus is busy too
while(PIOS_Flash_W25X_Busy() != 0);
while(PIOS_Flash_Jedec_Busy() != 0);
return 0;
}
@ -351,29 +352,29 @@ int32_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
* @return Zero if success or error code
* @retval -1 Unable to claim SPI bus
*/
int32_t PIOS_Flash_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len)
int32_t PIOS_Flash_Jedec_ReadData(uint32_t addr, uint8_t * data, uint16_t len)
{
if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
return -1;
if(PIOS_Flash_W25X_ClaimBus() == -1)
if(PIOS_Flash_Jedec_ClaimBus() == -1)
return -1;
/* 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[] = {JEDEC_READ_DATA, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,out,NULL,sizeof(out),NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -2;
}
/* Copy the transfer data to the buffer */
if(PIOS_SPI_TransferBlock(flash_dev->spi_id,NULL,data,len,NULL) < 0) {
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return -3;
}
PIOS_Flash_W25X_ReleaseBus();
PIOS_Flash_Jedec_ReleaseBus();
return 0;
}

View File

@ -78,7 +78,7 @@ int32_t PIOS_FLASHFS_Init(const struct flashfs_cfg * new_cfg)
bool magic_good = false;
while(!magic_good) {
if (PIOS_Flash_W25X_ReadData(0, (uint8_t *)&object_table_magic, sizeof(object_table_magic)) != 0)
if (PIOS_Flash_Jedec_ReadData(0, (uint8_t *)&object_table_magic, sizeof(object_table_magic)) != 0)
return -1;
if(object_table_magic != OBJECT_TABLE_MAGIC) {
if(magic_fail_count++ > MAX_BADMAGIC) {
@ -106,7 +106,7 @@ int32_t PIOS_FLASHFS_Init(const struct flashfs_cfg * new_cfg)
// Loop through header area while objects detect to count how many saved
while(addr < OBJECT_TABLE_END) {
// Read the instance data
if (PIOS_Flash_W25X_ReadData(addr, (uint8_t *)&header, sizeof(header)) != 0)
if (PIOS_Flash_Jedec_ReadData(addr, (uint8_t *)&header, sizeof(header)) != 0)
return -1;
// Counting number of valid headers
@ -126,7 +126,7 @@ int32_t PIOS_FLASHFS_Init(const struct flashfs_cfg * new_cfg)
*/
int32_t PIOS_FLASHFS_Format()
{
if(PIOS_Flash_W25X_EraseChip() != 0)
if(PIOS_Flash_Jedec_EraseChip() != 0)
return -1;
if(PIOS_FLASHFS_ClearObjectTableHeader() != 0)
return -1;
@ -139,11 +139,11 @@ int32_t PIOS_FLASHFS_Format()
*/
static int32_t PIOS_FLASHFS_ClearObjectTableHeader()
{
if(PIOS_Flash_W25X_EraseSector(0) != 0)
if(PIOS_Flash_Jedec_EraseSector(0) != 0)
return -1;
uint32_t object_table_magic = OBJECT_TABLE_MAGIC;
if (PIOS_Flash_W25X_WriteData(0, (uint8_t *)&object_table_magic, sizeof(object_table_magic)) != 0)
if (PIOS_Flash_Jedec_WriteData(0, (uint8_t *)&object_table_magic, sizeof(object_table_magic)) != 0)
return -1;
return 0;
@ -163,7 +163,7 @@ static int32_t PIOS_FLASHFS_GetObjAddress(uint32_t objId, uint16_t instId)
// Loop through header area while objects detect to count how many saved
while(addr < OBJECT_TABLE_END) {
// Read the instance data
if (PIOS_Flash_W25X_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0)
if (PIOS_Flash_Jedec_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0)
return -1;
if(header.objMagic != OBJ_MAGIC)
break; // stop searching once hit first non-object header
@ -207,7 +207,7 @@ int32_t PIOS_FLASHFS_GetNewAddress(uint32_t objId, uint16_t instId)
if((addr + sizeof(header)) > OBJECT_TABLE_END)
return -2;
if(PIOS_Flash_W25X_WriteData(addr, (uint8_t *) &header, sizeof(header)) != 0)
if(PIOS_Flash_Jedec_WriteData(addr, (uint8_t *) &header, sizeof(header)) != 0)
return -3;
// This numObejcts value must stay consistent or there will be a break in the table
@ -246,26 +246,26 @@ int32_t PIOS_FLASHFS_ObjSave(UAVObjHandle obj, uint16_t instId, uint8_t * data)
.size = UAVObjGetNumBytes(obj)
};
if(PIOS_Flash_W25X_EraseSector(addr) != 0)
if(PIOS_Flash_Jedec_EraseSector(addr) != 0)
return -2;
// Save header
// This information IS redundant with the object table id. Oh well. Better safe than sorry.
if(PIOS_Flash_W25X_WriteData(addr, (uint8_t *) &header, sizeof(header)) != 0)
if(PIOS_Flash_Jedec_WriteData(addr, (uint8_t *) &header, sizeof(header)) != 0)
return -3;
// Update CRC
crc = PIOS_CRC_updateCRC(0, (uint8_t *) &header, sizeof(header));
// Save data
if(PIOS_Flash_W25X_WriteData(addr + sizeof(header), data, UAVObjGetNumBytes(obj)) != 0)
if(PIOS_Flash_Jedec_WriteData(addr + sizeof(header), data, UAVObjGetNumBytes(obj)) != 0)
return -4;
// Update CRC
crc = PIOS_CRC_updateCRC(crc, (uint8_t *) data, UAVObjGetNumBytes(obj));
// Save CRC (written so will work when CRC changes to uint16)
if(PIOS_Flash_W25X_WriteData(addr + sizeof(header) + UAVObjGetNumBytes(obj), (uint8_t *) &crc, sizeof(crc)) != 0)
if(PIOS_Flash_Jedec_WriteData(addr + sizeof(header) + UAVObjGetNumBytes(obj), (uint8_t *) &crc, sizeof(crc)) != 0)
return -4;
return 0;
@ -304,7 +304,7 @@ int32_t PIOS_FLASHFS_ObjLoad(UAVObjHandle obj, uint16_t instId, uint8_t * data)
// Load header
// This information IS redundant with the object table id. Oh well. Better safe than sorry.
if(PIOS_Flash_W25X_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0)
if(PIOS_Flash_Jedec_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0)
return -2;
// Update CRC
@ -316,20 +316,20 @@ int32_t PIOS_FLASHFS_ObjLoad(UAVObjHandle obj, uint16_t instId, uint8_t * data)
// To avoid having to allocate the RAM for a copy of the object, we read by chunks
// and compute the CRC
for(uint32_t i = 0; i < objSize; i += crc_read_step) {
PIOS_Flash_W25X_ReadData(addr + sizeof(header) + i, crc_read_buffer, crc_read_step);
PIOS_Flash_Jedec_ReadData(addr + sizeof(header) + i, crc_read_buffer, crc_read_step);
uint8_t valid_bytes = ((i + crc_read_step) >= objSize) ? objSize - i : crc_read_step;
crc = PIOS_CRC_updateCRC(crc, crc_read_buffer, valid_bytes);
}
// Read CRC (written so will work when CRC changes to uint16)
if(PIOS_Flash_W25X_ReadData(addr + sizeof(header) + objSize, (uint8_t *) &crcFlash, sizeof(crcFlash)) != 0)
if(PIOS_Flash_Jedec_ReadData(addr + sizeof(header) + objSize, (uint8_t *) &crcFlash, sizeof(crcFlash)) != 0)
return -5;
if(crc != crcFlash)
return -6;
// Read the instance data
if (PIOS_Flash_W25X_ReadData(addr + sizeof(header), data, objSize) != 0)
if (PIOS_Flash_Jedec_ReadData(addr + sizeof(header), data, objSize) != 0)
return -4;
return 0;
@ -356,7 +356,7 @@ int32_t PIOS_FLASHFS_ObjDelete(UAVObjHandle obj, uint16_t instId)
if(addr < 0)
return -1;
if(PIOS_Flash_W25X_EraseSector(addr) != 0)
if(PIOS_Flash_Jedec_EraseSector(addr) != 0)
return -2;
return 0;

View File

@ -28,10 +28,15 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
int32_t PIOS_Flash_W25X_Init(uint32_t spi_id, uint32_t slave_num);
int32_t PIOS_Flash_W25X_ReadStatus();
int32_t PIOS_Flash_W25X_ReadID();
int32_t PIOS_Flash_W25X_EraseChip();
int32_t PIOS_Flash_W25X_EraseSector(uint32_t add);
int32_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len);
int32_t PIOS_Flash_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len);
struct pios_flash_jedec_cfg {
uint32_t sector_erase;
uint32_t chip_erase;
};
int32_t PIOS_Flash_Jedec_Init(uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg);
int32_t PIOS_Flash_Jedec_ReadStatus();
int32_t PIOS_Flash_Jedec_ReadID();
int32_t PIOS_Flash_Jedec_EraseChip();
int32_t PIOS_Flash_Jedec_EraseSector(uint32_t add);
int32_t PIOS_Flash_Jedec_WriteData(uint32_t addr, uint8_t * data, uint16_t len);
int32_t PIOS_Flash_Jedec_ReadData(uint32_t addr, uint8_t * data, uint16_t len);

View File

@ -140,7 +140,7 @@
#endif
#if defined(PIOS_INCLUDE_FLASH)
#include <pios_flash_w25x.h>
#include <pios_flash_jedec.h>
#include <pios_flashfs_objlist.h>
#endif

View File

@ -49,8 +49,6 @@
650D8E6812DFE16400D05CC9 /* telemetry.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = telemetry.c; sourceTree = "<group>"; };
650D8ED112DFE17500D05CC9 /* uavtalk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uavtalk.h; sourceTree = "<group>"; };
650D8ED212DFE17500D05CC9 /* uavtalk.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = uavtalk.c; sourceTree = "<group>"; };
6512D60512ED4CA2008175E5 /* pios_flash_w25x.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_flash_w25x.h; sourceTree = "<group>"; };
6512D60712ED4CB8008175E5 /* pios_flash_w25x.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_flash_w25x.c; sourceTree = "<group>"; };
65140DFA1496927D00E01D11 /* sensors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sensors.h; sourceTree = "<group>"; };
65140DFB1496927D00E01D11 /* sensors.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sensors.c; sourceTree = "<group>"; };
65173C9F12EBFD1700D6A7CB /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = ../../../Makefile; sourceTree = SOURCE_ROOT; };
@ -104,6 +102,8 @@
65643CBA141350C200A32F59 /* pios_sbus.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_sbus.c; sourceTree = "<group>"; };
6572CB1613D0F2B200FC2972 /* link_STM32103CB_CC_Rev1_memory.ld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = link_STM32103CB_CC_Rev1_memory.ld; path = ../../PiOS/STM32F10x/link_STM32103CB_CC_Rev1_memory.ld; sourceTree = SOURCE_ROOT; };
6572CB1713D0F2B200FC2972 /* link_STM32103CB_CC_Rev1_sections.ld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = link_STM32103CB_CC_Rev1_sections.ld; path = ../../PiOS/STM32F10x/link_STM32103CB_CC_Rev1_sections.ld; sourceTree = SOURCE_ROOT; };
657C413314CFD1CE0024FBB4 /* pios_flash_jedec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_flash_jedec.h; sourceTree = "<group>"; };
657C413414CFD1E00024FBB4 /* pios_flash_jedec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_flash_jedec.c; sourceTree = "<group>"; };
657CEEAD121DB6C8007A1FBE /* homelocation.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = homelocation.xml; sourceTree = "<group>"; };
657CEEB7121DBC63007A1FBE /* CoordinateConversions.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CoordinateConversions.c; sourceTree = "<group>"; };
657CEEB9121DBC63007A1FBE /* CoordinateConversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoordinateConversions.h; sourceTree = "<group>"; };
@ -8457,18 +8457,18 @@
6528CCB412E406B800CF5144 /* pios_adxl345.c */,
65FB1E6614CDBE26009C52B9 /* pios_bma180.c */,
65FB1E6714CDBE26009C52B9 /* pios_bmp085.c */,
65E8F03311EFF25C00BBF654 /* pios_hmc5843.c */,
65FB1E6814CDBE26009C52B9 /* pios_hmc5883.c */,
65FB1E6914CDBE26009C52B9 /* pios_l3gd20.c */,
65FB1E6A14CDBE26009C52B9 /* pios_mpu6000.c */,
65FB1E6B14CDBE26009C52B9 /* pios_ms5611.c */,
65904EDB14613BBD00FD9482 /* Libraries */,
65E8F03211EFF25C00BBF654 /* pios_com.c */,
65E8F03311EFF25C00BBF654 /* pios_hmc5843.c */,
657C413414CFD1E00024FBB4 /* pios_flash_jedec.c */,
65E8F03411EFF25C00BBF654 /* pios_opahrs.c */,
65E8F03511EFF25C00BBF654 /* pios_opahrs_proto.c */,
65E8F03611EFF25C00BBF654 /* pios_sdcard.c */,
65E8F03711EFF25C00BBF654 /* printf-stdarg.c */,
6512D60712ED4CB8008175E5 /* pios_flash_w25x.c */,
65FF4D5E137EDEC100146BE4 /* pios_flashfs_objlist.c */,
6562BE1713CCAD0600C823E8 /* pios_rcvr.c */,
65E8C743139A6D0900E1F979 /* pios_crc.c */,
@ -8497,7 +8497,7 @@
65E8F03E11EFF25C00BBF654 /* pios_debug.h */,
65E8F03F11EFF25C00BBF654 /* pios_delay.h */,
65E8F04011EFF25C00BBF654 /* pios_exti.h */,
6512D60512ED4CA2008175E5 /* pios_flash_w25x.h */,
657C413314CFD1CE0024FBB4 /* pios_flash_jedec.h */,
65FF4D61137EFA4F00146BE4 /* pios_flashfs_objlist.h */,
65FA9B7C14709E9E0019A260 /* pios_gcsrcvr_priv.h */,
65E8F04111EFF25C00BBF654 /* pios_gpio.h */,

View File

@ -145,7 +145,7 @@ SRC += $(PIOSCOMMON)/pios_ms5611.c
SRC += $(PIOSCOMMON)/pios_crc.c
SRC += $(PIOSCOMMON)/pios_com.c
SRC += $(PIOSCOMMON)/pios_rcvr.c
SRC += $(PIOSCOMMON)/pios_flash_w25x.c
SRC += $(PIOSCOMMON)/pios_flash_jedec.c
SRC += $(PIOSCOMMON)/pios_flashfs_objlist.c
SRC += $(PIOSCOMMON)/printf-stdarg.c

View File

@ -1582,7 +1582,7 @@ static const struct pios_l3gd20_cfg pios_l3gd20_cfg = {
#endif /* PIOS_INCLUDE_L3GD20 */
struct flashfs_cfg flashfs_m25p_cfg = {
static const struct flashfs_cfg flashfs_m25p_cfg = {
.table_magic = 0x85FB3C35,
.obj_magic = 0x3015AE71,
.obj_table_start = 0x00000010,
@ -1590,6 +1590,12 @@ struct flashfs_cfg flashfs_m25p_cfg = {
.sector_size = 0x00010000,
};
static const struct pios_flash_jedec_cfg flash_m25p_cfg = {
.sector_erase = 0xD8,
.chip_erase = 0xC7
};
/**
* PIOS_Board_Init()
* initializes all the core subsystems on this specific hardware
@ -1619,9 +1625,9 @@ void PIOS_Board_Init(void) {
if (PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) {
PIOS_DEBUG_Assert(0);
}
PIOS_Flash_W25X_Init(pios_spi_flash_id, 0);
PIOS_Flash_Jedec_Init(pios_spi_flash_id, 0, &flash_m25p_cfg);
#else
PIOS_Flash_W25X_Init(pios_spi_accel_id, 1);
PIOS_Flash_Jedec_Init(pios_spi_accel_id, 1, &flash_m25p_cfg);
#endif
PIOS_FLASHFS_Init(&flashfs_m25p_cfg);