Exemplo n.º 1
0
/*********************************************************************************************
Function name   : VCP_GetStr
Author 					: Grant Phillips
Date Modified   : 10/04/2014
Compiler        : Keil ARM-MDK (uVision V4.70.0.0)

Description			: Waits for a string from the Virtual COM Port terminated by \n or \r

Special Note(s) : NONE

Parameters			: str			-	string (char array) to print

Return value		: NONE
*********************************************************************************************/
void VCP_GetStr(char str[])
{
	uint8_t i;
	uint8_t bufferIndex = 0;
	uint8_t lineFinished = 0;
	CDC_Receive_DATA();																		//start receiving data from Virtual COM Port

	//wait for the \n or \r terminating characters
	int k = 0;
	while(lineFinished == 0) {
		k = k + 1;
		if (Receive_length == 0) {
			continue;
		}
		for(i=0; i<Receive_length; i++) {
			str[bufferIndex++] = Receive_Buffer[i];
			if (str[bufferIndex-1]=='\r') {
				bufferIndex--;
			}
			if (str[bufferIndex-1]=='\n') {
				str[bufferIndex-1] = 0;
				lineFinished = 1;
			}
		}
		str[bufferIndex] = 0;
		Receive_length = 0;
		CDC_Receive_DATA();
	}
	
	str[bufferIndex] = '\0';
}
Exemplo n.º 2
0
/*******************************************************************************
* Function Name  : main.
* Descriptioan    : Main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{
    int i;

    /* Set the Vector Table base adress at 0x8004000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000);
    
    // Disable JTAG not the SWD  
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO , ENABLE);      
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);  
  
    Set_System();
    Set_USBClock();
    USB_Interrupts_Config();
    USB_Init();
    
    for(i = 0; i < 27; i++) TestBuffer[i] = i % 9;  
    
    while (1)
    {
        if (bDeviceState == CONFIGURED)
        {
            //CDC_Send_DATA ((unsigned char*)TestBuffer,27);
            //Delay(0xFFF);         
            CDC_Receive_DATA();
            // Check to see if we have data yet
            if (Receive_length  != 0)
            {
                if (packet_sent == 1)
                CDC_Send_DATA ((unsigned char*)Receive_Buffer,Receive_length);
                Receive_length = 0;
            }
        }
    }
} 
Exemplo n.º 3
0
void RadioStart()
{
	bool bTX = false;
  BoardInit( );

  GreenLedBlink();
	RedLedBlink();


  Radio = RadioDriverInit();
  Radio->Init();

  Radio->StartRx( );

	while(1)
	{
	  switch(Radio->Process())
    {
    case RF_RX_DONE:
				Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );
				if( BufferSize > 0 )
        {
					if (bDeviceState == CONFIGURED)
					{
						if (packet_sent == 1)
						{
							CDC_Send_DATA ((unsigned char*)Buffer,BufferSize);
						}
					}
				}

				GreenLedBlink();
				Radio->StartRx( );

				break;
    case RF_TX_DONE:
				RedLedBlink();
        Radio->StartRx( );
				bTX = false;
        break;
    default:
			if (bDeviceState == CONFIGURED)
			{
				if(bTX) break;
				if (Receive_length  != 0)
				{
					Radio->SetTxPacket( (unsigned char*)Receive_Buffer,Receive_length );
					CDC_Receive_DATA();
					Receive_length = 0;
					bTX = true;
				}
			}
			break;
    }
	}
}
Exemplo n.º 4
0
static uint8_t usbVcpRead(serialPort_t *instance)
{
    UNUSED(instance);

    uint8_t buf[1];

    while (true) {
        if (CDC_Receive_DATA(buf, 1))
            return buf[0];
    }
}
Exemplo n.º 5
0
uint8_t usbRead(serialPort_t *instance)
{
    uint8_t buf[1];

    uint32_t rxed = 0;

    while (rxed < 1) {
        rxed += CDC_Receive_DATA((uint8_t*)buf + rxed, 1 - rxed);
    }

    return buf[0];
}
Exemplo n.º 6
0
uint8_t cliRead(void)
{
    uint8_t buf[1];

    uint32_t rxed = 0;

    while (rxed < 1)
    {
        rxed += CDC_Receive_DATA((uint8_t*)buf + rxed, 1 - rxed);
    }

    return buf[0];
}
Exemplo n.º 7
0
uint8_t * CDC_Loopback(void) {
    if (bDeviceState == CONFIGURED) {
        CDC_Receive_DATA();
        if (USB_PacketReceived) {
            USB_PacketReceived = false;
            if (USB_ReceiveLength >= CDC_RX_BUFFER_SIZE) {
                // adjust for trailing string delimiter
                USB_ReceiveLength--;
            }
            USB_ReceiveBuffer[USB_ReceiveLength] = '\0';
            if (USB_PacketSent) {
                CDC_Send_DATA((unsigned char*) USB_ReceiveBuffer, USB_ReceiveLength);
            }
            return &USB_ReceiveBuffer[0];
        }
    }
    return NULL ;
}
Exemplo n.º 8
0
int _read(int file, __IO char *ptr, int len) {
  uint8_t rLen=0;
  uint8_t *temp;
  while(rLen<len)
  {
    while(!packet_receive);
    CDC_Receive_DATA();
    temp = Receive_Buffer;
    for(u8 i=0; i<Receive_length; i++)
    {
      *ptr = *temp;
      ptr++;
      temp++;
    }
    rLen += Receive_length;
    printf("%u %d %x\r\n", (unsigned int)Receive_length, len, *Receive_Buffer);
  }
  return len;
}
Exemplo n.º 9
0
/**
 * @brief Initialize the VCOM interface
 * @details Enables the USB device on the STM board and configures
 * it as a virtual COM port.
 */
void vcom_init() {
  Set_System();
  Set_USBClock();
  USB_Interrupts_Config();

  USB_Init();

  _ge_usb_timeout = 100;

  while ((bDeviceState != CONFIGURED) && (_ge_usb_timeout != 0))
  {}

  //initialize positions
  _vcom_buf_head = 0;
  _vcom_buf_tail = 0;
  _vcom_buf_corrupt = 0;

  //enable receive channel
  CDC_Receive_DATA();
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: leyjere/usb
/*******************************************************************************
* Function Name  : main.
* Descriptioan    : Main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{
  Set_System();
  Set_USBClock();
  USB_Interrupts_Config();
  USB_Init();
  
  while (1)
  {
    if (bDeviceState == CONFIGURED)
    {
      CDC_Receive_DATA();
      /*Check to see if we have data yet */
      if (Receive_length  != 0)
      {
        if (packet_sent == 1)
          CDC_Send_DATA ((unsigned char*)Receive_Buffer,Receive_length);
        Receive_length = 0;
      }
    }
  }
} 
Exemplo n.º 11
0
void usbIface::readBytes( void ) {
  CDC_Receive_DATA();
  for ( uint8_t i=0; i < Receive_length; i++ ) 
    m_in->enqueue( Receive_Buffer[i] ); // Not checking for errors
  Receive_length = 0;
}
Exemplo n.º 12
0
int main()
{
     __disable_irq();


    // ------------------------------------------------------------------ 
    // Desc: System Clk Config
    //
    //  HCLK = PCLK2 = SYSCLK = 72M 
    //  PCLK1 = 36M
    // ------------------------------------------------------------------ 
     SystemInit();
     // SysTick_Config(SystemCoreClock / 1000);

#if 0 
     // ------------------------------------------------------------------ 
     // Desc: CLK OUTPUT for measure
     // ------------------------------------------------------------------ 

     //PA8 alternate mode
     GPIO_InitTypeDef        GPIO_InitStructure;

     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
     GPIO_Init(GPIOA, &GPIO_InitStructure);

     GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_0);    

     RCC_MCOConfig(RCC_MCOSource_PLLCLK,RCC_MCOPrescaler_1);
     // while(1);
#endif


     // ------------------------------------------------------------------ 
     // Desc: Debug 
     // ------------------------------------------------------------------ 
     DebugInit();
     // d_printf("UART debug Init OK\r\n");

     // ------------------------------------------------------------------ 
     // Desc: ILX511 CLK ON
     // ------------------------------------------------------------------ 
#if 1
     {
         GPIO_InitTypeDef        GPIO_InitStructure;
         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
         GPIO_Init(GPIOB, &GPIO_InitStructure);
     }
#endif

#if 0
     ILX_Init();
     __enable_irq();
     ILX_CLKOn();
     delay_nms(50);//CCD power up

     ConvertOn();
#endif


#if 0

     d_printf("\r\n-------------------\r\n");
     {
         uint32_t i;
         for(i=32;i<2048+32;i++)
             d_printf("0x%04X ",data[i]);

     }
#endif


#if 0
    USBInit();
#endif

#if 0
    while (1)
    {
        if (bDeviceState == CONFIGURED)
        {
            CDC_Receive_DATA();
            if (Receive_length  != 0)
            {
                if (packet_sent == 1)
                    CDC_Send_DATA ((unsigned char*)Receive_Buffer,Receive_length);
                Receive_length = 0;
            }
        }
    }
#endif

     while(1);

    return 0;
}