cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152C6 USB-FS virtual COM port

kaloyan
Associate III
Posted on August 15, 2013 at 21:35

Hello. I am using the MCU with the USB-FS library. I ran the examples successfully and I can send and receive characters via PuTTY. I've also hardcoded several messages in the program, so I can debug it easily.

Now I'm trying to parse some of the sent strings, however I have strange problem. When the letters are send, I put them in cumulative array. Then with for loop I'm searching for space or \r symbol, so I can parse the first word (which I'll use later as a command send to the MCU). When the string doesn't match any of the commands, messache should be print (like commands are: cmd1 cmd2). However, in the PuTTY window I'm getting only emtpy spaces or new lines. If I force send the (wrong) command many times, I get only part of the error message. The tricky part is that if I step the program with the debugger, I'm getting all the messages exactly the way I want. I'm retargeting printf directly:


int
printf
(
char
const
*data, ...) {

//if( bDeviceState == UNCONNECTED ) return 0;

uint8_t size = 
strlen
( data );

if
( size < 64 ) {

while
( bDeviceState != CONFIGURED ) {}

CDC_Send_DATA( (unsigned 
char
*) data, size );

}

return
0;

}

Any ideas are welcome!
1 REPLY 1
kaloyan
Associate III
Posted on August 16, 2013 at 10:30

Hello again!

It seems that I doesn't implement the CDC_Send_DATA function properly.

Although I call

while( bDevicceState != CONFIGURED ) {}

  it seems that the program runs faster and my printf function can't send all of the data.

Consider this case:

function() {

printf(''test'');

}

This works OK.

Now:

function(){

prinft(''test1'');

printf(''test2'');

printf(''test3'');

}

In this case some or all of my data is lost.

I fix this by adding a loop.

function() {

printf(''test'');

test = SysTickVar + 1;

while(SysTickVar <= timer1) {}

printf(''test2'');

test = SysTickVar + 1;

while(SysTickVar <= timer1) {}

printf(''test3'');

}

This makes 1 ms delay after each printf and everything is out in the PuTTY window.

It seems that I don't handle the CDC_Send_DATA function properly. What I know is that the PC is polling the MCU each xx us or ms. I've expected that the bDeviceState tells me when the USB is configured for data exchange, but maybe it sends the data too fast?

If any of you knows а better way of doing thins, please share.