Exemplo n.º 1
0
int usb_write(uint8_t *buf, unsigned int nbytes)
{
    U16 tosend = nbytes;
	U16 sent = 0;
	U8 *buffer8 = (U8 *)buf;
	int bytesput;
	
	if (usb_ready == 0)
	{
		return 0;
	}
		
	sent = 0;

	//if (!txfifo)
	//    {
	//	return 0;
	//    }

	//char *str = (char *)buf;
	//usart_putstr(_USART1, str);
	// blocking mode
	while(tosend)
	{					
		bytesput = VCP_DataTx(buffer8,nbytes);
		tosend -= bytesput;
		buffer8 += bytesput;
		sent += bytesput;
	}
	return sent;
}
int main(void)
{
  //Initial Set-up of: SPI, USB, TIM2, and ADC
  SysInit();
  LMP_SPI_Init();                       
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  InitTIM2();
  startUSBOTG();
  ADC3_CH2_DMA_Config();
  TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
  TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);
  
  ADC_DMACmd(ADC3, ENABLE);
  //Main Loop: Transmit ADC result to PC
  while (1)
  {
    //Convert array elements in 1000 element array to 8 bit words and store in 
    //2000 element array
    for (int i=0; i<2000; i++)
      {
        if (i%2 == 0) adc3ch2_16bit[i] = (adc3ch2[i/2] >> 8);
        else adc3ch2_16bit[i] = (adc3ch2[i/2]);
      }
   //Output 2000 element array of ADC results over USB VCP Data line   
   for (int i=0; i < 2000; i++) VCP_DataTx (&adc3ch2_16bit[i],0);
  }
TM_USB_VCP_Result TM_USB_VCP_Send(uint8_t* DataArray, uint32_t Length) {
	/* Send array */
	VCP_DataTx(DataArray, Length);
	
	/* Return OK */
	return TM_USB_VCP_OK;
}
int main(void)
{
  //Initial Set-up of: SPI, USB, TIM2, and ADC
  SysInit();
  SysTickInit();
  LMP_SPI_Init();                       
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  InitTIM2();
  startUSBOTG();
  ADC1_Config();
  TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
  TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);

  //Main Loop: Transmit ADC result to PC
  while (1)
  {
  //Read in from DMA buffer to output array
     while(!ADCBuffer[399]); //Wait until last element of buffer is non-zero(testing)
    for(int i = 0; i<400; i++) adc_16[i] = ADCBuffer[i];
    //Convert 16b array elements in 4000 element array to 8 bit words and store in 
    //8000 element array
   
    for (int i=0; i<800; i++)
      {
        if (i%2 == 0) adc_8[i] = (adc_16[i/2] >> 8);
        else adc_8[i] = (adc_16[i/2]);
      }

   //Output 2000 element array of ADC results over USB VCP Data line   
    APP_Rx_ptr_out = 0;
      APP_Rx_length = 0;
      APP_Rx_ptr_in = 0;
  //for (int i=0; i < 8; i++) VCP_DataTx(&adc_8[i], 1);
     VCP_DataTx(&adc_8[55], 1);
  }
Exemplo n.º 5
0
void 		Comm_SendOutMsg(const OutputMsg* msg)
{
	char 			outBuf[2*sizeof(OutputMsg)+3];
	uint16_t 	len;

	Comm_OutMsgToStr(msg, outBuf, &len);
	VCP_DataTx((uint8_t*)outBuf, len);
}
Exemplo n.º 6
0
/*******************************************************************************
 * Function Name  : Send DATA .
 * Description    : send the data received from the STM32 to the PC through USB
 * Input          : None.
 * Output         : None.
 * Return         : None.
 *******************************************************************************/
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength)
{
    if (USB_Tx_State) 
        return 0;

    VCP_DataTx(ptrBuffer, sendLength);
    return sendLength;
}
Exemplo n.º 7
0
TM_USB_VCP_Result TM_USB_VCP_Putc(volatile char c) {
	uint8_t ce = (uint8_t)c;
	/* Send data over USB */
	VCP_DataTx(&ce, 1);
	
	/* Return OK */
	return TM_USB_VCP_OK;
}
Exemplo n.º 8
0
/**
  * @brief  Sends a string over the USB serial link.
  *
  * @param  buf pointer to char array
  * @retval none
  */
void VCP_send_str(uint8_t* buf)
{
	uint32_t i=0;
	while(*(buf + i))
	{
		i++;
	}
	VCP_DataTx(buf, i);
}
Exemplo n.º 9
0
void DISCOVERY_COM_IRQHandler(void)
{
   GPIO_ToggleBits(LED_BLUE_GPIO_PORT, LED_BLUE_PIN);

   // Send the received data to the PC Host
   if (USART_GetITStatus(DISCOVERY_COM, USART_IT_RXNE) != RESET) 
     VCP_DataTx(0,0);    //Copies RS232 data to USB

   /* If overrun condition occurs, clear the ORE flag and recover communication */
   if (USART_GetFlagStatus(DISCOVERY_COM, USART_FLAG_ORE) != RESET)
      USART_ReceiveData(DISCOVERY_COM);
}
Exemplo n.º 10
0
/**
  * @brief  EVAL_COM_IRQHandler
  * @param  None.
  * @retval None.
  */
void EVAL_COM_IRQHandler(void)
{
    if (USART_GetITStatus(EVAL_COM1, USART_IT_RXNE) != RESET)
    {
        /* Send the received data to the PC Host*/
        VCP_DataTx (0,0);
    }

    /* If overrun condition occurs, clear the ORE flag and recover communication */
    if (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_ORE) != RESET)
    {
        (void)USART_ReceiveData(EVAL_COM1);
    }
}
Exemplo n.º 11
0
void shellReadChar(uint8_t ch)
{
    shellCmd_t* cmd;

    if (ch == '\n' || ch == '\r') {
        if (shellBufCnt != 0) {
            shellBuf[shellBufCnt++] = ch;
            cmd = shellFindCmd(shellBuf);
            shellPrintCR();
            if (cmd != NULL){
                cmd->cmdFunc(&(shellBuf[strlen(cmd->name)]));
            } else {
                printf("Unknown command\r\n");
            }
        }
        shellBufCnt = 0;
        shellPrintCR();
        shellPrintPrompt();
    } else if (ch == KEY_BACKSPACE) {
        if (shellBufCnt > 0) {
            shellBuf[--shellBufCnt] = ' ';
            shellPrintPrompt();        
            VCP_DataTx (shellBuf, shellBufCnt + 1);
            shellPrintPrompt();        
            VCP_DataTx (shellBuf, shellBufCnt);
        }
        else {
            shellPrintR();        
            shellPrintPrompt();        
        }
    } else if (ch < 32 || ch > 126) {
        
    } else {
        shellBuf[shellBufCnt++] = ch;
        VCP_DataTx (&ch, 1);
    }
}
Exemplo n.º 12
0
uint32_t usbSendBytes(const uint8_t* sendBuf, uint32_t len) {
	VCP_DataTx((uint8_t*)sendBuf, len);
	return len;
}
Exemplo n.º 13
0
int main(void)
{
	#warning change clock hse_value to 25m	
	SYSTIM_Init();
	
	LEDInit(LED_ACT);
	LEDInit(LED_COM);
	LEDInit(LED_ERR);
	
	LEDOn(LED_ACT);
	LEDOff(LED_COM);
	LEDOff(LED_ERR);
	SYSTIM_DelayTms(1000);
	LEDOff(LED_ACT);	
	
//	USBD_Init(&USB_OTG_dev,
//				USB_OTG_FS_CORE_ID,
//				&USR_desc,
//				&USBD_CDC_cb,
//				&USR_cb);

	usart_init();
	UART_DMAInit();
	if (!CheckXCLK())
	{
		XCLK_ON();	
		SYSTIM_DelayTms(100);
	}
#ifdef USE_MT9V034
	MT9V034_Init();
#endif
#ifdef USE_MT9D111	
	MT9D111_Init();	
#endif	
	#warning already enable i2c when init camera
	//mpu6050_enable();	
	memset(Cam_Capture,'1',FULL_IMAGE_SIZE);	
	Cam_Capture[FULL_IMAGE_SIZE] = 's';
	Cam_Capture[FULL_IMAGE_SIZE + 1] = 't';	
	Cam_Capture[FULL_IMAGE_SIZE + 2] = 'p';	
	DCMI_CaptureCmd(ENABLE);	
	while(1)
	{
		int i=0;
#ifdef TEST_MPU6050
		bool res;
		res = I2C_ReadBytes(I2C2,data,MPU_ADDR, MPU_DATA, 14);
		if (!res)
		{
			LEDOn(LED_ERR);		
		}
		ax = (double)(data[1] + (data[0]<<8));
		ay = (double)(data[3] + (data[2]<<8));
		az = (double)(data[5] + (data[4]<<8));
		wx = (double)(data[9] + (data[8]<<8));
		wy = (double)(data[11] + (data[10]<<8));
		wz = (double)(data[13] + (data[12]<<8));					
		SYSTIM_DelayTms(100);
#endif		

		if (DCMI_Flag)
		{
			DCMI_Flag = 0;
			LEDToggle(LED_ACT);
//			SendImageDMA((uint32_t*)&Cam_Capture[0], FULL_IMAGE_SIZE);			
//			for (i=0;i<FULL_IMAGE_SIZE;i++)
//			{
//				Cam_Buffer[i] = Cam_Capture[i];
//			}
			VCP_DataTx(Cam_Capture,FULL_IMAGE_SIZE+3);
			SYSTIM_DelayTms(5000);
 			DCMI_CaptureCmd(ENABLE); 	
		}	
	}
}
Exemplo n.º 14
0
void usb_cdc_printf(char *s){
	VCP_DataTx((uint8_t*)s);
}
Exemplo n.º 15
0
/**
  * @brief  VCP_DataRx
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
  */
uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{
	
  uint32_t i;
	
	/* too much data in buffer - transmission error */
	if(Len > LONGEST_FRAME_SIZE) return USBD_OK;
	
	/* invalid data - transmission error */
	if(currentIndex == 0 && Buf[0] != START_BYTE)
	{
		currentIndex = 0;
		return USBD_OK;
	}
	
	/* check for discovery frame */
	if(Buf[0] == START_BYTE && Buf[1] == DISCOVERY_FRAME 
		&& Buf[DISCOVERY_FRAME_SIZE -3] == 0 && Buf[DISCOVERY_FRAME_SIZE -2] == 0 && Buf[DISCOVERY_FRAME_SIZE -1] == STOP_BYTE)
	{
		VCP_DataTx(Buf, 5);
		return USBD_OK;
	}
	
	/* check for conversion start stop command frame */
	if(Buf[0] == START_BYTE && Buf[1] == CONVERSION_FRAME && Buf[CONVERSION_FRAME_SIZE -1] == STOP_BYTE)
	{
		if(Buf[2] == Buf[4])
		{
			if(Buf[2] == Stop) 
			{
				devStatus = Idle;
				TIM_Cmd(TIM6, DISABLE); 
			}
			else if(Buf[2] == Start && deviceConfiguredFlag == 1) 
			{
				devStatus = Busy;
				TIM_Cmd(TIM6, ENABLE); 
			}
		}
	}
	
	/* check for config frame */
	if(Buf[0] == START_BYTE && Buf[1] == CONFIG_FRAME && Buf[CONFIG_FRAME_SIZE -1] == STOP_BYTE)
	{
				uint16_t mod = 0, mod2 = 0;
				for(i = 0; i < 8; i++)
				{
					mod += Buf[2 + i];
				}
				
				mod2 = (Buf[CONFIG_FRAME_SIZE -3] << 8);
				mod2 |= Buf[CONFIG_FRAME_SIZE -2];

				if(mod == mod2)
				{
					/* save settings */
					currentSettings.samplingFrequency = (SampligFrequency) 	Buf[2];
     			currentSettings.compressionType = 	(CompressionType) 	Buf[3];
					currentSettings.wordLenght =  			(WordLenght) 				Buf[4];
					currentSettings.signalSource = 			(SignalSource) 			Buf[5];
					currentSettings.signalOutput = 			(SignalOutput) 			Buf[6];
					currentSettings.bitError = 					(BitError) 					Buf[7];
					double temp = Buf[8];
					temp *= 10;
					temp += Buf[9];
					currentSettings.analogCompressionParam = temp/10.0f;
					configurationChangedFlag = 1;
					
					/* create and send response */
					Buf[2] = 0;
					Buf[3] = 0;
					Buf[4] = STOP_BYTE;
					VCP_DataTx(Buf, 5);
				}	
				return USBD_OK;
	}
  
  return USBD_OK;
}
Exemplo n.º 16
0
//------------------------------------------------------------------------------
Usb::Error UsbStm32f4xx::driverTx(const ByteArray& byteArray)
{
    VCP_DataTx(byteArray.getItems(), byteArray.getSize());

    return ERROR_NONE;
}
Exemplo n.º 17
0
/**
  * @brief  DISCOVERY_COM_IRQHandler
  *
  * @param  None.
  * @retval None.
  */
void DISCOVERY_EXTI_IRQHandler(void)
{
	/*SEND 'A' to PC via USB evry time User Button is pressd*/
	VCP_DataTx (0, (uint32_t) 'A');
}
Exemplo n.º 18
0
/*****************************************************************************
 * Name:
 *    usb_cdc_putc
 * In:
 *    s: char
 * Description:
 *    Print the specified string or char via USB
 *****************************************************************************/
void usb_cdc_putc(char *s){
	VCP_DataTx((uint8_t*)s);
}
Exemplo n.º 19
0
void VCP_SendBuf(unsigned char* buf, unsigned int length)  {
	VCP_DataTx(buf, length);
Exemplo n.º 20
0
/**
  * @brief  Sends one char over the USB serial link.
  *
  * @param  buf: char to be sent
  * @retval none
  */
void VCP_put_char(uint8_t buf)
{
	VCP_DataTx(&buf,1);
}
Exemplo n.º 21
0
void VCP_put_char_printf(void *p, uint8_t buf)
{
	VCP_DataTx(&buf,1);
}
Exemplo n.º 22
0
/*******************************************************************************
 * Function Name  : Send DATA .
 * Description    : send the data received from the STM32 to the PC through USB
 * Input          : buffer to send, and the length of the buffer.
 * Output         : None.
 * Return         : None.
 *******************************************************************************/
uint32_t CDC_Send_DATA(const uint8_t *ptrBuffer, uint32_t sendLength)
{
    VCP_DataTx(ptrBuffer, sendLength);
    return sendLength;
}
Exemplo n.º 23
0
//void DISCOVERY_EXTI_IRQHandler(void)
//{
//	VCP_DataTx (0, (uint32_t) 'A');
//}
void EXTI0_IRQHandler(void)//EXTI0_IRQn
{
	
	VCP_DataTx (0, (uint32_t) 'A');
	//STM_EVAL_LEDOn(LED6);
}