mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-27 16:54:15 +01:00
Flashfs: Clean up some of the JEDEC commands and also format whole chip when FS
is wrong.
This commit is contained in:
parent
fe7b9a909a
commit
6d572986e5
@ -35,7 +35,7 @@
|
||||
#define JEDEC_WRITE_STATUS 0x01
|
||||
#define JEDEC_READ_DATA 0x03
|
||||
#define JEDEC_FAST_READ 0x0b
|
||||
#define JEDEC_DEVICE_ID 0x90
|
||||
#define JEDEC_DEVICE_ID 0x9F
|
||||
#define JEDEC_PAGE_WRITE 0x02
|
||||
|
||||
#define JEDEC_STATUS_BUSY 0x01
|
||||
@ -58,6 +58,8 @@ struct jedec_flash_dev {
|
||||
uint32_t spi_id;
|
||||
uint32_t slave_num;
|
||||
bool claimed;
|
||||
uint32_t device_type;
|
||||
uint32_t capacity;
|
||||
const struct pios_flash_jedec_cfg * cfg;
|
||||
enum pios_jedec_dev_magic magic;
|
||||
};
|
||||
@ -210,11 +212,8 @@ int32_t PIOS_Flash_Jedec_ReadStatus()
|
||||
*/
|
||||
int32_t PIOS_Flash_Jedec_ReadID()
|
||||
{
|
||||
if(PIOS_Flash_Jedec_Validate(flash_dev) != 0)
|
||||
return -1;
|
||||
|
||||
uint8_t out[] = {JEDEC_DEVICE_ID, 0, 0, 0, 0, 0};
|
||||
uint8_t in[6];
|
||||
uint8_t out[] = {JEDEC_DEVICE_ID};
|
||||
uint8_t in[4];
|
||||
if (PIOS_Flash_Jedec_ClaimBus() < 0)
|
||||
return -1;
|
||||
|
||||
@ -223,7 +222,10 @@ int32_t PIOS_Flash_Jedec_ReadID()
|
||||
return -2;
|
||||
}
|
||||
PIOS_Flash_Jedec_ReleaseBus();
|
||||
return in[5];
|
||||
|
||||
flash_dev->device_type = in[1];
|
||||
flash_dev->capacity = in[3];
|
||||
return in[1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,8 @@ int32_t PIOS_FLASHFS_Init(const struct flashfs_cfg * new_cfg)
|
||||
return -1;
|
||||
if(object_table_magic != OBJECT_TABLE_MAGIC) {
|
||||
if(magic_fail_count++ > MAX_BADMAGIC) {
|
||||
PIOS_FLASHFS_ClearObjectTableHeader();
|
||||
if(PIOS_FLASHFS_Format() != 0)
|
||||
return -1;
|
||||
#if defined(PIOS_LED_HEARTBEAT)
|
||||
PIOS_LED_Toggle(PIOS_LED_HEARTBEAT);
|
||||
#endif /* PIOS_LED_HEARTBEAT */
|
||||
@ -91,7 +92,6 @@ int32_t PIOS_FLASHFS_Init(const struct flashfs_cfg * new_cfg)
|
||||
} else {
|
||||
PIOS_DELAY_WaituS(1000);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
magic_good = true;
|
||||
@ -146,6 +146,10 @@ static int32_t PIOS_FLASHFS_ClearObjectTableHeader()
|
||||
if (PIOS_Flash_Jedec_WriteData(0, (uint8_t *)&object_table_magic, sizeof(object_table_magic)) != 0)
|
||||
return -1;
|
||||
|
||||
PIOS_Flash_Jedec_ReadData(0, (uint8_t *)&object_table_magic, sizeof(object_table_magic));
|
||||
if(object_table_magic != OBJECT_TABLE_MAGIC)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user