Ejemplo n.º 1
0
void setupUSB (void) {
	setupDisconnectPin();
	disconnectUSB();

  /* turn on the USB clock */
#ifdef STM32F2
  pRCC->AHB1ENR |= RCC_AHB1ENR_OTGHSEN;
#else
  pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;
#endif

  /* initialize the usb application */
	connectUSB();
	usbAppInit();
}
void setupUSB (void) {
  /* enable USB DISC Pin */
  pRCC->APB2ENR |= RCC_APB2ENR_USB;

  /* Setup USB DISC pin as output open drain */
  SET_REG(USB_DISC_CR,
          (GET_REG(USB_DISC_CR) & USB_DISC_CR_MASK) | USB_DISC_CR_OUTPUT_OD);
  setPin(USB_DISC_BANK, USB_DISC);

  /* turn on the USB clock */
  pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;

  /* initialize the USB application */
  resetPin(USB_DISC_BANK, USB_DISC);  /* present ourselves to the host */
  usbAppInit();
}
Ejemplo n.º 3
0
void setupUSB (void) {

#ifdef HAS_MAPLE_HARDWARE	
  /* Setup USB DISC pin as output open drain */	
  SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),(GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_OUTPUT_OD << CR_SHITF(LED_PIN));  
  gpio_write_bit(USB_DISC_BANK,USB_DISC,1);

  /* turn on the USB clock */
  //pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;// done in setupCLK()

  gpio_write_bit(USB_DISC_BANK,USB_DISC,0);  /* present ourselves to the host */
#else

/* Generic boards don't have disconnect hardware, so we drive PA12 which is connected to the usb D+ line*/
#define USB_DISC_BANK         GPIOA
#define USB_DISC              12

  SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),
          (GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_OUTPUT_PP << CR_SHITF(USB_DISC));

  gpio_write_bit(USB_DISC_BANK,USB_DISC,0);  /* present ourselves to the host */
  
  volatile unsigned int delay;
  for(delay = 0;delay<256;delay++);

  //  volatile unsigned x = 1024; do { ; }while(--x);// wait a moment
  /* turn on the USB clock */
   SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),
          (GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_INPUT << CR_SHITF(USB_DISC)); //Sets the PA12 as floating input
 //  pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;
#endif  
  /* initialize the usb application */
  
  wTransferSize=getFlashPageSize();
  u8_usbConfigDescriptorDFU[41]=(wTransferSize & 0x00FF);
  u8_usbConfigDescriptorDFU[42]=(wTransferSize & 0xFF00)>>8;
  
  u8_usbFunctionalDescriptor[5]=(wTransferSize & 0x00FF);
  u8_usbFunctionalDescriptor[6]=(wTransferSize & 0xFF00)>>8;  
  
  usbAppInit();

}
Ejemplo n.º 4
0
void setupUSB (void) {
  u32 rwmVal; /* read-write-modify place holder var */

  /* Setup the USB DISC Pin */
  rwmVal  = GET_REG(RCC_APB2ENR);
  rwmVal |= 0x00000010;
  SET_REG(RCC_APB2ENR,rwmVal);

  // todo, macroize usb_disc pin
  /* Setup GPIOC Pin 12 as OD out */
  rwmVal  = GET_REG(GPIO_CRH(GPIOC));
  rwmVal &= 0xFFF0FFFF;
  rwmVal |= 0x00050000;
  setPin (GPIOC,12);
  SET_REG(GPIO_CRH(GPIOC),rwmVal);

  pRCC->APB1ENR |= 0x00800000;

  /* initialize the usb application */
  resetPin (GPIOC,12);  /* present ourselves to the host */
  usbAppInit();

}
Ejemplo n.º 5
0
void setupUSB (void) {
  /* enable USB DISC Pin */
#ifdef STM32F2
#if !defined(BOARD_DiscoveryF4)
  pRCC->AHB1ENR |= RCC_AHB1ENR_USB;


	GPIO_TypeDef *p = (GPIO_TypeDef *)USB_DISC_BANK;
  /* set to output */
  p->MODER = 1 << (2*USB_DISC);
  /* Configure pins speed to 100 MHz */
  //p->OSPEEDR = 0xffffc00f; // 2 bit/port medium speed = %01
  /* Configure pins Output type to open drain */
  p->OTYPER  = 1 << (2*USB_DISC);
  /* No pull-up, pull-down for PEx pins */
  //p->PUPDR   = 0x00000000;
#endif
#else
  pRCC->APB2ENR |= RCC_APB2ENR_USB;
  /* Setup USB DISC pin as output open drain */
  SET_REG(USB_DISC_CR, (GET_REG(USB_DISC_CR) & USB_DISC_CR_MASK) | USB_DISC_CR_OUTPUT_OD); // ala42 just pull down external pull up
  //SET_REG(USB_DISC_CR, (GET_REG(USB_DISC_CR) & USB_DISC_CR_MASK) | USB_DISC_CR_OUTPUT_PP); // ala42 actively pull up USBDP
#endif

	disconnectUSB();

  /* turn on the USB clock */
#ifdef STM32F2
  pRCC->AHB1ENR |= RCC_AHB1ENR_OTGHSEN;
#else
  pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;
#endif

  /* initialize the usb application */
	connectUSB();
	usbAppInit();
}
Ejemplo n.º 6
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;
}