cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F105 unable to detect USB memory stick removal

BRama
Associate

Hello All, I m using STM32F105R8 as USB Host to read and write files to USB memory stick with HAL lib. Cube FW version STM32Cube_FW_F1_V1.7.0.

Setup:

1) Custom board with STM32F105R8 as USB host and USB socket for inserting USB memory stick (pen drive). It is basically a Datalogger project to store data in USB pen drive

2) USB Memory stick is powered by the uC board with its own 5v. Vbus sensing is used but i assume it is of no use the board is powering up all the time

3) I have not pulled up or pulled down the DP and DM lines of USB. ESD protection circuit is implemented with USBUF01W6. I assume as a HOST board, I dont need to pull up of DP with 1.5k.

Problem:

1) If I power up the board with USB already inserted, then MX_USB_HOST_Process() is able to start, enumerate and come to ready state. I could read write files using FATFS - This has no problem

2) The issue is : After power on, If I simply disconnect the USB memory stick, then no change in the Appli_state. I does not go to disconnect state at all. It is not able to recognize the disconnect.

3) If I insert the Memory stick again, it could not detect the new device anymore. Further file operation hangs the uC

4) As I mentioned in #1, If the USB is inserted since power on, it works fine and during file operation If i disconnect, then after several seconds it recovers after that it is not able to detect if I insert the memory stick again.

Question:

How to make the uC to detect the USB mass storage device is inserted as well able to detect the removal.

I call this in while under main()

void USB_HOST_BACKGROUND_TASK(void)

{

 MX_USB_HOST_Process();

switch(Appli_state)

{

case APPLICATION_IDLE:

break;

case APPLICATION_START:

if(f_mount(&myUSBfatfs,(TCHAR const*)USBHPath,0) != FR_OK)

{

Error_Handler();

}

else

{

}

break;

case APPLICATION_READY:

ResetMicros();

if(tmst>10)

{

 if(!B_f)

{

B_f=1;

//UsbTest_Write();

f_open(&myFile1, "file1.TXT", FA_WRITE | FA_CREATE_ALWAYS);

f_open(&myFile2, "file2.TXT", FA_WRITE | FA_CREATE_ALWAYS);

}

else if(tmst<20)

{

     sprintf(rwtext, "\r\nHello from Balaji Ramalingam %ul",timer1ms_l);

    //Write to text file

    f_write(&myFile1, (const void *)rwtext, strlen(rwtext), &byteswritten);

sprintf(rwtext, "\r\nHello from Balaji Ramalingam %ul",timer1ms_l+100);

     f_write(&myFile2, (const void *)rwtext, strlen(rwtext), &byteswritten);

}

else if(tmst==21)

{

 f_close(&myFile1);

f_close(&myFile2);

}

}

GetMicros();

break;

case APPLICATION_DISCONNECT:

//output_write(0,op_PWMLED2)

break;

}

}

0 REPLIES 0