Skip to main content
gafsos
Associate III
August 9, 2012
Question

USBD- and USBD+ (PA11/PA12) Alternate Function

  • August 9, 2012
  • 9 replies
  • 3093 views
Posted on August 09, 2012 at 10:52

Hello,

One simple question please: Why It is mandatory to Set PA11/PA12 for USB data (+/-) as Alternate Function (AF) ? in STM32F103 for example

I’m asking this because in other products such as STM32L , it working even without  putting them as “AFâ€�

Could You please help me

Abdul
    This topic has been closed for replies.

    9 replies

    Tesla DeLorean
    Guru
    August 9, 2012
    Posted on August 09, 2012 at 14:05

    It likely depends on the default settings for the GPIO/AFIO, or other registers in the design.

    When AF mode is enabled and routed, it changes the function of the IO cell and disconnects the GPIO output control.

    It is always a good plan to explicitly define/set the functionality you want rather than assume initial conditions.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    arulprabhu
    Associate
    February 2, 2013
    Posted on February 02, 2013 at 09:16

    Dear clive1,

    Now I am testing the STM32L151CB USB section.

    Can we require USB D+ and USB D- pin should be Alternate Function(AF)?

    Can i have any example code using USB as Alternate function?

    I have checked the USB mass storage example, but i got  USB not detected.

    Can you help me for this problem.

    Thanks

    Arul

    Tesla DeLorean
    Guru
    February 2, 2013
    Posted on February 02, 2013 at 10:44

    Looking at the manuals, one could assume that the pins do NOT default as AF/USB, but there is no code in the examples to change this.

    I would expect the following code would address that ambiguity.

    void PinConfigUSB(void)
    {
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_USB);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_USB);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    arulprabhu
    Associate
    February 4, 2013
    Posted on February 04, 2013 at 05:06

    Dear clive1,

    Thanks for your Response.

    I do the test and come back to you.

    Thanks

    Arul

    arulprabhu
    Associate
    February 4, 2013
    Posted on February 04, 2013 at 10:35

    Hi clive1,

    Still the problem is not solved.

    I found that we have to disable USB internal pull up before use external pull up.

    Thanks

    Arul

    arulprabhu
    Associate
    February 5, 2013
    Posted on February 05, 2013 at 05:50

    Hi Abdul,

    You mentioned that the STM32L usb section is working without configure as ''AF''

    Do you have working example code to test STM32L USB functionality?

    Thanks

    Arul

    tsuneo
    Associate II
    February 5, 2013
    Posted on February 05, 2013 at 17:48

    I've posted ported code of KEIL RL-USB HID for STM32L-DISCOVERY

    http://www.keil.com/forum/22234/

    Without alternate function setting, the USB D+/D- ports work, just upon the default setting.

    In above post, brief porting steps from STM32F103 to STM32L15x are described.

    It'll help you to find clues of your problem.

    Tsuneo

    arulprabhu
    Associate
    February 6, 2013
    Posted on February 06, 2013 at 06:00

    Hi all,

    Thanks for everyone response.

    Now STM32L151CB usb is working well.

    We need not to configure as ''USB AF''

    Actual problem in my custom PCB side.Some resistor affected the usb Pins.

    After remove it , it is working well.

    You may disable the USB internal pull up before using External pull up.

    Thanks

    Arul

    pgregson1
    Associate III
    January 27, 2014
    Posted on January 27, 2014 at 21:59

    Hello Clive1

    Actually, the Reference Manual RM0008  (Doc ID 13902 Rev 10) says that PA11 and PA12 are automatically connected to the USB transceiver when USB is enabled.  Thus, there is no need for your code for this.

    Regards,

    Peter