Skip to content

Commit

Permalink
Merge pull request #21 from spark/feature/software-factory-reset
Browse files Browse the repository at this point in the history
Enable factory reset from software
  • Loading branch information
Zachary Crockett committed Apr 13, 2014
2 parents a5eade6 + 2bede20 commit 2522bb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions SPARK_Firmware_Driver/inc/hw_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ extern uint8_t LED_RGB_OVERRIDE;
extern uint16_t CORE_FW_Version_SysFlag;
extern uint16_t NVMEM_SPARK_Reset_SysFlag;
extern uint16_t FLASH_OTA_Update_SysFlag;
extern uint16_t Factory_Reset_SysFlag;

extern unsigned char wlan_rx_buffer[];
extern unsigned char wlan_tx_buffer[];
Expand Down
17 changes: 14 additions & 3 deletions SPARK_Firmware_Driver/src/hw_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ uint16_t CORE_FW_Version_SysFlag = 0xFFFF;
uint16_t NVMEM_SPARK_Reset_SysFlag = 0xFFFF;
uint16_t FLASH_OTA_Update_SysFlag = 0xFFFF;
uint16_t OTA_FLASHED_Status_SysFlag = 0xFFFF;
uint16_t Factory_Reset_SysFlag = 0xFFFF;

uint32_t WRPR_Value = 0xFFFFFFFF;
uint32_t Flash_Pages_Protected = 0x0;
Expand Down Expand Up @@ -1267,6 +1268,9 @@ void Load_SystemFlags(void)

OTA_FLASHED_Status_SysFlag = (*(__IO uint16_t*) Address);
Address += 2;

Factory_Reset_SysFlag = (*(__IO uint16_t*) Address);
Address += 2;
}

void Save_SystemFlags(void)
Expand Down Expand Up @@ -1307,6 +1311,11 @@ void Save_SystemFlags(void)
while(FLASHStatus != FLASH_COMPLETE);
Address += 2;

/* Program Factory_Reset_SysFlag */
FLASHStatus = FLASH_ProgramHalfWord(Address, Factory_Reset_SysFlag);
while(FLASHStatus != FLASH_COMPLETE);
Address += 2;

/* Locks the FLASH Program Erase Controller */
FLASH_Lock();
}
Expand Down Expand Up @@ -1611,10 +1620,12 @@ void FLASH_Read_CorePrivateKey(uint8_t *keyBuffer)

void FACTORY_Flash_Reset(void)
{
//Restore the Factory programmed application firmware from External Flash
FLASH_Restore(EXTERNAL_FLASH_FAC_ADDRESS);
// Restore the Factory programmed application firmware from External Flash
FLASH_Restore(EXTERNAL_FLASH_FAC_ADDRESS);

Finish_Update();
Factory_Reset_SysFlag = 0xFFFF;

Finish_Update();
}

void BACKUP_Flash_Reset(void)
Expand Down

0 comments on commit 2522bb8

Please sign in to comment.