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_Ex(RESET_REASON_UPDATE, 0, nullptr); } } } 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; }
void panic_(ePanicCode code, void* extraInfo, void (*HAL_Delay_Microseconds)(uint32_t)) { #if HAL_PLATFORM_CORE_ENTER_PANIC_MODE HAL_Core_Enter_Panic_Mode(NULL); #else HAL_disable_irq(); #endif // HAL_PLATFORM_CORE_ENTER_PANIC_MODE // 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_PRINT(TRACE, "!"); 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)); #if defined(RELEASE_BUILD) || PANIC_BUT_KEEP_CALM == 1 if (--loops == 0) HAL_Core_System_Reset_Ex(RESET_REASON_PANIC, code, NULL); #endif } }