cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 usb example not working

aruns06
Associate II
Posted on March 16, 2015 at 06:54

Hi,

I'm trying to run a sample USB (memory) program present in Keil IDE. The source is located in C:\Keil\ARM\Boards\ST\CQ-STARM2\USBMem. As per the description, after loading the program,  the  USB Memory is automatically recognized by the host PC running Windows which will load a generic Mass Storage driver. I'm can compile and upload the program. After that I reset the hardware and plugged the USB (Mini) cable but nothing happens. As per the description the board is designed to run on 'STM32F103VB' controller. but I am using STM32F103RB. Also the example is designed for 'CQ-STARM2' Evaluation Board. But I 'm using a customized hardware. Where PA12 -D+ ,PA11-D-. In the sample program I never saw

the GPIO pins PA12 and PA11 configured. Any suggestions?

Regards,

Arun

#stm32f103-usb
4 REPLIES 4
Posted on March 16, 2015 at 12:29

It's probably not a problem with the configuration of PA11/PA12

Your description is confusing, does something actually work here? And on what?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aruns06
Associate II
Posted on March 16, 2015 at 12:40

As per the description in the Abstract, after I upload the code, I should plug a USB (Mini) cable to the hardware and then PC. Then it should be detected in the device manager.

Below is the abstract of the project.

The Memory project is a demo program for the ST 'STM32F103VB'
microcontroller using 'CQ-STARM2' Evaluation Board, compliant 
to Cortex Microcontroller Software Interface Standard (CMSIS v2.0).
Example functionality:
- Clock Settings:
- XTAL = 8 MHz
- SYSCLK = 72 MHz
- HCLK = SYSCLK = 72 MHz
- USB clock = 48 MHz
It demonstrates an USB Memory based on USB Mass Storage Class.
LEDs are used to display the following:
- LED1 (PC6): LED_CFG is on when USB Device is configured
The USB Memory is automatically recognized by the host PC
running Windows which will load a generic Mass Storage driver.
The Memory program is available for the following targets:
STM32F103 Flash: configured for on-chip Flash ROM
(used for production or target debugging)

Regards, Arun
aruns06
Associate II
Posted on March 17, 2015 at 07:24

Any Idea.....

Regards,

Arun.S

tsuneo
Senior
Posted on March 17, 2015 at 10:15

> But I 'm using a customized hardware.

A) Crystal frequency What is the Xtal frequency? As the abstract of CQ-STARM2 example tells, the example expects 8 MHz crystal across OSC_IN/_OUT pins. B) D+ pull-up resistor This USB device engine on STM32F103 requires an external D+ pull-up resistor (1k5), which is driven by a port pin. Does your board have this resistor?

STM32F103RB USB B-type connector

PA11 --------------- D- PA12 -----------+--- D+ | PB12 --- 1k5 ---+ GND --------------- GND The CQ-STARM2\USBMem example supposes to drive the external resistor over a transistor using PD9, but the direct connection like above makes the circuit simple. You may assign any extra GPIO port for this purpose, except for the JTAG ports (PA13-PA15, PB4). The example code around PD9 should be modified, according to your choice for the drive port. Here is modification for PB

\Keil\ARM\Boards\ST\CQ-STARM2\USBMem\usbhw_STM32F10x.c
void USB_Init (void) {
RCC->APB1ENR |= (1 << 
23
); /* enable clock for USB */
USB_IntrEna (); /* Enable USB Interrupts */
/* Control USB connecting via SW */
RCC->APB2ENR |= (1 << 
3
); /* enable clock for GPIOB */
GPIOB->CRH &= ~0x000F0000; /* clear port PB12 */
GPIOB->CRH |= 0x00040000; /* PB12 Floating input */
}
void USB_Connect (BOOL con) {
GPIOB->CRH &= ~0x000F0000; /* clear port PB12 */
if (con) {
GPIOB->BSRR = 0x1000; /* set PB12 */
GPIOB->CRH |= 0x00030000; /* PB12 General purpose output push-pull, 50 Mhz */
CNTR = CNTR_FRES; /* Force USB Reset */
CNTR = 0;
ISTR = 0; /* Clear Interrupt Status */
CNTR = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM; /* USB Interrupt Mask */
} else {
CNTR = CNTR_FRES | CNTR_PDWN; /* Switch Off USB Device */
GPIOB->CRH |= 0x00040000; /* PB12 Floating input */
}
}

Tsuneo