1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

OP-881 Make PIOS_Flash_Jedec_Init able to configure the flash chip based on Jedec Id returned using a catalog of known flash chips.

+review OPReview
This commit is contained in:
Alessio Morale 2013-03-27 00:26:47 +01:00
parent 8d6ef5cfe9
commit e68aeb0c8e
9 changed files with 102 additions and 45 deletions

View File

@ -30,6 +30,7 @@
*/
#include "pios.h"
#include "pios_flash_jedec_priv.h"
#include "pios_flash_jedec_catalog.h"
#define JEDEC_WRITE_ENABLE 0x06
#define JEDEC_WRITE_DISABLE 0x04
@ -115,7 +116,7 @@ static int32_t PIOS_Flash_Jedec_Validate(struct jedec_flash_dev * flash_dev) {
/**
* @brief Initialize the flash device and enable write access
*/
int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg)
int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t slave_num)
{
struct jedec_flash_dev * flash_dev = PIOS_Flash_Jedec_alloc();
if (flash_dev == NULL)
@ -123,16 +124,26 @@ int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t sl
flash_dev->spi_id = spi_id;
flash_dev->slave_num = slave_num;
flash_dev->cfg = cfg;
flash_dev->cfg = 0;
(void) PIOS_Flash_Jedec_ReadID(flash_dev);
if ((flash_dev->manufacturer != flash_dev->cfg->expect_manufacturer) ||
(flash_dev->memorytype != flash_dev->cfg->expect_memorytype) ||
(flash_dev->capacity != flash_dev->cfg->expect_capacity)) {
/* Mismatched device has been discovered */
return -1;
uint32_t i = 0;
while(i < pios_flash_jedec_catalog_size)
{
const struct pios_flash_jedec_cfg flash_jedec_entry = pios_flash_jedec_catalog[i];
if ((flash_dev->manufacturer == flash_jedec_entry.expect_manufacturer) &&
(flash_dev->memorytype == flash_jedec_entry.expect_memorytype) &&
(flash_dev->capacity == flash_jedec_entry.expect_capacity))
{
flash_dev->cfg = &pios_flash_jedec_catalog[i];
}
i++;
}
if(flash_dev->cfg == 0)
return -1;
/* Give back a handle to this flash device */
*flash_id = (uintptr_t) flash_dev;

View File

@ -0,0 +1,71 @@
/**
******************************************************************************
*
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_FLASH JEDEC devices catalog
* @{
*
* @file pios_flash_jedec_catalog.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
* @brief Driver for talking to most JEDEC flash chips
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* 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.
*
* This program is distributed in the hope that it will be useful, but
* 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
*/
#ifndef PIOS_FLASH_JEDEC_CATALOG_H_
#define PIOS_FLASH_JEDEC_CATALOG_H_
#include <pios_flash_jedec_priv.h>
// this structure contains the catalog of all "known" flash chip used
const struct pios_flash_jedec_cfg pios_flash_jedec_catalog [] =
{
{ // m25p16
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
.expect_memorytype = 0x20,
.expect_capacity = 0x15,
.sector_erase = 0xD8,
.chip_erase = 0xC7,
},
{ // m25px16
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
.expect_memorytype = 0x71,
.expect_capacity = 0x15,
.sector_erase = 0xD8,
.chip_erase = 0xC7,
},
{ //w25x
.expect_manufacturer = JEDEC_MANUFACTURER_WINBOND,
.expect_memorytype = 0x30,
.expect_capacity = 0x13,
.sector_erase = 0x20,
.chip_erase = 0x60
},
{ //25q16
.expect_manufacturer = JEDEC_MANUFACTURER_WINBOND,
.expect_memorytype = 0x40,
.expect_capacity = 0x15,
.sector_erase = 0x20,
.chip_erase = 0x60
}
};
const uint32_t pios_flash_jedec_catalog_size = NELEMENTS(pios_flash_jedec_catalog);
#endif /* PIOS_FLASH_JEDEC_CATALOG_H_ */

View File

@ -47,6 +47,6 @@ struct pios_flash_jedec_cfg {
uint32_t chip_erase;
};
int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg);
int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t slave_num);
#endif /* PIOS_FLASH_JEDEC_H_ */

View File

@ -169,11 +169,11 @@ void PIOS_Board_Init(void) {
uintptr_t fs_id;
switch(bdinfo->board_rev) {
case BOARD_REVISION_CC:
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_flash_accel_id, 1, &flash_w25x_cfg);
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_flash_accel_id, 1);
PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_w25x_cfg, &pios_jedec_flash_driver, flash_id);
break;
case BOARD_REVISION_CC3D:
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_flash_accel_id, 0, &flash_m25p_cfg);
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_flash_accel_id, 0);
PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_m25p_cfg, &pios_jedec_flash_driver, flash_id);
break;
default:

View File

@ -336,9 +336,14 @@ void PIOS_Board_Init(void) {
#if defined(PIOS_INCLUDE_FLASH)
/* Connect flash to the appropriate interface and configure it */
uintptr_t flash_id;
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_telem_flash_id, 1, &flash_m25p_cfg);
if (PIOS_Flash_Jedec_Init(&flash_id, pios_spi_telem_flash_id, 1))
PIOS_DEBUG_Assert(0);
uintptr_t fs_id;
PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_m25p_cfg, &pios_jedec_flash_driver, flash_id);
if (PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_m25p_cfg, &pios_jedec_flash_driver, flash_id))
PIOS_DEBUG_Assert(0);
#endif
/* Initialize UAVObject libraries */

View File

@ -386,11 +386,11 @@ void PIOS_Board_Init(void) {
}
/* Connect flash to the appropriate interface and configure it */
uintptr_t flash_id;
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_flash_id, 0, &flash_m25p_cfg);
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_flash_id, 0);
#else
/* Connect flash to the appropriate interface and configure it */
uintptr_t flash_id;
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_accel_id, 1, &flash_m25p_cfg);
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_accel_id, 1);
#endif
uintptr_t fs_id;
PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_m25p_cfg, &pios_jedec_flash_driver, flash_id);

View File

@ -414,13 +414,7 @@ static const struct flashfs_logfs_cfg flashfs_w25x_cfg = {
.page_size = 0x00000100, /* 256 bytes */
};
static const struct pios_flash_jedec_cfg flash_w25x_cfg = {
.expect_manufacturer = JEDEC_MANUFACTURER_WINBOND,
.expect_memorytype = 0x30,
.expect_capacity = 0x13,
.sector_erase = 0x20,
.chip_erase = 0x60
};
static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
.fs_magic = 0x99abceef,
@ -433,14 +427,6 @@ static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
.page_size = 0x00000100, /* 256 bytes */
};
static const struct pios_flash_jedec_cfg flash_m25p_cfg = {
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
.expect_memorytype = 0x20,
.expect_capacity = 0x15,
.sector_erase = 0xD8,
.chip_erase = 0xC7,
};
#include "pios_flash.h"
#endif /* PIOS_INCLUDE_FLASH */

View File

@ -462,14 +462,6 @@ static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
.page_size = 0x00000100, /* 256 bytes */
};
static const struct pios_flash_jedec_cfg flash_m25p_cfg = {
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
.expect_memorytype = 0x20,
.expect_capacity = 0x15,
.sector_erase = 0xD8,
.chip_erase = 0xC7,
};
#endif /* PIOS_INCLUDE_FLASH */
#if defined(PIOS_OVERO_SPI)

View File

@ -567,14 +567,6 @@ static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
.page_size = 0x00000100, /* 256 bytes */
};
static const struct pios_flash_jedec_cfg flash_m25p_cfg = {
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
.expect_memorytype = 0x20,
.expect_capacity = 0x15,
.sector_erase = 0xD8,
.chip_erase = 0xC7,
};
#endif /* PIOS_INCLUDE_FLASH */
#include <pios_usart_priv.h>