Ejemplo n.º 1
0
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();
  }
  
}
Ejemplo n.º 2
0
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
}
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_RAM) && !checkUserCode(USER_CODE_FLASH0X8005000) && !checkUserCode(USER_CODE_FLASH0X8002000)) || 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 (checkUserCodeRam(USER_CODE_FLASH0X8002000+4))
	{
		int ptr;
		/*
		u32 *flashAdr = (u32 *)USER_CODE_FLASH0X8002000;
		u32 *ramAdr = (u32 *)USER_CODE_RAM;
		for (ptr = 0; ptr < ((RAM_END-USER_CODE_RAM)-1024)/4; ptr ++) {
			ramAdr[ptr] = flashAdr[ptr];
        }
		*/
		u32 const *flashAdr = (u32 const *)USER_CODE_FLASH0X8002000;
		u32 *ramAdr = (u32 *)USER_CODE_RAM;
		ptr = ((RAM_END-USER_CODE_RAM)-1024)>>2;
		while (ptr--)
		{
			*ramAdr++ = *flashAdr++;
		}
		jumpToUser(USER_CODE_RAM);
	}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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 */
}