/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Newbie trying to get USB to work

Username:     
Password:     
             

Forum

# 1   2010-08-23 20:00:16 Newbie trying to get USB to work

VanKurt
Member
Registered: 2010-08-12
Posts: 10

Newbie trying to get USB to work

Hi fellas!
I've just downloaded an USB sample for my STM32 (Primer2). It should connect to windows as a virtual COM Port device.
The code compiles fine and I can download and run it on the Primer 2. Sadly nothing happens in windows :-(
This leaves me with some questions:

1.
What CPU frequency do I have to setup in the ride project? Is it 8, 12 or 72 Mhz?
Actually I can't figure out how fast the Primer2's crystal is...

2.
How do I connect the primer 2 to the PC?
Right now I have two USB cables, one on the debug and one on the PC port of the Primer. Can that work? Can I debug the Primer with Ride AND make it communicate with the PC via the other USB cable?

Thanks for your help!

Offline

 

# 2   2010-08-24 06:25:24 Newbie trying to get USB to work

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Newbie trying to get USB to work

Hi,

1 : the frequency to setup in Ride project is the crystal frequency = 12 MHz for Primer 2. Note that this parameter is only used for Ride debug display (clocks, SPI and USART speed...)
2 : There is no problem to debug with Ride on "debug" port, and in the same time, to communicate with PC on "STM32" port. The PC is able to differenciate the two ports (devices differents).

For your problem, check that the USB frequency is well configured to 48 MHz on Primer2, that is the most met mistake (in this case, Windows says "Unknown device"). Check also how is managed the disconnect pin, which is different for Primer2 from ST sample (in this case, Window don't say anything). Take a look to "ms_hw_config.c" in the CircleOS project.

Hope that helps !

Offline

 

# 3   2010-08-24 07:06:51 Newbie trying to get USB to work

VanKurt
Member
Registered: 2010-08-12
Posts: 10

Re: Newbie trying to get USB to work

Yeah, I think that's gonna help. At least it sounds promising ;-)
Thanks a bunch!

Offline

 

# 4   2010-08-24 16:42:12 Newbie trying to get USB to work

VanKurt
Member
Registered: 2010-08-12
Posts: 10

Re: Newbie trying to get USB to work

Alright, now it's almost working. Windows sees the device but can't recognize it.
That brings me to your first point: 48MHz.

Is there a way to check the set frequency in the debugger? Some special registers I could look at?


Oh, and one more thing:
I think something is wrong with the ST virtual com port driver. I've installed the 64bit version (v1.3.1 I think) from the st website. After installing the driver (on my WIn7 64) there was NO virtual com port in the device manager. In the manual it said such a thing would appear...
The readme also said that WIn7 x64 was supported, so may the pĆ¼roblem be somewhere here?
Is that why my Primer2 appears only ans an "Unknown USB device"?

Last edited by VanKurt (2010-08-24 18:23:33)

Offline

 

# 5   2010-08-25 06:42:02 Newbie trying to get USB to work

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Newbie trying to get USB to work

With Ride you can verify all clocks, if you have configured the CPU crystal parameter to 12 MHz (Rlink Configuration \ Advanced options \ Crystal Frequency).

Then, in debug session, go to the debug tab, choose the "Peripherals \ Reset/clock \ Clock summary", you will see the USBCLK current value.

A bad USB frequency can be a cause of the "Unknown USB device" message. But it can be also a bad device descriptor.

Which example did you get ? What did you modify ?

Offline

 

# 6   2010-08-25 14:54:53 Newbie trying to get USB to work

VanKurt
Member
Registered: 2010-08-12
Posts: 10

Re: Newbie trying to get USB to work

Ah, the register says 72MHz. That's definately not 48Mhz ;-)

I set my USB Clock up like this:
(taken from CircleOS)

void Set_System(void)
{
   RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_4 );

    GPIO_InitTypeDef GPIO_InitStructure;


  /* Enable USB_DISCONNECT GPIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_CONNECT, ENABLE);

  /* Configure USB pull-up pin */
  GPIO_InitStructure.GPIO_Pin = USB_CONNECT_PIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(USB_CONNECT, &GPIO_InitStructure);


  /* Enable and GPIOD clock */
  USB_Disconnect_Config();

}

and then:


void Set_USBClock(void)
{
  /* Select USBCLK source */
  RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
 
  /* Enable the USB clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
}

Offline

 

# 7   2010-08-25 18:09:21 Newbie trying to get USB to work

VanKurt
Member
Registered: 2010-08-12
Posts: 10

Re: Newbie trying to get USB to work

OK, I think I found the problem: the following code should set the clock to 48Mhz. But sadly it doesn't :-(
The USB clock is then derived correctly from this value, but since the value is wrong the USB clock is also wrong...

Code:

    /* Enable PLL */
    RCC_PLLCmd( DISABLE );

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig( RCC_SYSCLKSource_HSE );

   RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_4 );

    /* Enable PLL */
    RCC_PLLCmd( ENABLE );

    /* Wait till PLL is ready */
    while( RCC_GetFlagStatus( RCC_FLAG_PLLRDY ) == RESET )
        { ; }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );

    /* Wait till PLL is used as system clock source */
    while( RCC_GetSYSCLKSource() != 0x08 )
        { ; }

The result should be 48 Mhz (HSE Clock is 12 Mhz, 12*4/1 = 48), but it is 108....
Very strange :-(

Offline

 

# 8   2010-08-26 07:26:07 Newbie trying to get USB to work

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Newbie trying to get USB to work

Dont't be confused between system clock ad USB clock.

I suggest this code :
        /* PLLCLK = 12MHz * 6 = 72 MHz */
        RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_6 );
in order to set System clock to 72 MHz
Then.
/* Select USBCLK source */
  RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
in order to set USB clock to 48 MHz.

Another question, do you use old precompiled ST library or a new one with files in your project ? Because the ST library is configured by default with HSE = 8MHz, the bad display is often due to this fact (we also had the problem with USART speed).
It is better to add all need ST library files into your project.

Offline

 

# 9   2010-09-01 08:52:30 Newbie trying to get USB to work

jgemio
New member
Registered: 2010-08-03
Posts: 4

Re: Newbie trying to get USB to work

Hello Vankurt,
Which application did you use as USB sample?
Rgds,

Offline

 

Board footer