示例#1
0
int main(void)
{
	rcc_clock_setup_in_hse_8mhz_out_72mhz();
	/* LED to indicate boot process */
	rcc_periph_clock_enable(RCC_GPIOC);
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
		GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
	gpio_set(GPIOC, GPIO13);

	rcc_periph_clock_enable(RCC_GPIOA);
	/*
	 * Vile hack to reenumerate, physically _drag_ d+ low.
	 * do NOT do this if you're board has proper usb pull up control!
	 * (need at least 2.5us to trigger usb disconnect)
	 */
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
		GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
	gpio_clear(GPIOA, GPIO11);
	for (unsigned int i = 0; i < 800000; i++)
		__asm__("nop");

	rcc_periph_clock_enable(RCC_OTGFS);


	usbd_device *usbd_dev = gadget0_init(&st_usbfs_v1_usb_driver, "stm32f103-generic");

	ER_DPRINTF("bootup complete\n");
	gpio_clear(GPIOC, GPIO13);
	while (1) {
		usbd_poll(usbd_dev);
	}

}
int main(void)
{
	setup_main_clock();
	setup_peripheral_clocks();
	setup_usb_fullspeed();
	setup_leds();

	while (1)
		usbd_poll();
}
示例#3
0
int main() {
  rcc_clock_setup_hsi(&hsi_8mhz[CLOCK_48MHZ]);
  rcc_usb_prescale_1();
  rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1RSTR_USBRST);
  rcc_peripheral_reset(&RCC_AHBRSTR, RCC_AHBRSTR_IOPARST);
  rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1RSTR_USBRST);
  rcc_peripheral_clear_reset(&RCC_AHBRSTR, RCC_AHBRSTR_IOPARST);
  rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN);
  rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_IOPAEN);
  

  gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO11 | GPIO12);
  gpio_clear(GPIOA, GPIO11 | GPIO12);
  for (int i = 0; i < 0x800000; i++)
    __asm__ volatile("nop");
  
  
  gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12);
  gpio_set_af(GPIOA, GPIO_AF14, GPIO11| GPIO12);

  arm_bootloader::Dest dest = arm_bootloader::get_unique_dest();

  char serial[10] = {0};
  {
    uint32_t x = dest;
    char hex[] = "0123456789abcdef";
    for(int i = 0; i < 8; i++) {
      serial[7-i] = hex[x & 0xF];
      x = x >> 4;
    }
  }
  
  /* Buffer to be used for control requests. */
  uint8_t usbd_control_buffer[128];
  char const *usb_strings[] = {
    "uf-mil",
    "subbus",
    serial,
  };
  usbd_device * usbd_dev = usbd_init(&stm32f103_usb_driver, &uf_subbus_protocol::usb::dev, &uf_subbus_protocol::usb::config, usb_strings, 3, usbd_control_buffer, sizeof(usbd_control_buffer));
  usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);

  uf_subbus_protocol::usb::Sink sink(usbd_dev);

  arm_bootloader::Handler handler(
    sink,
    dest,
    2048);
  handlerp = &handler;

  while (1)
    usbd_poll(usbd_dev);
}
int main(void)
{
	usbd_device *usbd_dev;

	usb_simple_target_init();

	usbd_dev = usbd_init(usb_simple_target_usb_driver(), NULL, &info);

	usbd_register_setup_callback(usbd_dev, simple_setup_callback);

	while (1) {
		usbd_poll(usbd_dev, 0);
	}

	return 0;
}
示例#5
0
int main(void)
{
	rcc_clock_setup_pll(&this_clock_config);
	/* LED on custom board for boot progress */
	rcc_periph_clock_enable(RCC_GPIOB);
	gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO1);
	gpio_set(GPIOB, GPIO1);

	usbd_device *usbd_dev = gadget0_init(&st_usbfs_v1_usb_driver, "stm32l1-generic");

	ER_DPRINTF("bootup complete\n");
	gpio_clear(GPIOB, GPIO1);
	while (1) {
		usbd_poll(usbd_dev);
	}

}
示例#6
0
int main(void)
{
	rcc_clock_setup_in_hse_8mhz_out_72mhz();

	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);

	/* LED output */
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, 
			GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);

	usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
	usbd_register_control_callback(
				USB_REQ_TYPE_VENDOR, 
				USB_REQ_TYPE_TYPE,
				simple_control_callback);

	while (1) 
		usbd_poll();
}
示例#7
0
int main(void)
{
	rcc_clock_setup_in_hsi48_out_48mhz();
	crs_autotrim_usb_enable();
	rcc_set_usbclk_source(HSI48);

	/* LED on for boot progress */
	rcc_periph_clock_enable(RCC_GPIOC);
	gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO7);
	gpio_set(GPIOC, GPIO7);

	usbd_device *usbd_dev = gadget0_init(&st_usbfs_v2_usb_driver, "stm32f072disco");

	ER_DPRINTF("bootup complete\n");
	gpio_clear(GPIOC, GPIO7);
	while (1) {
		usbd_poll(usbd_dev);
	}

}
static int usb_fibre(fibre_t *fibre)
{
	PT_BEGIN_FIBRE(fibre);

	rcc_periph_clock_enable(RCC_OTGFS);

	gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
			GPIO9 | GPIO11 | GPIO12);
	gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);

	usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config,
			usb_strings, 2,
			usbd_control_buffer, sizeof(usbd_control_buffer));
	usbd_register_set_config_callback(usbd_dev, usb_set_config);

	while (true) {
		usbd_poll(usbd_dev);
		PT_YIELD();
	}

	PT_END();
}
示例#9
0
int main(void)
{
	rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_120MHZ]);

	rcc_periph_clock_enable(RCC_GPIOB);
	rcc_periph_clock_enable(RCC_OTGHS);

	gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE,
			GPIO13 | GPIO14 | GPIO15);
	gpio_set_af(GPIOB, GPIO_AF12, GPIO13 | GPIO14 | GPIO15);

	msc_dev = usbd_init(&otghs_usb_driver, &dev_descr, &config_descr,
			    usb_strings, 3,
			    usbd_control_buffer, sizeof(usbd_control_buffer));

	ramdisk_init();
	usb_msc_init(msc_dev, 0x82, 64, 0x01, 64, "VendorID", "ProductID",
		"0.00", ramdisk_blocks(), ramdisk_read, ramdisk_write);

	for (;;) {
		usbd_poll(msc_dev);
	}
}
int main(void)
{
	rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
	rcc_periph_clock_enable(RCC_GPIOA);
	rcc_periph_clock_enable(RCC_OTGFS);

	gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
			GPIO9 | GPIO11 | GPIO12);
	gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);

	/* LEDS on discovery board */
	rcc_periph_clock_enable(RCC_GPIOD);
	gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
			GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);

	usbd_device *usbd_dev = gadget0_init(&otgfs_usb_driver, "stm32f4disco");

	ER_DPRINTF("bootup complete\n");
	while (1) {
		usbd_poll(usbd_dev);
	}

}
示例#11
0
int main(void)
{
	usbd_device *usbd_dev;

	rcc_clock_setup_in_hse_25mhz_out_72mhz();

	rcc_periph_clock_enable(RCC_GPIOA);
	rcc_periph_clock_enable(RCC_GPIOC);
	rcc_periph_clock_enable(RCC_OTGFS);

	/* LED output */
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
		      GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);

	usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings, 3, usbd_control_buffer, sizeof(usbd_control_buffer));
	usbd_register_control_callback(
				usbd_dev,
				USB_REQ_TYPE_VENDOR,
				USB_REQ_TYPE_TYPE,
				simple_control_callback);

	while (1)
		usbd_poll(usbd_dev);
}
示例#12
0
int main(){
	uint32_t Old_timer = 0;

	// RCC clocking: 8MHz oscillator -> 72MHz system
	rcc_clock_setup_in_hse_8mhz_out_72mhz();

	GPIO_init();

	usb_disconnect(); // turn off USB while initializing all
	steppers_init();

	// USB
	usbd_dev = USB_init();

	// SysTick is a system timer with 1ms period
	SysTick_init();

	// wait a little and then turn on USB pullup
//	for (i = 0; i < 0x800000; i++)
//		__asm__("nop");

	usb_connect(); // turn on USB

	while(1){
		usbd_poll(usbd_dev);
		if(usbdatalen){ // there's something in USB buffer
			usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
		}
		//check_and_parce_UART(USART1); // also check data in UART buffers
		if(Timer - Old_timer > 999){ // one-second cycle
			Old_timer += 1000;
		}else if(Timer < Old_timer){ // Timer overflow
			Old_timer = 0;
		}
	}
}
示例#13
0
/**
 * SysTick interrupt: increment global time & send data buffer through USB
 */
void sys_tick_handler(){
	Timer++;
	usbd_poll(usbd_dev);
	usb_send_buffer();
}
示例#14
0
int main(){
	//int i;
	uint32_t Shtr_blink_timer = 0, Old_timer = 0, lastTRDread = 0, lastTmon = 0, OW_timer = 0;
	int oldusbdatalen = 0;
	//SPI_read_status SPI_stat;

	// RCC clocking: 8MHz oscillator -> 72MHz system
	rcc_clock_setup_in_hse_8mhz_out_72mhz();

	// turn off SWJ/JTAG
	AFIO_MAPR = AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF;

	// GPIO
	GPIO_init();
	usb_disconnect(); // turn off USB while initializing all

	// init USART3 (master) & USART1 (slave)
	UART_init(USART3);
	UART_init(USART1);

	// USB
	usbd_dev = USB_init();

	// SysTick is a system timer with 1mc period
	SysTick_init();

	// instead of SPI1 we use those pins to control shutter and system state
	// SPI2 used for working with external ADC
	switch_SPI(SPI2); // init SPI2
	SPI_init();

	// wait a little and then turn on USB pullup
//	for (i = 0; i < 0x800000; i++)
//		__asm__("nop");

	// init ADC
	ADC_init();
	ADC_calibrate_and_start();

	steppers_init();

	usb_connect(); // turn on USB
	shutter_init();

	read_stored_data(); // copy stored data into RAM

	init_ow_dmatimer();
	//OW_send_read_seq();

	LED_STATUS_OK(); // All initialized - light up LED
	while(1){
		init_on_poweron_proc();
		usbd_poll(usbd_dev);
		if(oldusbdatalen != usbdatalen){ // there's something in USB buffer
			usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen, usb_send);
			oldusbdatalen = usbdatalen;
		}
		check_and_parce_UART(USART3); // check data in master UART buffers
		check_and_parce_UART(USART1); // also check data in slave UART buffers
		if(ad7794_on){
			if(Timer != lastTRDread){ // run this not more than once in 1ms
				lastTRDread = Timer;
				read_next_TRD();
			}
		}
		OW_process(); // process 1-wire commands
		// scan 1-wire each 1 second
		if(OW_scan && (Timer - OW_timer > 999 || Timer < OW_timer)){
			OW_timer = Timer;
			scan_onewire();
		}
		process_stepper_motors(); // check flags of motors' timers
		process_shutter(); // shutter state machine

		if(Timer - Shtr_blink_timer > 500 ||  Timer < Shtr_blink_timer){
			Shtr_blink_timer = Timer;
			// shutter LED will be blinking until init occurs
			if(Shutter_State == SHUTTER_NOTREADY)
				gpio_toggle(LED_SHUTTER_PORT, LED_SHUTTER_PIN);
		}

		if(Timer - Old_timer > 999){ // one-second cycle
			Old_timer += 1000;
			// init shutter if error occurs
			if(Shutter_State == SHUTTER_NOTREADY){
				shutter_init();
			}
		}else if(Timer < Old_timer){ // Timer overflow
			Old_timer = 0;
			tOVRFL++; // this is an overflow counter - for workinkg in long-long time interval
		}

		if((Timer - lastTmon > 9999) || (Timer < lastTmon)){ // run constant monitoring of ADC values each 10 seconds
			lastTmon += 10000;
			if(ADC_monitoring){
				print_time(lastsendfun);
				print_int_ad_vals(lastsendfun);
				print_ad_vals(lastsendfun);
			}
		}
	}
}
示例#15
0
文件: usb.c 项目: entropia/usblockd
void usb_poll(void) {
	usbd_poll(usbd_dev);
}
示例#16
0
void USB_ISR(void)
{
	usbd_poll(tmc_dev);
}
示例#17
0
void usbmanager_poll(void) {
    usbd_poll(usbd_dev);
    msc_stateMachine(usbd_dev);
}
示例#18
0
文件: DAP42.c 项目: edwardcwang/dap42
int main(void) {
    if (DFU_AVAILABLE) {
        DFU_maybe_jump_to_bootloader();
    }

    clock_setup();
    tick_setup(1000);
    gpio_setup();
    led_num(0);

    if (CDC_AVAILABLE) {
        console_setup(DEFAULT_BAUDRATE);
    }

    if (SEMIHOSTING) {
        initialise_monitor_handles();
    }
    else if (VCDC_AVAILABLE) {
        retarget(STDOUT_FILENO, VIRTUAL_USART);
        retarget(STDERR_FILENO, VIRTUAL_USART);
    } else if (CDC_AVAILABLE) {
        retarget(STDOUT_FILENO, CONSOLE_USART);
        retarget(STDERR_FILENO, CONSOLE_USART);
    }
    
    led_num(1);

    {
        char serial[USB_SERIAL_NUM_LENGTH+1];
        desig_get_unique_id_as_string(serial, USB_SERIAL_NUM_LENGTH+1);
        cmp_set_usb_serial_number(serial);
    }

    usbd_device* usbd_dev = cmp_usb_setup();
    DAP_app_setup(usbd_dev, &on_dfu_request);

    if (CDC_AVAILABLE) {
        cdc_uart_app_setup(usbd_dev, &on_usb_activity, &on_usb_activity);
    }

    if (VCDC_AVAILABLE) {
        vcdc_app_setup(usbd_dev, &on_usb_activity, &on_usb_activity);
    }

    if (DFU_AVAILABLE) {
        dfu_setup(usbd_dev, &on_dfu_request);
    }

    tick_start();

    /* Enable the watchdog to enable DFU recovery from bad firmware images */
    iwdg_set_period_ms(1000);
    iwdg_start();

    while (1) {
        iwdg_reset();
        usbd_poll(usbd_dev);

        if (CDC_AVAILABLE) {
            cdc_uart_app_update();
        }

        if (VCDC_AVAILABLE) {
            vcdc_app_update();
        }

        // Handle DAP
        bool dap_active = DAP_app_update();
        if (dap_active) {
            usb_timer = 1000;
        } else if (do_reset_to_dfu && DFU_AVAILABLE) {
            /* Blink 3 times to indicate reset */
            int x;
            for (x=0; x < 3; x++) {
                iwdg_reset();
                led_num(7);
                wait_ms(150);
                led_num(0);
                wait_ms(150);
                iwdg_reset();
            }

            DFU_reset_and_jump_to_bootloader();
        }

        if (usb_timer > 0) {
            usb_timer--;
            LED_ACTIVITY_OUT(1);
        } else {
            LED_ACTIVITY_OUT(0);
        }
    }

    return 0;
}
示例#19
0
文件: main.c 项目: SickSad/DeltaRobot
int main(void)
{
	setup();
	
	char response_buffer[128];

	bool resend = false;

	GCODE_STATE previous_command; //stores the previous gcode command
    GCODE_STATE current_command; //stores the next gcode command
    init_gcode_state(&previous_command);
    init_gcode_state(&current_command);

	KINEMATIC_STATE current;
	KINEMATIC_STATE goal;
	init_kinematic_state(&current);
	init_kinematic_state(&goal);

	test_extuder(4000,4000);	
	calibrate(6000,3000);
	
	while (1){
		//should echo back any string sent to board over serial
		usbd_poll(usbd_dev);
		if(strlen(usb_buf) > 0){

			//if it's a re-sent command we don't want to overwrite the previous
			//command with something broken
			if (resend == false){
				previous_command = current_command;
			}else{
				//clear the resend
				resend = false;
			}

			current_command = parse_gcode(usb_buf);
			clear_USB_buffer();			
			current_command.x_offset = previous_command.x_offset;
			current_command.y_offset = previous_command.y_offset;
			current_command.z_offset = previous_command.z_offset;
			current_command.extrude_offset = previous_command.extrude_offset;
			//current_command.feed_rate = previous_command.feed_rate;

			//Handle checksums
			if(current_command.checksum_set){
				if (current_command.checksum != current_command.calculated_checksum){
					//if things get buggered, send a resend command
					sprintf(response_buffer, "rs %i\n", current_command.line_number);
					write_serial(response_buffer);
                    resend = true;
                    continue;
                }
			}

			//Handle GCommands
			if (current_command.g_command_set){
				//G0 Rapid move
				//G1 Controlled move
				if (current_command.g_command == 0.0f || current_command.g_command == 1.0f){
					if (current_command.x_set) goal.x = current_command.x + current_command.x_offset;
					if (current_command.y_set) goal.y = current_command.y + current_command.y_offset;
					//remember - z is inverted
					if (current_command.z_set) goal.z = (-current_command.z) + current_command.z_offset;
					if (current_command.extrude_length_set) goal.extrude_length = current_command.extrude_length + current_command.extrude_offset;

					if(current_command.feed_rate_set){
						goal.feed_rate = current_command.feed_rate;
					}else{
						//current_command.feed_rate = previous_command.feed_rate;
						//goal.feed_rate = current_command.feed_rate;
					}
					current = line_generator(current, goal, step_motors);
				}
				//G92 Set Position (without move)
				if (current_command.g_command == 92.0f){
					if (current_command.x_set){
						current_command.x_offset = current.x - current_command.x;
					}
					if (current_command.y_set){
						current_command.y_offset = current.y - current_command.y;
					}
					if (current_command.z_set){
						//remember - z is inverted
						current_command.z_offset = current.z - (-current_command.z);
					}
					if (current_command.extrude_length_set){
						current_command.extrude_offset = current.extrude_length - current_command.extrude_length;
					}
				}
			}
			
			if (current_command.m_command_set){
				//TODO: Sort the spindle code out so that it can be rotated in both directions
				//for now it is only used to control an acuator which is off or on.
				//M3 Spindle ON clockwise
				if (current_command.m_command == 3.0f){
					set_spindle(true);
				}
				//M4 Spindle ON counter-clockwise
				if (current_command.m_command == 3.0f){
					set_spindle(true);
				}
				//M5 Spindle OFF
				if (current_command.m_command == 5.0f){
					set_spindle(false);
					
				}
				//M105 get extruder temperature
				if (current_command.m_command == 105.0f){
					sprintf(response_buffer, "ok\n T:%d", read_adc());
					write_serial_string(response_buffer);
					continue;
				}
			}

			//DO NOT PUT CODE BELOW THIS POINT UNLESS THE "continue"'s in the above code
			//are taken care of or not important.

			//use the repsponse buffer because fuckit
			sprintf(response_buffer, "ok\n");
			write_serial_string(response_buffer);
		}
	}
}
示例#20
0
void otg_fs_isr(void)
{
  usbd_poll(usbdev);
}