CDC Class added to USB Device Library!

General discussion on Libstock website & codes posted on this website.
Author
Message
Bandyt
Posts: 14
Joined: 25 Oct 2013 10:40

Re: CDC Class added to USB Device Library!

#31 Post by Bandyt » 29 Oct 2013 10:36

I solved a problem with new settings of PLLx for 8MHz Xtal , :)
i use PLLN=420, PLLM=10, PLLP=2, PLLQ=7, Frequency = 168MHz.

Pbfree
Posts: 2
Joined: 24 Feb 2014 14:20

Re: CDC Class added to USB Device Library!

#32 Post by Pbfree » 24 Feb 2014 14:47

Can anyone get USB device library (CDC Class) working on the STM32F429-Discovery board? I tried but ended up with compilation errors.

matrix
Posts: 203
Joined: 26 Jan 2006 07:21
Location: Bulgaria
Contact:

Re: CDC Class added to USB Device Library!

#33 Post by matrix » 25 Feb 2014 13:32

Pbfree wrote:Can anyone get USB device library (CDC Class) working on the STM32F429-Discovery board? I tried but ended up with compilation errors.
Post your project, please, and I'll try look what happens.

Pbfree
Posts: 2
Joined: 24 Feb 2014 14:20

Re: CDC Class added to USB Device Library!

#34 Post by Pbfree » 01 Mar 2014 14:47

It's actually the same Virtual COM Port project in the mikroE USB Device Library, but with the project settings modified for STM32F429ZI.

The errors I get are unresolved externs in __Lib_USB_Device_STM_M4.c

If you still need the project (mikroC), I've attached it here. Thanks for your help!
Attachments
stm32f429vcp.zip
(3.19 KiB) Downloaded 1063 times

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: CDC Class added to USB Device Library!

#35 Post by dejan.odabasic » 05 Mar 2014 17:35

Hello,

Library requires modification for STM32F429.
I will present this problem to our developers and they will fix it as soon as possible.

Best regards.

JackMorrison
Posts: 7
Joined: 05 Apr 2015 23:00

Re: CDC Class added to USB Device Library!

#36 Post by JackMorrison » 05 Apr 2015 23:08

I'm using the CDC Class on a PIC Clicker (PIC18F47J53) board, and it works fine, except on some machines when my PIC application does a flash erase - then the COM port goes into a bad state where it doesn't respond until a board reset. The PIC datasheet says the flash erase can stall the CPU for 33msec, so I suspect that some hosts give up on the USB connection during that interval.

Does anyone know what I need to do to avoid this? I tried

Code: Select all

USBDev_StallEndpoint(0x81);
FLASH_Erase_1024(addr);
USBDev_ClearStallEndpoint(0x81);
(also with endpoint 0x82 or 0x03), which either makes it fail on *all* machines or has no improvement.

The Mikro HID USB bootloader seems to work okay on a machine where my code fails, so there must be a trick to it, but since there's no source for that bootloader...

Thanks for any suggestions.

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: CDC Class added to USB Device Library!

#37 Post by marina.petrovic » 06 Apr 2015 13:26

Hi,

Unfortunately, I don't have a lot of experience with USB CDC class, but from your explanation it seems that this behavior can be related (and can be avoid) with very PC application .
In theory, after "reset" host PC recognizes disconnection of the PIC and Windows invalidate current device handle of the CDC device. The PC application has to close the handle once and then application acquires new device handle for re-connected CDC device.

Like I already mentioned, I can't know for sure where the problem occurs and this is just assumption.
You can search our forum and LibStock Website to see whether some of our users posted their topics which can help you.

Best regards,
Marina

JackMorrison
Posts: 7
Joined: 05 Apr 2015 23:00

Re: CDC Class added to USB Device Library!

#38 Post by JackMorrison » 07 Apr 2015 01:10

marina.petrovic wrote: In theory, after "reset" host PC recognizes disconnection of the PIC and Windows invalidate current device handle of the CDC device. The PC application has to close the handle once and then application acquires new device handle for re-connected CDC device.
If you're suggesting the PC close the COM device handle while the PIC is doing a flash update, and re-open afterwards, I tried this and it doesn't help. The PC can reopen the device but it no longer transfers data. This is on a Windows8 machine - on a Win7 it works fine.

Yet the HID Bootloader works on Win8. I don't know if this is a difference between HID and CDC, or if you guys know a trick to keep the USB connection from borking during a flash erase.

I don't see anything in the USB_Device library to reset (disconnect/reenumerate) the USB connection.
You can search our forum and LibStock Website to see whether some of our users posted their topics which can help you.
Yes, I tried this before posting, and didn't see anything.
BTW, the forum search doesn't seem to handle multiple keywords well. If I search for "flash usb", it says

Search term used: flash usb ignored: usb

and returns 4868 results that mention "flash".

Even with "+flash +usb".

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: CDC Class added to USB Device Library!

#39 Post by marina.petrovic » 07 Apr 2015 11:45

Hi,

Unfortunately, like I already mentioned, as I don't have a lot of experience with CDC Class I don't have idea what can go
wrong in this case, especially related with Windows 8 platform.

Maybe some of our users which have more experience can give you some suggestion.

Thank you very much for pointing on the "problem" with search option on our forum.
I will certainly notify my colleagues in charge.

Best regards,
Marina

JackMorrison
Posts: 7
Joined: 05 Apr 2015 23:00

Re: CDC Class added to USB Device Library!

#40 Post by JackMorrison » 11 Apr 2015 05:46

Following up: it turns out that the flash erase timing was not the problem. I configured the USB IN/OUT descriptors for max 40 bytes. Under Win7 and Linux, if I write 66 bytes it works fine (splitting into two transfers presumably). But writing 66 bytes hoses the Win8 driver. If I keep individual writes under 40 bytes, it works fine.

Also, to answer my own question about shutting down and restarting USB (which doesn't help when the driver is hosed but could be useful for someone elsewhere), something like this should work

Code: Select all

UCON = 0;       // shutdown USB
UIR = 0;
UIE = 0;
UEIE = 0;
      
Delay_ms(5000);

USBDev_CDCInit();   // restart USB
USBDev_Init();
IPEN_bit = 1;
USBIP_bit = 1;
USBIE_bit = 1;

Findus
Posts: 87
Joined: 05 Oct 2012 15:28

Re: CDC Class added to USB Device Library!

#41 Post by Findus » 15 Apr 2015 07:40

The CDC Class works on the Mikromedia for Stellaris M3 good, but on Mikromedia for Tiva not. Unbekanntes Gerät. not known device

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: CDC Class added to USB Device Library!

#42 Post by marina.petrovic » 15 Apr 2015 09:55

Hi,

Please can you tell me which example/project you tested?

Maybe for Tiva MCU you need to have some additional settings (take a look at the MCU datasheet).

Best regards,
Marina

Findus
Posts: 87
Joined: 05 Oct 2012 15:28

Re: CDC Class added to USB Device Library!

#43 Post by Findus » 15 Apr 2015 10:56

Hi Marina,
marina.petrovic wrote:Please can you tell me which example/project you tested?
i took the old one from Stellaris and this works on Stellaris:

Code: Select all

procedure InitUsbUart();
var
  LoopCount: longint;
begin
   USBDev_CDCInit();
   USBDev_Init();
   USBDev_CDCSetLineCoding(115200,0,0,8);

   // Enable USB device interrupt
   {$IFDEF Stellaris}
   NVIC_IntEnable(IVT_INT_USB0);
   {$ELSE}
   NVIC_IntEnable(IVT_INT_USB);
   {$ENDIF}

   // Wait until device is configured (enumeration is successfully finished)
   Loopcount:=0;
   while (USBDev_GetDeviceState() <> _USB_DEV_STATE_CONFIGURED) and (LoopCount<400000) do begin
      inc(LoopCount);
   end;

  // Set receive buffer where received data is stored
  USBDev_CDCSetReceiveBuffer(@buffer);
end;
marina.petrovic wrote:Maybe for Tiva MCU you need to have some additional settings (take a look at the MCU datasheet).
USBdev ist totaly capseled, how can i use additional settings?

Best regards
Thomas

Findus
Posts: 87
Joined: 05 Oct 2012 15:28

Re: CDC Class added to USB Device Library!

#44 Post by Findus » 15 Apr 2015 13:44

Hi Marina,

i hope, the cause for this problem is not the missing pulldown.

Image

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: CDC Class added to USB Device Library!

#45 Post by marina.petrovic » 16 Apr 2015 14:45

Hi,

You probably mistakenly reverse schematics.
Pull-down resistor on USB-ID line is on mikromedia for Tiva board, but in any case this shouldn't affect proper USB (CDC class) communication.

This line is used for USB OTG, but we don't use it (it should determine which side is host and which side is device).
Our hardware developers use pull-down on this line only to not leave the line "not connected".

Please, double check your config words (project settings).
You can try some simple USB example from the compiler. If standard USB example works with your project settings,
your CDC example should work also.

Best regards,
Marina

Post Reply

Return to “Libstock Discussion”