1.问题描述,我移植例程做SPI FLASH模拟U盘,但是一直检测到U盘连接和断开连接提示,而且不断重复提示。从HAL库,移植到标准库上。 在电脑设备管理能看到分配的驱动器号,但是看不到U盘容量,且格式化失败。
2.现象截图如下:
3.由于图1,不断出现连接又断开的情况,应该是检测到USB接线引脚电平的变化,然后中断中不断判断U盘状态,但是我设置引脚模式也不见效果,相关的设置代码如下:
/**
* @brief USB_OTG_BSP_Init
* Initilizes BSP configurations
* @param None
* @retval None
*/
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE); //开启FS时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_OTG1_FS);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_OTG1_FS);
}
/**
* @brief USB_OTG_BSP_EnableInterrupt
* Configures USB Global interrupt
* @param None
* @retval None
*/
void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief SPI5初始化,SCLK MOSI MISO引脚以及SPI基本模式
* @param
* @retval
*/
void SPI5_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI5, ENABLE);
GPIO_PinAFConfig(GPIOF, GPIO_PinSource7, GPIO_AF_SPI5);
GPIO_PinAFConfig(GPIOF, GPIO_PinSource8, GPIO_AF_SPI5);
GPIO_PinAFConfig(GPIOF, GPIO_PinSource9, GPIO_AF_SPI5);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //CS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
//设置SCLKMISOMOSI引脚模式(复用推挽输出)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
//SPI模式配置
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI5, &SPI_InitStructure);
}
麻烦大家帮忙分析分析,谢谢!
USB USB Device Library v1.1.0 [FS]
eading...
USB Device Library v1.1.0 [FS]
MSC Interface started.
USB DisConnected
USB RUSB Device Library v1.1.0 [FS]
ading...
USB Connected
USB Device Library v1.1.0 [FS]
MSC Interface started.
USB DisConnectUSB Device Library v1.1.0 [FS]
d
USB Connected
USB Device Library v1.1.0 [FS]
MSC Interface started.
USB RUSB Device Library v1.1.0 [FS]
ading...
USB Device Library v1.1.0 [FS]
MSC Interface started.
USB DisConnected
USB RUSB Device Library v1.1.0 [FS]
ading...
USB Connected
USB Device Library v1.1.0 [FS]
MSC Interface started.
USB ReUSB Device Library v1.1.0 [FS]
ding...
USB Device Library v1.1.0 [FS]
MSC Interface started.
USB DisConnected
USB Device Library v1.1.0 [FS]
USB Device Library v1.1.0 [FS]
MSC Interface started.
USB Connected
一周热门 更多>