Exemplo n.º 1
0
int Spark_Finish_Firmware_Update(FileTransfer::Descriptor& file, uint32_t flags, void* reserved)
{
    SPARK_FLASH_UPDATE = 0;
    TimingFlashUpdateTimeout = 0;
    //serial_dump("update finished flags=%d store=%d", flags, file.store);


    if (flags & 1) {    // update successful
        if (file.store==FileTransfer::Store::FIRMWARE)
        {
            hal_update_complete_t result = HAL_FLASH_End(NULL);

            system_notify_event(firmware_update, result!=HAL_UPDATE_ERROR ? firmware_update_complete : firmware_update_failed, &file);

            // todo - talk with application and see if now is a good time to reset
            // if update not applied, do we need to reset?
            HAL_Core_System_Reset();
        }
    }
    else
    {
        system_notify_event(firmware_update, firmware_update_failed, &file);
    }
    RGB.control(false);
    return 0;
}
Exemplo n.º 2
0
bool system_fileTransfer(system_file_transfer_t* tx, void* reserved)
{
    bool status = false;
    Stream* serialObj = tx->stream;

    if (NULL != Ymodem_Serial_Flash_Update_Handler)
    {
        status = Ymodem_Serial_Flash_Update_Handler(serialObj, tx->descriptor, NULL);
        SPARK_FLASH_UPDATE = 0;
        TimingFlashUpdateTimeout = 0;

        if (status == true)
        {
            if (tx->descriptor.store==FileTransfer::Store::FIRMWARE) {
                serialObj->println("Restarting system to apply firmware update...");
                HAL_Delay_Milliseconds(100);
                HAL_Core_System_Reset();
            }
        }
    }
    else
    {
        serialObj->println("Firmware update using this terminal is not supported!");
        serialObj->println("Add #include \"Ymodem/Ymodem.h\" to your sketch and try again.");
    }
    return status;
}
Exemplo n.º 3
0
void panic_(ePanicCode code, void* extraInfo, void (*HAL_Delay_Microseconds)(uint32_t))
{
        HAL_disable_irq();
        // Flush any serial message to help the poor bugger debug this;
        flash_codes_t pcd = flash_codes[code];
        LED_SetRGBColor(RGB_COLOR_RED);
        LED_SetBrightness(DEFAULT_LED_RGB_BRIGHTNESS);
        LED_Signaling_Stop();
        uint16_t c;
        int loops = 2;
        log_direct_("!");
        LED_Off(LED_RGB);
        while(loops) {
                // preamble
            for (c = 3; c; c--) {
                LED_SetRGBColor(pcd.led);
                LED_On(LED_RGB);
                HAL_Delay_Microseconds(MS2u(150));
                LED_Off(LED_RGB);
                HAL_Delay_Microseconds(MS2u(100));
            }

            HAL_Delay_Microseconds(MS2u(100));
            for (c = 3; c; c--) {
                LED_SetRGBColor(pcd.led);
                LED_On(LED_RGB);
                HAL_Delay_Microseconds(MS2u(300));
                LED_Off(LED_RGB);
                HAL_Delay_Microseconds(MS2u(100));
            }
            HAL_Delay_Microseconds(MS2u(100));

            for (c = 3; c; c--) {
                LED_SetRGBColor(pcd.led);
                LED_On(LED_RGB);
                HAL_Delay_Microseconds(MS2u(150));
                LED_Off(LED_RGB);
                HAL_Delay_Microseconds(MS2u(100));
            }

            // pause
            HAL_Delay_Microseconds(MS2u(900));
            // play code
            for (c = code; c; c--) {
                LED_SetRGBColor(pcd.led);
                LED_On(LED_RGB);
                HAL_Delay_Microseconds(MS2u(300));
                LED_Off(LED_RGB);
                HAL_Delay_Microseconds(MS2u(300));
            }
            // pause
            HAL_Delay_Microseconds(MS2u(800));
#ifdef RELEASE_BUILD
            if (--loops == 0) HAL_Core_System_Reset();
#endif
        }

}
Exemplo n.º 4
0
void HAL_Core_System_Reset_Ex(int reason, uint32_t data, void *reserved)
{
    if (HAL_Feature_Get(FEATURE_RESET_INFO))
    {
        // Save reset info to backup registers
        BKP_WriteBackupRegister(BKP_DR2, reason);
        BKP_WriteBackupRegister(BKP_DR3, data >> 16);
        BKP_WriteBackupRegister(BKP_DR4, data & 0xffff);
    }
    HAL_Core_System_Reset();
}
Exemplo n.º 5
0
void HAL_Core_Enter_Bootloader(bool persist)
{
    if (persist)
    {
        BKP_WriteBackupRegister(BKP_DR10, 0xFFFF);
        FLASH_OTA_Update_SysFlag = 0xFFFF;
        Save_SystemFlags();
    }
    else
    {
        BKP_WriteBackupRegister(BKP_DR1, ENTER_DFU_APP_REQUEST);
    }

    HAL_Core_System_Reset();
}
Exemplo n.º 6
0
void generate_key()
{
    // normallly allocating such a large buffer on the stack would be a bad idea, however, we are quite near the start of execution, with few levels of recursion.
    char buf[EXTERNAL_FLASH_CORE_PRIVATE_KEY_LENGTH];
    // ensure the private key is provisioned

    // Reset the system after generating the key - reports of Serial not being available in listening mode
    // after generating the key.
    private_key_generation_t genspec;
    genspec.size = sizeof(genspec);
    genspec.gen = PRIVATE_KEY_GENERATE_MISSING;
    HAL_FLASH_Read_CorePrivateKey(buf, &genspec);
    if (genspec.generated_key)
        HAL_Core_System_Reset();
}
Exemplo n.º 7
0
void HAL_Core_Enter_Safe_Mode(void* reserved)
{
    BKP_WriteBackupRegister(BKP_DR1, ENTER_SAFE_MODE_APP_REQUEST);
    HAL_Core_System_Reset();
}
Exemplo n.º 8
0
void HAL_Core_Factory_Reset(void)
{
	Factory_Reset_SysFlag = 0xAAAA;
	Save_SystemFlags();
	HAL_Core_System_Reset();
}
Exemplo n.º 9
0
/*******************************************************************************
 * Function Name  : HAL_SysTick_Handler
 * Description    : Decrements the various Timing variables related to SysTick.
 * Input          : None
 * Output         : None.
 * Return         : None.
 ************************************************
 *******************************/
extern "C" void HAL_SysTick_Handler(void)
{
    if (LED_RGB_IsOverRidden())
    {
#ifndef SPARK_NO_CLOUD
        if (LED_Spark_Signal != 0)
        {
            LED_Signaling_Override();
        }
#endif
    }
    else if (TimingLED != 0x00)
    {
        TimingLED--;
    }
    else if(SPARK_FLASH_UPDATE || Spark_Error_Count || network.listening())
    {
        //Do nothing
    }
    else if (SYSTEM_POWEROFF)
    {
        LED_SetRGBColor(RGB_COLOR_GREY);
        LED_On(LED_RGB);
    }
    else if(SPARK_LED_FADE && (!SPARK_CLOUD_CONNECTED || system_cloud_active()))
    {
        LED_Fade(LED_RGB);
        TimingLED = 20;//Breathing frequency kept constant
    }
    else if(SPARK_CLOUD_CONNECTED)
    {
        LED_SetRGBColor(system_mode()==SAFE_MODE ? RGB_COLOR_MAGENTA : RGB_COLOR_CYAN);
        LED_On(LED_RGB);
        SPARK_LED_FADE = 1;
    }
    else
    {
        LED_Toggle(LED_RGB);
        if(SPARK_CLOUD_SOCKETED || ( network.connected() && !network.ready()))
            TimingLED = 50;         //50ms
        else
            TimingLED = 100;        //100ms
    }

    if(SPARK_FLASH_UPDATE)
    {
#ifndef SPARK_NO_CLOUD
        if (TimingFlashUpdateTimeout >= TIMING_FLASH_UPDATE_TIMEOUT)
        {
            //Reset is the only way now to recover from stuck OTA update
            HAL_Core_System_Reset();
        }
        else
        {
            TimingFlashUpdateTimeout++;
        }
#endif
    }
    else if(network.listening() && HAL_Core_Mode_Button_Pressed(10000))
    {
        network.listen_command();
    }
    // determine if the button press needs to change the state (and hasn't done so already))
    else if(!network.listening() && HAL_Core_Mode_Button_Pressed(3000) && !wasListeningOnButtonPress)
    {
        if (network.connecting()) {
            network.connect_cancel(true, true);
        }
        // fire the button event to the user, then enter listening mode (so no more button notifications are sent)
        // there's a race condition here - the HAL_notify_button_state function should
        // be thread safe, but currently isn't.
        HAL_Notify_Button_State(0, false);
        network.listen();
        HAL_Notify_Button_State(0, true);
    }

#ifdef IWDG_RESET_ENABLE
    if (TimingIWDGReload >= TIMING_IWDG_RELOAD)
    {
        TimingIWDGReload = 0;

        /* Reload WDG counter */
        HAL_Notify_WDT();
        DECLARE_SYS_HEALTH(CLEARED_WATCHDOG);
    }
    else
    {
        TimingIWDGReload++;
    }
#endif
}