Problems with ST32F302 and USB

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Problems with ST32F302 and USB

Post by gab »

External clock 16MHz

mcuconf.h:
---
#define STM32_NO_INIT FALSE
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI_ENABLED TRUE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED FALSE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PREDIV_VALUE 2 // 16MHZ HSE -> 72MHZ SYSCLK
#define STM32_PLLMUL_VALUE 9
#define STM32_HPRE STM32_HPRE_DIV1 // 72MHz AHB
#define STM32_PPRE1 STM32_PPRE1_DIV2 // 36MHz APB1
#define STM32_PPRE2 STM32_PPRE2_DIV2 // 72MHz APB2
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
#define STM32_ADC12PRES STM32_ADC12PRES_DIV1
---
in main.c:
---
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);

usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1500);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
---
program dont leave this block:
---
while (SDU1.config->usbp->state != USB_ACTIVE) {
led_toggle(STATUS_LED);
chThdSleepMilliseconds(500);
}
---
Led blinking.

When i set brickpoint in "usb_event" function, i catch 2 or more USB_EVENT_RESET event and, after all, USB_EVENT_SUSPEND event.
OS cannot read USB device descriptor.
Electrically all correct, i can enter to USB DFU mode. I see STM32 bootloader device.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problems with ST32F302 and USB

Post by Giovanni »

Hi,

Hard to tell, it works on a lot of F3 boards so it must be some configuration issue, does the host initiate the enumeration?

You could try to output the PLL on MCO and verify if the clock is what you expect.

Giovanni
gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Re: Problems with ST32F302 and USB

Post by gab »

I see good 16MHz sinusoidal signal on oscilloscope when connect to quarz pin.
Yes, host initiate the enumeration. Later i try to connect to linux pc and view dmesg output.
gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Re: Problems with ST32F302 and USB

Post by gab »

And some strange:
Chip marking: STM32F302C8T6

In OpenOCD:
Info : device id = 0x10036422
Info : flash size = 128kbytes
gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Re: Problems with ST32F302 and USB

Post by gab »

I write to config file this
#define STM32_MCOSEL STM32_MCOSEL_PLLDIV2

At A8 pin measure 35.9991 MHz

Al linux dmesg writes:
[117379.864359] usb 1-1: new full-speed USB device number 18 using xhci_hcd
[117379.992115] usb 1-1: device descriptor read/64, error -71
[117380.227595] usb 1-1: device descriptor read/64, error -71
[117380.335552] usb usb1-port1: attempt power cycle
[117380.985577] usb 1-1: new full-speed USB device number 19 using xhci_hcd
[117380.985719] usb 1-1: Device not responding to setup address.
[117381.193652] usb 1-1: Device not responding to setup address.
[117381.401082] usb 1-1: device not accepting address 19, error -71
[117381.528772] usb 1-1: new full-speed USB device number 20 using xhci_hcd
[117381.528990] usb 1-1: Device not responding to setup address.
[117381.736693] usb 1-1: Device not responding to setup address.
[117381.736778] debugfs: Directory '05' with parent 'devices' already present!
[117381.943880] usb 1-1: device not accepting address 20, error -71
[117381.944062] usb usb1-port1: unable to enumerate USB device
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problems with ST32F302 and USB

Post by Giovanni »

It looks like the device is not responding at all, is alternate mode 14 set for DM and DP in board.h?

Giovanni
gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Re: Problems with ST32F302 and USB

Post by gab »

Yes.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problems with ST32F302 and USB

Post by Giovanni »

You could try to put breakpoints in the USB driver state machine and see if it receives the first messages like set address.

This is so strange because that USB driver hasn't been touched for ages, it just works. Could you give details about your setup such as compiler, chibios version and anything you do differently from the USB demos.

Giovanni
gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Re: Problems with ST32F302 and USB

Post by gab »

I set breakpoint in OSAL_IRQ_HANDLER(STM32_USB1_LP_HANDLER) function

in called 3 times:
STM32_USB->ISTR value is

1st call: RESET bit set
2nd call: ESOF | RESET | SUSP bits set
3rd call: ESOF bit set

after that handler never called.
gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Re: Problems with ST32F302 and USB

Post by gab »

gnu ver. 9.0 2019q4
Post Reply