cancel
Showing results for 
Search instead for 
Did you mean: 

windows gets hanged in USB MSC (with uSD) example

martinj3456
Associate III
Posted on December 25, 2015 at 23:45

Hello,

For USB Mass storage, I've followed [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/USB%20CDC%20on%20STM32L%20device%20%20unable%20to%20connect%20to%20host&currentviews=5635]this post and connect PA11,12 directly D+,D- and used internal pull-up(SYSCFG_USB) for STM32L151. It works without AF function declaration. I've declared 2K stack size with 1K heap. Windows can detect ''STM32 Mass Storage'' as a drive, but, in the properties info tab:

''Device USB\VID_0483&PID_5720\C24C3DB3DB18 could not be migrated''.

Also, when I insert a uSD card in the socket and power on system, Windows gets hanged/ can't access.

My purpose is to check primarily whether I can read/copy files from uSD card to PC. Am I missing any code segment to add? Previously, I checked my SD card with simple FATFS read/write following Clive's

/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/FatFsSDIO%20on%20STM32L1xx&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=143

Thank you for your kind comment.

&sharpinclude ''nucleo15x_sdio.h''

&sharpinclude ''nucleo15x_sdio_sd.h''

......................

void SD_LowLevel_Init(void)

{

........

}

void SD_LowLevel_DeInit(void)

{

........

}

void SDIO_IRQHandler(void)

{

  SD_ProcessIRQSrc();

}

void USB_Interrupts_Config_1(void)

{

  NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;   

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

    

  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_Init(&NVIC_InitStructure);

    

//  NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;

//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

//  NVIC_Init(&NVIC_InitStructure);

//  NVIC_InitStructure.NVIC_IRQChannel = USB_FS_WKUP_IRQn;

//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

//  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

//  NVIC_Init(&NVIC_InitStructure);        

}

void USB_Set_System(void);

{

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);    

  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA,ENABLE) ;   

  EXTI_ClearITPendingBit(EXTI_Line18);

  EXTI_InitStructure1.EXTI_Line = EXTI_Line18;

  EXTI_InitStructure1.EXTI_Trigger = EXTI_Trigger_Rising;

  EXTI_InitStructure1.EXTI_LineCmd = ENABLE;

  EXTI_Init(&EXTI_InitStructure1);

}

int main(void)

{    

  USB_Set_System();

  //MAL_Config();  

  SD_Init();

 

  //Set_USBClock();

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);

 

  USB_Interrupts_Config_1();

 

  SYSCFG_USBPuCmd( ENABLE );  // Again called in USB_Cable_Config(ENABLE) of USB_Init() routine.

  delay_us(100000);  // 100ms delay

  USB_Init();

 

  //  while (bDeviceState != CONFIGURED);

 

  while (1)

        {

        }

}

null
4 REPLIES 4
Posted on December 26, 2015 at 00:45

You'd need to dig into the SCSI layer implementation, and it's interactions, to understand what's causing Windows issues. I'd probably look for code that might block execution, or how ST manages block/byte sizes, and device capacity.

I don't have any L1 boards to be able to do much more than blind porting or analysis.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
martinj3456
Associate III
Posted on December 26, 2015 at 01:31

My full project files are

https://drive.google.com/file/d/0ByhEessIB0peVFQtcHRLeTU5QkE/view?usp=sharing

, would you have time to take a look into.

Actually, I can't guess what might block the execution.

Thank you for your kind time spending on it. 
martinj3456
Associate III
Posted on December 26, 2015 at 05:39

Its working... I've added a 1K pull-up resistor with D+ pin and removed software delay.

And USB mass-storage is now full-functioning. I'll upload final code shortly.

Thank you Clive.
martinj3456
Associate III
Posted on December 27, 2015 at 02:53

Hi Clive,

I need to check the USB connection (of my battery powered device) at the startup, and halt the system for PC data transfer; Continue code execution if not connected.

Could you suggest me the appropriate code segment here? checking 'bDeviceState' status can help here?

I avoided suspend-wakeup in my project as I don't need USB frequently in the system. Thank you for your time. Full working project uploaded

https://drive.google.com/file/d/0ByhEessIB0peVl94dFh3dGdTelE/view?usp=sharing

.

void USB_Conf(void)

{

  NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;   

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

    

  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_Init(&NVIC_InitStructure);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);

  // Avoided internal pull-up here. 1K pull-up Resistor with PA11 and D+ pin.

        

  SD_Init();

  USB_Init();

}

int main(void)

{    

  USB_Conf();    

    while (1)

            {

            }

}