cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 USB doesn't work compilation with GCC

obit
Associate
Posted on February 02, 2015 at 00:12

I'm testing ST's USB Virtual COM Port example code(fromSTM32_USB-FS-Device_Lib_V4.0.0) on

STM32F103ZET6 board

,and the binary that is produced could not enumetate when compiling with
gcc(-O0 or -O2 or -O3).
if i compile with MDK

everything always works perfectly.

gcc compile another

example code such as led flicker will work fine.

who knows why? CFLAGS = -O3 -g -Wall -I.\ -mcpu=cortex-m3 \ -mthumb \ -mfloat-abi=soft \ $(INCLUDES) -DUSE_STDPERIPH_DRIVER -DSTM32F10X_HD -DUSE_STM3210E_EVAL sniffer by bushound

enumetate fail

DevicePhaseData Description Cmd.Phase.Ofs(rep)

---------------------------------------------------------------------

9.1IN 00 01 .. 1.1.0

9.0CTL a3 00 00 0008 00 04 00GET STATUS 2.1.0

9.0IN 01 01 01 00 .... 2.2.0

9.0CTL 23 01 10 0008 00 00 00CLEAR FEATURE 3.1.0

9.0CTL a3 00 00 0008 00 04 00GET STATUS 4.1.0

9.0IN 01 01 00 00 .... 4.2.0

9.0CTL 23 03 04 0008 00 00 00SET FEATURE 5.1.0(4)

9.1IN 00 01 .. 6.1.0(4)

9.0CTL a3 00 00 0008 00 04 00GET STATUS 7.1.0(4)

9.0IN 03 01 10 00 .... 7.2.0

9.0CTL 23 01 14 0008 00 00 00CLEAR FEATURE 8.1.0(4)

9.0CTL a3 00 00 0008 00 04 00GET STATUS 9.1.0(4)

9.0IN 03 01 00 00 .... 9.2.0

9.0CTL 23 01 01 0008 00 00 00CLEAR FEATURE 1.0

enumetate success

DevicePhaseData Description Cmd.Phase.Ofs(rep)

---------------------------------------------------------------------

9.1IN 00 01 .. 1.1.0

9.0CTL a3 00 00 0008 00 04 00GET STATUS 2.1.0

9.0IN 01 01 01 00 .... 2.2.0

9.0CTL 23 01 10 0008 00 00 00CLEAR FEATURE 3.1.0

9.0CTL a3 00 00 0008 00 04 00GET STATUS 4.1.0

9.0IN 01 01 00 00 .... 4.2.0

9.0CTL 23 03 04 0008 00 00 00SET FEATURE 5.1.0(2)

9.1IN 00 01 .. 6.1.0(2)

9.0CTL a3 00 00 0008 00 04 00GET STATUS 7.1.0(2)

9.0IN 03 01 10 00 .... 7.2.0

9.0CTL 23 01 14 0008 00 00 00CLEAR FEATURE 8.1.0(2)

9.0CTL a3 00 00 0008 00 04 00GET STATUS 9.1.0(3)

9.0IN 03 01 00 00 .... 9.2.0

9.0CTL 80 06 ee 0300 00 12 00GET DESCRIPTOR 1.0

9.0USTS c0000004 stall pid 2.0

9.0CTL 80 06 03 0309 04 ff 00GET DESCRIPTOR 1.0

9.0IN 1a 03 34 0038 00 45 00..4.8.E. 2.0

46 00 37 0036 00 35 00F.7.6.5. 2.8

43 00 33 0035 00 33 00C.3.5.3. 2.16

37 00 7. 2.24

9.0CTL 80 06 00 0300 00 ff 00GET DESCRIPTOR 1.0

9.0IN 04 03 09 04 .... 2.0

9.0CTL 80 06 02 0309 04 ff 00GET DESCRIPTOR 1.0

9.0IN 32 03 53 0054 00 4d S.T.M. 2.0

33 00 32 0020 00 56 2. .V. 2.8

69 00 72 0074 00 75 00i.r.t.u. 2.16

61 00 6c 0020 00 43 00a.l. .C. 2.24

9.0CTL 80 06 00 0600 00 0a 00GET DESCRIPTOR 1.0

9.0USTS c0000004 stall pid 2.0

3 REPLIES 3
Posted on February 02, 2015 at 01:42

Structure packing? HSE_VALUE?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
obit
Associate
Posted on February 02, 2015 at 02:23

#define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */

tsuneo
Senior
Posted on February 03, 2015 at 06:32

STM32_USB-FS-Device_Lib_V4.0.0 examples require extra macro definitions on GCC command line.

For STM32F103ZET6,

-DUSE_STM3210E_EVAL

-DSTM32F10X_HD

-DUSE_STDPERIPH_DRIVER

Did you add above definitions?

Anyway, what is the sniffer you are using?

It's useless at all to trace a problem on enumeration.

- On the ''failed'' log,

it shows just requests to the hub port, to which the device is plugged in.

Nothing to the target device.

- On the ''success'' log,

It drops many requests Windows OS sends to the device on enumeration.

Tsuneo