cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-F103RB + USB

lemac
Associate II
Posted on November 03, 2014 at 16:33

Hello

I have a board Nucleo-F103RB. 

I cut a usb cable and connect:

D+ to PA11 

D- to PA12 

GND to GND pin in morpho headers 

VCC to E5V pin in morpho headers

I am using the libraries. STM32_USB-FS-Device_Lib_V4.0.0. 

And i want make a HID dvice so I copi the source code to my IAR proyect

I use this functions in main function.

  Set_System();

  USB_Interrupts_Config();

  Set_USBClock();

  USB_Init();

    while (1)

    {

    }

But it don't make nothing the PC don't recog

Compile and execute but it don't make nothing the PC does not identify the a new device connected.

What am I making bad?

I must instal first the PC driver?

Where can i find a example code?

Some one can help me?

Best regards

#stm32f103rb #usb #usb #stm32f103
12 REPLIES 12
stm32forum
Associate II
Posted on November 03, 2014 at 16:55

D- =PA11

D+ =PA12

Just the other way around you have.

lemac
Associate II
Posted on November 03, 2014 at 17:20

Hello

I changed the lines and it don't work.

best regards

chen
Associate II
Posted on November 03, 2014 at 18:32

Hi

''Compile and execute but it don't make nothing the PC does not identify the a new device connected.''

''What am I making bad?''

So it sounds like the PC does see some USB device but it does not know what it is.

Is this correct?

''I must instal first the PC driver?''

Yes

''Where can i find a example code?''

Difficult, depends on the STM32 you have.

Not sure if this library supports you processor :

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257882

This one should but is less advanced (and I know almost nothing about this library because I have not used it)

http://www.st.com/web/en/catalog/tools/PF258157

Both should contain example projects.

lemac
Associate II
Posted on November 04, 2014 at 09:37

Hello

''''Compile and execute but it don't make nothing the PC does not identify the a new device connected.''

 

''What am I making bad?''

 

So it sounds like the PC does see some USB device but it does not know what it is.

 

Is this correct?''

The PC don't see the USB device. It is like the pc has nothing connect.

I am reading the sample code. And although the documentation said that it is valid for the STM32F103 in the function 

void Set_System(void) in hw_config.c don't are any line of code for this microcontroller.

I will prove this libraries Sung.chen_chung

So... I need a valid sample code.

Someone have code for control the USB in a STM32F103?

Best regards

chen
Associate II
Posted on November 04, 2014 at 10:14

''So it sounds like the PC does see some USB device but it does not know what it is.

 

Is this correct?''

The PC don't see the USB device. It is like the pc has nothing connect.''

In that case, the USB implementation is not working at all.

tsuneo
Senior
Posted on November 04, 2014 at 17:02

Hi lemos,

To run a USB device on NUCLEO-F103RB board, A) Hardware settings A-1) USB connector and an external D+ pull-up resistor This board doesn’t mount any USB connector for the target STM32F103 chip. Also, STM32F103 doesn’t have on-chip D+ pull-up resistor (1.5k Ohm). You have to connect these components to the board.

STM32F103RB USB B-type connector

PA11 --------------- D- PA12 -----------+--- D+ | PB12 --- 1k5 ---+ GND --------------- GND A-2) Clock supply Select ''MCO from ST-LINK'' option, following to the ''5.7.1 OSC clock supply'' section of the STM32TM Nucleo boards User manual (UM1724), - B54 and SB55 OFF - SB16 and SB50 ON - R35 and R37 removed With this option, ST-LINK provides 8 MHz clock over MCO trace to the target STM32F B) USB library and its modifications STM32F103 is supported by STM32_USB-FS-Device_Lib_V4.0.0 (STSW-STM32121) - STM32_USB-Host-Device_Lib_V2.1.0 (STSW-STM32046) doesn’t support this chip Starting with one of USB examples, - On your IDE, select STM3210B-EVAL configuration (for STM32F103VB), which is most similar to the Nucleo-F103 board among the configurations. - Above configuration defines USE_STDPERIPH_DRIVER, STM32F10X_MD, USE_STM3210B_EVAL macros, which are fine for STM32F103RB. As the assignment of GPIO ports for LEDs and switches on STM3210B-EVAL is different from the Nucleo board, you have to touch to the code which assigns these ports. Also, you may have to touch to other peripherals like USART. As of USB, Above hardware settings require these modifications. B-1) external D+ pull-up resistor

platform_config.h
/* Define the STM32F10x hardware depending on the used evaluation board */
#ifdef USE_STM3210B_EVAL
/* // <---- replace these three lines
#define USB_DISCONNECT GPIOD 
#define USB_DISCONNECT_PIN GPIO_Pin_9
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOD
*/
#define USB_DISCONNECT GPIOB
#define USB_DISCONNECT_PIN GPIO_Pin_12
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOB

hw_config.c
void Set_System(void)
{
...
#if !defined(STM32L1XX_MD)
/* Configure USB pull-up */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
/* Configure USB pull-up */
GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; // <---- replace this line
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN); // <---- add this line
#endif /* STM32L1XX_MD */

hw_config.c
void USB_Cable_Config (FunctionalState NewState)
{
#ifdef STM32L1XX_MD
...
#else
// <---- comment these lines
/*
if (NewState != DISABLE)
{
GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
}
else
{
GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
}
*/
// <---- add these lines
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
if (NewState == ENABLE)
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
}
else
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
}
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
#endif /* STM32L1XX_MD */ 
}

B-2) Clock supply - Set the RCC into HSE_Bypass mode - Enable USBPRE bit to generate 48MHz USB clock from 72MHz Sysclock.

system_stm32f10x.c
static void SetSysClockTo72(void)
{
// <---- comment these line
#if 0
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/ 
/* Enable HSE */ 
RCC->CR |= ((uint32_t)RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++; 
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
#endif
RCC_HSEConfig( RCC_HSE_Bypass ); // <---- add these two lines
if ( RCC_WaitForHSEStartUp() == SUCCESS )
// if ((RCC->CR & RCC_CR_HSERDY) != RESET) // <---- comment this line
{
HSEStatus = (uint32_t)0x01;
}

Hope this brief summary helps you 😉 Tsuneo
lemac
Associate II
Posted on November 05, 2014 at 11:26

Hello

Many thanks. I make all the changes that you said and now the PC see a new USB device. With a difference I instal a external cristal of 8MHz because in  the future i want remove the ST-Link part.

Now the PC see a USB device unknown.

Now I can continue working.

Thanks a lot. Best regards.

chen
Associate II
Posted on November 05, 2014 at 12:16

''I instal a external cristal of 8MHz''

''Now the PC see a USB device unknown.''

Classic problem. The clock to the USB peripheral is not the right freq to generate the correct USB timings. So the PC can kind of see a device but it does not understand the USB messages because the timing of the USB message is wrong.

Normally, the USB peripheral should be clocked at 48MHz.

If you have changed the crystal clocking the STM32 then you must also change the PLL setting to match. Also, check the clocking scheme to the USB peripheral give the correct 48MHz

lemac
Associate II
Posted on November 05, 2014 at 17:12

Hello

I measured with the oscilloscope the crystal signals and i saw that the Crystal is not right.

I was looking for and i don't have more 8MHz crystal in my store.

So... I make the pass like said Tsuneo

Select ''MCO from ST-LINK'' option,

 

following to the ''5.7.1 OSC clock supply'' section of the STM32TM Nucleo boards User manual (UM1724), 

 

- SB54 and SB55 OFF

 

- SB16 and SB50 ON

 

- R35 and R37 removed

 

With this option, ST-LINK provides 8 MHz clock over MCO trace to the target STM32F103.

But this don't work.

Do you are sure that i don't must modifie some ''Device_Info''?

Best regards