[STM32F1]

USB枚举不成功的原因

[复制链接]
2387|7
手机看帖
扫描二维码
随时随地手机跟帖
Cjy_JDxy|  楼主 | 2018-5-4 17:39 | 显示全部楼层 |阅读模式
我做了一块STM32 USB小板,用STM32自带的USB。
板子焊好,程序烧进去提示无法识别的USB设备。
现在正在查是什么原因。请问都有可能是什么原因导致
的USB枚举不成功呢?有一点我拿不准。
板子画的不太好,USB数据线上打了好几个过孔,不知道有没有
影响。各位大神给看看,谢谢!
Cjy_JDxy|  楼主 | 2018-5-5 09:13 | 显示全部楼层
好多网友都说是软件问题的概率大。
我把初始化贴出来看哪里不对。
/*
**************************************************************************
*º¯ÊýÔ­ÐÍ£ºvoid CPU_Init(void)
*Èë¿Ú²ÎÊý£ºÎÞ
*³ö¿Ú²ÎÊý£ºÎÞ
*º¯Êý¹¦ÄÜ£º¹Ü½Å³õʼ»¯
************************************************************************
*/
void CPU_Init(void)
{

    GPIO_InitTypeDef GPIO_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
    EXTI_InitTypeDef EXTI_InitStructure;

    /*  ÍâÉèʱÖÓ³õʼ»¯  */
    // GPIOA, GPIOB, GPIOC, AFIOÔÊÐí, GPIOD, GPIOE²»ÓÃ, GPIOF, GPIOGûÓÐ
    // TIM1 Periph clock enable ¶¨Ê±ÖжÏÓÃ
    // USART1, ÔÊÐí
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                           RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO  |
                                                   RCC_APB2Periph_TIM1  | RCC_APB2Periph_USART1 ,ENABLE);
    //UART2, UART3 ÔÊÐí, SPI2 ½ûÖ¹, I2C1, I2C2²»ÓÃ, WWDG ½ûÖ¹, CRCÔÊÐí, USB, CAN, BKP, DAC, µçÔ´½Ó¿Ú²»ÓÃ
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2| RCC_APB1Periph_USART3|
                           RCC_APB1Periph_CEC | RCC_APB1Periph_PWR | RCC_APB1Periph_USB , ENABLE);

    /* GPIOÅäÖÃ */
        //GPIOA
        /********************************************************************************/
        /*PA1->RF_RSTN          PA2->UART2_TXD   PA3->UART2_RXD  PA4->RF_SSN         PA8->LED       */
        /*PA9->UART1_TXD  PA10->UART1_RXD  PA11->USB_DM    PA12->USB_DP  PA14->SAMV_PWR */
        /********************************************************************************/
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0 | GPIO_Pin_3 | GPIO_Pin_5 | GPIO_Pin_6 |
                                       GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_13 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;                //ÉÏÀ­ÊäÈë
    GPIO_Init(GPIOA, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;                //ÏÂÀ­ÊäÈë
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_8 | GPIO_Pin_14;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;        //ÍÆÍìÊä³ö
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_9 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                //¸´ÓÃÍÆÍìÊä³ö
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

        //GPIOB                       
        /**************************************************************************/
    /*PB0->RF_STAND          PB2->BOOT1    PB3->SAM_TF  PB4->SAM_RT                      */
        /*PB6->SAM_SCK    PB7->SAM_DAT                                            */
        /**************************************************************************/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;                //¸¡¿ÕÊäÈë
    GPIO_Init(GPIOB, &GPIO_InitStructure);                 

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 |
                                      GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
                                                                  GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;                                //ÉÏÀ­ÊäÈë
    GPIO_Init(GPIOB, &GPIO_InitStructure);                 

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;                                //ÏÂÀ­ÊäÈë
    GPIO_Init(GPIOB, &GPIO_InitStructure);                 

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_4 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                        //ÍÆÍìÊä³ö
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);                 
               
        //GPIOC
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;                                //ÉÏÀ­ÊäÈë
    GPIO_Init(GPIOC, &GPIO_InitStructure);
   
    //ÉèÖÃÊä³ö¿Úµçƽ
        //AFIO->MAPR|=(0X04<<24);                                                          //¹Ø±ÕJTAG-DP,¹Ø±ÕSW-DP;
        GPIO_SetBits(GPIOA, GPIO_Pin_4 | GPIO_Pin_14);
        GPIO_ResetBits(GPIOA, GPIO_Pin_1 | GPIO_Pin_8);
        GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_4);

    //Set the Vector Table base address at 0x08000000
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, NVIC_APP_OFFSET);
    //Configure the Priority Group to 2 bits
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
               
   
}

使用特权

评论回复
Cjy_JDxy|  楼主 | 2018-5-5 09:14 | 显示全部楼层
使能了USB时钟,USB的两根数据线下拉输入。

使用特权

评论回复
huzi2099| | 2018-5-5 13:06 | 显示全部楼层
你没有usb代码呀

使用特权

评论回复
Cjy_JDxy|  楼主 | 2018-5-6 13:12 | 显示全部楼层
huzi2099 发表于 2018-5-5 13:06
你没有usb代码呀

明天贴出来。

使用特权

评论回复
Cjy_JDxy|  楼主 | 2018-5-10 13:56 | 显示全部楼层
        //thm3070_Init();              //3070³õʼ»¯»¯
        USB_Configurage();              //¿ªÆôUSBʱÖÓ
        USB_Interrupts_Config();        //ÉèÖÃÖжÏÓÅÏȼ¶2.0
        Set_USBClock();                 //USBʱÖÓÉèÖÃ
        USB_Init();                     //USB½Ó¿Ú³õʼ»¯

使用特权

评论回复
yiy| | 2018-5-11 23:43 | 显示全部楼层
哪个芯片?烧录进cube里面的例子试试看。如果例子都没法运行,那就是硬件问题。

使用特权

评论回复
Cjy_JDxy|  楼主 | 2018-5-12 08:45 | 显示全部楼层
yiy 发表于 2018-5-11 23:43
哪个芯片?烧录进cube里面的例子试试看。如果例子都没法运行,那就是硬件问题。 ...

STM32F103C8T6,换了个8M晶振好了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:绿水本无忧因风皱面,青山原不老为雪白头。

553

主题

3520

帖子

19

粉丝