int main() { systemReset(); // peripherals but not PC setupCLK(); setupLED(); setupUSB(); setupBUTTON(); setupFLASH(); strobePin(LED_BANK,LED,STARTUP_BLINKS,BLINK_FAST); /* wait for host to upload program or halt bootloader */ bool no_user_jump = !checkUserCode(USER_CODE_FLASH) && !checkUserCode(USER_CODE_RAM) || readPin(BUTTON_BANK,BUTTON); int delay_count = 0; while ((delay_count++ < BOOTLOADER_WAIT) || no_user_jump) { strobePin(LED_BANK,LED,1,BLINK_SLOW); if (dfuUploadStarted()) { dfuFinishUpload(); // systemHardReset from DFU once done } } if (checkUserCode(USER_CODE_RAM)) { jumpToUser(USER_CODE_RAM); } else if (checkUserCode(USER_CODE_FLASH)) { jumpToUser(USER_CODE_FLASH); } else { // some sort of fault occurred, hard reset strobePin(LED_BANK,LED,5,BLINK_FAST); systemHardReset(); } }
int main() { systemReset(); // peripherals but not PC setupCLK(); setupLEDAndButton(); setupUSB(); setupFLASH(); // strobePin(LED_BANK, LED_PIN, 9999, BLINK_SLOW,LED_ON_STATE); strobePin(LED_BANK, LED_PIN, STARTUP_BLINKS, BLINK_FAST,LED_ON_STATE); /* wait for host to upload program or halt bootloader */ bool no_user_jump = (!checkUserCode(USER_CODE_FLASH0X8005000) && !checkUserCode(USER_CODE_FLASH0X8002000)) || readButtonState() ; int delay_count = 0; while ((delay_count++ < BOOTLOADER_WAIT) || no_user_jump) { strobePin(LED_BANK, LED_PIN, 1, BLINK_SLOW,LED_ON_STATE); if (dfuUploadStarted()) { dfuFinishUpload(); // systemHardReset from DFU once done } } if (checkUserCode(USER_CODE_FLASH0X8002000)) { jumpToUser(USER_CODE_FLASH0X8002000); } else { if (checkUserCode(USER_CODE_FLASH0X8005000)) { jumpToUser(USER_CODE_FLASH0X8005000); } else { // Nothing to execute in either Flash or RAM strobePin(LED_BANK, LED_PIN, 5, BLINK_FAST,LED_ON_STATE); systemHardReset(); } } return 0;// Added to please the compiler }
void dfuUpdateByReset(void) { u8 startState = dfuAppStatus.bState; userFirmwareLen = 0; if (startState == appDETACH) { dfuAppStatus.bState = dfuIDLE; dfuAppStatus.bStatus = OK; nvicDisableInterrupts(); usbEnbISR(); } else if (startState == appIDLE || startState == dfuIDLE) { /* do nothing...might be normal usb bus activity */ } else { /* we reset from the dfu, reset everything and startover, which is the correct operation if this is an erroneous event or properly following a MANIFEST */ dfuAppStatus.bState = dfuIDLE; dfuAppStatus.bStatus = OK; systemHardReset(); } }
/** * @brief VCP_DataRx * Data received over USB OUT endpoint are sent over CDC interface * through this function. * * @note * This function will block any OUT packet reception on USB endpoint * until exiting this function. If you exit this function before transfer * is complete on CDC interface (ie. using DMA controller) it will result * in receiving more data while previous ones are still not sent. * * @param Buf: Buffer of data to be received * @param Len: Number of data received (in bytes) * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL */ static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len) { if(VCP_DTRHIGH) { if(Len >= 4) { if(Buf[0] == '1' && Buf[1] == 'E' && Buf[2] == 'A' && Buf[3] == 'F') { Len = 0; *(int*)0x20000BFC = 0x4AFC6BB2; systemHardReset(); } } } VCP_DTRHIGH = 0; while(Len-- > 0) { UsbRecBuffer[UsbRecWrite] = *Buf++; if(UsbRecWrite == UsbRecBufferSize) { UsbRecWrite = 0; } else { UsbRecWrite ++; } } return USBD_OK; }
int main() { systemReset(); // peripherals but not PC boardInit(); strobePin(LED_BANK,LED,STARTUP_BLINKS,BLINK_FAST); pRCC->APB1ENR |= 0x00800000; usbAppInit(); setupFLASH(); #ifdef CONFIG_EXTRA_MAIN_CODE CONFIG_EXTRA_MAIN_CODE #endif /* wait for host to upload program or halt bootloader */ while (bootloaderCondition) { strobePin(LED_BANK,LED,1,BLINK_SLOW); if (dfuUploadStarted()) { dfuFinishUpload(); // systemHardReset from DFU once done } #ifdef bootloaderExitCondition if (bootloaderExitCondition) break; #endif } if (checkUserCode(USER_CODE_RAM)) { jumpToUser(USER_CODE_RAM); } else if (checkUserCode(USER_CODE_FLASH)) { jumpToUser(USER_CODE_FLASH); } else { // some sort of fault occurred, hard reset strobePin(LED_BANK,LED,5,BLINK_FAST); systemHardReset(); } return 0; }
void usbWaitReset(void) { delay_us(RESET_DELAY); systemHardReset(); }
int main() { systemReset(); // peripherals but not PC setupCLK(); setupLED(); setupBUTTON(); #ifdef STM32F2 setupDisconnectPin(); disconnectUSB(); #else setupUSB(); setupFLASH(); #endif strobePin(LED_BANK,LED,STARTUP_BLINKS,BLINK_FAST); #ifdef STM32F2 // enter built in boot load if magic number found in RAM if(*START_BOOT_LOADER_MAGIC_ADDR == START_BOOT_LOADER_MAGIC) { connectUSB(); *START_BOOT_LOADER_MAGIC_ADDR = 0; jumpToUser(BUILT_IN_BOOT_LOADER); } #endif #ifdef FASTSTART // for an unknown reason the loader process hangs if the button port is not read bool pinState = readPin(BUTTON_BANK, BUTTON); #else bool buttonStatusHigh = TRUE; bool buttonStatusLow = FALSE; for(int i=0; i<10; i++) { bool pinState = readPin(BUTTON_BANK, BUTTON); buttonStatusHigh = buttonStatusHigh && pinState; buttonStatusLow = buttonStatusLow || pinState; } /* wait for host to upload program or halt bootloader */ bool no_user_jump = (!checkUserCode(USER_CODE_FLASH) && !checkUserCode(USER_CODE_RAM)) || buttonStatusHigh; int delay_count = 0; while ((delay_count++ < BOOTLOADER_WAIT) || no_user_jump) { strobePin(LED_BANK,LED,1,BLINK_SLOW); #ifndef STM32F2 if (dfuUploadStarted()) { dfuFinishUpload(); // systemHardReset from DFU once done } #endif } #endif if (checkUserCode(USER_CODE_RAM)) { jumpToUser(USER_CODE_RAM); } else if (checkUserCode(USER_CODE_FLASH)) { jumpToUser(USER_CODE_FLASH); } else { // some sort of fault occurred, hard reset strobePin(LED_BANK,LED,5,BLINK_FAST); systemHardReset(); } return 0; /* can't happen, but placate the compiler */ }