예제 #1
0
void VCP_put_string(char* string)
 {
 	 while(*string)
 	 {
 		VCP_put_char(*string++);
 	 }
 }
예제 #2
0
파일: main.c 프로젝트: glocklueng/STMHero
void TIM3_IRQHandler(void)
{
         	if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
         	{
         		A = !GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_0) * 0xFF;
         		S = !GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_1) * 0xFF;
         		D = !GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_2) * 0xFF;
         		F = !GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) * 0xFF;

         		if(VCP_get_char(&theByte))
         		{
         			if(theByte == 'H')
         			{
         				if(recieved)
         				{
         					VCP_put_char('I');
         					connected = true;
         					recieved = false;
         				}else
         				{
         					VCP_put_char('I');
         					recieved = true;
         				}

         			}else if (theByte == 'B')
         			{
						if(recieved)
						{
							VCP_put_char('Y');
		         			connected = false;
		         			recieved = false;
						}else
						{
							VCP_put_char('Y');
         					recieved = true;

						}
					}
         		}

         		if(connected)
				{
					VCP_put_char(0x38);
					VCP_put_char(A);
					VCP_put_char(S);
					VCP_put_char(D);
					VCP_put_char(F);
				}
                // wyzerowanie flagi wyzwolonego przerwania
                TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
         	}
}
예제 #3
0
파일: main.c 프로젝트: lbru/stm32
// this is the interrupt request handler (IRQ) for ALL USART1 interrupts
void USART1_IRQHandler(void){

  // check if the USART1 receive interrupt flag was set
  if( USART_GetITStatus(USART1, USART_IT_RXNE) ){

    char t = USART1->DR; // the character from the USART1 data register is saved in t
    VCP_put_char(t);
  }
}
예제 #4
0
int _read(int file, char *ptr, int len) {
	if (file != 0) {
		return 0;
	}

	// Use USB CDC Port for stdin
	while(!VCP_get_char((uint8_t*)ptr)){};

	// Echo typed characters
	VCP_put_char((uint8_t)*ptr);

	return 1;
}
예제 #5
0
/**
 * @brief Send multiple chars (uint8_t) over a comm channel
 *
 * @param chan MAVLink channel to use
 * @param ch Character to send
 */
void mavlink_send_uart_bytes(mavlink_channel_t chan, uint8_t * ch, uint16_t length)
{
	if (chan == MAVLINK_COMM_0)
	{
		/* send to UART3 */
		usart3_tx_ringbuffer_push(ch, length);
	}
	if (chan == MAVLINK_COMM_2)
	{
		/* send to USB serial port */
		for (int i = 0; i < length; i++)
		{
			VCP_put_char(ch[i]);
		}
	}
}
예제 #6
0
파일: car_conn.c 프로젝트: olonho/carkot
void car_conn_snd_byte(uint8_t b)
{
    VCP_put_char(b);
}
예제 #7
0
파일: main.c 프로젝트: PUT-PTM/STMDoodle
int main(void)
{
	uint8_t acc_x, acc_y, acc_z;
	tickerSendData = 0;

	LIS302DL_InitTypeDef  LIS302DL_InitStruct;
	       /* Set configuration of LIS302DL*/
	       LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
	       LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100;
	       LIS302DL_InitStruct.Axes_Enable = LIS302DL_X_ENABLE | LIS302DL_Y_ENABLE | LIS302DL_Z_ENABLE;
	       LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3;
	       LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
	       LIS302DL_Init(&LIS302DL_InitStruct);

	       GPIO_InitTypeDef GPIO_InitStructure;
	       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	       GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	       GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
	       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

	       /* SPI SCK pin configuration */
	       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
	       GPIO_Init(GPIOB, &GPIO_InitStructure);

	       /* SPI MOSI pin configuration */
	       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
	       GPIO_Init(GPIOB, &GPIO_InitStructure);

	       /* SPI MISO pin configuration */
	       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
	       GPIO_Init(GPIOB, &GPIO_InitStructure);


	/* Set up the system clocks */
	SystemInit();

	/* Initialize USB, IO, SysTick, and all those other things you do in the morning */
	init();


	while (1)
	{
		LIS302DL_Read(&acc_x, LIS302DL_OUT_X_ADDR, 1);
		LIS302DL_Read(&acc_y, LIS302DL_OUT_Y_ADDR, 1);
		LIS302DL_Read(&acc_z, LIS302DL_OUT_Z_ADDR, 1);

		if ((tickerSendData) >= 50){

			tickerSendData=0;
			VCP_put_char(acc_x);

		}

		/* Blink the orange LED at 1Hz */
		if (500 == ticker)
		{
			GPIOD->BSRRH = GPIO_Pin_13;
		}
		else if (1000 == ticker)
		{
			ticker = 0;
			GPIOD->BSRRL = GPIO_Pin_13;

		}


		/* If there's data on the virtual serial port:
		 *  - Echo it back
		 *  - Turn the green LED on for 10ms
		 */
		uint8_t theByte;
		if (VCP_get_char(&theByte))
		{



			GPIOD->BSRRL = GPIO_Pin_12;
			downTicker = 10;
		}
		if (0 == downTicker)
		{
			GPIOD->BSRRH = GPIO_Pin_12;
		}
	}

	return 0;
}
예제 #8
0
void vTaskVCP(void *pvParameters)
{
	static u32 address = 0;
	static uint8_t usb_inited = 0;
	uint8_t c;
	int arg;
	uint8_t tmpbuf[EERROM_SIZE];
	
	for(;;)
	{
	    //Give the change to the OS scheduling. It is really a fool idea. Change me!
	    //TODO - should use semaphore
	    vTaskDelay( 1 / portTICK_RATE_MS );
//		xSemaphoreTake(onVCPSemaphore, portMAX_DELAY);

		if(usb_inited == 0)
		{
		    GPIO_InitTypeDef  gpio;
            //This is a trick to perform a USB re-enumerate
            gpio.GPIO_Pin = GPIO_Pin_12;
            gpio.GPIO_Speed = GPIO_Speed_100MHz;
            gpio.GPIO_Mode = GPIO_Mode_OUT;
            gpio.GPIO_OType = GPIO_OType_PP;
            gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
            GPIO_Init(GPIOB, &gpio);
            GPIO_SetBits(GPIOB, GPIO_Pin_12 );
            vTaskDelay(500 / portTICK_RATE_MS);
            GPIO_ResetBits(GPIOB, GPIO_Pin_12 );

            // Initialize USB VCP. Do it ASAP
            USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb,
                    &USR_cb);
            usb_inited = 1;
		}

		if (VCP_get_char(&c))
		{
			switch(c) {
				case PROTO_GET_SYNC:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					break;
				case PROTO_GET_DEVICE:
					arg = cin_wait(usb_vcp_timeout);
					if (arg < 0)
						goto cmd_bad;
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					
					switch (arg) {
						case PROTO_DEVICE_BL_REV:
						    VCP_send_str((uint8_t*)&bl_proto_rev);
							break;
						default:
							goto cmd_bad;
					}
			
					break;
				case PROTO_START_TRANS:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					address = 0;
					memset(tmpbuf,0,EERROM_SIZE);
					break;
				case PROTO_SET_PARAMS:
					arg = cin_wait(usb_vcp_timeout);
					if (arg < 0)
						goto cmd_bad;

					// sanity-check arguments
					if (arg % 4)
						goto cmd_bad;
					if ((address + arg) > EERROM_SIZE)
						goto cmd_bad;
					for (int i = 0; i < arg; i++) 
					{
						c = cin_wait(usb_vcp_timeout);
						if (c < 0)
							goto cmd_bad;
						
						tmpbuf[address++] = c;
					}
					
					break;
				case PROTO_END_TRANS:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					
					//ensure we receive right size
					if(address == EERROM_SIZE)
					{
						memcpy(eeprom_buffer.c,tmpbuf,EERROM_SIZE); 
//						bool ret = StoreParams();
//						if(!ret)
//						{
//							//TODO - handle flash write error here
//						}
					}
					break;
				case PROTO_SAVE_TO_FLASH:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					
					//ensure we receive right size
					if(address == EERROM_SIZE)
					{
						bool ret = StoreParams();
						if(!ret)
						{
							//TODO - handle flash write error here
						}
					}
					break;	
				case PROTO_GET_PARAMS:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					for (int i = 0; i < EERROM_SIZE; i++)
					{
					    VCP_put_char(eeprom_buffer.c[i]);
						//TM_USB_VCP_Putc(testbuf[i]);
						//vTaskDelay( 1 / portTICK_RATE_MS );
					}
					
					break;
				case PROTO_BL_UPLOAD:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;

					sync_response();
					vTaskDelay( 200 / portTICK_RATE_MS );
					
					GPIO_SetBits(GPIOB,GPIO_Pin_12);
					vTaskDelay( 500 / portTICK_RATE_MS );
					GPIO_ResetBits(GPIOB,GPIO_Pin_12);
					
					__DSB();  /* Ensure all outstanding memory accesses included
                                buffered write are completed before reset */
					SCB->AIRCR  = ((0x5FA << SCB_AIRCR_VECTKEY_Pos)      |
								 (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
								 SCB_AIRCR_SYSRESETREQ_Msk);                   /* Keep priority group unchanged */
					__DSB();                                                     /* Ensure completion of memory access */
					
					while(1);  
					break;
				default:
					continue;
							
			}
			
			// send the sync response for this command
			sync_response();
			continue;
		}
		
		vTaskDelay( 10 / portTICK_RATE_MS );
		continue;
cmd_bad:
		// send an 'invalid' response but don't kill the timeout - could be garbage
		invalid_response();
		continue;

cmd_fail:
		// send a 'command failed' response but don't kill the timeout - could be garbage
		failure_response();
		continue;		
	}
}
예제 #9
0
/******************************************************************************
*	タイトル : microUSBの一文字送信
*	  関数名 : usb_put_char
*	  戻り値 : void型 
*	   引数1 : char型 c  送信する文字
*	  作成者 : 桐生
*	  作成日 : 2014/11/14
******************************************************************************/
void usb_put_char(char c){
	VCP_put_char((uint8_t)c);
}