cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 USB VCP_Tx Problem

firat_deveci
Associate
Posted on March 10, 2015 at 12:19

Hello,

Today I'm working on STM32F072 USB. I want to use VCP for my project, I downloaded ''STM32F0x2_USB-FS-Device_Lib V1.0.0'' and I compiled ''Virtual_COM_Port'' demo. It worked perfectly on STM32F072 discovery board. But in my project I want to use this VCP and dont want to use physcal UART because I want to read some ADC values and send it to PC for example. I'm working on ''usbd_cdc_vcp.c'' file. I found ''VCP_DataTx(Buf,Length);'' this function send data to PC over USB. But in that file this function called in UART Interrupt. When i want to use in main.c or in other interrupt function USB communication stop and dont send anything. I can't understand why it's happening. I looked tens of examples but i didn't find a solution. I call my Timer3 with 100ms. I use same library with STM32F103 before. I used it like this and never got problem. Why is it acting like that? Thanks.

static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)
{
// if (linecoding.datatype == 7)
// {
// APP_Rx_Buffer[APP_Rx_ptr_in] = USART_ReceiveData(EVAL_COM1) & 0x7F;
// }
// else if (linecoding.datatype == 8)
// {
// APP_Rx_Buffer[APP_Rx_ptr_in] = USART_ReceiveData(EVAL_COM1);
// }
// 
// APP_Rx_ptr_in++;
// 
// /* To avoid buffer overflow */
// if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
// {
// APP_Rx_ptr_in = 0;
// } 
uint16_t i;
if(APP_RX_DATA_SIZE <= Len + APP_Rx_ptr_in) // rollback
{
for(i = APP_Rx_ptr_in; i < APP_RX_DATA_SIZE; i++)
{
APP_Rx_Buffer[i] = *Buf;
Buf++;
}
Len -= (APP_RX_DATA_SIZE - APP_Rx_ptr_in);
for(APP_Rx_ptr_in = 0; APP_Rx_ptr_in < Len; APP_Rx_ptr_in++)
{
APP_Rx_Buffer[APP_Rx_ptr_in] = *Buf;
Buf++;
}
APP_Rx_ptr_in=0;
}
else
{
for(i = 0; i < Len; i++)
{
APP_Rx_Buffer[APP_Rx_ptr_in++] = *Buf;
Buf++;
}
}
return USBD_OK;
}
/**
* @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 operation: USBD_OK if all operations are OK else VCP_FAIL
*/
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{
uint32_t i;
// for (i = 0; i < Len; i++)
// {
// USART_SendData(EVAL_COM1, *(Buf + i) );
// while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TXE) == RESET); 
// } 
return USBD_OK;
}
void VCP_Send_String(uint8_t* Buf, unsigned int Length)
{
VCP_DataTx(Buf,Length);
}
/**
* @brief EVAL_COM_IRQHandler
* @param None.
* @retval None.
*/
void EVAL_COM_IRQHandler(void)
{
if (USART_GetITStatus(EVAL_COM1, USART_IT_RXNE) != RESET)
{
USART_ReceiveData(EVAL_COM1);
/* Send the received data to the PC Host*/
VCP_Send_String (''SomeWords'',6);
}
/* 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);
}
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
//VCP_Send_String (''SomeWords'',6);
USART_SendData(EVAL_COM1, 'U' );
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

#problem #stm32f0 #usb
0 REPLIES 0