cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 : USB library : toggle bug ?

Ixox
Associate II
Posted on October 09, 2012 at 23:02

Hello,

I'm trying to port the STM32  USB host+MSC driver to the little board fez cerb40 (stm32F405rg) to allow it to read a USB stick.

I'm blocked on a problem since several days.

I followed the guide and the CORE steps are OK.

The name of the KEY and manufactor are OK.

Then in the MSC_handle states :

. Get Max LUN is OK

. Test unit ready is OK

. mode sens 6 is OK

. request sens is OK 

(Some of them use the CBW / DATA / CSW mechanism. )

After that, the process arrives in the application state when i try to access the file system.

During the first READ (disk_read in usb_msc_fatfs.c) which occured during that FAT function chk_mounted, the program freezes.

What happens is a toggle error while reading the CSW. (USBH_MSC_RECEIVE_CSW_STATE).

The error is not tracked so the program goes in an infinite loop.

If I removed the CSW check part and make it return with an OK status.

After that, I was able to mount the file system and even read file on it.

I read a small file an display the content on my LCD, it was correct.

What can make the ''Receive CSW'' receving a toggle error during the SCSI command ?

Thanks for any idea or suggestion i could investigate,

Xavier

#stm32f405rg-toggle-csw-usb
4 REPLIES 4
Posted on October 10, 2012 at 02:41

Generally when SCSI commands fail, you send a Request Sense to find out why.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Ixox
Associate II
Posted on October 11, 2012 at 10:44

Thanks for your answer.

I'm not 100% sure yet, but that i have the feeling that can be a bug in the STM32 USB library.

I think that the toggle bit should be ''toggled'' in receving mode only when the number of packet to receive is odd.

With this modification on ''receving data'' in the BOT mechanism i can now read the fat FS on my USB stick :)

I'm now investigating a transmission error on DATA sent during a disk_write (again the error is not catched in the usb_msb_BOT.c file so the program enter en infinite loop).

I'm going to use Request Sense for that.

I didn't know  USB was so complicated ;)

Xavier

Ixox
Associate II
Posted on October 11, 2012 at 22:28

So there's really a problem the with the core OTG_HS and the STM32F4 USB library.

I changed in usbh_conf.h for OTG_HS :

USBH_MSC_MPS_SIZE  0x40

(Same value as for FS) and everything works like a charm.

I may be totally wrong but from what i understood the toggle bit does not work when the transfer size is bigger than the EP packet size. (that's why it works with OTG_FS)

Maybe due to the fact that toogle bits (in and out) are controlled by software and are not aware of the individual packet exchange between the USB and the device.

I could fix the problem when receiving DATA... i toggled the toggle_in one more time when the number of packet is even.

I did not find a proper solution when sending DATA. It always terminated in a infinite loop because of a transmission error... Do the core send all packets with the same DATA PID that lead to a transmission error exception ?

Erything work  with USBH_MSC_MPS_SIZE set to 0x40. I think it's because the toggle bit is correctly set by the STM32F4 library because one transfer = one packet.

I'm new to the forum, is there any one from STM that could confirm ? Or explain me what i missed ?

Thanks,

Xavier

lucas2
Associate
Posted on January 14, 2015 at 17:37

Hi, clive1!

I have some doubts about the USB STM32F4 processor and realized that you have enough experience with it. Any contact so I can contact?

My email address is lucas@tothtecnologia.com.br 

Best regards!