libopencm3 icon indicating copy to clipboard operation
libopencm3 copied to clipboard

stm32f401cc tiny 401 wont enumerate

Open bm16ton opened this issue 3 years ago • 9 comments

I have a tiny f4101cc which ive always used interchangeably with my blackpill the same firmwares unmodified have always worked on both, but in libopencm3 the 401 wont enumerate...It doesnt even try my various pc's act as if nothing was ever detected. Ive tried the various usb patch fixes, which did work for several other boards, also tried the various vbus disable and force periph mode bits IE, OTG_FS_GCCFG |= OTG_GCCFG_NOVBUSSENS; OTG_FS_GUSBCFG |= OTG_GUSBCFG_FDMOD | OTG_GUSBCFG_TRDT_MASK; OTG_FS_GCCFG |= OTG_GCCFG_NOVBUSSENS | OTG_GCCFG_PWRDWN; OTG_FS_GCCFG &= ~(OTG_GCCFG_VBUSBSEN | OTG_GCCFG_VBUSASEN); etc. Where it doesnt even try to enumerate I assume the usb peripheral eiter isnt getting turned on/activated or the actual hardware has an issue (like weak or no pullups on D) thats is known and fixed via software hacks on the other sdks/ides kinda like the bluepill hacks we use, but this is best guess, and a guess from a foolish man at that. Any help would be greatly appreciated. I believe this to be the exact model I have https://stm32-base.org/boards/STM32F401CCU6-STM32-Mini-F401.html nothing connected to the exra usb pins vbus etc. according to that link.

bm16ton avatar Feb 01 '22 02:02 bm16ton

I have a very similar board. According to the schematic they have in common that the CC1 and CC2 are connected and share a single 5.1kΩ resistor, which is wrong. If I connect it with a USB-C to USB-C cable to the USB-C port of a Mac or PC, the board does not get power. If I connect it through a USB hub with USB-A ports, it gets power.

Could the same be the cause with your board? As it has a power LED, it's easy to tell.

manuelbl avatar Feb 01 '22 17:02 manuelbl

Once the board has power, all that's needed is either PR #1256

Or:

#include <libopencm3/usb/dwc/otg_fs.h>

...

	usbd_dev = usbd_init( ...omitted... );

	OTG_FS_GCCFG |= OTG_GCCFG_VBDEN | OTG_GCCFG_PWRDWN;

manuelbl avatar Feb 01 '22 19:02 manuelbl

If there's no new issue here then, I think we can close this.

karlp avatar Feb 02 '22 12:02 karlp

All these solutions didnt work:( i know it took me a day or two to respond, stupid life getting in way of projects. But the code still works on blackpill 411 not greenpill 401, the usb cable amd port are fine. Ive tried (and just retried) using exactly what was me tioned for usb bits amd still dead. Whats the timeframe on having to respond before this gets closed?

On Wed, 2 Feb 2022, 7:49 am Karl Palsson, @.***> wrote:

Closed #1381 https://github.com/libopencm3/libopencm3/issues/1381.

— Reply to this email directly, view it on GitHub https://github.com/libopencm3/libopencm3/issues/1381#event-5995520462, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADAWMP7HE2INII4XJNYTM5DUZER6LANCNFSM5NH7CUCQ . You are receiving this because you authored the thread.Message ID: @.***>

bm16ton avatar Feb 02 '22 22:02 bm16ton

no problem, I just misunderstood :)

karlp avatar Feb 03 '22 09:02 karlp

Hi guys, I have same issue using the WebAct black pill board based on stm32f401ccu6 chip. The USB enumeration never occurrs.

Although, using CubeMx + HAL everything works.

My USB initialization code are following:

// A copy of the 84MHz cofiguration with the USB support.
const struct rcc_clock_scale g_fwapp_rcc_hse_config = {
    .pllm = 25,
    .plln = 336,
    .pllp = 4,
    .pllq = 7,
    .pllr = 0,
    .pll_source = RCC_CFGR_PLLSRC_HSE_CLK,
    .hpre = RCC_CFGR_HPRE_NODIV,
    .ppre1 = RCC_CFGR_PPRE_DIV2,
    .ppre2 = RCC_CFGR_PPRE_NODIV,
    .voltage_scale = PWR_SCALE1,
    .flash_config = FLASH_ACR_DCEN | FLASH_ACR_ICEN |
            FLASH_ACR_LATENCY_2WS,
    .ahb_frequency  = 84000000,
    .apb1_frequency = 42000000,
    .apb2_frequency = 84000000,
};

int main(void)
{
    rcc_clock_setup_pll(&g_fwapp_rcc_hse_config);
    rcc_periph_clock_enable(RCC_GPIOA); // usb + usart
    rcc_periph_clock_enable(RCC_GPIOC); // led
    rcc_periph_clock_enable(RCC_USART2);
    rcc_periph_clock_enable(RCC_OTGFS); // otg_fs
    ...
    ...

    gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12);
    gpio_set_af(GPIOA, GPIO_AF10, GPIO11 | GPIO12);

    m_dev = usbd_init(
        &otgfs_usb_driver,
        &m_dev_dsc,
        &m_config_dsc,
        m_strings,
        USB_STRINGS_NUMBER,
        m_control_buffer,
        sizeof(m_control_buffer));
   ...
   ...
}

What's I'm doing wrong?

denis-shienkov avatar May 24 '22 16:05 denis-shienkov

Ahh, sorry, the trick with: OTG_FS_GCCFG |= OTG_GCCFG_VBDEN | OTG_GCCFG_PWRDWN; does work for me.

denis-shienkov avatar May 24 '22 16:05 denis-shienkov

i still cannot get my greenpill to enumerate at all. tried every combo of patches and vbus etc hacks. Tho sum differences between greenpills that look identical, a previous user stated his usb-c doesnt have the resistor etc so needs to be plugged into usb-A but mine does so maybe sum other difference is getting me? I know its gonna be something simple in end. My blackpill 411 has always worked in libopencm3 and the two have always been able to run eachothers firmwares fine from arduini/hal/etc so not sure what im missing. Its a shame too i have uses for it from libopencm3 if i can ever figure out ththe magic needed.

On Tue, 24 May 2022, 12:38 pm denis-shienkov, @.***> wrote:

Ahh, sorry, the trick with: OTG_FS_GCCFG |= OTG_GCCFG_VBDEN | OTG_GCCFG_PWRDWN; does work for me.

— Reply to this email directly, view it on GitHub https://github.com/libopencm3/libopencm3/issues/1381#issuecomment-1136151449, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADAWMP5FWT3UITRSTJCIORDVLUAXXANCNFSM5NH7CUCQ . You are receiving this because you authored the thread.Message ID: @.***>

bm16ton avatar May 24 '22 17:05 bm16ton

Ok so after updating my libopencm3 and then applying these various patches (swear id tried'em several times before) It now works!! Def something different bout this board then even other ones that look identical, For instance sum with usb-c wont work on true usb-c ports but this one has the appropriate resistors (thought id mention the little i knew). I just want to thank everyone who helped me and the developers. Im knew to all this, and oding in general and so far this is the only place anyone has given any support. Not sure if you know how important and how much it means to me and people like me. Again thank you!

bm16ton avatar Jul 28 '22 04:07 bm16ton