cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072-Discovery Virtual Com Problem

cravaour
Associate II
Posted on December 25, 2015 at 19:48

Hi, I've been struggling to make a working program, that would allow my board to communicate with the computer. So far I reviewed a lot of examples but I still have problems to do so. I managed to connect the device, it is recognised as Virtual COM and I successfully connected through a terminal. However, I am unable to send anything. I tried using the function:

static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)
{
uint32_t i = 0;
//
while(i < Len)
{ //
APP_Rx_Buffer[APP_Rx_ptr_in] = *(Buf + i);
APP_Rx_ptr_in++;
i++;
/* To avoid buffer overflow */
if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
{
APP_Rx_ptr_in = 0;
}
}
return USBD_OK;

Along with:

void VCP_send_str(uint8_t* buf)
{
uint32_t i = 0;
//
while(*(buf + i))
{
i++;
}
VCP_DataTx(buf, i);
}

Now what I understand is I have to pass a buffor to the VCP_send_str and I do that this way in my main:

int main(void)
{
uint8_t Buffer[8];
int counter=0;
Buffer[0] = 't';
Buffer[1] = 'e';
Buffer[2] = 's';
Buffer[3] = 't';
Buffer[4] = 'i';
Buffer[5] = 'n';
Buffer[6] = 'g';
Buffer[7] = '.';
USBD_Init(&USB_Device_dev,
&USR_desc, 
&USBD_CDC_cb,
&USR_cb);
while (1)
{
if (counter>=1000){
counter=0;
}
if (counter%100==0){
VCP_send_str(Buffer);
}
counter++;
}
}

I can provide more code if needed, any help would be appreciated. #stm32-virtual-com-discovery
1 REPLY 1
Posted on December 26, 2015 at 00:53

I'm not sure the string stuff is helping here, you have a fixed length structure that consumes all it's own space, and lacks NUL termination. Just start by sending the 8 byte block directly, rather than as a length determined string.

Not really using Cortex-M0 parts here, but you might want to double check the USB/USART IRQ Handlers, and perhaps instrument the USB implementation to see what interactions are occurring. Debugging with break-points tends to be counter-productive with the real-time requirements of USB, and the M0 lacks the SWV channel.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..