예제 #1
0
/**
 *  \brief SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{

	DEBUG_PIN_HIGH;

	/* Jump in application if condition is satisfied */
	check_start_application();

	/* We have determined we should stay in the monitor. */
	/* System initialization */
	system_init();

	/* UART is enabled in all cases */
	usart_open();

	DEBUG_PIN_LOW;
	/* Wait for a complete enum on usb or a '#' char on serial line */
	while (1) {
		/* Check if a '#' has been received */
		if (usart_sharp_received()) {
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			/* SAM-BA on UART loop */
			while(1) {
				sam_ba_monitor_run();
			}
		}
	}
}
예제 #2
0
/**
 *  \brief SAMD20 SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
  
#if DEBUG_ENABLE
        /* Set BOOT_LED pin as output */
        PORT->Group[0].DIRSET.reg=(1u<<BOOT_LED);
#endif
	DEBUG_PIN_HIGH;
        
	/* Jump in application if condition is satisfied */
	check_start_application();
        
        /* Make OSC8M prescalar to zero rather divide by 8 */
        SYSCTRL->OSC8M.bit.PRESC = 0;

	/* UART is enabled in all cases */
	usart_open();

	/* Wait for a complete enum on usb or a '#' char on serial line */
	while (1) {
		/* Check if a '#' has been received */
		if (usart_sharp_received()) {
                        DEBUG_PIN_LOW;
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			/* SAM-BA on UART loop */
			while(1) {
				sam_ba_monitor_run();
			}
		}
	}
}
예제 #3
0
/**
 *  \brief SAMD21 SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES 
	P_USB_CDC pCdc;
#endif
	DEBUG_PIN_HIGH;

	/* Jump in application if condition is satisfied */
	check_start_application();

	/* We have determined we should stay in the monitor. */
	/* System initialization */
	system_init();
	cpu_irq_enable();

	#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
	/* UART is enabled in all cases */
	usart_open();
#endif

#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
	pCdc = (P_USB_CDC)usb_init();
#endif
	DEBUG_PIN_LOW;

	// output on D13 (PA.17)
	LED_PORT.PINCFG[LED_PIN].reg &= ~ (uint8_t)(PORT_PINCFG_INEN);
	LED_PORT.DIRSET.reg = (uint32_t)(1 << LED_PIN);

	/* Wait for a complete enum on usb or a '#' char on serial line */
	while (1) {
   	        pulse_led(1); // while we're waiting, blink the D13 

#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
		if (pCdc->IsConfigured(pCdc) != 0) {
			main_b_cdc_enable = true;
		}

		//Check if a USB enumeration has succeeded
		//And com port was opened
		if (main_b_cdc_enable) {
			sam_ba_monitor_init(SAM_BA_INTERFACE_USBCDC);
			//SAM-BA on USB loop
			while(1) {
				sam_ba_monitor_run();
			}
		}
#endif
#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
		/* Check if a '#' has been received */
		if (!main_b_cdc_enable && usart_sharp_received()) {
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			/* SAM-BA on UART loop */
			while(1) {
				sam_ba_monitor_run();
			}
		}
#endif
	}
}
예제 #4
0
/**
 *  \brief SAMD21 WINO SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint32_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;
  
	P_USB_CDC pCdc;

	DEBUG_PIN_HIGH;

	volatile PortGroup *esp8266_port = (volatile PortGroup *)(&(PORT->Group[ESP8266_CH_PD_PIN / 32]));

	/* Enable the ouput on the ESP8266 power down Pin and drive it to low */
	esp8266_port->DIRSET.reg = ESP8266_CH_PD_PIN_MASK;
	esp8266_port->PINCFG[ESP8266_CH_PD_PIN & 0x1F].reg = PORT_PINCFG_INEN;
	esp8266_port->OUTCLR.reg = ESP8266_CH_PD_PIN_MASK;

	/* Enable the ouput on the LED Pin and drive it to high */
	PORT->Group[LED_PORT].DIRSET.reg = LED_PIN_MASK;
	LED_ON;

	/* System initialization */
	system_init();
	cpu_irq_enable();
	usart_open();
	pCdc = (P_USB_CDC)usb_init();
  
	DEBUG_USART_OPEN;
  
	/* Pointer to store application start address */
	uint32_t *data_ptr = (uint32_t *)0x20000000;
	
	/* Store the application start address @0x20000000 */
	*data_ptr = APP_START_ADDRESS;

	/* Jump in application if condition is satisfied */
	static uint32_t app_start_address;

	/* Load the Reset Handler address of the application */
	app_start_address = *(uint32_t *)(APP_START_ADDRESS + 4);
	
	int waiting = WAIT_SHORT;
	int elapsed;

	/* Test reset vector of application @APP_START_ADDRESS+4
	 * If *(APP_START+0x4) == 0xFFFFFFFF then set waiting
	 * Application erased condition
	 */
	if (app_start_address == 0xFFFFFFFF)
	{
		waiting = -1;
	}
	else if (bootKeyPtrVal == bootKey)
	{
		waiting = WAIT_LONG;
	}
  
	DEBUG_PIN_LOW;
  
	*bootKeyPtr = bootKey;
  
	/* Wait for a complete enum on usb or a '#' char on serial line.
	 * If there is no user application in the device's memory,
	 * this loop will not end, in the other case, it will wait until timeout.
	 */
	while (waiting)
	{
		if (pCdc->IsConfigured(pCdc))
		{
			sam_ba_monitor_init(SAM_BA_INTERFACE_USBCDC);
			main_b_cdc_enable = true;
			break;
		}
		
		if (usart_sharp_received())
		{
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			break;
		}
		
		if (PORT->Group[LED_PORT].OUT.reg == LED_PIN_MASK)
		{
			if (elapsed > 3000)
			{
				LED_OFF;
				elapsed = 0;
			}
		}
		else
		{
			if (elapsed > 30000)
			{
				LED_ON;
				elapsed = 0;
			}
		}
		
		if (waiting > 0)
			waiting--;
			
		elapsed++;
	}

	*bootKeyPtr = 0;
	while (waiting)
	{
		uint32_t tmp = do_sam_ba_monitor();

		if (PORT->Group[LED_PORT].OUT.reg == LED_PIN_MASK)
		{
			if (elapsed > (1 ? 5000 : 1))
			{
				LED_OFF;
				elapsed = 0;
			}
		}
		else
		{
			if (elapsed > (1 ? 50000 : 2))
			{
				LED_ON;
				elapsed = 0;
			}
		}
   
		if (waiting > 0)
		{
			/* If there is no activity, decrement timeout */
			/* Else set WAIT_SHORT timeout */
			if (tmp == 0)
				waiting--;
			else
				waiting = WAIT_SHORT;
		}
		
		elapsed++;
	}
	
	/* Reset LED pin */
	LED_OFF;
	PORT->Group[LED_PORT].DIRCLR.reg = LED_PIN_MASK;
  
	usart_close();
	usb_deinit();
	
	// reset clocks
	
	//SYSCTRL->OSC8M.reg = SYSCTRL_OSC8M_RESETVALUE;
	//SYSCTRL->OSC32K.reg = SYSCTRL_OSC32K_RESETVALUE;
	//SYSCTRL->XOSC32K.reg = SYSCTRL_XOSC32K_RESETVALUE;
	//SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_RESETVALUE;
	//SYSCTRL->DFLLMUL.reg = SYSCTRL_DFLLMUL_RESETVALUE;
	//SYSCTRL->DFLLVAL.reg = SYSCTRL_DFLLVAL_RESETVALUE;
	
	/* Jump to the application */
  
	/* Rebase the Stack Pointer */
	__set_MSP(*(uint32_t *) APP_START_ADDRESS);

	/* Rebase the vector table base address */
	SCB->VTOR = ((uint32_t) APP_START_ADDRESS & SCB_VTOR_TBLOFF_Msk);

	/* Jump to application Reset Handler in the application */
	asm("bx %0"::"r"(app_start_address));
}