@ -44,16 +44,17 @@
/* Private function prototypes -----------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config ( void ) ;
static void SystemClock_Config ( void ) ;
static void GPIO_Init ( void ) ;
static void GPIO_Init ( void ) ;
void DisableFlashWrites ( void ) ;
static void DisableFlashWrites ( void ) ;
void CheckFirmwareMatchesHardware ( void ) ;
static void CheckFirmwareMatchesHardware ( void ) ;
volatile uint8_t UsbInterruptHasHappened = 0 ;
uint8_t IterationCount = 0 ;
int main ( void )
int main ( void )
{
{
uint32_t iterationCount = 0 ;
//First things first!
//First things first!
DisableFlashWrites ( ) ;
DisableFlashWrites ( ) ;
CheckFirmwareMatchesHardware ( ) ;
CheckFirmwareMatchesHardware ( ) ;
@ -77,12 +78,17 @@ int main(void)
Downstream_SPIProcess ( ) ;
Downstream_SPIProcess ( ) ;
Downstream_PacketProcessor_CheckNotifyDisconnectReply ( ) ;
Downstream_PacketProcessor_CheckNotifyDisconnectReply ( ) ;
//Count number of main loops since last USB interrupt
if ( UsbInterruptHasHappened )
{
UsbInterruptHasHappened = 0 ;
IterationCount = 0 ;
}
//Some USB host state transitions take 3 iterations to fully apply.
//Some USB host state transitions take 3 iterations to fully apply.
//We'll be generous and give it 5 before sleeping.
//We'll be generous and give it 5 before sleeping.
iterationCount + + ;
if ( IterationCount + + > 4 )
if ( iterationCount > 4 )
{
{
iterationCount = 0 ;
__WFI ( ) ; //sleep time!
__WFI ( ) ; //sleep time!
}
}
}
}
@ -97,10 +103,11 @@ void DisableFlashWrites(void)
FLASH - > KEYR = 999 ;
FLASH - > KEYR = 999 ;
//Confirm that flash cannot be unlocked
//Confirm that flash cannot be unlocked
//This unlock attempt will also cause a bus fault.
//This unlock attempt will also cause two bus faults.
EnableOneBusFault ( ) ;
if ( ( FLASH - > CR & FLASH_CR_LOCK ) = = 0 ) while ( 1 ) ;
if ( ( FLASH - > CR & FLASH_CR_LOCK ) = = 0 ) while ( 1 ) ;
EnableOneBusFault ( ) ;
FLASH - > KEYR = FLASH_KEY1 ;
FLASH - > KEYR = FLASH_KEY1 ;
EnableOneBusFault ( ) ;
FLASH - > KEYR = FLASH_KEY2 ;
FLASH - > KEYR = FLASH_KEY2 ;
if ( ( FLASH - > CR & FLASH_CR_LOCK ) = = 0 ) while ( 1 ) ;
if ( ( FLASH - > CR & FLASH_CR_LOCK ) = = 0 ) while ( 1 ) ;
}
}